Add inventory type convert

This commit is contained in:
ReinforceZwei 2020-03-26 17:15:00 +08:00 committed by ORelio
parent e9613ad366
commit 13206614c4
5 changed files with 49 additions and 33 deletions

View file

@ -26,10 +26,11 @@ namespace MinecraftClient.Inventory
Title = title; Title = title;
Items = items; Items = items;
} }
public Container(int id, Protocol.InventoryType type, string title) public Container(int id, ContainerTypeOld type, string title)
{ {
ID = id; ID = id;
Title = title; Title = title;
Type = ConvertType.ToNew(type);
} }
public Container(int id, int typeID, string title) public Container(int id, int typeID, string title)
{ {

View file

@ -31,8 +31,47 @@ namespace MinecraftClient.Inventory
Smoker, Smoker,
Cartography, Cartography,
Stonecutter, Stonecutter,
// not in the list // not in the wiki.vg list
PlayerInventory, PlayerInventory,
Unknown Unknown
} }
public enum ContainerTypeOld
{
CONTAINER,
CHEST,
CRAFTING_TABLE,
FURNACE,
DISPENSER,
ENCHANTING_TABLE,
BREWING_STAND,
VILLAGER,
BEACON,
ANVIL,
HOPPER,
DROPPER,
SHULKER_BOX,
ENTITYHORSE
}
public static class ConvertType
{
public static ContainerType ToNew(ContainerTypeOld type)
{
switch (type)
{
case ContainerTypeOld.CONTAINER: return ContainerType.Unknown;
case ContainerTypeOld.CHEST: return ContainerType.Generic_9x3;
case ContainerTypeOld.CRAFTING_TABLE: return ContainerType.Crafting;
case ContainerTypeOld.FURNACE: return ContainerType.Furnace;
case ContainerTypeOld.DISPENSER: return ContainerType.Generic_3x3;
case ContainerTypeOld.ENCHANTING_TABLE: return ContainerType.Enchantment;
case ContainerTypeOld.BREWING_STAND: return ContainerType.BrewingStand;
case ContainerTypeOld.VILLAGER: return ContainerType.Merchant;
case ContainerTypeOld.HOPPER: return ContainerType.Hopper;
case ContainerTypeOld.DROPPER: return ContainerType.Generic_3x3;
case ContainerTypeOld.SHULKER_BOX: return ContainerType.ShulkerBox;
case ContainerTypeOld.ENTITYHORSE: return ContainerType.Unknown;
default: return ContainerType.Unknown;
}
}
}
} }

View file

@ -262,9 +262,6 @@
<Compile Include="Commands\List.cs" /> <Compile Include="Commands\List.cs" />
<Compile Include="Mapping\Location.cs" /> <Compile Include="Mapping\Location.cs" />
<Compile Include="WinAPI\WindowsVersion.cs" /> <Compile Include="WinAPI\WindowsVersion.cs" />
<Compile Include="Protocol\Inventory.cs" />
<Compile Include="Protocol\InventoryType.cs" />
<Compile Include="Protocol\Item.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.0,Profile=Client"> <BootstrapperPackage Include=".NETFramework,Version=v4.0,Profile=Client">

View file

@ -10,6 +10,7 @@ using System.Security.Cryptography;
using MinecraftClient.Mapping; using MinecraftClient.Mapping;
using MinecraftClient.Mapping.BlockPalettes; using MinecraftClient.Mapping.BlockPalettes;
using MinecraftClient.Protocol.Handlers.Forge; using MinecraftClient.Protocol.Handlers.Forge;
using MinecraftClient.Inventory;
namespace MinecraftClient.Protocol.Handlers namespace MinecraftClient.Protocol.Handlers
{ {
@ -494,12 +495,11 @@ namespace MinecraftClient.Protocol.Handlers
{ {
byte windowID = dataTypes.ReadNextByte(packetData); byte windowID = dataTypes.ReadNextByte(packetData);
string type = dataTypes.ReadNextString(packetData).Replace("minecraft:", "").ToUpper(); string type = dataTypes.ReadNextString(packetData).Replace("minecraft:", "").ToUpper();
InventoryType inventoryType = (InventoryType)Enum.Parse(typeof(InventoryType), type); ContainerTypeOld inventoryType = (ContainerTypeOld)Enum.Parse(typeof(ContainerTypeOld), type);
string title = dataTypes.ReadNextString(packetData); string title = dataTypes.ReadNextString(packetData);
byte slots = dataTypes.ReadNextByte(packetData); byte slots = dataTypes.ReadNextByte(packetData);
// TODO: Container inventory = new Container(windowID, inventoryType, title);
MinecraftClient.Inventory.Container inventory = new MinecraftClient.Inventory.Container(windowID, inventoryType, title);
handler.OnInventoryOpen(inventory); handler.OnInventoryOpen(inventory);
} }
@ -508,7 +508,7 @@ namespace MinecraftClient.Protocol.Handlers
int WindowID = dataTypes.ReadNextVarInt(packetData); int WindowID = dataTypes.ReadNextVarInt(packetData);
int WindowType = dataTypes.ReadNextVarInt(packetData); int WindowType = dataTypes.ReadNextVarInt(packetData);
string title = dataTypes.ReadNextString(packetData); string title = dataTypes.ReadNextString(packetData);
MinecraftClient.Inventory.Container inventory = new MinecraftClient.Inventory.Container(WindowID, WindowType, title); Container inventory = new Container(WindowID, WindowType, title);
handler.OnInventoryOpen(inventory); handler.OnInventoryOpen(inventory);
} }
@ -547,7 +547,7 @@ namespace MinecraftClient.Protocol.Handlers
*/ */
byte id = dataTypes.ReadNextByte(packetData); byte id = dataTypes.ReadNextByte(packetData);
short elements = dataTypes.ReadNextShort(packetData); short elements = dataTypes.ReadNextShort(packetData);
Dictionary<int, MinecraftClient.Inventory.Item> itemsList = new Dictionary<int, MinecraftClient.Inventory.Item>(); // index is SlotID Dictionary<int, Item> itemsList = new Dictionary<int, Item>(); // index is SlotID
for(int i = 0; i < elements; i++) for(int i = 0; i < elements; i++)
{ {
bool haveItem = dataTypes.ReadNextBool(packetData); bool haveItem = dataTypes.ReadNextBool(packetData);
@ -557,7 +557,7 @@ namespace MinecraftClient.Protocol.Handlers
byte itemCount = dataTypes.ReadNextByte(packetData); byte itemCount = dataTypes.ReadNextByte(packetData);
dataTypes.ReadNextNbt(packetData); dataTypes.ReadNextNbt(packetData);
MinecraftClient.Inventory.Item item = new MinecraftClient.Inventory.Item(itemID, itemCount); Item item = new Item(itemID, itemCount);
itemsList.Add(i, item); itemsList.Add(i, item);
} }
} }

View file

@ -1,21 +0,0 @@
using System;
namespace MinecraftClient.Protocol
{
public enum InventoryType
{
CONTAINER,
CHEST,
CRAFTING_TABLE,
FURNACE,
DISPENSER,
ENCHANTING_TABLE,
BREWING_STAND,
VILLAGER,
BEACON,
ANVIL,
HOPPER,
DROPPER,
SHULKER_BOX,
ENTITYHORSE
}
}