protected override void DropItems(EntityBase entity, StructBlock block)
 {
     Player player = entity as Player;
     if (player != null)
     {
         DispenserInterface di = new DispenserInterface(block.World, block.X, block.Y, block.Z);
         di.Associate(player);
         di.DropAll(block.Y, block.Y, block.Z);
         di.Save();
     }
     base.DropItems(entity, block);
 }
Beispiel #2
0
        private void PacketHandler_PlayerDigging(object sender, PacketEventArgs<PlayerDiggingPacket> e)
        {
            int x = e.Packet.X;
            int y = e.Packet.Y;
            int z = e.Packet.Z;

            byte type = World.GetBlockId(x, y, z);
            byte data = World.GetBlockData(x, y, z);

            switch (e.Packet.Action)
            {
                case PlayerDiggingPacket.DigAction.StartDigging:
                    this.SendMessage(String.Format("SkyLight: {0}", World.GetSkyLight(x, y, z)));
                    this.SendMessage(String.Format("BlockLight: {0}", World.GetBlockLight(x, y, z)));
                    this.SendMessage(String.Format("Opacity: {0}", World.GetBlockChunk(x, y, z).GetOpacity(x & 0xf, y, z & 0xf)));
                    this.SendMessage(String.Format("Height: {0}", World.GetHeight(x, z)));
                    this.SendMessage(String.Format("Data: {0}", World.GetBlockData(x, y, z)));
                    //this.SendMessage()
                    if (BlockData.SingleHit.Contains((BlockData.Blocks)type))
                        goto case PlayerDiggingPacket.DigAction.FinishDigging;
                    if (GameMode == 1)
                        goto case PlayerDiggingPacket.DigAction.FinishDigging;
                    break;

                case PlayerDiggingPacket.DigAction.FinishDigging:
                    short give = type;
                    sbyte count = 1;
                    short durability = data;

                    switch ((BlockData.Blocks)type)
                    {
                        case BlockData.Blocks.Adminium:
                            if (GameMode == 1) break;
                            return;

                        case BlockData.Blocks.Air:
                            return;

                        case BlockData.Blocks.Bed:
                            give = (short)BlockData.Items.Bed;
                            break;

                        case BlockData.Blocks.Burning_Furnace:
                        case BlockData.Blocks.Furnace:
                            give = (short)BlockData.Blocks.Furnace;
                            FurnaceInterface fi = new FurnaceInterface(this.World, x, y, z);
                            fi.Associate(this);
                            fi.DropAll(x, y, z);
                            fi.Save();
                            break;

                        case BlockData.Blocks.Cake:
                            give = (short)BlockData.Items.Cake;
                            break;

                        case BlockData.Blocks.Chest:
                            // Need to drop the chest contents
                            SmallChestInterface sci = new SmallChestInterface(this.World, x, y, z);
                            sci.Associate(this);
                            sci.DropAll(x, y, z);
                            sci.Save();
                            break;

                        case BlockData.Blocks.Clay:
                            give = (short)BlockData.Items.Clay_Balls;
                            count = 4;
                            break;

                        case BlockData.Blocks.Coal_Ore:
                            give = (short)BlockData.Items.Coal;
                            //count = (sbyte)(1 + Server.Rand.Next(3));
                            break;
                        case BlockData.Blocks.Crops:
                            // TODO: Check crops are mature enough before giving items.
                            give = (short)BlockData.Items.Seeds;
                            count = 2;
                            break;

                        case BlockData.Blocks.Diamond_Ore:
                            give = (short)BlockData.Items.Diamond;
                            break;

                        case BlockData.Blocks.Dispenser:
                            // Drop the contents of the dispenser
                            DispenserInterface di = new DispenserInterface(this.World, x, y, z);
                            di.Associate(this);
                            di.DropAll(x, y, z);
                            di.Save();
                            break;

                        case BlockData.Blocks.Double_Stone_Slab:
                            give = (short)BlockData.Blocks.Stair;
                            break;

                        case BlockData.Blocks.Fire:
                            return;

                        case BlockData.Blocks.Glass:
                            give = -1;
                            break;

                        case BlockData.Blocks.Glowstone:
                            give = (short)BlockData.Items.Lightstone_Dust;
                            break;

                        case BlockData.Blocks.Grass:
                        case BlockData.Blocks.Soil:
                            give = (short)BlockData.Blocks.Dirt;
                            break;

                        case BlockData.Blocks.Gravel:
                            if (Server.Rand.Next(10) == 0)
                                Server.DropItem(World, x, y, z, new ItemStack((short)BlockData.Items.Flint));
                            break;

                        case BlockData.Blocks.Ice:
                            if (BlockData.Air.Contains((BlockData.Blocks)World.GetBlockId(x, y - 1, z)))
                            {
                                World.SetBlockAndData(x, y, z, 0, 0);
                                return;
                            }
                            World.SetBlockAndData(x, y, z, (byte)BlockData.Blocks.Still_Water, 0);
                            return;

                        case BlockData.Blocks.Lapis_Lazuli_Ore:
                            give = (short)BlockData.Items.Ink_Sack;
                            durability = 4;
                            count = (sbyte)(3 + Server.Rand.Next(17));
                            break;

                        case BlockData.Blocks.Lava:
                            return;

                        case BlockData.Blocks.Leaves:
                            give = Server.Rand.Next(5) == 0 ? (short)BlockData.Blocks.Sapling : (short)-1;
                            break;

                        case BlockData.Blocks.Portal:
                        case BlockData.Blocks.Mob_Spawner:
                            give = -1;
                            break;

                        case BlockData.Blocks.Redstone_Ore_Glowing:
                        case BlockData.Blocks.Redstone_Ore:
                            give = (short)BlockData.Items.Redstone;
                            count = (sbyte)(2 + Server.Rand.Next(4));
                            break;

                        case BlockData.Blocks.Redstone_Repeater:
                        case BlockData.Blocks.Redstone_Repeater_On:
                            give = (short)BlockData.Items.Redstone_Repeater;
                            break;

                        case BlockData.Blocks.Redstone_Torch_On:
                            give = (short)BlockData.Blocks.Redstone_Torch;
                            break;

                        case BlockData.Blocks.Redstone_Wire:
                            give = (short)BlockData.Items.Redstone;
                            break;

                        case BlockData.Blocks.Sign_Post:
                            give = (short)BlockData.Items.Sign;
                            break;
                        case BlockData.Blocks.Snow:
                            give = (short)BlockData.Items.Snowball;
                            break;

                        case BlockData.Blocks.Snow_Block:
                            give = (short)BlockData.Items.Snowball;
                            count = 3;
                            break;

                        case BlockData.Blocks.Stationary_Lava:
                        case BlockData.Blocks.Stationary_Water:
                            return;

                        case BlockData.Blocks.Stone:
                            give = (short)BlockData.Blocks.Cobblestone;
                            break;
                        case BlockData.Blocks.TNT:
                            // TODO: Spawn TNT Object and start explosion timer.
                            return;

                        case BlockData.Blocks.Wall_Sign:
                            give = (short)BlockData.Items.Sign;
                            break;

                        case BlockData.Blocks.Water:
                            return;
                    }
                    foreach (Client cl in Server.GetNearbyPlayers(World, Position.X, Position.Y, Position.Z))
                    {
                        cl.PacketHandler.SendPacket(new SoundEffectPacket
                        {
                            EffectID = SoundEffectPacket.SoundEffect.BLOCK_BREAK,
                            X = e.Packet.X,
                            Y = (byte)e.Packet.Y,
                            Z = e.Packet.Z,
                            SoundData = World.GetBlockId(x, y, z)
                        });
                    }
                    World.SetBlockAndData(x, y, z, 0, 0);
                    Chunk c = World[x >> 4, z >> 4, false, false];
                    c.RecalculateHeight(x & 0xf, z & 0xf);
                    c.RecalculateSky(x & 0xf, z & 0xf);
                    c.SpreadSkyLightFromBlock((byte)(x & 0xf), (byte)y, (byte)(z & 0xf));
                    World.Update(x, y, z, false);

                    if (GameMode == 0)
                    {
                        Inventory.DamageItem(Inventory.ActiveSlot);

                        if (give > 0)
                            Server.DropItem(World, x, y, z, new ItemStack(give, count, durability));
                    }
                    break;
            }
        }
Beispiel #3
0
        private void PacketHandler_PlayerDigging(object sender, PacketEventArgs<PlayerDiggingPacket> e)
        {
            int x = e.Packet.X;
            int y = e.Packet.Y;
            int z = e.Packet.Z;

            byte type = World.GetBlockId(x, y, z);
            byte data = World.GetBlockData(x, y, z);

            switch (e.Packet.Action)
            {
                case PlayerDiggingPacket.DigAction.StartDigging:
                    if (BlockData.SingleHit.Contains((BlockData.Blocks)type))
                        goto case PlayerDiggingPacket.DigAction.FinishDigging;
                    break;

                case PlayerDiggingPacket.DigAction.FinishDigging:
                    short give = type;
                    sbyte count = 1;
                    short durability = data;

                    switch ((BlockData.Blocks)type)
                    {
                        case BlockData.Blocks.Adminium:
                            return;

                        case BlockData.Blocks.Air:
                            return;

                        case BlockData.Blocks.Bed:
                            give = (short)BlockData.Items.Bed;
                            break;

                        case BlockData.Blocks.Burning_Furnace:
                        case BlockData.Blocks.Furnace:
                            give = (short)BlockData.Blocks.Furnace;
                            FurnaceInterface fi = new FurnaceInterface(this.World, x, y, z);
                            fi.Associate(this);
                            fi.DropAll(x, y, z);
                            fi.Save();
                            break;

                        case BlockData.Blocks.Cake:
                            give = (short)BlockData.Items.Cake;
                            break;

                        case BlockData.Blocks.Chest:
                            // Need to drop the chest contents
                            SmallChestInterface sci = new SmallChestInterface(this.World, x, y, z);
                            sci.Associate(this);
                            sci.DropAll(x, y, z);
                            sci.Save();
                            break;

                        case BlockData.Blocks.Clay:
                            give = (short)BlockData.Items.Clay_Balls;
                            count = 4;
                            break;

                        case BlockData.Blocks.Coal_Ore:
                            give = (short)BlockData.Items.Coal;
                            //count = (sbyte)(1 + Server.Rand.Next(3));
                            break;
                        case BlockData.Blocks.Crops:
                            // TODO: Check crops are mature enough before giving items.
                            give = (short)BlockData.Items.Seeds;
                            count = 2;
                            break;

                        case BlockData.Blocks.Diamond_Ore:
                            give = (short)BlockData.Items.Diamond;
                            break;

                        case BlockData.Blocks.Dispenser:
                            // Drop the contents of the dispenser
                            DispenserInterface di = new DispenserInterface(this.World, x, y, z);
                            di.Associate(this);
                            di.DropAll(x, y, z);
                            di.Save();
                            break;

                        case BlockData.Blocks.Double_Stone_Slab:
                            give = (short)BlockData.Blocks.Stair;
                            break;

                        case BlockData.Blocks.Fire:
                            return;

                        case BlockData.Blocks.Glass:
                            give = -1;
                            break;

                        case BlockData.Blocks.Glowstone:
                            give = (short)BlockData.Items.Lightstone_Dust;
                            break;

                        case BlockData.Blocks.Grass:
                        case BlockData.Blocks.Soil:
                            give = (short)BlockData.Blocks.Dirt;
                            break;

                        case BlockData.Blocks.Gravel:
                            if (Server.Rand.Next(10) == 0)
                                Server.DropItem(World, x, y, z, new ItemStack((short)BlockData.Items.Flint));
                            break;

                        case BlockData.Blocks.Ice:
                            if (BlockData.Air.Contains((BlockData.Blocks)World.GetBlockId(x, y - 1, z)))
                            {
                                World.SetBlockAndData(x, y, z, 0, 0);
                                return;
                            }
                            World.SetBlockAndData(x, y, z, (byte)BlockData.Blocks.Still_Water, 0);
                            return;

                        case BlockData.Blocks.Lapis_Lazuli_Ore:
                            give = (short)BlockData.Items.Ink_Sack;
                            durability = 4;
                            count = (sbyte)(3 + Server.Rand.Next(17));
                            break;

                        case BlockData.Blocks.Lava:
                            return;

                        case BlockData.Blocks.Leaves:
                            give = Server.Rand.Next(5) == 0 ? (short)BlockData.Blocks.Sapling : (short)-1;
                            break;

                        case BlockData.Blocks.Portal:
                        case BlockData.Blocks.Mob_Spawner:
                            give = -1;
                            break;

                        case BlockData.Blocks.Redstone_Ore_Glowing:
                        case BlockData.Blocks.Redstone_Ore:
                            give = (short)BlockData.Items.Redstone;
                            count = (sbyte)(2 + Server.Rand.Next(4));
                            break;

                        case BlockData.Blocks.Redstone_Repeater:
                        case BlockData.Blocks.Redstone_Repeater_On:
                            give = (short)BlockData.Items.Redstone_Repeater;
                            break;

                        case BlockData.Blocks.Redstone_Torch_On:
                            give = (short)BlockData.Blocks.Redstone_Torch;
                            break;

                        case BlockData.Blocks.Redstone_Wire:
                            give = (short)BlockData.Items.Redstone;
                            break;

                        case BlockData.Blocks.Sign_Post:
                            give = (short)BlockData.Items.Sign;
                            break;
                        case BlockData.Blocks.Snow:
                            give = (short)BlockData.Items.Snowball;
                            break;

                        case BlockData.Blocks.Snow_Block:
                            give = (short)BlockData.Items.Snowball;
                            count = 3;
                            break;

                        case BlockData.Blocks.Stationary_Lava:
                        case BlockData.Blocks.Stationary_Water:
                            return;

                        case BlockData.Blocks.Stone:
                            give = (short)BlockData.Blocks.Cobblestone;
                            break;
                        case BlockData.Blocks.TNT:
                            // TODO: Spawn TNT Object and start explosion timer.
                            return;

                        case BlockData.Blocks.Wall_Sign:
                            give = (short)BlockData.Items.Sign;
                            break;

                        case BlockData.Blocks.Water:
                            return;
                    }

                    World.SetBlockAndData(x, y, z, 0, 0);
                    World.Update(x, y, z);

                    Inventory.DamageItem(Inventory.ActiveSlot);

                    if (give > 0)
                        Server.DropItem(World, x, y, z, new ItemStack(give, count, durability));
                    break;
            }
        }