Properly sync thrower field for all throwable projectiles, fixes #42 (does not fix vanilla throwables though)

This commit is contained in:
Electroblob
2018-06-04 23:42:12 +01:00
parent 2cd8b46c1f
commit 54bb327fdf
3 changed files with 31 additions and 33 deletions
@@ -4,7 +4,6 @@ import io.netty.buffer.ByteBuf;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.registry.IEntityAdditionalSpawnData;
/**
* Same as {@link EntityMagicProjectile}, but with an additional blast multiplier field which is synced and saved to
@@ -13,7 +12,7 @@ import net.minecraftforge.fml.common.registry.IEntityAdditionalSpawnData;
* @author Electroblob
* @since Wizardry 1.2
*/
public abstract class EntityBomb extends EntityMagicProjectile implements IEntityAdditionalSpawnData {
public abstract class EntityBomb extends EntityMagicProjectile {
/** The entity blast multiplier. This is now synced and saved centrally from {@link EntityBomb}. */
public float blastMultiplier = 1.0f;
@@ -37,11 +36,13 @@ public abstract class EntityBomb extends EntityMagicProjectile implements IEntit
@Override
public void writeSpawnData(ByteBuf buffer){
super.writeSpawnData(buffer);
buffer.writeFloat(blastMultiplier);
}
@Override
public void readSpawnData(ByteBuf buffer){
super.readSpawnData(buffer);
blastMultiplier = buffer.readFloat();
}
@@ -1,7 +1,6 @@
package electroblob.wizardry.entity.projectile;
import java.util.List;
import io.netty.buffer.ByteBuf;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.projectile.EntityThrowable;
@@ -25,7 +24,7 @@ import net.minecraftforge.fml.common.registry.IEntityAdditionalSpawnData;
* @author Electroblob
* @see EntityBomb
*/
public abstract class EntityMagicProjectile extends EntityThrowable {
public abstract class EntityMagicProjectile extends EntityThrowable implements IEntityAdditionalSpawnData {
public float damageMultiplier = 1.0f;
@@ -42,6 +41,8 @@ public abstract class EntityMagicProjectile extends EntityThrowable {
// This is the standard set of parameters for this method, used by snowballs and ender pearls amongst others.
this.shoot(thrower, thrower.rotationPitch, thrower.rotationYaw, 0.0f, this.getSpeed(), 1.0f);
this.damageMultiplier = damageMultiplier;
// Mojang's 'fix' for the projectile-hitting-thrower bug actually made the problem worse, hence the following line.
this.ignoreEntity = thrower;
}
public EntityMagicProjectile(World world, double x, double y, double z){
@@ -78,17 +79,17 @@ public abstract class EntityMagicProjectile extends EntityThrowable {
// inside a mob using commands, it wouldn't hit that mob. This is so minor that it's not worth sending a packet
// for, though it may become more noticeable if spells firing from blocks are added.
// TODO: Investigate whether this is still necessary in 1.12
if(this.world.isRemote){
List<Entity> list = this.world.getEntitiesWithinAABBExcludingEntity(this, this.getEntityBoundingBox().expand(this.motionX, this.motionY, this.motionZ).grow(1.0D));
for(Entity entity : list){ // Why does vanilla still not use a for-each loop?
if(entity.canBeCollidedWith() && this.ticksExisted < 2 && this.ignoreEntity == null){
this.ignoreEntity = entity;
}
}
// Pretty sure EntityThrowable handles the rest.
}
// if(this.world.isRemote){
//
// List<Entity> list = this.world.getEntitiesWithinAABBExcludingEntity(this, this.getEntityBoundingBox().expand(this.motionX, this.motionY, this.motionZ).grow(1.0D));
//
// for(Entity entity : list){ // Why does vanilla still not use a for-each loop?
// if(entity.canBeCollidedWith() && this.ticksExisted < 2 && this.ignoreEntity == null){
// this.ignoreEntity = entity;
// }
// }
// // Pretty sure EntityThrowable handles the rest.
// }
super.onUpdate();
}
@@ -105,4 +106,16 @@ public abstract class EntityMagicProjectile extends EntityThrowable {
nbttagcompound.setFloat("damageMultiplier", damageMultiplier);
}
@Override
public void writeSpawnData(ByteBuf data){
data.writeInt(this.getThrower().getEntityId());
}
@Override
public void readSpawnData(ByteBuf data){
Entity entity = this.world.getEntityByID(data.readInt());
if(entity instanceof EntityLivingBase) this.thrower = (EntityLivingBase)entity;
this.ignoreEntity = this.thrower;
}
}
@@ -9,7 +9,6 @@ import electroblob.wizardry.util.MagicDamage;
import electroblob.wizardry.util.MagicDamage.DamageType;
import electroblob.wizardry.util.WizardryParticleType;
import electroblob.wizardry.util.WizardryUtilities;
import io.netty.buffer.ByteBuf;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
@@ -20,9 +19,6 @@ import net.minecraft.world.World;
public class EntitySparkBomb extends EntityBomb {
/** For client use, because thrower field is not visible. */
private int casterID;
public EntitySparkBomb(World par1World){
super(par1World);
}
@@ -84,7 +80,7 @@ public class EntitySparkBomb extends EntityBomb {
&& ((EntityPlayer)targets.get(i)).capabilities.isCreativeMode);
// Detects (client side) if target is the thrower, to stop particles being spawned around them.
if(flag && world.isRemote && targets.get(i).getEntityId() == this.casterID) flag = false;
//if(flag && world.isRemote && targets.get(i).getEntityId() == this.casterID) flag = false;
if(flag){
@@ -120,16 +116,4 @@ public class EntitySparkBomb extends EntityBomb {
this.setDead();
}
@Override
public void writeSpawnData(ByteBuf data){
super.writeSpawnData(data);
data.writeInt(this.getThrower().getEntityId());
}
@Override
public void readSpawnData(ByteBuf data){
super.readSpawnData(data);
this.casterID = data.readInt();
}
}