From 2d57900a61f1a979289c33e7f68e91e64529d655 Mon Sep 17 00:00:00 2001 From: Lorenz Date: Tue, 16 Aug 2022 18:13:22 +0200 Subject: moved tablist logic from mining overlay into seperate utils class, used tablist data to calculate pelts while on barn island, prefer this data over api data --- .../commands/dev/DevTestCommand.java | 10 ++++ .../miscgui/minionhelper/ApiData.java | 6 +- .../miscgui/minionhelper/MinionHelperManager.java | 15 +++++ .../loaders/MinionHelperApiLoader.java | 3 + .../loaders/MinionHelperInventoryLoader.java | 37 +++++++++--- .../notenoughupdates/overlays/MiningOverlay.java | 35 +---------- .../notenoughupdates/util/TabListUtils.java | 70 ++++++++++++++++++++++ 7 files changed, 133 insertions(+), 43 deletions(-) create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/util/TabListUtils.java (limited to 'src/main/java') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.java index ca4d3080..473bcc9d 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.java @@ -22,6 +22,7 @@ package io.github.moulberry.notenoughupdates.commands.dev; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.commands.ClientCommandBase; import io.github.moulberry.notenoughupdates.core.config.GuiPositionEditor; +import io.github.moulberry.notenoughupdates.core.util.MiscUtils; import io.github.moulberry.notenoughupdates.miscfeatures.FishingHelper; import io.github.moulberry.notenoughupdates.miscfeatures.customblockzones.CustomBiomes; import io.github.moulberry.notenoughupdates.miscfeatures.customblockzones.LocationChangeEvent; @@ -29,6 +30,7 @@ import io.github.moulberry.notenoughupdates.miscfeatures.customblockzones.Specia import io.github.moulberry.notenoughupdates.miscgui.GuiPriceGraph; import io.github.moulberry.notenoughupdates.miscgui.minionhelper.MinionHelperManager; import io.github.moulberry.notenoughupdates.util.SBInfo; +import io.github.moulberry.notenoughupdates.util.TabListUtils; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiScreen; @@ -182,5 +184,13 @@ public class DevTestCommand extends ClientCommandBase { if (args.length >= 1 && args[0].equalsIgnoreCase("minion")) { MinionHelperManager.getInstance().handleCommand(args); } + if (args.length == 1 && args[0].equalsIgnoreCase("copytablist")) { + StringBuilder builder = new StringBuilder(); + for (String name : TabListUtils.getTabList()) { + builder.append(name).append("\n"); + } + MiscUtils.copyToClipboard(builder.toString()); + Utils.addChatMessage("§e[NEU] Copied tablist to clipboard!"); + } } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/ApiData.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/ApiData.java index 62fda010..215c3fe7 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/ApiData.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/ApiData.java @@ -30,7 +30,7 @@ public class ApiData { private final int barbariansReputation; private final boolean collectionApiDisabled; private final List craftedMinions; - private final int peltCount; + private int peltCount; public ApiData( Map highestCollectionTier, @@ -77,4 +77,8 @@ public class ApiData { public int getPeltCount() { return peltCount; } + + public void setPeltCount(int peltCount) { + this.peltCount = peltCount; + } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/MinionHelperManager.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/MinionHelperManager.java index 6d7c9daa..78e51c0a 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/MinionHelperManager.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/MinionHelperManager.java @@ -45,6 +45,7 @@ public class MinionHelperManager { private static MinionHelperManager instance = null; private final Map minions = new HashMap<>(); private int needForNextSlot = -1; + private int localPelts = -1; private final MinionHelperPriceCalculation priceCalculation = new MinionHelperPriceCalculation(this); private final MinionHelperRequirementsManager requirementsManager = new MinionHelperRequirementsManager(this); @@ -258,4 +259,18 @@ public class MinionHelperManager { } minion.setCustomSource(customSource); } + + public int getLocalPelts() { + return localPelts; + } + + public void setLocalPelts(int pelts) { + localPelts = pelts; + if (localPelts != -1){ + ApiData apiData = api.getApiData(); + if (apiData != null) { + apiData.setPeltCount(localPelts); + } + } + } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/loaders/MinionHelperApiLoader.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/loaders/MinionHelperApiLoader.java index de0aff7e..15bcb1f0 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/loaders/MinionHelperApiLoader.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/loaders/MinionHelperApiLoader.java @@ -149,6 +149,9 @@ public class MinionHelperApiLoader { } private int loadPeltCount(JsonObject player) { + int localPelts = manager.getLocalPelts(); + if (localPelts != -1) return localPelts; + int peltCount = 0; if (player.has("trapper_quest")) { JsonObject jsonObject = player.getAsJsonObject("trapper_quest"); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/loaders/MinionHelperInventoryLoader.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/loaders/MinionHelperInventoryLoader.java index 3ff5a9c8..1e682618 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/loaders/MinionHelperInventoryLoader.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/loaders/MinionHelperInventoryLoader.java @@ -24,21 +24,24 @@ import io.github.moulberry.notenoughupdates.core.util.StringUtils; import io.github.moulberry.notenoughupdates.miscgui.minionhelper.Minion; import io.github.moulberry.notenoughupdates.miscgui.minionhelper.MinionHelperManager; import io.github.moulberry.notenoughupdates.util.ItemUtils; +import io.github.moulberry.notenoughupdates.util.TabListUtils; import net.minecraft.client.Minecraft; import net.minecraft.inventory.Container; import net.minecraft.inventory.ContainerChest; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; +import net.minecraftforge.event.world.WorldEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.gameevent.TickEvent; import java.util.ArrayList; import java.util.List; +import java.util.regex.Pattern; public class MinionHelperInventoryLoader { private final MinionHelperManager manager; private final List pagesSeenAlready = new ArrayList<>(); - private boolean shouldCheckNextSlot = true; + private boolean dirty = true; private int ticks = 0; @@ -46,6 +49,11 @@ public class MinionHelperInventoryLoader { this.manager = manager; } + @SubscribeEvent + public void onWorldLoad(WorldEvent.Load event) { + manager.setLocalPelts(-1); + } + @SubscribeEvent public void onTick(TickEvent.ClientTickEvent event) { if (!NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard()) return; @@ -59,25 +67,36 @@ public class MinionHelperInventoryLoader { checkInventory(); } else { pagesSeenAlready.clear(); - if (shouldCheckNextSlot) { - shouldCheckNextSlot = true; - } + dirty = true; } } private void checkInventory() { Container openContainer = Minecraft.getMinecraft().thePlayer.openContainer; if (openContainer instanceof ContainerChest) { - - if (shouldCheckNextSlot) { - shouldCheckNextSlot = false; + if (dirty) { + dirty = false; checkNextSlot(openContainer); + checkLocalPelts(); } - loadMinionData(openContainer); } } + private void checkLocalPelts() { + int pelts = -1; + for (String name : TabListUtils.getTabList()) { + if (name.startsWith("§r §r§fPelts: ")) { + name = name.replaceAll(Pattern.quote("§r"), ""); + String rawNumber = name.split("§5")[1]; + pelts = Integer.parseInt(rawNumber); + break; + } + } + + manager.setLocalPelts(pelts); + } + private void checkNextSlot(Container openContainer) { Slot informationSlot = openContainer.inventorySlots.get(50); if (informationSlot.getHasStack()) { @@ -141,6 +160,6 @@ public class MinionHelperInventoryLoader { } public void onProfileSwitch() { - shouldCheckNextSlot = true; + dirty = true; } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/overlays/MiningOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/overlays/MiningOverlay.java index 5dda0d85..8c87ba4c 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/overlays/MiningOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/overlays/MiningOverlay.java @@ -19,8 +19,6 @@ package io.github.moulberry.notenoughupdates.overlays; -import com.google.common.collect.ComparisonChain; -import com.google.common.collect.Ordering; import com.google.gson.annotations.Expose; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.core.config.Position; @@ -29,24 +27,19 @@ import io.github.moulberry.notenoughupdates.core.util.lerp.LerpUtils; import io.github.moulberry.notenoughupdates.miscfeatures.ItemCooldowns; import io.github.moulberry.notenoughupdates.options.NEUConfig; import io.github.moulberry.notenoughupdates.util.SBInfo; +import io.github.moulberry.notenoughupdates.util.TabListUtils; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.inventory.GuiChest; -import net.minecraft.client.network.NetworkPlayerInfo; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.init.Items; import net.minecraft.inventory.ContainerChest; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; -import net.minecraft.scoreboard.ScorePlayerTeam; import net.minecraft.util.EnumChatFormatting; -import net.minecraft.world.WorldSettings; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; import org.lwjgl.util.vector.Vector2f; import java.util.ArrayList; -import java.util.Comparator; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; @@ -262,11 +255,8 @@ public class MiningOverlay extends TextOverlay { int forgeInt = 0; boolean commissions = false; boolean forges = false; - List players = - playerOrdering.sortedCopy(Minecraft.getMinecraft().thePlayer.sendQueue.getPlayerInfoMap()); - for (NetworkPlayerInfo info : players) { - String name = Minecraft.getMinecraft().ingameGUI.getTabList().getPlayerName(info); + for (String name : TabListUtils.getTabList()) { if (name.contains("Mithril Powder:")) { mithrilPowder = DARK_AQUA + Utils.trimWhitespaceAndFormatCodes(name).replaceAll("\u00a7[f|F|r]", ""); continue; @@ -573,27 +563,6 @@ public class MiningOverlay extends TextOverlay { } } - private static final Ordering playerOrdering = Ordering.from(new PlayerComparator()); - - @SideOnly(Side.CLIENT) - static class PlayerComparator implements Comparator { - private PlayerComparator() {} - - public int compare(NetworkPlayerInfo o1, NetworkPlayerInfo o2) { - ScorePlayerTeam team1 = o1.getPlayerTeam(); - ScorePlayerTeam team2 = o2.getPlayerTeam(); - return ComparisonChain.start().compareTrueFirst( - o1.getGameType() != WorldSettings.GameType.SPECTATOR, - o2.getGameType() != WorldSettings.GameType.SPECTATOR - ) - .compare( - team1 != null ? team1.getRegisteredName() : "", - team2 != null ? team2.getRegisteredName() : "" - ) - .compare(o1.getGameProfile().getName(), o2.getGameProfile().getName()).result(); - } - } - @Override protected Vector2f getSize(List strings) { if (NotEnoughUpdates.INSTANCE.config.mining.dwarvenOverlayIcons) diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/TabListUtils.java b/src/main/java/io/github/moulberry/notenoughupdates/util/TabListUtils.java new file mode 100644 index 00000000..a0266122 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/util/TabListUtils.java @@ -0,0 +1,70 @@ +/* + * 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 . + */ + +package io.github.moulberry.notenoughupdates.util; + +import com.google.common.collect.ComparisonChain; +import com.google.common.collect.Ordering; +import net.minecraft.client.Minecraft; +import net.minecraft.client.network.NetworkPlayerInfo; +import net.minecraft.scoreboard.ScorePlayerTeam; +import net.minecraft.world.WorldSettings; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; + +public class TabListUtils { + + private static final Ordering playerOrdering = Ordering.from(new PlayerComparator()); + + @SideOnly(Side.CLIENT) + static class PlayerComparator implements Comparator { + private PlayerComparator() {} + + public int compare(NetworkPlayerInfo o1, NetworkPlayerInfo o2) { + ScorePlayerTeam team1 = o1.getPlayerTeam(); + ScorePlayerTeam team2 = o2.getPlayerTeam(); + return ComparisonChain.start().compareTrueFirst( + o1.getGameType() != WorldSettings.GameType.SPECTATOR, + o2.getGameType() != WorldSettings.GameType.SPECTATOR + ) + .compare( + team1 != null ? team1.getRegisteredName() : "", + team2 != null ? team2.getRegisteredName() : "" + ) + .compare(o1.getGameProfile().getName(), o2.getGameProfile().getName()).result(); + } + } + + public static List getTabList() { + List players = + playerOrdering.sortedCopy(Minecraft.getMinecraft().thePlayer.sendQueue.getPlayerInfoMap()); + + List result = new ArrayList<>(); + + for (NetworkPlayerInfo info : players) { + String name = Minecraft.getMinecraft().ingameGUI.getTabList().getPlayerName(info); + result.add(name); + } + return result; + } +} -- cgit