-Add: sync serverPos[XYZ] on spawning of entity
This fixes the issue that, up to 400 ticks from getting in range, entities have a wrong offset (because server and client don't agree on the position to calculate relative updates from)
This commit is contained in:
parent
1012531538
commit
7dff7fd62d
5 changed files with 95 additions and 1 deletions
|
@ -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,27 @@ 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);
|
||||
|
||||
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.
|
||||
|
|
|
@ -29,6 +29,7 @@ import net.minecraft.src.Packet250CustomPayload;
|
|||
import net.minecraft.src.World;
|
||||
import net.minecraft.src.mod_MinecraftForge;
|
||||
import net.minecraft.src.forge.packets.PacketEntitySpawn;
|
||||
import net.minecraft.src.forge.packets.PacketEntityTrack;
|
||||
import net.minecraft.src.forge.packets.PacketHandlerBase;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
|
@ -710,6 +711,12 @@ public class ForgeHooks
|
|||
PacketEntitySpawn pkt = new PacketEntitySpawn(entity, info.Mod, info.ID);
|
||||
return pkt.getPacket();
|
||||
}
|
||||
|
||||
public static Packet getEntityTrackPacket(int entityId, int serverPosX, int serverPosY, int serverPosZ)
|
||||
{
|
||||
PacketEntityTrack pkt = new PacketEntityTrack(entityId, serverPosX, serverPosY, serverPosZ);
|
||||
return pkt.getPacket();
|
||||
}
|
||||
|
||||
public static Hashtable<Integer, NetworkMod> networkMods = new Hashtable<Integer, NetworkMod>();
|
||||
public static Hashtable<BaseMod, IGuiHandler> guiHandlers = new Hashtable<BaseMod, IGuiHandler>();
|
||||
|
|
|
@ -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()
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -9,7 +9,22 @@
|
|||
public class EntityTrackerEntry
|
||||
{
|
||||
/** The entity that this EntityTrackerEntry tracks. */
|
||||
@@ -286,6 +288,11 @@
|
||||
@@ -226,6 +228,14 @@
|
||||
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)
|
||||
+ {
|
||||
+ par1EntityPlayerMP.playerNetServerHandler.sendPacket(ForgeHooks.getEntityTrackPacket(this.trackedEntity.entityId, this.encodedPosX, this.encodedPosY, this.encodedPosZ));
|
||||
+ }
|
||||
+
|
||||
if (this.shouldSendMotionUpdates)
|
||||
{
|
||||
par1EntityPlayerMP.playerNetServerHandler.sendPacket(new Packet28EntityVelocity(this.trackedEntity.entityId, this.trackedEntity.motionX, this.trackedEntity.motionY, this.trackedEntity.motionZ));
|
||||
@@ -286,6 +296,11 @@
|
||||
{
|
||||
System.out.println("Fetching addPacket for removed entity");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue