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);
        }
Exemple #2
0
        public override void UseItem(Level world, Player player, BlockCoordinates blockCoordinates, BlockFace face, Vector3 faceCoords)
        {
            var   coor  = GetNewCoordinatesFromFace(blockCoordinates, face);
            Chest chest = new Chest
            {
                Coordinates = coor,
                Metadata    = (byte)Metadata
            };

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

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

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

            ChestBlockEntity chestBlockEntity = new ChestBlockEntity
            {
                Coordinates = coor
            };

            world.SetBlockEntity(chestBlockEntity);
        }
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
            }

            ChestBlockEntity chestBlockEntity = new ChestBlockEntity
            {
                Coordinates = Coordinates
            };

            world.SetBlockEntity(chestBlockEntity);

            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 == "Furnace") blockEntity = new FurnaceBlockEntity();

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

            var chestBlockEntity = new ChestBlockEntity {
                Coordinates = Coordinates
            };

            world.SetBlockEntity(chestBlockEntity);

            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);
        }
        public void PlaceChest(PositionEdge postion)
        {
            Chest chest = new Chest
            {
                Coordinates = new BlockCoordinates(postion.X + 47, 75, postion.Z + 50),
                Metadata    = (byte)5
            };

            Level.SetBlock(chest);
            ChestBlockEntity chestBlockEntity = new ChestBlockEntity
            {
                Coordinates = new BlockCoordinates(postion.X + 47, 75, postion.Z + 50)
            };

            Level.SetBlockEntity(chestBlockEntity);
            Inventory inventory = Level.InventoryManager.GetInventory(new BlockCoordinates(postion.X + 47, 75, postion.Z + 50));
            byte      c         = 0;

            inventory.Slots[c++] = ItemFactory.GetItem(6, 0, 2);
            //inventory.Slots[c++] = ItemFactory.GetItem(6, 1, 2);
            //inventory.Slots[c++] = ItemFactory.GetItem(6, 2, 1);
            //inventory.Slots[c++] = ItemFactory.GetItem(6, 3, 2);
            //inventory.Slots[c++] = ItemFactory.GetItem(6, 4, 2);
            //inventory.Slots[c++] = ItemFactory.GetItem(6, 5, 2);
            inventory.Slots[c++] = ItemFactory.GetItem(8, 0, 2);
            inventory.Slots[c++] = ItemFactory.GetItem(10, 0, 1);
            inventory.Slots[c++] = ItemFactory.GetItem(17, 0, 15);
            inventory.Slots[c++] = ItemFactory.GetItem(39, 0, 3);
            inventory.Slots[c++] = ItemFactory.GetItem(40, 0, 3);
            inventory.Slots[c++] = ItemFactory.GetItem(58, 0, 1);
            inventory.Slots[c++] = ItemFactory.GetItem(81, 0, 1);
            inventory.Slots[c++] = ItemFactory.GetItem(391, 0, 3);
            inventory.Slots[c++] = ItemFactory.GetItem(392, 0, 3);
            inventory.Slots[c++] = ItemFactory.GetItem(260, 0, 10);
            inventory.Slots[c++] = ItemFactory.GetItem(325, 0, 1);
            inventory.Slots[c++] = ItemFactory.GetItem(352, 0, 5);
            inventory.Slots[c++] = ItemFactory.GetItem(361, 0, 2);
            inventory.Slots[c++] = ItemFactory.GetItem(362, 0, 2);
            inventory.Slots[c++] = ItemFactory.GetItem(338, 0, 1);
            inventory.SendInventory();
        }
Exemple #9
0
        public void OpenInventory(Player player)
        {
            BlockCoordinates coor  = new BlockCoordinates(player.KnownPosition);
            Chest            chest = new Chest
            {
                Coordinates = coor, Metadata = 0
            };

            player.Level.SetBlock(chest, true);

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

            ChestBlockEntity chestBlockEntity = new ChestBlockEntity
            {
                Coordinates = coor
            };

            player.Level.SetBlockEntity(chestBlockEntity, false);

            player.OpenInventory(coor);
        }
Exemple #10
0
        /// <inheritdoc />
        public override BlockState BlockPlaced(IBlockAccess world, BlockState state, BlockCoordinates position)
        {
            if (world is World w)
            {
                if ((w.EntityManager.TryGetBlockEntity(position, out var entity) && !(entity is ChestBlockEntity)))
                {
                    w.EntityManager.RemoveBlockEntity(position);
                }

                if (entity is ChestBlockEntity)
                {
                    return(base.BlockPlaced(world, state, position));
                }

                var ent = new ChestBlockEntity(this, w, BlockEntityFactory.ChestTexture)
                {
                    X = position.X & 0xf, Y = position.Y & 0xff, Z = position.Z & 0xf
                };

                w.SetBlockEntity(position.X, position.Y, position.Z, ent);
            }
            return(base.BlockPlaced(world, state, position));
        }
Exemple #11
0
        public override void UseItem(Level world, Player player, BlockCoordinates blockCoordinates, BlockFace face, Vector3 faceCoords)
        {
            if (player.GameMode != GameMode.Creative)
            {
                ItemStack itemStackInHand = player.Inventory.GetItemInHand();
                itemStackInHand.Count--;

                if (itemStackInHand.Count <= 0)
                {
                    // set empty
                    player.Inventory.Slots[player.Inventory.Slots.IndexOf(itemStackInHand)] = new ItemStack();
                }
            }

            var   coor  = GetNewCoordinatesFromFace(blockCoordinates, face);
            Chest chest = new Chest
            {
                Coordinates = coor,
                Metadata    = (byte)Metadata
            };

            if (!chest.CanPlace(world, face))
            {
                return;
            }

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

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

            ChestBlockEntity chestBlockEntity = new ChestBlockEntity
            {
                Coordinates = coor
            };

            world.SetBlockEntity(chestBlockEntity);
        }
Exemple #12
0
        /// <inheritdoc />
        public override BlockState BlockPlaced(IBlockAccess world, BlockState state, BlockCoordinates position)
        {
            if (world is World w)
            {
                if (!w.EntityManager.TryGetBlockEntity(position, out var entity))
                {
                    var ent = new ChestBlockEntity(this, w, BlockEntityFactory.ChestTexture)
                    {
                        X = position.X & 0xf, Y = position.Y & 0xff, Z = position.Z & 0xf
                    };

                    w.EntityManager.AddBlockEntity(
                        position, ent);

                    var chunk = world.GetChunk(position, true);

                    if (chunk != null)
                    {
                        chunk.AddBlockEntity(new BlockCoordinates(ent.X, ent.Y, ent.Z), ent);
                    }
                }
            }
            return(base.BlockPlaced(world, state, position));
        }
Exemple #13
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)
                {
                    Block inventoryBlock = _level.GetBlock(inventoryCoord);
                    switch (inventoryBlock)
                    {
                    case Chest _:
                        blockEntity = new ChestBlockEntity();
                        break;

                    case ShulkerBox _:
                        blockEntity = new ShulkerBoxBlockEntity();
                        break;
                    }
                }

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

                NbtCompound comp = blockEntity.GetCompound();

                Inventory inventory;
                switch (blockEntity)
                {
                case ChestBlockEntity _:
                case ShulkerBoxBlockEntity _:
                    inventory = new Inventory(GetInventoryId(), blockEntity, 27, (NbtList)comp["Items"])
                    {
                        Type      = 0,
                        WindowsId = 10,
                    };
                    break;

                case EnchantingTableBlockEntity _:
                    inventory = new Inventory(GetInventoryId(), blockEntity, 2, (NbtList)comp["Items"])
                    {
                        Type      = 3,
                        WindowsId = 12,
                    };
                    break;

                case FurnaceBlockEntity furnaceBlockEntity:
                {
                    inventory = new Inventory(GetInventoryId(), furnaceBlockEntity, 3, (NbtList)comp["Items"])
                    {
                        Type      = 2,
                        WindowsId = 11,
                    };

                    furnaceBlockEntity.Inventory = inventory;
                    break;
                }

                case BlastFurnaceBlockEntity furnaceBlockEntity:
                {
                    inventory = new Inventory(GetInventoryId(), furnaceBlockEntity, 3, (NbtList)comp["Items"])
                    {
                        Type      = 27,
                        WindowsId = 13,
                    };

                    furnaceBlockEntity.Inventory = inventory;
                    break;
                }

                default:
                {
                    if (Log.IsDebugEnabled)
                    {
                        Log.Warn($"Block entity did not have a matching inventory {blockEntity}");
                    }
                    return(null);
                }
                }

                _cache[inventoryCoord] = inventory;

                return(inventory);
            }
        }
        public void OpenInventory(Player player)
        {
            //Log.Info("Command Executed!");
            player.SendMessage("Opening Chest...");

            /*BlockCoordinates coords = (BlockCoordinates) player.KnownPosition;
             * coords.Y = 0;*/
            BlockCoordinates coords = new BlockCoordinates(0);

            //Block past = player.Level.GetBlock(coords);

            McpeUpdateBlock chest = Package <McpeUpdateBlock> .CreateObject();

            chest.blockId              = 54;
            chest.coordinates          = coords;
            chest.blockMetaAndPriority = 0 & 15;
            player.SendPackage(chest);

            ChestBlockEntity blockEntity = new ChestBlockEntity {
                Coordinates = coords
            };
            NbtCompound compound = blockEntity.GetCompound();

            compound["CustomName"] = new NbtString("CustomName", "§5§k--§r §l§o§2Virtual Chest§r §5§k--§r");
            //player.Level.SetBlockEntity(blockEntity);
            McpeBlockEntityData chestEntity = Package <McpeBlockEntityData> .CreateObject();

            chestEntity.namedtag = new Nbt
            {
                NbtFile = new NbtFile
                {
                    BigEndian = false,
                    UseVarInt = true,
                    RootTag   = compound
                }
            };
            chestEntity.coordinates = coords;
            player.SendPackage(chestEntity);

            //player.OpenInventory(coords);
            Inventory inventory = new Inventory(0, blockEntity, 1, new NbtList())
            {
                Type      = 0,
                WindowsId = 10
            };

            //inventory.InventoryChange += new Action<Player, MiNET.Inventory, byte, Item>(player.OnInventoryChange);
            inventory.AddObserver(player);
            McpeContainerOpen mcpeContainerOpen = Package <McpeContainerOpen> .CreateObject(1L);

            mcpeContainerOpen.windowId               = inventory.WindowsId;
            mcpeContainerOpen.type                   = inventory.Type;
            mcpeContainerOpen.coordinates            = coords;
            mcpeContainerOpen.unknownRuntimeEntityId = 1L;
            player.SendPackage((Package)mcpeContainerOpen);
            McpeInventoryContent inventoryContent = Package <McpeInventoryContent> .CreateObject(1L);

            inventoryContent.inventoryId = (uint)inventory.WindowsId;
            inventoryContent.input       = inventory.Slots;
            player.SendPackage((Package)inventoryContent);
        }
Exemple #15
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);
        }