Начинающий
- Статус
- Оффлайн
- Регистрация
- 23 Май 2025
- Сообщения
- 3
- Реакции
- 0
- Выберите загрузчик игры
- Прочие моды
Всем ку написал таргетхуд болемение норм но можно доделать в лучшую сторону например перместить броню в конвейнер также цвет меняеться в зависимости от хп ну а так хз дерзайте
Пожалуйста, авторизуйтесь для просмотра ссылки.
Код:
package im.expensive.ui.display.impl;
import com.mojang.blaze3d.platform.GlStateManager;
import im.expensive.Expensive;
import im.expensive.events.EventDisplay;
import im.expensive.ui.display.ElementRenderer;
import im.expensive.ui.styles.Style;
import im.expensive.utils.animations.Animation;
import im.expensive.utils.animations.Direction;
import im.expensive.utils.animations.impl.EaseBackIn;
import im.expensive.utils.drag.Dragging;
import im.expensive.utils.math.MathUtil;
import im.expensive.utils.math.StopWatch;
import im.expensive.utils.render.ColorUtils;
import im.expensive.utils.render.DisplayUtils;
import im.expensive.utils.render.Scissor;
import im.expensive.utils.render.font.Fonts;
import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;
import lombok.experimental.FieldDefaults;
import net.minecraft.client.gui.AbstractGui;
import net.minecraft.client.gui.screen.ChatScreen;
import net.minecraft.client.renderer.entity.EntityRenderer;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.scoreboard.Score;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.MathHelper;
import org.lwjgl.opengl.GL11;
import java.util.ArrayList;
import java.util.List;
@FieldDefaults(level = AccessLevel.PRIVATE)
@RequiredArgsConstructor
public class TargetInfoRenderer implements ElementRenderer {
final StopWatch stopWatch = new StopWatch();
final Dragging drag;
LivingEntity entity = null;
boolean allow;
final Animation animation = new EaseBackIn(300, 1, 1);
float healthAnimation = 0.0f;
@Override
public void render(EventDisplay eventDisplay) {
entity = getTarget(entity);
float rounding = 6; // Закругленные углы
boolean out = !allow || stopWatch.isReached(1000);
animation.setDuration(out ? 300 : 250);
animation.setDirection(out ? Direction.BACKWARDS : Direction.FORWARDS);
if (animation.getOutput() == 0.0f) {
entity = null;
}
if (entity != null) {
String name = entity.getName().getString();
float posX = drag.getX();
float posY = drag.getY();
float headSize = 20; // Уменьшенный размер головы
float spacing = 3; // Уменьшенные отступы
float width = 110; // Компактная ширина
float height = 32; // Компактная высота
drag.setWidth(width);
drag.setHeight(height);
Score score = mc.world.getScoreboard().getOrCreateScore(entity.getScoreboardName(), mc.world.getScoreboard().getObjectiveInDisplaySlot(2));
float hp = entity.getHealth();
float maxHp = entity.getMaxHealth();
String header = mc.ingameGUI.getTabList().header == null ? " " : mc.ingameGUI.getTabList().header.getString().toLowerCase();
if (mc.getCurrentServerData() != null && mc.getCurrentServerData().serverIP.contains("funtime") &&
(header.contains("анархия") || header.contains("гриферский")) && entity instanceof PlayerEntity) {
hp = score.getScorePoints();
maxHp = 20;
}
healthAnimation = MathUtil.fast(healthAnimation, MathHelper.clamp(hp / maxHp, 0, 1), 15);
float animationValue = (float) animation.getOutput();
float halfAnimationValueRest = (1 - animationValue) / 2f;
float testX = posX + (width * halfAnimationValueRest);
float testY = posY + (height * halfAnimationValueRest);
float testW = width * animationValue;
float testH = height * animationValue;
GlStateManager.pushMatrix();
Style style = Expensive.getInstance().getStyleManager().getCurrentStyle();
sizeAnimation(posX + (width / 2), posY + (height / 2), animation.getOutput());
// Черный фон
DisplayUtils.drawRoundedRect(posX, posY, width, height, rounding, ColorUtils.rgba(20, 20, 20, 220));
// Серая рамка
DisplayUtils.drawRoundedRect(posX - 0.5f, posY - 0.5f, width + 1, height + 1, rounding + 0.5f, ColorUtils.rgb(60, 60, 60));
// Голова игрока
drawTargetHead(entity, posX + spacing, posY + spacing, headSize, headSize);
Scissor.push();
Scissor.setFromComponentCoordinates(testX, testY, testW - 6, testH);
// Имя игрока
Fonts.sfui.drawText(eventDisplay.getMatrixStack(), name, posX + headSize + spacing * 2, posY + spacing + 1, -1, 7);
// HP текст
Fonts.sfMedium.drawText(eventDisplay.getMatrixStack(), "HP: " + (int) hp + "/" + (int) maxHp,
posX + headSize + spacing * 2, posY + spacing + 10, ColorUtils.rgb(240, 240, 240), 6);
Scissor.unset();
Scissor.pop();
// Полоса здоровья с изменяющимся цветом
int healthBarColor = getHealthColor(healthAnimation);
float healthBarWidth = (width - headSize - spacing * 4) * healthAnimation;
// Темный фон для полосы здоровья
DisplayUtils.drawRoundedRect(posX + headSize + spacing * 2, posY + height - spacing - 5,
width - headSize - spacing * 4, 4, 2, ColorUtils.rgb(40, 40, 40));
// Сама полоса здоровья с цветом в зависимости от HP
DisplayUtils.drawRoundedRect(posX + headSize + spacing * 2, posY + height - spacing - 5,
healthBarWidth, 4, 2, healthBarColor);
// Отображение предметов (броня и оружие)
if (entity instanceof PlayerEntity) {
PlayerEntity player = (PlayerEntity) entity;
List<ItemStack> items = new ArrayList<>();
// Главная рука
ItemStack mainHand = player.getHeldItemMainhand();
if (!mainHand.isEmpty()) items.add(mainHand);
// Броня (от шлема до ботинок)
for (int i = 3; i >= 0; i--) {
ItemStack armor = player.inventory.armorInventory.get(i);
if (!armor.isEmpty()) items.add(armor);
}
// Вторая рука
ItemStack offHand = player.getHeldItemOffhand();
if (!offHand.isEmpty()) items.add(offHand);
float itemSize = 12; // Уменьшенный размер предметов
float spacingItems = 2;
float totalWidth = items.size() * (itemSize + spacingItems) - spacingItems;
float startX = posX + (width - totalWidth) / 2;
float itemY = posY + height + 2; // Предметы под панелью
RenderHelper.enableStandardItemLighting();
for (ItemStack stack : items) {
mc.getItemRenderer().renderItemAndEffectIntoGUI(stack, (int) startX, (int) itemY);
startX += itemSize + spacingItems;
}
RenderHelper.disableStandardItemLighting();
}
GlStateManager.popMatrix();
}
}
// Метод для получения цвета полосы здоровья в зависимости от уровня HP
private int getHealthColor(float healthPercent) {
if (healthPercent > 0.66f) {
return ColorUtils.rgb(80, 200, 80); // Зеленый для высокого HP
} else if (healthPercent > 0.33f) {
return ColorUtils.rgb(220, 180, 60); // Желтый для среднего HP
} else {
return ColorUtils.rgb(220, 60, 60); // Красный для низкого HP
}
}
private LivingEntity getTarget(LivingEntity nullTarget) {
LivingEntity auraTarget = Expensive.getInstance().getFunctionRegistry().getKillAura().getTarget();
LivingEntity target = nullTarget;
if (auraTarget != null) {
stopWatch.reset();
allow = true;
target = auraTarget;
} else if (mc.currentScreen instanceof ChatScreen) {
stopWatch.reset();
allow = true;
target = mc.player;
} else {
allow = false;
}
return target;
}
public void drawTargetHead(LivingEntity entity, float x, float y, float width, float height) {
if (entity != null) {
EntityRenderer<? super LivingEntity> rendererManager = mc.getRenderManager().getRenderer(entity);
// Круглая голова с обводкой
DisplayUtils.drawRoundedRect(x - 0.5f, y - 0.5f, width + 1, height + 1, width / 2, ColorUtils.rgb(60, 60, 60));
DisplayUtils.drawRoundedRect(x, y, width, height, width / 2, ColorUtils.rgb(40, 40, 40));
drawFace(rendererManager.getEntityTexture(entity), x, y, 8F, 8F, 8F, 8F, width, height, 64F, 64F, entity);
}
}
public static void sizeAnimation(double width, double height, double scale) {
GlStateManager.translated(width, height, 0);
GlStateManager.scaled(scale, scale, scale);
GlStateManager.translated(-width, -height, 0);
}
public void drawFace(ResourceLocation res, float x, float y, float u, float v, float uWidth, float vHeight, float width, float height, float tileWidth, float tileHeight, LivingEntity target) {
GL11.glPushMatrix();
GL11.glEnable(GL11.GL_BLEND);
mc.getTextureManager().bindTexture(res);
float hurtPercent = (target.hurtTime - (target.hurtTime != 0 ? mc.timer.renderPartialTicks : 0.0f)) / 10.0f;
GL11.glColor4f(1, 1 - hurtPercent, 1 - hurtPercent, 1);
AbstractGui.drawScaledCustomSizeModalRect(x, y, u, v, uWidth, vHeight, width, height, tileWidth, tileHeight);
GL11.glColor4f(1, 1, 1, 1);
GL11.glPopMatrix();
}
}