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 posY = (double)packet.posY / 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
{
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)
{
Minecraft mc = ModLoader.getMinecraftInstance();
@ -98,8 +101,6 @@ public class PacketHandlerClient implements IPacketHandler
entity.serverPosX = packet.posX;
entity.serverPosY = packet.posY;
entity.serverPosZ = packet.posZ;
entity.rotationYaw = 0.0F;
entity.rotationPitch = 0.0F;
Entity parts[] = entity.getParts();
if (parts != null)
@ -112,6 +113,17 @@ public class PacketHandlerClient implements IPacketHandler
}
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)
{

View file

@ -5,6 +5,8 @@ import java.io.DataOutputStream;
import java.io.IOException;
import net.minecraft.src.Entity;
import net.minecraft.src.EntityLiving;
import net.minecraft.src.DataWatcher;
import net.minecraft.src.MathHelper;
import net.minecraft.src.forge.ISpawnHandler;
import net.minecraft.src.forge.IThrowableEntity;
@ -13,16 +15,20 @@ import net.minecraft.src.forge.NetworkMod;
public class PacketEntitySpawn extends ForgePacket
{
public int modID;
public int entityID;
public int typeID;
public int posX;
public int posY;
public int posZ;
public byte yaw;
public byte pitch;
public byte yawHead;
public int throwerID;
public int speedX;
public int speedY;
public int speedZ;
public int typeID;
public int modID;
public int throwerID;
public Object metadata;
private ISpawnHandler handler;
public PacketEntitySpawn(){}
@ -37,6 +43,11 @@ public class PacketEntitySpawn extends ForgePacket
typeID = type;
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)
{
Entity owner = ((IThrowableEntity)ent).getThrower();
@ -68,6 +79,10 @@ public class PacketEntitySpawn extends ForgePacket
data.writeInt(posX);
data.writeInt(posY);
data.writeInt(posZ);
data.writeByte(yaw);
data.writeByte(pitch);
data.writeByte(yawHead);
((DataWatcher)metadata).writeWatchableObjects(data);
data.writeInt(throwerID);
if (throwerID != 0)
{
@ -89,6 +104,10 @@ public class PacketEntitySpawn extends ForgePacket
posX = data.readInt();
posY = data.readInt();
posZ = data.readInt();
yaw = data.readByte();
pitch = data.readByte();
yawHead = data.readByte();
metadata = DataWatcher.readWatchableObjects(data);
throwerID = data.readInt();
if (throwerID != 0)
{