diff --git a/forge/forge_client/src/net/minecraft/src/forge/PacketHandlerClient.java b/forge/forge_client/src/net/minecraft/src/forge/PacketHandlerClient.java index 467a15422..c2e644002 100644 --- a/forge/forge_client/src/net/minecraft/src/forge/PacketHandlerClient.java +++ b/forge/forge_client/src/net/minecraft/src/forge/PacketHandlerClient.java @@ -51,6 +51,12 @@ public class PacketHandlerClient extends PacketHandlerBase pkt.readData(data); onOpenGui((PacketOpenGUI)pkt); break; + + case ForgePacket.TRACK: + pkt = new PacketEntityTrack(); + pkt.readData(data); + onEntityTrackPacket((PacketEntityTrack)pkt, ModLoader.getMinecraftInstance().theWorld); + break; } } catch (IOException e) @@ -60,6 +66,31 @@ public class PacketHandlerClient extends PacketHandlerBase } } + /** + * Process the Entity Track packet. This corrects the serverPos[XYZ] to match + * with the server, so any following relative updates are valid. + * @param packet The Track Packet + * @param world The world the entity is in + */ + public void onEntityTrackPacket(PacketEntityTrack packet, World world) + { + if (DEBUG) + { + System.out.println("S->C: " + packet.toString(true)); + } + + Minecraft mc = ModLoader.getMinecraftInstance(); + Entity entity = ((WorldClient)world).getEntityByID(packet.entityId); + if (entity == null) + { + return; + } + + entity.serverPosX = packet.serverPosX; + entity.serverPosY = packet.serverPosY; + entity.serverPosZ = packet.serverPosZ; + } + /** * Processes the Entity Spawn packet. And spawns an entity in world as needed. * If the client has the required client mod. diff --git a/forge/forge_common/net/minecraft/src/forge/packets/ForgePacket.java b/forge/forge_common/net/minecraft/src/forge/packets/ForgePacket.java index b739e427d..17c2fef1e 100644 --- a/forge/forge_common/net/minecraft/src/forge/packets/ForgePacket.java +++ b/forge/forge_common/net/minecraft/src/forge/packets/ForgePacket.java @@ -18,6 +18,7 @@ public abstract class ForgePacket public static final int MODLIST = 2; public static final int MOD_MISSING = 3; public static final int OPEN_GUI = 5; + public static final int TRACK = 6; public Packet getPacket() { diff --git a/forge/forge_common/net/minecraft/src/forge/packets/PacketEntityTrack.java b/forge/forge_common/net/minecraft/src/forge/packets/PacketEntityTrack.java new file mode 100644 index 000000000..6763c7cb2 --- /dev/null +++ b/forge/forge_common/net/minecraft/src/forge/packets/PacketEntityTrack.java @@ -0,0 +1,44 @@ +package net.minecraft.src.forge.packets; + +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; + +public class PacketEntityTrack extends ForgePacket +{ + public int entityId; + public int serverPosX; + public int serverPosY; + public int serverPosZ; + + public PacketEntityTrack(){} + public PacketEntityTrack(int entityId, int serverPosX, int serverPosY, int serverPosZ) + { + this.entityId = entityId; + this.serverPosX = serverPosX; + this.serverPosY = serverPosY; + this.serverPosZ = serverPosZ; + } + + public void writeData(DataOutputStream data) throws IOException + { + data.writeInt(entityId); + data.writeInt(serverPosX); + data.writeInt(serverPosY); + data.writeInt(serverPosZ); + } + + public void readData(DataInputStream data) throws IOException + { + entityId = data.readInt(); + serverPosX = data.readInt(); + serverPosY = data.readInt(); + serverPosZ = data.readInt(); + } + + @Override + public int getID() + { + return ForgePacket.TRACK; + } +} diff --git a/forge/patches/minecraft_server/net/minecraft/src/EntityTrackerEntry.java.patch b/forge/patches/minecraft_server/net/minecraft/src/EntityTrackerEntry.java.patch index c323eae7b..73e95709a 100644 --- a/forge/patches/minecraft_server/net/minecraft/src/EntityTrackerEntry.java.patch +++ b/forge/patches/minecraft_server/net/minecraft/src/EntityTrackerEntry.java.patch @@ -1,15 +1,32 @@ --- ../src_base/minecraft_server/net/minecraft/src/EntityTrackerEntry.java 0000-00-00 00:00:00.000000000 -0000 +++ ../src_work/minecraft_server/net/minecraft/src/EntityTrackerEntry.java 0000-00-00 00:00:00.000000000 -0000 -@@ -5,6 +5,8 @@ +@@ -5,6 +5,9 @@ import java.util.List; import java.util.Set; +import net.minecraft.src.forge.ForgeHooks; ++import net.minecraft.src.forge.packets.PacketEntityTrack; + public class EntityTrackerEntry { /** The entity that this EntityTrackerEntry tracks. */ -@@ -286,6 +288,11 @@ +@@ -226,6 +229,15 @@ + this.trackedPlayers.add(par1EntityPlayerMP); + par1EntityPlayerMP.playerNetServerHandler.sendPacket(this.getSpawnPacket()); + ++ int posX = MathHelper.floor_double(this.trackedEntity.posX * 32.0D); ++ int posY = MathHelper.floor_double(this.trackedEntity.posY * 32.0D); ++ int posZ = MathHelper.floor_double(this.trackedEntity.posZ * 32.0D); ++ if (posX != this.encodedPosX || posY != this.encodedPosY || posZ != this.encodedPosZ) ++ { ++ PacketEntityTrack pkt = new PacketEntityTrack(this.trackedEntity.entityId, this.encodedPosX, this.encodedPosY, this.encodedPosZ); ++ par1EntityPlayerMP.playerNetServerHandler.sendPacket(pkt.getPacket()); ++ } ++ + if (this.shouldSendMotionUpdates) + { + par1EntityPlayerMP.playerNetServerHandler.sendPacket(new Packet28EntityVelocity(this.trackedEntity.entityId, this.trackedEntity.motionX, this.trackedEntity.motionY, this.trackedEntity.motionZ)); +@@ -286,6 +298,11 @@ { System.out.println("Fetching addPacket for removed entity"); }