-
Автор темы
- #1
Как сделать так чтобы текст или картинка подстраивались под тему. вот код
PotionRenderer:
public class PotionRenderer
implements ElementRenderer {
private final Dragging dragging;
private final ResourceLocation logo = new ResourceLocation("wonderful/images/hud/potion1.png");
private float iconSizeX = 10.0f;
private float iconSizeY = 10.0f;
private float width;
private float height;
@Override
public void render(EventDisplay eventDisplay) {
MatrixStack ms = eventDisplay.getMatrixStack();
float posX = this.dragging.getX();
float posY = this.dragging.getY();
float fontSize = 6.5f;
float padding = 5.0f;
ITextComponent name = GradientUtil.gradient("Poitions");
String namemod = "Зелья";
float finalPosY = posY;
this.drawStyledRect(posX, finalPosY, this.width, this.height, 5.0f);
Scissor.push();
Scissor.setFromComponentCoordinates(posX, posY, this.width, this.height);
Fonts.sfui.drawText(ms, namemod, posX + padding, posY + padding + 1.0f, new Color(-131587, true).getRGB(), fontSize);
posY += fontSize + padding * 2.0f;
float maxWidth = Fonts.sfMedium.getWidth(name, fontSize) + padding * 2.0f;
float localHeight = fontSize + padding * 2.0f;
for (EffectInstance ef : Minecraft.player.getActivePotionEffects()) {
int amp = ef.getAmplifier();
Object ampStr = "";
if (amp >= 1 && amp <= 9) {
ampStr = " " + I18n.format("enchantment.level." + (amp + 1), new Object[0]);
}
String nameText = I18n.format(ef.getEffectName(), new Object[0]) + (String)ampStr;
float nameWidth = Fonts.sfMedium.getWidth(nameText, fontSize);
String bindText = EffectUtils.getPotionDurationString(ef, 1.0f);
float bindWidth = Fonts.sfMedium.getWidth(bindText, fontSize);
float localWidth = nameWidth + bindWidth + padding * 3.0f;
Fonts.sfMedium.drawText(ms, nameText, posX + padding, posY, ColorUtils.rgba(210, 210, 210, 255), fontSize);
Fonts.sfMedium.drawText(ms, bindText, posX + this.width - padding - bindWidth, posY, ColorUtils.rgba(210, 210, 210, 255), fontSize);
if (localWidth > maxWidth) {
maxWidth = localWidth;
}
posY += fontSize + padding;
localHeight += fontSize + padding;
}
this.width = Math.max(maxWidth, 70.0f);
this.height = localHeight + 2.5f;
this.dragging.setWidth(this.width);
this.dragging.setHeight(this.height);
float imagePosX = posX + this.width - this.iconSizeX - padding;
RenderUtil.drawImage(this.logo, imagePosX, finalPosY + 3.7f, this.iconSizeX, this.iconSizeY, new Color(-1, true).getRGB());
Scissor.unset();
Scissor.pop();
}
private void drawStyledRect(float x, float y, float width, float height, float radius) {
RenderUtil.drawRoundedRect(x - 0.5f, y - 0.5f, width + 1.0f, height + 1.0f, radius + 0.5f, new Color(0x7C000000, true).getRGB());
RenderUtil.drawRoundedRect(x, y, width, height, radius, new Color(0x7C000000, true).getRGB());
}
public PotionRenderer(Dragging dragging) {
this.dragging = dragging;
}
}