From 6d0f7ace17d30e70c8a82eee0dd6939572aad272 Mon Sep 17 00:00:00 2001 From: Christian Date: Thu, 9 Aug 2012 08:40:32 -0400 Subject: [PATCH] Entity spawn adjustment - tracker --- .../cpw/mods/fml/client/FMLClientHandler.java | 10 ++++ .../cpw/mods/fml/common/FMLCommonHandler.java | 6 +++ .../cpw/mods/fml/common/IFMLSidedHandler.java | 3 ++ .../network/EntitySpawnAdjustmentPacket.java | 53 +++++++++++++++++++ .../fml/common/network/FMLNetworkHandler.java | 10 ++++ .../mods/fml/common/network/FMLPacket.java | 6 ++- .../fml/common/registry/EntityRegistry.java | 2 +- .../cpw/mods/fml/server/FMLServerHandler.java | 16 ++++++ 8 files changed, 104 insertions(+), 2 deletions(-) create mode 100644 fml/common/cpw/mods/fml/common/network/EntitySpawnAdjustmentPacket.java diff --git a/fml/client/cpw/mods/fml/client/FMLClientHandler.java b/fml/client/cpw/mods/fml/client/FMLClientHandler.java index db0986239..9fda5eeb9 100644 --- a/fml/client/cpw/mods/fml/client/FMLClientHandler.java +++ b/fml/client/cpw/mods/fml/client/FMLClientHandler.java @@ -106,6 +106,7 @@ import cpw.mods.fml.common.TickType; import cpw.mods.fml.common.modloader.ModLoaderHelper; import cpw.mods.fml.common.modloader.ModLoaderModContainer; import cpw.mods.fml.common.modloader.ModProperty; +import cpw.mods.fml.common.network.EntitySpawnAdjustmentPacket; import cpw.mods.fml.common.network.EntitySpawnPacket; import cpw.mods.fml.common.registry.IEntityAdditionalSpawnData; import cpw.mods.fml.common.registry.IThrowableEntity; @@ -399,4 +400,13 @@ public class FMLClientHandler implements IFMLSidedHandler throw Throwables.propagate(e); } } + + @Override + public void adjustEntityLocationOnClient(EntitySpawnAdjustmentPacket packet) + { + Entity ent = client.field_71441_e.func_73024_a(packet.entityId); + ent.field_70118_ct = packet.serverX; + ent.field_70117_cu = packet.serverY; + ent.field_70116_cv = packet.serverZ; + } } diff --git a/fml/common/cpw/mods/fml/common/FMLCommonHandler.java b/fml/common/cpw/mods/fml/common/FMLCommonHandler.java index 40470d7e9..82ac129f0 100644 --- a/fml/common/cpw/mods/fml/common/FMLCommonHandler.java +++ b/fml/common/cpw/mods/fml/common/FMLCommonHandler.java @@ -44,6 +44,7 @@ import com.google.common.collect.ImmutableList.Builder; import com.google.common.collect.Lists; import cpw.mods.fml.common.discovery.ContainerType; +import cpw.mods.fml.common.network.EntitySpawnAdjustmentPacket; import cpw.mods.fml.common.network.EntitySpawnPacket; import cpw.mods.fml.common.registry.TickRegistry; import cpw.mods.fml.common.registry.GameRegistry; @@ -350,4 +351,9 @@ public class FMLCommonHandler { return sidedDelegate.spawnEntityIntoClientWorld(cls, entitySpawnPacket); } + + public void adjustEntityLocationOnClient(EntitySpawnAdjustmentPacket entitySpawnAdjustmentPacket) + { + sidedDelegate.adjustEntityLocationOnClient(entitySpawnAdjustmentPacket); + } } diff --git a/fml/common/cpw/mods/fml/common/IFMLSidedHandler.java b/fml/common/cpw/mods/fml/common/IFMLSidedHandler.java index d31911802..a856d5ebc 100644 --- a/fml/common/cpw/mods/fml/common/IFMLSidedHandler.java +++ b/fml/common/cpw/mods/fml/common/IFMLSidedHandler.java @@ -11,6 +11,7 @@ import net.minecraft.src.Entity; import net.minecraft.src.World; import cpw.mods.fml.common.modloader.ModProperty; +import cpw.mods.fml.common.network.EntitySpawnAdjustmentPacket; import cpw.mods.fml.common.network.EntitySpawnPacket; public interface IFMLSidedHandler @@ -28,4 +29,6 @@ public interface IFMLSidedHandler void showGuiScreen(Object clientGuiElement); Entity spawnEntityIntoClientWorld(Class entityClass, EntitySpawnPacket packet); + + void adjustEntityLocationOnClient(EntitySpawnAdjustmentPacket entitySpawnAdjustmentPacket); } diff --git a/fml/common/cpw/mods/fml/common/network/EntitySpawnAdjustmentPacket.java b/fml/common/cpw/mods/fml/common/network/EntitySpawnAdjustmentPacket.java new file mode 100644 index 000000000..fbdbf6509 --- /dev/null +++ b/fml/common/cpw/mods/fml/common/network/EntitySpawnAdjustmentPacket.java @@ -0,0 +1,53 @@ +package cpw.mods.fml.common.network; + +import com.google.common.io.ByteArrayDataInput; +import com.google.common.io.ByteArrayDataOutput; +import com.google.common.io.ByteStreams; + +import cpw.mods.fml.common.FMLCommonHandler; + +import net.minecraft.src.NetHandler; +import net.minecraft.src.NetworkManager; + +public class EntitySpawnAdjustmentPacket extends FMLPacket +{ + + public EntitySpawnAdjustmentPacket() + { + super(Type.ENTITYSPAWNADJUSTMENT); + } + + public int entityId; + public int serverX; + public int serverY; + public int serverZ; + + @Override + public byte[] generatePacket(Object... data) + { + ByteArrayDataOutput dat = ByteStreams.newDataOutput(); + dat.writeInt((Integer) data[0]); + dat.writeInt((Integer) data[1]); + dat.writeInt((Integer) data[2]); + dat.writeInt((Integer) data[3]); + return dat.toByteArray(); + } + + @Override + public FMLPacket consumePacket(byte[] data) + { + ByteArrayDataInput dat = ByteStreams.newDataInput(data); + entityId = dat.readInt(); + serverX = dat.readInt(); + serverY = dat.readInt(); + serverZ = dat.readInt(); + return this; + } + + @Override + public void execute(NetworkManager network, FMLNetworkHandler handler, NetHandler netHandler, String userName) + { + FMLCommonHandler.instance().adjustEntityLocationOnClient(this); + } + +} diff --git a/fml/common/cpw/mods/fml/common/network/FMLNetworkHandler.java b/fml/common/cpw/mods/fml/common/network/FMLNetworkHandler.java index d27879a9a..42682ea35 100644 --- a/fml/common/cpw/mods/fml/common/network/FMLNetworkHandler.java +++ b/fml/common/cpw/mods/fml/common/network/FMLNetworkHandler.java @@ -302,4 +302,14 @@ public class FMLNetworkHandler pkt.field_73628_b = pkt.field_73629_c.length; return pkt; } + + public static void makeEntitySpawnAdjustment(int entityId, EntityPlayerMP player, int serverX, int serverY, int serverZ) + { + Packet250CustomPayload pkt = new Packet250CustomPayload(); + pkt.field_73630_a = "FML"; + pkt.field_73629_c = FMLPacket.makePacket(Type.ENTITYSPAWNADJUSTMENT, entityId, serverX, serverY, serverZ); + pkt.field_73628_b = pkt.field_73629_c.length; + + player.field_71135_a.func_72567_b(pkt); + } } \ No newline at end of file diff --git a/fml/common/cpw/mods/fml/common/network/FMLPacket.java b/fml/common/cpw/mods/fml/common/network/FMLPacket.java index 33c01a91c..37f9e4600 100644 --- a/fml/common/cpw/mods/fml/common/network/FMLPacket.java +++ b/fml/common/cpw/mods/fml/common/network/FMLPacket.java @@ -43,7 +43,11 @@ public abstract class FMLPacket /** * Spawn an entity on the client from the server */ - ENTITYSPAWN(EntitySpawnPacket.class); + ENTITYSPAWN(EntitySpawnPacket.class), + /** + * Fixes entity location data after spawning + */ + ENTITYSPAWNADJUSTMENT(EntitySpawnAdjustmentPacket.class); private Class packetType; diff --git a/fml/common/cpw/mods/fml/common/registry/EntityRegistry.java b/fml/common/cpw/mods/fml/common/registry/EntityRegistry.java index 79ce1109a..6308c6db7 100644 --- a/fml/common/cpw/mods/fml/common/registry/EntityRegistry.java +++ b/fml/common/cpw/mods/fml/common/registry/EntityRegistry.java @@ -93,7 +93,7 @@ public class EntityRegistry } catch (IllegalArgumentException e) { - FMLLog.log(Level.WARNING, e, "The mod %s tried to register the entity (name,class) (%s,%s) one or bothe of which are already registered", mc.getModId(), entityName, entityClass.getName()); + FMLLog.log(Level.WARNING, e, "The mod %s tried to register the entity (name,class) (%s,%s) one or both of which are already registered", mc.getModId(), entityName, entityClass.getName()); return; } entityRegistrations.put(mc, er); diff --git a/fml/server/cpw/mods/fml/server/FMLServerHandler.java b/fml/server/cpw/mods/fml/server/FMLServerHandler.java index f782ed0b5..3a2c7485f 100644 --- a/fml/server/cpw/mods/fml/server/FMLServerHandler.java +++ b/fml/server/cpw/mods/fml/server/FMLServerHandler.java @@ -27,6 +27,7 @@ import net.minecraft.server.MinecraftServer; import net.minecraft.src.BaseMod; import net.minecraft.src.BiomeGenBase; import net.minecraft.src.Block; +import net.minecraft.src.Entity; import net.minecraft.src.EntityItem; import net.minecraft.src.EntityPlayer; import net.minecraft.src.EntityPlayerMP; @@ -54,6 +55,8 @@ import cpw.mods.fml.common.ProxyInjector; import cpw.mods.fml.common.Side; import cpw.mods.fml.common.modloader.ModLoaderModContainer; import cpw.mods.fml.common.modloader.ModProperty; +import cpw.mods.fml.common.network.EntitySpawnAdjustmentPacket; +import cpw.mods.fml.common.network.EntitySpawnPacket; /** * Handles primary communication from hooked code into the system @@ -173,4 +176,17 @@ public class FMLServerHandler implements IFMLSidedHandler { } + + @Override + public Entity spawnEntityIntoClientWorld(Class entityClass, EntitySpawnPacket packet) + { + // NOOP + return null; + } + + @Override + public void adjustEntityLocationOnClient(EntitySpawnAdjustmentPacket entitySpawnAdjustmentPacket) + { + // NOOP + } }