Exemple #1
0
        public static BlockEntity GetBlockEntityById(string blockEntityId)
        {
            BlockEntity blockEntity = null;

            if (blockEntityId == "Sign")
            {
                blockEntity = new Sign();
            }
            else if (blockEntityId == "Chest")
            {
                blockEntity = new ChestBlockEntity();
            }
            else if (blockEntityId == "EnchantTable")
            {
                blockEntity = new EnchantingTableBlockEntity();
            }
            else if (blockEntityId == "Furnace")
            {
                blockEntity = new FurnaceBlockEntity();
            }
            else if (blockEntityId == "Skull")
            {
                blockEntity = new SkullBlockEntity();
            }

            return(blockEntity);
        }
        public Inventory GetInventory(BlockCoordinates inventoryCoord)
        {
            lock (_cache)
            {
                if (_cache.ContainsKey(inventoryCoord))
                {
                    Inventory cachedInventory = _cache[inventoryCoord];
                    if (cachedInventory != null)
                    {
                        return(cachedInventory);
                    }
                }

                BlockEntity blockEntity = _level.GetBlockEntity(inventoryCoord);

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

                NbtCompound comp = blockEntity.GetCompound();

                Inventory inventory;
                if (blockEntity is ChestBlockEntity)
                {
                    inventory = new Inventory(GetInventoryId(), blockEntity, 27, (NbtList)comp["Items"])
                    {
                        Type      = 0,
                        WindowsId = 10,
                    };
                }
                else if (blockEntity is EnchantingTableBlockEntity)
                {
                    inventory = new Inventory(GetInventoryId(), blockEntity, 2, (NbtList)comp["Items"])
                    {
                        Type      = 4,
                        WindowsId = 12,
                    };
                }
                else if (blockEntity is FurnaceBlockEntity)
                {
                    inventory = new Inventory(GetInventoryId(), blockEntity, 3, (NbtList)comp["Items"])
                    {
                        Type      = 2,
                        WindowsId = 11,
                    };

                    FurnaceBlockEntity furnace = (FurnaceBlockEntity)blockEntity;
                    furnace.Inventory = inventory;
                }
                else
                {
                    return(null);
                }

                _cache[inventoryCoord] = inventory;

                return(inventory);
            }
        }
Exemple #3
0
        public override bool PlaceBlock(Level world, Player player, BlockCoordinates blockCoordinates, BlockFace face, Vector3 faceCoords)
        {
            byte direction = player.GetDirection();

            switch (direction)
            {
            case 1:
                Metadata = 2;
                break;                         // West

            case 2:
                Metadata = 5;
                break;                         // North

            case 3:
                Metadata = 3;
                break;                         // East

            case 0:
                Metadata = 4;
                break;                         // South
            }

            FurnaceBlockEntity furnaceBlockEntity = new FurnaceBlockEntity
            {
                Coordinates = Coordinates
            };

            world.SetBlockEntity(furnaceBlockEntity);

            return(false);
        }
Exemple #4
0
        public override void UseItem(Level world, Player player, BlockCoordinates blockCoordinates, BlockFace face, Vector3 faceCoords)
        {
            var     coor    = GetNewCoordinatesFromFace(blockCoordinates, face);
            Furnace furnace = new Furnace
            {
                Coordinates = coor,
                Metadata    = (byte)Metadata
            };

            if (!furnace.CanPlace(world))
            {
                return;
            }

            furnace.PlaceBlock(world, player, coor, face, faceCoords);

            // Then we create and set the sign block entity that has all the intersting data

            FurnaceBlockEntity furnaceBlockEntity = new FurnaceBlockEntity
            {
                Coordinates = coor
            };

            world.SetBlockEntity(furnaceBlockEntity);
        }
		public static BlockEntity GetBlockEntityById(string blockEntityId)
		{
			BlockEntity blockEntity = null;

			if (blockEntityId == "Sign") blockEntity = new Sign();
			else if (blockEntityId == "Chest") blockEntity = new ChestBlockEntity();
			else if (blockEntityId == "Furnace") blockEntity = new FurnaceBlockEntity();

			return blockEntity;
		}
Exemple #6
0
        public override bool PlaceBlock(Level world, Player player, BlockCoordinates blockCoordinates, BlockFace face, Vector3 faceCoords)
        {
            FacingDirection = ItemBlock.GetFacingDirectionFromEntity(player);

            var furnaceBlockEntity = new FurnaceBlockEntity {
                Coordinates = Coordinates
            };

            world.SetBlockEntity(furnaceBlockEntity);

            return(false);
        }
        public static BlockEntity GetBlockEntityById(string blockEntityId)
        {
            BlockEntity blockEntity = null;

            if (blockEntityId == "Sign") blockEntity = new Sign();
            else if (blockEntityId == "Chest") blockEntity = new ChestBlockEntity();
            else if (blockEntityId == "EnchantTable") blockEntity = new EnchantingTableBlockEntity();
            else if (blockEntityId == "Furnace") blockEntity = new FurnaceBlockEntity();
            else if (blockEntityId == "Skull") blockEntity = new SkullBlockEntity();
            else if (blockEntityId == "ItemFrame") blockEntity = new ItemFrameBlockEntity();

            return blockEntity;
        }
        public static BlockEntity GetBlockEntityById(string blockEntityId)
        {
            BlockEntity blockEntity = null;

            if (blockEntityId == "Sign")
            {
                blockEntity = new Sign();
            }
            else if (blockEntityId == "Chest")
            {
                blockEntity = new ChestBlockEntity();
            }
            else if (blockEntityId == "EnchantTable")
            {
                blockEntity = new EnchantingTableBlockEntity();
            }
            else if (blockEntityId == "Furnace")
            {
                blockEntity = new FurnaceBlockEntity();
            }
            else if (blockEntityId == "Skull")
            {
                blockEntity = new SkullBlockEntity();
            }
            else if (blockEntityId == "ItemFrame")
            {
                blockEntity = new ItemFrameBlockEntity();
            }
            else if (blockEntityId == "Bed")
            {
                blockEntity = new BedBlockEntity();
            }
            else if (blockEntityId == "Banner")
            {
                blockEntity = new BannerBlockEntity();
            }
            else if (blockEntityId == "FlowerPot")
            {
                blockEntity = new FlowerPotBlockEntity();
            }
            else if (blockEntityId == "Beacon")
            {
                blockEntity = new BeaconBlockEntity();
            }
            else if (blockEntityId == "MobSpawner")
            {
                blockEntity = new MobSpawnerBlockEntity();
            }

            return(blockEntity);
        }
Exemple #9
0
        public Inventory GetInventory(BlockCoordinates inventoryCoord)
        {
            lock (_cache)
            {
                if (_cache.ContainsKey(inventoryCoord))
                {
                    Inventory cachedInventory = _cache[inventoryCoord];
                    if (cachedInventory != null)
                    {
                        return(cachedInventory);
                    }
                }

                BlockEntity blockEntity = _level.GetBlockEntity(inventoryCoord);

                if (blockEntity == null)
                {
                    if (Log.IsDebugEnabled)
                    {
                        Log.Warn($"No blockentity found at {inventoryCoord}");
                    }
                    return(null);
                }

                NbtCompound comp = blockEntity.GetCompound();

                Inventory inventory;
                if (blockEntity is ChestBlockEntity || blockEntity is ShulkerBoxBlockEntity)
                {
                    inventory = new Inventory(GetInventoryId(), blockEntity, 27, (NbtList)comp["Items"])
                    {
                        Type      = 0,
                        WindowsId = 10,
                    };
                }
                else if (blockEntity is EnchantingTableBlockEntity)
                {
                    inventory = new Inventory(GetInventoryId(), blockEntity, 2, (NbtList)comp["Items"])
                    {
                        Type      = 3,
                        WindowsId = 12,
                    };
                }
                else if (blockEntity is FurnaceBlockEntity)
                {
                    inventory = new Inventory(GetInventoryId(), blockEntity, 3, (NbtList)comp["Items"])
                    {
                        Type      = 2,
                        WindowsId = 11,
                    };

                    FurnaceBlockEntity furnace = (FurnaceBlockEntity)blockEntity;
                    furnace.Inventory = inventory;
                }
                else
                {
                    if (Log.IsDebugEnabled)
                    {
                        Log.Warn($"Block entity did not have a matching inventory {blockEntity}");
                    }
                    return(null);
                }

                _cache[inventoryCoord] = inventory;

                return(inventory);
            }
        }
Exemple #10
0
        public static BlockEntity GetBlockEntityById(string blockEntityId)
        {
            BlockEntity blockEntity = CustomBlockEntityFactory?.GetBlockEntityById(blockEntityId);

            if (blockEntity != null)
            {
                return(blockEntity);
            }

            if (blockEntityId == "Sign")
            {
                blockEntity = new SignBlockEntity();
            }
            else if (blockEntityId == "Chest")
            {
                blockEntity = new ChestBlockEntity();
            }
            else if (blockEntityId == "EnchantTable")
            {
                blockEntity = new EnchantingTableBlockEntity();
            }
            else if (blockEntityId == "Furnace")
            {
                blockEntity = new FurnaceBlockEntity();
            }
            else if (blockEntityId == "BlastFurnace")
            {
                blockEntity = new BlastFurnaceBlockEntity();
            }
            else if (blockEntityId == "Skull")
            {
                blockEntity = new SkullBlockEntity();
            }
            else if (blockEntityId == "ItemFrame")
            {
                blockEntity = new ItemFrameBlockEntity();
            }
            else if (blockEntityId == "Bed")
            {
                blockEntity = new BedBlockEntity();
            }
            else if (blockEntityId == "Banner")
            {
                blockEntity = new BannerBlockEntity();
            }
            else if (blockEntityId == "FlowerPot")
            {
                blockEntity = new FlowerPotBlockEntity();
            }
            else if (blockEntityId == "Beacon")
            {
                blockEntity = new BeaconBlockEntity();
            }
            else if (blockEntityId == "MobSpawner")
            {
                blockEntity = new MobSpawnerBlockEntity();
            }
            else if (blockEntityId == "ChalkboardBlock")
            {
                blockEntity = new ChalkboardBlockEntity();
            }
            else if (blockEntityId == "ShulkerBox")
            {
                blockEntity = new ShulkerBoxBlockEntity();
            }
            else if (blockEntityId == "StructureBlock")
            {
                blockEntity = new StructureBlockBlockEntity();
            }

            return(blockEntity);
        }