diff --git a/TrueCraft.Core/Logic/Blocks/ChestBlock.cs b/TrueCraft.Core/Logic/Blocks/ChestBlock.cs index 7aabd61..17fa7fb 100644 --- a/TrueCraft.Core/Logic/Blocks/ChestBlock.cs +++ b/TrueCraft.Core/Logic/Blocks/ChestBlock.cs @@ -6,6 +6,8 @@ using TrueCraft.API.World; using TrueCraft.API.Networking; using fNbt; using TrueCraft.Core.Windows; +using System.Collections.Generic; +using TrueCraft.Core.Entities; namespace TrueCraft.Core.Logic.Blocks { @@ -204,5 +206,22 @@ namespace TrueCraft.Core.Logic.Blocks user.OpenWindow(window); return false; } + + public override void BlockMined(BlockDescriptor descriptor, BlockFace face, IWorld world, IRemoteClient user) + { + var self = descriptor.Coordinates; + var entity = world.GetTileEntity(self); + var manager = user.Server.GetEntityManagerForWorld(world); + if (entity != null) + { + foreach (var item in (NbtList)entity["Items"]) + { + var slot = ItemStack.FromNbt((NbtCompound)item); + manager.SpawnEntity(new ItemEntity(descriptor.Coordinates + new Vector3(0.5), slot)); + } + } + world.SetTileEntity(self, null); + base.BlockMined(descriptor, face, world, user); + } } } \ No newline at end of file diff --git a/TrueCraft.Core/Logic/Blocks/UprightSignBlock.cs b/TrueCraft.Core/Logic/Blocks/UprightSignBlock.cs index 23b29f2..84ee780 100644 --- a/TrueCraft.Core/Logic/Blocks/UprightSignBlock.cs +++ b/TrueCraft.Core/Logic/Blocks/UprightSignBlock.cs @@ -44,6 +44,12 @@ namespace TrueCraft.Core.Logic.Blocks return new[] { new ItemStack(SignItem.ItemID) }; } + public override void BlockMined(BlockDescriptor descriptor, BlockFace face, IWorld world, IRemoteClient user) + { + world.SetTileEntity(descriptor.Coordinates, null); + base.BlockMined(descriptor, face, world, user); + } + public override void TileEntityLoadedForClient(BlockDescriptor descriptor, IWorld world, NbtCompound entity, IRemoteClient client) { client.QueuePacket(new UpdateSignPacket diff --git a/TrueCraft.Core/Logic/Blocks/WallSignBlock.cs b/TrueCraft.Core/Logic/Blocks/WallSignBlock.cs index bffa96b..be084fd 100644 --- a/TrueCraft.Core/Logic/Blocks/WallSignBlock.cs +++ b/TrueCraft.Core/Logic/Blocks/WallSignBlock.cs @@ -40,21 +40,27 @@ namespace TrueCraft.Core.Logic.Blocks return new[] { new ItemStack(SignItem.ItemID) }; } + public override void BlockMined(BlockDescriptor descriptor, BlockFace face, IWorld world, IRemoteClient user) + { + world.SetTileEntity(descriptor.Coordinates, null); + base.BlockMined(descriptor, face, world, user); + } + public override void TileEntityLoadedForClient(BlockDescriptor descriptor, IWorld world, NbtCompound entity, IRemoteClient client) { client.QueuePacket(new UpdateSignPacket + { + X = descriptor.Coordinates.X, + Y = (short)descriptor.Coordinates.Y, + Z = descriptor.Coordinates.Z, + Text = new[] { - X = descriptor.Coordinates.X, - Y = (short)descriptor.Coordinates.Y, - Z = descriptor.Coordinates.Z, - Text = new[] - { - entity["Text1"].StringValue, - entity["Text2"].StringValue, - entity["Text3"].StringValue, - entity["Text4"].StringValue - } - }); + entity["Text1"].StringValue, + entity["Text2"].StringValue, + entity["Text3"].StringValue, + entity["Text4"].StringValue + } + }); } } } \ No newline at end of file diff --git a/TrueCraft.Core/World/Chunk.cs b/TrueCraft.Core/World/Chunk.cs index 4217ea2..745b2f1 100644 --- a/TrueCraft.Core/World/Chunk.cs +++ b/TrueCraft.Core/World/Chunk.cs @@ -177,7 +177,10 @@ namespace TrueCraft.Core.World /// public void SetTileEntity(Coordinates3D coordinates, NbtCompound value) { - TileEntities[coordinates] = value; + if (value == null && TileEntities.ContainsKey(coordinates)) + TileEntities.Remove(coordinates); + else + TileEntities[coordinates] = value; IsModified = true; } diff --git a/TrueCraft/Handlers/InteractionHandlers.cs b/TrueCraft/Handlers/InteractionHandlers.cs index c3c7db2..4fa58ac 100644 --- a/TrueCraft/Handlers/InteractionHandlers.cs +++ b/TrueCraft/Handlers/InteractionHandlers.cs @@ -9,6 +9,8 @@ using TrueCraft.Core.Windows; using TrueCraft.API.Logic; using TrueCraft.Core.Entities; using fNbt; +using TrueCraft.Core.Logic.Blocks; +using System.Linq; namespace TrueCraft.Handlers { @@ -286,14 +288,19 @@ namespace TrueCraft.Handlers var coords = new Coordinates3D(packet.X, packet.Y, packet.Z); if (client.Entity.Position.DistanceTo(coords) < 10) // TODO: Reach { - client.World.SetTileEntity(coords, new NbtCompound(new[] + var block = client.World.GetBlockID(coords); + if (block == UprightSignBlock.BlockID || block == WallSignBlock.BlockID) { - new NbtString("Text1", packet.Text[0]), - new NbtString("Text2", packet.Text[1]), - new NbtString("Text3", packet.Text[2]), - new NbtString("Text4", packet.Text[3]), - })); - client.QueuePacket(packet); + client.World.SetTileEntity(coords, new NbtCompound(new[] + { + new NbtString("Text1", packet.Text[0]), + new NbtString("Text2", packet.Text[1]), + new NbtString("Text3", packet.Text[2]), + new NbtString("Text4", packet.Text[3]), + })); + // TODO: Some utility methods for things like "clients with given chunk loaded" + server.Clients.Where(c => ((RemoteClient)c).LoggedIn && c.World == _client.World).ToList().ForEach(c => c.QueuePacket(packet)); + } } } }