yes the code with the animation was ctrl + v from the lb code:axocooler: :axocooler:
the design was also copied from flux
im bad at opengl
Changelog:
[25-02-2021]:
Optimized code
Removed unnecessary code
Slightly redesigned color and changed code
[26-02-2021]:
Some code has been reworked
Now if the target has no armor, the armor line will not be rendered
The size of TargetHud depends on the width of the target name
How it looks:
2021-02-25_13.30.09.png
Code:
var RenderUtils = Java.type('net.ccbluex.liquidbounce.utils.render.RenderUtils');
var ScaledResolution = Java.type('net.minecraft.client.gui.ScaledResolution');
var EntityPlayer = Java.type('net.minecraft.entity.player.EntityPlayer');
var Gui = Java.type('net.minecraft.client.gui.Gui');
var GL11 = Java.type('org.lwjgl.opengl.GL11');
var Color = Java.type('java.awt.Color');
var Fonts = Java.type('net.ccbluex.liquidbounce.ui.font.Fonts');
var fonts = Fonts.getFonts();
var font = undefined;
var easingHealth = 0;
function drawHead(skin, width, height) {
GL11.glColor4f(1, 1, 1, 1);
mc.getTextureManager().bindTexture(skin);
Gui.drawScaledCustomSizeModalRect(width, height, 8, 8, 8, 8, 16, 16, 64, 64);
}
function drawRect(paramXStart, paramYStart, paramXEnd, paramYEnd, color) {
var alpha = (color >> 24 & 0xFF) / 255;
var red = (color >> 16 & 0xFF) / 255;
var green = (color >> 8 & 0xFF) / 255;
var blue = (color & 0xFF) / 255;
GL11.glEnable(GL11.GL_BLEND);
GL11.glDisable(GL11.GL_TEXTURE_2D);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glEnable(GL11.GL_LINE_SMOOTH);
GL11.glPushMatrix();
GL11.glColor4f(red, green, blue, alpha);
GL11.glBegin(GL11.GL_TRIANGLE_FAN);
GL11.glVertex2d(paramXEnd, paramYStart);
GL11.glVertex2d(paramXStart, paramYStart);
GL11.glVertex2d(paramXStart, paramYEnd);
GL11.glVertex2d(paramXEnd, paramYEnd);
GL11.glEnd();
GL11.glPopMatrix();
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glDisable(GL11.GL_BLEND);
GL11.glDisable(GL11.GL_LINE_SMOOTH);
GL11.glColor4f(1, 1, 1, 1);
}
function getScaledWidth() {
var scaledWidth = new ScaledResolution(mc).getScaledWidth();
return scaledWidth;
}
function getScaledHeight() {
var scaledHeight = new ScaledResolution(mc).getScaledHeight();
return scaledHeight;
}
var script = registerScript({
name: 'TargetInfo',
version: '0.0.3',
authors: ['Shurpe']
});
script.registerModule({
name: 'TargetInfo',
description: '',
category: 'Fun',
settings: {
fadeTime: Setting.integer({
name: 'FadeTime',
default: 25,
min: 10,
max: 50
}),
fadeDist: Setting.integer({
name: 'FadeDistance',
default: 3,
min: 3,
max: 10
}),
fontIndex: Setting.integer({
name: 'Font',
default: 0,
min: 0,
max: fonts.length - 1
})
}
}, function (module) {
module.on('render2D', function () {
if (target != null) {
GL11.glPushMatrix();
GL11.glTranslated(mcWidth / 2 + 10, mcHeight / 2, mcWidth / 2 + 10); // Pos
drawRect(-2, 34, 2 + width, target.getTotalArmorValue() != 0 ? 66 : 60, new Color(35, 35, 40, 230).getRGB()); // Draw background
font.drawString(target.getName(), 20, 40, 0xFFFFFF); // Draw target name
drawHead(mc.getNetHandler().getPlayerInfo(target.getUniqueID()).getLocationSkin(), 0, 36); // Draw target head
drawRect(0, 56, width, 58, new Color(25, 25, 35, 255).getRGB()); // Draw health bar background
easingHealth += ((target.getHealth() - easingHealth) / Math.pow(2, 10.0 - 3)) * RenderUtils.deltaTime;
if (easingHealth < 0 || easingHealth > target.getMaxHealth()) {
easingHealth = target.getHealth();
}
if (easingHealth > target.getHealth()) {
drawRect(0, 56, (easingHealth / target.getMaxHealth()) * width, 58, new Color(231, 182, 0, 255).getRGB());
} // Damage animation
if (easingHealth < target.getHealth()) {
drawRect((easingHealth / target.getMaxHealth()) * width, 56, (easingHealth / target.getMaxHealth()) * width, 58, new Color(231, 182, 0, 255).getRGB());
} // Heal animation
drawRect(0, 56, (target.getHealth() / target.getMaxHealth()) * width, 58, new Color(0, 224, 84, 255).getRGB()); // Draw health bar
if (target.getTotalArmorValue() != 0) {
drawRect(0, 62, width, 64, new Color(25, 25, 35, 255).getRGB()); // Draw armor bar background
drawRect(0, 62, (target.getTotalArmorValue() / 20) * width, 64, new Color(77, 128, 255, 255).getRGB()); // Draw armor bar
}
GL11.glPopMatrix();
}
});
module.on('update', function () {
if (target != null) {
if (target.getHealth() > 1024 || isNaN(target.getHealth()) || target.getHealth() <= 0 || fadeTimer >= module.settings.fadeTime.get() || mc.thePlayer.getDistanceToEntity(target).toFixed() >= module.settings.fadeDist.get()) {
target = null;
} else {
fadeTimer++;
mcWidth = getScaledWidth(); mcHeight = getScaledHeight();
font = fonts[module.settings.fontIndex.get()];
width = 20 + font.getStringWidth(target.getName());
}
} else {
fadeTimer = null;
}
});
module.on('attack', function(e) {
if (e.getTargetEntity() instanceof EntityPlayer) {
target = e.getTargetEntity(); fadeTimer = 0;
}
});
module.on('disable', function() {
target = undefined;
fadeTimer = null;
});
});