package im.furious.ui.display.impl; import com.mojang.blaze3d.matrix.MatrixStack; import im.furious.Furious; import im.furious.events.EventDisplay; import im.furious.ui.display.ElementRenderer; import im.furious.ui.styles.Style; import im.furious.utils.drag.Dragging; import im.furious.utils.render.ColorUtils; import im.furious.utils.render.DisplayUtils; import im.furious.utils.render.Scissor; import im.furious.utils.render.font.Fonts; import lombok.AccessLevel; import lombok.RequiredArgsConstructor; import lombok.experimental.FieldDefaults; import net.minecraft.client.gui.DisplayEffectsScreen; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.client.resources.I18n; import net.minecraft.potion.EffectInstance; import net.minecraft.potion.EffectUtils; import net.minecraft.util.ResourceLocation; @FieldDefaults(level = AccessLevel.PRIVATE) @RequiredArgsConstructor public class PotionRenderer implements ElementRenderer { final Dragging dragging; float width; float height; @Override public void render(EventDisplay eventDisplay) { MatrixStack ms = eventDisplay.getMatrixStack(); float posX = dragging.getX(); float posY = dragging.getY(); float fontSize = 6.5f; float padding = 3; String name = I18n.format("Potions"); Style style = Furious.getInstance().getStyleManager().getCurrentStyle(); DisplayUtils.drawShadow(posX, posY, width, height, 15, style.getFirstColor().getRGB(), style.getSecondColor().getRGB()); drawStyledRect(posX, posY, width, height, 3); posY += 1f; ResourceLocation backgroundTexture = new ResourceLocation("expensive/images/hud/potions.png"); DisplayUtils.drawImage(backgroundTexture, posX + 14, posY + 2f, 9, 8, ColorUtils.rgb(255,255,255)); Scissor.push(); Scissor.setFromComponentCoordinates(posX, posY, width, height); Fonts.sfui.drawCenteredText(ms, name, posX + width / 2, posY + padding, ColorUtils.rgb(255, 255, 255), 7); posY += fontSize + padding * 2; float maxWidth = Fonts.sfMedium.getWidth(name, fontSize) + padding * 2; float localHeight = fontSize + padding * 2; DisplayUtils.drawRectHorizontalW(posX + 0.5f, posY, width - 6, 2.5f, 3, ColorUtils.rgba(0, 0, 0, (int) (255 * 0.25f))); posY += 1f; for (EffectInstance effectInstance : mc.player.getActivePotionEffects()) { int amplifier = effectInstance.getAmplifier(); String amplifierStr = ""; if (amplifier >= 1 && amplifier <= 9) { amplifierStr = " " + I18n.format("enchantment.level." + (amplifier + 1)); } String effectName = I18n.format(effectInstance.getEffectName()) + amplifierStr; float nameWidth = Fonts.sfMedium.getWidth(effectName, fontSize); String durationText = EffectUtils.getPotionDurationString(effectInstance, 1); float durationWidth = Fonts.sfMedium.getWidth(durationText, fontSize); TextureAtlasSprite potionSprite = mc.getPotionSpriteUploader().getSprite(effectInstance.getPotion()); mc.getTextureManager().bindTexture(potionSprite.getAtlasTexture().getTextureLocation()); DisplayEffectsScreen.blit(ms, (int) (posX + padding + durationWidth + 5), (int) posY + 2, 7, 7, 7, potionSprite); float localWidth = nameWidth + durationWidth + padding * 3; Fonts.sfbold.drawText(ms, effectName, posX + padding + durationWidth + 15, posY + 2f, ColorUtils.rgb(255, 255, 255), 5); Fonts.sfbold.drawText(ms, durationText, posX + padding - 0, posY + 2f, ColorUtils.rgb(255, 255, 255), 6); if (localWidth > maxWidth) { maxWidth = localWidth; } posY += fontSize + padding; localHeight += fontSize + padding; } Scissor.unset(); Scissor.pop(); width = Math.max(maxWidth, 80); height = localHeight + 2.5f; dragging.setWidth(width); dragging.setHeight(height); } private void drawStyledRect(float x, float y, float width, float height, float radius) { DisplayUtils.drawShadow(x, y, width, height, (int) (radius * 2f), ColorUtils.rgba(0, 0, 0, 120)); DisplayUtils.drawRoundedRect(x, y, width, height, radius, ColorUtils.rgba(0, 0, 0, 155)); } }