本文整理匯總了Java中net.minecraft.util.MathHelper.clamp_int方法的典型用法代碼示例。如果您正苦於以下問題:Java MathHelper.clamp_int方法的具體用法?Java MathHelper.clamp_int怎麽用?Java MathHelper.clamp_int使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類net.minecraft.util.MathHelper
的用法示例。
在下文中一共展示了MathHelper.clamp_int方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: updatePower
import net.minecraft.util.MathHelper; //導入方法依賴的package包/類
public void updatePower(World worldIn, BlockPos pos)
{
if (!worldIn.provider.getHasNoSky())
{
IBlockState iblockstate = worldIn.getBlockState(pos);
int i = worldIn.getLightFor(EnumSkyBlock.SKY, pos) - worldIn.getSkylightSubtracted();
float f = worldIn.getCelestialAngleRadians(1.0F);
float f1 = f < (float)Math.PI ? 0.0F : ((float)Math.PI * 2F);
f = f + (f1 - f) * 0.2F;
i = Math.round((float)i * MathHelper.cos(f));
i = MathHelper.clamp_int(i, 0, 15);
if (this.inverted)
{
i = 15 - i;
}
if (((Integer)iblockstate.getValue(POWER)).intValue() != i)
{
worldIn.setBlockState(pos, iblockstate.withProperty(POWER, Integer.valueOf(i)), 3);
}
}
}
示例2: getWeakPower
import net.minecraft.util.MathHelper; //導入方法依賴的package包/類
public int getWeakPower(IBlockAccess worldIn, BlockPos pos, IBlockState state, EnumFacing side)
{
if (!this.canProvidePower())
{
return 0;
}
else
{
int i = 0;
TileEntity tileentity = worldIn.getTileEntity(pos);
if (tileentity instanceof TileEntityChest)
{
i = ((TileEntityChest)tileentity).numPlayersUsing;
}
return MathHelper.clamp_int(i, 0, 15);
}
}
示例3: getSentHistory
import net.minecraft.util.MathHelper; //導入方法依賴的package包/類
/**
* input is relative and is applied directly to the sentHistoryCursor so -1 is the previous message, 1 is the next
* message from the current cursor position
*/
public void getSentHistory(int msgPos)
{
int i = this.sentHistoryCursor + msgPos;
int j = this.mc.ingameGUI.getChatGUI().getSentMessages().size();
i = MathHelper.clamp_int(i, 0, j);
if (i != this.sentHistoryCursor)
{
if (i == j)
{
this.sentHistoryCursor = j;
this.inputField.setText(this.historyBuffer);
}
else
{
if (this.sentHistoryCursor == j)
{
this.historyBuffer = this.inputField.getText();
}
this.inputField.setText((String)this.mc.ingameGUI.getChatGUI().getSentMessages().get(i));
this.sentHistoryCursor = i;
}
}
}
示例4: func_181553_a
import net.minecraft.util.MathHelper; //導入方法依賴的package包/類
private int func_181553_a(int p_181553_1_, int p_181553_2_, float p_181553_3_)
{
int i = p_181553_1_ >> 24 & 255;
int j = p_181553_1_ >> 16 & 255;
int k = p_181553_1_ >> 8 & 255;
int l = p_181553_1_ & 255;
int i1 = p_181553_2_ >> 24 & 255;
int j1 = p_181553_2_ >> 16 & 255;
int k1 = p_181553_2_ >> 8 & 255;
int l1 = p_181553_2_ & 255;
int i2 = MathHelper.clamp_int((int)((float)i + (float)(i1 - i) * p_181553_3_), 0, 255);
int j2 = MathHelper.clamp_int((int)((float)j + (float)(j1 - j) * p_181553_3_), 0, 255);
int k2 = MathHelper.clamp_int((int)((float)k + (float)(k1 - k) * p_181553_3_), 0, 255);
int l2 = MathHelper.clamp_int((int)((float)l + (float)(l1 - l) * p_181553_3_), 0, 255);
return i2 << 24 | j2 << 16 | k2 << 8 | l2;
}
示例5: getEntitiesWithinAABBForEntity
import net.minecraft.util.MathHelper; //導入方法依賴的package包/類
/**
* Fills the given list of all entities that intersect within the given bounding box that aren't the passed entity.
*/
public void getEntitiesWithinAABBForEntity(Entity entityIn, AxisAlignedBB aabb, List<Entity> listToFill, Predicate <? super Entity > p_177414_4_)
{
int i = MathHelper.floor_double((aabb.minY - 2.0D) / 16.0D);
int j = MathHelper.floor_double((aabb.maxY + 2.0D) / 16.0D);
i = MathHelper.clamp_int(i, 0, this.entityLists.length - 1);
j = MathHelper.clamp_int(j, 0, this.entityLists.length - 1);
for (int k = i; k <= j; ++k)
{
if (!this.entityLists[k].isEmpty())
{
for (Entity entity : this.entityLists[k])
{
if (entity.getEntityBoundingBox().intersectsWith(aabb) && entity != entityIn)
{
if (p_177414_4_ == null || p_177414_4_.apply(entity))
{
listToFill.add(entity);
}
Entity[] aentity = entity.getParts();
if (aentity != null)
{
for (int l = 0; l < aentity.length; ++l)
{
entity = aentity[l];
if (entity != entityIn && entity.getEntityBoundingBox().intersectsWith(aabb) && (p_177414_4_ == null || p_177414_4_.apply(entity)))
{
listToFill.add(entity);
}
}
}
}
}
}
}
}
示例6: setSelectionPos
import net.minecraft.util.MathHelper; //導入方法依賴的package包/類
/**
* Sets the position of the selection anchor (i.e. position the selection was started at)
*/
public void setSelectionPos(int pos) {
int i = this.text.length();
if (pos > i) {
pos = i;
}
if (pos < 0) {
pos = 0;
}
this.selectionEnd = pos;
if (this.fontRendererInstance != null) {
if (this.lineScrollOffset > i) {
this.lineScrollOffset = i;
}
int j = this.getWidth();
String s = this.fontRendererInstance.trimStringToWidth(this.text.substring(this.lineScrollOffset), j);
int k = s.length() + this.lineScrollOffset;
if (pos == this.lineScrollOffset) {
this.lineScrollOffset -= this.fontRendererInstance.trimStringToWidth(this.text, j, true).length();
}
if (pos > k) {
this.lineScrollOffset += pos - k;
} else if (pos <= this.lineScrollOffset) {
this.lineScrollOffset -= this.lineScrollOffset - pos;
}
this.lineScrollOffset = MathHelper.clamp_int(this.lineScrollOffset, 0, i);
}
}
示例7: load
import net.minecraft.util.MathHelper; //導入方法依賴的package包/類
/**
* Load note data from NBT tag
* @param note Target note
* @param tag tag to load
* @param seed Loading seed
*/
private static void load(TileEntityNote note, NBTTagCompound tag, long seed) {
if (tag == null) {
return;
}
Random random = new Random(seed);
note.note = (byte) MathHelper.clamp_int(tag.getByte("note"), 0, 24);
note.previousRedstoneState = tag.getBoolean("powered");
}
示例8: putColorRGB_F
import net.minecraft.util.MathHelper; //導入方法依賴的package包/類
public void putColorRGB_F(float red, float green, float blue, int p_178994_4_)
{
int i = this.getColorIndex(p_178994_4_);
int j = MathHelper.clamp_int((int)(red * 255.0F), 0, 255);
int k = MathHelper.clamp_int((int)(green * 255.0F), 0, 255);
int l = MathHelper.clamp_int((int)(blue * 255.0F), 0, 255);
this.putColorRGBA(i, j, k, l, 255);
}
示例9: transferEntityToWorld
import net.minecraft.util.MathHelper; //導入方法依賴的package包/類
/**
* Transfers an entity from a world to another world.
*/
public void transferEntityToWorld(Entity entityIn, int p_82448_2_, WorldServer p_82448_3_, WorldServer p_82448_4_)
{
double d0 = entityIn.posX;
double d1 = entityIn.posZ;
double d2 = 8.0D;
float f = entityIn.rotationYaw;
p_82448_3_.theProfiler.startSection("moving");
if (entityIn.dimension == -1)
{
d0 = MathHelper.clamp_double(d0 / d2, p_82448_4_.getWorldBorder().minX() + 16.0D, p_82448_4_.getWorldBorder().maxX() - 16.0D);
d1 = MathHelper.clamp_double(d1 / d2, p_82448_4_.getWorldBorder().minZ() + 16.0D, p_82448_4_.getWorldBorder().maxZ() - 16.0D);
entityIn.setLocationAndAngles(d0, entityIn.posY, d1, entityIn.rotationYaw, entityIn.rotationPitch);
if (entityIn.isEntityAlive())
{
p_82448_3_.updateEntityWithOptionalForce(entityIn, false);
}
}
else if (entityIn.dimension == 0)
{
d0 = MathHelper.clamp_double(d0 * d2, p_82448_4_.getWorldBorder().minX() + 16.0D, p_82448_4_.getWorldBorder().maxX() - 16.0D);
d1 = MathHelper.clamp_double(d1 * d2, p_82448_4_.getWorldBorder().minZ() + 16.0D, p_82448_4_.getWorldBorder().maxZ() - 16.0D);
entityIn.setLocationAndAngles(d0, entityIn.posY, d1, entityIn.rotationYaw, entityIn.rotationPitch);
if (entityIn.isEntityAlive())
{
p_82448_3_.updateEntityWithOptionalForce(entityIn, false);
}
}
else
{
BlockPos blockpos;
if (p_82448_2_ == 1)
{
blockpos = p_82448_4_.getSpawnPoint();
}
else
{
blockpos = p_82448_4_.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())
{
p_82448_3_.updateEntityWithOptionalForce(entityIn, false);
}
}
p_82448_3_.theProfiler.endSection();
if (p_82448_2_ != 1)
{
p_82448_3_.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);
p_82448_4_.getDefaultTeleporter().placeInPortal(entityIn, f);
p_82448_4_.spawnEntityInWorld(entityIn);
p_82448_4_.updateEntityWithOptionalForce(entityIn, false);
}
p_82448_3_.theProfiler.endSection();
}
entityIn.setWorld(p_82448_4_);
}
示例10: quantityDroppedWithBonus
import net.minecraft.util.MathHelper; //導入方法依賴的package包/類
/**
* Get the quantity dropped based on the given fortune level
*/
public int quantityDroppedWithBonus(int fortune, Random random)
{
return MathHelper.clamp_int(this.quantityDropped(random) + random.nextInt(fortune + 1), 1, 4);
}
示例11: readFromNBT
import net.minecraft.util.MathHelper; //導入方法依賴的package包/類
public void readFromNBT(NBTTagCompound compound)
{
super.readFromNBT(compound);
this.note = compound.getByte("note");
this.note = (byte)MathHelper.clamp_int(this.note, 0, 24);
}
示例12: drawScreen
import net.minecraft.util.MathHelper; //導入方法依賴的package包/類
public void drawScreen(int mouseXIn, int mouseYIn, float p_148128_3_)
{
if (this.field_178041_q)
{
this.mouseX = mouseXIn;
this.mouseY = mouseYIn;
this.drawBackground();
int i = this.getScrollBarX();
int j = i + 6;
this.bindAmountScrolled();
GlStateManager.disableLighting();
GlStateManager.disableFog();
Tessellator tessellator = Tessellator.getInstance();
WorldRenderer worldrenderer = tessellator.getWorldRenderer();
int k = this.left + this.width / 2 - this.getListWidth() / 2 + 2;
int l = this.top + 4 - (int)this.amountScrolled;
if (this.hasListHeader)
{
this.drawListHeader(k, l, tessellator);
}
this.drawSelectionBox(k, l, mouseXIn, mouseYIn);
GlStateManager.disableDepth();
int i1 = 4;
this.overlayBackground(0, this.top, 255, 255);
this.overlayBackground(this.bottom, this.height, 255, 255);
GlStateManager.enableBlend();
GlStateManager.tryBlendFuncSeparate(770, 771, 0, 1);
GlStateManager.disableAlpha();
GlStateManager.shadeModel(7425);
GlStateManager.disableTexture2D();
int j1 = this.func_148135_f();
if (j1 > 0)
{
int k1 = (this.bottom - this.top) * (this.bottom - this.top) / this.getContentHeight();
k1 = MathHelper.clamp_int(k1, 32, this.bottom - this.top - 8);
int l1 = (int)this.amountScrolled * (this.bottom - this.top - k1) / j1 + this.top;
if (l1 < this.top)
{
l1 = this.top;
}
worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
worldrenderer.pos((double)i, (double)this.bottom, 0.0D).tex(0.0D, 1.0D).color(0, 0, 0, 255).endVertex();
worldrenderer.pos((double)j, (double)this.bottom, 0.0D).tex(1.0D, 1.0D).color(0, 0, 0, 255).endVertex();
worldrenderer.pos((double)j, (double)this.top, 0.0D).tex(1.0D, 0.0D).color(0, 0, 0, 255).endVertex();
worldrenderer.pos((double)i, (double)this.top, 0.0D).tex(0.0D, 0.0D).color(0, 0, 0, 255).endVertex();
tessellator.draw();
worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
worldrenderer.pos((double)i, (double)(l1 + k1), 0.0D).tex(0.0D, 1.0D).color(128, 128, 128, 255).endVertex();
worldrenderer.pos((double)j, (double)(l1 + k1), 0.0D).tex(1.0D, 1.0D).color(128, 128, 128, 255).endVertex();
worldrenderer.pos((double)j, (double)l1, 0.0D).tex(1.0D, 0.0D).color(128, 128, 128, 255).endVertex();
worldrenderer.pos((double)i, (double)l1, 0.0D).tex(0.0D, 0.0D).color(128, 128, 128, 255).endVertex();
tessellator.draw();
worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
worldrenderer.pos((double)i, (double)(l1 + k1 - 1), 0.0D).tex(0.0D, 1.0D).color(192, 192, 192, 255).endVertex();
worldrenderer.pos((double)(j - 1), (double)(l1 + k1 - 1), 0.0D).tex(1.0D, 1.0D).color(192, 192, 192, 255).endVertex();
worldrenderer.pos((double)(j - 1), (double)l1, 0.0D).tex(1.0D, 0.0D).color(192, 192, 192, 255).endVertex();
worldrenderer.pos((double)i, (double)l1, 0.0D).tex(0.0D, 0.0D).color(192, 192, 192, 255).endVertex();
tessellator.draw();
}
this.func_148142_b(mouseXIn, mouseYIn);
GlStateManager.enableTexture2D();
GlStateManager.shadeModel(7424);
GlStateManager.enableAlpha();
GlStateManager.disableBlend();
}
}
示例13: readFromNBT
import net.minecraft.util.MathHelper; //導入方法依賴的package包/類
/**
* reads in data from the NBTTagCompound into this MapDataBase
*/
public void readFromNBT(NBTTagCompound nbt)
{
this.dimension = nbt.getByte("dimension");
this.xCenter = nbt.getInteger("xCenter");
this.zCenter = nbt.getInteger("zCenter");
this.scale = nbt.getByte("scale");
this.scale = (byte)MathHelper.clamp_int(this.scale, 0, 4);
int i = nbt.getShort("width");
int j = nbt.getShort("height");
if (i == 128 && j == 128)
{
this.colors = nbt.getByteArray("colors");
}
else
{
byte[] abyte = nbt.getByteArray("colors");
this.colors = new byte[16384];
int k = (128 - i) / 2;
int l = (128 - j) / 2;
for (int i1 = 0; i1 < j; ++i1)
{
int j1 = i1 + l;
if (j1 >= 0 || j1 < 128)
{
for (int k1 = 0; k1 < i; ++k1)
{
int l1 = k1 + k;
if (l1 >= 0 || l1 < 128)
{
this.colors[l1 + j1 * 128] = abyte[k1 + i1 * i];
}
}
}
}
}
}
示例14: setSelectionPos
import net.minecraft.util.MathHelper; //導入方法依賴的package包/類
/**
* Sets the position of the selection anchor (i.e. position the selection was started at)
*/
public void setSelectionPos(int p_146199_1_)
{
int i = this.text.length();
if (p_146199_1_ > i)
{
p_146199_1_ = i;
}
if (p_146199_1_ < 0)
{
p_146199_1_ = 0;
}
this.selectionEnd = p_146199_1_;
if (this.fontRendererInstance != null)
{
if (this.lineScrollOffset > i)
{
this.lineScrollOffset = i;
}
int j = this.getWidth();
String s = this.fontRendererInstance.trimStringToWidth(this.text.substring(this.lineScrollOffset), j);
int k = s.length() + this.lineScrollOffset;
if (p_146199_1_ == this.lineScrollOffset)
{
this.lineScrollOffset -= this.fontRendererInstance.trimStringToWidth(this.text, j, true).length();
}
if (p_146199_1_ > k)
{
this.lineScrollOffset += p_146199_1_ - k;
}
else if (p_146199_1_ <= this.lineScrollOffset)
{
this.lineScrollOffset -= this.lineScrollOffset - p_146199_1_;
}
this.lineScrollOffset = MathHelper.clamp_int(this.lineScrollOffset, 0, i);
}
}
示例15: update
import net.minecraft.util.MathHelper; //導入方法依賴的package包/類
/**
* Like the old updateEntity(), except more generic.
*/
public void update()
{
boolean flag = this.isBurning();
boolean flag1 = false;
if (this.isBurning())
{
--this.furnaceBurnTime;
}
if (!this.worldObj.isRemote)
{
if (this.isBurning() || this.furnaceItemStacks[1] != null && this.furnaceItemStacks[0] != null)
{
if (!this.isBurning() && this.canSmelt())
{
this.currentItemBurnTime = this.furnaceBurnTime = getItemBurnTime(this.furnaceItemStacks[1]);
if (this.isBurning())
{
flag1 = true;
if (this.furnaceItemStacks[1] != null)
{
--this.furnaceItemStacks[1].stackSize;
if (this.furnaceItemStacks[1].stackSize == 0)
{
Item item = this.furnaceItemStacks[1].getItem().getContainerItem();
this.furnaceItemStacks[1] = item != null ? new ItemStack(item) : null;
}
}
}
}
if (this.isBurning() && this.canSmelt())
{
++this.cookTime;
if (this.cookTime == this.totalCookTime)
{
this.cookTime = 0;
this.totalCookTime = this.getCookTime(this.furnaceItemStacks[0]);
this.smeltItem();
flag1 = true;
}
}
else
{
this.cookTime = 0;
}
}
else if (!this.isBurning() && this.cookTime > 0)
{
this.cookTime = MathHelper.clamp_int(this.cookTime - 2, 0, this.totalCookTime);
}
if (flag != this.isBurning())
{
flag1 = true;
BlockFurnace.setState(this.isBurning(), this.worldObj, this.pos);
}
}
if (flag1)
{
this.markDirty();
}
}