mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-11-07 17:36:07 +00:00
Fix backwards support for entity, inventory handling
Seems AutoAttack not work in 1.12.2 Entity handling currently only support 1.13 or higher
This commit is contained in:
parent
13206614c4
commit
311815be9f
2 changed files with 118 additions and 43 deletions
|
|
@ -564,6 +564,27 @@ namespace MinecraftClient
|
||||||
return entityHandlingEnabled;
|
return entityHandlingEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool SetEntityHandlingEnabled(bool enabled)
|
||||||
|
{
|
||||||
|
if (!enabled)
|
||||||
|
{
|
||||||
|
if (entityHandlingEnabled)
|
||||||
|
{
|
||||||
|
entityHandlingEnabled = false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Entity Handling cannot be enabled in runtime (or after joining server)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get client player's inventory items
|
/// Get client player's inventory items
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -1104,6 +1125,7 @@ namespace MinecraftClient
|
||||||
/// <param name="location"></param>
|
/// <param name="location"></param>
|
||||||
public void OnSpawnEntity(int EntityID, int TypeID, Guid UUID, Location location)
|
public void OnSpawnEntity(int EntityID, int TypeID, Guid UUID, Location location)
|
||||||
{
|
{
|
||||||
|
if (entities.ContainsKey(EntityID)) return;
|
||||||
Entity entity = new Entity(EntityID, TypeID, EntityType.NonLivingThings, location);
|
Entity entity = new Entity(EntityID, TypeID, EntityType.NonLivingThings, location);
|
||||||
entities.Add(EntityID, entity);
|
entities.Add(EntityID, entity);
|
||||||
foreach (ChatBot bot in bots.ToArray())
|
foreach (ChatBot bot in bots.ToArray())
|
||||||
|
|
@ -1120,6 +1142,7 @@ namespace MinecraftClient
|
||||||
/// <remarks>Cannot determine is a Mob or a Cuty Animal</remarks>
|
/// <remarks>Cannot determine is a Mob or a Cuty Animal</remarks>
|
||||||
public void OnSpawnLivingEntity(int EntityID, int TypeID, Guid UUID, Location location)
|
public void OnSpawnLivingEntity(int EntityID, int TypeID, Guid UUID, Location location)
|
||||||
{
|
{
|
||||||
|
if (entities.ContainsKey(EntityID)) return;
|
||||||
Entity entity = new Entity(EntityID, TypeID, EntityType.MobAndAnimal, location);
|
Entity entity = new Entity(EntityID, TypeID, EntityType.MobAndAnimal, location);
|
||||||
entities.Add(EntityID, entity);
|
entities.Add(EntityID, entity);
|
||||||
foreach (ChatBot bot in bots.ToArray())
|
foreach (ChatBot bot in bots.ToArray())
|
||||||
|
|
@ -1136,6 +1159,7 @@ namespace MinecraftClient
|
||||||
/// <param name="Pitch"></param>
|
/// <param name="Pitch"></param>
|
||||||
public void OnSpawnPlayer(int EntityID, Guid UUID, Location location, byte Yaw, byte Pitch)
|
public void OnSpawnPlayer(int EntityID, Guid UUID, Location location, byte Yaw, byte Pitch)
|
||||||
{
|
{
|
||||||
|
if (entities.ContainsKey(EntityID)) return;
|
||||||
Entity entity = new Entity(EntityID, EntityType.Player, location);
|
Entity entity = new Entity(EntityID, EntityType.Player, location);
|
||||||
entities.Add(EntityID, entity);
|
entities.Add(EntityID, entity);
|
||||||
foreach (ChatBot bot in bots.ToArray())
|
foreach (ChatBot bot in bots.ToArray())
|
||||||
|
|
|
||||||
|
|
@ -69,12 +69,18 @@ namespace MinecraftClient.Protocol.Handlers
|
||||||
handler.SetTerrainEnabled(false);
|
handler.SetTerrainEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (handler.GetInventoryEnabled() && protocolversion > MC1152Version)
|
if (handler.GetInventoryEnabled() && (protocolversion > MC1152Version || protocolversion < MC110Version))
|
||||||
{
|
{
|
||||||
ConsoleIO.WriteLineFormatted("§8Inventories are currently not handled for that MC version.");
|
ConsoleIO.WriteLineFormatted("§8Inventories are currently not handled for that MC version.");
|
||||||
handler.SetInventoryEnabled(false);
|
handler.SetInventoryEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(handler.GetEntityHandlingEnabled() && protocolversion < MC1122Version)
|
||||||
|
{
|
||||||
|
ConsoleIO.WriteLineFormatted("§8Entities are currently not handled for that MC version.");
|
||||||
|
handler.SetInventoryEnabled(false);
|
||||||
|
}
|
||||||
|
|
||||||
if (protocolversion >= MC113Version)
|
if (protocolversion >= MC113Version)
|
||||||
{
|
{
|
||||||
if (protocolVersion > MC1152Version && handler.GetTerrainEnabled())
|
if (protocolVersion > MC1152Version && handler.GetTerrainEnabled())
|
||||||
|
|
@ -525,61 +531,96 @@ namespace MinecraftClient.Protocol.Handlers
|
||||||
case PacketIncomingType.WindowItems:
|
case PacketIncomingType.WindowItems:
|
||||||
if (handler.GetInventoryEnabled())
|
if (handler.GetInventoryEnabled())
|
||||||
{
|
{
|
||||||
/*
|
// MC 1.12.2 or lower
|
||||||
* Following commented code will crash
|
if (protocolversion < MC113Version)
|
||||||
*
|
{
|
||||||
byte id = dataTypes.ReadNextByte(packetData);
|
byte id = dataTypes.ReadNextByte(packetData);
|
||||||
short elements = dataTypes.ReadNextShort(packetData);
|
short elements = dataTypes.ReadNextShort(packetData);
|
||||||
|
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++)
|
||||||
{
|
|
||||||
short itemID = dataTypes.ReadNextShort(packetData);
|
|
||||||
if (itemID == -1) continue;
|
|
||||||
byte itemCount = dataTypes.ReadNextByte(packetData);
|
|
||||||
short itemDamage = dataTypes.ReadNextShort(packetData);
|
|
||||||
Item item = new Item(itemID, itemCount, itemDamage, 0);
|
|
||||||
//TODO: Add to the dictionary for the inventory its in using the id
|
|
||||||
if (packetData.ToArray().Count() > 0)
|
|
||||||
{
|
{
|
||||||
dataTypes.ReadNextNbt(packetData);
|
short itemID = dataTypes.ReadNextShort(packetData);
|
||||||
}
|
if (itemID == -1) continue;
|
||||||
}
|
|
||||||
*/
|
|
||||||
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);
|
byte itemCount = dataTypes.ReadNextByte(packetData);
|
||||||
dataTypes.ReadNextNbt(packetData);
|
short itemDamage = dataTypes.ReadNextShort(packetData);
|
||||||
|
Dictionary<string, object> NBT = new Dictionary<string, object>();
|
||||||
Item item = new Item(itemID, itemCount);
|
//TODO: Add to the dictionary for the inventory its in using the id
|
||||||
|
if (packetData.ToArray().Count() > 0)
|
||||||
|
{
|
||||||
|
NBT = dataTypes.ReadNextNbt(packetData);
|
||||||
|
}
|
||||||
|
Item item = new Item(itemID, itemCount, itemDamage, NBT);
|
||||||
itemsList.Add(i, item);
|
itemsList.Add(i, item);
|
||||||
}
|
}
|
||||||
|
handler.OnWindowItems(id, itemsList);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// MC 1.13 after
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
handler.OnWindowItems(id, itemsList);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case PacketIncomingType.SetSlot:
|
case PacketIncomingType.SetSlot:
|
||||||
if(handler.GetInventoryEnabled())
|
if(handler.GetInventoryEnabled())
|
||||||
{
|
{
|
||||||
byte WindowID = dataTypes.ReadNextByte(packetData);
|
// MC 1.12.2 or lower
|
||||||
short SlotID = dataTypes.ReadNextShort(packetData);
|
if (protocolversion < MC113Version)
|
||||||
bool Present = dataTypes.ReadNextBool(packetData);
|
|
||||||
if (Present)
|
|
||||||
{
|
{
|
||||||
int ItemID = dataTypes.ReadNextVarInt(packetData);
|
byte WindowID = dataTypes.ReadNextByte(packetData);
|
||||||
byte Count = dataTypes.ReadNextByte(packetData);
|
short SlotID = dataTypes.ReadNextShort(packetData);
|
||||||
Dictionary<string, object> NBT = dataTypes.ReadNextNbt(packetData);
|
short ItemID = dataTypes.ReadNextShort(packetData);
|
||||||
handler.OnSetSlot(WindowID, SlotID, Present, ItemID, Count, NBT);
|
if (ItemID == -1)
|
||||||
|
{
|
||||||
|
handler.OnSetSlot(WindowID, SlotID, false);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
byte Count = dataTypes.ReadNextByte(packetData);
|
||||||
|
short itemDamage = dataTypes.ReadNextShort(packetData); // useless so ignored
|
||||||
|
Dictionary<string, object> NBT = new Dictionary<string, object>();
|
||||||
|
//TODO: Add to the dictionary for the inventory its in using the id
|
||||||
|
if (packetData.ToArray().Count() > 0)
|
||||||
|
{
|
||||||
|
NBT = dataTypes.ReadNextNbt(packetData);
|
||||||
|
}
|
||||||
|
handler.OnSetSlot(WindowID, SlotID, true, ItemID, Count, NBT);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
handler.OnSetSlot(WindowID, SlotID, Present);
|
// MC 1.13 after
|
||||||
|
byte WindowID = dataTypes.ReadNextByte(packetData);
|
||||||
|
short SlotID = dataTypes.ReadNextShort(packetData);
|
||||||
|
bool Present = dataTypes.ReadNextBool(packetData);
|
||||||
|
if (Present)
|
||||||
|
{
|
||||||
|
int ItemID = dataTypes.ReadNextVarInt(packetData);
|
||||||
|
byte Count = dataTypes.ReadNextByte(packetData);
|
||||||
|
Dictionary<string, object> NBT = dataTypes.ReadNextNbt(packetData);
|
||||||
|
handler.OnSetSlot(WindowID, SlotID, Present, ItemID, Count, NBT);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
handler.OnSetSlot(WindowID, SlotID, Present);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
@ -597,7 +638,11 @@ namespace MinecraftClient.Protocol.Handlers
|
||||||
if (handler.GetEntityHandlingEnabled())
|
if (handler.GetEntityHandlingEnabled())
|
||||||
{
|
{
|
||||||
int EntityID = dataTypes.ReadNextVarInt(packetData);
|
int EntityID = dataTypes.ReadNextVarInt(packetData);
|
||||||
Guid EntityUUID = dataTypes.ReadNextUUID(packetData);
|
Guid EntityUUID = Guid.Empty;
|
||||||
|
if (protocolversion > MC18Version)
|
||||||
|
{
|
||||||
|
EntityUUID = dataTypes.ReadNextUUID(packetData);
|
||||||
|
}
|
||||||
int EntityType = dataTypes.ReadNextVarInt(packetData);
|
int EntityType = dataTypes.ReadNextVarInt(packetData);
|
||||||
Double X = dataTypes.ReadNextDouble(packetData);
|
Double X = dataTypes.ReadNextDouble(packetData);
|
||||||
Double Y = dataTypes.ReadNextDouble(packetData);
|
Double Y = dataTypes.ReadNextDouble(packetData);
|
||||||
|
|
@ -619,7 +664,11 @@ namespace MinecraftClient.Protocol.Handlers
|
||||||
if (handler.GetEntityHandlingEnabled())
|
if (handler.GetEntityHandlingEnabled())
|
||||||
{
|
{
|
||||||
int EntityID = dataTypes.ReadNextVarInt(packetData);
|
int EntityID = dataTypes.ReadNextVarInt(packetData);
|
||||||
Guid EntityUUID = dataTypes.ReadNextUUID(packetData);
|
Guid EntityUUID = Guid.Empty;
|
||||||
|
if (protocolversion > MC18Version)
|
||||||
|
{
|
||||||
|
EntityUUID = dataTypes.ReadNextUUID(packetData);
|
||||||
|
}
|
||||||
int EntityType = dataTypes.ReadNextVarInt(packetData);
|
int EntityType = dataTypes.ReadNextVarInt(packetData);
|
||||||
Double X = dataTypes.ReadNextDouble(packetData);
|
Double X = dataTypes.ReadNextDouble(packetData);
|
||||||
Double Y = dataTypes.ReadNextDouble(packetData);
|
Double Y = dataTypes.ReadNextDouble(packetData);
|
||||||
|
|
@ -631,6 +680,8 @@ namespace MinecraftClient.Protocol.Handlers
|
||||||
short VelocityY = dataTypes.ReadNextShort(packetData);
|
short VelocityY = dataTypes.ReadNextShort(packetData);
|
||||||
short VelocityZ = dataTypes.ReadNextShort(packetData);
|
short VelocityZ = dataTypes.ReadNextShort(packetData);
|
||||||
|
|
||||||
|
// packet before 1.15 has metadata at the end
|
||||||
|
|
||||||
Location EntityLocation = new Location(X, Y, Z);
|
Location EntityLocation = new Location(X, Y, Z);
|
||||||
|
|
||||||
handler.OnSpawnLivingEntity(EntityID, EntityType, EntityUUID, EntityLocation);
|
handler.OnSpawnLivingEntity(EntityID, EntityType, EntityUUID, EntityLocation);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue