aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/de/cowtipper/cowlection/chesttracker/ChestTracker.java
diff options
context:
space:
mode:
authorCow <cow@volloeko.de>2021-07-06 22:17:44 +0200
committerCow <cow@volloeko.de>2021-07-06 22:17:44 +0200
commitc01904870e61a4de4c3424787682e7bc214afa1d (patch)
treec9f1446db969b734dcbe8d6482ef96d7a5a1d3e6 /src/main/java/de/cowtipper/cowlection/chesttracker/ChestTracker.java
parent65e5ee4b431cc7513e53d61827249148b06de79a (diff)
downloadCowlection-c01904870e61a4de4c3424787682e7bc214afa1d.tar.gz
Cowlection-c01904870e61a4de4c3424787682e7bc214afa1d.tar.bz2
Cowlection-c01904870e61a4de4c3424787682e7bc214afa1d.zip
Added search-for-item functionality to Chest Tracker & Analyzer
Diffstat (limited to 'src/main/java/de/cowtipper/cowlection/chesttracker/ChestTracker.java')
-rw-r--r--src/main/java/de/cowtipper/cowlection/chesttracker/ChestTracker.java40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/main/java/de/cowtipper/cowlection/chesttracker/ChestTracker.java b/src/main/java/de/cowtipper/cowlection/chesttracker/ChestTracker.java
index 4ff6fe2..34d4a44 100644
--- a/src/main/java/de/cowtipper/cowlection/chesttracker/ChestTracker.java
+++ b/src/main/java/de/cowtipper/cowlection/chesttracker/ChestTracker.java
@@ -25,6 +25,7 @@ public class ChestTracker {
public static long lastLowestBinsUpdate;
private final Map<BlockPos, List<ItemStack>> chestCache = new HashMap<>();
private final Map<BlockPos, EnumFacing> doubleChestCache = new HashMap<>();
+ private final Set<BlockPos> chestsWithWantedItem = new HashSet<>();
private Map<String, ItemData> analysisResult = new HashMap<>();
private ChestInteractionListener chestInteractionListener;
private HyBazaarData bazaarCache;
@@ -167,6 +168,10 @@ public class ChestTracker {
return chestCache.keySet();
}
+ public Set<BlockPos> getChestsWithWantedItem() {
+ return chestsWithWantedItem;
+ }
+
public void clear() {
MinecraftForge.EVENT_BUS.unregister(chestInteractionListener);
chestInteractionListener = null;
@@ -174,6 +179,7 @@ public class ChestTracker {
lowestBinsCache = null;
chestCache.clear();
doubleChestCache.clear();
+ chestsWithWantedItem.clear();
analysisResult.clear();
}
@@ -216,6 +222,7 @@ public class ChestTracker {
}
}
chestCache.remove(mainChestPos);
+ chestsWithWantedItem.remove(mainChestPos);
}
private boolean isOtherChestCached(BlockPos chestPos, EnumFacing otherChestFacing) {
@@ -266,6 +273,39 @@ public class ChestTracker {
return lowestBinsCache == null || (System.currentTimeMillis() - lastLowestBinsUpdate) > 300000;
}
+ public void markChestsWithWantedItem(String sbKey, int amount, String itemName) {
+ // clear old search results
+ chestsWithWantedItem.clear();
+
+ if (sbKey.endsWith("_ambiguous")) {
+ sbKey = sbKey.substring(0, sbKey.length() - 10);
+ }
+ int relevantChests = 0;
+ for (Map.Entry<BlockPos, List<ItemStack>> chestCache : chestCache.entrySet()) {
+ boolean hasItemBeenFoundInChest = false;
+ for (ItemStack item : chestCache.getValue()) {
+ String key = item.hasDisplayName() ? item.getDisplayName() : item.getUnlocalizedName();
+ if (item.hasTagCompound()) {
+ key = item.getTagCompound().getCompoundTag("ExtraAttributes").getString("id");
+ }
+ if (sbKey.equals(key)) {
+ if (!hasItemBeenFoundInChest) {
+ chestsWithWantedItem.add(chestCache.getKey());
+ hasItemBeenFoundInChest = true;
+ ++relevantChests;
+ }
+ amount -= item.stackSize;
+ }
+ }
+ if (amount <= 0) {
+ // already found all relevant chests
+ break;
+ }
+ }
+ main.getChatHelper().sendMessage(EnumChatFormatting.GREEN, "Chest Tracker & Analyzer is now highlighting " + EnumChatFormatting.LIGHT_PURPLE + relevantChests + EnumChatFormatting.GREEN + " chest" + (relevantChests > 1 ? "s" : "") + " with " + itemName
+ + EnumChatFormatting.GREEN + ". Re-opening the chest analysis results with " + EnumChatFormatting.GRAY + "/moo analyzeChests " + EnumChatFormatting.GREEN + "clears the current search.");
+ }
+
public enum Updating {
UNDEFINED, BAZAAR, LOWEST_BINS
}