package micdoodle8.mods.galacticraft.planets.venus.entities; import micdoodle8.mods.galacticraft.core.Constants; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.IProjectile; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.potion.Potion; import net.minecraft.potion.PotionEffect; import net.minecraft.util.*; import net.minecraft.world.World; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import java.util.List; public class EntityWebShot extends Entity implements IProjectile { public int canBePickedUp; public int arrowShake; public Entity shootingEntity; private int ticksInAir; public EntityWebShot(World worldIn) { super(worldIn); this.renderDistanceWeight = 10.0D; this.setSize(0.5F, 0.5F); } public EntityWebShot(World worldIn, double x, double y, double z) { super(worldIn); this.renderDistanceWeight = 10.0D; this.setSize(0.5F, 0.5F); this.setPosition(x, y, z); } public EntityWebShot(World worldIn, EntityLivingBase shooter, EntityLivingBase target, float p_i1755_4_, float p_i1755_5_) { super(worldIn); this.renderDistanceWeight = 10.0D; this.shootingEntity = shooter; if (shooter instanceof EntityPlayer) { this.canBePickedUp = 1; } this.posY = shooter.posY + (double)shooter.getEyeHeight() - 0.10000000149011612D; double d0 = target.posX - shooter.posX; double d1 = target.getEntityBoundingBox().minY + (double)(target.height / 3.0F) - this.posY; double d2 = target.posZ - shooter.posZ; double d3 = (double)MathHelper.sqrt_double(d0 * d0 + d2 * d2); if (d3 >= 1.0E-7D) { float f = (float) MathHelper.atan2(d2, d0) * Constants.RADIANS_TO_DEGREES - 90.0F; float f1 = (float) MathHelper.atan2(d1, d3) * -Constants.RADIANS_TO_DEGREES; double d4 = d0 / d3; double d5 = d2 / d3; this.setLocationAndAngles(shooter.posX + d4, this.posY, shooter.posZ + d5, f, f1); float f2 = (float)(d3 * 0.20000000298023224D); this.setThrowableHeading(d0, d1 + (double)f2, d2, p_i1755_4_, p_i1755_5_); } } public EntityWebShot(World worldIn, EntityLivingBase shooter, float velocity) { super(worldIn); this.renderDistanceWeight = 10.0D; this.shootingEntity = shooter; if (shooter instanceof EntityPlayer) { this.canBePickedUp = 1; } this.setSize(0.5F, 0.5F); this.setLocationAndAngles(shooter.posX, shooter.posY + (double)shooter.getEyeHeight(), shooter.posZ, shooter.rotationYaw, shooter.rotationPitch); this.posX -= (double)(MathHelper.cos(this.rotationYaw / Constants.RADIANS_TO_DEGREES) * 0.16F); this.posY -= 0.10000000149011612D; this.posZ -= (double)(MathHelper.sin(this.rotationYaw / Constants.RADIANS_TO_DEGREES) * 0.16F); this.setPosition(this.posX, this.posY, this.posZ); this.motionX = (double)(-MathHelper.sin(this.rotationYaw / Constants.RADIANS_TO_DEGREES) * MathHelper.cos(this.rotationPitch / Constants.RADIANS_TO_DEGREES)); this.motionZ = (double)(MathHelper.cos(this.rotationYaw / Constants.RADIANS_TO_DEGREES) * MathHelper.cos(this.rotationPitch / Constants.RADIANS_TO_DEGREES)); this.motionY = (double)(-MathHelper.sin(this.rotationPitch / Constants.RADIANS_TO_DEGREES)); this.setThrowableHeading(this.motionX, this.motionY, this.motionZ, velocity * 1.5F, 1.0F); } @Override protected void entityInit() { } @Override public void setThrowableHeading(double x, double y, double z, float velocity, float inaccuracy) { float f = MathHelper.sqrt_double(x * x + y * y + z * z); x = x / (double)f; y = y / (double)f; z = z / (double)f; x = x + this.rand.nextGaussian() * (double)(this.rand.nextBoolean() ? -1 : 1) * 0.007499999832361937D * (double)inaccuracy; y = y + this.rand.nextGaussian() * (double)(this.rand.nextBoolean() ? -1 : 1) * 0.007499999832361937D * (double)inaccuracy; z = z + this.rand.nextGaussian() * (double)(this.rand.nextBoolean() ? -1 : 1) * 0.007499999832361937D * (double)inaccuracy; x = x * (double)velocity; y = y * (double)velocity; z = z * (double)velocity; this.motionX = x; this.motionY = y; this.motionZ = z; float f1 = MathHelper.sqrt_double(x * x + z * z); this.prevRotationYaw = this.rotationYaw = (float) MathHelper.atan2(x, z) * Constants.RADIANS_TO_DEGREES; this.prevRotationPitch = this.rotationPitch = (float) MathHelper.atan2(y, (double)f1) * Constants.RADIANS_TO_DEGREES; } @Override @SideOnly(Side.CLIENT) public void setPositionAndRotation2(double x, double y, double z, float yaw, float pitch, int posRotationIncrements, boolean p_180426_10_) { this.setPosition(x, y, z); this.setRotation(yaw, pitch); } @Override @SideOnly(Side.CLIENT) public void setVelocity(double x, double y, double z) { this.motionX = x; this.motionY = y; this.motionZ = z; if (this.prevRotationPitch == 0.0F && this.prevRotationYaw == 0.0F) { float f = MathHelper.sqrt_double(x * x + z * z); this.prevRotationYaw = this.rotationYaw = (float) MathHelper.atan2(x, z) * Constants.RADIANS_TO_DEGREES; this.prevRotationPitch = this.rotationPitch = (float) MathHelper.atan2(y, (double)f) * Constants.RADIANS_TO_DEGREES; this.prevRotationPitch = this.rotationPitch; this.prevRotationYaw = this.rotationYaw; this.setLocationAndAngles(this.posX, this.posY, this.posZ, this.rotationYaw, this.rotationPitch); } } @Override public void onUpdate() { super.onUpdate(); if (this.prevRotationPitch == 0.0F && this.prevRotationYaw == 0.0F) { float f = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ); this.prevRotationYaw = this.rotationYaw = (float) MathHelper.atan2(this.motionX, this.motionZ) * Constants.RADIANS_TO_DEGREES; this.prevRotationPitch = this.rotationPitch = (float) MathHelper.atan2(this.motionY, (double)f) * Constants.RADIANS_TO_DEGREES; } if (this.arrowShake > 0) { --this.arrowShake; } if (this.ticksExisted > 1000) { this.setDead(); } ++this.ticksInAir; Vec3 vec31 = new Vec3(this.posX, this.posY, this.posZ); Vec3 vec3 = new Vec3(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ); MovingObjectPosition movingobjectposition = this.worldObj.rayTraceBlocks(vec31, vec3, false, true, false); vec31 = new Vec3(this.posX, this.posY, this.posZ); vec3 = new Vec3(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ); if (movingobjectposition != null) { vec3 = new Vec3(movingobjectposition.hitVec.xCoord, movingobjectposition.hitVec.yCoord, movingobjectposition.hitVec.zCoord); } Entity entity = null; List<Entity> 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; for (int i = 0; i < list.size(); ++i) { Entity entity1 = (Entity)list.get(i); if (entity1.canBeCollidedWith() && (entity1 != this.shootingEntity || this.ticksInAir >= 5)) { float f1 = 0.3F; AxisAlignedBB axisalignedbb1 = entity1.getEntityBoundingBox().expand((double)f1, (double)f1, (double)f1); MovingObjectPosition movingobjectposition1 = axisalignedbb1.calculateIntercept(vec31, vec3); if (movingobjectposition1 != null) { double d1 = vec31.squareDistanceTo(movingobjectposition1.hitVec); if (d1 < d0 || d0 == 0.0D) { entity = entity1; d0 = d1; } } } } if (entity != null) { movingobjectposition = new MovingObjectPosition(entity); } if (movingobjectposition != null && movingobjectposition.entityHit != null && movingobjectposition.entityHit instanceof EntityPlayer) { EntityPlayer entityplayer = (EntityPlayer)movingobjectposition.entityHit; if (entityplayer.capabilities.disableDamage || this.shootingEntity instanceof EntityPlayer && !((EntityPlayer)this.shootingEntity).canAttackPlayer(entityplayer)) { movingobjectposition = null; } } if (movingobjectposition != null) { if (movingobjectposition.entityHit != null) { if (movingobjectposition.entityHit != this.shootingEntity && !this.worldObj.isRemote) { if (movingobjectposition.entityHit instanceof EntityLivingBase) { ((EntityLivingBase) movingobjectposition.entityHit).addPotionEffect(new PotionEffect(Potion.moveSlowdown.id, 180, 2, true, true)); this.setDead(); } else { this.motionX *= -0.10000000149011612D; this.motionY *= -0.10000000149011612D; this.motionZ *= -0.10000000149011612D; this.rotationYaw += 180.0F; this.prevRotationYaw += 180.0F; this.ticksInAir = 0; } } } else { this.motionX = (double)((float)(movingobjectposition.hitVec.xCoord - this.posX)); this.motionY = (double)((float)(movingobjectposition.hitVec.yCoord - this.posY)); this.motionZ = (double)((float)(movingobjectposition.hitVec.zCoord - this.posZ)); float f5 = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionY * this.motionY + this.motionZ * this.motionZ); this.posX -= this.motionX / (double)f5 * 0.05000000074505806D; this.posY -= this.motionY / (double)f5 * 0.05000000074505806D; this.posZ -= this.motionZ / (double)f5 * 0.05000000074505806D; this.arrowShake = 7; this.setDead(); } } this.posX += this.motionX; this.posY += this.motionY; this.posZ += this.motionZ; float f3 = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ); this.rotationYaw = (float) MathHelper.atan2(this.motionX, this.motionZ) * Constants.RADIANS_TO_DEGREES; for (this.rotationPitch = (float) MathHelper.atan2(this.motionY, (double)f3) * Constants.RADIANS_TO_DEGREES; this.rotationPitch - this.prevRotationPitch < -180.0F; this.prevRotationPitch -= 360.0F) { } while (this.rotationPitch - this.prevRotationPitch >= 180.0F) { this.prevRotationPitch += 360.0F; } while (this.rotationYaw - this.prevRotationYaw < -180.0F) { this.prevRotationYaw -= 360.0F; } while (this.rotationYaw - this.prevRotationYaw >= 180.0F) { this.prevRotationYaw += 360.0F; } this.rotationPitch = this.prevRotationPitch + (this.rotationPitch - this.prevRotationPitch) * 0.2F; this.rotationYaw = this.prevRotationYaw + (this.rotationYaw - this.prevRotationYaw) * 0.2F; if (this.isInWater()) { for (int i1 = 0; i1 < 4; ++i1) { float f8 = 0.25F; this.worldObj.spawnParticle(EnumParticleTypes.WATER_BUBBLE, this.posX - this.motionX * (double)f8, this.posY - this.motionY * (double)f8, this.posZ - this.motionZ * (double)f8, this.motionX, this.motionY, this.motionZ); } } if (this.isWet()) { this.extinguish(); } this.setPosition(this.posX, this.posY, this.posZ); this.doBlockCollisions(); } @Override public void writeEntityToNBT(NBTTagCompound tagCompound) { tagCompound.setByte("shake", (byte)this.arrowShake); tagCompound.setByte("pickup", (byte)this.canBePickedUp); } @Override public void readEntityFromNBT(NBTTagCompound tagCompund) { this.arrowShake = tagCompund.getByte("shake") & 255; if (tagCompund.hasKey("pickup", 99)) { this.canBePickedUp = tagCompund.getByte("pickup"); } } @Override protected boolean canTriggerWalking() { return false; } @Override public boolean canAttackWithItem() { return false; } @Override public float getEyeHeight() { return 0.0F; } }