Beispiel #1
0
        public override void UseItem(Level world, Player player, BlockCoordinates blockCoordinates, BlockFace face, Vector3 faceCoords)
        {
            if (player.GameMode != GameMode.Creative)
            {
                Item itemStackInHand = player.Inventory.GetItemInHand();
                itemStackInHand.Count--;

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

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

            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);
        }
Beispiel #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, 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);
        }
Beispiel #3
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);
        }