diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2022-08-17 09:38:24 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-17 09:38:24 +0200 |
commit | 5d2aa40fdee044c0579f426bff279b9d631e306f (patch) | |
tree | 9596afb42da307f874b0bb06ae5aeeae04465aea | |
parent | 1d23d88488f1266538275e3c069916c1fec58281 (diff) | |
download | NotEnoughUpdates-5d2aa40fdee044c0579f426bff279b9d631e306f.tar.gz NotEnoughUpdates-5d2aa40fdee044c0579f426bff279b9d631e306f.tar.bz2 NotEnoughUpdates-5d2aa40fdee044c0579f426bff279b9d631e306f.zip |
Probably fixing Lag spikes (#229)
* using method getOpenChestName instead of field lastOpenContainerName
* probably fixing lag spikes in power stone stats display
* using new getOpenChestName in EnchantingSolvers
8 files changed, 47 insertions, 49 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AbiphoneWarning.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AbiphoneWarning.java index 75584662..254c891a 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AbiphoneWarning.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AbiphoneWarning.java @@ -24,7 +24,7 @@ import io.github.moulberry.notenoughupdates.core.GuiElement; import io.github.moulberry.notenoughupdates.core.util.render.RenderUtils; import io.github.moulberry.notenoughupdates.core.util.render.TextRenderUtils; import io.github.moulberry.notenoughupdates.util.ItemUtils; -import io.github.moulberry.notenoughupdates.util.SBInfo; +import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Gui; import net.minecraft.client.gui.ScaledResolution; @@ -56,8 +56,7 @@ public class AbiphoneWarning extends GuiElement { return false; } - if (Minecraft.getMinecraft().currentScreen instanceof GuiChest && - SBInfo.getInstance().lastOpenContainerName.startsWith("Abiphone ")) { + if (Utils.getOpenChestName().startsWith("Abiphone ")) { return true; } else { showWarning = false; diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AuctionBINWarning.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AuctionBINWarning.java index 0d2d863d..3bd674dd 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AuctionBINWarning.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AuctionBINWarning.java @@ -24,7 +24,6 @@ import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.core.GuiElement; import io.github.moulberry.notenoughupdates.core.util.render.RenderUtils; import io.github.moulberry.notenoughupdates.core.util.render.TextRenderUtils; -import io.github.moulberry.notenoughupdates.util.SBInfo; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Gui; @@ -67,8 +66,7 @@ public class AuctionBINWarning extends GuiElement { return false; } - if (Minecraft.getMinecraft().currentScreen instanceof GuiChest && - SBInfo.getInstance().lastOpenContainerName.startsWith("Create BIN Auction")) { + if (Utils.getOpenChestName().startsWith("Create BIN Auction")) { return true; } else { sellingTooltip = null; diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AuctionSortModeWarning.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AuctionSortModeWarning.java index 97e32749..8ac0151a 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AuctionSortModeWarning.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AuctionSortModeWarning.java @@ -23,7 +23,6 @@ import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.core.util.render.RenderUtils; import io.github.moulberry.notenoughupdates.core.util.render.TextRenderUtils; import io.github.moulberry.notenoughupdates.mixins.AccessorGuiContainer; -import io.github.moulberry.notenoughupdates.util.SBInfo; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.inventory.GuiChest; @@ -41,9 +40,8 @@ public class AuctionSortModeWarning { private boolean isAuctionBrowser() { return NotEnoughUpdates.INSTANCE.config.ahTweaks.enableSortWarning && - Minecraft.getMinecraft().currentScreen instanceof GuiChest && - (SBInfo.getInstance().lastOpenContainerName.startsWith("Auctions Browser") || - SBInfo.getInstance().lastOpenContainerName.startsWith("Auctions: \"")); + (Utils.getOpenChestName().startsWith("Auctions Browser") || + Utils.getOpenChestName().startsWith("Auctions: \"")); } public void onPostGuiRender() { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/EnchantingSolvers.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/EnchantingSolvers.java index 1032fe16..b1ffcb2d 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/EnchantingSolvers.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/EnchantingSolvers.java @@ -96,20 +96,14 @@ public class EnchantingSolvers { return; } - if (event.gui instanceof GuiChest) { - GuiChest chest = (GuiChest) event.gui; - ContainerChest container = (ContainerChest) chest.inventorySlots; - String containerName = container.getLowerChestInventory().getDisplayName().getUnformattedText(); - String lower = containerName.toLowerCase(); - - if (!lower.contains("stakes")) { - if (lower.startsWith("chronomatron")) { - currentSolver = SolverType.CHRONOMATRON; - } else if (lower.startsWith("ultrasequencer")) { - currentSolver = SolverType.ULTRASEQUENCER; - } else if (lower.startsWith("superpairs")) { - currentSolver = SolverType.SUPERPAIRS; - } + String openChestName = Utils.getOpenChestName(); + if (!openChestName.contains("stakes")) { + if (openChestName.startsWith("chronomatron")) { + currentSolver = SolverType.CHRONOMATRON; + } else if (openChestName.startsWith("ultrasequencer")) { + currentSolver = SolverType.ULTRASEQUENCER; + } else if (openChestName.startsWith("superpairs")) { + currentSolver = SolverType.SUPERPAIRS; } } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/PowerStoneStatsDisplay.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/PowerStoneStatsDisplay.java index e62e572d..975bbe6e 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/PowerStoneStatsDisplay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/PowerStoneStatsDisplay.java @@ -23,15 +23,13 @@ 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 io.github.moulberry.notenoughupdates.util.Utils; 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.client.event.GuiOpenEvent; import net.minecraftforge.event.entity.player.ItemTooltipEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.gameevent.TickEvent; @@ -43,7 +41,8 @@ import java.util.Locale; public class PowerStoneStatsDisplay { private static PowerStoneStatsDisplay instance = null; - NumberFormat format = NumberFormat.getInstance(Locale.US); + private final NumberFormat format = NumberFormat.getInstance(Locale.US); + private boolean dirty = true; public static PowerStoneStatsDisplay getInstance() { if (instance == null) { @@ -54,14 +53,12 @@ public class PowerStoneStatsDisplay { @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 (!dirty) return; - if (!title.equals("SkyBlock Menu")) return; + if (!Utils.getOpenChestName().equals("SkyBlock Menu")) { + dirty = false; + return; + } EntityPlayerSP p = Minecraft.getMinecraft().thePlayer; Container openContainer = p.openContainer; @@ -78,12 +75,20 @@ public class PowerStoneStatsDisplay { NEUConfig.HiddenProfileSpecific configProfileSpecific = NotEnoughUpdates.INSTANCE.config.getProfileSpecific(); if (configProfileSpecific == null) return; configProfileSpecific.magicalPower = Integer.parseInt(rawNumber); + dirty = false; } } } } @SubscribeEvent + public void onGuiOpen(GuiOpenEvent event) { + if (event.gui != null) { + dirty = true; + } + } + + @SubscribeEvent public void onItemTooltipLow(ItemTooltipEvent event) { if (!NotEnoughUpdates.INSTANCE.config.tooltipTweaks.powerStoneStats) return; diff --git a/src/main/java/io/github/moulberry/notenoughupdates/overlays/AuctionSearchOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/overlays/AuctionSearchOverlay.java index e0e2c2d3..ed1185ec 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/overlays/AuctionSearchOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/overlays/AuctionSearchOverlay.java @@ -27,7 +27,6 @@ import io.github.moulberry.notenoughupdates.core.GuiScreenElementWrapper; import io.github.moulberry.notenoughupdates.mixins.AccessorGuiEditSign; import io.github.moulberry.notenoughupdates.options.NEUConfigEditor; import io.github.moulberry.notenoughupdates.util.Constants; -import io.github.moulberry.notenoughupdates.util.SBInfo; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Gui; @@ -106,9 +105,7 @@ public class AuctionSearchOverlay { return false; } - String lastContainer = SBInfo.getInstance().lastOpenContainerName; - - if (lastContainer == null) return false; + String lastContainer = Utils.getOpenChestName(); if (!lastContainer.equals("Auctions Browser") && !lastContainer.startsWith("Auctions: ")) return false; TileEntitySign tes = ((AccessorGuiEditSign) Minecraft.getMinecraft().currentScreen).getTileSign(); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/SBInfo.java b/src/main/java/io/github/moulberry/notenoughupdates/util/SBInfo.java index 9419be4f..8bd7c581 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/util/SBInfo.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/util/SBInfo.java @@ -88,7 +88,11 @@ public class SBInfo { public Date currentTimeDate = null; - public String lastOpenContainerName = ""; + /** + * Use Utils.getOpenChestName() instead + */ + @Deprecated + public String currentlyOpenChestName = ""; private long lastManualLocRaw = -1; private long lastLocRaw = -1; @@ -131,19 +135,18 @@ public class SBInfo { GuiChest chest = (GuiChest) event.gui; ContainerChest container = (ContainerChest) chest.inventorySlots; - lastOpenContainerName = container.getLowerChestInventory().getDisplayName().getUnformattedText(); + currentlyOpenChestName = container.getLowerChestInventory().getDisplayName().getUnformattedText(); + } else { + currentlyOpenChestName = ""; } } @SubscribeEvent public void onGuiTick(TickEvent event) { if (tickCount++ % 10 != 0) return; - GuiScreen currentScreen = Minecraft.getMinecraft().currentScreen; - if (currentScreen instanceof GuiChest) { - ContainerChest container = (ContainerChest) ((GuiChest) currentScreen).inventorySlots; - if ("Profile Management".equals(container.getLowerChestInventory().getDisplayName().getUnformattedText())) { - updateProfileInformation(container); - } + if (Utils.getOpenChestName().equals("Profile Management")) { + ContainerChest container = (ContainerChest) ((GuiChest) Minecraft.getMinecraft().currentScreen).inventorySlots; + updateProfileInformation(container); } } @@ -226,7 +229,7 @@ public class SBInfo { locraw = null; this.setLocation(null); joinedWorld = System.currentTimeMillis(); - lastOpenContainerName = ""; + currentlyOpenChestName = ""; hasNewTab = false; } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java b/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java index 5d6af2aa..d7b80a0e 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java @@ -1978,4 +1978,8 @@ public class Utils { } return -1; } + + public static String getOpenChestName() { + return SBInfo.getInstance().currentlyOpenChestName; + } } |