- Статус
- Оффлайн
- Регистрация
- 11 Июл 2024
- Сообщения
- 256
- Реакции
- 3
- Выберите загрузчик игры
- Fabric
Привет.Сливаю самый обычный таргет худ для зенит клиента
Фото ниже
А вот и сам код
Фото ниже
А вот и сам код
Зенит:
package zenith.zov.client.hud.elements.component;
import net.minecraft.client.gui.screen.ChatScreen;
import net.minecraft.client.network.AbstractClientPlayerEntity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.scoreboard.ScoreboardDisplaySlot;
import net.minecraft.scoreboard.ScoreboardObjective;
import net.minecraft.scoreboard.ReadableScoreboardScore;
import net.minecraft.scoreboard.Scoreboard;
import zenith.zov.Zenith;
import zenith.zov.base.animations.base.Animation;
import zenith.zov.base.animations.base.Easing;
import zenith.zov.base.font.Font;
import zenith.zov.base.font.Fonts;
import zenith.zov.base.theme.Theme;
import zenith.zov.client.hud.elements.draggable.DraggableHudElement;
import zenith.zov.client.modules.impl.combat.Aura;
import zenith.zov.utility.render.display.base.BorderRadius;
import zenith.zov.utility.render.display.base.CustomDrawContext;
import zenith.zov.utility.render.display.base.color.ColorRGBA;
import zenith.zov.utility.render.display.shader.DrawUtil;
import static java.lang.Math.round;
public class TargetHudComponent extends DraggableHudElement {
private final Animation healthAnimation = new Animation(300, Easing.LINEAR);
private final Animation toggleAnimation = new Animation(300, 0, Easing.CUBIC_OUT);
private LivingEntity target;
public TargetHudComponent(String name, float initialX, float initialY, float windowWidth, float windowHeight, float offsetX, float offsetY, Align align) {
super(name, initialX, initialY, windowWidth, windowHeight, offsetX, offsetY, align);
}
@Override
public void render(CustomDrawContext ctx) {
this.width = 130f;
this.height = 40f;
Aura aura = Aura.INSTANCE;
LivingEntity target = (mc.currentScreen instanceof ChatScreen) ? mc.player : aura.getTarget();
setTarget(target);
if (toggleAnimation.getValue() == 0 || this.target == null) return;
renderTargetHud(ctx, this.target, (float) toggleAnimation.getValue());
}
private float getScoreboardHealth(LivingEntity entity) {
if (!(entity instanceof PlayerEntity player)) {
return entity.getHealth();
}
try {
Scoreboard scoreboard = player.getScoreboard();
if (scoreboard == null) return entity.getHealth();
ScoreboardObjective objective = scoreboard.getObjectiveForSlot(ScoreboardDisplaySlot.LIST);
if (objective == null) return entity.getHealth();
ReadableScoreboardScore score = scoreboard.getScore(player, objective);
if (score == null) return entity.getHealth();
int scorePoints = score.getScore();
if (scorePoints > 0 && scorePoints <= player.getMaxHealth()) {
return (float) scorePoints;
}
} catch (Exception e) {
}
return entity.getHealth();
}
private void renderTargetHud(CustomDrawContext ctx, LivingEntity target, float animation) {
float posX = x, posY = y;
float width = 130f;
float height = 36f;
float headSize = 22f;
float padding = 5f;
float barHeight = 2.5f;
Theme theme = Zenith.getInstance().getThemeManager().getCurrentTheme();
ctx.pushMatrix();
{
float scale = animation;
ctx.getMatrices().translate(posX + width / 2, posY + height / 2, 0);
ctx.getMatrices().scale(scale, scale, 1);
ctx.getMatrices().translate(-(posX + width / 2), -(posY + height / 2), 0);
ctx.getMatrices().translate(x, y, 0f);
ctx.getMatrices().scale(0.8f, 0.8f, 1f);
ctx.getMatrices().translate(-x, -y, 0f);
BorderRadius radius = BorderRadius.all(5f);
DrawUtil.drawBlurKawase(ctx.getMatrices(), posX, posY, width, height,
16, radius, new ColorRGBA(255, 255, 255, (int)(255 * animation)));
DrawUtil.drawRoundedRect(ctx.getMatrices(), posX, posY, width, height,
radius, new ColorRGBA(120, 120, 140, (int)(140 * animation)));
DrawUtil.drawRoundedRect(ctx.getMatrices(), posX, posY, width, height,
radius, new ColorRGBA(0, 0, 0, (int)(155 * animation)));
float headX = posX + padding;
float headY = posY + (height - headSize) / 2f;
if (target instanceof PlayerEntity player) {
DrawUtil.drawPlayerHeadWithRoundedShader(
ctx.getMatrices(),
((AbstractClientPlayerEntity) player).getSkinTextures().texture(),
headX + 1, headY - 3, headSize,
BorderRadius.all(0.5f), ColorRGBA.WHITE.withAlpha((int)(255 * animation))
);
} else {
Font iconFont = Fonts.ICONS.getFont(16);
ctx.drawText(iconFont, "M", headX + 1 + (headSize - iconFont.width("M")) / 2f,
headY - 4.5F + headSize / 2f - iconFont.height() / 2f, theme.getColor().withAlpha((int)(255 * animation)));
}
float textX = headX + headSize + padding + 1;
float textY = headY - 1;
Font nameFont = Fonts.MEDIUM.getFont(9f);
String name = target.getName().getString();
float maxNameWidth = width - (textX - posX) - padding;
String displayName = name;
if (nameFont.width(name) > maxNameWidth) {
while (nameFont.width(displayName + "...") > maxNameWidth && displayName.length() > 0) {
displayName = displayName.substring(0, displayName.length() - 1);
}
displayName += "...";
}
ctx.drawText(nameFont, displayName, textX, textY, theme.getWhite().withAlpha((int)(255 * animation)));
float hp = round(getScoreboardHealth(target));
Font hpFont = Fonts.MEDIUM.getFont(7.8f);
float hpTextY = textY + nameFont.height() + 3.5f;
String hpText = "HP: " + (int) hp;
ctx.drawText(hpFont, hpText, textX, hpTextY, theme.getColor().withAlpha((int)(255 * animation)));
float barX = posX + 1 + padding;
float barY = posY + height - padding - barHeight;
float barWidth = width - padding * 2;
float maxHp = target.getMaxHealth();
float healthPercent = Math.min(1.0f, hp / maxHp);
float animatedHealth = healthAnimation.update(barWidth * healthPercent);
ctx.drawRoundedRect(barX, barY, barWidth, barHeight, BorderRadius.all(0.5f),
new ColorRGBA(50, 50, 50, (int)(150 * animation)));
if (animatedHealth > 0) {
ctx.drawRoundedRect(barX, barY, animatedHealth, barHeight, BorderRadius.all(0.5f),
theme.getColor().withAlpha((int)(255 * animation)));
}
}
ctx.popMatrix();
this.width = width * 0.8f;
this.height = height * 0.8f;
}
public void setTarget(LivingEntity target) {
if (target == null) {
toggleAnimation.update(0);
if (toggleAnimation.getValue() == 0) {
this.target = null;
}
} else {
if (target != this.target) {
toggleAnimation.update(0);
if (toggleAnimation.getValue() == 0) {
this.target = target;
}
} else {
toggleAnimation.update(1);
}
}
}
}
