diff --git a/dependencies.gradle b/dependencies.gradle index 1e46bd8..4d3ecb8 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -6,4 +6,9 @@ dependencies { shadowImplementation('au.com.bytecode:opencsv:2.4') compileOnly("com.github.GTNewHorizons:GT5-Unofficial:5.09.52.69:dev") { transitive = false } + + // For testing addon integration + runtimeOnly("com.github.GTNewHorizons:WAILAPlugins:0.7.0:dev") { transitive = false } + runtimeOnly("com.github.GTNewHorizons:EnderCore:0.5.0:dev") { transitive = false } + runtimeOnly("com.mod-buildcraft:buildcraft:7.1.23:dev") { transitive = false } } diff --git a/src/main/java/mcp/mobius/waila/overlay/tooltiprenderers/TTRenderFluidBar.java b/src/main/java/mcp/mobius/waila/overlay/tooltiprenderers/TTRenderFluidBar.java index f184053..d1f695f 100644 --- a/src/main/java/mcp/mobius/waila/overlay/tooltiprenderers/TTRenderFluidBar.java +++ b/src/main/java/mcp/mobius/waila/overlay/tooltiprenderers/TTRenderFluidBar.java @@ -9,7 +9,6 @@ import net.minecraft.client.gui.Gui; import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.texture.TextureMap; import net.minecraft.util.IIcon; -import net.minecraft.util.ResourceLocation; import net.minecraftforge.fluids.FluidRegistry; import net.minecraftforge.fluids.FluidStack; @@ -24,7 +23,9 @@ 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; +import mcp.mobius.waila.overlay.OverlayConfig; public class TTRenderFluidBar implements IWailaVariableWidthTooltipRenderer { @@ -32,10 +33,9 @@ public class TTRenderFluidBar implements IWailaVariableWidthTooltipRenderer { private final Consumer bindColor; private final Function formatNumber; - private static final int height = 12; public TTRenderFluidBar() { - if (Loader.isModLoaded("gregtech_nh")) { + if (Loader.isModLoaded("gregtech")) { bindColor = (fluidName) -> { FluidStack aCheck = FluidUtils.getWildcardFluidStack(fluidName, 1000); if (aCheck != null && (aCheck.getFluid() instanceof FluidGT6 || aCheck.getFluid() instanceof GTFluid)) { @@ -64,18 +64,23 @@ public class TTRenderFluidBar implements IWailaVariableWidthTooltipRenderer { return new Dimension( DisplayUtil.getDisplayWidth( params[2] + " / " + params[3] + ConfigHandler.instance().fluidUnit + params[1] + sb) + 4, - height); + 12); } - public static final ResourceLocation gradient = new ResourceLocation("waila", "textures/gradient.png"); - @Override public void draw(String[] params, IWailaCommonAccessor accessor) { String fluidName = params[0]; String localizedName = params[1]; double amount = Double.parseDouble(params[2]); double capacity = Double.parseDouble(params[3]); - Tessellator tessellator = Tessellator.instance; + boolean isEmpty = fluidName.equals("EMPTYFLUID") && localizedName.equals("EMPTYFLUID"); + if (isEmpty) { + fluidName = "water"; + localizedName = ""; + amount = 0; + } + + drawThickBeveledBox(0, 0, maxStringW, 12, 1, 0xFF505050, 0xFF505050, -1); IIcon icon = FluidRegistry.getFluid(fluidName).getIcon(); @@ -84,61 +89,62 @@ public class TTRenderFluidBar implements IWailaVariableWidthTooltipRenderer { 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); + for (; i > 10; i = i - 10) { + drawTexturedModelRectFromIcon(1 + (j * 10), 1, icon, 10, 10, 100); j++; } - if (i > 0) drawRect( - tessellator, - 1 + (j * height), - 0, - 0, + if (i > 0) drawTexturedModelRectFromIcon( + 1 + (j * 10), + 1, + icon, i, - height, - icon.getMinU(), - icon.getMinV(), - icon.getMinU() + ((icon.getMaxU() - icon.getMinU()) * ((double) i / height)), + 10, + 100, + icon.getMinU() + ((icon.getMaxU() - icon.getMinU()) * ((double) i / 10D)), icon.getMaxV()); - tessellator.draw(); - GL11.glEnable(GL11.GL_BLEND); - GL11.glColor4f(1F, 1F, 1F, 0.70F); - mc.getTextureManager().bindTexture(gradient); + if (!isEmpty) { + DisplayUtil.drawString( + formatNumber.apply((int) amount) + " / " + + formatNumber.apply((int) capacity) + + " " + + ConfigHandler.instance().fluidUnit + + " " + + localizedName, + 2, + 2, + OverlayConfig.fontcolor, + true); + } else { + DisplayUtil.drawString( + LangUtil.translateG("hud.msg.empty").replace("<", "").replace(">", "") + " / " + + formatNumber.apply((int) capacity) + + " " + + ConfigHandler.instance().fluidUnit + + " " + + localizedName, + 2, + 2, + 0xFF9D9D9D, // Important at merge with lighter color PR + true); + } + } + + public static void drawTexturedModelRectFromIcon(int x, int y, IIcon icon, int width, int height, double z) { + drawTexturedModelRectFromIcon(x, y, icon, width, height, z, icon.getMaxU(), icon.getMaxV()); + } + + public static void drawTexturedModelRectFromIcon(int x, int y, IIcon icon, int width, int height, double z, + double maxU, double maxV) { + Tessellator tessellator = Tessellator.instance; tessellator.startDrawingQuads(); - drawRect(tessellator, 1, 0, 0, maxStringW - 2, height - 1, 0, 0, 1, 1); - tessellator.draw(); - - 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); - - } - - public static void drawRectFromIcon(Tessellator tessellator, int x, int y, double z, IIcon icon, int width, - int height) { - drawRect(tessellator, x, y, z, width, height, icon.getMinU(), icon.getMinV(), icon.getMaxU(), icon.getMaxV()); - } - - 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, y + height, z, icon.getMinU(), 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); + tessellator.addVertexWithUV(x + width, y, z, maxU, icon.getMinV()); + tessellator.addVertexWithUV(x, y, z, icon.getMinU(), icon.getMinV()); + tessellator.draw(); } public static void drawThickBeveledBox(int x1, int y1, int x2, int y2, int thickness, int topleftcolor,