Java Code Examples for net.minecraft.util.MathHelper#clamp_double()

The following examples show how to use net.minecraft.util.MathHelper#clamp_double() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SlowlyStyle.java    From LiquidBounce with GNU General Public License v3.0 6 votes vote down vote up
public static float drawSlider(final float value, final float min, final float max, final int x, final int y, final int width, final int mouseX, final int mouseY, final Color color) {
    final float displayValue = Math.max(min, Math.min(value, max));

    final float sliderValue = (float) x + (float) width * (displayValue - min) / (max - min);

    RenderUtils.drawRect(x, y, x + width, y + 2, Integer.MAX_VALUE);
    RenderUtils.drawRect(x, y, sliderValue, y + 2, color);
    RenderUtils.drawFilledCircle((int) sliderValue, y + 1, 3, color);

    if (mouseX >= x && mouseX <= x + width && mouseY >= y && mouseY <= y + 3 && Mouse.isButtonDown(0)) {
        double i = MathHelper.clamp_double(((double) mouseX - (double) x) / ((double) width - 3), 0, 1);

        BigDecimal bigDecimal = new BigDecimal(Double.toString((min + (max - min) * i)));
        bigDecimal = bigDecimal.setScale(2, 4);
        return bigDecimal.floatValue();
    }

    return value;
}
 
Example 2
Source File: ThermiteTeleportationHandler.java    From Thermos with GNU General Public License v3.0 6 votes vote down vote up
public static void transferEntityToWorld(Entity ent, WorldServer oldWorld, WorldServer newWorld) {

		WorldProvider pOld = oldWorld.provider;
		WorldProvider pNew = newWorld.provider;
		double moveFactor = pOld.getMovementFactor() / pNew.getMovementFactor();
		double x = ent.posX * moveFactor;
		double z = ent.posZ * moveFactor;
		x = MathHelper.clamp_double(x, -29999872, 29999872);
		z = MathHelper.clamp_double(z, -29999872, 29999872);

		if (ent.isEntityAlive()) {
			ent.setLocationAndAngles(x, ent.posY, z, ent.rotationYaw, ent.rotationPitch);
			newWorld.spawnEntityInWorld(ent);
			newWorld.updateEntityWithOptionalForce(ent, false);
		}

		ent.setWorld(newWorld);
	}
 
Example 3
Source File: MixinGuiNewChat.java    From LiquidBounce with GNU General Public License v3.0 4 votes vote down vote up
@Inject(method = "drawChat", at = @At("HEAD"), cancellable = true)
private void drawChat(int p_drawChat_1_, final CallbackInfo callbackInfo) {
    final HUD hud = (HUD) LiquidBounce.moduleManager.getModule(HUD.class);

    if(hud.getState() && hud.fontChatValue.get()) {
        callbackInfo.cancel();
        if(this.mc.gameSettings.chatVisibility != EntityPlayer.EnumChatVisibility.HIDDEN) {
            int lvt_2_1_ = this.getLineCount();
            boolean lvt_3_1_ = false;
            int lvt_4_1_ = 0;
            int lvt_5_1_ = this.drawnChatLines.size();
            float lvt_6_1_ = this.mc.gameSettings.chatOpacity * 0.9F + 0.1F;
            if(lvt_5_1_ > 0) {
                if(this.getChatOpen()) {
                    lvt_3_1_ = true;
                }

                float lvt_7_1_ = this.getChatScale();
                int lvt_8_1_ = MathHelper.ceiling_float_int((float) this.getChatWidth() / lvt_7_1_);
                GlStateManager.pushMatrix();
                GlStateManager.translate(2.0F, 20.0F, 0.0F);
                GlStateManager.scale(lvt_7_1_, lvt_7_1_, 1.0F);

                int lvt_9_1_;
                int lvt_11_1_;
                int lvt_14_1_;
                for(lvt_9_1_ = 0; lvt_9_1_ + this.scrollPos < this.drawnChatLines.size() && lvt_9_1_ < lvt_2_1_; ++lvt_9_1_) {
                    ChatLine lvt_10_1_ = (ChatLine) this.drawnChatLines.get(lvt_9_1_ + this.scrollPos);
                    if(lvt_10_1_ != null) {
                        lvt_11_1_ = p_drawChat_1_ - lvt_10_1_.getUpdatedCounter();
                        if(lvt_11_1_ < 200 || lvt_3_1_) {
                            double lvt_12_1_ = (double) lvt_11_1_ / 200.0D;
                            lvt_12_1_ = 1.0D - lvt_12_1_;
                            lvt_12_1_ *= 10.0D;
                            lvt_12_1_ = MathHelper.clamp_double(lvt_12_1_, 0.0D, 1.0D);
                            lvt_12_1_ *= lvt_12_1_;
                            lvt_14_1_ = (int) (255.0D * lvt_12_1_);
                            if(lvt_3_1_) {
                                lvt_14_1_ = 255;
                            }

                            lvt_14_1_ = (int) ((float) lvt_14_1_ * lvt_6_1_);
                            ++lvt_4_1_;
                            if(lvt_14_1_ > 3) {
                                int lvt_15_1_ = 0;
                                int lvt_16_1_ = -lvt_9_1_ * 9;
                                Gui.drawRect(lvt_15_1_, lvt_16_1_ - 9, lvt_15_1_ + lvt_8_1_ + 4, lvt_16_1_, lvt_14_1_ / 2 << 24);
                                String lvt_17_1_ = lvt_10_1_.getChatComponent().getFormattedText();
                                Fonts.font40.drawStringWithShadow(lvt_17_1_, (float) lvt_15_1_ + 2, (float) (lvt_16_1_ - 8), 16777215 + (lvt_14_1_ << 24));
                                GL11.glColor4f(1, 1, 1, 1);
                                GlStateManager.resetColor();
                            }
                        }
                    }
                }

                if(lvt_3_1_) {
                    lvt_9_1_ = Fonts.font40.FONT_HEIGHT;
                    GlStateManager.translate(-3.0F, 0.0F, 0.0F);
                    int lvt_10_2_ = lvt_5_1_ * lvt_9_1_ + lvt_5_1_;
                    lvt_11_1_ = lvt_4_1_ * lvt_9_1_ + lvt_4_1_;
                    int lvt_12_2_ = this.scrollPos * lvt_11_1_ / lvt_5_1_;
                    int lvt_13_1_ = lvt_11_1_ * lvt_11_1_ / lvt_10_2_;
                    if(lvt_10_2_ != lvt_11_1_) {
                        lvt_14_1_ = lvt_12_2_ > 0 ? 170 : 96;
                        int lvt_15_2_ = this.isScrolled ? 13382451 : 3355562;
                        Gui.drawRect(0, -lvt_12_2_, 2, -lvt_12_2_ - lvt_13_1_, lvt_15_2_ + (lvt_14_1_ << 24));
                        Gui.drawRect(2, -lvt_12_2_, 1, -lvt_12_2_ - lvt_13_1_, 13421772 + (lvt_14_1_ << 24));
                    }
                }

                GlStateManager.popMatrix();
            }
        }
    }
}
 
Example 4
Source File: MixinGuiNewChat.java    From LiquidBounce with GNU General Public License v3.0 4 votes vote down vote up
@Inject(method = "drawChat", at = @At("HEAD"), cancellable = true)
private void drawChat(int p_drawChat_1_, final CallbackInfo callbackInfo) {
    final HUD hud = (HUD) LiquidBounce.moduleManager.getModule(HUD.class);

    if(hud.getState() && hud.fontChatValue.get()) {
        callbackInfo.cancel();
        if(this.mc.gameSettings.chatVisibility != EntityPlayer.EnumChatVisibility.HIDDEN) {
            int lvt_2_1_ = this.getLineCount();
            boolean lvt_3_1_ = false;
            int lvt_4_1_ = 0;
            int lvt_5_1_ = this.drawnChatLines.size();
            float lvt_6_1_ = this.mc.gameSettings.chatOpacity * 0.9F + 0.1F;
            if(lvt_5_1_ > 0) {
                if(this.getChatOpen()) {
                    lvt_3_1_ = true;
                }

                float lvt_7_1_ = this.getChatScale();
                int lvt_8_1_ = MathHelper.ceiling_float_int((float) this.getChatWidth() / lvt_7_1_);
                GlStateManager.pushMatrix();
                GlStateManager.translate(2.0F, 20.0F, 0.0F);
                GlStateManager.scale(lvt_7_1_, lvt_7_1_, 1.0F);

                int lvt_9_1_;
                int lvt_11_1_;
                int lvt_14_1_;
                for(lvt_9_1_ = 0; lvt_9_1_ + this.scrollPos < this.drawnChatLines.size() && lvt_9_1_ < lvt_2_1_; ++lvt_9_1_) {
                    ChatLine lvt_10_1_ = (ChatLine) this.drawnChatLines.get(lvt_9_1_ + this.scrollPos);
                    if(lvt_10_1_ != null) {
                        lvt_11_1_ = p_drawChat_1_ - lvt_10_1_.getUpdatedCounter();
                        if(lvt_11_1_ < 200 || lvt_3_1_) {
                            double lvt_12_1_ = (double) lvt_11_1_ / 200.0D;
                            lvt_12_1_ = 1.0D - lvt_12_1_;
                            lvt_12_1_ *= 10.0D;
                            lvt_12_1_ = MathHelper.clamp_double(lvt_12_1_, 0.0D, 1.0D);
                            lvt_12_1_ *= lvt_12_1_;
                            lvt_14_1_ = (int) (255.0D * lvt_12_1_);
                            if(lvt_3_1_) {
                                lvt_14_1_ = 255;
                            }

                            lvt_14_1_ = (int) ((float) lvt_14_1_ * lvt_6_1_);
                            ++lvt_4_1_;
                            if(lvt_14_1_ > 3) {
                                int lvt_15_1_ = 0;
                                int lvt_16_1_ = -lvt_9_1_ * 9;
                                Gui.drawRect(lvt_15_1_, lvt_16_1_ - 9, lvt_15_1_ + lvt_8_1_ + 4, lvt_16_1_, lvt_14_1_ / 2 << 24);
                                String lvt_17_1_ = lvt_10_1_.getChatComponent().getFormattedText();
                                Fonts.font40.drawStringWithShadow(lvt_17_1_, (float) lvt_15_1_ + 2, (float) (lvt_16_1_ - 8), 16777215 + (lvt_14_1_ << 24));
                                GL11.glColor4f(1, 1, 1, 1);
                                GlStateManager.resetColor();
                            }
                        }
                    }
                }

                if(lvt_3_1_) {
                    lvt_9_1_ = Fonts.font40.FONT_HEIGHT;
                    GlStateManager.translate(-3.0F, 0.0F, 0.0F);
                    int lvt_10_2_ = lvt_5_1_ * lvt_9_1_ + lvt_5_1_;
                    lvt_11_1_ = lvt_4_1_ * lvt_9_1_ + lvt_4_1_;
                    int lvt_12_2_ = this.scrollPos * lvt_11_1_ / lvt_5_1_;
                    int lvt_13_1_ = lvt_11_1_ * lvt_11_1_ / lvt_10_2_;
                    if(lvt_10_2_ != lvt_11_1_) {
                        lvt_14_1_ = lvt_12_2_ > 0 ? 170 : 96;
                        int lvt_15_2_ = this.isScrolled ? 13382451 : 3355562;
                        Gui.drawRect(0, -lvt_12_2_, 2, -lvt_12_2_ - lvt_13_1_, lvt_15_2_ + (lvt_14_1_ << 24));
                        Gui.drawRect(2, -lvt_12_2_, 1, -lvt_12_2_ - lvt_13_1_, 13421772 + (lvt_14_1_ << 24));
                    }
                }

                GlStateManager.popMatrix();
            }
        }
    }
}
 
Example 5
Source File: HyperiumGuiNewChat.java    From Hyperium with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void drawChat(int updateCounter, List<ChatLine> drawnChatLines, int scrollPos, boolean isScrolled, Minecraft mc) {
    if (mc.gameSettings.chatVisibility != EntityPlayer.EnumChatVisibility.HIDDEN) {
        int i = parent.getLineCount();
        boolean flag = false;
        int j = 0;
        int k = drawnChatLines.size();
        float f = mc.gameSettings.chatOpacity * 0.9F + 0.1F;

        if (k > 0) {
            if (parent.getChatOpen()) flag = true;

            float f1 = parent.getChatScale();
            int l = MathHelper.ceiling_float_int((float) parent.getChatWidth() / f1);
            GlStateManager.pushMatrix();
            GlStateManager.translate(2.0F, 20.0F, 0.0F);
            GlStateManager.scale(f1, f1, 1.0F);

            for (int i1 = 0; i1 + scrollPos < drawnChatLines.size() && i1 < i; ++i1) {
                ChatLine chatline = drawnChatLines.get(i1 + scrollPos);

                if (chatline != null) {
                    int j1 = updateCounter - chatline.getUpdatedCounter();

                    if (j1 < 200 || flag) {
                        double d0 = (double) j1 / 200.0D;
                        d0 = 1.0D - d0;
                        d0 = d0 * 10.0D;
                        d0 = MathHelper.clamp_double(d0, 0.0D, 1.0D);
                        d0 = d0 * d0;
                        int l1 = (int) (255.0D * d0);

                        if (flag) l1 = 255;

                        l1 = (int) ((float) l1 * f);
                        ++j;

                        if (l1 > 3) {
                            int i2 = 0;
                            int j2 = -i1 * 9;
                            if (!Settings.FASTCHAT)
                                Gui.drawRect(i2, j2 - 9, i2 + l + 4, j2, l1 / 2 << 24);
                            String s = chatline.getChatComponent().getFormattedText();
                            GlStateManager.enableBlend();
                            mc.fontRendererObj.drawStringWithShadow(s, (float) i2, (float) (j2 - 8), 16777215 + (l1 << 24));
                            GlStateManager.disableAlpha();
                            GlStateManager.disableBlend();
                        }
                    }
                }
            }

            if (flag) {
                int k2 = mc.fontRendererObj.FONT_HEIGHT;
                GlStateManager.translate(-3.0F, 0.0F, 0.0F);
                int l2 = k * k2 + k;
                int i3 = j * k2 + j;
                int j3 = scrollPos * i3 / k;
                int k1 = i3 * i3 / l2;

                if (l2 != i3) {
                    int k3 = j3 > 0 ? 170 : 96;
                    int l3 = isScrolled ? 13382451 : 3355562;
                    Gui.drawRect(0, -j3, 2, -j3 - k1, l3 + (k3 << 24));
                    Gui.drawRect(2, -j3, 1, -j3 - k1, 13421772 + (k3 << 24));
                }
            }

            GlStateManager.popMatrix();
        }
    }
}
 
Example 6
Source File: EntityHamster.java    From Hyperium with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void moveEntityWithHeading(float strafe, float forward) {
    if (!isInWater()) {
        if (!isInLava()) {
            float f4 = 0.91F;

            if (onGround) {
                f4 = worldObj.getBlockState(new BlockPos(MathHelper.floor_double(posX), MathHelper.floor_double(getEntityBoundingBox().minY) - 1,
                    MathHelper.floor_double(posZ))).getBlock().slipperiness * 0.91F;
            }

            float f = 0.16277136F / (f4 * f4 * f4);
            float f5 = onGround ? getAIMoveSpeed() * f : jumpMovementFactor;
            moveFlying(strafe, forward, f5);
            f4 = 0.91F;

            if (onGround) {
                f4 = worldObj.getBlockState(new BlockPos(MathHelper.floor_double(posX), MathHelper.floor_double(getEntityBoundingBox().minY) - 1,
                    MathHelper.floor_double(posZ))).getBlock().slipperiness * 0.91F;
            }

            if (isOnLadder()) {
                float f6 = 0.15F;
                motionX = MathHelper.clamp_double(motionX, -f6, f6);
                motionZ = MathHelper.clamp_double(motionZ, -f6, f6);
                fallDistance = 0.0F;
                if (motionY < -0.15D) motionY = -0.15D;
            }

            moveEntity(motionX, motionY, motionZ);

            if (isCollidedHorizontally && isOnLadder()) motionY = 0.2D;

            if (worldObj.isRemote && (!worldObj.isBlockLoaded(new BlockPos((int) posX, 0, (int) posZ)) ||
                !worldObj.getChunkFromBlockCoords(new BlockPos((int) posX, 0, (int) posZ)).isLoaded())) {
                motionY = posY > 0.0D ? -0.1D : 0.0D;
            } else {
                motionY -= 0.08D;
            }

            motionY *= 0.9800000190734863D;
            motionX *= f4;
            motionZ *= f4;
        } else {
            double d1 = posY;
            moveFlying(strafe, forward, 0.02F);
            moveEntity(motionX, motionY, motionZ);
            motionX *= 0.5D;
            motionY *= 0.5D;
            motionZ *= 0.5D;
            motionY -= 0.02D;

            if (isCollidedHorizontally && isOffsetPositionInLiquid(motionX, motionY + 0.6000000238418579D - posY + d1, motionZ)) {
                motionY = 0.30000001192092896D;
            }
        }
    } else {
        double d0 = posY;
        float f1 = 0.8F;
        float f2 = 0.02F;
        float f3 = (float) EnchantmentHelper.getDepthStriderModifier(this);
        if (f3 > 3.0F) f3 = 3.0F;
        if (!onGround) f3 *= 0.5F;

        if (f3 > 0.0F) {
            f1 += (0.54600006F - f1) * f3 / 3.0F;
            f2 += (getAIMoveSpeed() * 1.0F - f2) * f3 / 3.0F;
        }

        moveFlying(strafe, forward, f2);
        moveEntity(motionX, motionY, motionZ);
        motionX *= f1;
        motionY *= 0.800000011920929D;
        motionZ *= f1;
        motionY -= 0.02D;

        if (isCollidedHorizontally && isOffsetPositionInLiquid(motionX, motionY + 0.6000000238418579D - posY + d0, motionZ)) {
            motionY = 0.30000001192092896D;
        }
    }

    super.moveEntityWithHeading(strafe, forward);
}