本文整理汇总了Java中net.minecraft.util.math.MathHelper.clamp方法的典型用法代码示例。如果您正苦于以下问题:Java MathHelper.clamp方法的具体用法?Java MathHelper.clamp怎么用?Java MathHelper.clamp使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.minecraft.util.math.MathHelper
的用法示例。
在下文中一共展示了MathHelper.clamp方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: safeImpact
import net.minecraft.util.math.MathHelper; //导入方法依赖的package包/类
@Override
public void safeImpact(BlockPos pos, @Nullable EnumFacing side, World world, int amplifier) {
int box = 1 + (int) ((float) amplifier / 2F);
BlockPos posI = pos.add(box, 1, box);
BlockPos posF = pos.add(-box, -1, -box);
Iterable<BlockPos> spots = BlockPos.getAllInBox(posI, posF);
int chance = 10 + amplifier * 2;
int fortune = MathHelper.clamp(amplifier, 0, 5);
for (BlockPos spot : spots) {
IBlockState state = world.getBlockState(spot);
boolean place = amplifier > 1 || world.rand.nextBoolean();
if (place && state.getBlock() instanceof BlockCrops) {
BlockCrops crop = (BlockCrops) state.getBlock();
if (crop.isMaxAge(state)) {
crop.dropBlockAsItemWithChance(world, spot, state, chance, fortune);
world.setBlockToAir(spot);
}
}
}
}
示例2: getBrightnessForRender
import net.minecraft.util.math.MathHelper; //导入方法依赖的package包/类
public int getBrightnessForRender(float partialTicks)
{
float f = 0.5F;
f = MathHelper.clamp(f, 0.0F, 1.0F);
int i = super.getBrightnessForRender(partialTicks);
int j = i & 255;
int k = i >> 16 & 255;
j = j + (int)(f * 15.0F * 16.0F);
if (j > 240)
{
j = 240;
}
return j | k << 16;
}
示例3: preRenderCallback
import net.minecraft.util.math.MathHelper; //导入方法依赖的package包/类
@Override
protected void preRenderCallback(EntityCreeperween entity, float partialTickTime)
{
float f = entity.getCreeperFlashIntensity(partialTickTime);
float f1 = 1.0F + MathHelper.sin(f * 100.0F) * f * 0.01F;
f = MathHelper.clamp(f, 0.0F, 1.0F);
f = f * f;
f = f * f;
float width = (1.625F + f * 0.4F) * f1;
float height = (1.625F + f * 0.1F) / f1;
GlStateManager.scale(width, height, width);
}
示例4: renderParticle
import net.minecraft.util.math.MathHelper; //导入方法依赖的package包/类
/**
* Renders the particle
*/
public void renderParticle(VertexBuffer worldRendererIn, Entity entityIn, float partialTicks, float rotationX, float rotationZ, float rotationYZ, float rotationXY, float rotationXZ)
{
float f = ((float)this.particleAge + partialTicks) / (float)this.particleMaxAge * 32.0F;
f = MathHelper.clamp(f, 0.0F, 1.0F);
this.particleScale = this.smokeParticleScale * f;
super.renderParticle(worldRendererIn, entityIn, partialTicks, rotationX, rotationZ, rotationYZ, rotationXY, rotationXZ);
}
示例5: onLivingUpdate
import net.minecraft.util.math.MathHelper; //导入方法依赖的package包/类
/**
* Called frequently so the entity can update its state every tick as required. For example, zombies and skeletons
* use this to react to sunlight and start to burn.
*/
public void onLivingUpdate()
{
super.onLivingUpdate();
this.oFlap = this.wingRotation;
this.oFlapSpeed = this.destPos;
this.destPos = (float)((double)this.destPos + (double)(this.onGround ? -1 : 4) * 0.3D);
this.destPos = MathHelper.clamp(this.destPos, 0.0F, 1.0F);
if (!this.onGround && this.wingRotDelta < 1.0F)
{
this.wingRotDelta = 1.0F;
}
this.wingRotDelta = (float)((double)this.wingRotDelta * 0.9D);
if (!this.onGround && this.motionY < 0.0D)
{
this.motionY *= 0.6D;
}
this.wingRotation += this.wingRotDelta * 2.0F;
if (!this.world.isRemote && !this.isChild() && !this.isChickenJockey() && --this.timeUntilNextEgg <= 0)
{
this.playSound(SoundEvents.ENTITY_CHICKEN_EGG, 1.0F, (this.rand.nextFloat() - this.rand.nextFloat()) * 0.2F + 1.0F);
this.dropItem(Items.EGG, 1);
this.timeUntilNextEgg = this.rand.nextInt(6000) + 6000;
}
}
示例6: handleMouseInput
import net.minecraft.util.math.MathHelper; //导入方法依赖的package包/类
public void handleMouseInput() throws IOException {
int i = Mouse.getEventDWheel();
i = MathHelper.clamp(i, -1, 1);
buttonListOffset -= i*10;
if (buttonListOffset < 0) buttonListOffset = 0; // dont scroll up if its already at the top
int lowestButtonY = (GuiButton.height+1) * buttonList.size() + windowY;
int lowestAllowedOffset = lowestButtonY - height - windowY + 3;
if (lowestButtonY - buttonListOffset < bottomY)
buttonListOffset = lowestAllowedOffset;
}
示例7: readFromNBT
import net.minecraft.util.math.MathHelper; //导入方法依赖的package包/类
public void readFromNBT(NBTTagCompound compound)
{
super.readFromNBT(compound);
this.note = compound.getByte("note");
this.note = (byte)MathHelper.clamp(this.note, 0, 24);
this.previousRedstoneState = compound.getBoolean("powered");
}
示例8: renderParticle
import net.minecraft.util.math.MathHelper; //导入方法依赖的package包/类
public void renderParticle(BufferBuilder buffer, Entity entityIn, float partialTicks, float rotationX, float rotationZ, float rotationYZ, float rotationXY, float rotationXZ) {
float scale = ((float) this.particleAge + partialTicks) / (float) this.particleMaxAge * 32.0F;
scale = MathHelper.clamp(scale, 0.0F, 1.0F);
this.particleScale = this.oSize * scale;
super.renderParticle(buffer, entityIn, partialTicks, rotationX, rotationZ, rotationYZ, rotationXY, rotationXZ);
GlStateManager.color(getRedColorF(), getGreenColorF(), getBlueColorF(), 1.0F);
}
示例9: getMapAngleFromPitch
import net.minecraft.util.math.MathHelper; //导入方法依赖的package包/类
/**
* Return the angle to render the Map
*/
private float getMapAngleFromPitch(float pitch)
{
float f = 1.0F - pitch / 45.0F + 0.1F;
f = MathHelper.clamp(f, 0.0F, 1.0F);
f = -MathHelper.cos(f * (float)Math.PI) * 0.5F + 0.5F;
return f;
}
示例10: setCursorPosition
import net.minecraft.util.math.MathHelper; //导入方法依赖的package包/类
/**
* Sets the current position of the cursor.
*/
public void setCursorPosition(int pos)
{
this.cursorPosition = pos;
int i = this.text.length();
this.cursorPosition = MathHelper.clamp(this.cursorPosition, 0, i);
this.setSelectionPos(this.cursorPosition);
}
示例11: setStability
import net.minecraft.util.math.MathHelper; //导入方法依赖的package包/类
public StabilityData setStability(float amount) {
this.stability = MathHelper.clamp(amount, MIN_STABILITY, MAX_STABILITY);
return this;
}
示例12: quantityDroppedWithBonus
import net.minecraft.util.math.MathHelper; //导入方法依赖的package包/类
public int quantityDroppedWithBonus(int fortune, @Nonnull Random random) {
return MathHelper.clamp(this.quantityDropped(random) + random.nextInt(fortune + 1), 1, 4);
}
示例13: 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.world.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(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(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.world.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));
}
}
}
示例14: getDamageBeforeAbsorb
import net.minecraft.util.math.MathHelper; //导入方法依赖的package包/类
public static float getDamageBeforeAbsorb(float damage, float totalArmor, float toughnessAttribute)
{
float f = 2.0F + toughnessAttribute / 4.0F;
float f1 = MathHelper.clamp(totalArmor - damage / f, totalArmor * 0.2F, 20.0F);
return damage * (1.0F - f1 / 25.0F);
}
示例15: setPlayerViewRadius
import net.minecraft.util.math.MathHelper; //导入方法依赖的package包/类
public void setPlayerViewRadius(int radius)
{
radius = MathHelper.clamp(radius, 3, 32);
if (radius != this.playerViewRadius)
{
int i = radius - this.playerViewRadius;
for (EntityPlayerMP entityplayermp : Lists.newArrayList(this.players))
{
int j = (int)entityplayermp.posX >> 4;
int k = (int)entityplayermp.posZ >> 4;
if (i > 0)
{
for (int j1 = j - radius; j1 <= j + radius; ++j1)
{
for (int k1 = k - radius; k1 <= k + radius; ++k1)
{
PlayerChunkMapEntry playerchunkmapentry = this.getOrCreateEntry(j1, k1);
if (!playerchunkmapentry.containsPlayer(entityplayermp))
{
playerchunkmapentry.addPlayer(entityplayermp);
}
}
}
}
else
{
for (int l = j - this.playerViewRadius; l <= j + this.playerViewRadius; ++l)
{
for (int i1 = k - this.playerViewRadius; i1 <= k + this.playerViewRadius; ++i1)
{
if (!this.overlaps(l, i1, j, k, radius))
{
this.getOrCreateEntry(l, i1).removePlayer(entityplayermp);
}
}
}
}
}
this.playerViewRadius = radius;
this.markSortPending();
}
}