From 06a928edbf4eb6b4ac2e30824a2f75d750fdce8f Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Wed, 15 Apr 2015 19:21:55 -0600 Subject: [PATCH] Implement cake logic --- TrueCraft.Core/Logic/Blocks/CakeBlock.cs | 11 +++++++++++ TrueCraft.Core/Logic/Items/CakeItem.cs | 15 +++++++++++++++ TrueCraft/Handlers/InteractionHandlers.cs | 2 ++ 3 files changed, 28 insertions(+) diff --git a/TrueCraft.Core/Logic/Blocks/CakeBlock.cs b/TrueCraft.Core/Logic/Blocks/CakeBlock.cs index e643f6b..0cdd132 100644 --- a/TrueCraft.Core/Logic/Blocks/CakeBlock.cs +++ b/TrueCraft.Core/Logic/Blocks/CakeBlock.cs @@ -2,6 +2,8 @@ using System; using TrueCraft.API; using TrueCraft.API.Logic; using TrueCraft.Core.Logic.Items; +using TrueCraft.API.World; +using TrueCraft.API.Networking; namespace TrueCraft.Core.Logic.Blocks { @@ -60,5 +62,14 @@ namespace TrueCraft.Core.Logic.Blocks { get { return false; } } + + public override bool BlockRightClicked(BlockDescriptor descriptor, BlockFace face, IWorld world, IRemoteClient user) + { + if (descriptor.Metadata == 5) + world.SetBlockID(descriptor.Coordinates, AirBlock.BlockID); + else + world.SetMetadata(descriptor.Coordinates, (byte)(descriptor.Metadata + 1)); + return false; + } } } \ No newline at end of file diff --git a/TrueCraft.Core/Logic/Items/CakeItem.cs b/TrueCraft.Core/Logic/Items/CakeItem.cs index 7fbcab6..ab0364a 100644 --- a/TrueCraft.Core/Logic/Items/CakeItem.cs +++ b/TrueCraft.Core/Logic/Items/CakeItem.cs @@ -1,6 +1,9 @@ using System; using TrueCraft.API.Logic; using TrueCraft.API; +using TrueCraft.API.World; +using TrueCraft.API.Networking; +using TrueCraft.Core.Logic.Blocks; namespace TrueCraft.Core.Logic.Items { @@ -43,5 +46,17 @@ namespace TrueCraft.Core.Logic.Items return false; } } + + public override void ItemUsedOnBlock(Coordinates3D coordinates, ItemStack item, BlockFace face, IWorld world, IRemoteClient user) + { + coordinates += MathHelper.BlockFaceToCoordinates(face); + var old = world.BlockRepository.GetBlockProvider(world.GetBlockID(coordinates)); + if (old.Hardness == 0) + { + world.SetBlockID(coordinates, CakeBlock.BlockID); + item.Count--; + user.Inventory[user.SelectedSlot] = item; + } + } } } \ No newline at end of file diff --git a/TrueCraft/Handlers/InteractionHandlers.cs b/TrueCraft/Handlers/InteractionHandlers.cs index 3eee2df..1d63f45 100644 --- a/TrueCraft/Handlers/InteractionHandlers.cs +++ b/TrueCraft/Handlers/InteractionHandlers.cs @@ -139,6 +139,7 @@ namespace TrueCraft.Handlers client.ItemStaging = held; window[packet.SlotIndex] = ItemStack.EmptyStack; } + client.QueuePacket(new WindowItemsPacket(packet.WindowID, window.GetSlots())); return; } if (client.ItemStaging.Empty) // Picking up something @@ -209,6 +210,7 @@ namespace TrueCraft.Handlers } } } + client.QueuePacket(new WindowItemsPacket(packet.WindowID, window.GetSlots())); } public static void HandleCloseWindowPacket(IPacket _packet, IRemoteClient _client, IMultiplayerServer server)