本文整理汇总了Java中net.minecraft.util.math.MathHelper.sqrt_double方法的典型用法代码示例。如果您正苦于以下问题:Java MathHelper.sqrt_double方法的具体用法?Java MathHelper.sqrt_double怎么用?Java MathHelper.sqrt_double使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.minecraft.util.math.MathHelper
的用法示例。
在下文中一共展示了MathHelper.sqrt_double方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: update
import net.minecraft.util.math.MathHelper; //导入方法依赖的package包/类
/**
* Like the old updateEntity(), except more generic.
*/
public void update()
{
if (this.minecart.isDead)
{
this.donePlaying = true;
}
else
{
this.xPosF = (float)this.minecart.posX;
this.yPosF = (float)this.minecart.posY;
this.zPosF = (float)this.minecart.posZ;
float f = MathHelper.sqrt_double(this.minecart.motionX * this.minecart.motionX + this.minecart.motionZ * this.minecart.motionZ);
if ((double)f >= 0.01D)
{
this.distance = MathHelper.clamp_float(this.distance + 0.0025F, 0.0F, 1.0F);
this.volume = 0.0F + MathHelper.clamp_float(f, 0.0F, 0.5F) * 0.7F;
}
else
{
this.distance = 0.0F;
this.volume = 0.0F;
}
}
}
示例2: moveAlongTrack
import net.minecraft.util.math.MathHelper; //导入方法依赖的package包/类
protected void moveAlongTrack(BlockPos pos, IBlockState state)
{
super.moveAlongTrack(pos, state);
double d0 = this.pushX * this.pushX + this.pushZ * this.pushZ;
if (d0 > 1.0E-4D && this.motionX * this.motionX + this.motionZ * this.motionZ > 0.001D)
{
d0 = (double)MathHelper.sqrt_double(d0);
this.pushX /= d0;
this.pushZ /= d0;
if (this.pushX * this.motionX + this.pushZ * this.motionZ < 0.0D)
{
this.pushX = 0.0D;
this.pushZ = 0.0D;
}
else
{
double d1 = d0 / this.getMaximumSpeed();
this.pushX *= d1;
this.pushZ *= d1;
}
}
}
示例3: EntityFireball
import net.minecraft.util.math.MathHelper; //导入方法依赖的package包/类
public EntityFireball(World worldIn, EntityLivingBase shooter, double accelX, double accelY, double accelZ)
{
super(worldIn);
this.shootingEntity = shooter;
this.setSize(1.0F, 1.0F);
this.setLocationAndAngles(shooter.posX, shooter.posY, shooter.posZ, shooter.rotationYaw, shooter.rotationPitch);
this.setPosition(this.posX, this.posY, this.posZ);
this.motionX = 0.0D;
this.motionY = 0.0D;
this.motionZ = 0.0D;
accelX = accelX + this.rand.nextGaussian() * 0.4D;
accelY = accelY + this.rand.nextGaussian() * 0.4D;
accelZ = accelZ + this.rand.nextGaussian() * 0.4D;
double d0 = (double)MathHelper.sqrt_double(accelX * accelX + accelY * accelY + accelZ * accelZ);
this.accelerationX = accelX / d0 * 0.1D;
this.accelerationY = accelY / d0 * 0.1D;
this.accelerationZ = accelZ / d0 * 0.1D;
}
示例4: setVelocity
import net.minecraft.util.math.MathHelper; //导入方法依赖的package包/类
/**
* Updates the velocity of the entity to a new value.
*/
@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.rotationPitch = (float)(MathHelper.atan2(y, (double)f) * (180D / Math.PI));
this.rotationYaw = (float)(MathHelper.atan2(x, z) * (180D / Math.PI));
this.prevRotationPitch = this.rotationPitch;
this.prevRotationYaw = this.rotationYaw;
this.setLocationAndAngles(this.posX, this.posY, this.posZ, this.rotationYaw, this.rotationPitch);
this.ticksInGround = 0;
}
}
示例5: setThrowableHeading
import net.minecraft.util.math.MathHelper; //导入方法依赖的package包/类
/**
* Similar to setArrowHeading, it's point the throwable entity to a x, y, z direction.
*/
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() * 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_double(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;
}
示例6: setVelocity
import net.minecraft.util.math.MathHelper; //导入方法依赖的package包/类
/**
* Updates the velocity of the entity to a new value.
*/
@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.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;
}
}
示例7: handleHookCasting
import net.minecraft.util.math.MathHelper; //导入方法依赖的package包/类
public void handleHookCasting(double p_146035_1_, double p_146035_3_, double p_146035_5_, float p_146035_7_, float p_146035_8_)
{
float f = MathHelper.sqrt_double(p_146035_1_ * p_146035_1_ + p_146035_3_ * p_146035_3_ + p_146035_5_ * p_146035_5_);
p_146035_1_ = p_146035_1_ / (double)f;
p_146035_3_ = p_146035_3_ / (double)f;
p_146035_5_ = p_146035_5_ / (double)f;
p_146035_1_ = p_146035_1_ + this.rand.nextGaussian() * 0.007499999832361937D * (double)p_146035_8_;
p_146035_3_ = p_146035_3_ + this.rand.nextGaussian() * 0.007499999832361937D * (double)p_146035_8_;
p_146035_5_ = p_146035_5_ + this.rand.nextGaussian() * 0.007499999832361937D * (double)p_146035_8_;
p_146035_1_ = p_146035_1_ * (double)p_146035_7_;
p_146035_3_ = p_146035_3_ * (double)p_146035_7_;
p_146035_5_ = p_146035_5_ * (double)p_146035_7_;
this.motionX = p_146035_1_;
this.motionY = p_146035_3_;
this.motionZ = p_146035_5_;
float f1 = MathHelper.sqrt_double(p_146035_1_ * p_146035_1_ + p_146035_5_ * p_146035_5_);
this.rotationYaw = (float)(MathHelper.atan2(p_146035_1_, p_146035_5_) * (180D / Math.PI));
this.rotationPitch = (float)(MathHelper.atan2(p_146035_3_, (double)f1) * (180D / Math.PI));
this.prevRotationYaw = this.rotationYaw;
this.prevRotationPitch = this.rotationPitch;
this.ticksInGround = 0;
}
示例8: onUpdateMoveHelper
import net.minecraft.util.math.MathHelper; //导入方法依赖的package包/类
public void onUpdateMoveHelper()
{
if (this.action == EntityMoveHelper.Action.MOVE_TO)
{
double d0 = this.posX - this.parentEntity.posX;
double d1 = this.posY - this.parentEntity.posY;
double d2 = this.posZ - this.parentEntity.posZ;
double d3 = d0 * d0 + d1 * d1 + d2 * d2;
if (this.courseChangeCooldown-- <= 0)
{
this.courseChangeCooldown += this.parentEntity.getRNG().nextInt(5) + 2;
d3 = (double)MathHelper.sqrt_double(d3);
if (this.isNotColliding(this.posX, this.posY, this.posZ, d3))
{
this.parentEntity.motionX += d0 / d3 * 0.1D;
this.parentEntity.motionY += d1 / d3 * 0.1D;
this.parentEntity.motionZ += d2 / d3 * 0.1D;
}
else
{
this.action = EntityMoveHelper.Action.WAIT;
}
}
}
}
示例9: onImpact
import net.minecraft.util.math.MathHelper; //导入方法依赖的package包/类
@Override
protected void onImpact(RayTraceResult result) {
if (result.typeOfHit == RayTraceResult.Type.ENTITY) {
EntityLivingBase thrower = getThrower();
// prevent damaging thrower
if (result.entityHit == thrower)
return;
Entity entity = result.entityHit;
DamageSource ds = createDamageSource(null == thrower ? this : thrower);
if (isBurning() && !(entity instanceof EntityEnderman))
entity.setFire(5);
if (entity.attackEntityFrom(ds, getDamage())) {
if (entity instanceof EntityLivingBase) {
EntityLivingBase base = (EntityLivingBase) entity;
if (knockbackStrength > 0) {
float f1 = MathHelper.sqrt_double(motionX * motionX + motionZ * motionZ);
if (f1 > 0f) {
base.addVelocity(motionX * knockbackStrength * 0.6000000238418579D / f1,
0.1D, motionZ * knockbackStrength * 0.6000000238418579D / f1);
}
}
if (null != thrower) {
EnchantmentHelper.applyThornEnchantments(base, thrower);
EnchantmentHelper.applyArthropodEnchantments(thrower, base);
if (base != thrower && base instanceof EntityPlayer && thrower instanceof EntityPlayerMP)
{
((EntityPlayerMP)thrower).connection.sendPacket(new SPacketChangeGameState(6, 0.0F));
}
}
}
}
}
if (!worldObj.isRemote)
setDead();
}
示例10: startExecuting
import net.minecraft.util.math.MathHelper; //导入方法依赖的package包/类
/**
* Execute a one shot task or start executing a continuous task
*/
public void startExecuting()
{
double d0 = this.leapTarget.posX - this.leaper.posX;
double d1 = this.leapTarget.posZ - this.leaper.posZ;
float f = MathHelper.sqrt_double(d0 * d0 + d1 * d1);
this.leaper.motionX += d0 / (double)f * 0.5D * 0.800000011920929D + this.leaper.motionX * 0.20000000298023224D;
this.leaper.motionZ += d1 / (double)f * 0.5D * 0.800000011920929D + this.leaper.motionZ * 0.20000000298023224D;
this.leaper.motionY = (double)this.leapMotionY;
}
示例11: attackEntityWithRangedAttack
import net.minecraft.util.math.MathHelper; //导入方法依赖的package包/类
/**
* Attack the specified entity using a ranged attack.
*
* @param distanceFactor How far the target is, normalized and clamped between 0.1 and 1.0
*/
public void attackEntityWithRangedAttack(EntityLivingBase target, float distanceFactor)
{
EntitySnowball entitysnowball = new EntitySnowball(this.worldObj, this);
double d0 = target.posY + (double)target.getEyeHeight() - 1.100000023841858D;
double d1 = target.posX - this.posX;
double d2 = d0 - entitysnowball.posY;
double d3 = target.posZ - this.posZ;
float f = MathHelper.sqrt_double(d1 * d1 + d3 * d3) * 0.2F;
entitysnowball.setThrowableHeading(d1, d2 + (double)f, d3, 1.6F, 12.0F);
this.playSound(SoundEvents.ENTITY_SNOWMAN_SHOOT, 1.0F, 1.0F / (this.getRNG().nextFloat() * 0.4F + 0.8F));
this.worldObj.spawnEntityInWorld(entitysnowball);
}
示例12: rotateTowardsMovement
import net.minecraft.util.math.MathHelper; //导入方法依赖的package包/类
public static final void rotateTowardsMovement(Entity p_188803_0_, float p_188803_1_)
{
double d0 = p_188803_0_.motionX;
double d1 = p_188803_0_.motionY;
double d2 = p_188803_0_.motionZ;
float f = MathHelper.sqrt_double(d0 * d0 + d2 * d2);
p_188803_0_.rotationYaw = (float)(MathHelper.atan2(d2, d0) * (180D / Math.PI)) + 90.0F;
for (p_188803_0_.rotationPitch = (float)(MathHelper.atan2((double)f, d1) * (180D / Math.PI)) - 90.0F; p_188803_0_.rotationPitch - p_188803_0_.prevRotationPitch < -180.0F; p_188803_0_.prevRotationPitch -= 360.0F)
{
;
}
while (p_188803_0_.rotationPitch - p_188803_0_.prevRotationPitch >= 180.0F)
{
p_188803_0_.prevRotationPitch += 360.0F;
}
while (p_188803_0_.rotationYaw - p_188803_0_.prevRotationYaw < -180.0F)
{
p_188803_0_.prevRotationYaw -= 360.0F;
}
while (p_188803_0_.rotationYaw - p_188803_0_.prevRotationYaw >= 180.0F)
{
p_188803_0_.prevRotationYaw += 360.0F;
}
p_188803_0_.rotationPitch = p_188803_0_.prevRotationPitch + (p_188803_0_.rotationPitch - p_188803_0_.prevRotationPitch) * p_188803_1_;
p_188803_0_.rotationYaw = p_188803_0_.prevRotationYaw + (p_188803_0_.rotationYaw - p_188803_0_.prevRotationYaw) * p_188803_1_;
}
示例13: Particle
import net.minecraft.util.math.MathHelper; //导入方法依赖的package包/类
public Particle(World worldIn, double xCoordIn, double yCoordIn, double zCoordIn, double xSpeedIn, double ySpeedIn, double zSpeedIn)
{
this(worldIn, xCoordIn, yCoordIn, zCoordIn);
this.motionX = xSpeedIn + (Math.random() * 2.0D - 1.0D) * 0.4000000059604645D;
this.motionY = ySpeedIn + (Math.random() * 2.0D - 1.0D) * 0.4000000059604645D;
this.motionZ = zSpeedIn + (Math.random() * 2.0D - 1.0D) * 0.4000000059604645D;
float f = (float)(Math.random() + Math.random() + 1.0D) * 0.15F;
float f1 = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionY * this.motionY + this.motionZ * this.motionZ);
this.motionX = this.motionX / (double)f1 * (double)f * 0.4000000059604645D;
this.motionY = this.motionY / (double)f1 * (double)f * 0.4000000059604645D + 0.10000000149011612D;
this.motionZ = this.motionZ / (double)f1 * (double)f * 0.4000000059604645D;
}
示例14: attackEntityWithRangedAttack
import net.minecraft.util.math.MathHelper; //导入方法依赖的package包/类
/**
* Attack the specified entity using a ranged attack.
*
* @param distanceFactor How far the target is, normalized and clamped between 0.1 and 1.0
*/
public void attackEntityWithRangedAttack(EntityLivingBase target, float distanceFactor)
{
if (!this.isDrinkingPotion())
{
double d0 = target.posY + (double)target.getEyeHeight() - 1.100000023841858D;
double d1 = target.posX + target.motionX - this.posX;
double d2 = d0 - this.posY;
double d3 = target.posZ + target.motionZ - this.posZ;
float f = MathHelper.sqrt_double(d1 * d1 + d3 * d3);
PotionType potiontype = PotionTypes.HARMING;
if (f >= 8.0F && !target.isPotionActive(MobEffects.SLOWNESS))
{
potiontype = PotionTypes.SLOWNESS;
}
else if (target.getHealth() >= 8.0F && !target.isPotionActive(MobEffects.POISON))
{
potiontype = PotionTypes.POISON;
}
else if (f <= 3.0F && !target.isPotionActive(MobEffects.WEAKNESS) && this.rand.nextFloat() < 0.25F)
{
potiontype = PotionTypes.WEAKNESS;
}
EntityPotion entitypotion = new EntityPotion(this.worldObj, this, PotionUtils.addPotionToItemStack(new ItemStack(Items.SPLASH_POTION), potiontype));
entitypotion.rotationPitch -= -20.0F;
entitypotion.setThrowableHeading(d1, d2 + (double)(f * 0.2F), d3, 0.75F, 8.0F);
this.worldObj.playSound((EntityPlayer)null, this.posX, this.posY, this.posZ, SoundEvents.ENTITY_WITCH_THROW, this.getSoundCategory(), 1.0F, 0.8F + this.rand.nextFloat() * 0.4F);
this.worldObj.spawnEntityInWorld(entitypotion);
}
}
示例15: doLocalUpdate
import net.minecraft.util.math.MathHelper; //导入方法依赖的package包/类
/**
* Gives the phase a chance to update its status.
* Called by dragon's onLivingUpdate. Only used when !worldObj.isRemote.
*/
public void doLocalUpdate()
{
++this.scanningTime;
EntityLivingBase entitylivingbase = this.dragon.worldObj.getNearestAttackablePlayer(this.dragon, 20.0D, 10.0D);
if (entitylivingbase != null)
{
if (this.scanningTime > 25)
{
this.dragon.getPhaseManager().setPhase(PhaseList.SITTING_ATTACKING);
}
else
{
Vec3d vec3d = (new Vec3d(entitylivingbase.posX - this.dragon.posX, 0.0D, entitylivingbase.posZ - this.dragon.posZ)).normalize();
Vec3d vec3d1 = (new Vec3d((double)MathHelper.sin(this.dragon.rotationYaw * 0.017453292F), 0.0D, (double)(-MathHelper.cos(this.dragon.rotationYaw * 0.017453292F)))).normalize();
float f = (float)vec3d1.dotProduct(vec3d);
float f1 = (float)(Math.acos((double)f) * (180D / Math.PI)) + 0.5F;
if (f1 < 0.0F || f1 > 10.0F)
{
double d0 = entitylivingbase.posX - this.dragon.dragonPartHead.posX;
double d1 = entitylivingbase.posZ - this.dragon.dragonPartHead.posZ;
double d2 = MathHelper.clamp_double(MathHelper.wrapDegrees(180.0D - MathHelper.atan2(d0, d1) * (180D / Math.PI) - (double)this.dragon.rotationYaw), -100.0D, 100.0D);
this.dragon.randomYawVelocity *= 0.8F;
float f2 = MathHelper.sqrt_double(d0 * d0 + d1 * d1) + 1.0F;
float f3 = f2;
if (f2 > 40.0F)
{
f2 = 40.0F;
}
this.dragon.randomYawVelocity = (float)((double)this.dragon.randomYawVelocity + d2 * (double)(0.7F / f2 / f3));
this.dragon.rotationYaw += this.dragon.randomYawVelocity;
}
}
}
else if (this.scanningTime >= 100)
{
entitylivingbase = this.dragon.worldObj.getNearestAttackablePlayer(this.dragon, 150.0D, 150.0D);
this.dragon.getPhaseManager().setPhase(PhaseList.TAKEOFF);
if (entitylivingbase != null)
{
this.dragon.getPhaseManager().setPhase(PhaseList.CHARGING_PLAYER);
((PhaseChargingPlayer)this.dragon.getPhaseManager().getPhase(PhaseList.CHARGING_PLAYER)).setTarget(new Vec3d(entitylivingbase.posX, entitylivingbase.posY, entitylivingbase.posZ));
}
}
}