mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +00:00
Implemented basic player inventory items handle
This commit is contained in:
parent
51d03b9ced
commit
8b8f3a719b
3 changed files with 44 additions and 1 deletions
|
|
@ -57,6 +57,9 @@ namespace MinecraftClient
|
|||
private object lastKeepAliveLock = new object();
|
||||
|
||||
private int playerEntityID;
|
||||
// not really understand the Inventory Class
|
||||
// so I use a Dict instead for player inventory
|
||||
private Dictionary<int, Item> playerItems;
|
||||
|
||||
// auto attack
|
||||
private class Entity
|
||||
|
|
@ -763,6 +766,23 @@ namespace MinecraftClient
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// When received window items from server.
|
||||
/// </summary>
|
||||
/// <param name="type"></param>
|
||||
/// <param name="itemList"></param>
|
||||
public void OnWindowItems(int type, Dictionary<int, Item> itemList)
|
||||
{
|
||||
// player inventory
|
||||
//if (type == 0)
|
||||
// playerItems = itemList;
|
||||
foreach(KeyValuePair<int,Item> pair in itemList)
|
||||
{
|
||||
ConsoleIO.WriteLine("Slot: "+pair.Key+" itemID:"+pair.Value.id);
|
||||
}
|
||||
ConsoleIO.WriteLine("Type: "+type);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// When connection has been lost, login was denied or played was kicked from the server
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -510,8 +510,11 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
}
|
||||
break;
|
||||
case PacketIncomingType.WindowItems:
|
||||
if (handler.GetInventoryEnabled())
|
||||
if (handler.GetInventoryEnabled()||true)
|
||||
{
|
||||
/*
|
||||
* Following commented code not working
|
||||
*
|
||||
byte id = dataTypes.ReadNextByte(packetData);
|
||||
short elements = dataTypes.ReadNextShort(packetData);
|
||||
|
||||
|
|
@ -528,6 +531,24 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
dataTypes.ReadNextNbt(packetData);
|
||||
}
|
||||
}
|
||||
*/
|
||||
byte id = dataTypes.ReadNextByte(packetData);
|
||||
short elements = dataTypes.ReadNextShort(packetData);
|
||||
Dictionary<int, Item> itemsList = new Dictionary<int, Item>(); // index is SlotID
|
||||
for(int i = 0; i < elements; i++)
|
||||
{
|
||||
bool haveItem = dataTypes.ReadNextBool(packetData);
|
||||
if (haveItem)
|
||||
{
|
||||
int itemID = dataTypes.ReadNextVarInt(packetData);
|
||||
byte itemCount = dataTypes.ReadNextByte(packetData);
|
||||
dataTypes.ReadNextNbt(packetData);
|
||||
|
||||
Item item = new Item(itemID, itemCount);
|
||||
itemsList.Add(i, item);
|
||||
}
|
||||
}
|
||||
handler.OnWindowItems(id, itemsList);
|
||||
}
|
||||
break;
|
||||
case PacketIncomingType.ResourcePackSend:
|
||||
|
|
|
|||
|
|
@ -144,6 +144,8 @@ namespace MinecraftClient.Protocol
|
|||
|
||||
void OnEntityStatus(int EntityID, byte EntityStatus);
|
||||
|
||||
void OnWindowItems(int type, Dictionary<int, Item> itemList);
|
||||
|
||||
void SetPlayerEntityID(int EntityID);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue