Подписывайтесь на наш Telegram и не пропускайте важные новости! Перейти

Визуальная часть TargetInfoRenderer | exp 3.1

Начинающий
Начинающий
Статус
Оффлайн
Регистрация
12 Мар 2026
Сообщения
19
Реакции
0
Выберите загрузчик игры
  1. Vanilla
  2. OptiFine
Всем привет, сделал еще один таргет худ, не судите строго, ток бекнулся, напиши если что-то поменять надо или улучшить, критике тоже рад, если объясните , что не так сделано!
SS -
1773521021114.png


Code -
TargetInfoRenderer:
Expand Collapse Copy
package im.expensive.ui.display.impl;

import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.platform.GlStateManager;
import im.expensive.Expensive;
import im.expensive.events.EventDisplay;
import im.expensive.ui.display.ElementRenderer;
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.Stencil;
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.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.EquipmentSlotType;
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;

@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(400, 1, 1);
    float healthAnimation = 0.0f;
    float absorptionAnimation = 0.0f;

    @Override
    public void render(EventDisplay eventDisplay) {
        entity = getTarget(entity);
        boolean out = !allow || stopWatch.isReached(1000);
        animation.setDuration(out ? 400 : 300);
        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 headBoxSize = 44;
            float gap = 4;
            float infoBoxWidth = 115;
            float height = headBoxSize;
            float width = headBoxSize + gap + infoBoxWidth;

            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), 10);
            absorptionAnimation = MathUtil.fast(absorptionAnimation, MathHelper.clamp(entity.getAbsorptionAmount() / maxHp, 0, 1), 10);

            GlStateManager.pushMatrix();
            sizeAnimation(posX + (width / 2), posY + (height / 2), animation.getOutput());

            int glassBgColor = ColorUtils.rgba(10, 10, 10, 110);
            int glassOutline = ColorUtils.rgba(255, 255, 255, 25);
            int healthBarBg = ColorUtils.rgba(25, 25, 25, 150);
            int accentWhite = ColorUtils.rgba(245, 245, 245, 255);
            int shadowColor = ColorUtils.rgba(0, 0, 0, 130);
            float radius = 6;

            DisplayUtils.drawShadow(posX, posY, headBoxSize, headBoxSize, 14, shadowColor, shadowColor);
            DisplayUtils.drawRoundedRect(posX - 0.5f, posY - 0.5f, headBoxSize + 1, headBoxSize + 1, radius + 0.5f, glassOutline);
            DisplayUtils.drawRoundedRect(posX, posY, headBoxSize, headBoxSize, radius, glassBgColor);

            float headPadding = 4;
            drawTargetHead(entity, posX + headPadding, posY + headPadding, headBoxSize - headPadding * 2, headBoxSize - headPadding * 2);

            float infoX = posX + headBoxSize + gap;

            DisplayUtils.drawShadow(infoX, posY, infoBoxWidth, height, 14, shadowColor, shadowColor);
            DisplayUtils.drawRoundedRect(infoX - 0.5f, posY - 0.5f, infoBoxWidth + 1, height + 1, radius + 0.5f, glassOutline);
            DisplayUtils.drawRoundedRect(infoX, posY, infoBoxWidth, height, radius, glassBgColor);

            float innerPad = 6;

            Scissor.push();
            Scissor.setFromComponentCoordinates(infoX, posY, infoBoxWidth - innerPad - 25, height);
            Fonts.sfui.drawText(eventDisplay.getMatrixStack(), name, infoX + innerPad, posY + 5, -1, 8.5f);
            Scissor.unset();
            Scissor.pop();

            String hpVal = String.format("%.0f", hp);
            float hpValWidth = Fonts.sfui.getWidth(hpVal, 8.5f);
            float hpTextWidth = Fonts.sfui.getWidth(" hp", 8.5f);
            float totalHpWidth = hpValWidth + hpTextWidth;

            Fonts.sfui.drawText(eventDisplay.getMatrixStack(), hpVal, infoX + infoBoxWidth - innerPad - totalHpWidth, posY + 5, -1, 8.5f);
            Fonts.sfui.drawText(eventDisplay.getMatrixStack(), " hp", infoX + infoBoxWidth - innerPad - hpTextWidth, posY + 5, ColorUtils.rgba(180, 180, 180, 255), 8.5f);

            if (entity instanceof PlayerEntity) {
                PlayerEntity player = (PlayerEntity) entity;
                float itemX = infoX + innerPad;
                float itemY = posY + 16;
                float itemSize = 12;
                float itemSpacing = 17;

                drawItemStack(eventDisplay.getMatrixStack(), player.getHeldItemMainhand(), itemX, itemY, itemSize);
                drawItemStack(eventDisplay.getMatrixStack(), player.getItemStackFromSlot(EquipmentSlotType.HEAD), itemX + itemSpacing, itemY, itemSize);
                drawItemStack(eventDisplay.getMatrixStack(), player.getItemStackFromSlot(EquipmentSlotType.CHEST), itemX + itemSpacing * 2, itemY, itemSize);
                drawItemStack(eventDisplay.getMatrixStack(), player.getItemStackFromSlot(EquipmentSlotType.LEGS), itemX + itemSpacing * 3, itemY, itemSize);
                drawItemStack(eventDisplay.getMatrixStack(), player.getItemStackFromSlot(EquipmentSlotType.FEET), itemX + itemSpacing * 4, itemY, itemSize);
                drawItemStack(eventDisplay.getMatrixStack(), player.getHeldItemOffhand(), itemX + itemSpacing * 5, itemY, itemSize);
            }

            float barX = infoX + innerPad;
            float barY = posY + height - 9;
            float barWidth = infoBoxWidth - innerPad * 2;
            float barHeight = 4;

            DisplayUtils.drawRoundedRect(barX, barY, barWidth, barHeight, 2, healthBarBg);
            DisplayUtils.drawRoundedRect(barX, barY, barWidth * healthAnimation, barHeight, 2, accentWhite);

            GlStateManager.popMatrix();
        }
    }

    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 if (mc.pointedEntity instanceof LivingEntity) {
            stopWatch.reset();
            allow = true;
            target = (LivingEntity) mc.pointedEntity;
        } else {
            allow = false;
        }

        return target;
    }

    private void drawItemStack(MatrixStack matrixStack, ItemStack stack, float x, float y, float size) {
        if (stack.isEmpty()) {
            float crossSize = 6f;
            float thickness = 1.0f;
            int color = ColorUtils.rgba(150, 150, 150, 100);

            GlStateManager.pushMatrix();
            GlStateManager.translated(x + size / 2.0f, y + size / 2.0f, 0);
            GlStateManager.rotatef(45, 0, 0, 1);
            DisplayUtils.drawRoundedRect(-crossSize / 2.0f, -thickness / 2.0f, crossSize, thickness, 0.5f, color);
            GlStateManager.rotatef(90, 0, 0, 1);
            DisplayUtils.drawRoundedRect(-crossSize / 2.0f, -thickness / 2.0f, crossSize, thickness, 0.5f, color);
            GlStateManager.popMatrix();
            return;
        }

        GlStateManager.pushMatrix();
        GlStateManager.enableBlend();
        GlStateManager.blendFunc(770, 771);

        float scale = size / 16.0f;
        GlStateManager.scaled(scale, scale, scale);

        mc.getItemRenderer().renderItemAndEffectIntoGUI(stack, (int)(x / scale), (int)(y / scale));
        mc.getItemRenderer().renderItemOverlayIntoGUI(mc.fontRenderer, stack, (int)(x / scale), (int)(y / scale), null);

        GlStateManager.disableBlend();
        GlStateManager.popMatrix();
    }

    public void drawTargetHead(LivingEntity entity, float x, float y, float width, float height) {
        if (entity != null) {
            EntityRenderer<? super LivingEntity> rendererManager = mc.getRenderManager().getRenderer(entity);

            GlStateManager.pushMatrix();
            Stencil.initStencilToWrite();
            DisplayUtils.drawRoundedRect(x, y, width, height, 4, -1);
            Stencil.readStencilBuffer(1);
            drawFace(rendererManager.getEntityTexture(entity), x, y, 8F, 8F, 8F, 8F, width, height, 64F, 64F, entity);
            Stencil.uninitStencilBuffer();
            GlStateManager.popMatrix();
        }
    }

    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 d, 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(d, y, u, v, uWidth, vHeight, width, height, tileWidth, tileHeight);
        GL11.glColor4f(1, 1, 1, 1);
        GL11.glPopMatrix();
    }
}
 
Назад
Сверху Снизу