From 2ad8838768dcdfa8bf8633479e6aaa25aadc650f Mon Sep 17 00:00:00 2001 From: Flummi Date: Thu, 2 May 2024 17:59:59 +0200 Subject: [PATCH] muh --- .../client/rendering/OverlayRenderer.java | 39 ++++-------------- .../championoverlay/utils/ExpTools.java | 40 +++++++++++++++++++ 2 files changed, 48 insertions(+), 31 deletions(-) create mode 100644 src/main/java/lul/flummi/championoverlay/utils/ExpTools.java diff --git a/src/main/java/lul/flummi/championoverlay/client/rendering/OverlayRenderer.java b/src/main/java/lul/flummi/championoverlay/client/rendering/OverlayRenderer.java index 83271cf..3d8b5ac 100644 --- a/src/main/java/lul/flummi/championoverlay/client/rendering/OverlayRenderer.java +++ b/src/main/java/lul/flummi/championoverlay/client/rendering/OverlayRenderer.java @@ -10,33 +10,10 @@ import net.minecraft.client.network.ClientPlayerEntity; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NbtCompound; +import lul.flummi.championoverlay.utils.ExpTools; +import lul.flummi.championoverlay.utils.ExpTools.ExpObject; + public class OverlayRenderer { - private record ExpObject(double ExpRequired, double ExpPrevious, String EnchantLevel) {} - private static double[] EnchantInfoChampion = { 0, 50000, 100000, 250000, 500000, 1000000, 1500000, 2000000, 2500000, 3000000 }; - private static double[] EnchantInfoCultivation = { 0, 1000, 5000, 25000, 100000, 300000, 1500000, 5000000, 20000000, 100000000 }; - private static double[] EnchantInfoExpertise = { 0, 50, 100, 250, 500, 1000, 2500, 5500, 10000, 15000 }; - private static double[] EnchantInfoCompact = { 0, 100, 500, 1500, 5000, 15000, 50000, 150000, 500000, 1000000 }; - private static String[] Levels = { "", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", "X" }; - - private static ExpObject getExpInformation(double[] InfoTable, double itemExp) { - if (itemExp >= InfoTable[InfoTable.length - 1]) - return new ExpObject(-1, InfoTable[InfoTable.length - 1], Levels[Levels.length - 1]); - - double ExpRequired = 0; - double ExpPrevious = 0; - String EnchantLevel = Levels[0]; - for (int i = 0; i < InfoTable.length; i++) { - if (itemExp < InfoTable[i]) { - ExpRequired = InfoTable[i]; - EnchantLevel = Levels[i]; - break; - } - else - ExpPrevious = InfoTable[i]; - } - return new ExpObject(ExpRequired, ExpPrevious, EnchantLevel); - } - public static void renderOverlay(DrawContext context, float deltaTick) { MinecraftClient Instance = MinecraftClient.getInstance(); ClientPlayerEntity player = Instance.player; @@ -49,7 +26,7 @@ public class OverlayRenderer { double ItemExp = 0; String EnchantPercent = "0%"; String EnchantName = ""; - ExpObject ExpInfo; + ExpObject ExpInfo = null; if (mainHandItem == null) return; @@ -65,22 +42,22 @@ public class OverlayRenderer { if (extraAttributes.contains("champion_combat_xp")) { EnchantName = "Champion"; ItemExp = extraAttributes.getDouble("champion_combat_xp"); - ExpInfo = getExpInformation(EnchantInfoChampion, ItemExp); + ExpInfo = ExpTools.getExpInformation(ExpTools.EnchantInfoChampion, ItemExp); } else if (extraAttributes.contains("farmed_cultivating")) { EnchantName = "Cultivating"; ItemExp = extraAttributes.getDouble("farmed_cultivating"); - ExpInfo = getExpInformation(EnchantInfoCultivation, ItemExp); + ExpInfo = ExpTools.getExpInformation(ExpTools.EnchantInfoCultivation, ItemExp); } else if (extraAttributes.contains("expertise_kills")) { EnchantName = "Expertise"; ItemExp = extraAttributes.getDouble("expertise_kills"); - ExpInfo = getExpInformation(EnchantInfoExpertise, ItemExp); + ExpInfo = ExpTools.getExpInformation(ExpTools.EnchantInfoExpertise, ItemExp); } else if (extraAttributes.contains("compact_blocks")) { EnchantName = "Compact"; ItemExp = extraAttributes.getDouble("compact_blocks"); - ExpInfo = getExpInformation(EnchantInfoCompact, ItemExp); + ExpInfo = ExpTools.getExpInformation(ExpTools.EnchantInfoCompact, ItemExp); } else return; diff --git a/src/main/java/lul/flummi/championoverlay/utils/ExpTools.java b/src/main/java/lul/flummi/championoverlay/utils/ExpTools.java new file mode 100644 index 0000000..4be6f40 --- /dev/null +++ b/src/main/java/lul/flummi/championoverlay/utils/ExpTools.java @@ -0,0 +1,40 @@ +package lul.flummi.championoverlay.utils; + +public class ExpTools { + public static double[] EnchantInfoChampion = { 0, 50000, 100000, 250000, 500000, 1000000, 1500000, 2000000, 2500000, 3000000 }; + public static double[] EnchantInfoCultivation = { 0, 1000, 5000, 25000, 100000, 300000, 1500000, 5000000, 20000000, 100000000 }; + public static double[] EnchantInfoExpertise = { 0, 50, 100, 250, 500, 1000, 2500, 5500, 10000, 15000 }; + public static double[] EnchantInfoCompact = { 0, 100, 500, 1500, 5000, 15000, 50000, 150000, 500000, 1000000 }; + public static String[] Levels = { "", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", "X" }; + + public static class ExpObject { + public final double ExpRequired; + public final double ExpPrevious; + public final String EnchantLevel; + + public ExpObject(double ExpRequired, double ExpPrevious, String EnchantLevel) { + this.ExpRequired = ExpRequired; + this.ExpPrevious = ExpPrevious; + this.EnchantLevel = EnchantLevel; + } + } + + public static ExpObject getExpInformation(double[] InfoTable, double itemExp) { + if (itemExp >= InfoTable[InfoTable.length - 1]) + return new ExpObject(-1, InfoTable[InfoTable.length - 1], Levels[Levels.length - 1]); + + double ExpRequired = 0; + double ExpPrevious = 0; + String EnchantLevel = Levels[0]; + for (int i = 0; i < InfoTable.length; i++) { + if (itemExp < InfoTable[i]) { + ExpRequired = InfoTable[i]; + EnchantLevel = Levels[i]; + break; + } + else + ExpPrevious = InfoTable[i]; + } + return new ExpObject(ExpRequired, ExpPrevious, EnchantLevel); + } +}