Ejemplo n.º 1
0
        protected override bool CanBePlacedOn(EntityBase who, StructBlock block, StructBlock targetBlock, BlockFace targetSide)
        {
            // Cactus can only be placed on the top of the sand block or on the top of the other cactus
            if ((targetBlock.Type != (byte)BlockData.Blocks.Sand && targetBlock.Type != (byte)BlockData.Blocks.Cactus) || targetSide != BlockFace.Up)
                return false;
            // Can be placed only if North/West/East/South is clear
            bool isAir = true;

            Chunk chunk = GetBlockChunk(block);

            if (chunk == null)
                return false;

            chunk.ForNSEW(block.Coords,
                delegate(UniversalCoords uc)
                {
                    byte? blockId = block.World.GetBlockId(uc);
                    if (blockId == null || blockId != (byte)BlockData.Blocks.Air)
                        isAir = false;
                });
            if (!isAir)
                return false;

            return base.CanBePlacedOn(who, block, targetBlock, targetSide);
        }
Ejemplo n.º 2
0
        protected override void OnStop()
        {
            UniversalCoords currentBlockCoords = UniversalCoords.FromAbsWorld(Position);
            byte?           blockId            = World.GetBlockId(currentBlockCoords);

            if (blockId == null)
            {
                return;
            }

            if (BlockHelper.Instance.IsAir((byte)blockId))
            {
                World.Server.DropItem(World, currentBlockCoords, new ItemStack(BlockId, 1));
            }
            else
            {
                UniversalCoords aboveBlockCoords = UniversalCoords.FromWorld(currentBlockCoords.WorldX,
                                                                             currentBlockCoords.WorldY + 1,
                                                                             currentBlockCoords.WorldZ);
                StructBlock aboveBlock = new StructBlock(aboveBlockCoords, BlockId, 0, World);
                BlockHelper.Instance.CreateBlockInstance(BlockId).Spawn(aboveBlock);

                foreach (LivingEntity living in World.Server.GetNearbyLivings(World, aboveBlockCoords))
                {
                    if (Math.Abs(living.Position.X - aboveBlockCoords.WorldX) < 2 &&
                        Math.Abs(living.Position.Z - aboveBlockCoords.WorldZ) < 2 &&
                        Math.Abs(living.Position.Y + living.Height - aboveBlockCoords.WorldY) < 2)
                    {
                        living.CheckSuffocation();
                    }
                }
            }
            base.OnStop();
        }
Ejemplo n.º 3
0
        protected override bool CanBePlacedOn(EntityBase who, StructBlock block, StructBlock targetBlock, BlockFace targetSide)
        {
            // Cactus can only be placed on the top of the sand block or on the top of the other cactus
            if ((targetBlock.Type != (byte)BlockData.Blocks.Sand && targetBlock.Type != (byte)BlockData.Blocks.Cactus) || targetSide != BlockFace.Up)
            {
                return(false);
            }
            // Can be placed only if North/West/East/South is clear
            bool isAir = true;

            Chunk chunk = GetBlockChunk(block);

            if (chunk == null)
            {
                return(false);
            }

            chunk.ForNSEW(block.Coords,
                          delegate(UniversalCoords uc)
            {
                byte?blockId = block.World.GetBlockId(uc);
                if (blockId == null || blockId != (byte)BlockData.Blocks.Air)
                {
                    isAir = false;
                }
            });
            if (!isAir)
            {
                return(false);
            }

            return(base.CanBePlacedOn(who, block, targetBlock, targetSide));
        }
Ejemplo n.º 4
0
        protected override void DropItems(EntityBase who, StructBlock block, List <ItemStack> overridedLoot = null)
        {
            WorldManager world  = block.World as WorldManager;
            Server       server = world.Server;

            overridedLoot = new List <ItemStack>();
            // TODO: Fully grown drops 1 Wheat & 0-3 Seeds. 0 seeds - very rarely
            if (block.MetaData == 7)
            {
                overridedLoot.Add(new ItemStack((short)BlockData.Items.Wheat, 1));
                sbyte seeds = (sbyte)server.Rand.Next(3);
                if (seeds > 0)
                {
                    overridedLoot.Add(new ItemStack((short)BlockData.Items.Seeds, seeds));
                }
            }
            else if (block.MetaData >= 5)
            {
                sbyte seeds = (sbyte)server.Rand.Next(3);
                if (seeds > 0)
                {
                    overridedLoot.Add(new ItemStack((short)BlockData.Items.Seeds, seeds));
                }
            }
            base.DropItems(who, block, overridedLoot);
        }
Ejemplo n.º 5
0
 protected void StartPhysics(StructBlock block)
 {
     Remove(block);
     var fsBlock = new FallingSand(block.World, new AbsWorldCoords(block.Coords.WorldX + 0.5, block.Coords.WorldY + 0.5, block.Coords.WorldZ + 0.5));
     fsBlock.Start();
     block.World.PhysicsBlocks.TryAdd(fsBlock.EntityId, fsBlock);
 }
Ejemplo n.º 6
0
        protected override void DropItems(EntityBase who, StructBlock block, List <ItemInventory> overridedLoot = null)
        {
            var world  = block.World;
            var server = world.Server;

            overridedLoot = new List <ItemInventory>();
            // TODO: Fully grown drops 1 Wheat & 0-3 Seeds. 0 seeds - very rarely
            if (block.MetaData == 7)
            {
                ItemInventory item = ItemHelper.GetInstance((short)BlockData.Items.Wheat);
                item.Count = 1;
                overridedLoot.Add(item);
                sbyte seeds = (sbyte)server.Rand.Next(3);
                if (seeds > 0)
                {
                    item       = ItemHelper.GetInstance((short)BlockData.Items.Seeds);
                    item.Count = seeds;
                    overridedLoot.Add(item);
                }
            }
            else if (block.MetaData >= 5)
            {
                var seeds = (sbyte)server.Rand.Next(3);
                if (seeds > 0)
                {
                    ItemInventory item = ItemHelper.GetInstance((short)BlockData.Items.Seeds);
                    item.Count = seeds;
                    overridedLoot.Add(item);
                }
            }
            base.DropItems(who, block, overridedLoot);
        }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
0
        protected override void DropItems(EntityBase who, StructBlock block, List<ItemInventory> overridedLoot = null)
        {
            var world = block.World;
            var server = world.Server;

            overridedLoot = new List<ItemInventory>();
            // TODO: Fully grown drops 1 Wheat & 0-3 Seeds. 0 seeds - very rarely
            if (block.MetaData == 7)
            {
                ItemInventory item = ItemHelper.GetInstance((short) BlockData.Items.Wheat);
                item.Count = 1;
                overridedLoot.Add(item);
                sbyte seeds = (sbyte)server.Rand.Next(3);
                if (seeds > 0)
                {
                    item = ItemHelper.GetInstance((short) BlockData.Items.Seeds);
                    item.Count = seeds;
                    overridedLoot.Add(item);
                }
            }
            else if (block.MetaData >= 5)
            {
                var seeds = (sbyte)server.Rand.Next(3);
                if (seeds > 0)
                {
                    ItemInventory item = ItemHelper.GetInstance((short) BlockData.Items.Seeds);
                    item.Count = seeds;
                    overridedLoot.Add(item);
                }
            }
            base.DropItems(who, block, overridedLoot);
        }
Ejemplo n.º 9
0
        public override void Place(IEntityBase entity, IStructBlock iBlock, IStructBlock targetIBlock, BlockFace targetSide)
        {
            StructBlock  block  = (StructBlock)iBlock;
            LivingEntity 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, targetSide);
        }
Ejemplo n.º 10
0
        protected override void DropItems(EntityBase entity, StructBlock block, List <ItemInventory> overridedLoot = null)
        {
            overridedLoot = new List <ItemInventory>();
            var player = entity as Player;

            if (player != null)
            {
                ItemInventory item;
                // If hit by a shear - drop the grass
                if (player.Inventory.ActiveItem.Type == (short)BlockData.Items.Shears)
                {
                    item            = ItemHelper.GetInstance((short)Type);
                    item.Count      = 1;
                    item.Durability = block.MetaData;
                    overridedLoot.Add(item);
                }
                else if (player.Server.Rand.Next(3) == 0)
                {
                    item       = ItemHelper.GetInstance((short)BlockData.Items.Seeds);
                    item.Count = 1;
                    overridedLoot.Add(item);
                }
            }
            base.DropItems(entity, block, overridedLoot);
        }
Ejemplo n.º 11
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 (face)
            {
            case BlockFace.Down:
            case BlockFace.Up:
                return;

            case BlockFace.West: block.MetaData = (byte)MetaData.Button.WestWall;
                break;

            case BlockFace.East: block.MetaData = (byte)MetaData.Button.EastWall;
                break;

            case BlockFace.North: block.MetaData = (byte)MetaData.Button.NorthWall;
                break;

            case BlockFace.South: block.MetaData = (byte)MetaData.Button.SouthWall;
                break;
            }

            base.Place(entity, block, targetIBlock, face);
        }
Ejemplo n.º 12
0
        public static void HandlePacketPlayerDigging(Client client, PlayerDiggingPacket packet)
        {
            var player = client.Owner;

            UniversalCoords coords = UniversalCoords.FromWorld(packet.X, packet.Y, packet.Z);

            Chunk chunk = player.World.GetChunk(coords) as Chunk;

            if (chunk == null)
            {
                return;
            }

            byte type = (byte)chunk.GetType(coords);
            byte data = chunk.GetData(coords);

            switch (packet.Action)
            {
            case PlayerDiggingPacket.DigAction.StartDigging:
#if DEBUG
                UniversalCoords oneUp = UniversalCoords.FromWorld(coords.WorldX, coords.WorldY + 1, coords.WorldZ);
                client.SendMessage(String.Format("SkyLight: {0}", player.World.GetSkyLight(oneUp)));
                client.SendMessage(String.Format("BlockLight: {0}", player.World.GetBlockLight(oneUp)));
                client.SendMessage(String.Format("Opacity: {0}", player.World.GetChunk(oneUp, false, false).GetOpacity(oneUp)));
                client.SendMessage(String.Format("Height: {0}", player.World.GetHeight(oneUp)));
                client.SendMessage(String.Format("Data: {0}", player.World.GetBlockData(oneUp)));
                //this.SendMessage()
#endif
                if (BlockHelper.Instance.IsSingleHit(type))
                {
                    goto case PlayerDiggingPacket.DigAction.FinishDigging;
                }
                if (BlockHelper.Instance.CreateBlockInstance(type) is BlockLeaves && player.Inventory.ActiveItem.Type == (short)BlockData.Items.Shears)
                {
                    goto case PlayerDiggingPacket.DigAction.FinishDigging;
                }
                if (player.GameMode == GameMode.Creative)
                {
                    goto case PlayerDiggingPacket.DigAction.FinishDigging;
                }
                break;

            case PlayerDiggingPacket.DigAction.CancelledDigging:
                break;

            case PlayerDiggingPacket.DigAction.FinishDigging:
                var block = new StructBlock(coords, type, data, player.World);
                player.Exhaustion += 25;
                player.Inventory.ActiveItem.DestroyBlock(block);
                break;

            case PlayerDiggingPacket.DigAction.DropItem:
                player.DropActiveSlotItem();
                break;

            case PlayerDiggingPacket.DigAction.ShootArrow:     // Finish eating food too
                client.Owner.FinishUseActiveSlotItem();
                break;
            }
        }
Ejemplo n.º 13
0
 protected override void UpdateWorld(StructBlock block, bool isDestroyed = false)
 {
     base.UpdateWorld(block, isDestroyed);
     if (!isDestroyed && block.Coords.WorldY > 1)
         if (block.World.GetBlockId(block.Coords.WorldX, block.Coords.WorldY - 1, block.Coords.WorldZ) == (byte)BlockData.Blocks.Air)
             StartPhysics(block);
 }
Ejemplo n.º 14
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);
        }
Ejemplo n.º 15
0
        public bool CanGrow(StructBlock block, Chunk chunk)
        {
            if (chunk == null)
            {
                return(false);
            }

            bool canGrow = false;

            if (block.Coords.WorldY < 127)
            {
                UniversalCoords oneUp = UniversalCoords.FromWorld(block.Coords.WorldX, block.Coords.WorldY + 1,
                                                                  block.Coords.WorldZ);

                byte blockAboveId    = (byte)chunk.GetType(oneUp);
                byte?blockAboveLight = chunk.World.GetEffectiveLight(oneUp);
                if (blockAboveLight != null && ((blockAboveLight < 4 && BlockHelper.Instance.CreateBlockInstance(blockAboveId).Opacity > 2) || blockAboveLight >= 9))
                {
                    canGrow = true;
                }
            }
            else
            {
                canGrow = true;
            }

            return(canGrow);
        }
Ejemplo n.º 16
0
        public static void HandlePacketPlayerBlockPlacement(Client client, PlayerBlockPlacementPacket packet)
        {
            var baseBlockcoords = UniversalCoords.FromWorld(packet.X, packet.Y, packet.Z);
            var player          = client.Owner;

            // Consume food, charge the bow etc
            if (packet.X == -1 && packet.Y == -1 && packet.Z == -1 && packet.Face == BlockFace.Held)
            {
                if (ItemHelper.IsVoid(player.Inventory.ActiveItem))
                {
                    return;
                }

                if (player.Inventory.ActiveItem is IItemConsumable)
                {
                    var consumable = player.Inventory.ActiveItem as IItemConsumable;
                    consumable.StartConsuming();
                }
                return;
            }

            var chunk = player.World.GetChunk(baseBlockcoords) as Chunk;

            if (chunk == null)
            {
                return;
            }

            var  baseBlockType = chunk.GetType(baseBlockcoords); // Get block being built against.
            byte baseBlockMeta = chunk.GetData(baseBlockcoords);
            var  baseBlock     = new StructBlock(baseBlockcoords, (byte)baseBlockType, baseBlockMeta, player.World);


            // Interaction with the blocks - chest, furnace, enchantment table etc
            if (BlockHelper.Instance.IsInteractive(baseBlockType))
            {
                (BlockHelper.Instance.CreateBlockInstance(baseBlock.Type) as IBlockInteractive).Interact(client.Owner, baseBlock);
                return;
            }

            if (ItemHelper.IsVoid(player.Inventory.ActiveItem))
            {
                return;
            }


            if (player.Inventory.ActiveItem is IItemUsable)
            {
                var consumable = player.Inventory.ActiveItem as IItemUsable;
                consumable.Use(baseBlock, packet.Face);
                //HandlePacketPlayerItemPlacement(client, packet);
            }

            if (player.Inventory.ActiveItem is IItemPlaceable)
            {
                var consumable = player.Inventory.ActiveItem as IItemPlaceable;
                consumable.Place(baseBlock, packet.Face);
            }
        }
Ejemplo n.º 17
0
 protected override void DropItems(EntityBase entity, StructBlock block, List <ItemStack> overridedLoot = null)
 {
     // SnowBlock requires 9 snowballs to craft and drops 4-6 snowballs upon destruction.
     // No tools required.
     overridedLoot = new List <ItemStack>();
     overridedLoot.Add(new ItemStack((short)BlockData.Items.Snowball, (sbyte)(4 + block.World.Server.Rand.Next(2))));
     base.DropItems(entity, block, overridedLoot);
 }
Ejemplo n.º 18
0
        protected void StartPhysics(StructBlock block)
        {
            Remove(block);
            FallingSand fsBlock = new FallingSand((WorldManager)block.World, new AbsWorldCoords(block.Coords.WorldX + 0.5, block.Coords.WorldY + 0.5, block.Coords.WorldZ + 0.5));

            fsBlock.Start();
            block.World.PhysicsBlocks.TryAdd(fsBlock.EntityId, fsBlock);
        }
Ejemplo n.º 19
0
 protected override void NotifyDestroy(EntityBase entity, StructBlock sourceBlock, StructBlock targetBlock)
 {
     if ((targetBlock.Coords.WorldY - sourceBlock.Coords.WorldY) == 1 &&
             targetBlock.Coords.WorldX == sourceBlock.Coords.WorldX &&
             targetBlock.Coords.WorldZ == sourceBlock.Coords.WorldZ)
         StartPhysics(targetBlock);
     base.NotifyDestroy(entity, sourceBlock, targetBlock);
 }
Ejemplo n.º 20
0
 protected override bool CanBePlacedOn(EntityBase who, StructBlock block, StructBlock targetBlock, BlockFace targetSide)
 {
     if (!BlockHelper.Instance.IsPlowed(targetBlock.Type) || targetSide != BlockFace.Up)
     {
         return(false);
     }
     return(base.CanBePlacedOn(who, targetBlock, targetBlock, targetSide));
 }
Ejemplo n.º 21
0
 protected override void NotifyPlace(EntityBase entity, StructBlock sourceBlock, StructBlock targetBlock)
 {
     if (sourceBlock.Type == (byte)BlockData.Blocks.Chest)
     {
         targetBlock.World.SetBlockData(targetBlock.Coords, sourceBlock.MetaData);
     }
     base.NotifyPlace(entity, sourceBlock, targetBlock);
 }
Ejemplo n.º 22
0
 protected override void NotifyDestroy(EntityBase entity, StructBlock sourceBlock, StructBlock thisBlock)
 {
     if ((thisBlock.Coords.WorldY - sourceBlock.Coords.WorldY) == 1 &&
         thisBlock.Coords.WorldX == sourceBlock.Coords.WorldX &&
         thisBlock.Coords.WorldZ == sourceBlock.Coords.WorldZ)
         Destroy(thisBlock);
     base.NotifyDestroy(entity, sourceBlock, thisBlock);
 }
Ejemplo n.º 23
0
 protected override void DropItems(EntityBase entity, StructBlock block, List<ItemInventory> overridedLoot = null)
 {
     overridedLoot = new List<ItemInventory>();
     var item = ItemHelper.GetInstance(BlockData.Items.Redstone);
     item.Count = (sbyte) (2 + block.World.Server.Rand.Next(4));
     overridedLoot.Add(item);
     base.DropItems(entity, block, overridedLoot);
 }
Ejemplo n.º 24
0
 protected override void DropItems(EntityBase entity, StructBlock block, List<ItemStack> overridedLoot = null)
 {
     // SnowBlock requires 9 snowballs to craft and drops 4-6 snowballs upon destruction.
     // No tools required.
     overridedLoot = new List<ItemStack>();
     overridedLoot.Add(new ItemStack((short)BlockData.Items.Snowball, (sbyte)(4 + block.World.Server.Rand.Next(2))));
     base.DropItems(entity, block, overridedLoot);
 }
Ejemplo n.º 25
0
 protected void StartPhysics(StructBlock block)
 {
     var world = block.World;
     Remove(block);
     FallingGravel fgBlock = new FallingGravel(world, new AbsWorldCoords(block.Coords.WorldX + 0.5, block.Coords.WorldY + 0.5, block.Coords.WorldZ + 0.5));
     fgBlock.Start();
     world.PhysicsBlocks.TryAdd(fgBlock.EntityId, fgBlock);
 }
Ejemplo n.º 26
0
        public override void Place(IEntityBase iEntity, IStructBlock iBlock, IStructBlock targetIBlock, BlockFace face)
        {
            StructBlock block  = (StructBlock)iBlock;
            EntityBase  entity = iEntity as EntityBase;

            if (entity == null)
            {
                return;
            }

            switch (face)
            {
            case BlockFace.North:
                block.MetaData = (byte)MetaData.Lever.NorthWall;
                break;

            case BlockFace.West:
                block.MetaData = (byte)MetaData.Lever.WestWall;
                break;

            case BlockFace.East:
                block.MetaData = (byte)MetaData.Lever.EastWall;
                break;

            case BlockFace.South:
                block.MetaData = (byte)MetaData.Lever.SouthWall;
                break;

            case BlockFace.Up:
                // Works weird. Even in the original game
                if (targetIBlock.Coords.WorldZ > entity.Position.Z)
                {
                    block.MetaData = (byte)MetaData.Lever.EWGround;
                }
                else if (targetIBlock.Coords.WorldZ < entity.Position.Z)
                {
                    block.MetaData = (byte)MetaData.Lever.EWGround;
                }
                else if (targetIBlock.Coords.WorldX > entity.Position.X)
                {
                    block.MetaData = (byte)MetaData.Lever.NSGround;
                }
                else if (targetIBlock.Coords.WorldX < entity.Position.X)
                {
                    block.MetaData = (byte)MetaData.Lever.NSGround;
                }
                else
                {
                    block.MetaData = (byte)MetaData.Lever.NSGround;
                }
                break;

            default:
                return;
            }

            base.Place(entity, block, targetIBlock, face);
        }
Ejemplo n.º 27
0
 protected override void DropItems(EntityBase entity, StructBlock block, List<ItemInventory> overridedLoot = null)
 {
     overridedLoot = new List<ItemInventory>();
     var item = ItemHelper.GetInstance((short) Type);
     item.Count = 1;
     item.Durability = block.MetaData;
     overridedLoot.Add(item);
     base.DropItems(entity, block, overridedLoot);
 }
Ejemplo n.º 28
0
 protected override void DropItems(EntityBase entity, StructBlock block, List<ItemInventory> overridedLoot = null)
 {
     overridedLoot = new List<ItemInventory>();
     ItemInventory item = ItemHelper.GetInstance((short) BlockData.Items.Ink_Sack);
     item.Count = (sbyte) (3 + block.World.Server.Rand.Next(17));
     item.Durability = 4;
     overridedLoot.Add(item);
     base.DropItems(entity, block, overridedLoot);
 }
Ejemplo n.º 29
0
        protected override void DropItems(EntityBase entity, StructBlock block, List <ItemInventory> overridedLoot = null)
        {
            overridedLoot = new List <ItemInventory>();
            var item = ItemHelper.GetInstance(BlockData.Items.Redstone);

            item.Count = (sbyte)(2 + block.World.Server.Rand.Next(4));
            overridedLoot.Add(item);
            base.DropItems(entity, block, overridedLoot);
        }
Ejemplo n.º 30
0
        protected override void DropItems(EntityBase entity, StructBlock block, List <ItemInventory> overridedLoot = null)
        {
            overridedLoot = new List <ItemInventory>();
            ItemInventory item = ItemHelper.GetInstance((short)BlockData.Items.Ink_Sack);

            item.Count      = (sbyte)(3 + block.World.Server.Rand.Next(17));
            item.Durability = 4;
            overridedLoot.Add(item);
            base.DropItems(entity, block, overridedLoot);
        }
Ejemplo n.º 31
0
 protected override void DropItems(EntityBase entity, StructBlock block, List<ItemInventory> overridedLoot = null)
 {
     // SnowBlock requires 9 snowballs to craft and drops 4-6 snowballs upon destruction.
     // No tools required.
     overridedLoot = new List<ItemInventory>();
     var item = ItemHelper.GetInstance(BlockData.Items.Snowball);
     item.Count = (sbyte) (4 + block.World.Server.Rand.Next(2));
     overridedLoot.Add(item);
     base.DropItems(entity, block, overridedLoot);
 }
Ejemplo n.º 32
0
 protected override void NotifyDestroy(EntityBase entity, StructBlock sourceBlock, StructBlock targetBlock)
 {
     if (targetBlock.Coords.WorldY > sourceBlock.Coords.WorldY && targetBlock.MetaData == (byte)MetaData.Torch.Standing ||
         targetBlock.Coords.WorldX > sourceBlock.Coords.WorldX && targetBlock.MetaData == (byte)MetaData.Torch.South ||
         targetBlock.Coords.WorldX < sourceBlock.Coords.WorldX && targetBlock.MetaData == (byte)MetaData.Torch.North ||
         targetBlock.Coords.WorldZ > sourceBlock.Coords.WorldZ && targetBlock.MetaData == (byte)MetaData.Torch.West ||
         targetBlock.Coords.WorldZ < sourceBlock.Coords.WorldZ && targetBlock.MetaData == (byte)MetaData.Torch.East)
         Destroy(targetBlock);
     base.NotifyDestroy(entity, sourceBlock, targetBlock);
 }
Ejemplo n.º 33
0
        protected void StartPhysics(StructBlock block)
        {
            var world = block.World;

            Remove(block);
            FallingGravel fgBlock = new FallingGravel(world, new AbsWorldCoords(block.Coords.WorldX + 0.5, block.Coords.WorldY + 0.5, block.Coords.WorldZ + 0.5));

            fgBlock.Start();
            world.PhysicsBlocks.TryAdd(fgBlock.EntityId, fgBlock);
        }
Ejemplo n.º 34
0
 protected override void NotifyDestroy(EntityBase entity, StructBlock sourceBlock, StructBlock targetBlock)
 {
     if ((targetBlock.Coords.WorldY - sourceBlock.Coords.WorldY) == 1 &&
         targetBlock.Coords.WorldX == sourceBlock.Coords.WorldX &&
         targetBlock.Coords.WorldZ == sourceBlock.Coords.WorldZ)
     {
         Destroy(targetBlock);
     }
     base.NotifyDestroy(entity, sourceBlock, targetBlock);
 }
Ejemplo n.º 35
0
        protected override void DropItems(EntityBase entity, StructBlock block, List <ItemInventory> overridedLoot = null)
        {
            overridedLoot = new List <ItemInventory>();
            var item = ItemHelper.GetInstance((short)Type);

            item.Count      = 1;
            item.Durability = block.MetaData;
            overridedLoot.Add(item);
            base.DropItems(entity, block, overridedLoot);
        }
Ejemplo n.º 36
0
        protected override void DropItems(EntityBase entity, StructBlock block, List <ItemStack> overridedLoot = null)
        {
            overridedLoot = new List <ItemStack>();
            int amount = block.World.Server.Rand.Next(10) - 7;

            if (amount > 0)
            {
                overridedLoot.Add(new ItemStack((short)BlockData.Blocks.Red_Mushroom, (sbyte)amount));
            }
            base.DropItems(entity, block, overridedLoot);
        }
Ejemplo n.º 37
0
        protected override byte GetDirection(LivingEntity living, StructBlock block, StructBlock targetBlock, BlockFace face)
        {
            Chunk chunk = GetBlockChunk(block);
            // Load the blocks surrounding the position (NSEW) not diagonals
            var nsewBlocks = new BlockData.Blocks[4];
            var nsewBlockPositions = new UniversalCoords[4];
            int nsewCount = 0;

            int secondChestIndex = -1;
            chunk.ForNSEW(block.Coords, uc =>
            {
                byte? nearbyBlockId = block.World.GetBlockId(uc);

                if (nearbyBlockId == null)
                    return;

                if (nearbyBlockId == (byte)BlockData.Blocks.Chest)
                    secondChestIndex = nsewCount;

                nsewBlocks[nsewCount] = (BlockData.Blocks)nearbyBlockId;
                nsewBlockPositions[nsewCount] = uc;
                nsewCount++;
            });
            byte direction = base.GetDirection(living, block, targetBlock, face);
            if (secondChestIndex != -1)
            {
                var secondChestCoords = nsewBlockPositions[secondChestIndex];
                byte secondChestDirection = chunk.GetData(secondChestCoords);
                if (secondChestDirection != direction)
                {
                    if (secondChestCoords.WorldX == block.Coords.WorldX)
                    {
                        if (direction != (byte)MetaData.Container.South && direction != (byte)MetaData.Container.North)
                            direction = (byte)MetaData.Container.South;                          
                    }
                    else
                    {
                        if (direction != (byte)MetaData.Container.East && direction != (byte)MetaData.Container.West)
                            direction = (byte)MetaData.Container.West;
                    }
                }
                else
                {

                    if (secondChestCoords.WorldX == block.Coords.WorldX && block.MetaData != (byte)MetaData.Container.North && block.MetaData != (byte)MetaData.Container.South)
                        direction = (byte)MetaData.Container.South;
                    else
                        if (block.MetaData != (byte)MetaData.Container.West && block.MetaData != (byte)MetaData.Container.East)
                            direction = (byte)MetaData.Container.West;
                }
            }

            return direction;
        }
Ejemplo n.º 38
0
 public void Interact(IEntityBase entity, StructBlock block)
 {
     if (block.Coords.WorldY < 127)
     {
         // Cannot open a chest if no space is above it
         byte? blockId = block.World.GetBlockId(block.Coords.WorldX, block.Coords.WorldY + 1, block.Coords.WorldZ);
         if (blockId == null || !BlockHelper.Instance.IsAir((byte)blockId))
             return;
     }
     base.Interact(entity, block);
 }
Ejemplo n.º 39
0
        protected override void DropItems(EntityBase entity, StructBlock block, List <ItemInventory> overridedLoot = null)
        {
            // SnowBlock requires 9 snowballs to craft and drops 4-6 snowballs upon destruction.
            // No tools required.
            overridedLoot = new List <ItemInventory>();
            var item = ItemHelper.GetInstance(BlockData.Items.Snowball);

            item.Count = (sbyte)(4 + block.World.Server.Rand.Next(2));
            overridedLoot.Add(item);
            base.DropItems(entity, block, overridedLoot);
        }
Ejemplo n.º 40
0
 protected override void UpdateWorld(StructBlock block, bool isDestroyed = false)
 {
     base.UpdateWorld(block, isDestroyed);
     if (!isDestroyed && block.Coords.WorldY > 1)
     {
         if (block.World.GetBlockId(block.Coords.WorldX, block.Coords.WorldY - 1, block.Coords.WorldZ) == (byte)BlockData.Blocks.Air)
         {
             StartPhysics(block);
         }
     }
 }
Ejemplo n.º 41
0
        protected override void UpdateWorld(StructBlock block, bool isDestroyed = false)
        {
            if (!isDestroyed)
            {
                base.UpdateWorld(block, isDestroyed);
                return;
            }

            var water = new StructBlock(block.Coords, (byte)BlockData.Blocks.Water, 0, block.World);
            BlockHelper.Instance.CreateBlockInstance((byte)BlockData.Blocks.Water).Spawn(water);
        }
Ejemplo n.º 42
0
        public override void Place(IEntityBase entity, IStructBlock iBlock, IStructBlock targetBlock, BlockFace face)
        {
            StructBlock  block  = (StructBlock)iBlock;
            LivingEntity living = (entity as LivingEntity);

            if (living == null)
            {
                return;
            }

            switch (face) //Bugged, as the client has a mind of its own for facing
            {
            case BlockFace.East:
                block.MetaData = (byte)MetaData.Container.East;
                break;

            case BlockFace.West:
                block.MetaData = (byte)MetaData.Container.West;
                break;

            case BlockFace.North:
                block.MetaData = (byte)MetaData.Container.North;
                break;

            case BlockFace.South:
                block.MetaData = (byte)MetaData.Container.South;
                break;

            default:
                switch (living.FacingDirection(4))     // Built on floor, set by facing dir
                {
                case "N":
                    block.MetaData = (byte)MetaData.Container.North;
                    break;

                case "W":
                    block.MetaData = (byte)MetaData.Container.West;
                    break;

                case "S":
                    block.MetaData = (byte)MetaData.Container.South;
                    break;

                case "E":
                    block.MetaData = (byte)MetaData.Container.East;
                    break;

                default:
                    return;
                }
                break;
            }
            base.Place(entity, block, targetBlock, face);
        }
Ejemplo n.º 43
0
        protected override void UpdateWorld(StructBlock block, bool isDestroyed = false)
        {
            if (!isDestroyed)
            {
                base.UpdateWorld(block, isDestroyed);
                return;
            }

            StructBlock water = new StructBlock(block.Coords, (byte)BlockData.Blocks.Water, 0, block.World);

            BlockHelper.Instance.CreateBlockInstance((byte)BlockData.Blocks.Water).Spawn(water);
        }
Ejemplo n.º 44
0
 protected override void DropItems(EntityBase entity, StructBlock block, List<ItemInventory> overridedLoot = null)
 {
     overridedLoot = new List<ItemInventory>();
     int amount = block.World.Server.Rand.Next(10) - 7;
     if (amount > 0)
     {
         var item = ItemHelper.GetInstance(BlockData.Blocks.Red_Mushroom);
         item.Count = (sbyte) amount;
         overridedLoot.Add(item);
     }
     base.DropItems(entity, block, overridedLoot);
 }
Ejemplo n.º 45
0
 protected override void NotifyDestroy(EntityBase entity, StructBlock sourceBlock, StructBlock targetBlock)
 {
     if (targetBlock.Coords.WorldY > sourceBlock.Coords.WorldY && targetBlock.MetaData == (byte)MetaData.Torch.Standing ||
         targetBlock.Coords.WorldX > sourceBlock.Coords.WorldX && targetBlock.MetaData == (byte)MetaData.Torch.South ||
         targetBlock.Coords.WorldX < sourceBlock.Coords.WorldX && targetBlock.MetaData == (byte)MetaData.Torch.North ||
         targetBlock.Coords.WorldZ > sourceBlock.Coords.WorldZ && targetBlock.MetaData == (byte)MetaData.Torch.West ||
         targetBlock.Coords.WorldZ < sourceBlock.Coords.WorldZ && targetBlock.MetaData == (byte)MetaData.Torch.East)
     {
         Destroy(targetBlock);
     }
     base.NotifyDestroy(entity, sourceBlock, targetBlock);
 }
Ejemplo n.º 46
0
 public void Interact(IEntityBase entity, StructBlock block)
 {
     if (block.Coords.WorldY < 127)
     {
         // Cannot open a chest if no space is above it
         byte?blockId = block.World.GetBlockId(block.Coords.WorldX, block.Coords.WorldY + 1, block.Coords.WorldZ);
         if (blockId == null || !BlockHelper.Instance.IsAir((byte)blockId))
         {
             return;
         }
     }
     base.Interact(entity, block);
 }
Ejemplo n.º 47
0
        protected override void DropItems(EntityBase entity, StructBlock block, List <ItemInventory> overridedLoot = null)
        {
            overridedLoot = new List <ItemInventory>();
            int amount = block.World.Server.Rand.Next(10) - 7;

            if (amount > 0)
            {
                var item = ItemHelper.GetInstance(BlockData.Blocks.Red_Mushroom);
                item.Count = (sbyte)amount;
                overridedLoot.Add(item);
            }
            base.DropItems(entity, block, overridedLoot);
        }
Ejemplo n.º 48
0
 protected override void DropItems(EntityBase entity, StructBlock block, List<ItemStack> overridedLoot = null)
 {
     Player player = entity as Player;
     overridedLoot = new List<ItemStack>();
     if (player != null)
         if (player.Inventory.ActiveItem.Type == (short) BlockData.Items.Wooden_Pickaxe ||
             player.Inventory.ActiveItem.Type == (short) BlockData.Items.Stone_Pickaxe ||
             player.Inventory.ActiveItem.Type == (short) BlockData.Items.Iron_Pickaxe ||
             player.Inventory.ActiveItem.Type == (short) BlockData.Items.Gold_Pickaxe ||
             player.Inventory.ActiveItem.Type == (short) BlockData.Items.Diamond_Pickaxe)
             overridedLoot.Add(new ItemStack((short)BlockData.Items.Lightstone_Dust, 1, (sbyte)(2 + block.World.Server.Rand.Next(2))));
     base.DropItems(entity, block, overridedLoot);
 }
Ejemplo n.º 49
0
 protected override void DropItems(EntityBase entity, StructBlock block, List<ItemStack> overridedLoot = null)
 {
     overridedLoot = new List<ItemStack>();
     Player player = entity as Player;
     if (player != null)
     {
         // If hit by a shear - drop the grass
         if (player.Inventory.ActiveItem.Type == (short)BlockData.Items.Shears)
             overridedLoot.Add(new ItemStack((short) Type, 1, block.MetaData));
         else if (player.Server.Rand.Next(3) == 0)
                 overridedLoot.Add(new ItemStack((short)BlockData.Items.Seeds, 1));
     }
     base.DropItems(entity, block, overridedLoot);
 }
Ejemplo n.º 50
0
        public void Grow(StructBlock block, Chunk chunk)
        {
            if (!CanGrow(block, chunk))
            {
                return;
            }

            UniversalCoords oneUp           = UniversalCoords.FromWorld(block.Coords.WorldX, block.Coords.WorldY + 1, block.Coords.WorldZ);
            byte            blockAboveId    = (byte)chunk.GetType(oneUp);
            byte?           blockAboveLight = chunk.World.GetEffectiveLight(oneUp);

            if (blockAboveLight == null)
            {
                return;
            }
            if (blockAboveLight < 4 && BlockHelper.Instance.CreateBlockInstance(blockAboveId).Opacity > 2)
            {
                if (block.World.Server.Rand.Next(3) == 0)
                {
                    chunk.SetBlockAndData(block.Coords, (byte)BlockData.Blocks.Dirt, 0);
                }
                return;
            }

            if (blockAboveLight >= 9)
            {
                int x = block.Coords.WorldX + block.World.Server.Rand.Next(2) - 1;
                int y = block.Coords.WorldY + block.World.Server.Rand.Next(4) - 3;
                int z = block.Coords.WorldZ + block.World.Server.Rand.Next(2) - 1;

                Chunk nearbyChunk = block.World.GetChunkFromWorld(x, z) as Chunk;

                if (nearbyChunk == null)
                {
                    return;
                }

                byte newBlockId = (byte)nearbyChunk.GetType(x & 0xF, y, z & 0xF);
                if (newBlockId != (byte)BlockData.Blocks.Dirt)
                {
                    return;
                }

                byte?newBlockAboveLight = nearbyChunk.World.GetEffectiveLight(UniversalCoords.FromWorld(x, y + 1, z));
                if (newBlockAboveLight != null && (newBlockAboveLight >= 4 && BlockHelper.Instance.CreateBlockInstance(newBlockId).Opacity <= 2))
                {
                    nearbyChunk.SetBlockAndData(x & 0xF, y, z & 0xF, (byte)BlockData.Blocks.Grass, 0);
                }
            }
        }
Ejemplo n.º 51
0
        public virtual void Place(IStructBlock baseBlock, BlockFace face)
        {
            if (!CanBePlacedOn(baseBlock, face))
                return;

            var player = Owner.GetPlayer() as Player;
            byte bType = GetBlockToPlace(baseBlock, face);
            byte bMetaData = (byte)Durability;

            var coordsFromFace = UniversalCoords.FromFace(baseBlock.Coords, face);
            var bBlock = new StructBlock(coordsFromFace, bType, bMetaData, player.World);

            BlockHelper.Instance.CreateBlockInstance(bType).Place(player, bBlock, baseBlock, face);
            //Owner.GetPlayer().GetInventory().RemoveItem(Slot);
        }
Ejemplo n.º 52
0
 protected override void DropItems(EntityBase entity, StructBlock block, List<ItemInventory> overridedLoot = null)
 {
     var player = entity as Player;
     overridedLoot = new List<ItemInventory>();
     if (player != null)
         if (player.Inventory.ActiveItem.Type == (short)BlockData.Items.Wooden_Pickaxe ||
             player.Inventory.ActiveItem.Type == (short)BlockData.Items.Stone_Pickaxe ||
             player.Inventory.ActiveItem.Type == (short)BlockData.Items.Iron_Pickaxe ||
             player.Inventory.ActiveItem.Type == (short)BlockData.Items.Gold_Pickaxe ||
             player.Inventory.ActiveItem.Type == (short)BlockData.Items.Diamond_Pickaxe)
         {
             var item = ItemHelper.GetInstance(BlockData.Items.Lightstone_Dust);
             item.Count = (sbyte)(2 + block.World.Server.Rand.Next(2));
             overridedLoot.Add(item);
         }
     base.DropItems(entity, block, overridedLoot);
 }
Ejemplo n.º 53
0
 protected override void DropItems(EntityBase entity, StructBlock block, List<ItemStack> overridedLoot = null)
 {
     overridedLoot = new List<ItemStack>();
     Player player = entity as Player;
     if (player != null)
     {
         if (player.Inventory.ActiveItem.Type == (short)BlockData.Items.Wooden_Spade ||
             player.Inventory.ActiveItem.Type == (short)BlockData.Items.Stone_Spade ||
             player.Inventory.ActiveItem.Type == (short)BlockData.Items.Iron_Spade ||
             player.Inventory.ActiveItem.Type == (short)BlockData.Items.Gold_Spade ||
             player.Inventory.ActiveItem.Type == (short)BlockData.Items.Diamond_Spade)
         {
             overridedLoot.Add(new ItemStack((short)BlockData.Items.Snowball, 1));
         }
     }
     base.DropItems(entity, block, overridedLoot);
 }
Ejemplo n.º 54
0
 protected override void OnStop()
 {
     UniversalCoords currentBlockCoords = UniversalCoords.FromWorld(Position.X, Position.Y, Position.Z);
     byte blockId = World.GetBlockId(currentBlockCoords);
     if (BlockHelper.Instance(blockId).IsAir)
     {
         World.Server.DropItem(World, currentBlockCoords, new ItemStack(BlockId, 1));
     }
     else
     {
         UniversalCoords aboveBlockCoords = UniversalCoords.FromWorld(currentBlockCoords.WorldX,
                                                                      currentBlockCoords.WorldY + 1,
                                                                      currentBlockCoords.WorldZ);
         StructBlock aboveBlock = new StructBlock(aboveBlockCoords, BlockId, 0, World);
         BlockHelper.Instance(BlockId).Spawn(aboveBlock);
     }
     base.OnStop();
 }
Ejemplo n.º 55
0
 protected override void DropItems(EntityBase entity, StructBlock block, List<ItemInventory> overridedLoot = null)
 {
     overridedLoot = new List<ItemInventory>();
     var player = entity as Player;
     if (player != null)
     {
         if (player.Inventory.ActiveItem is ItemWoodenShovel ||
             player.Inventory.ActiveItem is ItemStoneShovel ||
             player.Inventory.ActiveItem is ItemIronShovel ||
             player.Inventory.ActiveItem is ItemGoldShovel ||
             player.Inventory.ActiveItem is ItemDiamondShovel)
         {
             var item = ItemHelper.GetInstance(BlockData.Items.Snowball);
             item.Count = 1;
             overridedLoot.Add(item);
         }
     }
     base.DropItems(entity, block, overridedLoot);
 }
Ejemplo n.º 56
0
 protected override void DropItems(EntityBase entity, StructBlock block, List<ItemInventory> overridedLoot = null)
 {
     var player = entity as Player;
     if (player != null)
     {
         if ((player.Inventory.ActiveItem is ItemWoodenShovel ||
             player.Inventory.ActiveItem is ItemStoneShovel ||
             player.Inventory.ActiveItem is ItemIronShovel ||
             player.Inventory.ActiveItem is ItemGoldShovel ||
             player.Inventory.ActiveItem is ItemDiamondShovel) &&
             block.World.Server.Rand.Next(10) == 0)
         {
             overridedLoot = new List<ItemInventory>(1);
             ItemInventory item = ItemHelper.GetInstance((short) BlockData.Items.Flint);
             item.Count = 1;
             overridedLoot.Add(item);
             base.DropItems(entity, block, overridedLoot);
             return;
         }
     }
     base.DropItems(entity, block);
 }
Ejemplo n.º 57
0
        public void Grow(StructBlock block, Chunk chunk)
        {
            if (!CanGrow(block, chunk))
                return;

            var oneUp = UniversalCoords.FromWorld(block.Coords.WorldX, block.Coords.WorldY + 1, block.Coords.WorldZ);
            byte blockAboveId = (byte)chunk.GetType(oneUp);
            byte? blockAboveLight = chunk.World.GetEffectiveLight(oneUp);
            if (blockAboveLight == null)
                return;
            if (blockAboveLight < 4 && BlockHelper.Instance.CreateBlockInstance(blockAboveId).Opacity > 2)
            {
                if (block.World.Server.Rand.Next(3) == 0)
                {
                    chunk.SetBlockAndData(block.Coords, (byte)BlockData.Blocks.Dirt, 0);
                }
                return;
            }

            if (blockAboveLight >= 9)
            {
                int x = block.Coords.WorldX + block.World.Server.Rand.Next(2) - 1;
                int y = block.Coords.WorldY + block.World.Server.Rand.Next(4) - 3;
                int z = block.Coords.WorldZ + block.World.Server.Rand.Next(2) - 1;

                var nearbyChunk = block.World.GetChunkFromWorld(x, z) as Chunk;

                if (nearbyChunk == null)
                    return;

                byte newBlockId = (byte)nearbyChunk.GetType(x & 0xF, y, z & 0xF);
                if (newBlockId != (byte)BlockData.Blocks.Dirt)
                    return;

                byte? newBlockAboveLight = nearbyChunk.World.GetEffectiveLight(UniversalCoords.FromWorld(x, y + 1, z));
                if (newBlockAboveLight != null && (newBlockAboveLight >= 4 && BlockHelper.Instance.CreateBlockInstance(newBlockId).Opacity <= 2))
                    nearbyChunk.SetBlockAndData(x & 0xF, y, z & 0xF, (byte)BlockData.Blocks.Grass, 0);
            }
        }
Ejemplo n.º 58
0
 protected override void DropItems(EntityBase entity, StructBlock block, List<ItemInventory> overridedLoot = null)
 {
     overridedLoot = new List<ItemInventory>();
     var player = entity as Player;
     if (player != null)
     {
         ItemInventory item;
         if (player.Inventory.ActiveItem is ItemShears)
         {
             item = ItemHelper.GetInstance((short)Type);
             item.Count = 1;
             item.Durability = block.MetaData;
             overridedLoot.Add(item);
         }
         else if (block.World.Server.Rand.Next(5) == 0)
         {
             item = ItemHelper.GetInstance((short)BlockData.Blocks.Sapling);
             item.Count = 1;
             overridedLoot.Add(item);
         }
     }
     base.DropItems(entity, block, overridedLoot);
 }
Ejemplo n.º 59
0
        public bool CanGrow(StructBlock block, Chunk chunk)
        {
            if (chunk == null)
                return false;

            bool canGrow = false;

            if (block.Coords.WorldY < 127)
            {
                UniversalCoords oneUp = UniversalCoords.FromWorld(block.Coords.WorldX, block.Coords.WorldY + 1,
                                                                  block.Coords.WorldZ);

                byte blockAboveId = (byte)chunk.GetType(oneUp);
                byte? blockAboveLight = chunk.World.GetEffectiveLight(oneUp);
                if (blockAboveLight != null && ((blockAboveLight < 4 && BlockHelper.Instance.CreateBlockInstance(blockAboveId).Opacity > 2) || blockAboveLight >= 9))
                    canGrow = true;
            }
            else
            {
                canGrow = true;
            }

            return canGrow;
        }