Skip to content

Commit

Permalink
fix potion and enchantments level not rendering above a certain value (
Browse files Browse the repository at this point in the history
…#153)

* fix potion effect in inventory not rendering amplifier level above IV

* Fix enchantment levels not displaying properly above a certain value

* spotless

* add setting to show arabic numbers for enchant levels and potion effect levels

* forgot config check to apply mixin

* fix potion effects level not displaying properly on the tooltips above a certain value

* update dep file

(cherry picked from commit 599e7e9)
(cherry picked from commit 780cbea)

* update Buildscript

(cherry picked from commit 3f4bcfd)

* use @ModifyReturnValue instead of @reDIrect

* only return custom roman numbers if no translation key is found

Co-authored-by: Martin Robertz <[email protected]>
Co-authored-by: Jason Mitchell <[email protected]>
  • Loading branch information
3 people authored Jan 10, 2023
1 parent 6bc2323 commit 86a2f79
Show file tree
Hide file tree
Showing 6 changed files with 190 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/main/java/com/mitchej123/hodgepodge/LoadingConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
public class LoadingConfig {
// Adjustments
public boolean addSystemInfo;
public boolean arabicNumbersForEnchantsPotions;
public int chatLength;
public int ic2SeedMaxStackSize;
public int itemStacksPickedUpPerTick;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/com/mitchej123/hodgepodge/mixins/Mixins.java
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
Original file line number Diff line number Diff line change
@@ -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 "";
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
42 changes: 42 additions & 0 deletions src/main/java/com/mitchej123/hodgepodge/util/RomanNumerals.java
Original file line number Diff line number Diff line change
@@ -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<Integer, String> map = new TreeMap<>();
private static final Map<Integer, String> 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);
}
}

0 comments on commit 86a2f79

Please sign in to comment.