Skip to content

Commit

Permalink
Merge pull request #5 from GTNewHorizons/dev
Browse files Browse the repository at this point in the history
Config Rework
  • Loading branch information
Caedis authored Jun 9, 2023
2 parents 786b5c2 + 280f829 commit a007642
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 72 deletions.
111 changes: 67 additions & 44 deletions src/main/java/com/caedis/duradisplay/config/DuraDisplayConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down
26 changes: 26 additions & 0 deletions src/main/java/com/caedis/duradisplay/config/OverlayConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
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 static class DurabilityOverlayConfig extends OverlayConfig {

public DurabilityOverlayConfig() {
Position = 2;
}
}

public static class ChargeOverlayConfig extends OverlayConfig {

public ChargeOverlayConfig() {
Position = 8;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand Down
34 changes: 17 additions & 17 deletions src/main/java/com/caedis/duradisplay/render/DurabilityRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Class<?>, ItemHandler> itemHandlers = new LinkedHashMap<>();
Expand Down Expand Up @@ -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 {
Expand All @@ -110,8 +110,8 @@ public static int getRGBDurabilityForDisplay(double dur) {
private static List<ItemStackOverlay> 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<ItemStackOverlay> overlays = new ArrayList<>();
Expand All @@ -135,7 +135,7 @@ private static List<ItemStackOverlay> handleGregTech(@NotNull ItemStack stack) {

List<ItemStackOverlay> overlays = new ArrayList<>();

if (DuraDisplayConfig.Charge_Enable) {
if (DuraDisplayConfig.ChargeConfig.Enabled) {
Long[] elecStats = gtItem.getElectricStats(stack);
if (elecStats != null) {
ItemStackOverlay chargeOverlay = new ItemStackOverlay.ChargeOverlay();
Expand All @@ -148,7 +148,7 @@ private static List<ItemStackOverlay> 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) {
Expand Down Expand Up @@ -186,7 +186,7 @@ private static List<ItemStackOverlay> 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;
Expand All @@ -202,7 +202,7 @@ private static List<ItemStackOverlay> handleToolCore(@NotNull ItemStack stack) {
}

private static List<ItemStackOverlay> 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;

Expand All @@ -221,7 +221,7 @@ private static List<ItemStackOverlay> handleGregTechRadioactiveCell(@NotNull Ite
}

private static List<ItemStackOverlay> handleIElectricItem(@NotNull ItemStack stack) {
if (!DuraDisplayConfig.Charge_Enable) return null;
if (!DuraDisplayConfig.ChargeConfig.Enabled) return null;
IElectricItem bei = ((IElectricItem) stack.getItem());
assert bei != null;

Expand All @@ -238,7 +238,7 @@ private static List<ItemStackOverlay> handleIElectricItem(@NotNull ItemStack sta
}

private static List<ItemStackOverlay> handleItemArmorFluidTank(@NotNull ItemStack stack) {
if (!DuraDisplayConfig.Durability_Enable) return null;
if (!DuraDisplayConfig.DurabilityConfig.Enabled) return null;
ItemArmorFluidTank bei = ((ItemArmorFluidTank) stack.getItem());
assert bei != null;

Expand All @@ -257,7 +257,7 @@ private static List<ItemStackOverlay> handleItemArmorFluidTank(@NotNull ItemStac
}

private static List<ItemStackOverlay> handleICustomDamageItem(@NotNull ItemStack stack) {
if (!DuraDisplayConfig.Durability_Enable) return null;
if (!DuraDisplayConfig.DurabilityConfig.Enabled) return null;
ICustomDamageItem bei = ((ICustomDamageItem) stack.getItem());
assert bei != null;

Expand All @@ -276,7 +276,7 @@ private static List<ItemStackOverlay> handleICustomDamageItem(@NotNull ItemStack
}

private static List<ItemStackOverlay> handleBotaniaBrew(@NotNull ItemStack stack) {
if (!DuraDisplayConfig.Durability_Enable) return null;
if (!DuraDisplayConfig.DurabilityConfig.Enabled) return null;
ItemBrewBase brew = ((ItemBrewBase) stack.getItem());
assert brew != null;

Expand All @@ -299,7 +299,7 @@ private static List<ItemStackOverlay> 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;
Expand All @@ -321,7 +321,7 @@ private static List<ItemStackOverlay> 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")) {
Expand Down
Loading

0 comments on commit a007642

Please sign in to comment.