net.minecraft.util.math.MathHelper#sqrt ( )源码实例Demo

下面列出了net.minecraft.util.math.MathHelper#sqrt ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: EnderZoo   文件: EntityWitherWitch.java
@Override
public void attackEntityWithRangedAttack(EntityLivingBase entity, float rangeRatio) {   
  //the EntityPotion class validates if this potion is throwable, and if not it logs error "ThrownPotion entity {} has no item?!
  if(attackTimer <= 0 && getHeldItem(EnumHand.MAIN_HAND).getItem() == Items.SPLASH_POTION && !isHealing) {

    attackedWithPotion = entity;

    double x = entity.posX + entity.motionX - posX;
    double y = entity.posY + entity.getEyeHeight() - 1.100000023841858D - posY;
    double z = entity.posZ + entity.motionZ - posZ;
    float groundDistance = MathHelper.sqrt(x * x + z * z);

    ItemStack potion = getHeldItem(EnumHand.MAIN_HAND);
    attackTimer = getHeldItem(EnumHand.MAIN_HAND).getMaxItemUseDuration();

    EntityPotion entitypotion = new EntityPotion(world, this, potion);
    entitypotion.rotationPitch -= -20.0F;
    entitypotion.setThrowableHeading(x, y + groundDistance * 0.2F, z, 0.75F, 8.0F);
    world.spawnEntity(entitypotion);

    setItemStackToSlot(EntityEquipmentSlot.MAINHAND, ItemStack.EMPTY);
  }
}
 
源代码2 项目: TofuCraftReload   文件: EntityTofuFish.java
public void onUpdateMoveHelper() {
    if (this.fish.isInWater()) {
        this.fish.motionY += 0.005D;
    }

    if (this.action == EntityMoveHelper.Action.MOVE_TO && !this.fish.getNavigator().noPath()) {
        double d0 = this.posX - this.fish.posX;
        double d1 = this.posY - this.fish.posY;
        double d2 = this.posZ - this.fish.posZ;
        double d3 = (double) MathHelper.sqrt(d0 * d0 + d1 * d1 + d2 * d2);
        d1 = d1 / d3;
        float f = (float)(MathHelper.atan2(d2, d0) * (double)(180F / (float)Math.PI)) - 90.0F;
        this.fish.rotationYaw = this.limitAngle(this.fish.rotationYaw, f, 90.0F);
        this.fish.renderYawOffset = this.fish.rotationYaw;
        float f1 = (float)(this.speed * this.fish.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).getBaseValue());
        this.fish.setAIMoveSpeed(this.fish.getAIMoveSpeed() + (f1 - this.fish.getAIMoveSpeed()) * 0.125F);
        this.fish.motionY += (double)this.fish.getAIMoveSpeed() * d1 * 0.1D;
    } else {
        this.fish.setAIMoveSpeed(0.0F);
    }
}
 
源代码3 项目: Sakura_mod   文件: WorldGenBigMaple.java
/**
   * Gets the rough size of a layer of the tree.
   */
  float layerSize(int y)
  {
      if (y < this.heightLimit * 0.3F)
      {
          return -1.0F;
      }
float f = this.heightLimit / 2.0F;
float f1 = f - 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;
  }
 
源代码4 项目: ToroQuest   文件: EntityGuard.java
public void onUpdate_OFF() {
	super.onUpdate();

	// this.renderOffsetY = 0.0F;
	super.onUpdate();
	this.prevLimbSwingAmount = this.limbSwingAmount;
	double d0 = this.posX - this.prevPosX;
	double d1 = this.posZ - this.prevPosZ;
	float f = MathHelper.sqrt(d0 * d0 + d1 * d1) * 4.0F;

	if (f > 1.0F) {
		f = 1.0F;
	}

	this.limbSwingAmount += (f - this.limbSwingAmount) * 0.4F;
	this.limbSwing += this.limbSwingAmount;
}
 
源代码5 项目: ToroQuest   文件: EntityMage.java
protected void attackWithPotion(EntityLivingBase target) {
	double targetY = target.posY + (double) target.getEyeHeight() - 1.100000023841858D;
	double targetX = target.posX + target.motionX - this.posX;
	double d2 = targetY - this.posY;
	double targetZ = target.posZ + target.motionZ - this.posZ;

	float f = MathHelper.sqrt(targetX * targetX + targetZ * targetZ);
	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.shoot(targetX, d2 + (double) (f * 0.2F), targetZ, 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.spawnEntity(entitypotion);
}
 
源代码6 项目: fabric-carpet   文件: DistanceCalculator.java
public static List<BaseText> findDistanceBetweenTwoPoints(Vec3d pos1, Vec3d pos2)
{
    double dx = MathHelper.abs((float)pos1.x-(float)pos2.x);
    double dy = MathHelper.abs((float)pos1.y-(float)pos2.y);
    double dz = MathHelper.abs((float)pos1.z-(float)pos2.z);
    double manhattan = dx+dy+dz;
    double spherical = MathHelper.sqrt(dx*dx + dy*dy + dz*dz);
    double cylindrical = MathHelper.sqrt(dx*dx + dz*dz);
    List<BaseText> res = new ArrayList<>();
    res.add(Messenger.c("w Distance between ",
            Messenger.tp("c",pos1),"w  and ",
            Messenger.tp("c",pos2),"w :"));
    res.add(Messenger.c("w  - Spherical: ", String.format("wb %.2f", spherical)));
    res.add(Messenger.c("w  - Cylindrical: ", String.format("wb %.2f", cylindrical)));
    res.add(Messenger.c("w  - Manhattan: ", String.format("wb %.1f", manhattan)));
    return res;
}
 
源代码7 项目: Wizardry   文件: CapeHandler.java
private void resolve(Point point) {
	float dx = point.posX - dest.posX;
	float dy = point.posY - dest.posY;
	float dz = point.posZ - dest.posZ;
	float dist = MathHelper.sqrt(dx * dx + dy * dy + dz * dz);
	float d = dist * (point.invMass + dest.invMass);
	float diff = d < EPSILON ? length / 2 : (dist - length) / d;
	float px = dx * diff * strength;
	float py = dy * diff * strength;
	float pz = dz * diff * strength;
	point.posX -= px * point.invMass;
	point.posY -= py * point.invMass;
	point.posZ -= pz * point.invMass;
	dest.posX += px * dest.invMass;
	dest.posY += py * dest.invMass;
	dest.posZ += pz * dest.invMass;
}
 
源代码8 项目: ToroQuest   文件: EntityMonolithEye.java
protected void attackWithArrow(EntityLivingBase target) {

		int charge = 2 + rand.nextInt(10);

		EntityArrow entityarrow = new EntityTippedArrow(this.world, this);
		double d0 = target.posX - this.posX;
		double d1 = target.getEntityBoundingBox().minY + (double) (target.height / 3.0F) - entityarrow.posY;
		double d2 = target.posZ - this.posZ;
		double d3 = (double) MathHelper.sqrt(d0 * d0 + d2 * d2);
		entityarrow.shoot(d0, d1 + d3 * 0.20000000298023224D, d2, 1.6F,
				(float) (14 - this.world.getDifficulty().getDifficultyId() * 4));
		int i = EnchantmentHelper.getMaxEnchantmentLevel(Enchantments.POWER, this);
		int j = EnchantmentHelper.getMaxEnchantmentLevel(Enchantments.PUNCH, this);
		entityarrow.setDamage((double) (charge * 2.0F) + this.rand.nextGaussian() * 0.25D
				+ (double) ((float) this.world.getDifficulty().getDifficultyId() * 0.11F));

		if (i > 0) {
			entityarrow.setDamage(entityarrow.getDamage() + (double) i * 0.5D + 0.5D);
		}

		if (j > 0) {
			entityarrow.setKnockbackStrength(j);
		}

		if (rand.nextBoolean()) {
			entityarrow.setFire(100);
		}

		this.playSound(SoundEvents.ENTITY_SKELETON_SHOOT, 1.0F, 1.0F / (this.getRNG().nextFloat() * 0.4F + 0.8F));
		this.world.spawnEntity(entityarrow);
	}
 
源代码9 项目: seppuku   文件: MathUtil.java
public static float[] calcAngle(Vec3d from, Vec3d to) {
    final double difX = to.x - from.x;
    final double difY = (to.y - from.y) * -1.0F;
    final double difZ = to.z - from.z;

    final double dist = MathHelper.sqrt(difX * difX + difZ * difZ);

    return new float[]{(float) MathHelper.wrapDegrees(Math.toDegrees(Math.atan2(difZ, difX)) - 90.0f), (float) MathHelper.wrapDegrees(Math.toDegrees(Math.atan2(difY, dist)))};
}
 
源代码10 项目: seppuku   文件: DraggableHudComponent.java
private AnchorPoint findClosest(int x, int y) {
    AnchorPoint ret = null;
    double max = ANCHOR_THRESHOLD;
    for (AnchorPoint point : Seppuku.INSTANCE.getHudManager().getAnchorPoints()) {
        final double deltaX = x - point.getX();
        final double deltaY = y - point.getY();

        final double dist = MathHelper.sqrt(deltaX * deltaX + deltaY * deltaY);
        if (dist <= max) {
            max = dist;
            ret = point;
        }
    }
    return ret;
}
 
源代码11 项目: ToroQuest   文件: EntityMage.java
protected void attackWithArrow(EntityLivingBase target) {

		int charge = 2 + rand.nextInt(10);

		EntityArrow entityarrow = new EntityTippedArrow(this.world, this);
		double d0 = target.posX - this.posX;
		double d1 = target.getEntityBoundingBox().minY + (double) (target.height / 3.0F) - entityarrow.posY;
		double d2 = target.posZ - this.posZ;
		double d3 = (double) MathHelper.sqrt(d0 * d0 + d2 * d2);
		entityarrow.shoot(d0, d1 + d3 * 0.20000000298023224D, d2, 1.6F,
				(float) (14 - this.world.getDifficulty().getDifficultyId() * 4));
		int i = EnchantmentHelper.getMaxEnchantmentLevel(Enchantments.POWER, this);
		int j = EnchantmentHelper.getMaxEnchantmentLevel(Enchantments.PUNCH, this);
		entityarrow.setDamage((double) (charge * 2.0F) + this.rand.nextGaussian() * 0.25D
				+ (double) ((float) this.world.getDifficulty().getDifficultyId() * 0.11F));

		if (i > 0) {
			entityarrow.setDamage(entityarrow.getDamage() + (double) i * 0.5D + 0.5D);
		}

		if (j > 0) {
			entityarrow.setKnockbackStrength(j);
		}

		if (rand.nextBoolean()) {
			entityarrow.setFire(100);
		}

		this.playSound(SoundEvents.ENTITY_SKELETON_SHOOT, 1.0F, 1.0F / (this.getRNG().nextFloat() * 0.4F + 0.8F));
		this.world.spawnEntity(entityarrow);
	}
 
源代码12 项目: GregTech   文件: MetaTileEntityItemCollector.java
protected void moveItemsInEffectRange() {
    List<EntityItem> itemsInRange = getWorld().getEntitiesWithinAABB(EntityItem.class, areaBoundingBox);
    for (EntityItem entityItem : itemsInRange) {
        double distanceX = (areaCenterPos.getX() + 0.5) - entityItem.posX;
        double distanceZ = (areaCenterPos.getZ() + 0.5) - entityItem.posZ;
        double distance = MathHelper.sqrt(distanceX * distanceX + distanceZ * distanceZ);
        if(!itemFilter.testItemStack(entityItem.getItem())) {
            continue;
        }
        if (distance >= 0.7) {
            if(!entityItem.cannotPickup()) {
                double directionX = distanceX / distance;
                double directionZ = distanceZ / distance;
                entityItem.motionX = directionX * MOTION_MULTIPLIER * getTier();
                entityItem.motionZ = directionZ * MOTION_MULTIPLIER * getTier();
                entityItem.velocityChanged = true;
                entityItem.setPickupDelay(1);
            }
        } else {
            ItemStack itemStack = entityItem.getItem();
            ItemStack remainder = ItemHandlerHelper.insertItemStacked(exportItems, itemStack, false);
            if (remainder.isEmpty()) {
                entityItem.setDead();
            } else if (itemStack.getCount() > remainder.getCount()) {
                entityItem.setItem(remainder);
            }
        }
    }
    if (getTimer() % 5 == 0) {
        pushItemsIntoNearbyHandlers(getFrontFacing());
    }
}
 
源代码13 项目: Kettle   文件: CraftFireball.java
public void setDirection(Vector direction) {
    Validate.notNull(direction, "Direction can not be null");
    double x = direction.getX();
    double y = direction.getY();
    double z = direction.getZ();
    double magnitude = (double) MathHelper.sqrt(x * x + y * y + z * z);
    getHandle().accelerationX = x / magnitude;
    getHandle().accelerationY = y / magnitude;
    getHandle().accelerationZ = z / magnitude;
}
 
源代码14 项目: enderutilities   文件: EntityEnderArrow.java
public EntityEnderArrow(World worldIn, EntityLivingBase shooter, EntityLivingBase par3EntityLivingBase, float par4, float par5)
{
    super(worldIn);
    this.shootingEntity = shooter;
    this.shooterUUID = shooter.getUniqueID();

    if (shooter instanceof EntityPlayer)
    {
        this.canBePickedUp = 1;

        if (((EntityPlayer)shooter).capabilities.isCreativeMode)
        {
            this.canBePickedUp = 2;
        }
    }

    this.posY = shooter.posY + (double)shooter.getEyeHeight() - 0.10000000149011612D;
    double d0 = par3EntityLivingBase.posX - shooter.posX;
    double d1 = par3EntityLivingBase.getEntityBoundingBox().minY + (double)(par3EntityLivingBase.height / 3.0F) - this.posY;
    double d2 = par3EntityLivingBase.posZ - shooter.posZ;
    double d3 = (double)MathHelper.sqrt(d0 * d0 + d2 * d2);

    if (d3 >= 1.0E-7D)
    {
        float f2 = (float)(Math.atan2(d2, d0) * 180.0D / Math.PI) - 90.0F;
        float f3 = (float)(-(Math.atan2(d1, d3) * 180.0D / Math.PI));
        double d4 = d0 / d3;
        double d5 = d2 / d3;
        this.setLocationAndAngles(shooter.posX + d4, this.posY, shooter.posZ + d5, f2, f3);
        float f4 = (float)d3 * 0.2F;
        this.shoot(d0, d1 + (double)f4, d2, par4, par5);
    }
}
 
源代码15 项目: Wizardry   文件: FairyMoveHelper.java
@Override
public void onUpdateMoveHelper() {
	if (this.action == EntityMoveHelper.Action.MOVE_TO) {
		double x = this.posX - this.entity.posX;
		double y = this.posY - this.entity.posY;
		double z = this.posZ - this.entity.posZ;
		double distance = x * x + y * y + z * z;
		distance = (double) MathHelper.sqrt(distance);

		if (distance < this.entity.getEntityBoundingBox().getAverageEdgeLength()) {
			this.action = EntityMoveHelper.Action.WAIT;
			//	this.entity.motionX *= 0.9D;
			//	this.entity.motionY *= 0.9D;
			//	this.entity.motionZ *= 0.9D;
		} else {
			this.entity.motionX += x / distance * 0.05D * this.speed;
			this.entity.motionY += y / distance * 0.05D * this.speed;
			this.entity.motionZ += z / distance * 0.05D * this.speed;

			if (this.entity.getAttackTarget() == null) {
				this.entity.rotationYaw = -((float) MathHelper.atan2(this.entity.motionX, this.entity.motionZ)) * (180F / (float) Math.PI);
				this.entity.renderYawOffset = this.entity.rotationYaw;
			} else {
				double d4 = this.entity.getAttackTarget().posX - this.entity.posX;
				double d5 = this.entity.getAttackTarget().posZ - this.entity.posZ;
				this.entity.rotationYaw = -((float) MathHelper.atan2(d4, d5)) * (180F / (float) Math.PI);
				this.entity.renderYawOffset = this.entity.rotationYaw;
			}
		}
	}
}
 
/**
 * Moves the ridden entity based on player input
 * @param player
 */
public void moveEntity(EntityLiving entity, EntityPlayer player)
{
    entity.prevRotationYaw = entity.rotationYaw = player.rotationYaw % 360.0F;
    entity.rotationPitch = (player.rotationPitch * 0.5F) % 360.0F;
    entity.rotationYawHead = entity.renderYawOffset = entity.rotationYaw;
    float strafe = player.moveStrafing * 0.5F;
    float forward = player.moveForward;

    if (forward <= 0.0F)
    {
        forward *= 0.25F;
    }

    entity.stepHeight = 1.0F;
    entity.jumpMovementFactor = entity.getAIMoveSpeed() * 0.1F;

    if (entity.getEntityWorld().isRemote == false)
    {
        //float speed = (float)entity.getEntityAttribute(SharedMonsterAttributes.movementSpeed).getAttributeValue();
        float speed = this.maxSpeed;
        entity.setAIMoveSpeed(speed);
        entity.travel(strafe, player.moveVertical, forward);
    }

    entity.prevLimbSwingAmount = entity.limbSwingAmount;
    double d1 = entity.posX - entity.prevPosX;
    double d0 = entity.posZ - entity.prevPosZ;
    float f4 = MathHelper.sqrt(d1 * d1 + d0 * d0) * 4.0F;

    if (f4 > 1.0F)
    {
        f4 = 1.0F;
    }

    entity.limbSwingAmount += (f4 - entity.limbSwingAmount) * 0.4F;
    entity.limbSwing += entity.limbSwingAmount;
}
 
源代码17 项目: seppuku   文件: MathUtil.java
public static double getDistance(Vec3d pos, double x, double y, double z) {
    final double deltaX = pos.x - x;
    final double deltaY = pos.y - y;
    final double deltaZ = pos.z - z;
    return (double) MathHelper.sqrt(deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ);
}
 
源代码18 项目: seppuku   文件: ObsidianReplaceModule.java
private double calculateVecDistance(final Vec3d vec, final BlockPos blockPosition) {
    final double diffX = blockPosition.getX() - vec.x;
    final double diffY = blockPosition.getY() - vec.y;
    final double diffZ = blockPosition.getZ() - vec.z;
    return MathHelper.sqrt(diffX * diffX + diffY * diffY + diffZ * diffZ);
}
 
源代码19 项目: GregTech   文件: DynamiteEntity.java
@Override
public void onUpdate() {
    this.lastTickPosX = this.posX;
    this.lastTickPosY = this.posY;
    this.lastTickPosZ = this.posZ;
    this.onEntityUpdate();

    ticksUntilExplosion--;

    if (world.rand.nextInt(3) == 2) {
        world.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, this.posX, this.posY, this.posZ, -this.motionX * 0.05f, this.inGround ? 0.05f : -this.motionY * 0.05f, -this.motionZ * 0.05f);
    }

    if (ticksUntilExplosion < 0 && !world.isRemote) {
        EntityLivingBase thrower = getThrower();
        world.createExplosion(thrower == null ? this : thrower, this.posX, this.posY, this.posZ, 1.5f, true);
        this.setDead();
        return;
    }

    if (this.inGround) {
        if (blockPosCollidedAt == null || this.world.getBlockState(blockPosCollidedAt).getBlock() != Blocks.AIR) {
            return;
        }

        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);
    }

    Vec3d vec3d = new Vec3d(this.posX, this.posY, this.posZ);
    Vec3d vec3d1 = new Vec3d(this.posX + this.motionX + (this.motionX > 0 ? 0.5f : -0.5f), this.posY + this.motionY + (this.motionY > 0 ? 0.2f : -0.2f), this.posZ + this.motionZ + (this.motionZ > 0 ? 0.2f : -0.2f));
    RayTraceResult raytraceresult = this.world.rayTraceBlocks(vec3d, vec3d1);

    if (raytraceresult != null) {
        if (raytraceresult.typeOfHit == RayTraceResult.Type.BLOCK && this.world.getBlockState(raytraceresult.getBlockPos()).getBlock() == Blocks.PORTAL) {
            this.setPortal(raytraceresult.getBlockPos());
        } else if (!net.minecraftforge.event.ForgeEventFactory.onProjectileImpact(this, raytraceresult)) {
            this.onImpact(raytraceresult);
        }
    }

    this.posX += this.motionX;
    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));
    this.rotationPitch = (float) (MathHelper.atan2(this.motionY, (double) f) * (180D / Math.PI));

    while (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;
    float f1 = 0.99F;
    float f2 = this.getGravityVelocity();

    if (this.isInWater()) {
        for (int j = 0; j < 4; ++j) {
            this.world.spawnParticle(EnumParticleTypes.WATER_BUBBLE, this.posX - this.motionX * 0.25D, this.posY - this.motionY * 0.25D, this.posZ - this.motionZ * 0.25D, this.motionX, this.motionY, this.motionZ);
        }

        f1 = 0.8F;
    }

    this.motionX *= (double) f1;
    this.motionY *= (double) f1;
    this.motionZ *= (double) f1;

    if (!this.hasNoGravity()) {
        this.motionY -= (double) f2;
    }

    this.setPosition(this.posX, this.posY, this.posZ);
}
 
源代码20 项目: AdvancedRocketry   文件: TileRocketBuilder.java
public float getNeededFuel() { return getAcceleration() > 0 ? stats.getFuelRate(FuelType.LIQUID)*MathHelper.sqrt((2*(Configuration.orbit-this.getPos().getY()))/getAcceleration()) : 0; }