本文整理汇总了Java中net.minecraft.util.math.MathHelper.sqrt方法的典型用法代码示例。如果您正苦于以下问题:Java MathHelper.sqrt方法的具体用法?Java MathHelper.sqrt怎么用?Java MathHelper.sqrt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.minecraft.util.math.MathHelper
的用法示例。
在下文中一共展示了MathHelper.sqrt方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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(accelX * accelX + accelY * accelY + accelZ * accelZ);
this.accelerationX = accelX / d0 * 0.1D;
this.accelerationY = accelY / d0 * 0.1D;
this.accelerationZ = accelZ / d0 * 0.1D;
}
示例2: layerSize
import net.minecraft.util.math.MathHelper; //导入方法依赖的package包/类
/**
* Gets the rough size of a layer of the tree.
*/
float layerSize(int y)
{
if ((float)y < (float)this.heightLimit * 0.3F)
{
return -1.0F;
}
else
{
float f = (float)this.heightLimit / 2.0F;
float f1 = f - (float)y;
float f2 = MathHelper.sqrt(f * f - f1 * f1);
if (f1 == 0.0F)
{
f2 = f;
}
else if (Math.abs(f1) >= f)
{
return 0.0F;
}
return f2 * 0.5F;
}
}
示例3: setVelocity
import net.minecraft.util.math.MathHelper; //导入方法依赖的package包/类
/**
* Sets the velocity to the args. Args: x, y, z
*/
// @SideOnly(Side.CLIENT)
@Override
public void setVelocity(double p_70016_1_, double p_70016_3_, double p_70016_5_) {
this.motionX = p_70016_1_;
this.motionY = p_70016_3_;
this.motionZ = p_70016_5_;
if (this.prevRotationPitch == 0.0F && this.prevRotationYaw == 0.0F) {
float f = MathHelper.sqrt(p_70016_1_ * p_70016_1_ + p_70016_5_ * p_70016_5_);
this.prevRotationYaw = this.rotationYaw = (float) (Math.atan2(p_70016_1_, p_70016_5_) * 180.0D / Math.PI);
this.prevRotationPitch = this.rotationPitch = (float) (Math.atan2(p_70016_3_, f) * 180.0D / Math.PI);
this.prevRotationPitch = this.rotationPitch;
this.prevRotationYaw = this.rotationYaw;
this.setLocationAndAngles(this.posX, this.posY, this.posZ, this.rotationYaw, this.rotationPitch);
}
}
示例4: moveTowards
import net.minecraft.util.math.MathHelper; //导入方法依赖的package包/类
public void moveTowards(BlockPos pos)
{
double d0 = (double)pos.getX();
int i = pos.getY();
double d1 = (double)pos.getZ();
double d2 = d0 - this.posX;
double d3 = d1 - this.posZ;
float f = MathHelper.sqrt(d2 * d2 + d3 * d3);
if (f > 12.0F)
{
this.targetX = this.posX + d2 / (double)f * 12.0D;
this.targetZ = this.posZ + d3 / (double)f * 12.0D;
this.targetY = this.posY + 8.0D;
}
else
{
this.targetX = d0;
this.targetY = (double)i;
this.targetZ = d1;
}
this.despawnTimer = 0;
this.shatterOrDrop = this.rand.nextInt(5) > 0;
}
示例5: knockBack
import net.minecraft.util.math.MathHelper; //导入方法依赖的package包/类
/**
* Constructs a knockback vector from the given direction ratio and magnitude and adds it to the entity's velocity.
* If it is on the ground (i.e. {@code this.onGround}), the Y-velocity is increased as well, clamping it to {@code
* .4}.
* The entity's existing horizontal velocity is halved, and if the entity is on the ground the Y-velocity is too.
*
* @param strength Magnitude of the knockback vector, and also the Y-velocity to add if the entity is on the ground.
* @param xRatio The X part of the direction ratio of the knockback vector.
* @param zRatio The Z part of the direction ratio of the knockback vector.
*/
public void knockBack(Entity entityIn, float strength, double xRatio, double zRatio)
{
if (this.rand.nextDouble() >= this.getEntityAttribute(SharedMonsterAttributes.KNOCKBACK_RESISTANCE).getAttributeValue())
{
this.isAirBorne = true;
float f = MathHelper.sqrt(xRatio * xRatio + zRatio * zRatio);
this.motionX /= 2.0D;
this.motionZ /= 2.0D;
this.motionX -= xRatio / (double)f * (double)strength;
this.motionZ -= zRatio / (double)f * (double)strength;
if (this.onGround)
{
this.motionY /= 2.0D;
this.motionY += (double)strength;
if (this.motionY > 0.4000000059604645D)
{
this.motionY = 0.4000000059604645D;
}
}
}
}
示例6: rotateCorpse
import net.minecraft.util.math.MathHelper; //导入方法依赖的package包/类
protected void rotateCorpse(EntityDragon entityLiving, float p_77043_2_, float p_77043_3_, float partialTicks)
{
float f = (float)entityLiving.getMovementOffsets(7, partialTicks)[0];
float f1 = (float)(entityLiving.getMovementOffsets(5, partialTicks)[1] - entityLiving.getMovementOffsets(10, partialTicks)[1]);
GlStateManager.rotate(-f, 0.0F, 1.0F, 0.0F);
GlStateManager.rotate(f1 * 10.0F, 1.0F, 0.0F, 0.0F);
GlStateManager.translate(0.0F, 0.0F, 1.0F);
if (entityLiving.deathTime > 0)
{
float f2 = ((float)entityLiving.deathTime + partialTicks - 1.0F) / 20.0F * 1.6F;
f2 = MathHelper.sqrt(f2);
if (f2 > 1.0F)
{
f2 = 1.0F;
}
GlStateManager.rotate(f2 * this.getDeathMaxRotation(entityLiving), 0.0F, 0.0F, 1.0F);
}
}
示例7: renderParchmentFirstPerson
import net.minecraft.util.math.MathHelper; //导入方法依赖的package包/类
public static void renderParchmentFirstPerson(float pitch, float p_187463_2_, float p_187463_3_,
ItemStack parchment)
{
GlStateManager.pushMatrix();
GlStateManager.pushAttrib();
float f = MathHelper.sqrt(p_187463_3_);
float f1 = -0.2F * MathHelper.sin(p_187463_3_ * (float) Math.PI);
float f2 = -0.4F * MathHelper.sin(f * (float) Math.PI);
GlStateManager.translate(0.0F, -f1 / 2.0F, f2);
float f3 = Minecraft.getMinecraft().getItemRenderer().getMapAngleFromPitch(pitch);
GlStateManager.translate(0.0F, 0.04F + p_187463_2_ * -1.2F + f3 * -0.5F, -0.72F);
GlStateManager.rotate(f3 * -85.0F, 1.0F, 0.0F, 0.0F);
Minecraft.getMinecraft().getItemRenderer().renderArms();
float f4 = MathHelper.sin(f * (float) Math.PI);
GlStateManager.rotate(f4 * 20.0F, 1.0F, 0.0F, 0.0F);
GlStateManager.scale(2.0F, 2.0F, 2.0F);
renderParchmentFirstPerson(parchment);
GlStateManager.popAttrib();
GlStateManager.popMatrix();
}
示例8: rotateCorpse
import net.minecraft.util.math.MathHelper; //导入方法依赖的package包/类
protected void rotateCorpse(T entityLiving, float p_77043_2_, float p_77043_3_, float partialTicks)
{
GlStateManager.rotate(180.0F - p_77043_3_, 0.0F, 1.0F, 0.0F);
if (entityLiving.deathTime > 0)
{
float f = ((float)entityLiving.deathTime + partialTicks - 1.0F) / 20.0F * 1.6F;
f = MathHelper.sqrt(f);
if (f > 1.0F)
{
f = 1.0F;
}
GlStateManager.rotate(f * this.getDeathMaxRotation(entityLiving), 0.0F, 0.0F, 1.0F);
}
else
{
String s = TextFormatting.getTextWithoutFormattingCodes(entityLiving.getName());
if (s != null && ("Dinnerbone".equals(s) || "Grumm".equals(s)) && (!(entityLiving instanceof EntityPlayer) || ((EntityPlayer)entityLiving).isWearing(EnumPlayerModelParts.CAPE)))
{
GlStateManager.translate(0.0F, entityLiving.height + 0.1F, 0.0F);
GlStateManager.rotate(180.0F, 0.0F, 0.0F, 1.0F);
}
}
}
示例9: getAngleToServerRotation
import net.minecraft.util.math.MathHelper; //导入方法依赖的package包/类
public static float getAngleToServerRotation(IEntity entity) {
float[] needed = getRotations(entity.getEntity().boundingBox.getCenter());
float diffYaw = serverYaw - needed[0];
float diffPitch = serverPitch - needed[1];
float angle = MathHelper.sqrt(diffYaw * diffYaw + diffPitch * diffPitch);
return angle;
}
示例10: onUpdateMoveHelper
import net.minecraft.util.math.MathHelper; //导入方法依赖的package包/类
public void onUpdateMoveHelper() {
if(action == EntityMoveHelper.Action.MOVE_TO && !entity.getNavigator().noPath()) {
double d0 = posX - entity.posX;
double d1 = posY - entity.posY;
double d2 = posZ - entity.posZ;
double speed = MathHelper.sqrt(d0 * d0 + d1 * d1 + d2 * d2);
speed = speed * entity.getEntityAttribute(SharedMonsterAttributes.FLYING_SPEED).getAttributeValue();
float flyingSpeed = (float) (this.entity.getAIMoveSpeed() + (speed - this.entity.getAIMoveSpeed()) * 0.125F);
if(flyingSpeed > 1F) {
flyingSpeed = 1F;
}
entity.setAIMoveSpeed(flyingSpeed);
entity.setMoveVertical(d1 > 0.0D ? flyingSpeed : -flyingSpeed);
float f = (float)(MathHelper.atan2(d2, d0) * (180D / Math.PI)) - 90.0F;
this.entity.rotationYaw = this.limitAngle(this.entity.rotationYaw, f, 180F);
this.entity.renderYawOffset = this.entity.rotationYaw;
double d4 = (double)MathHelper.sqrt(d0 * d0 + d2 * d2);
float f2 = (float)(-(MathHelper.atan2(d1, d4) * (180D / Math.PI)));
this.entity.rotationPitch = this.limitAngle(this.entity.rotationPitch, f2, 180F);
} else {
entity.setAIMoveSpeed(0F);
entity.setMoveForward(0F);
entity.setMoveVertical(0F);
entity.motionX *= 0.75;
entity.motionY *= 0.75;
entity.motionZ *= 0.75;
}
}
示例11: setAim
import net.minecraft.util.math.MathHelper; //导入方法依赖的package包/类
public void setAim(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;
}
示例12: 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(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.world, 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.world.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.world.spawnEntityInWorld(entitypotion);
}
}
示例13: getDistanceToEntity
import net.minecraft.util.math.MathHelper; //导入方法依赖的package包/类
/**
* Returns the distance to the entity.
*/
public float getDistanceToEntity(Entity entityIn)
{
float f = (float)(this.posX - entityIn.posX);
float f1 = (float)(this.posY - entityIn.posY);
float f2 = (float)(this.posZ - entityIn.posZ);
return MathHelper.sqrt(f * f + f1 * f1 + f2 * f2);
}
示例14: onUpdateMoveHelper
import net.minecraft.util.math.MathHelper; //导入方法依赖的package包/类
public void onUpdateMoveHelper()
{
if (this.action == EntityMoveHelper.Action.MOVE_TO)
{
double d0 = this.posX - EntityVex.this.posX;
double d1 = this.posY - EntityVex.this.posY;
double d2 = this.posZ - EntityVex.this.posZ;
double d3 = d0 * d0 + d1 * d1 + d2 * d2;
d3 = (double)MathHelper.sqrt(d3);
if (d3 < EntityVex.this.getEntityBoundingBox().getAverageEdgeLength())
{
this.action = EntityMoveHelper.Action.WAIT;
EntityVex.this.motionX *= 0.5D;
EntityVex.this.motionY *= 0.5D;
EntityVex.this.motionZ *= 0.5D;
}
else
{
EntityVex.this.motionX += d0 / d3 * 0.05D * this.speed;
EntityVex.this.motionY += d1 / d3 * 0.05D * this.speed;
EntityVex.this.motionZ += d2 / d3 * 0.05D * this.speed;
if (EntityVex.this.getAttackTarget() == null)
{
EntityVex.this.rotationYaw = -((float)MathHelper.atan2(EntityVex.this.motionX, EntityVex.this.motionZ)) * (180F / (float)Math.PI);
EntityVex.this.renderYawOffset = EntityVex.this.rotationYaw;
}
else
{
double d4 = EntityVex.this.getAttackTarget().posX - EntityVex.this.posX;
double d5 = EntityVex.this.getAttackTarget().posZ - EntityVex.this.posZ;
EntityVex.this.rotationYaw = -((float)MathHelper.atan2(d4, d5)) * (180F / (float)Math.PI);
EntityVex.this.renderYawOffset = EntityVex.this.rotationYaw;
}
}
}
}
示例15: render
import net.minecraft.util.math.MathHelper; //导入方法依赖的package包/类
public void render(float partialTicks, double x1, double y1, double z1, double x2, double y2, double z2) {
Minecraft mc = FMLClientHandler.instance().getClient();
TextureManager textureManager = mc.renderEngine;
double laserLength = PneumaticCraftUtils.distBetween(x1, y1, z1, x2, y2, z2);
double laserSize = 0.4;
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glDisable(GL11.GL_CULL_FACE);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glTranslated(x1, y1, z1);
double dx = x2 - x1;
double dy = y2 - y1;
double dz = z2 - z1;
float f3 = MathHelper.sqrt(dx * dx + dz * dz);
double rotYaw = Math.atan2(dx, dz) * 180.0D / Math.PI;
double rotPitch = 90 - (float) (Math.atan2(dy, f3) * 180.0D / Math.PI);
GL11.glRotated(rotYaw, 0, 1, 0);
GL11.glRotated(rotPitch, 1, 0, 0);
GL11.glScaled(laserSize, laserSize, laserSize);
GL11.glTranslated(0, 0.6, 0);
GL11.glRotated((ticksExisted + partialTicks) * 200, 0, 1, 0);
GL11.glPushMatrix();
GL11.glScaled(1, laserLength / laserSize, 1);
/* GL11.glTranslated(0, -0.01, 0);
textureManager.bindTexture(Textures.RENDER_LASER_ANIMATION);
renderAnimation(partialTicks, laserLength / laserSize);
GL11.glTranslated(0, 0.01, 0);*/
textureManager.bindTexture(Textures.RENDER_LASER);
renderQuad(glowColor);
textureManager.bindTexture(Textures.RENDER_LASER_OVERLAY);
renderQuad(coreColor);
GL11.glPopMatrix();
GL11.glRotated(180, 1, 0, 0);
textureManager.bindTexture(Textures.RENDER_LASER_START);
renderQuad(glowColor);
textureManager.bindTexture(Textures.RENDER_LASER_START_OVERLAY);
renderQuad(coreColor);
GL11.glDisable(GL11.GL_BLEND);
GL11.glEnable(GL11.GL_CULL_FACE);
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glColor4d(1, 1, 1, 1);
}