- Выберите загрузчик игры
- OptiFine
- ForgeOptiFine
- Прочие моды
Добавил иконки рядом с пойшанами и сделал окошечко для таймера, мб кому нужно будет
не бейте палками, первый раз код переделываю
Скрин ниже
не бейте палками, первый раз код переделываю
Скрин ниже
JavaScript:
package log.evcalipse.ui.display.impl;
import log.evcalipse.modules.impl.render.Theme;
import log.evcalipse.utils.animations.Animation;
import log.evcalipse.utils.animations.Direction;
import log.evcalipse.utils.animations.easing.CompactAnimation;
import log.evcalipse.utils.animations.easing.Easing;
import log.evcalipse.utils.animations.impl.DecelerateAnimation;
import log.evcalipse.utils.animations.impl.EaseBackIn;
import log.evcalipse.utils.math.Vector4i;
import com.mojang.blaze3d.matrix.MatrixStack;
import log.evcalipse.Evcalipse;
import log.evcalipse.events.EventDisplay;
import log.evcalipse.modules.api.ModuleManager;
import log.evcalipse.modules.impl.render.HUD;
import log.evcalipse.ui.display.ElementRenderer;
import log.evcalipse.utils.drag.Dragging;
import log.evcalipse.utils.render.GaussianBlur;
import log.evcalipse.utils.render.color.ColorUtils;
import log.evcalipse.utils.render.font.Fonts;
import log.evcalipse.utils.render.gl.Scissor;
import log.evcalipse.utils.render.rect.RenderUtility;
import log.evcalipse.utils.text.GradientUtil;
import com.mojang.blaze3d.platform.GlStateManager;
import dev.sunlight.utils.text.font.ClientFonts;
import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;
import lombok.experimental.FieldDefaults;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screen.ChatScreen;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.texture.PotionSpriteUploader;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.client.resources.I18n;
import net.minecraft.potion.Effect;
import net.minecraft.potion.EffectInstance;
import net.minecraft.potion.EffectUtils;
import net.minecraft.util.math.vector.Vector4f;
import net.minecraft.util.text.Color;
import net.minecraft.util.text.ITextComponent;
import org.lwjgl.opengl.GL11;
@FieldDefaults(level = AccessLevel.PRIVATE)
@RequiredArgsConstructor
public class PotionRenderer implements ElementRenderer {
final Dragging dragging;
private final CompactAnimation widthAnimation = new CompactAnimation(Easing.EASE_OUT_QUART, 100);
private final CompactAnimation heightAnimation = new CompactAnimation(Easing.EASE_OUT_QUART, 100);
final Animation alphaAnimation = new DecelerateAnimation(300, 1, Direction.FORWARDS);
float width;
float height;
float animatedX = -1;
float animatedY = -1;
float dragSpeed = 0.15f;
boolean isFirstRender = true;
private static final Minecraft mc = Minecraft.getInstance();
@Override
public void render(EventDisplay eventDisplay) {
MatrixStack ms = eventDisplay.getMatrixStack();
if (isFirstRender) {
animatedX = dragging.getX();
animatedY = dragging.getY();
isFirstRender = false;
}
float targetX = dragging.getX();
float targetY = dragging.getY();
if (Math.abs(targetX - animatedX) > 0.01f || Math.abs(targetY - animatedY) > 0.01f) {
animatedX += (targetX - animatedX) * dragSpeed;
animatedY += (targetY - animatedY) * dragSpeed;
if (Math.abs(targetX - animatedX) < 0.1f) animatedX = targetX;
dragging.setX(animatedX);
dragging.setY(animatedY);
}
float posX = animatedX;
float posY = animatedY;
float titleFontSize = 7.5f;
float potionFontSize = 7.5f;
float padding = 1.5f;
float effectPadding = 0f;
float sidePadding = 7;
float rectHeight = 15;
float cornerRadius = 6;
float timerRectPadding = 1f;
float iconSize = 10f;
float iconTextSpacing = 4f;
ITextComponent name = GradientUtil.gradient(" Effects");
boolean isAnyPotionActive = false;
for (EffectInstance effectInstance : mc.player.getActivePotionEffects()) {
if (effectInstance.getDuration() > 0 && effectInstance.isShowIcon()) {
isAnyPotionActive = true;
break;
}
}
boolean chatOpen = mc.currentScreen instanceof ChatScreen;
if (chatOpen) {
isAnyPotionActive = true;
}
Direction targetDirection = isAnyPotionActive ? Direction.FORWARDS : Direction.BACKWARDS;
if (alphaAnimation.getDirection() != targetDirection) {
alphaAnimation.setDirection(targetDirection);
if (targetDirection == Direction.FORWARDS) {
alphaAnimation.reset();
}
}
alphaAnimation.isDone();
float finalAlpha = (float) alphaAnimation.getOutput();
if (finalAlpha <= 0.01) {
return;
}
float textWidth = Fonts.sfMedium.getWidth(" Effects", titleFontSize);
float targetWidth = textWidth + 2 * sidePadding + 40;
float totalPotionHeight = 0;
for (EffectInstance ef : mc.player.getActivePotionEffects()) {
if (ef.isShowIcon()) {
int amp = ef.getAmplifier();
String ampStr = amp >= 1 && amp <= 9 ? " " + I18n.format("enchantment.level." + (amp + 1)) : "";
String nameText = I18n.format(ef.getEffectName()) + ampStr;
float nameWidth = Fonts.sfMedium.getWidth(nameText, potionFontSize);
String bindText = EffectUtils.getPotionDurationString(ef, 1);
float bindWidth = Fonts.sfMedium.getWidth(bindText, potionFontSize);
float timerRectWidth = bindWidth + 6f * timerRectPadding;
float localWidth = sidePadding + iconSize + iconTextSpacing + nameWidth + padding + timerRectWidth + sidePadding;
if (localWidth > targetWidth) {
targetWidth = localWidth;
}
totalPotionHeight += (rectHeight + effectPadding);
}
}
widthAnimation.run(Math.max(targetWidth, 90) + 10);
heightAnimation.run(rectHeight + (mc.player.getActivePotionEffects().isEmpty() && chatOpen ? 0 : totalPotionHeight));
width = (float) widthAnimation.getValue();
height = (float) heightAnimation.getValue();
int themeColor1 = Theme.MainColor(0);
int themeColor2 = Theme.MainColor(1);
GL11.glPushMatrix();
GL11.glTranslatef(posX, posY, 0);
int alpha = (int) (245 * finalAlpha);
alpha = Math.max(1, alpha);
int headerTopLeft = ColorUtils.rgba(0, 0, 0, alpha);
int headerTopRight = ColorUtils.rgba(0, 0, 0, alpha);
int headerBottomLeft = ColorUtils.rgba(0, 0, 0, alpha);
int headerBottomRight = ColorUtils.rgba(0, 0, 0, alpha);
boolean hasActivePotions = !mc.player.getActivePotionEffects().isEmpty();
boolean shouldHaveExpandedLayout = (hasActivePotions || !chatOpen) && height > rectHeight + 1;
Vector4f headerRadius = shouldHaveExpandedLayout ?
new Vector4f(cornerRadius, 0, cornerRadius, 0) :
new Vector4f(cornerRadius, cornerRadius, cornerRadius, cornerRadius);
RenderUtility.drawRoundedRect(0, 0, width + 4, rectHeight, headerRadius,
new Vector4i(headerTopLeft, headerTopRight, headerBottomLeft, headerBottomRight));
if (height > rectHeight + 1) {
int mainTopLeft = ColorUtils.rgba(0, 0, 0, alpha);
int mainTopRight = ColorUtils.rgba(0, 0, 0, alpha);
int mainBottomLeft = ColorUtils.rgba(0, 0, 0, alpha);
int mainBottomRight = ColorUtils.rgba(0, 0, 0, alpha);
RenderUtility.drawRoundedRect(0, rectHeight, width + 4, height - rectHeight,
new Vector4f(0, cornerRadius, 0, cornerRadius),
new Vector4i(mainTopLeft, mainTopRight, mainBottomLeft, mainBottomRight));
}
int logoColor = ColorUtils.interpolateColor(themeColor1, ColorUtils.rgb(255, 255, 255), 0.2f);
logoColor = ColorUtils.setAlpha(logoColor, (int) (255 * finalAlpha));
ClientFonts.icons_nur[20].drawCenteredString(ms, "B", sidePadding + 4.5f, (rectHeight - 12.5f) / 2 + 4.5f, logoColor);
float xOffset = sidePadding + 8;
for (ITextComponent sibling : name.getSiblings()) {
String charText = sibling.getString();
int colorInt = ColorUtils.rgb(255, 255, 255);
colorInt = ColorUtils.setAlpha(colorInt, (int) (255 * finalAlpha));
Fonts.sfMedium.drawText(ms, charText, xOffset, (rectHeight - titleFontSize) / 2, colorInt, titleFontSize);
xOffset += Fonts.sfMedium.getWidth(charText, titleFontSize);
}
if (hasActivePotions) {
float effectY = rectHeight;
PotionSpriteUploader potionspriteuploader = mc.getPotionSpriteUploader();
for (EffectInstance ef : mc.player.getActivePotionEffects()) {
if (ef.isShowIcon()) {
Effect effect = ef.getPotion();
int amp = ef.getAmplifier();
String ampStr = amp >= 1 && amp <= 9 ? " " + I18n.format("enchantment.level." + (amp + 1)) : "";
String nameText = I18n.format(ef.getEffectName()) + ampStr;
float nameWidth = Fonts.sfuy.getWidth(nameText, potionFontSize);
String bindText = EffectUtils.getPotionDurationString(ef, 1);
float bindWidth = Fonts.sfuy.getWidth(bindText, potionFontSize);
float alphaMultiplier = 1f;
if (ef.getDuration() < 200) {
alphaMultiplier = (float) (Math.sin(System.currentTimeMillis() / 200.0) * 0.3 + 0.7);
}
alphaMultiplier *= finalAlpha;
float timerRectX = width - sidePadding - (bindWidth + 6f * timerRectPadding);
float timerRectY = effectY + (rectHeight - (potionFontSize + timerRectPadding * 2)) / 2;
float timerRectWidth = bindWidth + timerRectPadding * 6;
float timerRectHeight = potionFontSize + timerRectPadding * 2;
int timerBgColor1 = ColorUtils.setAlpha(ColorUtils.rgba(20, 20, 20, 255), (int) (240 * alphaMultiplier));
int timerBgColor2 = ColorUtils.setAlpha(ColorUtils.rgba(30, 30, 30, 255), (int) (240 * alphaMultiplier));
Vector4f timerBgRadius = new Vector4f(3, 3, 3, 3);
Vector4i timerBgColors = new Vector4i(timerBgColor1, timerBgColor2, timerBgColor2, timerBgColor1);
RenderUtility.drawRoundedRect(timerRectX, timerRectY, timerRectWidth, timerRectHeight, timerBgRadius, timerBgColors);
float textY = effectY + (rectHeight - potionFontSize) / 2;
float iconX = sidePadding;
float nameStartX = iconX + iconSize + iconTextSpacing;
TextureAtlasSprite sprite = potionspriteuploader.getSprite(effect);
drawIcon(sprite, iconX, effectY + (rectHeight - iconSize) / 2, iconSize, iconSize);
if (!ef.getPotion().isBeneficial()) {
Fonts.sfuy.drawText(ms, nameText, nameStartX, textY,
ColorUtils.rgba(255, 80, 80, (int) (255 * alphaMultiplier)), potionFontSize);
Fonts.sfuy.drawText(ms, bindText, timerRectX + timerRectPadding * 3, textY,
ColorUtils.rgba(255, 102, 102, (int) (255 * alphaMultiplier)), potionFontSize);
} else {
Fonts.sfuy.drawText(ms, nameText, nameStartX, textY,
ColorUtils.rgba(255, 255, 255, (int) (255 * alphaMultiplier)), potionFontSize);
Fonts.sfuy.drawText(ms, bindText, timerRectX + timerRectPadding * 3, textY,
ColorUtils.rgba(255, 255, 255, (int) (255 * alphaMultiplier)), potionFontSize);
}
effectY += (rectHeight + effectPadding);
}
}
}
GL11.glPopMatrix();
dragging.setWidth(width);
dragging.setHeight(height);
}
private void drawIcon(TextureAtlasSprite sprite, float x, float y, float width, float height) {
if (sprite == null) return;
GlStateManager.pushMatrix();
GlStateManager.enableBlend();
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
mc.getTextureManager().bindTexture(sprite.getAtlasTexture().getTextureLocation());
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder bufferBuilder = tessellator.getBuffer();
bufferBuilder.begin(7, DefaultVertexFormats.POSITION_TEX);
bufferBuilder.pos(x, y + height, 0).tex(sprite.getMinU(), sprite.getMaxV()).endVertex();
bufferBuilder.pos(x + width, y + height, 0).tex(sprite.getMaxU(), sprite.getMaxV()).endVertex();
bufferBuilder.pos(x + width, y, 0).tex(sprite.getMaxU(), sprite.getMinV()).endVertex();
bufferBuilder.pos(x, y, 0).tex(sprite.getMinU(), sprite.getMinV()).endVertex();
tessellator.draw();
GlStateManager.disableBlend();
GlStateManager.popMatrix();
}
}