aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorLorenz <lo.scherf@gmail.com>2022-08-16 18:13:22 +0200
committerLorenz <lo.scherf@gmail.com>2022-08-16 18:13:22 +0200
commit2d57900a61f1a979289c33e7f68e91e64529d655 (patch)
tree3974d2c80bb6c4b1bd9e1cbed390306b6310650c /src/main/java
parent9b7ee0259912ad1c6f7522f0dc2d158dd272b726 (diff)
downloadNotEnoughUpdates-2d57900a61f1a979289c33e7f68e91e64529d655.tar.gz
NotEnoughUpdates-2d57900a61f1a979289c33e7f68e91e64529d655.tar.bz2
NotEnoughUpdates-2d57900a61f1a979289c33e7f68e91e64529d655.zip
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
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.java10
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/ApiData.java6
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/MinionHelperManager.java15
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/loaders/MinionHelperApiLoader.java3
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/loaders/MinionHelperInventoryLoader.java37
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/overlays/MiningOverlay.java35
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/util/TabListUtils.java70
7 files changed, 133 insertions, 43 deletions
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<String> craftedMinions;
- private final int peltCount;
+ private int peltCount;
public ApiData(
Map<String, Integer> 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<String, Minion> 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<String> pagesSeenAlready = new ArrayList<>();
- private boolean shouldCheckNextSlot = true;
+ private boolean dirty = true;
private int ticks = 0;
@@ -47,6 +50,11 @@ public class MinionHelperInventoryLoader {
}
@SubscribeEvent
+ public void onWorldLoad(WorldEvent.Load event) {
+ manager.setLocalPelts(-1);
+ }
+
+ @SubscribeEvent
public void onTick(TickEvent.ClientTickEvent event) {
if (!NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard()) return;
if (!NotEnoughUpdates.INSTANCE.config.minionHelper.gui) 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<NetworkPlayerInfo> 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<NetworkPlayerInfo> playerOrdering = Ordering.from(new PlayerComparator());
-
- @SideOnly(Side.CLIENT)
- static class PlayerComparator implements Comparator<NetworkPlayerInfo> {
- 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<String> 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 <https://www.gnu.org/licenses/>.
+ */
+
+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<NetworkPlayerInfo> playerOrdering = Ordering.from(new PlayerComparator());
+
+ @SideOnly(Side.CLIENT)
+ static class PlayerComparator implements Comparator<NetworkPlayerInfo> {
+ 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<String> getTabList() {
+ List<NetworkPlayerInfo> players =
+ playerOrdering.sortedCopy(Minecraft.getMinecraft().thePlayer.sendQueue.getPlayerInfoMap());
+
+ List<String> result = new ArrayList<>();
+
+ for (NetworkPlayerInfo info : players) {
+ String name = Minecraft.getMinecraft().ingameGUI.getTabList().getPlayerName(info);
+ result.add(name);
+ }
+ return result;
+ }
+}