diff --git a/src/main/java/com/mitchej123/hodgepodge/LoadingConfig.java b/src/main/java/com/mitchej123/hodgepodge/LoadingConfig.java index 6ced6d52..4017ce0d 100644 --- a/src/main/java/com/mitchej123/hodgepodge/LoadingConfig.java +++ b/src/main/java/com/mitchej123/hodgepodge/LoadingConfig.java @@ -10,6 +10,7 @@ public class LoadingConfig { // Adjustments public boolean addSystemInfo; + public boolean arabicNumbersForEnchantsPotions; public int chatLength; public int ic2SeedMaxStackSize; public int itemStacksPickedUpPerTick; @@ -29,6 +30,7 @@ public class LoadingConfig { public boolean fixDebugBoundingBox; public boolean fixDimensionChangeHearts; public boolean fixEatingStackedStew; + public boolean fixEnchantmentNumerals; public boolean fixExtraUtilitiesUnEnchanting; public boolean fixFenceConnections; public boolean fixFireSpread; @@ -55,6 +57,7 @@ public class LoadingConfig { public boolean fixNorthWestBias; public boolean fixOptifineChunkLoadingCrash; public boolean fixPerspectiveCamera; + public boolean fixPotionEffectNumerals; public boolean fixPotionEffectRender; public boolean fixPotionIterating; public boolean fixPotionLimit; @@ -152,6 +155,7 @@ public LoadingConfig(File file) { addCVSupportToWandPedestal = config.get(Category.TWEAKS.toString(), "addCVSupportToWandPedestal", true, "Add CV support to Thaumcraft wand recharge pedestal").getBoolean(); addSystemInfo = config.get(Category.TWEAKS.toString(), "addSystemInfo", true, "Adds system info to the F3 overlay (Java version and vendor; GPU name; OpenGL version; CPU cores; OS name, version and architecture)").getBoolean(); addToggleDebugMessage = config.get(Category.TWEAKS.toString(), "addToggleDebugMessage", true, "Add a debug message in the chat when toggling vanilla debug options").getBoolean(); + arabicNumbersForEnchantsPotions = config.get(Category.TWEAKS.toString(), "arabicNumbersForEnchantsPotions", false, "Uses arabic numbers for enchantment levels and potion amplifier levels instead of roman numbers").getBoolean(); biblocraftRecipes = config.get(Category.ASM.toString(), "biblocraftRecipes", true, "Remove recipe generation from BiblioCraft").getBoolean(); chatLength = Math.max(100, Math.min(32767, config.get(Category.TWEAKS.toString(), "chatLength", 8191, "Amount of chat lines kept [100(Vanilla) - 32767]").getInt())); cofhWorldTransformer = config.get(Category.ASM.toString(), "cofhWorldTransformer", true, "Enable Glease's ASM patch to disable unused CoFH tileentity cache").getBoolean(); @@ -167,6 +171,7 @@ public LoadingConfig(File file) { fixDebugBoundingBox = config.get(Category.FIXES.toString(), "fixDebugBoundingBox", true, "Fixes the debug hitbox of the player beeing offset").getBoolean(); fixDimensionChangeHearts = config.get(Category.FIXES.toString(), "fixDimensionChangeHearts", true, "Fix losing bonus hearts on dimension change").getBoolean(); fixEatingStackedStew = config.get(Category.FIXES.toString(), "fixEatingStackedStew", true, "Fix deleting stack when eating mushroom stew").getBoolean(); + fixEnchantmentNumerals = config.get(Category.FIXES.toString(), "fixEnchantmentNumerals", true, "Fix enchantment levels not displaying properly above a certain value").getBoolean(); fixExtraUtilitiesUnEnchanting = config.get(Category.FIXES.toString(), "fixExtraUtilitiesUnEnchanting", true, "Fix dupe bug with division sigil removing enchantment").getBoolean(); fixFenceConnections = config.get(Category.FIXES.toString(), "fixFenceConnections", true, "Fix fence connections with other types of fence").getBoolean(); fixFireSpread = config.get(Category.FIXES.toString(), "fixFireSpread", true, "Fix vanilla fire spread sometimes cause NPE on thermos").getBoolean(); @@ -196,6 +201,7 @@ public LoadingConfig(File file) { fixNorthWestBias = config.get(Category.FIXES.toString(), "fixNorthWestBias", true, "Fix northwest bias on RandomPositionGenerator").getBoolean(); fixOptifineChunkLoadingCrash = config.get(Category.FIXES.toString(), "fixOptifineChunkLoadingCrash", true, "Forces the chunk loading option from optifine to default since other values can crash the game").getBoolean(); fixPerspectiveCamera = config.get(Category.FIXES.toString(), "fixPerspectiveCamera", true, "Prevent tall grass and such to affect the perspective camera").getBoolean(); + fixPotionEffectNumerals = config.get(Category.FIXES.toString(), "fixPotionEffectNumerals", true, "Properly display level of potion effects in the inventory and on tooltips").getBoolean(); fixPotionEffectRender = config.get(Category.TWEAKS.toString(), "fixPotionEffectRender", true, "Fix vanilla potion effects rendering above the NEI tooltips in the inventory").getBoolean(); fixPotionIterating = config.get(Category.FIXES.toString(), "fixPotionIterating", true, "Fix crashes with ConcurrentModificationException because of incorrectly iterating over active potions").getBoolean(); fixPotionLimit = config.get(Category.FIXES.toString(), "fixPotionLimit", true, "Fix potions >= 128").getBoolean(); diff --git a/src/main/java/com/mitchej123/hodgepodge/mixins/Mixins.java b/src/main/java/com/mitchej123/hodgepodge/mixins/Mixins.java index 85883786..568ab0ba 100644 --- a/src/main/java/com/mitchej123/hodgepodge/mixins/Mixins.java +++ b/src/main/java/com/mitchej123/hodgepodge/mixins/Mixins.java @@ -10,6 +10,21 @@ public enum Mixins { // Vanilla Fixes + FIX_ENCHANTMENT_LEVEL_NUMERALS(new Builder("Fix enchantment levels not displaying properly above a certain value") + .setPhase(Phase.EARLY) + .addMixinClasses("minecraft.MixinEnchantment_FixRomanNumerals") + .setSide(Side.BOTH) + .setApplyIf(() -> Common.config.fixEnchantmentNumerals || Common.config.arabicNumbersForEnchantsPotions) + .addTargetedMod(TargetedMod.VANILLA)), + FIX_INVENTORY_POTION_EFFECT_NUMERALS(new Builder( + "Fix potion effects level not displaying properly above a certain value") + .setPhase(Phase.EARLY) + .addMixinClasses( + "minecraft.MixinInventoryEffectRenderer_FixPotionEffectNumerals", + "minecraft.MixinItemPotion_FixRomanNumerals") + .setSide(Side.CLIENT) + .setApplyIf(() -> Common.config.fixPotionEffectNumerals || Common.config.arabicNumbersForEnchantsPotions) + .addTargetedMod(TargetedMod.VANILLA)), FIX_HASTE_ARM_SWING_ANIMATION(new Builder("Fix arm not swinging when having too much haste") .setPhase(Phase.EARLY) .addMixinClasses("minecraft.MixinEntityLivingBase_FixHasteArmSwing") diff --git a/src/main/java/com/mitchej123/hodgepodge/mixins/early/minecraft/MixinEnchantment_FixRomanNumerals.java b/src/main/java/com/mitchej123/hodgepodge/mixins/early/minecraft/MixinEnchantment_FixRomanNumerals.java new file mode 100644 index 00000000..77edc478 --- /dev/null +++ b/src/main/java/com/mitchej123/hodgepodge/mixins/early/minecraft/MixinEnchantment_FixRomanNumerals.java @@ -0,0 +1,38 @@ +package com.mitchej123.hodgepodge.mixins.early.minecraft; + +import com.gtnewhorizon.mixinextras.injector.ModifyExpressionValue; +import com.mitchej123.hodgepodge.Common; +import com.mitchej123.hodgepodge.util.RomanNumerals; +import net.minecraft.enchantment.Enchantment; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; + +/** + * Mixin from Sk1erLLC/Patcher + */ +@Mixin(Enchantment.class) +public abstract class MixinEnchantment_FixRomanNumerals { + + @Shadow + public abstract String getName(); + + @ModifyExpressionValue( + method = "getTranslatedName", + at = + @At( + value = "INVOKE", + target = + "Lnet/minecraft/util/StatCollector;translateToLocal(Ljava/lang/String;)Ljava/lang/String;", + ordinal = 1)) + private String hodgepodge$modifyRomanNumerals(String translation, int level) { + if (Common.config.arabicNumbersForEnchantsPotions) { + return String.valueOf(level); + } + if (translation != null && translation.startsWith("enchantment.level.")) { + return RomanNumerals.toRoman(level); + } else { + return translation; + } + } +} diff --git a/src/main/java/com/mitchej123/hodgepodge/mixins/early/minecraft/MixinInventoryEffectRenderer_FixPotionEffectNumerals.java b/src/main/java/com/mitchej123/hodgepodge/mixins/early/minecraft/MixinInventoryEffectRenderer_FixPotionEffectNumerals.java new file mode 100644 index 00000000..a1c1a9b0 --- /dev/null +++ b/src/main/java/com/mitchej123/hodgepodge/mixins/early/minecraft/MixinInventoryEffectRenderer_FixPotionEffectNumerals.java @@ -0,0 +1,49 @@ +package com.mitchej123.hodgepodge.mixins.early.minecraft; + +import com.gtnewhorizon.mixinextras.injector.ModifyExpressionValue; +import com.mitchej123.hodgepodge.Common; +import com.mitchej123.hodgepodge.util.RomanNumerals; +import net.minecraft.client.renderer.InventoryEffectRenderer; +import net.minecraft.client.resources.I18n; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +@Mixin(InventoryEffectRenderer.class) +public class MixinInventoryEffectRenderer_FixPotionEffectNumerals { + + private int hodgepodge$potionAmplifierLevel; + + @ModifyExpressionValue( + method = "func_147044_g", + at = @At(value = "INVOKE", target = "Lnet/minecraft/potion/PotionEffect;getAmplifier()I", ordinal = 0)) + private int hodgepodge$skipOriginalCode(int amplifier) { + this.hodgepodge$potionAmplifierLevel = amplifier; + return 1; + } + + @Redirect( + method = "func_147044_g", + at = + @At( + value = "INVOKE", + target = + "Lnet/minecraft/client/resources/I18n;format(Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;", + ordinal = 1)) + private String hodgepodge$addRomanNumeral(String string, Object... objects) { + if (this.hodgepodge$potionAmplifierLevel > 0) { + if (Common.config.arabicNumbersForEnchantsPotions) { + return String.valueOf(this.hodgepodge$potionAmplifierLevel + 1); + } else { + final String translation = + I18n.format("enchantment.level." + (this.hodgepodge$potionAmplifierLevel + 1), objects); + if (translation != null && translation.startsWith("enchantment.level.")) { + return RomanNumerals.toRoman(this.hodgepodge$potionAmplifierLevel + 1); + } else { + return translation; + } + } + } + return ""; + } +} diff --git a/src/main/java/com/mitchej123/hodgepodge/mixins/early/minecraft/MixinItemPotion_FixRomanNumerals.java b/src/main/java/com/mitchej123/hodgepodge/mixins/early/minecraft/MixinItemPotion_FixRomanNumerals.java new file mode 100644 index 00000000..dd831c05 --- /dev/null +++ b/src/main/java/com/mitchej123/hodgepodge/mixins/early/minecraft/MixinItemPotion_FixRomanNumerals.java @@ -0,0 +1,40 @@ +package com.mitchej123.hodgepodge.mixins.early.minecraft; + +import com.gtnewhorizon.mixinextras.injector.ModifyExpressionValue; +import com.mitchej123.hodgepodge.Common; +import com.mitchej123.hodgepodge.util.RomanNumerals; +import net.minecraft.item.ItemPotion; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; + +@Mixin(ItemPotion.class) +public class MixinItemPotion_FixRomanNumerals { + + private int hodgepodge$potionAmplifierLevel; + + @ModifyExpressionValue( + method = "addInformation", + at = @At(value = "INVOKE", target = "Lnet/minecraft/potion/PotionEffect;getAmplifier()I", ordinal = 1)) + private int hodgepodge$getAmplifierLevel(int amplifier) { + this.hodgepodge$potionAmplifierLevel = amplifier; + return amplifier; + } + + @ModifyExpressionValue( + method = "addInformation", + at = + @At( + value = "INVOKE", + target = + "Lnet/minecraft/util/StatCollector;translateToLocal(Ljava/lang/String;)Ljava/lang/String;", + ordinal = 1)) + private String hodgepodge$addRomanNumeral(String translation) { + if (Common.config.arabicNumbersForEnchantsPotions) { + return String.valueOf(this.hodgepodge$potionAmplifierLevel + 1); + } else if (translation != null && translation.startsWith("potion.potency.")) { + return RomanNumerals.toRoman(this.hodgepodge$potionAmplifierLevel + 1); + } else { + return translation; + } + } +} diff --git a/src/main/java/com/mitchej123/hodgepodge/util/RomanNumerals.java b/src/main/java/com/mitchej123/hodgepodge/util/RomanNumerals.java new file mode 100644 index 00000000..14a287f4 --- /dev/null +++ b/src/main/java/com/mitchej123/hodgepodge/util/RomanNumerals.java @@ -0,0 +1,42 @@ +package com.mitchej123.hodgepodge.util; + +import java.util.HashMap; +import java.util.Map; +import java.util.TreeMap; + +// https://stackoverflow.com/questions/12967896/converting-integers-to-roman-numerals-java +public class RomanNumerals { + + private static final TreeMap map = new TreeMap<>(); + private static final Map cache = new HashMap<>(); + + static { + map.put(1000, "M"); + map.put(900, "CM"); + map.put(500, "D"); + map.put(400, "CD"); + map.put(100, "C"); + map.put(90, "XC"); + map.put(50, "L"); + map.put(40, "XL"); + map.put(10, "X"); + map.put(9, "IX"); + map.put(5, "V"); + map.put(4, "IV"); + map.put(1, "I"); + } + + public static String toRoman(int number) { + return cache.computeIfAbsent(number, RomanNumerals::toRomanUncached); + } + + private static String toRomanUncached(int number) { + if (number == 0) return "0"; + if (number < 0) return "-" + toRomanUncached(Math.abs(number)); + int floor = map.floorKey(number); + if (number == floor) { + return map.get(number); + } + return map.get(floor) + toRomanUncached(number - floor); + } +}