Changed entity Forge spawning code works to be more in line with normal spawning:

(World, double, double double) constructor is nolonger called, normal (World) constructor, and setPositionAndRotation is called afterwords.
yaw, pitch, and yawHead is sent (if the entity isn't a EntityLiving yawHead isn't used)
The datawatcher data is also sent like a normal Entity.
This commit is contained in:
LexManos 2012-04-15 07:36:17 -07:00
parent bda94ce522
commit cdf9361d07
2 changed files with 40 additions and 9 deletions

View file

@ -85,9 +85,12 @@ public class PacketHandlerClient implements IPacketHandler
double posX = (double)packet.posX / 32D; double posX = (double)packet.posX / 32D;
double posY = (double)packet.posY / 32D; double posY = (double)packet.posY / 32D;
double posZ = (double)packet.posZ / 32D; double posZ = (double)packet.posZ / 32D;
float yaw = (float)(packet.yaw * 360) / 256.0F;
float pitch = (float)(packet.pitch * 360) / 256.0F;
float yawHead = (float)(packet.yawHead * 360) / 256.0F;
try try
{ {
Entity entity = (Entity)(cls.getConstructor(World.class, double.class, double.class, double.class).newInstance(world, posX, posY, posZ)); Entity entity = (Entity)(cls.getConstructor(World.class).newInstance(world));
if (entity instanceof IThrowableEntity) if (entity instanceof IThrowableEntity)
{ {
Minecraft mc = ModLoader.getMinecraftInstance(); Minecraft mc = ModLoader.getMinecraftInstance();
@ -95,11 +98,9 @@ public class PacketHandlerClient implements IPacketHandler
((IThrowableEntity)entity).setThrower(thrower); ((IThrowableEntity)entity).setThrower(thrower);
} }
entity.serverPosX = packet.posX; entity.serverPosX = packet.posX;
entity.serverPosY = packet.posY; entity.serverPosY = packet.posY;
entity.serverPosZ = packet.posZ; entity.serverPosZ = packet.posZ;
entity.rotationYaw = 0.0F;
entity.rotationPitch = 0.0F;
Entity parts[] = entity.getParts(); Entity parts[] = entity.getParts();
if (parts != null) if (parts != null)
@ -112,6 +113,17 @@ public class PacketHandlerClient implements IPacketHandler
} }
entity.entityId = packet.entityID; entity.entityId = packet.entityID;
entity.setPositionAndRotation(posX, posY, posZ, yaw, pitch);
if (entity instanceof EntityLiving)
{
((EntityLiving)entity).rotationYawHead = yawHead;
}
if (packet.metadata != null)
{
entity.getDataWatcher().updateWatchedObjectsFromList((List)packet.metadata);
}
if (packet.throwerID > 0) if (packet.throwerID > 0)
{ {

View file

@ -5,6 +5,8 @@ import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
import net.minecraft.src.Entity; import net.minecraft.src.Entity;
import net.minecraft.src.EntityLiving;
import net.minecraft.src.DataWatcher;
import net.minecraft.src.MathHelper; import net.minecraft.src.MathHelper;
import net.minecraft.src.forge.ISpawnHandler; import net.minecraft.src.forge.ISpawnHandler;
import net.minecraft.src.forge.IThrowableEntity; import net.minecraft.src.forge.IThrowableEntity;
@ -13,16 +15,20 @@ import net.minecraft.src.forge.NetworkMod;
public class PacketEntitySpawn extends ForgePacket public class PacketEntitySpawn extends ForgePacket
{ {
public int modID;
public int entityID; public int entityID;
public int typeID;
public int posX; public int posX;
public int posY; public int posY;
public int posZ; public int posZ;
public byte yaw;
public byte pitch;
public byte yawHead;
public int throwerID;
public int speedX; public int speedX;
public int speedY; public int speedY;
public int speedZ; public int speedZ;
public int typeID; public Object metadata;
public int modID;
public int throwerID;
private ISpawnHandler handler; private ISpawnHandler handler;
public PacketEntitySpawn(){} public PacketEntitySpawn(){}
@ -37,6 +43,11 @@ public class PacketEntitySpawn extends ForgePacket
typeID = type; typeID = type;
modID = MinecraftForge.getModID(mod); modID = MinecraftForge.getModID(mod);
yaw = (byte)(ent.rotationYaw * 256.0F / 360.0F);
pitch = (byte)(ent.rotationPitch * 256.0F / 360.0F);
yawHead = (byte)(ent instanceof EntityLiving ? ((EntityLiving)ent).rotationYawHead * 256.0F / 360.0F : 0);
metadata = ent.getDataWatcher();
if (ent instanceof IThrowableEntity) if (ent instanceof IThrowableEntity)
{ {
Entity owner = ((IThrowableEntity)ent).getThrower(); Entity owner = ((IThrowableEntity)ent).getThrower();
@ -68,6 +79,10 @@ public class PacketEntitySpawn extends ForgePacket
data.writeInt(posX); data.writeInt(posX);
data.writeInt(posY); data.writeInt(posY);
data.writeInt(posZ); data.writeInt(posZ);
data.writeByte(yaw);
data.writeByte(pitch);
data.writeByte(yawHead);
((DataWatcher)metadata).writeWatchableObjects(data);
data.writeInt(throwerID); data.writeInt(throwerID);
if (throwerID != 0) if (throwerID != 0)
{ {
@ -89,6 +104,10 @@ public class PacketEntitySpawn extends ForgePacket
posX = data.readInt(); posX = data.readInt();
posY = data.readInt(); posY = data.readInt();
posZ = data.readInt(); posZ = data.readInt();
yaw = data.readByte();
pitch = data.readByte();
yawHead = data.readByte();
metadata = DataWatcher.readWatchableObjects(data);
throwerID = data.readInt(); throwerID = data.readInt();
if (throwerID != 0) if (throwerID != 0)
{ {