Exemplo n.º 1
0
        public override void UseItem(Level world, Player player, BlockCoordinates blockCoordinates, BlockFace face, Vector3 faceCoords)
        {
            var coor = GetNewCoordinatesFromFace(blockCoordinates, face);
            if (face == BlockFace.Up) // On top of block
            {
                // Standing Sign
                var sign = new StandingSign();
                sign.Coordinates = coor;
                // metadata for sign is a value 0-15 that signify the orientation of the sign. Same as PC metadata.
                sign.Metadata = (byte) ((int) (Math.Floor((player.KnownPosition.Yaw + 180)*16/360) + 0.5) & 0x0f);
                world.SetBlock(sign);
            }
            else if (face == BlockFace.North) // At the bottom of block
            {
                // Doesn't work, ignore if that happen.
                return;
            }
            else
            {
                // Wall sign
                var sign = new WallSign();
                sign.Coordinates = coor;
                sign.Metadata = (byte) face;
                world.SetBlock(sign);
            }

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

            var signBlockEntity = new Sign
            {
                Coordinates = coor
            };

            world.SetBlockEntity(signBlockEntity);
        }
Exemplo n.º 2
0
        public override void UseItem(Level world, Player player, BlockCoordinates blockCoordinates, BlockFace face, Vector3 faceCoords)
        {
            var coor = GetNewCoordinatesFromFace(blockCoordinates, face);
            if (face == BlockFace.Up) // On top of block
            {
                Block skull = new Block(144);
                skull.Coordinates = coor;
                skull.Metadata = 1; // Skull on floor, rotation in block entity
                world.SetBlock(skull);
            }
            else if (face == BlockFace.Down) // At the bottom of block
            {
                // Doesn't work, ignore if that happen.
                return;
            }
            else
            {
                Block skull = new Block(144);
                skull.Coordinates = coor;
                skull.Metadata = (byte) face; // Skull on floor, rotation in block entity
                world.SetBlock(skull);
            }

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

            var skullBlockEntity = new SkullBlockEntity
            {
                Coordinates = coor,
                Rotation = (byte)((int)(Math.Floor(((player.KnownPosition.Yaw)) * 16 / 360) + 0.5) & 0x0f),
                SkullType = (byte) Metadata
            };

            world.SetBlockEntity(skullBlockEntity);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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);
			EnchantingTable table = new EnchantingTable
			{
				Coordinates = coor,
				Metadata = (byte) Metadata
			};

			if (!table.CanPlace(world, face)) return;

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

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

			EnchantingTableBlockEntity tableBlockEntity = new EnchantingTableBlockEntity
			{
				Coordinates = coor
			};

			world.SetBlockEntity(tableBlockEntity);
		}
Exemplo n.º 5
0
        public override bool Interact(Level world, Player player, BlockCoordinates blockCoordinates, BlockFace face, Vector3 faceCoords)
        {
            Item itemInHande = player.Inventory.GetItemInHand();

            ItemFrameBlockEntity blockEntity = world.GetBlockEntity(blockCoordinates) as ItemFrameBlockEntity;
            if (blockEntity != null)
            {
                blockEntity.SetItem(itemInHande);
                world.SetBlockEntity(blockEntity);
            }

            return true;
        }
Exemplo n.º 6
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,
            };

            if (!furnace.CanPlace(world, face)) 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);
        }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
0
        public override void UseItem(Level world, Player player, BlockCoordinates blockCoordinates, BlockFace face, Vector3 faceCoords)
        {
            Log.Warn("Using custom item frame");

            var coor = GetNewCoordinatesFromFace(blockCoordinates, face);

            ItemFrameBlockEntity itemFrameBlockEntity = new ItemFrameBlockEntity
            {
                Coordinates = coor
            };

            CustomItemFrame itemFrame = new CustomItemFrame(_frames, itemFrameBlockEntity, world, _frameTicker)
            {
                Coordinates = coor,
            };

            if (!itemFrame.CanPlace(world, face)) return;

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

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

            world.SetBlockEntity(itemFrameBlockEntity);
        }