mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +00:00
Fix 1.19.2 entity metadata handle
This commit is contained in:
parent
26bc6f16c0
commit
c00468c103
6 changed files with 48 additions and 31 deletions
|
|
@ -580,9 +580,9 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
}
|
||||
}
|
||||
|
||||
public Dictionary<int, object> ReadNextMetadata(Queue<byte> cache, ItemPalette itemPalette)
|
||||
public Dictionary<int, object?> ReadNextMetadata(Queue<byte> cache, ItemPalette itemPalette)
|
||||
{
|
||||
Dictionary<int, object> data = new Dictionary<int, object>();
|
||||
Dictionary<int, object?> data = new();
|
||||
byte key = ReadNextByte(cache);
|
||||
while (key != 0xff)
|
||||
{
|
||||
|
|
@ -600,7 +600,7 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
}
|
||||
}
|
||||
// Value's data type is depended on Type
|
||||
object value = null;
|
||||
object? value = null;
|
||||
|
||||
// This is backward compatible since new type is appended to the end
|
||||
// Version upgrade note
|
||||
|
|
@ -625,9 +625,7 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
break;
|
||||
case 5: // Optional Chat
|
||||
if (ReadNextBool(cache))
|
||||
{
|
||||
value = ReadNextString(cache);
|
||||
}
|
||||
break;
|
||||
case 6: // Slot
|
||||
value = ReadNextItemSlot(cache, itemPalette);
|
||||
|
|
@ -636,11 +634,12 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
value = ReadNextBool(cache);
|
||||
break;
|
||||
case 8: // Rotation (3x floats)
|
||||
List<float> t = new List<float>();
|
||||
t.Add(ReadNextFloat(cache));
|
||||
t.Add(ReadNextFloat(cache));
|
||||
t.Add(ReadNextFloat(cache));
|
||||
value = t;
|
||||
value = new List<float>
|
||||
{
|
||||
ReadNextFloat(cache),
|
||||
ReadNextFloat(cache),
|
||||
ReadNextFloat(cache)
|
||||
};
|
||||
break;
|
||||
case 9: // Position
|
||||
value = ReadNextLocation(cache);
|
||||
|
|
@ -689,11 +688,12 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
}
|
||||
break;
|
||||
case 16: // Villager Data (3x VarInt)
|
||||
List<int> d = new List<int>();
|
||||
d.Add(ReadNextVarInt(cache));
|
||||
d.Add(ReadNextVarInt(cache));
|
||||
d.Add(ReadNextVarInt(cache));
|
||||
value = d;
|
||||
value = new List<int>
|
||||
{
|
||||
ReadNextVarInt(cache),
|
||||
ReadNextVarInt(cache),
|
||||
ReadNextVarInt(cache)
|
||||
};
|
||||
break;
|
||||
case 17: // Optional VarInt
|
||||
if (ReadNextBool(cache))
|
||||
|
|
@ -704,6 +704,21 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
case 18: // Pose
|
||||
value = ReadNextVarInt(cache);
|
||||
break;
|
||||
case 19: // Cat Variant
|
||||
value = ReadNextVarInt(cache);
|
||||
break;
|
||||
case 20: // Frog Varint
|
||||
value = ReadNextVarInt(cache);
|
||||
break;
|
||||
case 21: // GlobalPos at 1.19.2+; Painting Variant at 1.19-
|
||||
if (protocolversion <= Protocol18Handler.MC_1_19_Version)
|
||||
value = ReadNextVarInt(cache);
|
||||
else
|
||||
value = null; // Dimension and blockPos, currently not in use
|
||||
break;
|
||||
case 22: // Painting Variant
|
||||
value = ReadNextVarInt(cache);
|
||||
break;
|
||||
default:
|
||||
throw new System.IO.InvalidDataException("Unknown Metadata Type ID " + type + ". Is this up to date for new MC Version?");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1470,7 +1470,7 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
if (handler.GetEntityHandlingEnabled())
|
||||
{
|
||||
int EntityID = dataTypes.ReadNextVarInt(packetData);
|
||||
Dictionary<int, object> metadata = dataTypes.ReadNextMetadata(packetData, itemPalette);
|
||||
Dictionary<int, object?> metadata = dataTypes.ReadNextMetadata(packetData, itemPalette);
|
||||
|
||||
int healthField; // See https://wiki.vg/Entity_metadata#Living_Entity
|
||||
if (protocolVersion > MC_1_19_2_Version)
|
||||
|
|
@ -1484,8 +1484,9 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
else
|
||||
throw new NotImplementedException(Translations.Get("exception.palette.healthfield"));
|
||||
|
||||
if (metadata.ContainsKey(healthField) && metadata[healthField] != null && metadata[healthField].GetType() == typeof(float))
|
||||
handler.OnEntityHealth(EntityID, (float)metadata[healthField]);
|
||||
if (metadata.TryGetValue(healthField, out object? healthObj) && healthObj != null && healthObj.GetType() == typeof(float))
|
||||
handler.OnEntityHealth(EntityID, (float)healthObj);
|
||||
|
||||
handler.OnEntityMetadata(EntityID, metadata);
|
||||
}
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -318,7 +318,7 @@ namespace MinecraftClient.Protocol
|
|||
/// </summary>
|
||||
/// <param name="EntityID">Entity ID</param>
|
||||
/// <param name="metadata">Entity metadata</param>
|
||||
void OnEntityMetadata(int EntityID, Dictionary<int, object> metadata);
|
||||
void OnEntityMetadata(int EntityID, Dictionary<int, object?> metadata);
|
||||
|
||||
/// <summary>
|
||||
/// Called when and explosion occurs on the server
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue