当前位置: 首页>>代码示例>>Java>>正文


Java MathHelper.atan2方法代码示例

本文整理汇总了Java中net.minecraft.util.math.MathHelper.atan2方法的典型用法代码示例。如果您正苦于以下问题:Java MathHelper.atan2方法的具体用法?Java MathHelper.atan2怎么用?Java MathHelper.atan2使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在net.minecraft.util.math.MathHelper的用法示例。


在下文中一共展示了MathHelper.atan2方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: updateTask

import net.minecraft.util.math.MathHelper; //导入方法依赖的package包/类
/**
 * Updates the task
 */
public void updateTask()
{
    if (this.parentEntity.getAttackTarget() == null)
    {
        this.parentEntity.rotationYaw = -((float)MathHelper.atan2(this.parentEntity.motionX, this.parentEntity.motionZ)) * (180F / (float)Math.PI);
        this.parentEntity.renderYawOffset = this.parentEntity.rotationYaw;
    }
    else
    {
        EntityLivingBase entitylivingbase = this.parentEntity.getAttackTarget();
        if (entitylivingbase.getDistanceSqToEntity(this.parentEntity) < 4096.0D)
        {
            double d1 = entitylivingbase.posX - this.parentEntity.posX;
            double d2 = entitylivingbase.posZ - this.parentEntity.posZ;
            this.parentEntity.rotationYaw = -((float)MathHelper.atan2(d1, d2)) * (180F / (float)Math.PI);
            this.parentEntity.renderYawOffset = this.parentEntity.rotationYaw;
        }
    }
}
 
开发者ID:Herobone,项目名称:HeroUtils,代码行数:23,代码来源:AILookAround.java

示例2: 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;
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:26,代码来源:EntityThrowable.java

示例3: setVelocity

import net.minecraft.util.math.MathHelper; //导入方法依赖的package包/类
/**
 * Updates the velocity of the entity to a new value.
 */
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;
    }
}
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:19,代码来源:EntityEnderEye.java

示例4: 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;
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:23,代码来源:EntityFishHook.java

示例5: setVelocity

import net.minecraft.util.math.MathHelper; //导入方法依赖的package包/类
/**
 * Updates the velocity of the entity to a new value.
 */
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.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);
    }
}
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:20,代码来源:EntityLlamaSpit.java

示例6: updateTask

import net.minecraft.util.math.MathHelper; //导入方法依赖的package包/类
public void updateTask()
{
    if (this.parentEntity.getAttackTarget() == null)
    {
        this.parentEntity.rotationYaw = -((float)MathHelper.atan2(this.parentEntity.motionX, this.parentEntity.motionZ)) * (180F / (float)Math.PI);
        this.parentEntity.renderYawOffset = this.parentEntity.rotationYaw;
    }
    else
    {
        EntityLivingBase entitylivingbase = this.parentEntity.getAttackTarget();
        double d0 = 64.0D;

        if (entitylivingbase.getDistanceSqToEntity(this.parentEntity) < 4096.0D)
        {
            double d1 = entitylivingbase.posX - this.parentEntity.posX;
            double d2 = entitylivingbase.posZ - this.parentEntity.posZ;
            this.parentEntity.rotationYaw = -((float)MathHelper.atan2(d1, d2)) * (180F / (float)Math.PI);
            this.parentEntity.renderYawOffset = this.parentEntity.rotationYaw;
        }
    }
}
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:22,代码来源:EntityGhast.java

示例7: 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(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;
}
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:26,代码来源:EntityArrow.java

示例8: setVelocity

import net.minecraft.util.math.MathHelper; //导入方法依赖的package包/类
/**
 * Updates the velocity of the entity to a new value.
 */
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.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;
    }
}
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:21,代码来源:EntityArrow.java

示例9: updateTask

import net.minecraft.util.math.MathHelper; //导入方法依赖的package包/类
/**
 * Updates the task
 */
public void updateTask()
{
    if (this.parentEntity.getAttackTarget() == null)
    {
        this.parentEntity.rotationYaw = -((float)MathHelper.atan2(this.parentEntity.motionX, this.parentEntity.motionZ)) * (180F / (float)Math.PI);
        this.parentEntity.renderYawOffset = this.parentEntity.rotationYaw;
    }
    else
    {
        EntityLivingBase entitylivingbase = this.parentEntity.getAttackTarget();
        double d0 = 64.0D;

        if (entitylivingbase.getDistanceSqToEntity(this.parentEntity) < 4096.0D)
        {
            double d1 = entitylivingbase.posX - this.parentEntity.posX;
            double d2 = entitylivingbase.posZ - this.parentEntity.posZ;
            this.parentEntity.rotationYaw = -((float)MathHelper.atan2(d1, d2)) * (180F / (float)Math.PI);
            this.parentEntity.renderYawOffset = this.parentEntity.rotationYaw;
        }
    }
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:25,代码来源:EntityGhast.java

示例10: func_190623_q

import net.minecraft.util.math.MathHelper; //导入方法依赖的package包/类
private void func_190623_q()
{
    float f = MathHelper.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ);
    this.rotationYaw = (float)(MathHelper.atan2(this.motionX, this.motionZ) * (180D / Math.PI));

    for (this.rotationPitch = (float)(MathHelper.atan2(this.motionY, (double)f) * (180D / Math.PI)); 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;
}
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:29,代码来源:EntityFishHook.java

示例11: 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(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_;
}
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:32,代码来源:ProjectileHelper.java

示例12: onUpdateLook

import net.minecraft.util.math.MathHelper; //导入方法依赖的package包/类
/**
 * Updates look
 */
public void onUpdateLook()
{
    this.entity.rotationPitch = 0.0F;

    if (this.isLooking)
    {
        this.isLooking = false;
        double d0 = this.posX - this.entity.posX;
        double d1 = this.posY - (this.entity.posY + (double)this.entity.getEyeHeight());
        double d2 = this.posZ - this.entity.posZ;
        double d3 = (double)MathHelper.sqrt_double(d0 * d0 + d2 * d2);
        float f = (float)(MathHelper.atan2(d2, d0) * (180D / Math.PI)) - 90.0F;
        float f1 = (float)(-(MathHelper.atan2(d1, d3) * (180D / Math.PI)));
        this.entity.rotationPitch = this.updateRotation(this.entity.rotationPitch, f1, this.deltaLookPitch);
        this.entity.rotationYawHead = this.updateRotation(this.entity.rotationYawHead, f, this.deltaLookYaw);
    }
    else
    {
        this.entity.rotationYawHead = this.updateRotation(this.entity.rotationYawHead, this.entity.renderYawOffset, 10.0F);
    }

    float f2 = MathHelper.wrapDegrees(this.entity.rotationYawHead - this.entity.renderYawOffset);

    if (!this.entity.getNavigator().noPath())
    {
        if (f2 < -75.0F)
        {
            this.entity.rotationYawHead = this.entity.renderYawOffset - 75.0F;
        }

        if (f2 > 75.0F)
        {
            this.entity.rotationYawHead = this.entity.renderYawOffset + 75.0F;
        }
    }
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:40,代码来源:EntityLookHelper.java

示例13: onUpdateMoveHelper

import net.minecraft.util.math.MathHelper; //导入方法依赖的package包/类
public void onUpdateMoveHelper()
{
    if (this.action == EntityMoveHelper.Action.MOVE_TO && !this.entityGuardian.getNavigator().noPath())
    {
        double d0 = this.posX - this.entityGuardian.posX;
        double d1 = this.posY - this.entityGuardian.posY;
        double d2 = this.posZ - this.entityGuardian.posZ;
        double d3 = d0 * d0 + d1 * d1 + d2 * d2;
        d3 = (double)MathHelper.sqrt_double(d3);
        d1 = d1 / d3;
        float f = (float)(MathHelper.atan2(d2, d0) * (180D / Math.PI)) - 90.0F;
        this.entityGuardian.rotationYaw = this.limitAngle(this.entityGuardian.rotationYaw, f, 90.0F);
        this.entityGuardian.renderYawOffset = this.entityGuardian.rotationYaw;
        float f1 = (float)(this.speed * this.entityGuardian.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).getAttributeValue());
        this.entityGuardian.setAIMoveSpeed(this.entityGuardian.getAIMoveSpeed() + (f1 - this.entityGuardian.getAIMoveSpeed()) * 0.125F);
        double d4 = Math.sin((double)(this.entityGuardian.ticksExisted + this.entityGuardian.getEntityId()) * 0.5D) * 0.05D;
        double d5 = Math.cos((double)(this.entityGuardian.rotationYaw * 0.017453292F));
        double d6 = Math.sin((double)(this.entityGuardian.rotationYaw * 0.017453292F));
        this.entityGuardian.motionX += d4 * d5;
        this.entityGuardian.motionZ += d4 * d6;
        d4 = Math.sin((double)(this.entityGuardian.ticksExisted + this.entityGuardian.getEntityId()) * 0.75D) * 0.05D;
        this.entityGuardian.motionY += d4 * (d6 + d5) * 0.25D;
        this.entityGuardian.motionY += (double)this.entityGuardian.getAIMoveSpeed() * d1 * 0.1D;
        EntityLookHelper entitylookhelper = this.entityGuardian.getLookHelper();
        double d7 = this.entityGuardian.posX + d0 / d3 * 2.0D;
        double d8 = (double)this.entityGuardian.getEyeHeight() + this.entityGuardian.posY + d1 / d3;
        double d9 = this.entityGuardian.posZ + d2 / d3 * 2.0D;
        double d10 = entitylookhelper.getLookPosX();
        double d11 = entitylookhelper.getLookPosY();
        double d12 = entitylookhelper.getLookPosZ();

        if (!entitylookhelper.getIsLooking())
        {
            d10 = d7;
            d11 = d8;
            d12 = d9;
        }

        this.entityGuardian.getLookHelper().setLookPosition(d10 + (d7 - d10) * 0.125D, d11 + (d8 - d11) * 0.125D, d12 + (d9 - d12) * 0.125D, 10.0F, 40.0F);
        this.entityGuardian.setMoving(true);
    }
    else
    {
        this.entityGuardian.setAIMoveSpeed(0.0F);
        this.entityGuardian.setMoving(false);
    }
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:48,代码来源:EntityGuardian.java

示例14: onReceived

import net.minecraft.util.math.MathHelper; //导入方法依赖的package包/类
@Override
public void onReceived(MessagePacketRingUpdate message, EntityPlayer player) {
	if(message.ringType < 2)
	{
		ArrayList<Item> ringTypeItem = new ArrayList<Item>();
		ringTypeItem.add(HarshenItems.TELERING);
		ringTypeItem.add(HarshenItems.MINERING);
		if(HarshenUtils.containsItem(player,ringTypeItem.get(message.ringType)))
		{
			World world = player.world;
			Vec3d vec = new Vec3d(player.posX + (player.getLookVec().x * 4f),
					player.posY + (player.getLookVec().y * 4f), player.posZ + (player.getLookVec().z* 4f));
			BlockPos blockpos = message.ringType == 0? HarshenUtils.getTopBlock(world, vec) : HarshenUtils.getBottomBlockAir(world, vec);
			Vec3d vecPos = new Vec3d(blockpos).addVector(0.5, 0, 0.5);
			if(blockpos.getY() != -1 && player.getFoodStats().getFoodLevel() > 0)
			{
				((EntityPlayerMP)player).velocityChanged = true;
				((EntityPlayerMP)player).fallDistance = 0;
				HarshenNetwork.sendToPlayer(player, new MessagePacketPlayerTeleportEffects(vecPos));
				((EntityPlayerMP)player).setPositionAndUpdate(vecPos.x, vecPos.y, vecPos.z);
				world.playSound((EntityPlayer)null, player.posX, player.posY, player.posZ, SoundEvents.ITEM_CHORUS_FRUIT_TELEPORT, SoundCategory.PLAYERS, 1.0F, 1.0F);
                player.playSound(SoundEvents.ITEM_CHORUS_FRUIT_TELEPORT, 1.0F, 1.0F);
                player.addExhaustion(0.5F);
                HarshenUtils.damageFirstOccuringItem(player, ringTypeItem.get(message.ringType));
			}
		}			
	}
	else if(message.ringType == 2 && HarshenUtils.containsItem(player, HarshenItems.COMBAT_PENDANT))
	{
		EntityLivingBase entityToAttack = HarshenUtils.getFirstEntityInDirection(player.world, player.getPositionVector(), player.getLookVec().normalize(), 5, EntityLivingBase.class);
		if(entityToAttack == null)
		{
			List<EntityLivingBase> list = player.world.getEntitiesWithinAABB(EntityLivingBase.class, new AxisAlignedBB(player.posX - 4d, player.posY - 4d, player.posZ - 4d, player.posX + 4d, player.posY + 4d, player.posZ + 4d));
			if(!list.isEmpty())
				entityToAttack = list.get(0);
		}
		if(!player.equals(entityToAttack) && (entityToAttack != null || (entityToAttack instanceof EntityPlayerMP && player.canAttackPlayer((EntityPlayerMP)entityToAttack)
				&& HarshenUtils.toArray(GameType.SURVIVAL, GameType.ADVENTURE).contains(((EntityPlayerMP)entityToAttack).interactionManager.getGameType()))))
		{
			Vec3d position = entityToAttack.getPositionVector();
			Vec3d playerPosNoY = position.addVector(movePos(), 0, movePos());
			Vec3d pos = new Vec3d(playerPosNoY.x, HarshenUtils.getTopBlock(player.world, new BlockPos(playerPosNoY)).getY(), playerPosNoY.z);
			double d0 = position.x - pos.x;
            double d1 = position.y - (pos.y + (double)player.getEyeHeight() - entityToAttack.height / 2f + 0.1f);
            double d2 = position.z - pos.z;
            double d3 = (double)MathHelper.sqrt(d0 * d0 + d2 * d2);
            float yaw = (float)(MathHelper.atan2(d2, d0) * (180D / Math.PI)) - 90.0F;
            float pitch = (float)(-(MathHelper.atan2(d1, d3) * (180D / Math.PI)));
			((EntityPlayerMP)player).velocityChanged = true;
			((EntityPlayerMP)player).connection.setPlayerLocation(pos.x, pos.y, pos.z, yaw, pitch);
		}
	}
}
 
开发者ID:kenijey,项目名称:harshencastle,代码行数:54,代码来源:MessagePacketRingUpdate.java

示例15: onUpdateMoveHelper

import net.minecraft.util.math.MathHelper; //导入方法依赖的package包/类
public void onUpdateMoveHelper()
{
    if (this.action == EntityMoveHelper.Action.STRAFE)
    {
        float f = (float)this.entity.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).getAttributeValue();
        float f1 = (float)this.speed * f;
        float f2 = this.moveForward;
        float f3 = this.moveStrafe;
        float f4 = MathHelper.sqrt(f2 * f2 + f3 * f3);

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

        f4 = f1 / f4;
        f2 = f2 * f4;
        f3 = f3 * f4;
        float f5 = MathHelper.sin(this.entity.rotationYaw * 0.017453292F);
        float f6 = MathHelper.cos(this.entity.rotationYaw * 0.017453292F);
        float f7 = f2 * f6 - f3 * f5;
        float f8 = f3 * f6 + f2 * f5;
        PathNavigate pathnavigate = this.entity.getNavigator();

        if (pathnavigate != null)
        {
            NodeProcessor nodeprocessor = pathnavigate.getNodeProcessor();

            if (nodeprocessor != null && nodeprocessor.getPathNodeType(this.entity.world, MathHelper.floor(this.entity.posX + (double)f7), MathHelper.floor(this.entity.posY), MathHelper.floor(this.entity.posZ + (double)f8)) != PathNodeType.WALKABLE)
            {
                this.moveForward = 1.0F;
                this.moveStrafe = 0.0F;
                f1 = f;
            }
        }

        this.entity.setAIMoveSpeed(f1);
        this.entity.setMoveForward(this.moveForward);
        this.entity.setMoveStrafing(this.moveStrafe);
        this.action = EntityMoveHelper.Action.WAIT;
    }
    else if (this.action == EntityMoveHelper.Action.MOVE_TO)
    {
        this.action = EntityMoveHelper.Action.WAIT;
        double d0 = this.posX - this.entity.posX;
        double d1 = this.posZ - this.entity.posZ;
        double d2 = this.posY - this.entity.posY;
        double d3 = d0 * d0 + d2 * d2 + d1 * d1;

        if (d3 < 2.500000277905201E-7D)
        {
            this.entity.setMoveForward(0.0F);
            return;
        }

        float f9 = (float)(MathHelper.atan2(d1, d0) * (180D / Math.PI)) - 90.0F;
        this.entity.rotationYaw = this.limitAngle(this.entity.rotationYaw, f9, 90.0F);
        this.entity.setAIMoveSpeed((float)(this.speed * this.entity.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).getAttributeValue()));

        if (d2 > (double)this.entity.stepHeight && d0 * d0 + d1 * d1 < (double)Math.max(1.0F, this.entity.width))
        {
            this.entity.getJumpHelper().setJumping();
            this.action = EntityMoveHelper.Action.JUMPING;
        }
    }
    else if (this.action == EntityMoveHelper.Action.JUMPING)
    {
        this.entity.setAIMoveSpeed((float)(this.speed * this.entity.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).getAttributeValue()));

        if (this.entity.onGround)
        {
            this.action = EntityMoveHelper.Action.WAIT;
        }
    }
    else
    {
        this.entity.setMoveForward(0.0F);
    }
}
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:80,代码来源:EntityMoveHelper.java


注:本文中的net.minecraft.util.math.MathHelper.atan2方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。