diff --git a/src/main/java/tconstruct/client/TProxyClient.java b/src/main/java/tconstruct/client/TProxyClient.java index ed19e4dc..d94d884e 100644 --- a/src/main/java/tconstruct/client/TProxyClient.java +++ b/src/main/java/tconstruct/client/TProxyClient.java @@ -23,6 +23,7 @@ import tconstruct.TConstruct; import tconstruct.armor.ArmorProxyClient; import tconstruct.armor.player.TPlayerStats; import tconstruct.common.TProxyCommon; +import tconstruct.library.util.LocalizedColors; import tconstruct.tools.items.ManualInfo; public class TProxyClient extends TProxyCommon { @@ -38,6 +39,7 @@ public class TProxyClient extends TProxyCommon { public void initialize() { registerRenderer(); readManuals(); + LocalizedColors.reload(); } /* Registers any rendering code. */ diff --git a/src/main/java/tconstruct/library/util/LocalizedColors.java b/src/main/java/tconstruct/library/util/LocalizedColors.java new file mode 100644 index 00000000..8f959c73 --- /dev/null +++ b/src/main/java/tconstruct/library/util/LocalizedColors.java @@ -0,0 +1,63 @@ +package tconstruct.library.util; + +import net.minecraft.util.StatCollector; + +public final class LocalizedColors { + + private static final String KEY_PREFIX = "tconstruct.nei.color."; + + public static int MATERIAL_NAME = 0x404040; + public static int MATERIAL_DURABILITY = 0x404040; + public static int MATERIAL_HANDLE_MODIFIER1 = 0x404040; + public static int MATERIAL_HANDLE_MODIFIER2 = 0x404040; + public static int MATERIAL_MINING_SPEED = 0x404040; + public static int MATERIAL_HARVEST_LEVEL = 0x404040; + public static int MATERIAL_ATTACK1 = 0x404040; + public static int MATERIAL_ATTACK2 = 0x404040; + public static int MATERIAL_REINFORCED = 0x404040; + public static int MATERIAL_STONEBOUND = 0x404040; + public static int MATERIAL_ABILITY = 0x404040; + public static int MATERIAL_BOW = 0x404040; + public static int MATERIAL_BOW_DRAW_SPEED = 0x404040; + public static int MATERIAL_BOW_FLIGHT_SPEED_MAX = 0x404040; + public static int MATERIAL_ARROW_MASS = 0x404040; + public static int MATERIAL_ARROW_BREAK_CHANCE = 0x404040; + + private LocalizedColors() {} + + public static void reload() { + MATERIAL_NAME = get("materialName", MATERIAL_NAME); + MATERIAL_DURABILITY = get("materialDurability", MATERIAL_DURABILITY); + MATERIAL_HANDLE_MODIFIER1 = get("materialHandleModifier1", MATERIAL_HANDLE_MODIFIER1); + MATERIAL_HANDLE_MODIFIER2 = get("materialHandleModifier2", MATERIAL_HANDLE_MODIFIER2); + MATERIAL_MINING_SPEED = get("materialMiningSpeed", MATERIAL_MINING_SPEED); + MATERIAL_HARVEST_LEVEL = get("materialHarvestLevel", MATERIAL_HARVEST_LEVEL); + MATERIAL_ATTACK1 = get("materialAttack1", MATERIAL_ATTACK1); + MATERIAL_ATTACK2 = get("materialAttack2", MATERIAL_ATTACK2); + MATERIAL_REINFORCED = get("materialReinforced", MATERIAL_REINFORCED); + MATERIAL_STONEBOUND = get("materialStonebound", MATERIAL_STONEBOUND); + MATERIAL_ABILITY = get("materialAbility", MATERIAL_ABILITY); + MATERIAL_BOW = get("materialBow", MATERIAL_BOW); + MATERIAL_BOW_DRAW_SPEED = get("materialBowDrawSpeed", MATERIAL_BOW_DRAW_SPEED); + MATERIAL_BOW_FLIGHT_SPEED_MAX = get("materialBowFlightSpeedMax", MATERIAL_BOW_FLIGHT_SPEED_MAX); + MATERIAL_ARROW_MASS = get("materialArrowMass", MATERIAL_ARROW_MASS); + MATERIAL_ARROW_BREAK_CHANCE = get("materialArrowBreakChance", MATERIAL_ARROW_BREAK_CHANCE); + } + + private static int get(String key, int fallback) { + String full = KEY_PREFIX + key; + + if (!StatCollector.canTranslate(full)) return fallback; + + String raw = StatCollector.translateToLocal(full).trim(); + + if (raw.startsWith("0x") || raw.startsWith("0X")) raw = raw.substring(2); + else if (raw.startsWith("#")) raw = raw.substring(1); + + try { + return (int) Long.parseLong(raw, 16); + } catch (NumberFormatException ignored) { + return fallback; + } + } +} diff --git a/src/main/java/tconstruct/plugins/nei/RecipeHandlerToolMaterials.java b/src/main/java/tconstruct/plugins/nei/RecipeHandlerToolMaterials.java index 397abbc7..fa6fbe39 100644 --- a/src/main/java/tconstruct/plugins/nei/RecipeHandlerToolMaterials.java +++ b/src/main/java/tconstruct/plugins/nei/RecipeHandlerToolMaterials.java @@ -23,27 +23,13 @@ import tconstruct.library.tools.DynamicToolPart; import tconstruct.library.tools.ToolMaterial; import tconstruct.library.util.HarvestLevels; import tconstruct.library.util.IToolPart; +import tconstruct.library.util.LocalizedColors; import tconstruct.tools.items.ToolPart; import tconstruct.util.config.PHConstruct; public class RecipeHandlerToolMaterials extends RecipeHandlerBase { private static final int DefaultTextColor = 0x404040; - private static final String ColorKey = "tconstruct.nei.color."; - - private static int getLocalizedColor(String colorName, int fallbackColor) { - String colorKey = ColorKey + colorName; - String colorValue = StatCollector.translateToLocal(colorKey); - if (colorKey.equals(colorValue)) { - return fallbackColor; - } - - try { - return Integer.decode(colorValue.trim()); - } catch (NumberFormatException ignored) { - return fallbackColor; - } - } public class CachedToolMaterialsRecipe extends CachedBaseRecipe { @@ -120,39 +106,39 @@ public class RecipeHandlerToolMaterials extends RecipeHandlerBase { EnumChatFormatting.BOLD + crecipe.material.localizedName(), 35, 10, - getLocalizedColor("materialName", DefaultTextColor), + LocalizedColors.MATERIAL_NAME, false); GuiDraw.drawString( StatCollector.translateToLocal("gui.partcrafter4") + crecipe.material.durability, 35, 20, - getLocalizedColor("materialDurability", DefaultTextColor), + LocalizedColors.MATERIAL_DURABILITY, false); GuiDraw.drawString( StatCollector.translateToLocal("gui.partcrafter5") + crecipe.material.handleModifier + "x", 35, 30, - getLocalizedColor("materialHandleModifier1", DefaultTextColor), + LocalizedColors.MATERIAL_HANDLE_MODIFIER1, false); GuiDraw.drawString( StatCollector.translateToLocal("gui.partcrafter11") + Math.round(crecipe.material.durability * crecipe.material.handleModifier), 35, 40, - getLocalizedColor("materialHandleModifier2", DefaultTextColor), + LocalizedColors.MATERIAL_HANDLE_MODIFIER2, false); GuiDraw.drawString( StatCollector.translateToLocal("gui.partcrafter6") + crecipe.material.miningspeed / 100F, 35, 50, - getLocalizedColor("materialMiningSpeed", DefaultTextColor), + LocalizedColors.MATERIAL_MINING_SPEED, false); GuiDraw.drawString( StatCollector.translateToLocal("gui.partcrafter7") + HarvestLevels.getHarvestLevelName(crecipe.material.harvestLevel), 35, 60, - getLocalizedColor("materialHarvestLevel", DefaultTextColor), + LocalizedColors.MATERIAL_HARVEST_LEVEL, false); String heart = crecipe.material.attack == 2 ? StatCollector.translateToLocal("gui.partcrafter8") : StatCollector.translateToLocal("gui.partcrafter9"); @@ -161,14 +147,14 @@ public class RecipeHandlerToolMaterials extends RecipeHandlerBase { StatCollector.translateToLocal("gui.partcrafter10") + crecipe.material.attack / 2 + heart, 35, 70, - getLocalizedColor("materialAttack1", DefaultTextColor), + LocalizedColors.MATERIAL_ATTACK1, false); } else { GuiDraw.drawString( StatCollector.translateToLocal("gui.partcrafter10") + crecipe.material.attack / 2F + heart, 35, 70, - getLocalizedColor("materialAttack2", DefaultTextColor), + LocalizedColors.MATERIAL_ATTACK2, false); } int abilityY = 85; @@ -177,7 +163,7 @@ public class RecipeHandlerToolMaterials extends RecipeHandlerBase { getReinforcedString(crecipe.material.reinforced), 35, 85, - getLocalizedColor("materialReinforced", DefaultTextColor), + LocalizedColors.MATERIAL_REINFORCED, false); abilityY += 10; } @@ -188,15 +174,10 @@ public class RecipeHandlerToolMaterials extends RecipeHandlerBase { ability + " (" + Math.abs(crecipe.material.stonebound) + ")", 35, abilityY, - getLocalizedColor("materialStonebound", DefaultTextColor), + LocalizedColors.MATERIAL_STONEBOUND, false); } else { - GuiDraw.drawString( - ability, - 35, - abilityY, - getLocalizedColor("materialAbility", DefaultTextColor), - false); + GuiDraw.drawString(ability, 35, abilityY, LocalizedColors.MATERIAL_ABILITY, false); } } } @@ -207,20 +188,20 @@ public class RecipeHandlerToolMaterials extends RecipeHandlerBase { EnumChatFormatting.BOLD + StatCollector.translateToLocal("tconstruct.nei.projectilematerials"), 35, 10, - getLocalizedColor("materialBow", DefaultTextColor), + LocalizedColors.MATERIAL_BOW, false); GuiDraw.drawString( StatCollector.translateToLocal("gui.toolstation6") + crecipe.bowMaterial.drawspeed, x, y, - getLocalizedColor("materialBowDrawSpeed", DefaultTextColor), + LocalizedColors.MATERIAL_BOW_DRAW_SPEED, false); y += 10; GuiDraw.drawString( StatCollector.translateToLocal("gui.toolstation7") + crecipe.bowMaterial.flightSpeedMax, x, y, - getLocalizedColor("materialBowFlightSpeedMax", DefaultTextColor), + LocalizedColors.MATERIAL_BOW_FLIGHT_SPEED_MAX, false); } if (crecipe.arrowMaterial != null) { @@ -230,14 +211,14 @@ public class RecipeHandlerToolMaterials extends RecipeHandlerBase { StatCollector.translateToLocal("gui.toolstation8") + crecipe.arrowMaterial.mass, x, y, - getLocalizedColor("materialArrowMass", DefaultTextColor), + LocalizedColors.MATERIAL_ARROW_MASS, false); y += 10; GuiDraw.drawString( StatCollector.translateToLocal("gui.toolstation22") + crecipe.arrowMaterial.breakChance, x, y, - getLocalizedColor("materialArrowBreakChance", DefaultTextColor), + LocalizedColors.MATERIAL_ARROW_BREAK_CHANCE, false); } }