本文整理汇总了Java中net.minecraft.util.math.MathHelper.clamp_double方法的典型用法代码示例。如果您正苦于以下问题:Java MathHelper.clamp_double方法的具体用法?Java MathHelper.clamp_double怎么用?Java MathHelper.clamp_double使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.minecraft.util.math.MathHelper
的用法示例。
在下文中一共展示了MathHelper.clamp_double方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: moveMinecartOnRail
import net.minecraft.util.math.MathHelper; //导入方法依赖的package包/类
/**
* Moved to allow overrides.
* This code handles minecart movement and speed capping when on a rail.
*/
public void moveMinecartOnRail(BlockPos pos)
{
double mX = this.motionX;
double mZ = this.motionZ;
if (this.isBeingRidden())
{
mX *= 0.75D;
mZ *= 0.75D;
}
double max = this.getMaxSpeed();
mX = MathHelper.clamp_double(mX, -max, max);
mZ = MathHelper.clamp_double(mZ, -max, max);
this.moveEntity(mX, 0.0D, mZ);
}
示例2: SPacketSpawnObject
import net.minecraft.util.math.MathHelper; //导入方法依赖的package包/类
public SPacketSpawnObject(Entity entityIn, int typeIn, int dataIn)
{
this.entityId = entityIn.getEntityId();
this.uniqueId = entityIn.getUniqueID();
this.x = entityIn.posX;
this.y = entityIn.posY;
this.z = entityIn.posZ;
this.pitch = MathHelper.floor_float(entityIn.rotationPitch * 256.0F / 360.0F);
this.yaw = MathHelper.floor_float(entityIn.rotationYaw * 256.0F / 360.0F);
this.type = typeIn;
this.data = dataIn;
double d0 = 3.9D;
this.speedX = (int)(MathHelper.clamp_double(entityIn.motionX, -3.9D, 3.9D) * 8000.0D);
this.speedY = (int)(MathHelper.clamp_double(entityIn.motionY, -3.9D, 3.9D) * 8000.0D);
this.speedZ = (int)(MathHelper.clamp_double(entityIn.motionZ, -3.9D, 3.9D) * 8000.0D);
}
示例3: pickRandomFlower
import net.minecraft.util.math.MathHelper; //导入方法依赖的package包/类
public BlockFlower.EnumFlowerType pickRandomFlower(Random rand, BlockPos pos)
{
if (this.type == BiomeForest.Type.FLOWER)
{
double d0 = MathHelper.clamp_double((1.0D + GRASS_COLOR_NOISE.getValue((double)pos.getX() / 48.0D, (double)pos.getZ() / 48.0D)) / 2.0D, 0.0D, 0.9999D);
BlockFlower.EnumFlowerType blockflower$enumflowertype = BlockFlower.EnumFlowerType.values()[(int)(d0 * (double)BlockFlower.EnumFlowerType.values().length)];
return blockflower$enumflowertype == BlockFlower.EnumFlowerType.BLUE_ORCHID ? BlockFlower.EnumFlowerType.POPPY : blockflower$enumflowertype;
}
else
{
return super.pickRandomFlower(rand, pos);
}
}
示例4: moveDerailedMinecart
import net.minecraft.util.math.MathHelper; //导入方法依赖的package包/类
/**
* Moves a minecart that is not attached to a rail
*/
protected void moveDerailedMinecart()
{
double d0 = onGround ? this.getMaximumSpeed() : getMaxSpeedAirLateral();
this.motionX = MathHelper.clamp_double(this.motionX, -d0, d0);
this.motionZ = MathHelper.clamp_double(this.motionZ, -d0, d0);
double moveY = motionY;
if(getMaxSpeedAirVertical() > 0 && motionY > getMaxSpeedAirVertical())
{
moveY = getMaxSpeedAirVertical();
if(Math.abs(motionX) < 0.3f && Math.abs(motionZ) < 0.3f)
{
moveY = 0.15f;
motionY = moveY;
}
}
if (this.onGround)
{
this.motionX *= 0.5D;
this.motionY *= 0.5D;
this.motionZ *= 0.5D;
}
this.moveEntity(this.motionX, moveY, this.motionZ);
if (!this.onGround)
{
this.motionX *= getDragAir();
this.motionY *= getDragAir();
this.motionZ *= getDragAir();
}
}
示例5: setPositionAndRotation
import net.minecraft.util.math.MathHelper; //导入方法依赖的package包/类
/**
* Sets the entity's position and rotation.
*/
public void setPositionAndRotation(double x, double y, double z, float yaw, float pitch)
{
this.posX = MathHelper.clamp_double(x, -3.0E7D, 3.0E7D);
this.posY = y;
this.posZ = MathHelper.clamp_double(z, -3.0E7D, 3.0E7D);
this.prevPosX = this.posX;
this.prevPosY = this.posY;
this.prevPosZ = this.posZ;
pitch = MathHelper.clamp_float(pitch, -90.0F, 90.0F);
this.rotationYaw = yaw;
this.rotationPitch = pitch;
this.prevRotationYaw = this.rotationYaw;
this.prevRotationPitch = this.rotationPitch;
double d0 = (double)(this.prevRotationYaw - yaw);
if (d0 < -180.0D)
{
this.prevRotationYaw += 360.0F;
}
if (d0 >= 180.0D)
{
this.prevRotationYaw -= 360.0F;
}
this.setPosition(this.posX, this.posY, this.posZ);
this.setRotation(yaw, pitch);
}
示例6: onItemUseFinish
import net.minecraft.util.math.MathHelper; //导入方法依赖的package包/类
/**
* Called when the player finishes using this Item (E.g. finishes eating.). Not called when the player stops using
* the Item before the action is complete.
*/
@Nullable
public ItemStack onItemUseFinish(ItemStack stack, World worldIn, EntityLivingBase entityLiving)
{
ItemStack itemstack = super.onItemUseFinish(stack, worldIn, entityLiving);
if (!worldIn.isRemote)
{
double d0 = entityLiving.posX;
double d1 = entityLiving.posY;
double d2 = entityLiving.posZ;
for (int i = 0; i < 16; ++i)
{
double d3 = entityLiving.posX + (entityLiving.getRNG().nextDouble() - 0.5D) * 16.0D;
double d4 = MathHelper.clamp_double(entityLiving.posY + (double)(entityLiving.getRNG().nextInt(16) - 8), 0.0D, (double)(worldIn.getActualHeight() - 1));
double d5 = entityLiving.posZ + (entityLiving.getRNG().nextDouble() - 0.5D) * 16.0D;
if (entityLiving.isRiding())
{
entityLiving.dismountRidingEntity();
}
if (entityLiving.attemptTeleport(d3, d4, d5))
{
worldIn.playSound((EntityPlayer)null, d0, d1, d2, SoundEvents.ITEM_CHORUS_FRUIT_TELEPORT, SoundCategory.PLAYERS, 1.0F, 1.0F);
entityLiving.playSound(SoundEvents.ITEM_CHORUS_FRUIT_TELEPORT, 1.0F, 1.0F);
break;
}
}
if (entityLiving instanceof EntityPlayer)
{
((EntityPlayer)entityLiving).getCooldownTracker().setCooldown(this, 20);
}
}
return itemstack;
}
示例7: getHeights
import net.minecraft.util.math.MathHelper; //导入方法依赖的package包/类
private double[] getHeights(double[] p_185963_1_, int p_185963_2_, int p_185963_3_, int p_185963_4_, int p_185963_5_, int p_185963_6_, int p_185963_7_)
{
net.minecraftforge.event.terraingen.ChunkGeneratorEvent.InitNoiseField event = new net.minecraftforge.event.terraingen.ChunkGeneratorEvent.InitNoiseField(this, p_185963_1_, p_185963_2_, p_185963_3_, p_185963_4_, p_185963_5_, p_185963_6_, p_185963_7_);
net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(event);
if (event.getResult() == net.minecraftforge.fml.common.eventhandler.Event.Result.DENY) return event.getNoisefield();
if (p_185963_1_ == null)
{
p_185963_1_ = new double[p_185963_5_ * p_185963_6_ * p_185963_7_];
}
double d0 = 684.412D;
double d1 = 684.412D;
d0 = d0 * 2.0D;
this.pnr = this.perlinNoise1.generateNoiseOctaves(this.pnr, p_185963_2_, p_185963_3_, p_185963_4_, p_185963_5_, p_185963_6_, p_185963_7_, d0 / 80.0D, 4.277575000000001D, d0 / 80.0D);
this.ar = this.lperlinNoise1.generateNoiseOctaves(this.ar, p_185963_2_, p_185963_3_, p_185963_4_, p_185963_5_, p_185963_6_, p_185963_7_, d0, 684.412D, d0);
this.br = this.lperlinNoise2.generateNoiseOctaves(this.br, p_185963_2_, p_185963_3_, p_185963_4_, p_185963_5_, p_185963_6_, p_185963_7_, d0, 684.412D, d0);
int i = p_185963_2_ / 2;
int j = p_185963_4_ / 2;
int k = 0;
for (int l = 0; l < p_185963_5_; ++l)
{
for (int i1 = 0; i1 < p_185963_7_; ++i1)
{
float f = this.getIslandHeightValue(i, j, l, i1);
for (int j1 = 0; j1 < p_185963_6_; ++j1)
{
double d2 = this.ar[k] / 512.0D;
double d3 = this.br[k] / 512.0D;
double d5 = (this.pnr[k] / 10.0D + 1.0D) / 2.0D;
double d4;
if (d5 < 0.0D)
{
d4 = d2;
}
else if (d5 > 1.0D)
{
d4 = d3;
}
else
{
d4 = d2 + (d3 - d2) * d5;
}
d4 = d4 - 8.0D;
d4 = d4 + (double)f;
int k1 = 2;
if (j1 > p_185963_6_ / 2 - k1)
{
double d6 = (double)((float)(j1 - (p_185963_6_ / 2 - k1)) / 64.0F);
d6 = MathHelper.clamp_double(d6, 0.0D, 1.0D);
d4 = d4 * (1.0D - d6) + -3000.0D * d6;
}
k1 = 8;
if (j1 < k1)
{
double d7 = (double)((float)(k1 - j1) / ((float)k1 - 1.0F));
d4 = d4 * (1.0D - d7) + -30.0D * d7;
}
p_185963_1_[k] = d4;
++k;
}
}
}
return p_185963_1_;
}
示例8: clampValue
import net.minecraft.util.math.MathHelper; //导入方法依赖的package包/类
public double clampValue(double value)
{
value = MathHelper.clamp_double(value, this.minimumValue, this.maximumValue);
return value;
}
示例9: 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));
}
}
}
示例10: clamp
import net.minecraft.util.math.MathHelper; //导入方法依赖的package包/类
public static double clamp(double p_clamp_0_, double p_clamp_2_, double p_clamp_4_)
{
return MathHelper.clamp_double(p_clamp_0_, p_clamp_2_, p_clamp_4_);
}
示例11: transferEntityToWorld
import net.minecraft.util.math.MathHelper; //导入方法依赖的package包/类
@SuppressWarnings("unused")
public void transferEntityToWorld(Entity entityIn, int lastDimension, WorldServer oldWorldIn, WorldServer toWorldIn, net.minecraft.world.Teleporter teleporter)
{
net.minecraft.world.WorldProvider pOld = oldWorldIn.provider;
net.minecraft.world.WorldProvider pNew = toWorldIn.provider;
double moveFactor = pOld.getMovementFactor() / pNew.getMovementFactor();
double d0 = entityIn.posX * moveFactor;
double d1 = entityIn.posZ * moveFactor;
double d2 = 8.0D;
float f = entityIn.rotationYaw;
oldWorldIn.theProfiler.startSection("moving");
if (false && entityIn.dimension == -1)
{
d0 = MathHelper.clamp_double(d0 / 8.0D, toWorldIn.getWorldBorder().minX() + 16.0D, toWorldIn.getWorldBorder().maxX() - 16.0D);
d1 = MathHelper.clamp_double(d1 / 8.0D, toWorldIn.getWorldBorder().minZ() + 16.0D, toWorldIn.getWorldBorder().maxZ() - 16.0D);
entityIn.setLocationAndAngles(d0, entityIn.posY, d1, entityIn.rotationYaw, entityIn.rotationPitch);
if (entityIn.isEntityAlive())
{
oldWorldIn.updateEntityWithOptionalForce(entityIn, false);
}
}
else if (false && entityIn.dimension == 0)
{
d0 = MathHelper.clamp_double(d0 * 8.0D, toWorldIn.getWorldBorder().minX() + 16.0D, toWorldIn.getWorldBorder().maxX() - 16.0D);
d1 = MathHelper.clamp_double(d1 * 8.0D, toWorldIn.getWorldBorder().minZ() + 16.0D, toWorldIn.getWorldBorder().maxZ() - 16.0D);
entityIn.setLocationAndAngles(d0, entityIn.posY, d1, entityIn.rotationYaw, entityIn.rotationPitch);
if (entityIn.isEntityAlive())
{
oldWorldIn.updateEntityWithOptionalForce(entityIn, false);
}
}
if (entityIn.dimension == 1)
{
BlockPos blockpos;
if (lastDimension == 1)
{
blockpos = toWorldIn.getSpawnPoint();
}
else
{
blockpos = toWorldIn.getSpawnCoordinate();
}
d0 = (double)blockpos.getX();
entityIn.posY = (double)blockpos.getY();
d1 = (double)blockpos.getZ();
entityIn.setLocationAndAngles(d0, entityIn.posY, d1, 90.0F, 0.0F);
if (entityIn.isEntityAlive())
{
oldWorldIn.updateEntityWithOptionalForce(entityIn, false);
}
}
oldWorldIn.theProfiler.endSection();
if (lastDimension != 1)
{
oldWorldIn.theProfiler.startSection("placing");
d0 = (double)MathHelper.clamp_int((int)d0, -29999872, 29999872);
d1 = (double)MathHelper.clamp_int((int)d1, -29999872, 29999872);
if (entityIn.isEntityAlive())
{
entityIn.setLocationAndAngles(d0, entityIn.posY, d1, entityIn.rotationYaw, entityIn.rotationPitch);
teleporter.placeInPortal(entityIn, f);
toWorldIn.spawnEntityInWorld(entityIn);
toWorldIn.updateEntityWithOptionalForce(entityIn, false);
}
oldWorldIn.theProfiler.endSection();
}
entityIn.setWorld(toWorldIn);
}
示例12: updateTimer
import net.minecraft.util.math.MathHelper; //导入方法依赖的package包/类
/**
* Updates all fields of the Timer using the current time
*/
public void updateTimer()
{
long i = Minecraft.getSystemTime();
long j = i - this.lastSyncSysClock;
long k = System.nanoTime() / 1000000L;
double d0 = (double)k / 1000.0D;
if (j <= 1000L && j >= 0L)
{
this.counter += j;
if (this.counter > 1000L)
{
long l = k - this.lastSyncHRClock;
double d1 = (double)this.counter / (double)l;
this.timeSyncAdjustment += (d1 - this.timeSyncAdjustment) * 0.20000000298023224D;
this.lastSyncHRClock = k;
this.counter = 0L;
}
if (this.counter < 0L)
{
this.lastSyncHRClock = k;
}
}
else
{
this.lastHRTime = d0;
}
this.lastSyncSysClock = i;
double d2 = (d0 - this.lastHRTime) * this.timeSyncAdjustment;
this.lastHRTime = d0;
d2 = MathHelper.clamp_double(d2, 0.0D, 1.0D);
this.elapsedPartialTicks = (float)((double)this.elapsedPartialTicks + d2 * (double)this.timerSpeed * (double)this.ticksPerSecond);
this.elapsedTicks = (int)this.elapsedPartialTicks;
this.elapsedPartialTicks -= (float)this.elapsedTicks;
if (this.elapsedTicks > 10)
{
this.elapsedTicks = 10;
}
this.renderPartialTicks = this.elapsedPartialTicks;
}