From afb9650b12d0f6f3c9cde36a445daa50827f5b8f Mon Sep 17 00:00:00 2001 From: Vincent Lee Date: Sat, 14 Nov 2015 15:49:58 -0600 Subject: [PATCH] Update EntityThrowableCopy to 1.8 ver --- .../common/entity/EntityThrowableCopy.java | 298 +++++++++--------- 1 file changed, 147 insertions(+), 151 deletions(-) diff --git a/src/main/java/vazkii/botania/common/entity/EntityThrowableCopy.java b/src/main/java/vazkii/botania/common/entity/EntityThrowableCopy.java index 431e9720c..c094097a9 100644 --- a/src/main/java/vazkii/botania/common/entity/EntityThrowableCopy.java +++ b/src/main/java/vazkii/botania/common/entity/EntityThrowableCopy.java @@ -19,10 +19,7 @@ import net.minecraft.entity.IProjectile; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.AxisAlignedBB; -import net.minecraft.util.MathHelper; -import net.minecraft.util.MovingObjectPosition; -import net.minecraft.util.Vec3; +import net.minecraft.util.*; import net.minecraft.world.World; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; @@ -30,11 +27,12 @@ import net.minecraftforge.fml.relauncher.SideOnly; // A copy of the vanilla EntityThrowable class // Doing this because if I didn't do this it'd be an EntityThrowable // And we all know how much mods like deflecting EntityThrowables -public abstract class EntityThrowableCopy extends Entity implements IProjectile { - private int field_145788_c = -1; - private int field_145786_d = -1; - private int field_145787_e = -1; - private Block field_145785_f; +public abstract class EntityThrowableCopy extends Entity implements IProjectile +{ + private int xTile = -1; + private int yTile = -1; + private int zTile = -1; + private Block inTile; protected boolean inGround; public int throwableShake; /** The entity that threw this throwable item. */ @@ -42,177 +40,174 @@ public abstract class EntityThrowableCopy extends Entity implements IProjectile private String throwerName; private int ticksInGround; private int ticksInAir; - public EntityThrowableCopy(World p_i1776_1_) + private static final String __OBFID = "CL_00001723"; + + public EntityThrowable(World worldIn) { - super(p_i1776_1_); - setSize(0.25F, 0.25F); + super(worldIn); + this.setSize(0.25F, 0.25F); } - @Override protected void entityInit() {} /** * Checks if the entity is in range to render by using the past in distance and comparing it to its average edge * length * 64 * renderDistanceWeight Args: distance */ - @Override @SideOnly(Side.CLIENT) - public boolean isInRangeToRenderDist(double p_70112_1_) + public boolean isInRangeToRenderDist(double distance) { - double d1 = boundingBox.getAverageEdgeLength() * 4.0D; + double d1 = this.getEntityBoundingBox().getAverageEdgeLength() * 4.0D; d1 *= 64.0D; - return p_70112_1_ < d1 * d1; + return distance < d1 * d1; } - public EntityThrowableCopy(World p_i1777_1_, EntityLivingBase p_i1777_2_) + public EntityThrowable(World worldIn, EntityLivingBase throwerIn) { - super(p_i1777_1_); - thrower = p_i1777_2_; - setSize(0.25F, 0.25F); - setLocationAndAngles(p_i1777_2_.posX, p_i1777_2_.posY + p_i1777_2_.getEyeHeight(), p_i1777_2_.posZ, p_i1777_2_.rotationYaw, p_i1777_2_.rotationPitch); - posX -= MathHelper.cos(rotationYaw / 180.0F * (float)Math.PI) * 0.16F; - posY -= 0.10000000149011612D; - posZ -= MathHelper.sin(rotationYaw / 180.0F * (float)Math.PI) * 0.16F; - setPosition(posX, posY, posZ); - yOffset = 0.0F; + super(worldIn); + this.thrower = throwerIn; + this.setSize(0.25F, 0.25F); + this.setLocationAndAngles(throwerIn.posX, throwerIn.posY + (double)throwerIn.getEyeHeight(), throwerIn.posZ, throwerIn.rotationYaw, throwerIn.rotationPitch); + this.posX -= (double)(MathHelper.cos(this.rotationYaw / 180.0F * (float)Math.PI) * 0.16F); + this.posY -= 0.10000000149011612D; + this.posZ -= (double)(MathHelper.sin(this.rotationYaw / 180.0F * (float)Math.PI) * 0.16F); + this.setPosition(this.posX, this.posY, this.posZ); float f = 0.4F; - motionX = -MathHelper.sin(rotationYaw / 180.0F * (float)Math.PI) * MathHelper.cos(rotationPitch / 180.0F * (float)Math.PI) * f; - motionZ = MathHelper.cos(rotationYaw / 180.0F * (float)Math.PI) * MathHelper.cos(rotationPitch / 180.0F * (float)Math.PI) * f; - motionY = -MathHelper.sin((rotationPitch + func_70183_g()) / 180.0F * (float)Math.PI) * f; - setThrowableHeading(motionX, motionY, motionZ, func_70182_d(), 1.0F); + this.motionX = (double)(-MathHelper.sin(this.rotationYaw / 180.0F * (float)Math.PI) * MathHelper.cos(this.rotationPitch / 180.0F * (float)Math.PI) * f); + this.motionZ = (double)(MathHelper.cos(this.rotationYaw / 180.0F * (float)Math.PI) * MathHelper.cos(this.rotationPitch / 180.0F * (float)Math.PI) * f); + this.motionY = (double)(-MathHelper.sin((this.rotationPitch + this.getInaccuracy()) / 180.0F * (float)Math.PI) * f); + this.setThrowableHeading(this.motionX, this.motionY, this.motionZ, this.getVelocity(), 1.0F); } - public EntityThrowableCopy(World p_i1778_1_, double p_i1778_2_, double p_i1778_4_, double p_i1778_6_) + public EntityThrowable(World worldIn, double x, double y, double p_i1778_6_) { - super(p_i1778_1_); - ticksInGround = 0; - setSize(0.25F, 0.25F); - setPosition(p_i1778_2_, p_i1778_4_, p_i1778_6_); - yOffset = 0.0F; + super(worldIn); + this.ticksInGround = 0; + this.setSize(0.25F, 0.25F); + this.setPosition(x, y, p_i1778_6_); } - protected float func_70182_d() + protected float getVelocity() { return 1.5F; } - protected float func_70183_g() + protected float getInaccuracy() { return 0.0F; } /** * Similar to setArrowHeading, it's point the throwable entity to a x, y, z direction. + * + * @param inaccuracy Higher means more error. */ - @Override - public void setThrowableHeading(double p_70186_1_, double p_70186_3_, double p_70186_5_, float p_70186_7_, float p_70186_8_) + public void setThrowableHeading(double x, double y, double z, float velocity, float inaccuracy) { - float f2 = MathHelper.sqrt_double(p_70186_1_ * p_70186_1_ + p_70186_3_ * p_70186_3_ + p_70186_5_ * p_70186_5_); - p_70186_1_ /= f2; - p_70186_3_ /= f2; - p_70186_5_ /= f2; - p_70186_1_ += rand.nextGaussian() * 0.007499999832361937D * p_70186_8_; - p_70186_3_ += rand.nextGaussian() * 0.007499999832361937D * p_70186_8_; - p_70186_5_ += rand.nextGaussian() * 0.007499999832361937D * p_70186_8_; - p_70186_1_ *= p_70186_7_; - p_70186_3_ *= p_70186_7_; - p_70186_5_ *= p_70186_7_; - motionX = p_70186_1_; - motionY = p_70186_3_; - motionZ = p_70186_5_; - float f3 = MathHelper.sqrt_double(p_70186_1_ * p_70186_1_ + p_70186_5_ * p_70186_5_); - prevRotationYaw = rotationYaw = (float)(Math.atan2(p_70186_1_, p_70186_5_) * 180.0D / Math.PI); - prevRotationPitch = rotationPitch = (float)(Math.atan2(p_70186_3_, f3) * 180.0D / Math.PI); - ticksInGround = 0; + float f2 = MathHelper.sqrt_double(x * x + y * y + z * z); + x /= (double)f2; + y /= (double)f2; + z /= (double)f2; + x += this.rand.nextGaussian() * 0.007499999832361937D * (double)inaccuracy; + y += this.rand.nextGaussian() * 0.007499999832361937D * (double)inaccuracy; + z += this.rand.nextGaussian() * 0.007499999832361937D * (double)inaccuracy; + x *= (double)velocity; + y *= (double)velocity; + z *= (double)velocity; + this.motionX = x; + this.motionY = y; + this.motionZ = z; + float f3 = MathHelper.sqrt_double(x * x + z * z); + this.prevRotationYaw = this.rotationYaw = (float)(Math.atan2(x, z) * 180.0D / Math.PI); + this.prevRotationPitch = this.rotationPitch = (float)(Math.atan2(y, (double)f3) * 180.0D / Math.PI); + this.ticksInGround = 0; } /** * Sets the velocity to the args. Args: x, y, z */ - @Override @SideOnly(Side.CLIENT) - public void setVelocity(double p_70016_1_, double p_70016_3_, double p_70016_5_) + public void setVelocity(double x, double y, double z) { - motionX = p_70016_1_; - motionY = p_70016_3_; - motionZ = p_70016_5_; + this.motionX = x; + this.motionY = y; + this.motionZ = z; - if (prevRotationPitch == 0.0F && prevRotationYaw == 0.0F) + if (this.prevRotationPitch == 0.0F && this.prevRotationYaw == 0.0F) { - float f = MathHelper.sqrt_double(p_70016_1_ * p_70016_1_ + p_70016_5_ * p_70016_5_); - prevRotationYaw = rotationYaw = (float)(Math.atan2(p_70016_1_, p_70016_5_) * 180.0D / Math.PI); - prevRotationPitch = rotationPitch = (float)(Math.atan2(p_70016_3_, f) * 180.0D / Math.PI); + float f = MathHelper.sqrt_double(x * x + z * z); + this.prevRotationYaw = this.rotationYaw = (float)(Math.atan2(x, z) * 180.0D / Math.PI); + this.prevRotationPitch = this.rotationPitch = (float)(Math.atan2(y, (double)f) * 180.0D / Math.PI); } } /** * Called to update the entity's position/logic. */ - @Override public void onUpdate() { - lastTickPosX = posX; - lastTickPosY = posY; - lastTickPosZ = posZ; + this.lastTickPosX = this.posX; + this.lastTickPosY = this.posY; + this.lastTickPosZ = this.posZ; super.onUpdate(); - if (throwableShake > 0) + if (this.throwableShake > 0) { - --throwableShake; + --this.throwableShake; } - if (inGround) + if (this.inGround) { - if (worldObj.getBlock(field_145788_c, field_145786_d, field_145787_e) == field_145785_f) + if (this.worldObj.getBlockState(new BlockPos(this.xTile, this.yTile, this.zTile)).getBlock() == this.inTile) { - ++ticksInGround; + ++this.ticksInGround; - if (ticksInGround == 1200) + if (this.ticksInGround == 1200) { - setDead(); + this.setDead(); } return; } - inGround = false; - motionX *= rand.nextFloat() * 0.2F; - motionY *= rand.nextFloat() * 0.2F; - motionZ *= rand.nextFloat() * 0.2F; - ticksInGround = 0; - ticksInAir = 0; + this.inGround = false; + this.motionX *= (double)(this.rand.nextFloat() * 0.2F); + this.motionY *= (double)(this.rand.nextFloat() * 0.2F); + this.motionZ *= (double)(this.rand.nextFloat() * 0.2F); + this.ticksInGround = 0; + this.ticksInAir = 0; } else { - ++ticksInAir; + ++this.ticksInAir; } - Vec3 vec3 = new Vec3(posX, posY, posZ); - Vec3 vec31 = new Vec3(posX + motionX, posY + motionY, posZ + motionZ); - MovingObjectPosition movingobjectposition = worldObj.rayTraceBlocks(vec3, vec31); - vec3 = new Vec3(posX, posY, posZ); - vec31 = new Vec3(posX + motionX, posY + motionY, posZ + motionZ); + Vec3 vec3 = new Vec3(this.posX, this.posY, this.posZ); + Vec3 vec31 = new Vec3(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ); + MovingObjectPosition movingobjectposition = this.worldObj.rayTraceBlocks(vec3, vec31); + vec3 = new Vec3(this.posX, this.posY, this.posZ); + vec31 = new Vec3(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ); if (movingobjectposition != null) { vec31 = new Vec3(movingobjectposition.hitVec.xCoord, movingobjectposition.hitVec.yCoord, movingobjectposition.hitVec.zCoord); } - if (!worldObj.isRemote) + if (!this.worldObj.isRemote) { Entity entity = null; - List list = worldObj.getEntitiesWithinAABBExcludingEntity(this, boundingBox.addCoord(motionX, motionY, motionZ).expand(1.0D, 1.0D, 1.0D)); + List list = this.worldObj.getEntitiesWithinAABBExcludingEntity(this, this.getEntityBoundingBox().addCoord(this.motionX, this.motionY, this.motionZ).expand(1.0D, 1.0D, 1.0D)); double d0 = 0.0D; - EntityLivingBase entitylivingbase = getThrower(); + EntityLivingBase entitylivingbase = this.getThrower(); for (int j = 0; j < list.size(); ++j) { Entity entity1 = (Entity)list.get(j); - if (entity1.canBeCollidedWith() && (entity1 != entitylivingbase || ticksInAir >= 5)) + if (entity1.canBeCollidedWith() && (entity1 != entitylivingbase || this.ticksInAir >= 5)) { float f = 0.3F; - AxisAlignedBB axisalignedbb = entity1.boundingBox.expand(f, f, f); + AxisAlignedBB axisalignedbb = entity1.getEntityBoundingBox().expand((double)f, (double)f, (double)f); MovingObjectPosition movingobjectposition1 = axisalignedbb.calculateIntercept(vec3, vec31); if (movingobjectposition1 != null) @@ -236,63 +231,63 @@ public abstract class EntityThrowableCopy extends Entity implements IProjectile if (movingobjectposition != null) { - if (movingobjectposition.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK && worldObj.getBlock(movingobjectposition.blockX, movingobjectposition.blockY, movingobjectposition.blockZ) == Blocks.portal) + if (movingobjectposition.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK && this.worldObj.getBlockState(movingobjectposition.getBlockPos()).getBlock() == Blocks.portal) { - setInPortal(); + this.setInPortal(); } else { - onImpact(movingobjectposition); + this.onImpact(movingobjectposition); } } - posX += motionX; - posY += motionY; - posZ += motionZ; - float f1 = MathHelper.sqrt_double(motionX * motionX + motionZ * motionZ); - rotationYaw = (float)(Math.atan2(motionX, motionZ) * 180.0D / Math.PI); + this.posX += this.motionX; + this.posY += this.motionY; + this.posZ += this.motionZ; + float f1 = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ); + this.rotationYaw = (float)(Math.atan2(this.motionX, this.motionZ) * 180.0D / Math.PI); - for (rotationPitch = (float)(Math.atan2(motionY, f1) * 180.0D / Math.PI); rotationPitch - prevRotationPitch < -180.0F; prevRotationPitch -= 360.0F) + for (this.rotationPitch = (float)(Math.atan2(this.motionY, (double)f1) * 180.0D / Math.PI); this.rotationPitch - this.prevRotationPitch < -180.0F; this.prevRotationPitch -= 360.0F) { ; } - while (rotationPitch - prevRotationPitch >= 180.0F) + while (this.rotationPitch - this.prevRotationPitch >= 180.0F) { - prevRotationPitch += 360.0F; + this.prevRotationPitch += 360.0F; } - while (rotationYaw - prevRotationYaw < -180.0F) + while (this.rotationYaw - this.prevRotationYaw < -180.0F) { - prevRotationYaw -= 360.0F; + this.prevRotationYaw -= 360.0F; } - while (rotationYaw - prevRotationYaw >= 180.0F) + while (this.rotationYaw - this.prevRotationYaw >= 180.0F) { - prevRotationYaw += 360.0F; + this.prevRotationYaw += 360.0F; } - rotationPitch = prevRotationPitch + (rotationPitch - prevRotationPitch) * 0.2F; - rotationYaw = prevRotationYaw + (rotationYaw - prevRotationYaw) * 0.2F; + this.rotationPitch = this.prevRotationPitch + (this.rotationPitch - this.prevRotationPitch) * 0.2F; + this.rotationYaw = this.prevRotationYaw + (this.rotationYaw - this.prevRotationYaw) * 0.2F; float f2 = 0.99F; - float f3 = getGravityVelocity(); + float f3 = this.getGravityVelocity(); - if (isInWater()) + if (this.isInWater()) { for (int i = 0; i < 4; ++i) { float f4 = 0.25F; - worldObj.spawnParticle("bubble", posX - motionX * f4, posY - motionY * f4, posZ - motionZ * f4, motionX, motionY, motionZ); + this.worldObj.spawnParticle(EnumParticleTypes.WATER_BUBBLE, this.posX - this.motionX * (double)f4, this.posY - this.motionY * (double)f4, this.posZ - this.motionZ * (double)f4, this.motionX, this.motionY, this.motionZ, new int[0]); } f2 = 0.8F; } - motionX *= f2; - motionY *= f2; - motionZ *= f2; - motionY -= f3; - setPosition(posX, posY, posZ); + this.motionX *= (double)f2; + this.motionY *= (double)f2; + this.motionZ *= (double)f2; + this.motionY -= (double)f3; + this.setPosition(this.posX, this.posY, this.posZ); } /** @@ -311,58 +306,59 @@ public abstract class EntityThrowableCopy extends Entity implements IProjectile /** * (abstract) Protected helper method to write subclass entity data to NBT. */ - @Override - public void writeEntityToNBT(NBTTagCompound p_70014_1_) + public void writeEntityToNBT(NBTTagCompound tagCompound) { - p_70014_1_.setShort("xTile", (short)field_145788_c); - p_70014_1_.setShort("yTile", (short)field_145786_d); - p_70014_1_.setShort("zTile", (short)field_145787_e); - p_70014_1_.setByte("inTile", (byte)Block.getIdFromBlock(field_145785_f)); - p_70014_1_.setByte("shake", (byte)throwableShake); - p_70014_1_.setByte("inGround", (byte)(inGround ? 1 : 0)); + tagCompound.setShort("xTile", (short)this.xTile); + tagCompound.setShort("yTile", (short)this.yTile); + tagCompound.setShort("zTile", (short)this.zTile); + ResourceLocation resourcelocation = (ResourceLocation)Block.blockRegistry.getNameForObject(this.inTile); + tagCompound.setString("inTile", resourcelocation == null ? "" : resourcelocation.toString()); + tagCompound.setByte("shake", (byte)this.throwableShake); + tagCompound.setByte("inGround", (byte)(this.inGround ? 1 : 0)); - if ((throwerName == null || throwerName.length() == 0) && thrower != null && thrower instanceof EntityPlayer) + if ((this.throwerName == null || this.throwerName.length() == 0) && this.thrower instanceof EntityPlayer) { - throwerName = thrower.getCommandSenderName(); + this.throwerName = this.thrower.getCommandSenderName(); } - p_70014_1_.setString("ownerName", throwerName == null ? "" : throwerName); + tagCompound.setString("ownerName", this.throwerName == null ? "" : this.throwerName); } /** * (abstract) Protected helper method to read subclass entity data from NBT. */ - @Override - public void readEntityFromNBT(NBTTagCompound p_70037_1_) + public void readEntityFromNBT(NBTTagCompound tagCompund) { - field_145788_c = p_70037_1_.getShort("xTile"); - field_145786_d = p_70037_1_.getShort("yTile"); - field_145787_e = p_70037_1_.getShort("zTile"); - field_145785_f = Block.getBlockById(p_70037_1_.getByte("inTile") & 255); - throwableShake = p_70037_1_.getByte("shake") & 255; - inGround = p_70037_1_.getByte("inGround") == 1; - throwerName = p_70037_1_.getString("ownerName"); + this.xTile = tagCompund.getShort("xTile"); + this.yTile = tagCompund.getShort("yTile"); + this.zTile = tagCompund.getShort("zTile"); - if (throwerName != null && throwerName.length() == 0) + if (tagCompund.hasKey("inTile", 8)) { - throwerName = null; + this.inTile = Block.getBlockFromName(tagCompund.getString("inTile")); + } + else + { + this.inTile = Block.getBlockById(tagCompund.getByte("inTile") & 255); } - } - @Override - @SideOnly(Side.CLIENT) - public float getShadowSize() - { - return 0.0F; + this.throwableShake = tagCompund.getByte("shake") & 255; + this.inGround = tagCompund.getByte("inGround") == 1; + this.throwerName = tagCompund.getString("ownerName"); + + if (this.throwerName != null && this.throwerName.length() == 0) + { + this.throwerName = null; + } } public EntityLivingBase getThrower() { - if (thrower == null && throwerName != null && throwerName.length() > 0) + if (this.thrower == null && this.throwerName != null && this.throwerName.length() > 0) { - thrower = worldObj.getPlayerEntityByName(throwerName); + this.thrower = this.worldObj.getPlayerEntityByName(this.throwerName); } - return thrower; + return this.thrower; } } \ No newline at end of file