Визуальная часть TargetHud \\ exp 3.1

моя первая работа, не закидывайте палками пожалуйста
ss - Посмотреть вложение 319054

Код:
Expand Collapse Copy
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.client.ClientUtil;
import im.expensive.utils.drag.Dragging;
import im.expensive.utils.math.MathUtil;
import im.expensive.utils.math.StopWatch;
import im.expensive.utils.math.Vector4i;
import im.expensive.utils.render.*;
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 net.minecraft.util.math.vector.Vector4f;
import org.lwjgl.opengl.GL11;

import java.awt.*;

@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);

        float rounding = 6;
        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 headSize = 28;
            float spacing = 5;

            float width = 180 / 1.75f;
            float height = 64.75f / 1.75f;
            drag.setWidth(width);
            drag.setHeight(height);
            float shrinking = 1.5f;
            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);


            if (mc.getCurrentServerData() != null && mc.getCurrentServerData().serverIP.contains("funtime")
                    && (header.contains("анархия") || header.contains("гриферский")) && entity instanceof PlayerEntity) {
                hp = score.getScorePoints();
                maxHp = 20;
            }



            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;
            int windowWidth = ClientUtil.calc(mc.getMainWindow().getScaledWidth());

            GlStateManager.pushMatrix();

            sizeAnimation(posX + (width / 2), posY + (height / 2), animation.getOutput());
            float finalPosY = posY;
            drawStyledRect(posX, finalPosY, width, height, 8);



            Stencil.initStencilToWrite();
            DisplayUtils.drawRoundedRect(posX + spacing + 0 , posY + 2 + spacing, 40 / 1.75f, 40 / 1.75f,3, ColorUtils.rgba(25,26,40,165));
            Stencil.readStencilBuffer(1);
            drawTargetHead(entity, posX + spacing + 0, posY + 2 + spacing, 40 / 1.75f, 40 / 1.75f);
            Stencil.uninitStencilBuffer();
            Scissor.push();

            Scissor.setFromComponentCoordinates(testX, testY, testW - 6, testH);

            Fonts.sfui.drawText(eventDisplay.getMatrixStack(), entity.getName().getString(), posX + headSize + spacing + spacing + - 8, posY + spacing + 6, -1, 8);
            Fonts.sfMedium.drawText(eventDisplay.getMatrixStack(), "HP: " + ((int) hp + (int) mc.player.getAbsorptionAmount()), posX - 23 + headSize + spacing + spacing + 15,
                    posY - 5 + spacing + 22, ColorUtils.rgb(255, 255, 255), 6);
            Scissor.unset();
            Scissor.pop();


            int rightColor = ColorUtils.getColor(75);

            drawArmor(eventDisplay, posX + headSize + spacing + spacing + 15, posY + spacing + 32);
            int healthColor = interpolateColor(ColorUtils.rgb(255, 0, 0), ColorUtils.rgb(0, 255, 0), healthAnimation);
            int rightBlack = ColorUtils.rgba(0, 0, 0, 34) + healthColor;
            int healthColor1 = interpolateColor(ColorUtils.rgb(255, 0, 0), ColorUtils.rgb(0, 255, 0), healthAnimation);

            int rightColor1 = ColorUtils.getColor(75);

            int leftColor = ColorUtils.getColor(0);
            DisplayUtils.drawRoundedRect(
                    posX + headSize + spacing + spacing + 15 - 48,
                    posY + height - spacing * 2 + 1 + 4,
                    (width - 7) * healthAnimation,
                    4,
                    new Vector4f(4, 4, 4, 4),
                    new Vector4i(leftColor, leftColor, rightColor1, rightColor1)
            );

            GlStateManager.popMatrix();
        }
    }


    private int interpolateColor(int startColor, int endColor, float fraction) {
        int startAlpha = (startColor >> 24) & 0xff;
        int startRed = (startColor >> 16) & 0xff;
        int startGreen = (startColor >> 8) & 0xff;
        int startBlue = startColor & 0xff;

        int endAlpha = (endColor >> 24) & 0xff;
        int endRed = (endColor >> 16) & 0xff;
        int endGreen = (endColor >> 8) & 0xff;
        int endBlue = endColor & 0xff;

        int alpha = (int) (startAlpha + (endAlpha - startAlpha) * fraction);
        int red = (int) (startRed + (endRed - startRed) * fraction);
        int green = (int) (startGreen + (endGreen - startGreen) * fraction);
        int blue = (int) (startBlue + (endBlue - startBlue) * fraction);

        return (alpha << 24) | (red << 16) | (green << 8) | blue;
    }

    private int darkenColor(int color, float factor) {
        int a = (color >> 24) & 0xff;
        int r = (color >> 16) & 0xff;
        int g = (color >> 8) & 0xff;
        int b = color & 0xff;
        r = (int) (r * factor);
        g = (int) (g * factor);
        b = (int) (b * factor);
        if (r < 0) r = 0; if (g < 0) g = 0; if (b < 0) b = 0;
        return (a << 24) | (r << 16) | (g << 8) | b;
    }




    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);
            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 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();
    }

    private void drawStyledRect(float x,
                                float y,
                                float width,
                                float height,
                                float radius) {

        DisplayUtils.drawRoundedRect(x + 2, y + 4, width - 1 , height - 2.5f, 3, ColorUtils.rgba(15, 15, 15, 255));
        DisplayUtils.drawShadow(x + 50, y + 12, 15, 15, 25, ColorUtils.rgba(255, 255, 255, 86));

    }
    private void drawArmor(EventDisplay eventDisplay, float x, float y) {
        float spacing = 12f;
        float scale = 0.7f;

        ItemStack helmet = entity.getItemStackFromSlot(EquipmentSlotType.HEAD);
        ItemStack chestplate = entity.getItemStackFromSlot(EquipmentSlotType.CHEST);
        ItemStack leggings = entity.getItemStackFromSlot(EquipmentSlotType.LEGS);
        ItemStack boots = entity.getItemStackFromSlot(EquipmentSlotType.FEET);


// Рисуем каждый слот в фиксированной позиции
        float currentX = x - 50;

// Шлем
        if (helmet != null && !helmet.isEmpty()) {
            renderItemStack(eventDisplay, helmet, currentX, y - 42, scale);
        }
        currentX += spacing;

// Нагрудник
        if (chestplate != null && !chestplate.isEmpty()) {
            renderItemStack(eventDisplay, chestplate, currentX, y - 42, scale);

        }
        currentX += spacing;

// Поножи
        if (leggings != null && !leggings.isEmpty()) {
            renderItemStack(eventDisplay, leggings, currentX, y - 42, scale);

        }
        currentX += spacing;

// Ботинки
        if (boots != null && !boots.isEmpty()) {
            renderItemStack(eventDisplay, boots, currentX, y - 42, scale);
        }
        currentX += spacing;

    }

    private void renderItemStack(EventDisplay eventDisplay, ItemStack stack, float x, float y, float scale) {
        GlStateManager.pushMatrix();
        GlStateManager.enableDepthTest();
        GlStateManager.scalef(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),
                stack.getCount() > 1 ? String.valueOf(stack.getCount()) : "");
        GlStateManager.disableDepthTest();
        GlStateManager.popMatrix();
    }

}
ужас
 
Назад
Сверху Снизу