Exemple #1
1
        public override void UseItem(Level world, Player player, BlockCoordinates blockCoordinates, BlockFace face, Vector3 faceCoords)
        {
            Log.Warn("Player " + player.Username + " should be banned for hacking!");

            var block = world.GetBlock(blockCoordinates);
            if (block is Tnt)
            {
                world.SetBlock(new Air() {Coordinates = block.Coordinates});
                new PrimedTnt(world)
                {
                    KnownPosition = new PlayerLocation(blockCoordinates.X, blockCoordinates.Y, blockCoordinates.Z),
                    Fuse = (byte) (new Random().Next(0, 20) + 10)
                }.SpawnEntity();
            }
            else if (block.IsSolid)
            {
                var affectedBlock = world.GetBlock(GetNewCoordinatesFromFace(blockCoordinates, BlockFace.Up));
                if (affectedBlock.Id == 0)
                {
                    var fire = new Fire
                    {
                        Coordinates = affectedBlock.Coordinates
                    };
                    world.SetBlock(fire);
                }
            }
        }
		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);
		}
Exemple #3
0
 public override void ItemUsedOnBlock(Coordinates3D coordinates, ItemStack item, BlockFace face, IWorld world, IRemoteClient user)
 {
     coordinates += MathHelper.BlockFaceToCoordinates(face);
     var descriptor = world.GetBlockData(coordinates);
     LadderDirection direction;
     switch (MathHelper.DirectionByRotationFlat(user.Entity.Yaw))
     {
         case Direction.North:
             direction = LadderDirection.North;
             break;
         case Direction.South:
             direction = LadderDirection.South;
             break;
         case Direction.East:
             direction = LadderDirection.East;
             break;
         default:
             direction = LadderDirection.West;
             break;
     }
     descriptor.Metadata = (byte)direction;
     if (IsSupported(descriptor, user.Server, world))
     {
         world.SetBlockID(descriptor.Coordinates, BlockID);
         world.SetMetadata(descriptor.Coordinates, (byte)direction);
         item.Count--;
         user.Inventory[user.SelectedSlot] = item;
     }
 }
Exemple #4
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);
        }
        public override void Place(EntityBase entity, StructBlock block, StructBlock targetBlock, BlockFace targetSide)
        {
            Player player = entity as Player;
            if (player == null)
                return;

            // TODO: Bugged - should depend on the player's Yaw/Pitch
            switch (player.Client.FacingDirection(4))
            {
                case "N":
                    block.MetaData = (byte)MetaData.Stairs.South;
                    break;
                case "E":
                    block.MetaData = (byte)MetaData.Stairs.West;
                    break;
                case "S":
                    block.MetaData = (byte)MetaData.Stairs.North;
                    break;
                case "W":
                    block.MetaData = (byte)MetaData.Stairs.East;
                    break;
                default:
                    return;
            }
            base.Place(entity, block, targetBlock, targetSide);
        }
Exemple #6
0
        public override void ItemUsedOnBlock(Coordinates3D coordinates, ItemStack item, BlockFace face, IWorld world, IRemoteClient user)
        {
            if (face == BlockFace.PositiveY || face == BlockFace.NegativeY)
            {
                // Trapdoors are not placed when the user clicks on the top or bottom of a block
                return;
            }

            // NOTE: These directions are rotated by 90 degrees so that the hinge of the trapdoor is placed
            // where the user had their cursor.
            switch (face)
            {
                case BlockFace.NegativeZ:
                    item.Metadata = (byte)TrapdoorDirection.West;
                    break;
                case BlockFace.PositiveZ:
                    item.Metadata = (byte)TrapdoorDirection.East;
                    break;
                case BlockFace.NegativeX:
                    item.Metadata = (byte)TrapdoorDirection.South;
                    break;
                case BlockFace.PositiveX:
                    item.Metadata = (byte)TrapdoorDirection.North;
                    break;
                default:
                    return;
            }

            base.ItemUsedOnBlock(coordinates, item, face, world, user);
        }
Exemple #7
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);
        }
Exemple #8
0
        public override bool PlaceBlock(Level world, Player player, BlockCoordinates blockCoordinates, BlockFace face, Vector3 faceCoords)
        {
            byte direction = player.GetDirection();

            switch (face)
            {
                case BlockFace.South: // ok
                    Metadata = 0;
                    break;
                case BlockFace.North:
                    Metadata = 1;
                    break;
                case BlockFace.West:
                    Metadata = 2;
                    break;
                case BlockFace.East: // ok
                    Metadata = 3;
                    break;
            }

            Log.Warn($"Direction={direction}, face={face}, metadata={Metadata}");

            world.SetBlock(this);

            return true;
        }
Exemple #9
0
		public override bool PlaceBlock(Level world, Player player, BlockCoordinates blockCoordinates, BlockFace face, Vector3 faceCoords)
		{
			if (face == BlockFace.Down) return true;

			switch (face)
			{
				case BlockFace.Up:
					Metadata = 5;
					break;
				case BlockFace.East:
					Metadata = 4;
					break;
				case BlockFace.West:
					Metadata = 3;
					break;
				case BlockFace.North:
					Metadata = 2;
					break;
				case BlockFace.South:
					Metadata = 1;
					break;
			}

			world.SetBlock(this);
			return true;
		}
Exemple #10
0
 public override void BlockPlaced(BlockDescriptor descriptor, BlockFace face, IWorld world, IRemoteClient user)
 {
     var chunk = world.FindChunk(descriptor.Coordinates);
     user.Server.Scheduler.ScheduleEvent("crops", chunk,
         TimeSpan.FromSeconds(MathHelper.Random.Next(30, 60)),
         (server) => GrowBlock(server, world, descriptor.Coordinates + MathHelper.BlockFaceToCoordinates(face)));
 }
        public override bool Interact(Level currentLevel, Player player, BlockCoordinates blockCoordinates, BlockFace face)
        {
            Sign signEntity = currentLevel.GetBlockEntity(blockCoordinates) as Sign;
            if (signEntity == null) return false;

            string world = signEntity.Text1;

            if (player.Level.LevelId.Equals(world)) return true;

            if (!Worlds.ContainsKey(player.Level.LevelId))
            {
                Worlds.Add(player.Level.LevelId, player.Level);
            }

            if (!Worlds.ContainsKey(world))
            {
                var mobHuntLevel = new MobHuntLevel(world, new FlatlandWorldProvider());
                mobHuntLevel.Initialize();
                Worlds.Add(world, mobHuntLevel);
            }

            Level level = Worlds[world];
            player.SpawnLevel(level);
            level.BroadcastTextMessage(string.Format("{0} teleported to world <{1}>.", player.Username, level.LevelId));

            return true;
        }
Exemple #12
0
 public override void BlockPlaced(BlockDescriptor descriptor, BlockFace face, IWorld world, IRemoteClient user)
 {
     var chunk = world.FindChunk(descriptor.Coordinates);
     user.Server.Scheduler.ScheduleEvent(chunk,
         DateTime.UtcNow.AddSeconds(MathHelper.Random.Next(MinGrowthTime, MaxGrowthTime)),
         s => TrySpread(descriptor.Coordinates, world, user.Server));
 }
Exemple #13
0
        public override void Place(IEntityBase entity, IStructBlock iBlock, IStructBlock targetIBlock, BlockFace face)
        {
            var block = (StructBlock)iBlock;
            var living = entity as LivingEntity;
            if (living == null)
                return;

            // TODO: Bugged - should depend on the player's Yaw/Pitch
            switch (living.FacingDirection(4))
            {
                case "N":
                    block.MetaData = (byte)MetaData.Stairs.South;
                    break;
                case "E":
                    block.MetaData = (byte)MetaData.Stairs.West;
                    break;
                case "S":
                    block.MetaData = (byte)MetaData.Stairs.North;
                    break;
                case "W":
                    block.MetaData = (byte)MetaData.Stairs.East;
                    break;
                default:
                    return;
            }
            base.Place(entity, block, targetIBlock, face);
        }
Exemple #14
0
    /// <summary>
    /// Gets the uvs for face given face.
    /// </summary>
    /// <returns>The uvs for face.</returns>
    /// <param name="face">Face.</param>
    public Vector2[] GetUvsForFace(BlockFace face)
    {
        switch (face)
        {
            case BlockFace.FRONT:
                return this.frontUv;

            case BlockFace.BACK:
                return this.backUv;

            case BlockFace.LEFT:
                return this.leftUv;

            case BlockFace.RIGHT:
                return this.rightUv;

            case BlockFace.TOP:
                return this.topUv;

            case BlockFace.BOTTOM:
                return this.bottomUv;
        }

        return null;
    }
Exemple #15
0
        public override bool PlaceBlock(Level world, Player player, Vector3 blockCoordinates, BlockFace face, Vector3 mouseLocation)
        {
            var rawbits = new BitArray(new byte[] { 0x00 });

            byte direction = player.GetDirection();
            if (face == BlockFace.PositiveY)
            {
                switch (direction)
                {
                    case 0:
                        //South
                        rawbits[1] = true;
                        rawbits[2] = true;
                        break;
                    case 1:
                        //West
                        rawbits[0] = true;
                        rawbits[2] = true;
                        break;
                    case 2:
                        //North
                        rawbits[1] = true;
                        rawbits[2] = true;
                        break;
                    case 3:
                        //East
                        rawbits[0] = true;
                        rawbits[2] = true;
                        break;
                }
            }
            else if (face == BlockFace.NegativeY)
            {
                rawbits[0] = true;
                rawbits[1] = true;
                rawbits[2] = true;
            }
            else if (face == BlockFace.PositiveZ)
            {
                rawbits[0] = true;
                rawbits[1] = true;
            }
            else if (face == BlockFace.NegativeZ)
            {
                rawbits[2] = true;
            }
            else if (face == BlockFace.PositiveX)
            {
                rawbits[0] = true;
            }
            else if (face == BlockFace.NegativeX)
            {
                rawbits[1] = true;
            }

            Metadata = ConvertToByte(rawbits);

            world.SetBlock(this);
            return true;
        }
Exemple #16
0
        protected override bool CanBePlacedOn(EntityBase who, StructBlock block, StructBlock targetBlock, BlockFace targetSide)
        {
            Chunk chunk = GetBlockChunk(block);
            if (chunk == null)
                return false;

            bool isDoubleChestNearby = false;
            int chestCount = 0;
            chunk.ForNSEW(block.Coords, uc =>
            {
                byte? nearbyBlockId = block.World.GetBlockId(uc);

                if (nearbyBlockId == null)
                    return;

                // Cannot place next to a double chest
                if (nearbyBlockId == (byte)BlockData.Blocks.Chest)
                {
                    chestCount++;
                     if (chunk.IsNSEWTo(uc, (byte)BlockData.Blocks.Chest))
                        isDoubleChestNearby = true;
                }
            });

            if (isDoubleChestNearby || chestCount > 1)
                return false;
            return base.CanBePlacedOn(who, block, targetBlock, targetSide);
        }
        public override void Place(EntityBase entity, StructBlock block, StructBlock targetBlock, BlockFace face)
        {
            Player player = (entity as Player);
            if (player == null)
                return;
            if (face == BlockFace.Down)
                return;

            switch (face)
            {
                case BlockFace.Down: return;
                case BlockFace.Up: block.MetaData = (byte)MetaData.Torch.Standing;
                    break;
                case BlockFace.West: block.MetaData = (byte)MetaData.Torch.West;
                    break;
                case BlockFace.East: block.MetaData = (byte)MetaData.Torch.East;
                    break;
                case BlockFace.North: block.MetaData = (byte)MetaData.Torch.North;
                    break;
                case BlockFace.South: block.MetaData = (byte)MetaData.Torch.South;
                    break;
            }

            base.Place(entity, block, targetBlock, face);
        }
Exemple #18
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);
        }
Exemple #19
0
        public override void UseItem(Level world, Player player, BlockCoordinates targetCoordinates, 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();
            //	}
            //}

            _block.Coordinates = GetNewCoordinatesFromFace(targetCoordinates, face);
            _block.Metadata = (byte) Metadata;

            if ((player.GetBoundingBox() - 0.01f).Intersects(_block.GetBoundingBox()))
            {
                Log.Debug("Can't build where you are standing: " + _block.GetBoundingBox());
                return;
            }
            if (!_block.CanPlace(world, face)) return;

            if (_block.PlaceBlock(world, player, targetCoordinates, face, faceCoords)) return; // Handled

            world.SetBlock(_block);
        }
Exemple #20
0
        protected override bool CanBePlacedOn(EntityBase who, StructBlock block, StructBlock targetBlock, BlockFace targetSide)
        {
            if (targetBlock.Type == (byte)BlockData.Blocks.Reed && targetSide == BlockFace.Up)
                return true;

            if ((targetBlock.Type != (byte)BlockData.Blocks.Sand &&
                targetBlock.Type != (byte)BlockData.Blocks.Dirt &&
                targetBlock.Type != (byte)BlockData.Blocks.Grass &&
                targetBlock.Type != (byte)BlockData.Blocks.Soil) || targetSide != BlockFace.Up)
                return false;

            bool isWater = false;

            var chunk = GetBlockChunk(block);

            if (chunk == null)
                return false;

            chunk.ForNSEW(targetBlock.Coords,
                delegate(UniversalCoords uc)
                {
                    byte? blockId = block.World.GetBlockId(uc);
                    if (blockId != null && (blockId == (byte)BlockData.Blocks.Water || blockId == (byte)BlockData.Blocks.Still_Water))
                        isWater = true;
                });

            if (!isWater)
                return false;

            return base.CanBePlacedOn(who, block, targetBlock, targetSide);
        }
Exemple #21
0
        private void ItemUsedOnBlock(World world, Coordinates3D coordinates, BlockFace face, Coordinates3D cursor, ItemInfo item)
        {
            var info = world.GetBlockInfo(coordinates);
            if (Block.GetIsSolidOnFace(info, face) == false)
                return;
            
            coordinates += MathHelper.BlockFaceToCoordinates(face);

            switch (face)
            {
                case BlockFace.NegativeZ:
                    world.SetBlockId(coordinates, item.ItemId);
                    world.SetMetadata(coordinates, (byte)Orientation.FacingNorth);
                    break;
                case BlockFace.PositiveZ:
                    world.SetBlockId(coordinates, item.ItemId);
                    world.SetMetadata(coordinates, (byte)Orientation.FacingSouth);
                    break;
                case BlockFace.NegativeX:
                    world.SetBlockId(coordinates, item.ItemId);
                    world.SetMetadata(coordinates, (byte)Orientation.FacingWest);
                    break;
                case BlockFace.PositiveX:
                    world.SetBlockId(coordinates, item.ItemId);
                    world.SetMetadata(coordinates, (byte)Orientation.FacingEast);
                    break;
                default:
                    // Ladders can't be placed lying flat.
                    break;
            }
        }
Exemple #22
0
 public override void ItemUsedOnBlock(Coordinates3D coordinates, ItemStack item, BlockFace face, IWorld world, IRemoteClient user)
 {
     var bottom = coordinates + MathHelper.BlockFaceToCoordinates(face);
     var top = bottom + Coordinates3D.Up;
     if (world.GetBlockID(top) != 0 || world.GetBlockID(bottom) != 0)
         return;
     DoorFlags direction;
     switch (MathHelper.DirectionByRotationFlat(user.Entity.Yaw))
     {
         case Direction.North:
             direction = DoorFlags.Northwest;
             break;
         case Direction.South:
             direction = DoorFlags.Southeast;
             break;
         case Direction.East:
             direction = DoorFlags.Northeast;
             break;
         default: // Direction.West:
             direction = DoorFlags.Southwest;
             break;
     }
     user.Server.BlockUpdatesEnabled = false;
     world.SetBlockID(bottom, BlockID);
     world.SetMetadata(bottom, (byte)direction);
     world.SetBlockID(top, BlockID);
     world.SetMetadata(top, (byte)(direction | DoorFlags.Upper));
     user.Server.BlockUpdatesEnabled = true;
     item.Count--;
     user.Inventory[user.SelectedSlot] = item;
 }
Exemple #23
0
 public override void Place(IEntityBase entity, IStructBlock iBlock, IStructBlock targetIBlock, BlockFace face)
 {
     StructBlock block = (StructBlock)iBlock;
     LivingEntity living = entity as LivingEntity;
     if (living == null)
         return;
     switch (living.FacingDirection(4))
     {
         case "N":
             block.MetaData = (byte)MetaData.Door.Northwest;
             break;
         case "W":
             block.MetaData = (byte)MetaData.Door.Southwest;
             break;
         case "S":
             block.MetaData = (byte)MetaData.Door.Southeast;
             break;
         case "E":
             block.MetaData = (byte)MetaData.Door.Northeast;
             break;
         default:
             return;
     }
     base.Place(entity, block, targetIBlock, face);
 }
Exemple #24
0
		public override bool PlaceBlock(Level world, Player player, BlockCoordinates blockCoordinates, BlockFace face, Vector3 faceCoords)
		{
			Metadata = (byte) face;

			world.SetBlock(this);
			return true;
		}
Exemple #25
0
		public override bool Interact(Level world, Player player, BlockCoordinates blockCoordinates, BlockFace face)
		{
			Metadata = (byte) (Metadata | (0x8));
			world.SetBlock(this);
			world.ScheduleBlockTick(this, TickRate);
			return true;
		}
Exemple #26
0
 public override bool PlaceBlock(Level world, Player player, Vector3 blockCoordinates, BlockFace face, Vector3 mouseLocation)
 {
     var prevblock = world.GetBlock(Coordinates);
     if (prevblock.Id == Id && prevblock.Metadata == Metadata)
     {
         DoubleSlab ds = new DoubleSlab(Metadata) {Coordinates = Coordinates};
         world.SetBlock(ds);
     }
     else if (prevblock.Id == Id && prevblock.Metadata != Metadata)
     {
         if (player.Gamemode != Gamemode.Creative)
         {
             player.Inventory.AddItem((short)Id, Metadata, 1);
         }
         return true;
     }
     else
     {
         bool upper = ((mouseLocation.Y >= 8 && face != BlockFace.PositiveY) || face == BlockFace.NegativeY);
         BitArray b = new BitArray(new byte[] {Metadata});
         b[3] = upper;
         Metadata = ConvertToByte(b);
         world.SetBlock(this);
     }
     return true;
 }
Exemple #27
0
        public override void Place(EntityBase entity, StructBlock block, StructBlock targetBlock, BlockFace face)
        {
            // Load the blocks surrounding the position (NSEW) not diagonals
            BlockData.Blocks[] nsewBlocks = new BlockData.Blocks[4];
            UniversalCoords[] nsewBlockPositions = new UniversalCoords[4];
            int nsewCount = 0;
            block.Chunk.ForNSEW(block.Coords, (uc) =>
            {
                nsewBlocks[nsewCount] = (BlockData.Blocks)block.World.GetBlockId(uc);
                nsewBlockPositions[nsewCount] = uc;
                nsewCount++;
            });

            // Count chests in list
            if (nsewBlocks.Where((b) => b == BlockData.Blocks.Chest).Count() > 1)
            {
                // Cannot place next to two chests
                return;
            }

            for (int i = 0; i < 4; i++)
            {
                UniversalCoords p = nsewBlockPositions[i];
                if (nsewBlocks[i] == BlockData.Blocks.Chest && block.Chunk.IsNSEWTo(p, (byte)BlockData.Blocks.Chest))
                {
                    // Cannot place next to a double chest
                    return;
                }
            }
            base.Place(entity, block, targetBlock, face);
        }
Exemple #28
0
        // 000 001 010 011 100
        public override bool PlaceBlock(Level world, Player player, BlockCoordinates blockCoordinates, BlockFace face, Vector3 faceCoords)
        {
            byte direction = player.GetDirection();

            byte upper = (byte) ((faceCoords.Y > 0.5 && face != BlockFace.Up) || face == BlockFace.Down ? 0x04 : 0x00);

            switch (direction)
            {
                case 0:
                    Metadata = (byte) (0 | upper);
                    break;
                case 1:
                    Metadata = (byte) (2 | upper);
                    break;
                case 2:
                    Metadata = (byte) (1 | upper);
                    break;
                case 3:
                    Metadata = (byte) (3 | upper);
                    break;
            }

            world.SetBlock(this);
            return true;
        }
Exemple #29
0
 public override void UseItem(Level world, Player player, Vector3 blockCoordinates, BlockFace face)
 {
     blockCoordinates = GetNewCoordinatesFromFace(blockCoordinates, face);
     var d = new BlockRedstoneDust {Coordinates = blockCoordinates};
     //d.SetPowerLevel(new Random().Next(0,15));
     world.SetBlock(d, true, true);
 }
Exemple #30
0
        public override void UseItem(Level world, Player player, Vector3 blockCoordinates, BlockFace face)
        {
            blockCoordinates = GetNewCoordinatesFromFace(blockCoordinates, face);
            var bl = world.GetBlock(blockCoordinates);

            var slot = 0;
            var hand0 = player.Inventory.GetItemInHand(0);
            var hand1 = player.Inventory.GetItemInHand(1);
            if (hand0.Id == Id)
            {
                slot = player.Inventory.CurrentSlot + 36;
            }
            else if (hand1.Id == Id)
            {
                slot = 45;
            }

            //player.SendChat("Block: " + bl.Id, ChatColor.Bold);
            if (bl.Id == 65535) return;

            if (bl.Id == 8)
            {
                //Water
                player.Inventory.SetSlot(slot, 326, 0, 1);
                world.SetBlock(new BlockAir() {Coordinates = blockCoordinates}, true, true);
            }

            if (bl.Id == 10)
            {
                //lava
                player.Inventory.SetSlot(slot, 327, 0, 1);
                world.SetBlock(new BlockAir() { Coordinates = blockCoordinates }, true, true);
            }
        }
Exemple #31
0
 protected virtual bool CanPlace(Level world, BlockCoordinates blockCoordinates, BlockCoordinates targetCoordinates, BlockFace face)
 {
     return(world.GetBlock(blockCoordinates).IsReplacible);
 }
Exemple #32
0
        public override void BuildMesh(
            Map map, RenderGeometryBatcher batcher, int offsetX, int offsetY, int offsetZ,
            int minX, int maxX, int minY, int maxY, int minZ, int maxZ, int lod,
            LocalPools pools
            )
        {
            BlockFace face = 0;

            int stepSize = 1 << lod;

            Assert.IsTrue(lod <= EngineSettings.ChunkConfig.LogSize); // LOD can't be bigger than chunk size
            int width = EngineSettings.ChunkConfig.Size >> lod;

            int[] mins  = { minX >> lod, minY >> lod, minZ >> lod };
            int[] maxes = { maxX >> lod, maxY >> lod, maxZ >> lod };

            int[] x  = { 0, 0, 0 };                                                    // Relative position of a block
            int[] xx = { 0, 0, 0 };                                                    // Relative position of a block after applying lod
            int[] q  = { 0, 0, 0 };                                                    // Direction in which we compare neighbors when building mask (q[d] is our current direction)
            int[] du = { 0, 0, 0 };                                                    // Width in a given dimension (du[u] is our current dimension)
            int[] dv = { 0, 0, 0 };                                                    // Height in a given dimension (dv[v] is our current dimension)
            int[] s  = { map.VoxelLogScaleX, map.VoxelLogScaleY, map.VoxelLogScaleZ }; // Scale in each dimension

            BlockData[] mask = pools.PopBlockDataArray(width * width);
            Vector3[]   vecs = pools.PopVector3Array(4);

            // Iterate over 3 dimensions. Once for front faces, once for back faces
            for (int dd = 0; dd < 2 * 3; dd++)
            {
                int d = dd % 3;
                int u = (d + 1) % 3;
                int v = (d + 2) % 3;

                x[0] = 0;
                x[1] = 0;
                x[2] = 0;

                q[0] = 0;
                q[1] = 0;
                q[2] = 0;
                q[d] = stepSize << s[d];

                // Determine which side we're meshing
                bool backFace = dd < 3;
                switch (dd)
                {
                case 0: face = BlockFace.Left; break;

                case 3: face = BlockFace.Right; break;

                case 1: face = BlockFace.Bottom; break;

                case 4: face = BlockFace.Top; break;

                case 2: face = BlockFace.Back; break;

                case 5: face = BlockFace.Front; break;
                }

                // Move through the dimension from front to back
                for (x[d] = mins[d] - 1; x[d] <= maxes[d];)
                {
                    // Compute the mask
                    int n = 0;

                    for (x[v] = 0; x[v] < mins[v]; x[v]++)
                    {
                        for (x[u] = 0; x[u] < width; x[u]++)
                        {
                            mask[n++] = BlockData.Air;
                        }
                    }

                    for (x[v] = mins[v]; x[v] <= maxes[v]; x[v]++)
                    {
                        for (x[u] = 0; x[u] < mins[u]; x[u]++)
                        {
                            mask[n++] = BlockData.Air;
                        }

                        for (x[u] = mins[u]; x[u] <= maxes[u]; x[u]++)
                        {
                            int realX = (x[0] << lod << s[0]) + offsetX;
                            int realY = (x[1] << lod << s[1]) + offsetY;
                            int realZ = (x[2] << lod << s[2]) + offsetZ;

                            BlockData voxelFace0 = map.GetBlock(realX, realY, realZ);
                            BlockData voxelFace1 = map.GetBlock(realX + q[0], realY + q[1], realZ + q[2]);

                            mask[n++] = (voxelFace0.IsSolid() && voxelFace1.IsSolid())
                                            ? BlockData.Air
                                            : (backFace ? voxelFace1 : voxelFace0);
                        }

                        for (x[u] = maxes[u] + 1; x[u] < width; x[u]++)
                        {
                            mask[n++] = BlockData.Air;
                        }
                    }

                    for (x[v] = maxes[v] + 1; x[v] < width; x[v]++)
                    {
                        for (x[u] = 0; x[u] < width; x[u]++)
                        {
                            mask[n++] = BlockData.Air;
                        }
                    }

                    x[d]++;
                    n = 0;

                    // Build faces from the mask if it's possible
                    int j;
                    for (j = 0; j < width; j++)
                    {
                        int i;
                        for (i = 0; i < width;)
                        {
                            if (mask[n].IsEmpty())
                            {
                                i++;
                                n++;
                                continue;
                            }

                            BlockType type = mask[n].BlockType;

                            // Compute width
                            int w;
                            for (w = 1; i + w < width && mask[n + w].BlockType == type; w++)
                            {
                            }

                            // Compute height
                            bool done = false;
                            int  k;
                            int  h;
                            for (h = 1; j + h < width; h++)
                            {
                                for (k = 0; k < w; k++)
                                {
                                    if (
                                        mask[n + k + h * width].IsEmpty() ||
                                        mask[n + k + h * width].BlockType != type
                                        )
                                    {
                                        done = true;
                                        break;
                                    }
                                }

                                if (done)
                                {
                                    break;
                                }
                            }

                            // Determine whether we really want to build this face
                            // TODO: Skip bottom faces at the bottom of the world
                            bool buildFace = true;
                            if (buildFace)
                            {
                                // Prepare face coordinates and dimensions
                                x[u] = i;
                                x[v] = j;

                                xx[0] = ((x[0] << lod) << s[0]) + offsetX;
                                xx[1] = ((x[1] << lod) << s[1]) + offsetY;
                                xx[2] = ((x[2] << lod) << s[2]) + offsetZ;

                                du[0] = du[1] = du[2] = 0;
                                dv[0] = dv[1] = dv[2] = 0;
                                du[u] = (w << lod) << s[u];
                                dv[v] = (h << lod) << s[v];

                                // Face vertices
                                Vector3Int v1 = new Vector3Int(
                                    xx[0], xx[1], xx[2]
                                    );
                                Vector3Int v2 = new Vector3Int(
                                    xx[0] + du[0], xx[1] + du[1], xx[2] + du[2]
                                    );
                                Vector3Int v3 = new Vector3Int(
                                    xx[0] + du[0] + dv[0], xx[1] + du[1] + dv[1], xx[2] + du[2] + dv[2]
                                    );
                                Vector3Int v4 = new Vector3Int(
                                    xx[0] + dv[0], xx[1] + dv[1], xx[2] + dv[2]
                                    );

                                // Face vertices transformed to world coordinates
                                // 0--1
                                // |  |
                                // |  |
                                // 3--2
                                vecs[0] = new Vector3(v4.X, v4.Y, v4.Z);
                                vecs[1] = new Vector3(v3.X, v3.Y, v3.Z);
                                vecs[2] = new Vector3(v2.X, v2.Y, v2.Z);
                                vecs[3] = new Vector3(v1.X, v1.Y, v1.Z);

                                // Build the face
                                IFaceBuilder builder = BlockDatabase.GetFaceBuilder(type);
                                builder.Build(batcher, ref mask[n], face, backFace, ref vecs, pools);
                            }

                            // Zero out the mask
                            int l;
                            for (l = 0; l < h; ++l)
                            {
                                for (k = 0; k < w; ++k)
                                {
                                    mask[n + k + l * width] = BlockData.Air;
                                }
                            }

                            i += w;
                            n += w;
                        }
                    }
                }
            }

            pools.PushBlockDataArray(mask);
            pools.PushVector3Array(vecs);
        }
 public override int GetTextureIndex(BlockFace face)
 {
     return(_staticData.GetTextureIndex(face));
 }
        public byte GetAuxForPlacement(Vector3 viewDirection, GlobalPoint3D swingTarget, BlockFace swingFace, int facePos, Block blockID)
        {
            switch (blockID)
            {
            case Blocks.TrainTrackStraight:
                return((byte)(Math.Abs(viewDirection.X) > Math.Abs(viewDirection.Z) ? 0 : 1));

            case Blocks.TrainTrackCorner:
                return((byte)(facePos & 0x3));

            default:
                return(0);
            }
        }
Exemple #35
0
        //public double GetMineTime(Item miningTool)
        //{
        //	int multiplier = (int) miningTool.ItemMaterial;
        //	return Hardness*(1.5*multiplier);
        //}

        protected BlockCoordinates GetNewCoordinatesFromFace(BlockCoordinates target, BlockFace face)
        {
            switch (face)
            {
            case BlockFace.Down:
                return(target + Level.Down);

            case BlockFace.Up:
                return(target + Level.Up);

            case BlockFace.East:
                return(target + Level.East);

            case BlockFace.West:
                return(target + Level.West);

            case BlockFace.North:
                return(target + Level.North);

            case BlockFace.South:
                return(target + Level.South);

            default:
                return(target);
            }
        }
Exemple #36
0
 public virtual bool Interact(Level world, Player player, BlockCoordinates blockCoordinates, BlockFace face, Vector3 faceCoord)
 {
     // No default interaction. Return unhandled.
     return(false);
 }
Exemple #37
0
 public virtual bool PlaceBlock(Level world, Player player, BlockCoordinates targetCoordinates, BlockFace face, Vector3 faceCoords)
 {
     // No default placement. Return unhandled.
     return(false);
 }
Exemple #38
0
 public override void BlockLeftClicked(BlockDescriptor descriptor, BlockFace face, IWorld world, IRemoteClient user)
 {
     BlockRightClicked(descriptor, face, world, user);
 }
Exemple #39
0
        private static Vector3 CalculateBrightness(WorldServer world, Block block, Vector3i blockPos, BlockFace face, Vector3 vertexPosition)
        {
            //if its not a full opaque block return brightness of itself
            if (!block.IsOpaqueFullBlock(world, blockPos) || !block.Model.AmbientOcclusion)
            {
                return(LightLevelToBrightness(world.GetBlockLightLevel(blockPos).Vector3));
            }

            //TODO: smooth lighting setting
            //return LightLevelToBrightness(world.GetBlockLightLevel(blockPos + face.GetNormali()));

            var normal = face.GetNormali();
            var pos    = blockPos + normal;
            var offset = (vertexPosition * 2).ToVector3i();

            if ((offset - normal * normal).LengthSquared != 2)
            {
                //If vertex is not a corner do not apply ambient occlusion but apply the blocks own brightness
                return(LightLevelToBrightness(world.GetBlockLightLevel(blockPos).Vector3));
            }

            if (normal.X != 0)
            {
                return(GetSmoothLightValue(world, pos, pos + new Vector3i(0, offset.Y, 0),
                                           pos + new Vector3i(0, 0, offset.Z), pos + new Vector3i(0, offset.Y, offset.Z)));
            }
            if (normal.Y != 0)
            {
                return(GetSmoothLightValue(world, pos, pos + new Vector3i(offset.X, 0, 0),
                                           pos + new Vector3i(0, 0, offset.Z), pos + new Vector3i(offset.X, 0, offset.Z)));
            }
            if (normal.Z != 0)
            {
                return(GetSmoothLightValue(world, pos, pos + new Vector3i(offset.X, 0, 0),
                                           pos + new Vector3i(0, offset.Y, 0), pos + new Vector3i(offset.X, offset.Y, 0)));
            }

            throw new Exception("Something is really broken if you can read this :S");
        }
Exemple #40
0
 public bool CanPlace(Level world, BlockCoordinates targetCoordinates, BlockFace face)
 {
     return(CanPlace(world, Coordinates, targetCoordinates, face));
 }
Exemple #41
0
        public override bool PlaceBlock(Level world, Player player, BlockCoordinates targetCoordinates, BlockFace face, Vector3 faceCoords)
        {
            // metadata for banner is a value 0-15 that signify the orientation of the banner. Same as PC metadata.
            GroundSignDirection = (byte)((int)(Math.Floor((player.KnownPosition.Yaw + 180) * 16 / 360) + 0.5) & 0x0f);

            var bannerBlockEntity = new BannerBlockEntity
            {
                Coordinates = Coordinates,
                Base        = Base,
            };

            bannerBlockEntity.SetCompound(ExtraData);
            world.SetBlockEntity(bannerBlockEntity);

            return(false);
        }
Exemple #42
0
        public static void AddFaceToVao(WorldServer world, Vector3i blockPos, int x, int y, int z, Block block, BlockFace face, BlockModel.FaceData data, VertexArrayObject vao, Matrix4 transform)
        {
            var faceId        = (int)face - 1;
            var indicesOffset = vao.VertexCount;

            //var transform = Matrix4.CreateScale()//Matrix4.Identity;//block.GetTransform(world, blockPos, face);
            var texture = data.LoadedTexture;    //block.GetTexture(world, blockPos, face);
            //var overlayTexture = block.GetOverlayTexture(world, blockPos, face);
            var texCoords = data.GetTexCoords(); //block.GetTexCoords(world, blockPos, face) ?? FaceTexCoords;
            //var overlayTexCoords = block.GetOverlayTexCoords(world, blockPos, face) ?? FaceTexCoords;
            var color  = data.TintIndex == -1 ? new Vector4(1) : block.GetTintColor(world, blockPos, data.TintIndex).ToVector4();
            var normal = face.GetNormal();

            if (texCoords.Length != 4)
            {
                throw new Exception($"\"{block}\" invalid texture coords array length!");
            }


            var vPositions        = new Vector3[4];
            var vTexCoords        = new Vector4[4];
            var vOverlayTexCoords = new Vector4[4]; //TODO: Remove
            var vBrightness       = new Vector3[4];

            for (var j = 0; j < 4; j++)
            {
                var vertexPosition = FacePositions[faceId * 4 + j];
                var position       = (new Vector4(vertexPosition, 1) * transform).Xyz + new Vector3(x, y, z);

                //tex coords are -1 if texture is null
                var texCoord = texture == null ? new Vector4(-1) : new Vector4(texCoords[j])
                {
                    //texCoord z = texId, w = textureArrayId
                    Z = texture.TextureId,
                    W = texture.ArrayId
                };



                //per vertex light value interpolation (smooth lighting + free ambient occlusion)
                var brightness = CalculateBrightness(world, block, blockPos, face, vertexPosition);

                //TODO: transform normals

                vPositions[j]        = position;
                vTexCoords[j]        = texCoord;
                vOverlayTexCoords[j] = new Vector4(-1);
                vBrightness[j]       = brightness;
            }

            //Flip faces to fix ambient occlusion anisotrophy
            //https://0fps.net/2013/07/03/ambient-occlusion-for-minecraft-like-worlds/

            for (var j = 0; j < 4; j++)
            {
                vao.Add(vPositions[j], vTexCoords[j], new Vector4(normal), color.Xyz, vBrightness[j]);
            }

            var newIndices = new uint[FaceIndices.Length];

            if ((vBrightness[0] + vBrightness[3]).LengthSquared > (vBrightness[1] + vBrightness[2]).LengthSquared)
            {
                for (var j = 0; j < newIndices.Length; j++)
                {
                    newIndices[j] = (uint)(FlippedFaceIndices[j] + indicesOffset);
                }
            }
            else
            {
                for (var j = 0; j < newIndices.Length; j++)
                {
                    newIndices[j] = (uint)(FaceIndices[j] + indicesOffset);
                }
            }

            //Calculate face middle for transparency sorting
            var faceMiddle = Vector3.Zero;

            if (vao is SortedVertexArrayObject)
            {
                faceMiddle = vPositions.Aggregate(faceMiddle, (current, pos) => current + pos);
                faceMiddle = faceMiddle / vPositions.Length + blockPos.ToVector3() - new Vector3(x, y, z);
            }

            vao.AddFace(newIndices, faceMiddle);
        }
Exemple #43
0
        public override void UseItem(Level world, Player player, BlockCoordinates blockCoordinates, BlockFace face, Vector3 faceCoords)
        {
            byte direction = player.GetDirection();

            var coordinates = GetNewCoordinatesFromFace(blockCoordinates, face);

            // Base block, meta sets orientation

            Bed block = new Bed
            {
                Coordinates = coordinates
            };

            switch (direction)
            {
            case 1:
                block.Metadata = 0;
                break;                         // West

            case 2:
                block.Metadata = 1;
                break;                         // North

            case 3:
                block.Metadata = 2;
                break;                         // East

            case 0:
                block.Metadata = 3;
                break;                         // South
            }

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

            BlockFace lowerFace = BlockFace.None;

            switch (block.Metadata)
            {
            case 0:
                lowerFace = (BlockFace)3;
                break;                         // West

            case 1:
                lowerFace = (BlockFace)4;
                break;                         // North

            case 2:
                lowerFace = (BlockFace)2;
                break;                         // East

            case 3:
                lowerFace = (BlockFace)5;
                break;                         // South
            }

            Bed blockUpper = new Bed
            {
                Coordinates = GetNewCoordinatesFromFace(coordinates, lowerFace),
                Metadata    = (byte)(block.Metadata | 0x08)
            };

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

            //TODO: Check down from both blocks, must be solids

            world.SetBlock(block);
            world.SetBlock(blockUpper);
        }
Exemple #44
0
        public override bool Interact(Level level, Player player, BlockCoordinates blockCoordinates, BlockFace face, Vector3 faceCoord)
        {
            var itemInHand = player.Inventory.GetItemInHand();

            if (Metadata < MaxGrowth && itemInHand is ItemDye && itemInHand.Metadata == 15 && new Random().NextDouble() > 0.25)
            {
                Metadata++;
                level.SetBlock(this);

                return(true);
            }

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

            switch (face)
            {
            case BlockFace.South:                     // ok
                Metadata = 0;
                break;

            case BlockFace.North:
                Metadata = 1;
                break;

            case BlockFace.West:
                Metadata = 2;
                break;

            case BlockFace.East:                     // ok
                Metadata = 3;
                break;
            }

            Log.Warn($"Direction={direction}, face={face}, metadata={Metadata}");

            world.SetBlock(this);

            return(true);
        }
Exemple #46
0
        public override void ItemUsedOnBlock(Coordinates3D coordinates, ItemStack item, BlockFace face, IWorld world,
                                             IRemoteClient user)
        {
            coordinates += MathHelper.BlockFaceToCoordinates(face);
            var old = world.GetBlockData(coordinates);

            byte[] overwritable =
            {
                AirBlock.BlockId,
                WaterBlock.BlockId,
                StationaryWaterBlock.BlockId,
                LavaBlock.BlockId,
                StationaryLavaBlock.BlockId
            };
            if (overwritable.Any(b => b == old.Id))
            {
                var data = world.GetBlockData(coordinates);
                data.Id       = Id;
                data.Metadata = (byte)item.Metadata;

                BlockPlaced(data, face, world, user);

                if (!IsSupported(world.GetBlockData(coordinates), user.Server, world))
                {
                    world.SetBlockData(coordinates, old);
                }
                else
                {
                    item.Count--;
                    user.Inventory[user.SelectedSlot] = item;
                }
            }
        }
Exemple #47
0
        public override bool PlaceBlock(Level world, Player player, BlockCoordinates blockCoordinates, BlockFace face, Vector3 faceCoords)
        {
            Direction = player.GetOppositeDirection();

            return(false);
        }
Exemple #48
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);
        }
 protected override string GetTextureName(BlockFace face)
 {
     return("log_oak");
 }
Exemple #50
0
        public override bool Interact(Level world, Player player, BlockCoordinates blockCoordinates, BlockFace face, Vector3 faceCoord)
        {
            var containerOpen = McpeContainerOpen.CreateObject();

            containerOpen.windowId        = 24;
            containerOpen.type            = 24;
            containerOpen.coordinates     = blockCoordinates;
            containerOpen.runtimeEntityId = EntityManager.EntityIdSelf;
            player.SendPacket(containerOpen);

            return(true);
        }
Exemple #51
0
        /// <summary>
        /// Returns the distance along the ray where it intersects the specified bounding box, if it intersects at all.
        /// </summary>
        public double?Intersects(BoundingBox box, out BlockFace face)
        {
            face = BlockFace.PositiveY;
            //first test if start in box
            if (Position.X >= box.Min.X &&
                Position.X <= box.Max.X &&
                Position.Y >= box.Min.Y &&
                Position.Y <= box.Max.Y &&
                Position.Z >= box.Min.Z &&
                Position.Z <= box.Max.Z)
            {
                return(0.0f);// here we concidere cube is full and origine is in cube so intersect at origine
            }
            //Second we check each face
            Vector3 maxT = new Vector3(-1.0f);

            //Vector3 minT = new Vector3(-1.0f);
            //calcul intersection with each faces
            if (Direction.X != 0.0f)
            {
                if (Position.X < box.Min.X)
                {
                    maxT.X = (box.Min.X - Position.X) / Direction.X;
                }
                else if (Position.X > box.Max.X)
                {
                    maxT.X = (box.Max.X - Position.X) / Direction.X;
                }
            }

            if (Direction.Y != 0.0f)
            {
                if (Position.Y < box.Min.Y)
                {
                    maxT.Y = (box.Min.Y - Position.Y) / Direction.Y;
                }
                else if (Position.Y > box.Max.Y)
                {
                    maxT.Y = (box.Max.Y - Position.Y) / Direction.Y;
                }
            }

            if (Direction.Z != 0.0f)
            {
                if (Position.Z < box.Min.Z)
                {
                    maxT.Z = (box.Min.Z - Position.Z) / Direction.Z;
                }
                else if (Position.Z > box.Max.Z)
                {
                    maxT.Z = (box.Max.Z - Position.Z) / Direction.Z;
                }
            }

            //get the maximum maxT
            if (maxT.X > maxT.Y && maxT.X > maxT.Z)
            {
                if (maxT.X < 0.0f)
                {
                    return(null);// ray go on opposite of face
                }
                //coordonate of hit point of face of cube
                double coord = Position.Z + maxT.X * Direction.Z;
                // if hit point coord ( intersect face with ray) is out of other plane coord it miss
                if (coord < box.Min.Z || coord > box.Max.Z)
                {
                    return(null);
                }
                coord = Position.Y + maxT.X * Direction.Y;
                if (coord < box.Min.Y || coord > box.Max.Y)
                {
                    return(null);
                }

                if (Position.X < box.Min.X)
                {
                    face = BlockFace.NegativeX;
                }
                else if (Position.X > box.Max.X)
                {
                    face = BlockFace.PositiveX;
                }

                return(maxT.X);
            }
            if (maxT.Y > maxT.X && maxT.Y > maxT.Z)
            {
                if (maxT.Y < 0.0f)
                {
                    return(null);// ray go on opposite of face
                }
                //coordonate of hit point of face of cube
                double coord = Position.Z + maxT.Y * Direction.Z;
                // if hit point coord ( intersect face with ray) is out of other plane coord it miss
                if (coord < box.Min.Z || coord > box.Max.Z)
                {
                    return(null);
                }
                coord = Position.X + maxT.Y * Direction.X;
                if (coord < box.Min.X || coord > box.Max.X)
                {
                    return(null);
                }

                if (Position.Y < box.Min.Y)
                {
                    face = BlockFace.NegativeY;
                }
                else if (Position.Y > box.Max.Y)
                {
                    face = BlockFace.PositiveY;
                }

                return(maxT.Y);
            }
            else //Z
            {
                if (maxT.Z < 0.0f)
                {
                    return(null);// ray go on opposite of face
                }
                //coordonate of hit point of face of cube
                double coord = Position.X + maxT.Z * Direction.X;
                // if hit point coord ( intersect face with ray) is out of other plane coord it miss
                if (coord < box.Min.X || coord > box.Max.X)
                {
                    return(null);
                }
                coord = Position.Y + maxT.Z * Direction.Y;
                if (coord < box.Min.Y || coord > box.Max.Y)
                {
                    return(null);
                }

                if (Position.Z < box.Min.Z)
                {
                    face = BlockFace.NegativeZ;
                }
                else if (Position.Z > box.Max.Z)
                {
                    face = BlockFace.PositiveZ;
                }

                return(maxT.Z);
            }
        }
Exemple #52
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);
        }
Exemple #53
0
        public override void UseItem(Level world, Player player, BlockCoordinates blockCoordinates, BlockFace face, Vector3 faceCoords)
        {
            var coordinates = GetNewCoordinatesFromFace(blockCoordinates, face);

            Mob mob = null;

            EntityType type = (EntityType)Metadata;

            switch (type)
            {
            case EntityType.Chicken:
                mob = new Chicken(world);
                break;

            case EntityType.Cow:
                mob = new Cow(world);
                break;

            case EntityType.Pig:
                mob = new Pig(world);
                break;

            case EntityType.Sheep:
                mob = new Sheep(world);
                break;

            case EntityType.Wolf:
                mob = new Wolf(world);
                break;

            case EntityType.Npc:
                mob = new Villager(world);
                break;

            case EntityType.MushroomCow:
                mob = new MushroomCow(world);
                break;

            case EntityType.Squid:
                mob = new Squid(world);
                break;

            case EntityType.Rabbit:
                mob = new Rabbit(world);
                break;

            case EntityType.Bat:
                mob = new Bat(world);
                break;

            case EntityType.IronGolem:
                mob = new IronGolem(world);
                break;

            case EntityType.SnowGolem:
                mob = new SnowGolem(world);
                break;

            case EntityType.Ocelot:
                mob = new Ocelot(world);
                break;

            case EntityType.Zombie:
                mob = new Zombie(world);
                break;

            case EntityType.Creeper:
                mob = new Creeper(world);
                break;

            case EntityType.Skeleton:
                mob = new Skeleton(world);
                break;

            case EntityType.Spider:
                mob = new Spider(world);
                break;

            case EntityType.ZombiePigman:
                mob = new ZombiePigman(world);
                break;

            case EntityType.Slime:
                mob = new Slime(world);
                break;

            case EntityType.Enderman:
                mob = new Enderman(world);
                break;

            case EntityType.Silverfish:
                mob = new Silverfish(world);
                break;

            case EntityType.CaveSpider:
                mob = new CaveSpider(world);
                break;

            case EntityType.Ghast:
                mob = new Ghast(world);
                break;

            case EntityType.MagmaCube:
                mob = new MagmaCube(world);
                break;

            case EntityType.Blaze:
                mob = new Blaze(world);
                break;

            case EntityType.ZombieVillager:
                mob = new ZombieVillager(world);
                break;

            case EntityType.Witch:
                mob = new Witch(world);
                break;
            }

            if (mob == null)
            {
                return;
            }

            mob.KnownPosition = new PlayerLocation(coordinates.X, coordinates.Y, coordinates.Z);
            mob.SpawnEntity();

            Log.WarnFormat("Player {0} spawned Mob #{1}.", player.Username, Metadata);
        }
Exemple #54
0
 public override void UseItem(Level world, Player player, BlockCoordinates blockCoordinates, BlockFace face, Vector3 faceCoords)
 {
 }
Exemple #55
0
 public override int GetTextureIndex(BlockFace face)
 {
     return(0);
 }
Exemple #56
0
 public override bool PlaceBlock(Level world, Player player, BlockCoordinates blockCoordinates, BlockFace face, Vector3 faceCoords)
 {
     world.ScheduleBlockTick(this, _tickRate);
     return(false);
 }
Exemple #57
0
 protected override bool CanPlace(Level world, Player player, BlockCoordinates blockCoordinates, BlockCoordinates targetCoordinates, BlockFace face)
 {
     return(world.GetBlock(blockCoordinates).IsReplaceable);
 }
Exemple #58
0
        public void Interact(Level world, Player player, short itemId, BlockCoordinates blockCoordinates, short metadata, BlockFace face, Vector3 faceCoords)
        {
            // Make sure we are holding the item we claim to be using

            Block target = GetBlock(blockCoordinates);

            if (target.Interact(world, player, blockCoordinates, face, faceCoords))
            {
                return;                                                                                 // Handled in block interaction
            }
            Item itemInHand = player.Inventory.GetItemInHand();

            if (itemInHand.GetType() == typeof(Item))
            {
                Log.Warn($"Generic item in hand when placing block. Can not complete request. Expected item {itemId} and item in hand is {itemInHand?.Id}");
                return;                 // Cheat(?)
            }

            if (itemInHand == null || itemInHand.Id != itemId)
            {
                if (player.GameMode != GameMode.Creative)
                {
                    Log.Error($"Wrong item in hand when placing block. Expected item {itemId} but had item {itemInHand?.Id}");
                }
                return;                 // Cheat(?)
            }

            if (itemInHand is ItemBlock)
            {
                Block block = GetBlock(itemInHand.GetNewCoordinatesFromFace(blockCoordinates, face));
                if (!AllowBuild || !OnBlockPlace(new BlockPlaceEventArgs(player, this, target, block)))
                {
                    // Revert

                    player.SendPlayerInventory();

                    var message = McpeUpdateBlock.CreateObject();
                    message.blockId              = block.Id;
                    message.coordinates          = block.Coordinates;
                    message.blockMetaAndPriority = (byte)(0xb << 4 | (block.Metadata & 0xf));
                    player.SendPackage(message);

                    return;
                }
            }

            itemInHand.UseItem(world, player, blockCoordinates, face, faceCoords);
        }
Exemple #59
0
        public override bool Interact(Level world, Player player, BlockCoordinates blockCoordinates, BlockFace face, Vector3 faceCoord)
        {
            Block block = this;

            // Remove door
            if ((Metadata & 0x08) == 0x08)             // Is Upper?
            {
                block = world.GetBlock(GetNewCoordinatesFromFace(blockCoordinates, BlockFace.Down));
            }

            block.Metadata ^= 0x04;
            world.SetBlock(block);

            return(true);
        }
Exemple #60
0
        public override void PlaceBlock(Level world, Player player, BlockCoordinates blockCoordinates, BlockFace face, Vector3 faceCoords)
        {
            if (NeedBlockRevert)
            {
                var coord = GetNewCoordinatesFromFace(blockCoordinates, face);

                Log.Info("Reset block");
                // Resend the block to removed the new one
                Block block = world.GetBlock(coord);
                world.SetBlock(block);
            }

            Action(this, world, player, blockCoordinates);
        }