下面列出了net.minecraft.util.math.MathHelper#abs ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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;
}
private void transformEatFirstPerson(float p_187454_1_, EnumHandSide p_187454_2_, ItemStack p_187454_3_)
{
float f = (float)this.mc.thePlayer.getItemInUseCount() - p_187454_1_ + 1.0F;
float f1 = f / (float)p_187454_3_.getMaxItemUseDuration();
if (f1 < 0.8F)
{
float f2 = MathHelper.abs(MathHelper.cos(f / 4.0F * (float)Math.PI) * 0.1F);
GlStateManager.translate(0.0F, f2, 0.0F);
}
float f3 = 1.0F - (float)Math.pow((double)f1, 27.0D);
int i = p_187454_2_ == EnumHandSide.RIGHT ? 1 : -1;
GlStateManager.translate(f3 * 0.6F * (float)i, f3 * -0.5F, f3 * 0.0F);
GlStateManager.rotate((float)i * f3 * 90.0F, 0.0F, 1.0F, 0.0F);
GlStateManager.rotate(f3 * 10.0F, 1.0F, 0.0F, 0.0F);
GlStateManager.rotate((float)i * f3 * 30.0F, 0.0F, 0.0F, 1.0F);
}
/**
* Returns the absolute greatest distance in the BlockPos object.
*/
private int getGreatestDistance(BlockPos posIn)
{
int i = MathHelper.abs(posIn.getX());
int j = MathHelper.abs(posIn.getY());
int k = MathHelper.abs(posIn.getZ());
if (k > i && k > j)
{
return k;
}
return j > i ? j : i;
}
/**
* Returns the absolute greatest distance in the BlockPos object.
*/
private int getGreatestDistance(BlockPos posIn)
{
int i = MathHelper.abs(posIn.getX());
int j = MathHelper.abs(posIn.getY());
int k = MathHelper.abs(posIn.getZ());
if (k > i && k > j)
{
return k;
}
return j > i ? j : i;
}
public static EnumFacing getFacingFromEntity(BlockPos pos, EntityLivingBase entity) {
if (MathHelper.abs((float)entity.posX - (float)pos.getX()) < 2.0F && MathHelper.abs((float)entity.posZ - (float)pos.getZ()) < 2.0F) {
double d0 = entity.posY + (double)entity.getEyeHeight();
if (d0 - (double)pos.getY() > 2.0D) {
return EnumFacing.UP;
}
if ((double)pos.getY() - d0 > 0.0D) {
return EnumFacing.DOWN;
}
}
return entity.getHorizontalFacing().getOpposite();
}
public static EnumFacing get3dOrientation(EntityLivingBase entity, BlockPos pos) {
if (MathHelper.abs((float)entity.posX - pos.getX()) < 2.0F && MathHelper.abs((float)entity.posZ - pos.getZ()) < 2.0F) {
final double entityEyes = entity.posY + entity.getEyeHeight();
if (entityEyes - pos.getY() > 2.0D) return EnumFacing.DOWN;
if (pos.getY() - entityEyes > 0.0D) return EnumFacing.UP;
}
return entity.getHorizontalFacing();
}
public void render(int int_1, int int_2, float float_1) {
if (this.backgroundFadeStart == 0L && this.doBackgroundFade) {
this.backgroundFadeStart = Util.getMeasuringTimeMs();
}
float float_2 = this.doBackgroundFade ? (float) (Util.getMeasuringTimeMs() - this.backgroundFadeStart) / 1000.0F : 1.0F;
fill(0, 0, this.width, this.height, -1);
this.backgroundRenderer.render(float_1, MathHelper.clamp(float_2, 0.0F, 1.0F));
int int_4 = this.width / 2 - 137;
this.minecraft.getTextureManager().bindTexture(PANORAMA_OVERLAY);
GlStateManager.enableBlend();
GlStateManager.blendFunc(GlStateManager.SrcFactor.SRC_ALPHA.value, GlStateManager.DstFactor.ONE_MINUS_SRC_ALPHA.value);
GlStateManager.color4f(1.0F, 1.0F, 1.0F, this.doBackgroundFade ? (float) MathHelper.ceil(MathHelper.clamp(float_2, 0.0F, 1.0F)) : 1.0F);
blit(0, 0, this.width, this.height, 0.0F, 0.0F, 16, 128, 16, 128);
float float_3 = this.doBackgroundFade ? MathHelper.clamp(float_2 - 1.0F, 0.0F, 1.0F) : 1.0F;
int int_6 = MathHelper.ceil(float_3 * 255.0F) << 24;
if ((int_6 & -67108864) != 0) {
this.minecraft.getTextureManager().bindTexture(MINECRAFT_TITLE_TEXTURE);
GlStateManager.color4f(1.0F, 1.0F, 1.0F, float_3);
if (this.field_17776) {
this.blit(int_4 + 0, 30, 0, 0, 99, 44);
this.blit(int_4 + 99, 30, 129, 0, 27, 44);
this.blit(int_4 + 99 + 26, 30, 126, 0, 3, 44);
this.blit(int_4 + 99 + 26 + 3, 30, 99, 0, 26, 44);
this.blit(int_4 + 155, 30, 0, 45, 155, 44);
} else {
this.blit(int_4 + 0, 30, 0, 0, 155, 44);
this.blit(int_4 + 155, 30, 0, 45, 155, 44);
}
this.minecraft.getTextureManager().bindTexture(EDITION_TITLE_TEXTURE);
blit(int_4 + 88, 67, 0.0F, 0.0F, 98, 14, 128, 16);
if (this.splashText != null) {
GlStateManager.pushMatrix();
GlStateManager.translatef((float) (this.width / 2 + 90), 70.0F, 0.0F);
GlStateManager.rotatef(-20.0F, 0.0F, 0.0F, 1.0F);
float float_4 = 1.8F - MathHelper.abs(MathHelper.sin((float) (Util.getMeasuringTimeMs() % 1000L) / 1000.0F * 6.2831855F) * 0.1F);
float_4 = float_4 * 100.0F / (float) (this.font.getStringWidth(this.splashText) + 32);
GlStateManager.scalef(float_4, float_4, float_4);
this.drawCenteredString(this.font, this.splashText, 0, -8, 16776960 | int_6);
GlStateManager.popMatrix();
}
String string_1 = "Minecraft " + SharedConstants.getGameVersion().getName();
if (this.minecraft.isDemo()) {
string_1 = string_1 + " Demo";
} else {
string_1 = string_1 + ("release".equalsIgnoreCase(this.minecraft.getVersionType()) ? "" : "/" + this.minecraft.getVersionType());
}
this.drawString(this.font, string_1, 2, this.height - 10, 16777215 | int_6);
this.drawString(this.font, "Copyright Mojang AB. Do not distribute!", this.copyrightTextX, this.height - 10, 16777215 | int_6);
if (int_1 > this.copyrightTextX && int_1 < this.copyrightTextX + this.copyrightTextWidth && int_2 > this.height - 10 && int_2 < this.height) {
fill(this.copyrightTextX, this.height - 1, this.copyrightTextX + this.copyrightTextWidth, this.height, 16777215 | int_6);
}
if (this.warning != null) {
this.warning.render(int_6);
}
Iterator var11 = this.buttons.iterator();
while (var11.hasNext()) {
AbstractButtonWidget abstractButtonWidget_1 = (AbstractButtonWidget) var11.next();
abstractButtonWidget_1.setAlpha(float_3);
}
super.render(int_1, int_2, float_1);
}
}
public boolean generate(World worldIn, Random rand, BlockPos position) {
while (worldIn.isAirBlock(position) && position.getY() > 2) {
position = position.down();
}
if (worldIn.getBlockState(position).getBlock() != Blocks.SNOW) {
return false;
} else {
position = position.up(rand.nextInt(4));
int i = rand.nextInt(4) + 7;
int j = i / 4 + rand.nextInt(2);
if (j > 1 && rand.nextInt(60) == 0) {
position = position.up(10 + rand.nextInt(30));
}
for (int k = 0; k < i; ++k) {
float f = (1.0F - (float) k / (float) i) * (float) j;
int l = MathHelper.ceil(f);
for (int i1 = -l; i1 <= l; ++i1) {
float f1 = (float) MathHelper.abs(i1) - 0.25F;
for (int j1 = -l; j1 <= l; ++j1) {
float f2 = (float) MathHelper.abs(j1) - 0.25F;
if ((i1 == 0 && j1 == 0 || f1 * f1 + f2 * f2 <= f * f) && (i1 != -l && i1 != l && j1 != -l && j1 != l || rand.nextFloat() <= 0.75F)) {
IBlockState iblockstate = worldIn.getBlockState(position.add(i1, k, j1));
Block block = iblockstate.getBlock();
if (iblockstate.getBlock().isAir(iblockstate, worldIn, position.add(i1, k, j1)) || block == Blocks.DIRT || block == Blocks.SNOW || block == Blocks.ICE) {
this.setBlockAndNotifyAdequately(worldIn, position.add(i1, k, j1), Blocks.PACKED_ICE.getDefaultState());
}
if (k != 0 && l > 1) {
iblockstate = worldIn.getBlockState(position.add(i1, -k, j1));
block = iblockstate.getBlock();
if (iblockstate.getBlock().isAir(iblockstate, worldIn, position.add(i1, -k, j1)) || block == Blocks.DIRT || block == Blocks.SNOW || block == Blocks.ICE) {
this.setBlockAndNotifyAdequately(worldIn, position.add(i1, -k, j1), Blocks.PACKED_ICE.getDefaultState());
}
}
}
}
}
}
int k1 = j - 1;
if (k1 < 0) {
k1 = 0;
} else if (k1 > 1) {
k1 = 1;
}
for (int l1 = -k1; l1 <= k1; ++l1) {
for (int i2 = -k1; i2 <= k1; ++i2) {
BlockPos blockpos = position.add(l1, -1, i2);
int j2 = 50;
if (Math.abs(l1) == 1 && Math.abs(i2) == 1) {
j2 = rand.nextInt(5);
}
while (blockpos.getY() > 50) {
IBlockState iblockstate1 = worldIn.getBlockState(blockpos);
Block block1 = iblockstate1.getBlock();
if (!iblockstate1.getBlock().isAir(iblockstate1, worldIn, blockpos) && block1 != Blocks.DIRT && block1 != Blocks.SNOW && block1 != Blocks.ICE && block1 != Blocks.PACKED_ICE) {
break;
}
this.setBlockAndNotifyAdequately(worldIn, blockpos, Blocks.PACKED_ICE.getDefaultState());
blockpos = blockpos.down();
--j2;
if (j2 <= 0) {
blockpos = blockpos.down(rand.nextInt(5) + 1);
j2 = rand.nextInt(5);
}
}
}
}
return true;
}
}