Merge pull request #102 from TrueBrain/EntityTracker
-Add: sync serverPos[XYZ] on spawning of entity
This commit is contained in:
commit
45f0c521a3
4 changed files with 95 additions and 2 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,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.
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue