Give players an inventory and send it to clients

This also gives the player a stack of stone to play with on login, but
that's a temporary change.
This commit is contained in:
Drew DeVault 2014-12-28 12:09:55 -07:00
parent f02dcd9004
commit c7a11b320d
4 changed files with 22 additions and 0 deletions

View File

@ -1,6 +1,7 @@
using System;
using TrueCraft.API.World;
using TrueCraft.API.Entities;
using TrueCraft.API.Windows;
namespace TrueCraft.API.Networking
{
@ -10,6 +11,7 @@ namespace TrueCraft.API.Networking
bool DataAvailable { get; }
IWorld World { get; }
IEntity Entity { get; }
IWindow Inventory { get; }
void QueuePacket(IPacket packet);
}

View File

@ -11,6 +11,12 @@ namespace TrueCraft.Core.Networking.Packets
{
public byte ID { get { return 0x68; } }
public WindowItemsPacket(sbyte windowID, ItemStack[] items)
{
WindowID = windowID;
Items = items;
}
public sbyte WindowID;
public ItemStack[] Items;

View File

@ -38,6 +38,7 @@ namespace TrueCraft.Handlers
client.QueuePacket(new LoginResponsePacket(0, 0, Dimension.Overworld));
client.ChunkRadius = 2;
client.UpdateChunks();
client.QueuePacket(new WindowItemsPacket(0, client.Inventory.GetSlots()));
client.QueuePacket(new SpawnPositionPacket(0, 16, 0));
client.QueuePacket(new SetPlayerPositionPacket(0, 16, 17, 0, 0, 0, true));
server.Scheduler.ScheduleEvent(DateTime.Now.AddSeconds(10), client.SendKeepAlive);

View File

@ -12,6 +12,8 @@ using System.Linq;
using TrueCraft.Core.Networking.Packets;
using TrueCraft.Core.World;
using Ionic.Zlib;
using TrueCraft.API.Windows;
using TrueCraft.Core.Windows;
namespace TrueCraft
{
@ -24,6 +26,8 @@ namespace TrueCraft
PacketQueue = new ConcurrentQueue<IPacket>();
LoadedChunks = new List<Coordinates2D>();
Server = server;
Inventory = new InventoryWindow();
InventoryWindow.Hotbar[0] = new ItemStack(1, 64);
}
public NetworkStream NetworkStream { get; set; }
@ -34,6 +38,15 @@ namespace TrueCraft
public IMultiplayerServer Server { get; set; }
public IWorld World { get; internal set; }
public IEntity Entity { get; internal set; }
public IWindow Inventory { get; private set; }
public InventoryWindow InventoryWindow
{
get
{
return Inventory as InventoryWindow;
}
}
internal int ChunkRadius { get; set; }
internal IList<Coordinates2D> LoadedChunks { get; set; }