Merge remote-tracking branch 'MalTeeez/master' into dev

This commit is contained in:
Martin Robertz committed 2025-11-15 13:08:11 +01:00
commit 7687cfae06
2 files changed
+99 -52

No files matched your search

@@ -1,6 +1,7 @@
package mcp.mobius.waila.overlay.tooltiprenderers;
import java.awt.Dimension;
import java.text.NumberFormat;
import java.util.function.Consumer;
import java.util.function.Function;
@@ -24,6 +25,7 @@ import gtPlusPlus.core.util.minecraft.FluidUtils;
import mcp.mobius.waila.api.IWailaCommonAccessor;
import mcp.mobius.waila.api.IWailaVariableWidthTooltipRenderer;
import mcp.mobius.waila.api.impl.ConfigHandler;
import mcp.mobius.waila.cbcore.LangUtil;
import mcp.mobius.waila.overlay.DisplayUtil;
public class TTRenderFluidBar implements IWailaVariableWidthTooltipRenderer {
@@ -33,6 +35,11 @@ public class TTRenderFluidBar implements IWailaVariableWidthTooltipRenderer {
private final Consumer<String> bindColor;
private final Function<Integer, String> formatNumber;
private static final int height = 12;
private static final NumberFormat numberFormat = NumberFormat.getInstance();
static {
numberFormat.setGroupingUsed(true);
}
public TTRenderFluidBar() {
if (Loader.isModLoaded("gregtech_nh")) {
@@ -49,22 +56,39 @@ public class TTRenderFluidBar implements IWailaVariableWidthTooltipRenderer {
formatNumber = GTUtility::formatNumbers;
} else {
bindColor = (fluidName) -> GL11.glColor4f(1F, 1F, 1F, 1F);
formatNumber = (number) -> String.format("%,d", number);
formatNumber = numberFormat::format;
}
}
@Override
public Dimension getSize(String[] params, IWailaCommonAccessor accessor) {
int commaCount = (int) (Math.floor((params[2].length() - 1) / 3D) + Math.floor((params[3].length() - 1) / 3D));
// ",".repeat(commaCount) doesn't exist in java 8 so do this instead.
StringBuilder sb = new StringBuilder(commaCount);
for (int i = 0; i < commaCount; i++) {
sb.append(",");
String barText;
if (!(params[0].equals("EMPTYFLUID") && params[1].equals("EMPTYFLUID"))) {
int commaCount = (int) (Math.floor((params[2].length() - 1) / 3D)
+ Math.floor((params[3].length() - 1) / 3D));
// ",".repeat(commaCount) doesn't exist in java 8 so do this instead.
StringBuilder sb = new StringBuilder(commaCount);
for (int i = 0; i < commaCount; i++) {
sb.append(",");
}
barText = String
.format("%s / %s %s %s%s", params[2], params[3], ConfigHandler.instance().fluidUnit, params[1], sb);
} else {
int commaCount = (int) (Math.floor((params[3].length() - 1) / 3D));
// ",".repeat(commaCount) doesn't exist in java 8 so do this instead.
StringBuilder sb = new StringBuilder(commaCount);
for (int i = 0; i < commaCount; i++) {
sb.append(",");
}
barText = String.format(
"%s / %s %s%s",
LangUtil.translateG("hud.msg.empty"),
params[3],
ConfigHandler.instance().fluidUnit,
sb);
}
return new Dimension(
DisplayUtil.getDisplayWidth(
params[2] + " / " + params[3] + ConfigHandler.instance().fluidUnit + params[1] + sb) + 4,
height);
return new Dimension(DisplayUtil.getDisplayWidth(barText) + 4, height);
}
public static final ResourceLocation gradient = new ResourceLocation("waila", "textures/gradient.png");
@@ -76,56 +100,74 @@ public class TTRenderFluidBar implements IWailaVariableWidthTooltipRenderer {
double amount = Double.parseDouble(params[2]);
double capacity = Double.parseDouble(params[3]);
Tessellator tessellator = Tessellator.instance;
IIcon icon = FluidRegistry.getFluid(fluidName).getIcon();
boolean isEmpty = fluidName.equals("EMPTYFLUID") && localizedName.equals("EMPTYFLUID");
Minecraft mc = Minecraft.getMinecraft();
mc.getTextureManager().bindTexture(TextureMap.locationBlocksTexture);
if (!isEmpty) {
IIcon icon = FluidRegistry.getFluid(fluidName).getIcon();
mc.getTextureManager().bindTexture(TextureMap.locationBlocksTexture);
bindColor.accept(fluidName);
bindColor.accept(fluidName);
tessellator.startDrawingQuads();
// Intentionally draw 2 pixels taller than needed than cover with the border to make the texture more visible
int i = (int) ((double) (maxStringW - 2) * amount / capacity);
int j = 0;
for (; i > height; i = i - height) {
drawRectFromIcon(tessellator, 1 + (j * height), 0, 0, icon, height, height);
j++;
tessellator.startDrawingQuads();
// Intentionally draw 2 pixels taller than needed than cover with the border to make the texture more
// visible
int i = (int) ((double) (maxStringW - 2) * amount / capacity);
int j = 0;
for (; i > height; i = i - height) {
drawRectFromIcon(tessellator, 1 + (j * height), 0, 0, icon, height, height);
j++;
}
if (i > 0) drawRect(
tessellator,
1 + (j * height),
0,
0,
i,
height,
icon.getMinU(),
icon.getMinV(),
icon.getMinU() + ((icon.getMaxU() - icon.getMinU()) * ((double) i / height)),
icon.getMaxV());
tessellator.draw();
}
if (i > 0) drawRect(
tessellator,
1 + (j * height),
0,
0,
i,
height,
icon.getMinU(),
icon.getMinV(),
icon.getMinU() + ((icon.getMaxU() - icon.getMinU()) * ((double) i / height)),
icon.getMaxV());
tessellator.draw();
GL11.glEnable(GL11.GL_BLEND);
GL11.glColor4f(1F, 1F, 1F, 0.70F);
mc.getTextureManager().bindTexture(gradient);
tessellator.startDrawingQuads();
drawRect(tessellator, 1, 0, 0, maxStringW - 2, height - 1, 0, 0, 1, 1);
tessellator.draw();
if (!isEmpty) {
GL11.glEnable(GL11.GL_BLEND);
GL11.glColor4f(1F, 1F, 1F, 0.70F);
mc.getTextureManager().bindTexture(gradient);
tessellator.startDrawingQuads();
drawRect(tessellator, 1, 0, 0, maxStringW - 2, height - 1, 0, 0, 1, 1);
tessellator.draw();
} else {
Gui.drawRect(1, 0, maxStringW - 1, height - 1, 0x1A575656);
}
drawThickBeveledBox(0, 0, maxStringW, height, 1, 0xFF505050, 0xFF505050, -1);
DisplayUtil.drawString(
formatNumber.apply((int) amount) + " / "
+ formatNumber.apply((int) capacity)
+ " "
+ ConfigHandler.instance().fluidUnit
+ " "
+ localizedName,
2,
2,
0xFFFFFFFF,
true);
if (!isEmpty) {
DisplayUtil.drawString(
String.format(
"%s / %s %s %s",
formatNumber.apply((int) amount),
formatNumber.apply((int) capacity),
ConfigHandler.instance().fluidUnit,
localizedName),
2,
2,
0xFFFFFFFF,
true);
} else {
DisplayUtil.drawString(
String.format(
"%s / %s %s",
LangUtil.translateG("hud.msg.empty"),
formatNumber.apply((int) capacity),
ConfigHandler.instance().fluidUnit),
2,
2,
0xFFDDDDDD,
true);
}
}
public static void drawRectFromIcon(Tessellator tessellator, int x, int y, double z, IIcon icon, int width,