Add condition to only write magic projectile thrower to spawn data if the thrower exists and tweak overrides so it is always written/read last, fixes #71

This commit is contained in:
Electroblob77
2019-01-04 20:04:43 +00:00
parent 83edb8007e
commit 98b334e6d7
2 changed files with 11 additions and 6 deletions
@@ -36,14 +36,14 @@ public abstract class EntityBomb extends EntityMagicProjectile {
@Override
public void writeSpawnData(ByteBuf buffer){
super.writeSpawnData(buffer);
buffer.writeFloat(blastMultiplier);
super.writeSpawnData(buffer);
}
@Override
public void readSpawnData(ByteBuf buffer){
super.readSpawnData(buffer);
blastMultiplier = buffer.readFloat();
super.readSpawnData(buffer);
}
@Override
@@ -107,15 +107,20 @@ public abstract class EntityMagicProjectile extends EntityThrowable implements I
}
@Override
// For now, we're only writing when the thrower exists, so subclasses MUST CALL SUPER LAST.
// TODO: Figure out whether there's a default value we can write that is never used as an entity id (0? -1? +/-MAX_VALUE?)
public void writeSpawnData(ByteBuf data){
data.writeInt(this.getThrower().getEntityId());
if(this.getThrower() != null) data.writeInt(this.getThrower().getEntityId());
}
@Override
// For now, we're only writing when the thrower exists, so subclasses MUST CALL SUPER LAST.
public void readSpawnData(ByteBuf data){
Entity entity = this.world.getEntityByID(data.readInt());
if(entity instanceof EntityLivingBase) this.thrower = (EntityLivingBase)entity;
this.ignoreEntity = this.thrower;
if(data.isReadable()){
Entity entity = this.world.getEntityByID(data.readInt());
if(entity instanceof EntityLivingBase) this.thrower = (EntityLivingBase)entity;
this.ignoreEntity = this.thrower;
}
}
}