Skip to content

Commit

Permalink
Fixed entity positions in 1.8
Browse files Browse the repository at this point in the history
  • Loading branch information
milutinke committed Mar 29, 2023
1 parent 1901f4b commit 978dc4b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 19 deletions.
6 changes: 3 additions & 3 deletions MinecraftClient/Protocol/Handlers/DataTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -491,9 +491,9 @@ public Entity ReadNextEntity(Queue<byte> cache, EntityPalette entityPalette, boo

if (protocolversion < Protocol18Handler.MC_1_9_Version)
{
entityX = (Double)ReadNextInt(cache); // X
entityY = (Double)ReadNextInt(cache); // Y
entityZ = (Double)ReadNextInt(cache); // Z
entityX = ReadNextInt(cache) / 32.0D; // X
entityY = ReadNextInt(cache) / 32.0D; // Y
entityZ = ReadNextInt(cache) / 32.0D; // Z
}
else
{
Expand Down
45 changes: 29 additions & 16 deletions MinecraftClient/Protocol/Handlers/Protocol18.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public Protocol18Handler(TcpClient Client, int protocolVersion, IMinecraftComHan
}

if (handler.GetInventoryEnabled() &&
(protocolVersion < MC_1_8_Version || protocolVersion > MC_1_19_4_Version))
(protocolVersion < MC_1_9_Version || protocolVersion > MC_1_19_4_Version))
{
log.Error("§c" + Translations.extra_inventory_disabled);
handler.SetInventoryEnabled(false);
Expand Down Expand Up @@ -2001,13 +2001,26 @@ internal bool HandlePacket(int packetID, Queue<byte> packetData)
{
int EntityID = dataTypes.ReadNextVarInt(packetData);
Guid UUID = dataTypes.ReadNextUUID(packetData);
double X = dataTypes.ReadNextDouble(packetData);
double Y = dataTypes.ReadNextDouble(packetData);
double Z = dataTypes.ReadNextDouble(packetData);

double x, y, z;

if (protocolVersion < MC_1_9_Version)
{
x = dataTypes.ReadNextInt(packetData) / 32.0D;
y = dataTypes.ReadNextInt(packetData) / 32.0D;
z = dataTypes.ReadNextInt(packetData) / 32.0D;
}
else
{
x = dataTypes.ReadNextDouble(packetData);
y = dataTypes.ReadNextDouble(packetData);
z = dataTypes.ReadNextDouble(packetData);
}

byte Yaw = dataTypes.ReadNextByte(packetData);
byte Pitch = dataTypes.ReadNextByte(packetData);

Location EntityLocation = new(X, Y, Z);
Location EntityLocation = new(x, y, z);

handler.OnSpawnPlayer(EntityID, UUID, EntityLocation, Yaw, Pitch);
}
Expand Down Expand Up @@ -2098,9 +2111,9 @@ internal bool HandlePacket(int packetID, Queue<byte> packetData)

if (protocolVersion < MC_1_9_Version)
{
DeltaX = Convert.ToDouble(dataTypes.ReadNextByte(packetData));
DeltaY = Convert.ToDouble(dataTypes.ReadNextByte(packetData));
DeltaZ = Convert.ToDouble(dataTypes.ReadNextByte(packetData));
DeltaX = dataTypes.ReadNextByte(packetData) / 32.0D;
DeltaY = dataTypes.ReadNextByte(packetData) / 32.0D;
DeltaZ = dataTypes.ReadNextByte(packetData) / 32.0D;
}
else
{
Expand Down Expand Up @@ -2216,25 +2229,25 @@ internal bool HandlePacket(int packetID, Queue<byte> packetData)
{
int EntityID = dataTypes.ReadNextVarInt(packetData);

Double X, Y, Z;
double x, y, z;

if (protocolVersion < MC_1_9_Version)
{
X = Convert.ToDouble(dataTypes.ReadNextInt(packetData));
Y = Convert.ToDouble(dataTypes.ReadNextInt(packetData));
Z = Convert.ToDouble(dataTypes.ReadNextInt(packetData));
x = dataTypes.ReadNextInt(packetData) / 32.0D;
y = dataTypes.ReadNextInt(packetData) / 32.0D;
z = dataTypes.ReadNextInt(packetData) / 32.0D;
}
else
{
X = dataTypes.ReadNextDouble(packetData);
Y = dataTypes.ReadNextDouble(packetData);
Z = dataTypes.ReadNextDouble(packetData);
x = dataTypes.ReadNextDouble(packetData);
y = dataTypes.ReadNextDouble(packetData);
z = dataTypes.ReadNextDouble(packetData);
}

byte EntityYaw = dataTypes.ReadNextByte(packetData);
byte EntityPitch = dataTypes.ReadNextByte(packetData);
bool OnGround = dataTypes.ReadNextBool(packetData);
handler.OnEntityTeleport(EntityID, X, Y, Z, OnGround);
handler.OnEntityTeleport(EntityID, x, y, z, OnGround);
}

break;
Expand Down

0 comments on commit 978dc4b

Please sign in to comment.