-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix potion and enchantments level not rendering above a certain value (…
…#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
1 parent
6bc2323
commit 86a2f79
Showing
6 changed files
with
190 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
...a/com/mitchej123/hodgepodge/mixins/early/minecraft/MixinEnchantment_FixRomanNumerals.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...dgepodge/mixins/early/minecraft/MixinInventoryEffectRenderer_FixPotionEffectNumerals.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ""; | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...va/com/mitchej123/hodgepodge/mixins/early/minecraft/MixinItemPotion_FixRomanNumerals.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
42
src/main/java/com/mitchej123/hodgepodge/util/RomanNumerals.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |