From 35f624356d27d13de875b897b3cee9be3618d1c3 Mon Sep 17 00:00:00 2001 From: Caedis Date: Fri, 9 Jun 2023 14:25:33 -0500 Subject: [PATCH 1/2] Rework config --- .../duradisplay/config/DuraDisplayConfig.java | 111 +++++++++++------- .../config/GuiConfigDuraDisplay.java | 2 + .../duradisplay/config/OverlayConfig.java | 27 +++++ .../mixins/minecraft/MixinGuiScreen.java | 4 +- .../mixins/minecraft/MixinRenderItem.java | 11 +- .../render/DurabilityRenderer.java | 34 +++--- .../duradisplay/render/ItemStackOverlay.java | 9 +- 7 files changed, 126 insertions(+), 72 deletions(-) create mode 100644 src/main/java/com/caedis/duradisplay/config/OverlayConfig.java diff --git a/src/main/java/com/caedis/duradisplay/config/DuraDisplayConfig.java b/src/main/java/com/caedis/duradisplay/config/DuraDisplayConfig.java index fed9076..766208c 100644 --- a/src/main/java/com/caedis/duradisplay/config/DuraDisplayConfig.java +++ b/src/main/java/com/caedis/duradisplay/config/DuraDisplayConfig.java @@ -12,22 +12,14 @@ public class DuraDisplayConfig { + public static OverlayConfig.DurabilityOverlayConfig DurabilityConfig = new OverlayConfig.DurabilityOverlayConfig(); + public static OverlayConfig.ChargeOverlayConfig ChargeConfig = new OverlayConfig.ChargeOverlayConfig(); public static final String CATEGORY_CHARGE = "charge"; public static final String CATEGORY_DURABILITY = "durability"; private static boolean configLoaded = false; - public static boolean Durability_Enable = true; - public static boolean Charge_Enable = true; - public static boolean Durability_HideBar = true; - public static boolean Charge_HideBar = true; - public static int Durability_PercentageLocation = 2; - public static int Charge_PercentageLocation = 8; - public static boolean Durability_PercentageWhenFull = false; - public static boolean Charge_PercentageWhenFull = false; - - public static boolean Durability_UseColorThresholds = false; - public static double[] Durability_ColorThresholds = new double[] { 25.0, 75.0 }; + public static boolean Enable = true; public static Configuration config = null; @@ -52,78 +44,109 @@ public static void loadConfig() { public static void reloadConfigObject() { - Durability_Enable = config - .getBoolean("Enable", DuraDisplayConfig.CATEGORY_DURABILITY, Durability_Enable, "Enable durability module"); + Enable = config.getBoolean("Enable", Configuration.CATEGORY_GENERAL, Enable, "Enable/disable the entire mod"); + + DurabilityConfig.Enabled = config.getBoolean( + "Enable", + DuraDisplayConfig.CATEGORY_DURABILITY, + DurabilityConfig.Enabled, + "Enable durability module"); - Durability_HideBar = config - .getBoolean("HideBar", DuraDisplayConfig.CATEGORY_DURABILITY, Durability_HideBar, "Hide durability bar"); + DurabilityConfig.RenderBar = config.getBoolean( + "RenderBar", + DuraDisplayConfig.CATEGORY_DURABILITY, + DurabilityConfig.RenderBar, + "Render durability bar"); - Charge_Enable = config - .getBoolean("Enable", DuraDisplayConfig.CATEGORY_CHARGE, Charge_Enable, "Enable charge module"); + ChargeConfig.Enabled = config + .getBoolean("Enable", DuraDisplayConfig.CATEGORY_CHARGE, ChargeConfig.Enabled, "Enable charge module"); - Charge_HideBar = config - .getBoolean("HideBar", DuraDisplayConfig.CATEGORY_CHARGE, Charge_HideBar, "Hide charge bar"); + ChargeConfig.RenderBar = config + .getBoolean("RenderBar", DuraDisplayConfig.CATEGORY_CHARGE, ChargeConfig.RenderBar, "Render charge bar"); - Durability_PercentageLocation = config.getInt( - "PercentageLocation", + DurabilityConfig.Position = config.getInt( + "Position", DuraDisplayConfig.CATEGORY_DURABILITY, - Durability_PercentageLocation, + DurabilityConfig.Position, 1, 9, "Location in item where the durability percentage will be (numpad style)"); - Charge_PercentageLocation = config.getInt( - "PercentageLocation", + ChargeConfig.Position = config.getInt( + "Position", DuraDisplayConfig.CATEGORY_CHARGE, - Charge_PercentageLocation, + ChargeConfig.Position, 1, 9, "Location in item where the charge percentage will be (numpad style)"); - Durability_PercentageWhenFull = config.getBoolean( - "PercentageWhenFull", + DurabilityConfig.ShowWhenFull = config.getBoolean( + "ShowWhenFull", DuraDisplayConfig.CATEGORY_DURABILITY, - Durability_PercentageWhenFull, + DurabilityConfig.ShowWhenFull, "Show durability percentage when item is undamaged/full"); - Charge_PercentageWhenFull = config.getBoolean( - "PercentageWhenFull", + ChargeConfig.ShowWhenFull = config.getBoolean( + "ShowWhenFull", DuraDisplayConfig.CATEGORY_CHARGE, - Charge_PercentageWhenFull, + ChargeConfig.ShowWhenFull, "Show charge percentage when item is full"); - Durability_UseColorThresholds = config.getBoolean( - "UseColorThresholds", + DurabilityConfig.UseColorThreshold = config.getBoolean( + "UseColorThreshold", DuraDisplayConfig.CATEGORY_DURABILITY, - Durability_UseColorThresholds, - "Use the stated color thresholds instead of the default gradient coloring."); + DurabilityConfig.UseColorThreshold, + "Use the color thresholds instead of the default gradient coloring."); - Property colorThresh = config.get( + ChargeConfig.UseColorThreshold = config.getBoolean( + "UseColorThreshold", + DuraDisplayConfig.CATEGORY_CHARGE, + ChargeConfig.UseColorThreshold, + "Use the color thresholds instead of the static blue color."); + + Property dura_colorThresh = config.get( CATEGORY_DURABILITY, "ColorThresholds", - Durability_ColorThresholds, + DurabilityConfig.ColorThreshold, "List of numbers in ascending order from 0-100 that set the thresholds for durability color mapping. " + "Colors are from Red -> Yellow -> Green with Red being less than or equal to the first value " + "and Green being greater than or equal to the last value"); - Durability_ColorThresholds = colorThresh.getDoubleList(); + DurabilityConfig.ColorThreshold = dura_colorThresh.getDoubleList(); + + // clean up whatever the user inputs + DurabilityConfig.ColorThreshold = Arrays.stream(DurabilityConfig.ColorThreshold) + .filter(num -> num >= 0.0 && num <= 100.0) + .sorted() + .toArray(); + dura_colorThresh.set(DurabilityConfig.ColorThreshold); + + Property charge_colorThresh = config.get( + CATEGORY_CHARGE, + "ColorThresholds", + ChargeConfig.ColorThreshold, + "List of numbers in ascending order from 0-100 that set the thresholds for charge color mapping. " + + "Colors are from Red -> Orange -> Blue with Red being less than or equal to the first value " + + "and Blue being greater than or equal to the last value"); + ChargeConfig.ColorThreshold = charge_colorThresh.getDoubleList(); // clean up whatever the user inputs - Durability_ColorThresholds = Arrays.stream(Durability_ColorThresholds) + ChargeConfig.ColorThreshold = Arrays.stream(ChargeConfig.ColorThreshold) .filter(num -> num >= 0.0 && num <= 100.0) .sorted() .toArray(); - colorThresh.set(Durability_ColorThresholds); + charge_colorThresh.set(ChargeConfig.ColorThreshold); if (config.hasChanged()) { config.save(); } // Gregtech Bars - GT_Mod.gregtechproxy.mRenderItemDurabilityBar = !(Durability_Enable && Durability_HideBar); - GT_Mod.gregtechproxy.mRenderItemChargeBar = !(Charge_Enable && Charge_HideBar); + GT_Mod.gregtechproxy.mRenderItemDurabilityBar = Enable + && !(DurabilityConfig.Enabled && !DurabilityConfig.RenderBar); + GT_Mod.gregtechproxy.mRenderItemChargeBar = Enable && !(ChargeConfig.Enabled && !ChargeConfig.RenderBar); // EnderIO Bars - Config.renderChargeBar = !(Charge_Enable && Charge_HideBar); - Config.renderDurabilityBar = !(Durability_Enable && Durability_HideBar); + Config.renderChargeBar = Enable && !(ChargeConfig.Enabled && !ChargeConfig.RenderBar); + Config.renderDurabilityBar = Enable && !(DurabilityConfig.Enabled && !DurabilityConfig.RenderBar); } } diff --git a/src/main/java/com/caedis/duradisplay/config/GuiConfigDuraDisplay.java b/src/main/java/com/caedis/duradisplay/config/GuiConfigDuraDisplay.java index d6bd4c9..06c7e3e 100644 --- a/src/main/java/com/caedis/duradisplay/config/GuiConfigDuraDisplay.java +++ b/src/main/java/com/caedis/duradisplay/config/GuiConfigDuraDisplay.java @@ -2,6 +2,7 @@ import net.minecraft.client.gui.GuiScreen; import net.minecraftforge.common.config.ConfigElement; +import net.minecraftforge.common.config.Configuration; import com.caedis.duradisplay.Tags; import com.google.common.collect.Lists; @@ -15,6 +16,7 @@ public GuiConfigDuraDisplay(GuiScreen parent) { super( parent, Lists.newArrayList( + new ConfigElement<>(DuraDisplayConfig.config.getCategory(Configuration.CATEGORY_GENERAL)), new ConfigElement<>(DuraDisplayConfig.config.getCategory(DuraDisplayConfig.CATEGORY_DURABILITY)), new ConfigElement<>(DuraDisplayConfig.config.getCategory(DuraDisplayConfig.CATEGORY_CHARGE))), Tags.MODID, diff --git a/src/main/java/com/caedis/duradisplay/config/OverlayConfig.java b/src/main/java/com/caedis/duradisplay/config/OverlayConfig.java new file mode 100644 index 0000000..97f0c9c --- /dev/null +++ b/src/main/java/com/caedis/duradisplay/config/OverlayConfig.java @@ -0,0 +1,27 @@ +package com.caedis.duradisplay.config; + +public abstract class OverlayConfig { + + public boolean Enabled = true; + public int Position; + public boolean ShowWhenFull = false; + public boolean RenderBar = false; + + public boolean UseColorThreshold; + public double[] ColorThreshold = new double[] { 15, 50 }; + public double VisibleThreshold = 100; + + public static class DurabilityOverlayConfig extends OverlayConfig { + + public DurabilityOverlayConfig() { + Position = 2; + } + } + + public static class ChargeOverlayConfig extends OverlayConfig { + + public ChargeOverlayConfig() { + Position = 8; + } + } +} diff --git a/src/main/java/com/caedis/duradisplay/mixins/minecraft/MixinGuiScreen.java b/src/main/java/com/caedis/duradisplay/mixins/minecraft/MixinGuiScreen.java index aef98a9..d46c463 100644 --- a/src/main/java/com/caedis/duradisplay/mixins/minecraft/MixinGuiScreen.java +++ b/src/main/java/com/caedis/duradisplay/mixins/minecraft/MixinGuiScreen.java @@ -15,12 +15,12 @@ public class MixinGuiScreen { @SuppressWarnings("UnresolvedMixinReference") @Inject(method = "drawScreen(IIF)V", at = @At("HEAD")) private void drawScreenStart(CallbackInfo cbi) { - DurabilityRenderer.ShouldRun = false; + DurabilityRenderer.Execute = false; } @SuppressWarnings("UnresolvedMixinReference") @Inject(method = "drawScreen(IIF)V", at = @At("RETURN")) private void drawScreenEnd(CallbackInfo cbi) { - DurabilityRenderer.ShouldRun = true; + DurabilityRenderer.Execute = true; } } diff --git a/src/main/java/com/caedis/duradisplay/mixins/minecraft/MixinRenderItem.java b/src/main/java/com/caedis/duradisplay/mixins/minecraft/MixinRenderItem.java index 479a618..02684f2 100644 --- a/src/main/java/com/caedis/duradisplay/mixins/minecraft/MixinRenderItem.java +++ b/src/main/java/com/caedis/duradisplay/mixins/minecraft/MixinRenderItem.java @@ -32,12 +32,13 @@ public abstract class MixinRenderItem { target = "Lnet/minecraft/item/Item;showDurabilityBar(Lnet/minecraft/item/ItemStack;)Z")) private boolean showDurabilityBar(Item item0, ItemStack stack0, FontRenderer fontRenderer, TextureManager textureManager, ItemStack stack, int xPosition, int yPosition, String string) { - if (!DurabilityRenderer.ShouldRun) return item0.showDurabilityBar(stack0); - if (!DuraDisplayConfig.Durability_Enable && !DuraDisplayConfig.Charge_Enable) + if (!DurabilityRenderer.Execute) return item0.showDurabilityBar(stack0); + if (!DuraDisplayConfig.Enable + || (!DuraDisplayConfig.DurabilityConfig.Enabled && !DuraDisplayConfig.ChargeConfig.Enabled)) return item0.showDurabilityBar(stack0); DurabilityRenderer.Render(fontRenderer, stack0, xPosition, yPosition, zLevel); - return !DuraDisplayConfig.Durability_HideBar && item0.showDurabilityBar(stack0); + return DuraDisplayConfig.DurabilityConfig.RenderBar && item0.showDurabilityBar(stack0); } // Handle GT Tools @@ -50,8 +51,8 @@ private boolean showDurabilityBar(Item item0, ItemStack stack0, FontRenderer fon ordinal = 0)) private void renderItemAndEffectIntoGUI(FontRenderer fontRenderer, TextureManager textureManager, ItemStack stack, int xPosition, int yPosition, CallbackInfo ci) { - if (!DurabilityRenderer.ShouldRun) return; - if (!DuraDisplayConfig.Durability_Enable && !DuraDisplayConfig.Charge_Enable) return; + if (!DurabilityRenderer.Execute) return; + if (!DuraDisplayConfig.DurabilityConfig.Enabled && !DuraDisplayConfig.ChargeConfig.Enabled) return; if (stack == null || stack.getItem() == null || !(stack.getItem() instanceof GT_MetaBase_Item)) return; DurabilityRenderer.Render(fontRenderer, stack, xPosition, yPosition, zLevel); diff --git a/src/main/java/com/caedis/duradisplay/render/DurabilityRenderer.java b/src/main/java/com/caedis/duradisplay/render/DurabilityRenderer.java index cda3435..3214f55 100644 --- a/src/main/java/com/caedis/duradisplay/render/DurabilityRenderer.java +++ b/src/main/java/com/caedis/duradisplay/render/DurabilityRenderer.java @@ -31,8 +31,8 @@ public class DurabilityRenderer { - // - public static boolean ShouldRun = true; + // Used to prevent calls from outside actual inventories + public static boolean Execute = true; // Linked so that classes are checked in order private static final Map, ItemHandler> itemHandlers = new LinkedHashMap<>(); @@ -91,14 +91,14 @@ public static void Render(FontRenderer fontRenderer, ItemStack stack, int xPosit } public static int getRGBDurabilityForDisplay(double dur) { - if (!DuraDisplayConfig.Durability_UseColorThresholds) + if (!DuraDisplayConfig.DurabilityConfig.UseColorThreshold) return Color.HSBtoRGB(Math.max(0.0F, (float) dur) / 3.0F, 1.0F, 1.0F); else { double durability = dur * 100; - if (durability <= DuraDisplayConfig.Durability_ColorThresholds[0]) { + if (durability <= DuraDisplayConfig.DurabilityConfig.ColorThreshold[0]) { return 0xFF0000; } else if (durability - >= DuraDisplayConfig.Durability_ColorThresholds[DuraDisplayConfig.Durability_ColorThresholds.length + >= DuraDisplayConfig.DurabilityConfig.ColorThreshold[DuraDisplayConfig.DurabilityConfig.ColorThreshold.length - 1]) { return 0x55FF00; } else { @@ -110,8 +110,8 @@ public static int getRGBDurabilityForDisplay(double dur) { private static List handleDefault(@NotNull ItemStack stack) { Item item = stack.getItem(); assert item != null; - if (!DuraDisplayConfig.Durability_Enable - || !(item.isDamageable() && (DuraDisplayConfig.Durability_PercentageWhenFull || item.isDamaged(stack)))) + if (!DuraDisplayConfig.DurabilityConfig.Enabled + || !(item.isDamageable() && (DuraDisplayConfig.DurabilityConfig.ShowWhenFull || item.isDamaged(stack)))) return null; List overlays = new ArrayList<>(); @@ -135,7 +135,7 @@ private static List handleGregTech(@NotNull ItemStack stack) { List overlays = new ArrayList<>(); - if (DuraDisplayConfig.Charge_Enable) { + if (DuraDisplayConfig.ChargeConfig.Enabled) { Long[] elecStats = gtItem.getElectricStats(stack); if (elecStats != null) { ItemStackOverlay chargeOverlay = new ItemStackOverlay.ChargeOverlay(); @@ -148,7 +148,7 @@ private static List handleGregTech(@NotNull ItemStack stack) { } } - if (DuraDisplayConfig.Durability_Enable) { + if (DuraDisplayConfig.DurabilityConfig.Enabled) { ItemStackOverlay durabilityOverlay = new ItemStackOverlay.DurabilityOverlay(); GTToolsInfo gti = NBTUtils.getToolInfo(stack); if (gti.getRemainingPaint() > 0) { @@ -186,7 +186,7 @@ private static List handleToolCore(@NotNull ItemStack stack) { } } - if (!DuraDisplayConfig.Charge_Enable || !stack.getTagCompound() + if (!DuraDisplayConfig.ChargeConfig.Enabled || !stack.getTagCompound() .hasKey("Energy")) return overlays; IEnergyContainerItem eci = ((IEnergyContainerItem) stack.getItem()); assert eci != null; @@ -202,7 +202,7 @@ private static List handleToolCore(@NotNull ItemStack stack) { } private static List handleGregTechRadioactiveCell(@NotNull ItemStack stack) { - if (!DuraDisplayConfig.Durability_Enable) return null; + if (!DuraDisplayConfig.DurabilityConfig.Enabled) return null; GT_RadioactiveCell_Item bei = ((GT_RadioactiveCell_Item) stack.getItem()); assert bei != null; @@ -221,7 +221,7 @@ private static List handleGregTechRadioactiveCell(@NotNull Ite } private static List handleIElectricItem(@NotNull ItemStack stack) { - if (!DuraDisplayConfig.Charge_Enable) return null; + if (!DuraDisplayConfig.ChargeConfig.Enabled) return null; IElectricItem bei = ((IElectricItem) stack.getItem()); assert bei != null; @@ -238,7 +238,7 @@ private static List handleIElectricItem(@NotNull ItemStack sta } private static List handleItemArmorFluidTank(@NotNull ItemStack stack) { - if (!DuraDisplayConfig.Durability_Enable) return null; + if (!DuraDisplayConfig.DurabilityConfig.Enabled) return null; ItemArmorFluidTank bei = ((ItemArmorFluidTank) stack.getItem()); assert bei != null; @@ -257,7 +257,7 @@ private static List handleItemArmorFluidTank(@NotNull ItemStac } private static List handleICustomDamageItem(@NotNull ItemStack stack) { - if (!DuraDisplayConfig.Durability_Enable) return null; + if (!DuraDisplayConfig.DurabilityConfig.Enabled) return null; ICustomDamageItem bei = ((ICustomDamageItem) stack.getItem()); assert bei != null; @@ -276,7 +276,7 @@ private static List handleICustomDamageItem(@NotNull ItemStack } private static List handleBotaniaBrew(@NotNull ItemStack stack) { - if (!DuraDisplayConfig.Durability_Enable) return null; + if (!DuraDisplayConfig.DurabilityConfig.Enabled) return null; ItemBrewBase brew = ((ItemBrewBase) stack.getItem()); assert brew != null; @@ -299,7 +299,7 @@ private static List handleEnergyContainer(@NotNull ItemStack s overlays.addAll(defaultOverlays); } - if (!DuraDisplayConfig.Charge_Enable || !(stack.hasTagCompound() && stack.getTagCompound() + if (!DuraDisplayConfig.ChargeConfig.Enabled || !(stack.hasTagCompound() && stack.getTagCompound() .hasKey("Energy"))) return overlays; IEnergyContainerItem eci = ((IEnergyContainerItem) stack.getItem()); assert eci != null; @@ -321,7 +321,7 @@ private static List handleDarkSteelItems(@NotNull ItemStack st if (defaultOverlays != null) { overlays.addAll(defaultOverlays); } - if (!DuraDisplayConfig.Charge_Enable || !stack.hasTagCompound()) return overlays; + if (!DuraDisplayConfig.ChargeConfig.Enabled || !stack.hasTagCompound()) return overlays; NBTTagCompound nbt = stack.getTagCompound(); if (nbt.hasKey("enderio.darksteel.upgrade.energyUpgrade")) { diff --git a/src/main/java/com/caedis/duradisplay/render/ItemStackOverlay.java b/src/main/java/com/caedis/duradisplay/render/ItemStackOverlay.java index 329fe63..7ee809a 100644 --- a/src/main/java/com/caedis/duradisplay/render/ItemStackOverlay.java +++ b/src/main/java/com/caedis/duradisplay/render/ItemStackOverlay.java @@ -13,6 +13,7 @@ public abstract class ItemStackOverlay { public boolean isFull; public int color; public String value; + public double raw_value; public abstract int getColor(); @@ -77,7 +78,7 @@ public static class DurabilityOverlay extends ItemStackOverlay { @Override public void Render(FontRenderer fontRenderer, int xPosition, int yPosition, float zLevel) { - if (!DuraDisplayConfig.Durability_PercentageWhenFull && this.isFull) return; + if (!DuraDisplayConfig.DurabilityConfig.ShowWhenFull && this.isFull) return; super.Render(fontRenderer, xPosition, yPosition, zLevel); } @@ -88,7 +89,7 @@ public int getColor() { @Override public int getLocation() { - return DuraDisplayConfig.Durability_PercentageLocation; + return DuraDisplayConfig.DurabilityConfig.Position; } } @@ -96,7 +97,7 @@ public static class ChargeOverlay extends ItemStackOverlay { @Override public void Render(FontRenderer fontRenderer, int xPosition, int yPosition, float zLevel) { - if (!DuraDisplayConfig.Charge_PercentageWhenFull && this.isFull) return; + if (!DuraDisplayConfig.ChargeConfig.ShowWhenFull && this.isFull) return; super.Render(fontRenderer, xPosition, yPosition, zLevel); } @@ -107,7 +108,7 @@ public int getColor() { @Override public int getLocation() { - return DuraDisplayConfig.Charge_PercentageLocation; + return DuraDisplayConfig.ChargeConfig.Position; } } } From 280f829a7c7ed2e92b202df80abdb46b4d2f398e Mon Sep 17 00:00:00 2001 From: Caedis Date: Fri, 9 Jun 2023 14:30:28 -0500 Subject: [PATCH 2/2] Remove Unused --- src/main/java/com/caedis/duradisplay/config/OverlayConfig.java | 1 - .../java/com/caedis/duradisplay/render/ItemStackOverlay.java | 1 - 2 files changed, 2 deletions(-) diff --git a/src/main/java/com/caedis/duradisplay/config/OverlayConfig.java b/src/main/java/com/caedis/duradisplay/config/OverlayConfig.java index 97f0c9c..33462fc 100644 --- a/src/main/java/com/caedis/duradisplay/config/OverlayConfig.java +++ b/src/main/java/com/caedis/duradisplay/config/OverlayConfig.java @@ -9,7 +9,6 @@ public abstract class OverlayConfig { public boolean UseColorThreshold; public double[] ColorThreshold = new double[] { 15, 50 }; - public double VisibleThreshold = 100; public static class DurabilityOverlayConfig extends OverlayConfig { diff --git a/src/main/java/com/caedis/duradisplay/render/ItemStackOverlay.java b/src/main/java/com/caedis/duradisplay/render/ItemStackOverlay.java index 7ee809a..ce839f2 100644 --- a/src/main/java/com/caedis/duradisplay/render/ItemStackOverlay.java +++ b/src/main/java/com/caedis/duradisplay/render/ItemStackOverlay.java @@ -13,7 +13,6 @@ public abstract class ItemStackOverlay { public boolean isFull; public int color; public String value; - public double raw_value; public abstract int getColor();