Use progress bars to render IEnergyInfo RF content (#55)

Co-authored-by: Martin Robertz <[email protected]>
This commit is contained in:
MalTeeezandMartin Robertz authored and GitHub committed 2025-11-17 00:50:04 +01:00
1 parent 5c115d9af3
commit d14044c92e
9 files changed
+162 -14

No files matched your search

@@ -12,6 +12,7 @@ import mcp.mobius.waila.api.IWailaConfigHandler;
import mcp.mobius.waila.api.IWailaDataAccessor;
import mcp.mobius.waila.api.IWailaDataProvider;
import mcp.mobius.waila.cbcore.LangUtil;
import mcp.mobius.waila.utils.NumberFormatter;
public class HUDHandlerEnergyCell implements IWailaDataProvider {
@@ -36,11 +37,11 @@ public class HUDHandlerEnergyCell implements IWailaDataProvider {
currenttip.add(
String.format(
"%s/%s : %d / %d RF/t",
"%s/%s : %s / %s RF/t",
LangUtil.translateG("hud.msg.in"),
LangUtil.translateG("hud.msg.out"),
energyReceive,
energySend));
NumberFormatter.format(energyReceive),
NumberFormatter.format(energySend)));
return currenttip;
}
@@ -13,7 +13,8 @@ import mcp.mobius.waila.api.ITaggedList;
import mcp.mobius.waila.api.IWailaConfigHandler;
import mcp.mobius.waila.api.IWailaDataAccessor;
import mcp.mobius.waila.api.IWailaDataProvider;
import mcp.mobius.waila.utils.WailaExceptionHandler;
import mcp.mobius.waila.api.SpecialChars;
import mcp.mobius.waila.utils.NumberFormatter;
public class HUDHandlerIEnergyHandler implements IWailaDataProvider {
@@ -34,15 +35,26 @@ public class HUDHandlerIEnergyHandler implements IWailaDataProvider {
if (!config.getConfig("thermalexpansion.energyhandler")) return currenttip;
if (!accessor.getNBTData().hasKey("Energy")) return currenttip;
if (!accessor.getNBTData().hasKey("MaxStorage")) return currenttip;
int energy = accessor.getNBTInteger(accessor.getNBTData(), "Energy");
int maxEnergy = accessor.getNBTInteger(accessor.getNBTData(), "MaxStorage");
try {
if ((maxEnergy != 0) && (((ITaggedList) currenttip).getEntries("RFEnergyStorage").size() == 0)) {
((ITaggedList) currenttip).add(String.format("%d / %d RF", energy, maxEnergy), "RFEnergyStorage");
if (currenttip instanceof ITaggedList taggedTips) {
int energy = accessor.getNBTInteger(accessor.getNBTData(), "Energy");
int maxEnergy = accessor.getNBTInteger(accessor.getNBTData(), "MaxStorage");
if (maxEnergy > 0 && taggedTips.getEntries("RFEnergyStorage").isEmpty()) {
if (config.getConfig("thermalexpansion.rfenergybar")) {
taggedTips.add(
SpecialChars.getRenderString("waila.rfenergy", energy + "", maxEnergy + ""),
"RFEnergyStorage");
} else {
taggedTips.add(
String.format(
"%s / %s RF",
NumberFormatter.format(energy),
NumberFormatter.format(maxEnergy)),
"RFEnergyStorage");
}
}
} catch (Exception e) {
currenttip = WailaExceptionHandler.handleErr(e, accessor.getTileEntity().getClass().getName(), currenttip);
}
return currenttip;
@@ -11,6 +11,7 @@ import net.minecraft.world.World;
import mcp.mobius.waila.api.IWailaConfigHandler;
import mcp.mobius.waila.api.IWailaDataAccessor;
import mcp.mobius.waila.api.IWailaDataProvider;
import mcp.mobius.waila.api.SpecialChars;
import mcp.mobius.waila.cbcore.LangUtil;
public class HUDHandlerTesseract implements IWailaDataProvider {
@@ -33,9 +34,9 @@ public class HUDHandlerTesseract implements IWailaDataProvider {
if (config.getConfig("thermalexpansion.tesssendrecv")) {
String send = String.format("%s : ", LangUtil.translateG("hud.msg.send"));
String recv = String.format("%s : ", LangUtil.translateG("hud.msg.recv"));
String item = String.format("\u00a7a%s ", LangUtil.translateG("hud.msg.item"));
String fluid = String.format("\u00a79%s ", LangUtil.translateG("hud.msg.fluid"));
String energ = String.format("\u00a7c%s ", LangUtil.translateG("hud.msg.energ"));
String item = String.format("%s ", SpecialChars.GREEN + LangUtil.translateG("hud.msg.item"));
String fluid = String.format("%s ", SpecialChars.BLUE + LangUtil.translateG("hud.msg.fluid"));
String energ = String.format("%s ", SpecialChars.RED + LangUtil.translateG("hud.msg.energ"));
switch (accessor.getNBTInteger(accessor.getNBTData(), "Item.Mode")) {
case 0:
@@ -68,6 +68,7 @@ public class ThermalExpansionModule {
IEnergyInfo_getCurStorage = IEnergyInfo.getMethod("getInfoEnergyStored");
ModuleRegistrar.instance().addConfigRemote("Thermal Expansion", "thermalexpansion.energyhandler");
ModuleRegistrar.instance().addConfigRemote("Thermal Expansion", "thermalexpansion.rfenergybar");
ModuleRegistrar.instance().registerBodyProvider(new HUDHandlerIEnergyHandler(), IEnergyProvider);
ModuleRegistrar.instance().registerNBTProvider(new HUDHandlerIEnergyHandler(), IEnergyProvider);
ModuleRegistrar.instance().registerBodyProvider(new HUDHandlerIEnergyHandler(), IEnergyReceiver);
@@ -24,6 +24,7 @@ import mcp.mobius.waila.overlay.tooltiprenderers.TTRenderAspectString;
import mcp.mobius.waila.overlay.tooltiprenderers.TTRenderFluidBar;
import mcp.mobius.waila.overlay.tooltiprenderers.TTRenderHealth;
import mcp.mobius.waila.overlay.tooltiprenderers.TTRenderProgressBar;
import mcp.mobius.waila.overlay.tooltiprenderers.TTRenderRFBar;
import mcp.mobius.waila.overlay.tooltiprenderers.TTRenderStack;
import mcp.mobius.waila.server.ProxyServer;
import mcp.mobius.waila.utils.LoadedMods;
@@ -61,6 +62,7 @@ public class ProxyClient extends ProxyServer {
ModuleRegistrar.instance().registerTooltipRenderer("waila.stack", new TTRenderStack());
ModuleRegistrar.instance().registerTooltipRenderer("waila.progress", new TTRenderProgressBar());
ModuleRegistrar.instance().registerTooltipRenderer("waila.fluid", new TTRenderFluidBar());
ModuleRegistrar.instance().registerTooltipRenderer("waila.rfenergy", new TTRenderRFBar());
ModuleRegistrar.instance().registerTooltipRenderer("waila.tcaspect", new TTRenderAspectString());
@@ -0,0 +1,116 @@
package mcp.mobius.waila.overlay.tooltiprenderers;
import java.awt.Dimension;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;
import mcp.mobius.waila.api.IWailaCommonAccessor;
import mcp.mobius.waila.api.IWailaVariableWidthTooltipRenderer;
import mcp.mobius.waila.overlay.DisplayUtil;
import mcp.mobius.waila.utils.NumberFormatter;
public class TTRenderRFBar implements IWailaVariableWidthTooltipRenderer {
int maxStringW;
private static final int height = 12;
private static final int width = 2;
@Override
public Dimension getSize(String[] params, IWailaCommonAccessor accessor) {
return new Dimension(
DisplayUtil.getDisplayWidth(buildDisplayText(Integer.parseInt(params[0]), Integer.parseInt(params[1])))
+ 4,
height);
}
public static final ResourceLocation barTexture = new ResourceLocation("waila", "textures/rf_energy_bar.png");
public static final ResourceLocation gradientTexture = new ResourceLocation("waila", "textures/gradient.png");
@Override
public void draw(String[] params, IWailaCommonAccessor accessor) {
int amount = Integer.parseInt(params[0]);
int capacity = Integer.parseInt(params[1]);
Tessellator tessellator = Tessellator.instance;
Minecraft mc = Minecraft.getMinecraft();
mc.getTextureManager().bindTexture(barTexture);
GL11.glColor4f(1F, 1F, 1F, 1F);
tessellator.startDrawingQuads();
// Draw dark (uncharged) background for whole bar first
for (int i = 0; i < (maxStringW - 2); i += width) {
drawRect(tessellator, 1 + i, 0, 0, width, height, 0.0, 0.0, 0.5, 1.0);
}
double i = (double) (maxStringW - 2) * amount / capacity;
int drawnRects = 0;
for (; i > width; i -= width) {
drawRect(tessellator, 1 + (drawnRects * width), 0, 0, width, height, 0.5, 0.0, 1.0, 1.0);
drawnRects++;
}
// Do less than full increments just as much as they take up on the scaled texture
drawRectD(tessellator, 1 + (drawnRects * width), 0, 0, i, height, 0.5, 0.0, 0.5 + 0.25 * i, 1.0);
tessellator.draw();
// Border
drawThickBeveledBox(0, 0, maxStringW, height, 1, 0xFF505050, 0xFF505050, -1);
// Gradient
GL11.glEnable(GL11.GL_BLEND);
GL11.glColor4f(1F, 1F, 1F, 0.5F);
mc.getTextureManager().bindTexture(gradientTexture);
tessellator.startDrawingQuads();
drawRect(tessellator, 1, 1, 0, maxStringW - 2, height - 2, 0, 0, 1, 1);
tessellator.draw();
DisplayUtil.drawString(buildDisplayText(amount, capacity), 2, 2, 0xFFFFFFFF, true);
}
public String buildDisplayText(int amount, int capacity) {
return String.format("%s / %s RF", NumberFormatter.format(amount), NumberFormatter.format(capacity));
}
public static void drawRect(Tessellator tessellator, int x, int y, double z, int width, int height, double minU,
double minV, double maxU, double maxV) {
tessellator.addVertexWithUV(x, y + height, z, minU, maxV);
tessellator.addVertexWithUV(x + width, y + height, z, maxU, maxV);
tessellator.addVertexWithUV(x + width, y, z, maxU, minV);
tessellator.addVertexWithUV(x, y, z, minU, minV);
}
public static void drawRectD(Tessellator tessellator, double x, double y, double z, double width, double height,
double minU, double minV, double maxU, double maxV) {
tessellator.addVertexWithUV(x, y + height, z, minU, maxV);
tessellator.addVertexWithUV(x + width, y + height, z, maxU, maxV);
tessellator.addVertexWithUV(x + width, y, z, maxU, minV);
tessellator.addVertexWithUV(x, y, z, minU, minV);
}
public static void drawThickBeveledBox(int x1, int y1, int x2, int y2, int thickness, int topleftcolor,
int botrightcolor, int fillcolor) {
if (fillcolor != -1) {
Gui.drawRect(x1 + 1, y1 + 1, x2 - 1, y2 - 1, fillcolor);
}
Gui.drawRect(x1, y1, x2 - 1, y1 + thickness, topleftcolor);
Gui.drawRect(x1, y1, x1 + thickness, y2 - 1, topleftcolor);
Gui.drawRect(x2 - thickness, y1, x2, y2 - 1, botrightcolor);
Gui.drawRect(x1, y2 - thickness, x2, y2, botrightcolor);
}
@Override
public void setMaxLineWidth(int width) {
maxStringW = width + 2;
}
@Override
public int getMaxLineWidth() {
return maxStringW;
}
}