Fix entity metadata for lower MC versions

This commit is contained in:
ReinforceZwei 2020-08-15 13:11:38 +08:00
parent 888297dd4b
commit 85c32b9a47
2 changed files with 32 additions and 4 deletions

View file

@ -59,6 +59,7 @@ namespace MinecraftClient
private object lastKeepAliveLock = new object();
private int respawnTicks = 0;
private int gamemode = 0;
private int protocolVersion;
private int playerEntityID;
@ -155,6 +156,7 @@ namespace MinecraftClient
this.username = user;
this.host = server_ip;
this.port = port;
this.protocolVersion = protocolversion;
if (!singlecommand)
{
@ -2122,9 +2124,19 @@ namespace MinecraftClient
if (entities.ContainsKey(entityID))
{
// Get health data for an entity
if (metadata.ContainsKey(8) && metadata[8].GetType() == typeof(float))
int key;
// Key for 1.10+ is 7 and 1.14+ is 8
if (protocolVersion >= Protocol.Handlers.Protocol18Handler.MC114Version)
{
entities[entityID].Health = (float)metadata[8];
key = 8;
}
else
{
key = 7;
}
if (metadata.ContainsKey(key) && metadata[key].GetType() == typeof(float))
{
entities[entityID].Health = (float)metadata[key];
}
}
}