/** * Similar to setArrowHeading, it's point the throwable entity to a x, y, z direction. */ public void shoot(double x, double y, double z, float velocity, float inaccuracy) { float f = MathHelper.sqrt(x * x + y * y + z * z); x = x / (double)f; y = y / (double)f; z = z / (double)f; x = x + this.rand.nextGaussian() * 0.007499999832361937D * (double)inaccuracy; y = y + this.rand.nextGaussian() * 0.007499999832361937D * (double)inaccuracy; z = z + this.rand.nextGaussian() * 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(x * x + z * z); this.rotationYaw = (float)(MathHelper.atan2(x, z) * (180D / Math.PI)); this.rotationPitch = (float)(MathHelper.atan2(y, (double)f1) * (180D / Math.PI)); this.prevRotationYaw = this.rotationYaw; this.prevRotationPitch = this.rotationPitch; this.ticksInGround = 0; }
/** * Updates the entity motion clientside, called by packets from the server */ @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(x * x + z * z); this.rotationYaw = (float)(MathHelper.atan2(x, z) * (180D / Math.PI)); this.rotationPitch = (float)(MathHelper.atan2(y, (double)f) * (180D / Math.PI)); this.prevRotationYaw = this.rotationYaw; this.prevRotationPitch = this.rotationPitch; } }
private static void renderItemInFirstPerson(AbstractClientPlayer player, float partialTicks, float interpPitch, EnumHand hand, float swingProgress, ItemStack stack, float equipProgress) throws Throwable { // Cherry picked from ItemRenderer.renderItemInFirstPerson boolean flag = hand == EnumHand.MAIN_HAND; EnumHandSide enumhandside = flag ? player.getPrimaryHand() : player.getPrimaryHand().opposite(); GlStateManager.pushMatrix(); boolean flag1 = enumhandside == EnumHandSide.RIGHT; float f = -0.4F * MathHelper.sin(MathHelper.sqrt(swingProgress) * (float)Math.PI); float f1 = 0.2F * MathHelper.sin(MathHelper.sqrt(swingProgress) * ((float)Math.PI * 2F)); float f2 = -0.2F * MathHelper.sin(swingProgress * (float)Math.PI); int i = flag1 ? 1 : -1; GlStateManager.translate(i * f, f1, f2); transformSideFirstPerson(enumhandside, equipProgress); transformFirstPerson(enumhandside, swingProgress); doRender(enumhandside, partialTicks, stack); GlStateManager.popMatrix(); }
public EntityDragonFireCharge(World worldIn, EntityDragonBase shooter, double accelX, double accelY, double accelZ) { super(worldIn, shooter, accelX, accelY, accelZ); double d0 = (double) MathHelper.sqrt(accelX * accelX + accelY * accelY + accelZ * accelZ); this.accelerationX = accelX / d0 * 0.07D; this.accelerationY = accelY / d0 * 0.07D; this.accelerationZ = accelZ / d0 * 0.07D; }
public float getDistanceFrom(Node node) { if (node == null) { return 0; } float x = this.x - node.x; float y = this.y - node.y; float z = this.z - node.z; return MathHelper.sqrt(x * x + y * y + z * z); }
/** * Euclidean distance between this and the specified vector, returned as double. */ public double distanceTo(MutableVec3 vec) { double d0 = vec.xCoord - this.xCoord; double d1 = vec.yCoord - this.yCoord; double d2 = vec.zCoord - this.zCoord; return (double) MathHelper.sqrt(d0 * d0 + d1 * d1 + d2 * d2); }
public EntityDragonIceCharge(World worldIn, double posX, double posY, double posZ, double accelX, double accelY, double accelZ) { super(worldIn, posX, posY, posZ, accelX, accelY, accelZ); double d0 = (double) MathHelper.sqrt(accelX * accelX + accelY * accelY + accelZ * accelZ); this.accelerationX = accelX / d0 * 0.07D; this.accelerationY = accelY / d0 * 0.07D; this.accelerationZ = accelZ / d0 * 0.07D; }
public NormalTerrainGenerator() { this.heightMap = new double[825]; this.biomeWeights = new float[25]; for (int j = -2; j <= 2; ++j) { for (int k = -2; k <= 2; ++k) { float f = 10.0F / MathHelper.sqrt((j * j + k * k) + 0.2F); this.biomeWeights[j + 2 + (k + 2) * 5] = f; } } }
public float getDistanceFrom(int x, int y, int z) { float x1 = this.x - x; float y1 = this.y - y; float z1 = this.z - z; return MathHelper.sqrt(x1 * x1 + y1 * y1 + z1 * z1); }
private static void transformFirstPerson(EnumHandSide p_187453_1_, float p_187453_2_) { int i = p_187453_1_ == EnumHandSide.RIGHT ? 1 : -1; // Botania - added GlStateManager.translate(p_187453_1_ == EnumHandSide.RIGHT ? 0.2F : 0.52F, -0.125F, p_187453_1_ == EnumHandSide.RIGHT ? 0.6F : 0.25F); GlStateManager.rotate(p_187453_1_ == EnumHandSide.RIGHT ? 60F : 120F, 0F, 1F, 0F); GlStateManager.rotate(30F, 0F, 0F, -1F); // End add float f = MathHelper.sin(p_187453_2_ * p_187453_2_ * (float)Math.PI); GlStateManager.rotate(i * (45.0F + f * -20.0F), 0.0F, 1.0F, 0.0F); float f1 = MathHelper.sin(MathHelper.sqrt(p_187453_2_) * (float)Math.PI); GlStateManager.rotate(i * f1 * -20.0F, 0.0F, 0.0F, 1.0F); GlStateManager.rotate(f1 * -80.0F, 1.0F, 0.0F, 0.0F); GlStateManager.rotate(i * -45.0F, 0.0F, 1.0F, 0.0F); }
public Vector3 normalize() { double d0 = (double) MathHelper.sqrt(this.x * this.x + this.y * this.y + this.z * this.z); if (d0 < 1.0E-4D) { this.set(0.0D, 0.0D, 0.0D); } else { this.x /= d0; this.y /= d0; this.z /= d0; } return this; }
this.posY += this.motionY; this.posZ += this.motionZ; float f = MathHelper.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ); this.rotationYaw = (float)(MathHelper.atan2(this.motionX, this.motionZ) * (180D / Math.PI));
@Override protected void applyRotations(@Nonnull EntityDireSlime p_77043_1_, float p_77043_2_, float p_77043_3_, float p_77043_4_) { // this.rotateCorpse(entityLiving, p_77043_2_, p_77043_3_, partialTicks); if (p_77043_1_.deathTime > 0) { float f3 = (p_77043_1_.deathTime + p_77043_4_ - 1.0F) / 20.0F * 1.6F; f3 = Math.max(MathHelper.sqrt(f3), 1.0F); GL11.glRotatef(f3 * this.getDeathMaxRotation(p_77043_1_), 0.0F, 0.0F, 1.0F); } }
private void calculatePistonPosition2(float crankAngleRadians, float radius, float length) { float cA = MathHelper.cos(crankAngleRadians); float sA = MathHelper.sin(crankAngleRadians); float pistonPos2 = radius * cA + MathHelper.sqrt(length * length - radius * radius * sA * sA); float bx = sA * radius; float by = cA * radius; float cx = -2f; armAngle2 = (float) Math.atan2(cx - bx, pistonPos2 - by); } }
/** * Normalizes the vector to a length of 1 (except if it is the zero vector) */ public MutableVec3 normalize() { double d0 = (double) MathHelper.sqrt(this.xCoord * this.xCoord + this.yCoord * this.yCoord + this.zCoord * this.zCoord); if (d0 < 1.0E-4D) { this.set(0, 0, 0); } else { this.set(this.xCoord / d0, this.yCoord / d0, this.zCoord / d0); } return this; }
posY += motionY; posZ += motionZ; float f = MathHelper.sqrt(motionX * motionX + motionZ * motionZ); rotationYaw = (float)(MathHelper.atan2(motionX, motionZ) * (180D / Math.PI));
@Override public void attackEntityWithRangedAttack(EntityLivingBase entity, float range) { EntitySporeBall sporeball = new EntitySporeBall(getEntityWorld(), this); double distanceX = entity.posX - posX; double distanceY = entity.posY + height - 4D - sporeball.posY; double distanceZ = entity.posZ - posZ; float height = MathHelper.sqrt(distanceX * distanceX + distanceZ * distanceZ) * 0.2F; sporeball.shoot(distanceX, distanceY + height, distanceZ, 0.8F, 0.0F); getEntityWorld().playSound(null, getPosition(), ModSounds.SPRAY_CAN_SOUND, SoundCategory.HOSTILE, 0.5F, 0.1F / (getRNG().nextFloat() * 0.4F + 0.8F)); getEntityWorld().spawnEntity(sporeball); }
public EntityDragonFire(World worldIn, EntityDragonBase shooter, double accelX, double accelY, double accelZ) { super(worldIn, shooter, accelX, accelY, accelZ); this.setSize(0.5F, 0.5F); double d0 = (double) MathHelper.sqrt(accelX * accelX + accelY * accelY + accelZ * accelZ); this.accelerationX = accelX / d0 * (0.1D * (shooter.isFlying() ? 4 * shooter.getDragonStage() : 1)); this.accelerationY = accelY / d0 * (0.1D * (shooter.isFlying() ? 4 * shooter.getDragonStage() : 1)); this.accelerationZ = accelZ / d0 * (0.1D * (shooter.isFlying() ? 4 * shooter.getDragonStage() : 1)); }
public void faceEntity(Entity entityIn) { double d0 = entityIn.posX - this.posX; double d2 = entityIn.posZ - this.posZ; double d1; if (entityIn instanceof EntityLivingBase) { EntityLivingBase entitylivingbase = (EntityLivingBase) entityIn; d1 = entitylivingbase.posY + entitylivingbase.getEyeHeight() - (this.posY + this.getEyeHeight()); } else { d1 = (entityIn.getEntityBoundingBox().minY + entityIn.getEntityBoundingBox().maxY) / 2.0D - (this.posY + this.getEyeHeight()); } double d3 = MathHelper.sqrt(d0 * d0 + d2 * d2); rotationPitch = MathHelper.wrapDegrees((float) (-(MathHelper.atan2(d1, d3) * (180D / Math.PI)))); rotationYaw = MathHelper.wrapDegrees((float) (MathHelper.atan2(d2, d0) * (180D / Math.PI)) - 90.0F); }
protected void attackWithCrossbow(EntityLivingBase target) { ItemStack arrows = attacker.getArrowStackForAttack(target); EntityCrossbowArrow entityArrow = EntityCrossbowArrow.createWithShooter(entity.getEntityWorld(), entity, 0, 0.3F, !entity.isLeftHanded(), arrows); double sx = target.posX - entityArrow.posX; double sy = target.getEntityBoundingBox().minY + (double) (target.height / 3.0F) - entityArrow.posY; double sz = target.posZ - entityArrow.posZ; double dist = MathHelper.sqrt(sx * sx + sz * sz); entityArrow.shoot(sx, sy + dist * 0.2, sz, 1.6F, (float) (13 - target.getEntityWorld().getDifficulty().getDifficultyId() * 4)); this.entity.playSound(ModSounds.crossbow, 0.5F, 1); this.entity.getEntityWorld().spawnEntity(entityArrow); }