diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2022-07-26 14:00:45 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-26 22:00:45 +1000 |
commit | 5bcf7cc19df3ff59385b1de06cc3e2e827f5e2b6 (patch) | |
tree | ed52c6dbb61df92cd6fe7e9cb94a753ba1ca2a15 | |
parent | 01ce1186f271be0fc9cd65d759bc3905392c4ca8 (diff) | |
download | NotEnoughUpdates-5bcf7cc19df3ff59385b1de06cc3e2e827f5e2b6.tar.gz NotEnoughUpdates-5bcf7cc19df3ff59385b1de06cc3e2e827f5e2b6.tar.bz2 NotEnoughUpdates-5bcf7cc19df3ff59385b1de06cc3e2e827f5e2b6.zip |
Added power stone feature (#194)
Co-authored-by: Lorenz <ESs95s3P5z8Pheb>
6 files changed, 191 insertions, 0 deletions
diff --git a/Update Notes/2.1.md b/Update Notes/2.1.md index 71350dc7..57ad2bbb 100644 --- a/Update Notes/2.1.md +++ b/Update Notes/2.1.md @@ -100,6 +100,7 @@ - Added Fishing Timer over bobber - nea89 - Added [Auction Profit Viewer Overlay](https://cdn.discordapp.com/attachments/848901833119629332/993191851400101918/176946124-28ddf336-1ec7-460b-b22a-5fe2733b46a3.png) - efefury - Added Trophy Reward Overlay - hannibal2 +- Added power stone feature - hannibal2 ### **Bug Fixes:** diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java index 8c23aa60..6bf6d86b 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java @@ -49,6 +49,7 @@ import io.github.moulberry.notenoughupdates.miscfeatures.NPCRetexturing; import io.github.moulberry.notenoughupdates.miscfeatures.Navigation; import io.github.moulberry.notenoughupdates.miscfeatures.NullzeeSphere; import io.github.moulberry.notenoughupdates.miscfeatures.PetInfoOverlay; +import io.github.moulberry.notenoughupdates.miscfeatures.PowerStoneStatsDisplay; import io.github.moulberry.notenoughupdates.miscfeatures.SlotLocking; import io.github.moulberry.notenoughupdates.miscfeatures.StorageManager; import io.github.moulberry.notenoughupdates.miscfeatures.SunTzu; @@ -287,6 +288,7 @@ public class NotEnoughUpdates { MinecraftForge.EVENT_BUS.register(new OldAnimationChecker()); MinecraftForge.EVENT_BUS.register(new SignCalculator()); MinecraftForge.EVENT_BUS.register(TrophyRewardOverlay.getInstance()); + MinecraftForge.EVENT_BUS.register(PowerStoneStatsDisplay.getInstance()); MinecraftForge.EVENT_BUS.register(navigation); if (Minecraft.getMinecraft().getResourceManager() instanceof IReloadableResourceManager) { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/util/StringUtils.java b/src/main/java/io/github/moulberry/notenoughupdates/core/util/StringUtils.java index 41f2742f..d52f9ba1 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/core/util/StringUtils.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/util/StringUtils.java @@ -53,4 +53,14 @@ public class StringUtils { return trim; } + + public static String substringBetween(String str, String open, String close) { + return org.apache.commons.lang3.StringUtils.substringBetween(str, open, close); + } + + public static int cleanAndParseInt(String str) { + str = cleanColour(str); + str = str.replace(",", ""); + return Integer.parseInt(str); + } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/PowerStoneStatsDisplay.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/PowerStoneStatsDisplay.java new file mode 100644 index 00000000..e62e572d --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/PowerStoneStatsDisplay.java @@ -0,0 +1,168 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. + */ + +package io.github.moulberry.notenoughupdates.miscfeatures; + +import io.github.moulberry.notenoughupdates.NotEnoughUpdates; +import io.github.moulberry.notenoughupdates.core.util.StringUtils; +import io.github.moulberry.notenoughupdates.options.NEUConfig; +import io.github.moulberry.notenoughupdates.util.ItemUtils; +import net.minecraft.client.Minecraft; +import net.minecraft.client.entity.EntityPlayerSP; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.gui.inventory.GuiChest; +import net.minecraft.inventory.Container; +import net.minecraft.inventory.ContainerChest; +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; +import net.minecraftforge.event.entity.player.ItemTooltipEvent; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.common.gameevent.TickEvent; + +import java.text.NumberFormat; +import java.util.LinkedList; +import java.util.List; +import java.util.Locale; + +public class PowerStoneStatsDisplay { + private static PowerStoneStatsDisplay instance = null; + NumberFormat format = NumberFormat.getInstance(Locale.US); + + public static PowerStoneStatsDisplay getInstance() { + if (instance == null) { + instance = new PowerStoneStatsDisplay(); + } + return instance; + } + + @SubscribeEvent + public void onTick(TickEvent event) { + GuiScreen currentScreen = Minecraft.getMinecraft().currentScreen; + if (currentScreen == null) return; + if (!(currentScreen instanceof GuiChest)) return; + ContainerChest container = (ContainerChest) ((GuiChest) currentScreen).inventorySlots; + IInventory menu = container.getLowerChestInventory(); + String title = menu.getDisplayName().getUnformattedText(); + + if (!title.equals("SkyBlock Menu")) return; + + EntityPlayerSP p = Minecraft.getMinecraft().thePlayer; + Container openContainer = p.openContainer; + for (Slot slot : openContainer.inventorySlots) { + ItemStack stack = slot.getStack(); + if (stack == null) continue; + + String displayName = stack.getDisplayName(); + if (!"§aAccessory Bag".equals(displayName)) continue; + + for (String line : ItemUtils.getLore(stack)) { + if (line.startsWith("§7Magical Power: ")) { + String rawNumber = line.split("§6")[1].replace(",", ""); + NEUConfig.HiddenProfileSpecific configProfileSpecific = NotEnoughUpdates.INSTANCE.config.getProfileSpecific(); + if (configProfileSpecific == null) return; + configProfileSpecific.magicalPower = Integer.parseInt(rawNumber); + } + } + } + } + + @SubscribeEvent + public void onItemTooltipLow(ItemTooltipEvent event) { + if (!NotEnoughUpdates.INSTANCE.config.tooltipTweaks.powerStoneStats) return; + + ItemStack itemStack = event.itemStack; + if (itemStack == null) return; + List<String> lore = ItemUtils.getLore(itemStack); + + boolean isPowerStone = false; + for (String line : lore) { + if (line.equals("§8Power Stone")) { + isPowerStone = true; + break; + } + } + + if (!isPowerStone) return; + + NEUConfig.HiddenProfileSpecific configProfileSpecific = NotEnoughUpdates.INSTANCE.config.getProfileSpecific(); + if (configProfileSpecific == null) return; + + int magicalPower = configProfileSpecific.magicalPower; + if (magicalPower < 1) return; + + double scaledMagicalPower = scalePower(magicalPower); + double scaledCurrentPower = 0.0; + + int index = 0; + boolean foundMagicalPower = false; + for (String line : new LinkedList<>(lore)) { + index++; + line = line.replace("§k", ""); + + if (line.startsWith("§7At ")) { + + String rawNumber = StringUtils.substringBetween(StringUtils.cleanColour(line), "At ", " Magical"); + if (rawNumber == null) return; + + //This ignores old repo entries in the item browser from neu + if (rawNumber.equals("mmm")) return; + + try { + scaledCurrentPower = scalePower(StringUtils.cleanAndParseInt(rawNumber)); + } catch (NumberFormatException ignored) { + return; + } + + event.toolTip.set(index, "§7At §6" + format.format((double) magicalPower) + " Magical Power§7:"); + foundMagicalPower = true; + continue; + } + + if (!foundMagicalPower) continue; + + String cleanLine = StringUtils.cleanColour(line); + if (cleanLine.equals("")) { + break; + } + + for (String operator : new String[]{"+", "-"}) { + if (!cleanLine.startsWith(operator)) continue; + String rawStat = StringUtils.cleanColour(StringUtils.substringBetween(line, operator, " ")); + + double currentStat; + try { + currentStat = 0.0 + StringUtils.cleanAndParseInt(rawStat.substring(0, rawStat.length() - 1)); + } catch (NumberFormatException ignored) { + continue; + } + double realStat = (currentStat / scaledCurrentPower) * scaledMagicalPower; + + String format = this.format.format((double) Math.round(realStat)); + format += rawStat.substring(rawStat.length() - 1); + + event.toolTip.set(index, line.replace(rawStat, format)); + } + } + } + + private double scalePower(int magicalPower) { + return Math.pow(29.97 * (Math.log(0.0019 * magicalPower + 1)), 1.2); + } +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java b/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java index e1848382..ade9edfe 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java @@ -564,6 +564,8 @@ public class NEUConfig extends Config { public long dailyHeavyPearlCompleted = 0L; @Expose public HashMap<Integer, JsonObject> savedEquipment = new HashMap<>(); + @Expose + public int magicalPower = 0; } public HiddenLocationSpecific getLocationSpecific() { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/TooltipTweaks.java b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/TooltipTweaks.java index d1660e68..bcb7e8a7 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/TooltipTweaks.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/TooltipTweaks.java @@ -172,4 +172,12 @@ public class TooltipTweaks { minStep = 1f ) public int tooltipBorderOpacity = 200; + + @Expose + @ConfigOption( + name = "Power Stone Stats", + desc = "Show your real magical power and real stat increase on power stones" + ) + @ConfigEditorBoolean + public boolean powerStoneStats = true; } |