Decode and store inventory updates from server
This commit is contained in:
parent
b0c41ffdcc
commit
8d8da15f5a
@ -9,7 +9,7 @@ using TrueCraft.API.World;
|
||||
|
||||
namespace TrueCraft.Client.Handlers
|
||||
{
|
||||
internal static class ChunkHandler
|
||||
internal static class ChunkHandlers
|
||||
{
|
||||
public static void HandleBlockChange(IPacket _packet, MultiplayerClient client)
|
||||
{
|
41
TrueCraft.Client/Handlers/InventoryHandlers.cs
Normal file
41
TrueCraft.Client/Handlers/InventoryHandlers.cs
Normal file
@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using TrueCraft.API.Networking;
|
||||
using TrueCraft.Core.Networking.Packets;
|
||||
using TrueCraft.API.Windows;
|
||||
using TrueCraft.API;
|
||||
|
||||
namespace TrueCraft.Client.Handlers
|
||||
{
|
||||
internal static class InventoryHandlers
|
||||
{
|
||||
public static void HandleWindowItems(IPacket _packet, MultiplayerClient client)
|
||||
{
|
||||
var packet = (WindowItemsPacket)_packet;
|
||||
if (packet.WindowID == 0)
|
||||
client.Inventory.SetSlots(packet.Items);
|
||||
else
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
|
||||
public static void HandleSetSlot(IPacket _packet, MultiplayerClient client)
|
||||
{
|
||||
var packet = (SetSlotPacket)_packet;
|
||||
IWindow window = null;
|
||||
if (packet.WindowID == 0)
|
||||
window = client.Inventory;
|
||||
else
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
if (window != null)
|
||||
{
|
||||
if (packet.SlotIndex >= 0 && packet.SlotIndex < window.Length)
|
||||
{
|
||||
window[packet.SlotIndex] = new ItemStack(packet.ItemID, packet.Count, packet.Metadata);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -17,9 +17,12 @@ namespace TrueCraft.Client.Handlers
|
||||
client.RegisterPacketHandler(new SetPlayerPositionPacket().ID, HandlePositionAndLook);
|
||||
client.RegisterPacketHandler(new LoginResponsePacket().ID, HandleLoginResponse);
|
||||
|
||||
client.RegisterPacketHandler(new ChunkPreamblePacket().ID, ChunkHandler.HandleChunkPreamble);
|
||||
client.RegisterPacketHandler(new ChunkDataPacket().ID, ChunkHandler.HandleChunkData);
|
||||
client.RegisterPacketHandler(new BlockChangePacket().ID, ChunkHandler.HandleBlockChange);
|
||||
client.RegisterPacketHandler(new ChunkPreamblePacket().ID, ChunkHandlers.HandleChunkPreamble);
|
||||
client.RegisterPacketHandler(new ChunkDataPacket().ID, ChunkHandlers.HandleChunkData);
|
||||
client.RegisterPacketHandler(new BlockChangePacket().ID, ChunkHandlers.HandleBlockChange);
|
||||
|
||||
client.RegisterPacketHandler(new WindowItemsPacket().ID, InventoryHandlers.HandleWindowItems);
|
||||
client.RegisterPacketHandler(new SetSlotPacket().ID, InventoryHandlers.HandleSetSlot);
|
||||
}
|
||||
|
||||
public static void HandleChatMessage(IPacket _packet, MultiplayerClient client)
|
||||
|
@ -5,6 +5,7 @@ using TrueCraft.Client.Input;
|
||||
using TrueCraft.Client.Rendering;
|
||||
using TrueCraft.API;
|
||||
using System;
|
||||
using System.Text;
|
||||
|
||||
namespace TrueCraft.Client.Modules
|
||||
{
|
||||
@ -92,6 +93,18 @@ namespace TrueCraft.Client.Modules
|
||||
Font.DrawText(SpriteBatch, xOrigin, yOrigin + (yOffset * 3),
|
||||
string.Format(ChatColor.Gray + "{0} pending chunks", Game.ChunkModule.ChunkRenderer.PendingChunks));
|
||||
|
||||
var sb = new StringBuilder(ChatColor.DarkGray + "inv: ");
|
||||
for (int i = 0; i < Game.Client.Inventory.Hotbar.Length; i++)
|
||||
{
|
||||
var provider = Game.ItemRepository.GetItemProvider(Game.Client.Inventory.Hotbar[i].ID);
|
||||
if (provider != null)
|
||||
sb.Append(provider.DisplayName + " ");
|
||||
else
|
||||
sb.Append("[empty]");
|
||||
}
|
||||
|
||||
Font.DrawText(SpriteBatch, xOrigin, yOrigin + (yOffset * 4), sb.ToString());
|
||||
|
||||
SpriteBatch.End();
|
||||
}
|
||||
|
||||
|
@ -16,6 +16,7 @@ using System.IO;
|
||||
using TrueCraft.Core;
|
||||
using TrueCraft.API.Physics;
|
||||
using TrueCraft.Core.Physics;
|
||||
using TrueCraft.Core.Windows;
|
||||
|
||||
namespace TrueCraft.Client
|
||||
{
|
||||
@ -36,6 +37,7 @@ namespace TrueCraft.Client
|
||||
public PhysicsEngine Physics { get; set; }
|
||||
public bool LoggedIn { get; internal set; }
|
||||
public int EntityID { get; internal set; }
|
||||
public InventoryWindow Inventory { get; set; }
|
||||
|
||||
public bool Connected
|
||||
{
|
||||
@ -66,6 +68,7 @@ namespace TrueCraft.Client
|
||||
PacketHandlers = new PacketHandler[0x100];
|
||||
Handlers.PacketHandlers.RegisterHandlers(this);
|
||||
World = new ReadOnlyWorld();
|
||||
Inventory = new InventoryWindow(null);
|
||||
var repo = new BlockRepository();
|
||||
repo.DiscoverBlockProviders();
|
||||
World.World.BlockRepository = repo;
|
||||
|
@ -101,7 +101,6 @@
|
||||
<Compile Include="Handlers\PacketHandlers.cs" />
|
||||
<Compile Include="Events\ChatMessageEventArgs.cs" />
|
||||
<Compile Include="BMFont.cs" />
|
||||
<Compile Include="Handlers\ChunkHandler.cs" />
|
||||
<Compile Include="ReadOnlyWorld.cs" />
|
||||
<Compile Include="Events\ChunkEventArgs.cs" />
|
||||
<Compile Include="Rendering\Mesh.cs" />
|
||||
@ -135,6 +134,8 @@
|
||||
<Compile Include="Modules\DebugInfoModule.cs" />
|
||||
<Compile Include="Modules\HUDModule.cs" />
|
||||
<Compile Include="Rendering\Blocks\CactusRenderer.cs" />
|
||||
<Compile Include="Handlers\InventoryHandlers.cs" />
|
||||
<Compile Include="Handlers\ChunkHandlers.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<ItemGroup>
|
||||
|
@ -18,6 +18,8 @@ namespace TrueCraft.Core.Windows
|
||||
|
||||
private void HandleWindowChange(object sender, WindowChangeEventArgs e)
|
||||
{
|
||||
if (Repository == null)
|
||||
return;
|
||||
var current = Repository.GetRecipe(Bench);
|
||||
if (e.SlotIndex == CraftingOutput)
|
||||
{
|
||||
|
Reference in New Issue
Block a user