Начинающий
- Статус
- Оффлайн
- Регистрация
- 17 Мар 2025
- Сообщения
- 35
- Реакции
- 0
- Выберите загрузчик игры
- Fabric
Недавно наколякал таргет худ типо как в нурсултане
ss прикреплен
анимка хп имеется
КОД
↓
ss прикреплен
анимка хп имеется
КОД
↓
TargetHud:
package fun.roclub.display.hud;
import com.nimbusds.jose.crypto.impl.MACProvider;
import fun.roclub.utils.interactions.interact.PlayerInteractionHelper;
import fun.roclub.utils.math.time.StopWatch;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.render.entity.EntityRenderer;
import net.minecraft.client.render.entity.LivingEntityRenderer;
import net.minecraft.client.render.entity.state.LivingEntityRenderState;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.LivingEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.MathHelper;
import fun.roclub.utils.client.managers.api.draggable.AbstractDraggable;
import fun.roclub.features.impl.combat.Aura;
import fun.roclub.features.impl.render.Hud;
import fun.roclub.common.animation.Animation;
import fun.roclub.common.animation.Direction;
import fun.roclub.common.animation.implement.Decelerate;
import fun.roclub.utils.display.font.FontRenderer;
import fun.roclub.utils.display.font.Fonts;
import fun.roclub.utils.display.shape.ShapeProperties;
import fun.roclub.Roclub;
import fun.roclub.utils.display.color.ColorAssist;
import fun.roclub.utils.interactions.item.ItemTask;
import fun.roclub.utils.math.calc.Calculate;
import fun.roclub.utils.display.geometry.Render2D;
import fun.roclub.utils.display.scissor.ScissorAssist;
import fun.roclub.utils.client.packet.network.Network;
import java.awt.*;
public class TargetHud extends AbstractDraggable {
private final Animation animation = new Decelerate().setMs(650).setValue(1);
private final Animation faceAlphaAnimation = new Decelerate().setMs(125).setValue(1);
private final StopWatch stopWatch = new StopWatch();
private final StopWatch distanceUpdateTimer = new StopWatch();
private LivingEntity lastTarget;
private Item lastItem = Items.AIR;
private float health;
private float animatedHealthPercent;
private float absorption;
private float displayedDistance;
public TargetHud() {
super("Target Hud", 10, 80, 100, 36, true);
}
@Override
public boolean visible() {
return scaleAnimation.isDirection(Direction.FORWARDS);
}
@Override
public void tick() {
LivingEntity auraTarget = Aura.getInstance().getTarget();
if (auraTarget != null) {
lastTarget = auraTarget;
startAnimation();
faceAlphaAnimation.setDirection(Direction.FORWARDS);
} else if (PlayerInteractionHelper.isChat(mc.currentScreen)) {
lastTarget = mc.player;
startAnimation();
faceAlphaAnimation.setDirection(Direction.FORWARDS);
} else if (stopWatch.finished(500)) {
stopAnimation();
faceAlphaAnimation.setDirection(Direction.BACKWARDS);
}
}
@Override
public void drawDraggable(DrawContext context) {
if (Hud.getInstance().interfaceSettings.isSelected("Target Hud") && Hud.getInstance().state) {
if (lastTarget != null) {
MatrixStack matrix = context.getMatrices();
drawMain(context, matrix);
drawFace(context);
}
}
}
private void drawMain(DrawContext context, MatrixStack matrix) {
float posX = getX();
float posY = getY();
float oldWidth = getWidth();
float width = 165f / 1.5f;
float height = 60f / 1.5f;
float headSize = height - 6f;
float spacing = 5f;
float diff = width - oldWidth;
if (diff != 0) {
setX((int) (getX() - diff / 2f));
}
setWidth((int) width);
setHeight((int) height);
float animationValue = animation.getOutput().floatValue();
float alphaAnimationValue = animationValue;
int alpha = (int) (255 * alphaAnimationValue);
float targetHp = PlayerInteractionHelper.getHealth(lastTarget);
float maxHp = Math.max(lastTarget.getMaxHealth(), 1.0f);
if (health <= 0 || targetHp <= 0 || Math.abs(health - targetHp) < 0.05f) {
health = targetHp;
} else {
float factor = targetHp < health ? 0.15f : 0.07f;
health = MathHelper.lerp(factor, health, targetHp);
}
float healthPercent = MathHelper.clamp(health / maxHp, 0.0f, 1.0f);
if (animatedHealthPercent < 0.0f || animatedHealthPercent > 1.0f || Math.abs(animatedHealthPercent - healthPercent) < 0.001f) {
animatedHealthPercent = healthPercent;
} else {
float barFactor = healthPercent < animatedHealthPercent ? 0.12f : 0.06f;
animatedHealthPercent = MathHelper.lerp(barFactor, animatedHealthPercent, healthPercent);
}
String name = lastTarget.getName().getString();
String healthText = (lastTarget.isInvisible() && !Network.isSpookyTime() && !Network.isCopyTime())
? "HP: Неизвестно"
: String.format("HP: %.1f", health).replace(',', '.');
FontRenderer nameFont = Fonts.getSize(17, Fonts.Type.REGULAR);
FontRenderer hpFont = Fonts.getSize(15, Fonts.Type.REGULAR);
int themeColorInt = ColorAssist.getClientColor();
Color theme = new Color(themeColorInt);
blur.render(ShapeProperties.create(matrix, posX, posY, width, height)
.round(5f)
.quality(24)
.color(new Color(0, 0, 0, 180).getRGB())
.build());
rectangle.render(ShapeProperties.create(matrix, posX, posY, width, height)
.round(5f)
.color(new Color(0, 0, 0, 40).getRGB())
.build());
float headCenterX = posX + 4 + headSize / 2f;
float headCenterY = posY + height / 2f;
float lineX = posX + headSize + spacing * 1.5f;
float halfAnimationValueRest = (1 - animationValue) / 2f;
float testX = lineX + (width * halfAnimationValueRest);
float testY = (posY - 0.5f) + (height * halfAnimationValueRest);
float testW = width * animationValue;
float testH = nameFont.getStringHeight(name) * animationValue;
ScissorAssist scissorManager = Rich.getInstance().getScissorManager();
scissorManager.push(matrix.peek().getPositionMatrix(),
testX, testY + 6f,
testW - 50f, testH + 2f);
nameFont.drawString(matrix, name,
lineX, (posY - 0.5f) + spacing + 3f,
ColorAssist.setAlpha(new Color(255, 255, 255, 255).getRGB(), alpha));
scissorManager.pop();
float healthY = posY + height - spacing - 16f;
hpFont.drawString(matrix, healthText,
lineX, healthY,
ColorAssist.setAlpha(ColorAssist.getText(), alpha));
float barWidth = width - (headSize + spacing * 2f);
float barY = posY + height - spacing * 2f - 2.5f;
rectangle.render(ShapeProperties.create(matrix, lineX - 1f, barY, barWidth, 8f)
.round(2f)
.color(new Color(35, 35, 35, alpha).getRGB())
.build());
float hpWidth = barWidth * animatedHealthPercent;
int hpAlpha = (int) (220 * alphaAnimationValue);
int darkerTheme = ColorAssist.multDark(themeColorInt, 0.5f);
int brighterTheme = ColorAssist.multBright(themeColorInt, 1.5f);
int baseLeft = ColorAssist.interpolateColor(darkerTheme, ColorAssist.red, 0.3f);
int baseRight = brighterTheme;
int hpLeft = ColorAssist.setAlpha(baseLeft, hpAlpha);
int hpRight = ColorAssist.setAlpha(baseRight, hpAlpha);
rectangle.render(ShapeProperties.create(matrix, lineX - 1f, barY, hpWidth, 7.5f)
.round(2f)
.color(
hpLeft,
hpRight,
hpRight,
hpLeft
)
.build());
}
private void drawArmor(DrawContext context, MatrixStack matrix) {
ItemStack[] slots = new ItemStack[] {
lastTarget.getMainHandStack(),
lastTarget.getOffHandStack(),
lastTarget.getEquippedStack(net.minecraft.entity.EquipmentSlot.HEAD),
lastTarget.getEquippedStack(net.minecraft.entity.EquipmentSlot.CHEST),
lastTarget.getEquippedStack(net.minecraft.entity.EquipmentSlot.LEGS),
lastTarget.getEquippedStack(net.minecraft.entity.EquipmentSlot.FEET)
};
float x = getX() + 21f;
float y = getY() + 17;
float slotSize = 16 * 0.5F + 2;
matrix.push();
matrix.translate(x, y, 0);
for (int i = 0; i < 6; i++) {
float currentX = i * 11.5f;
blur.render(ShapeProperties.create(matrix, currentX - 0.5f, 15F, slotSize + 1, slotSize + 1)
.round(3).quality(12)
.color(new Color(0, 0, 0, 150).getRGB())
.build());
rectangle.render(ShapeProperties.create(matrix, currentX - 0.5f, 15F, slotSize + 1, slotSize + 1)
.round(3)
.thickness(0.1f)
.outlineColor(new Color(33, 33, 33, 255).getRGB())
.color(
new Color(18, 19, 20, 75).getRGB(),
new Color(0, 2, 5, 75).getRGB(),
new Color(0, 2, 5, 75).getRGB(),
new Color(18, 19, 20, 75).getRGB())
.build());
if (!slots[i].isEmpty()) {
Render2D.defaultDrawStack(context, slots[i], currentX, 15.5F, false, false, 0.5F);
} else {
String xText = "x";
FontRenderer font = Fonts.getSize(12, Fonts.Type.DEFAULT);
float textWidth = font.getStringWidth(xText);
float textHeight = font.getStringHeight(xText);
float textX = currentX + (slotSize - textWidth) / 2.0F;
float textY = 15.5F + (slotSize - textHeight) / 2.0F;
font.drawString(matrix, xText, textX, textY + 6.25f, new Color(225, 225, 255, 255).getRGB());
}
}
matrix.pop();
}
private void drawUsingItem(DrawContext context, MatrixStack matrix) {
animation.setDirection(lastTarget.isUsingItem() ? Direction.FORWARDS : Direction.BACKWARDS);
if (!lastTarget.getActiveItem().isEmpty() && lastTarget.getActiveItem().getCount() != 0) {
lastItem = lastTarget.getActiveItem().getItem();
}
if (!animation.isFinished(Direction.BACKWARDS) && !lastItem.equals(Items.AIR)) {
int size = 24;
float anim = animation.getOutput().floatValue();
float progress = (lastTarget.getItemUseTime() + tickCounter.getTickDelta(false)) / ItemTask.maxUseTick(lastItem) * 360;
float x = getX() - (size + 5) * anim;
float y = getY() + 4;
ScissorAssist scissorManager = Rich.getInstance().getScissorManager();
scissorManager.push(matrix.peek().getPositionMatrix(), getX() - 50, getY(), 50, getHeight());
Calculate.setAlpha(anim, () -> {
blur.render(ShapeProperties.create(matrix, x, y, size, size).quality(5)
.round(12).softness(1).thickness(2).outlineColor(ColorAssist.getOutline(0)).color(ColorAssist.getRect(0.7F)).build());
arc.render(ShapeProperties.create(matrix, x, y, size, size).round(0.38F).thickness(0.30f).end(progress)
.color(ColorAssist.fade(0), ColorAssist.fade(200), ColorAssist.fade(0), ColorAssist.fade(200)).build());
Render2D.defaultDrawStack(context, lastItem.getDefaultStack(), x + 3f, y + 3f, false, false, 1f);
});
scissorManager.pop();
}
}
private void drawFace(DrawContext context) {
EntityRenderer<? super LivingEntity, ?> baseRenderer = mc.getEntityRenderDispatcher().getRenderer(lastTarget);
if (!(baseRenderer instanceof LivingEntityRenderer<?, ?, ?>)) {
return;
}
@SuppressWarnings("unchecked")
LivingEntityRenderer<LivingEntity, LivingEntityRenderState, ?> renderer = (LivingEntityRenderer<LivingEntity, LivingEntityRenderState, ?>) baseRenderer;
LivingEntityRenderState state = renderer.getAndUpdateRenderState(lastTarget, tickCounter.getTickDelta(false));
Identifier textureLocation = renderer.getTexture(state);
float alpha = faceAlphaAnimation.getOutput().floatValue();
Calculate.setAlpha(alpha, () -> {
float size = getHeight() - 6f;
float x = getX() + 4f;
float y = getY() + (getHeight() - size) / 2f;
Render2D.drawTexture(context, textureLocation, x, y, size, 4f, 8, 8, 64,
ColorAssist.getRect(1),
ColorAssist.multRed(-1, 1 + lastTarget.hurtTime / 4F));
});
}
}