Update FML Entity Spawn packet for 1.9's location change. Closes #2567

This commit is contained in:
LexManos committed 2016-03-22 13:35:45 -07:00
1 parent a596984bfd
commit 25cd7cc3e1
2 files changed
+20 -21

No files matched your search

@@ -9,6 +9,7 @@ import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.client.multiplayer.WorldClient;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityTracker;
import net.minecraft.util.IThreadListener;
import net.minecraft.world.World;
import net.minecraftforge.fml.client.FMLClientHandler;
@@ -61,7 +62,7 @@ public class EntitySpawnHandler extends SimpleChannelInboundHandler<FMLMessage.E
if (er == null)
{
throw new RuntimeException( "Could not spawn mod entity ModID: " + spawnMsg.modId + " EntityID: " + spawnMsg.modEntityTypeId +
" at ( " + spawnMsg.scaledX + "," + spawnMsg.scaledY + ", " + spawnMsg.scaledZ + ") Please contact mod author or server admin.");
" at ( " + spawnMsg.rawX + "," + spawnMsg.rawY + ", " + spawnMsg.rawZ + ") Please contact mod author or server admin.");
}
WorldClient wc = FMLClientHandler.instance().getWorldClient();
Class<? extends Entity> cls = er.getEntityClass();
@@ -77,7 +78,8 @@ public class EntitySpawnHandler extends SimpleChannelInboundHandler<FMLMessage.E
int offset = spawnMsg.entityId - entity.getEntityId();
entity.setEntityId(spawnMsg.entityId);
entity.setLocationAndAngles(spawnMsg.scaledX, spawnMsg.scaledY, spawnMsg.scaledZ, spawnMsg.scaledYaw, spawnMsg.scaledPitch);
entity.setUniqueId(spawnMsg.entityUUID);
entity.setLocationAndAngles(spawnMsg.rawX, spawnMsg.rawY, spawnMsg.rawZ, spawnMsg.scaledYaw, spawnMsg.scaledPitch);
if (entity instanceof EntityLiving)
{
((EntityLiving) entity).rotationYawHead = spawnMsg.scaledHeadYaw;
@@ -93,9 +95,7 @@ public class EntitySpawnHandler extends SimpleChannelInboundHandler<FMLMessage.E
}
}
entity.serverPosX = spawnMsg.rawX;
entity.serverPosY = spawnMsg.rawY;
entity.serverPosZ = spawnMsg.rawZ;
EntityTracker.func_187254_a(entity, spawnMsg.rawX, spawnMsg.rawY, spawnMsg.rawZ);
EntityPlayerSP clientPlayer = FMLClientHandler.instance().getClientPlayerEntity();
if (entity instanceof IThrowableEntity)
@@ -121,7 +121,7 @@ public class EntitySpawnHandler extends SimpleChannelInboundHandler<FMLMessage.E
wc.addEntityToWorld(spawnMsg.entityId, entity);
} catch (Exception e)
{
FMLLog.log(Level.ERROR, e, "A severe problem occurred during the spawning of an entity at ( " + spawnMsg.scaledX + "," + spawnMsg.scaledY + ", " + spawnMsg.scaledZ +")");
FMLLog.log(Level.ERROR, e, "A severe problem occurred during the spawning of an entity at ( " + spawnMsg.rawX + "," + spawnMsg.rawY + ", " + spawnMsg.rawZ +")");
throw Throwables.propagate(e);
}
}
@@ -5,6 +5,7 @@ import io.netty.buffer.Unpooled;
import java.io.IOException;
import java.util.List;
import java.util.UUID;
import net.minecraft.network.datasync.EntityDataManager;
import org.apache.logging.log4j.Level;
@@ -112,12 +113,10 @@ public abstract class FMLMessage {
public static class EntitySpawnMessage extends EntityMessage {
String modId;
int modEntityTypeId;
int rawX;
int rawY;
int rawZ;
double scaledX;
double scaledY;
double scaledZ;
UUID entityUUID;
double rawX;
double rawY;
double rawZ;
float scaledYaw;
float scaledPitch;
float scaledHeadYaw;
@@ -141,10 +140,12 @@ public abstract class FMLMessage {
super.toBytes(buf);
ByteBufUtils.writeUTF8String(buf, modId);
buf.writeInt(modEntityTypeId);
buf.writeLong(entityUUID.getMostSignificantBits());
buf.writeLong(entityUUID.getLeastSignificantBits());
// posX, posY, posZ
buf.writeInt(MathHelper.floor_double(entity.posX * 32D));
buf.writeInt(MathHelper.floor_double(entity.posY * 32D));
buf.writeInt(MathHelper.floor_double(entity.posZ * 32D));
buf.writeDouble(entity.posX);
buf.writeDouble(entity.posY);
buf.writeDouble(entity.posZ);
// yaw, pitch
buf.writeByte((byte)(entity.rotationYaw * 256.0F / 360.0F));
buf.writeByte((byte) (entity.rotationPitch * 256.0F / 360.0F));
@@ -204,12 +205,10 @@ public abstract class FMLMessage {
super.fromBytes(dat);
modId = ByteBufUtils.readUTF8String(dat);
modEntityTypeId = dat.readInt();
rawX = dat.readInt();
rawY = dat.readInt();
rawZ = dat.readInt();
scaledX = rawX / 32D;
scaledY = rawY / 32D;
scaledZ = rawZ / 32D;
entityUUID = new UUID(dat.readLong(), dat.readLong());
rawX = dat.readDouble();
rawY = dat.readDouble();
rawZ = dat.readDouble();
scaledYaw = dat.readByte() * 360F / 256F;
scaledPitch = dat.readByte() * 360F / 256F;
scaledHeadYaw = dat.readByte() * 360F / 256F;