예제 #1
0
 public static bool MatchingWood(this AssetLocation asset, ref string woodtype)
 {
     foreach (string a in woodtypes)
     {
         if (asset.ToString().Contains(a))
         {
             woodtype = a;
             return(true);
         }
     }
     woodtype = null;
     return(false);
 }
예제 #2
0
        public override void StartClientSide(ICoreClientAPI api)
        {
            capi = api;

            WaypointClassifications.Clear();
            api.Event.LevelFinalize += () =>
            {
                foreach (var block in api.World.Blocks)
                {
                    if (block.Code == null)
                    {
                        continue;
                    }
                    string col = ColorUtil.Int2Hex(~block.GetColor(api, new BlockPos()));
                    col = col.Insert(1, "FF");
                    AssetLocation loc = GetClassifiedAssetLocation(block.Code, "block");
                    WaypointClassifications[loc] = new WaypointClassification()
                    {
                        Name  = Lang.GetMatching(loc.ToString()),
                        Color = col
                    };
                }

                foreach (var entity in api.World.EntityTypes)
                {
                    if (entity.Code == null)
                    {
                        continue;
                    }

                    AssetLocation loc = GetClassifiedAssetLocation(entity.Code, "item-creature");
                    WaypointClassifications[loc] = new WaypointClassification()
                    {
                        Name  = Lang.GetMatching(loc.ToString()),
                        Color = "#FFFF0000"
                    };
                }
            };

            api.Input.RegisterHotKey("vshud.markwaypoint", "(VSHUD) Mark Waypoint", GlKeys.BackSlash);
            api.Input.SetHotKeyHandler("vshud.markwaypoint", (a) =>
            {
                MarkWPForSelection(api.World.Player);
                return(true);
            });
        }
예제 #3
0
        public static MeshData GetMesh(ITesselatorAPI tesselator, ICoreAPI api, BlockCrock block, ItemStack[] stacks, string recipeCode, Vec3f rot)
        {
            Dictionary <string, MeshData> meshes = ObjectCacheUtil.GetOrCreate(api, "blockCrockMeshes", () => new Dictionary <string, MeshData>());
            MeshData mesh = null;



            AssetLocation labelLoc = block.LabelForContents(recipeCode, stacks);

            if (labelLoc == null)
            {
                return(null);
            }

            if (meshes.TryGetValue(labelLoc.ToShortString() + block.Shape.rotateY, out mesh))
            {
                return(mesh);
            }

            return(meshes[labelLoc.ToString() + block.Shape.rotateY] = block.GenMesh(api as ICoreClientAPI, labelLoc, rot, tesselator));
        }
예제 #4
0
        public override bool OnBlockInteractStart(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel, ref EnumHandling handling)
        {
            BlockPos pos = blockSel.Position;
            ModSystemBlockReinforcement bR = api.ModLoader.GetModSystem <ModSystemBlockReinforcement>();

            if (disabled || bR.IsReinforced(pos) || bR.IsLocked(pos, byPlayer))
            {
                return(base.OnBlockInteractStart(world, byPlayer, blockSel, ref handling));
            }

            SwapSystem swapSystem = api.ModLoader.GetModSystem <SwapSystem>();

            handling = EnumHandling.PreventDefault;
            ItemSlot slot = byPlayer.InventoryManager.ActiveHotbarSlot;


            if (!(requireSneak && !byPlayer.Entity.Controls.Sneak) && slot.Itemstack != null)
            {
                string key = GetKey(slot.Itemstack.Collectible.Code.ToString());

                if (swapSystem.SwapPairs.TryGetValue(key, out SwapBlocks swap))
                {
                    if (swap.Takes != null && swap.Takes != block.Code.ToString())
                    {
                        return(true);
                    }
                    AssetLocation asset = slot.Itemstack.Collectible.Code;
                    if (asset.ToString() == swap.Tool)
                    {
                        AssetLocation toAsset = new AssetLocation(swap.Makes.WithDomain());
                        Block         toBlock = toAsset.GetBlock(world.Api);

                        int count = swap.Count;

                        if (count != 0)
                        {
                            if (count < 0)
                            {
                                ItemStack withCount = slot.Itemstack.Clone();
                                withCount.StackSize = Math.Abs(count);
                                if (!byPlayer.InventoryManager.TryGiveItemstack(withCount))
                                {
                                    world.SpawnItemEntity(withCount, pos.ToVec3d().Add(0.5, 0.5, 0.5));
                                }
                            }
                            else if (slot.Itemstack.StackSize >= count)
                            {
                                if (byPlayer.WorldData.CurrentGameMode.IsSurvival())
                                {
                                    slot.TakeOut(count);
                                }
                            }
                            else
                            {
                                return(true);
                            }
                        }

                        ((byPlayer.Entity as EntityPlayer)?.Player as IClientPlayer)?.TriggerFpAnimation(EnumHandInteract.HeldItemInteract);

                        if ((block.EntityClass != null && toBlock.EntityClass != null) && (toBlock.EntityClass == block.EntityClass))
                        {
                            world.BlockAccessor.ExchangeBlock(toBlock.BlockId, pos);
                        }
                        else
                        {
                            world.BlockAccessor.SetBlock(toBlock.BlockId, pos);
                        }
                        slot.MarkDirty();
                        PlaySoundDispenseParticles(world, pos, slot);
                    }
                }
            }
            return(true);
        }
예제 #5
0
        public override void OnBlockInteractStop(float secondsUsed, IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel, ref EnumHandling handling)
        {
            BlockPos pos = blockSel?.Position;

            if (pos == null)
            {
                return;
            }

            ModSystemBlockReinforcement bR = api.ModLoader.GetModSystem <ModSystemBlockReinforcement>();

            if (disabled || bR.IsReinforced(pos) || bR.IsLocked(pos, byPlayer))
            {
                return;
            }

            SwapSystem swapSystem = api.ModLoader.GetModSystem <SwapSystem>();

            handling = EnumHandling.PreventDefault;
            ItemSlot slot = byPlayer.InventoryManager.ActiveHotbarSlot;


            if (!(requireSneak && !byPlayer.Entity.Controls.Sneak) && slot.Itemstack != null)
            {
                string key = GetKey(slot.Itemstack.Collectible.Code.ToString());

                if (swapSystem.SwapPairs.TryGetValue(key, out SwapBlocks swap))
                {
                    if (world.Side.IsClient())
                    {
                        api.ModLoader.GetModSystem <ShaderTest>().progressBar = 0;
                    }

                    if (swap.Takes != null && swap.Takes != block.Code.ToString() || secondsUsed < swap.MakeTime)
                    {
                        return;
                    }

                    AssetLocation asset = slot.Itemstack.Collectible.Code;
                    if (asset.ToString() == swap.Tool)
                    {
                        AssetLocation toAsset = new AssetLocation(swap.Makes.WithDomain());
                        Block         toBlock = toAsset.GetBlock(world.Api);

                        int count = swap.Count;

                        if (count != 0)
                        {
                            if (count < 0)
                            {
                                ItemStack withCount = slot.Itemstack.Clone();
                                withCount.StackSize = Math.Abs(count);
                                if (!byPlayer.InventoryManager.TryGiveItemstack(withCount))
                                {
                                    world.SpawnItemEntity(withCount, pos.ToVec3d().Add(0.5, 0.5, 0.5));
                                }
                            }
                            else if (slot.Itemstack.StackSize >= count)
                            {
                                if (byPlayer.WorldData.CurrentGameMode.IsSurvival())
                                {
                                    slot.TakeOut(count);
                                }
                            }
                            else
                            {
                                return;
                            }
                        }

                        if ((block.EntityClass != null && toBlock.EntityClass != null) && (toBlock.EntityClass == block.EntityClass))
                        {
                            world.BlockAccessor.ExchangeBlock(toBlock.BlockId, pos);
                        }
                        else
                        {
                            world.BlockAccessor.SetBlock(toBlock.BlockId, pos);
                        }
                        slot.MarkDirty();
                        PlaySoundDispenseParticles(world, pos, slot);
                        return;
                    }
                }
            }

            ItemStack stack = byPlayer?.InventoryManager?.ActiveHotbarSlot?.Itemstack;

            if (stack != null && allowPlaceOn)
            {
                string         r      = "";
                BlockSelection newsel = blockSel.Clone();
                newsel.Position = newsel.Position.Offset(blockSel.Face);
                Block block = stack.Block;

                if (block != null && block.TryPlaceBlock(world, byPlayer, stack, newsel, ref r))
                {
                    world.PlaySoundAt(stack.Block?.Sounds.Place, newsel.Position);
                }
            }
        }
예제 #6
0
 public static AssetLocation WithVariant(this AssetLocation location, string variantcode, string variantstate)
 {
     return(new AssetLocation(location.ToString().Replace("{" + variantcode + "}", variantstate)));
 }
예제 #7
0
 public override string ToString()
 {
     return(Base.ToString() + "@" + Rotation + "a" + Alpha);
 }
예제 #8
0
 public override string ToString()
 {
     return(Base.ToString() + "@" + Rotation);
 }