aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/de/cowtipper/cowlection/chesttracker/ChestInteractionListener.java15
-rw-r--r--src/main/java/de/cowtipper/cowlection/chesttracker/ChestOverviewGui.java10
-rw-r--r--src/main/java/de/cowtipper/cowlection/chesttracker/ChestTracker.java40
-rw-r--r--src/main/java/de/cowtipper/cowlection/command/MooCommand.java1
4 files changed, 64 insertions, 2 deletions
diff --git a/src/main/java/de/cowtipper/cowlection/chesttracker/ChestInteractionListener.java b/src/main/java/de/cowtipper/cowlection/chesttracker/ChestInteractionListener.java
index eea6988..be661ca 100644
--- a/src/main/java/de/cowtipper/cowlection/chesttracker/ChestInteractionListener.java
+++ b/src/main/java/de/cowtipper/cowlection/chesttracker/ChestInteractionListener.java
@@ -212,9 +212,20 @@ public class ChestInteractionListener {
Tessellator tessellator = Tessellator.getInstance();
WorldRenderer worldRenderer = tessellator.getWorldRenderer();
- GlStateManager.color(55 / 255f, 155 / 255f, 55 / 255f, 100 / 255f);
-
+ Set<BlockPos> chestsWithWantedItem = main.getChestTracker().getChestsWithWantedItem();
for (BlockPos chestPos : cachedChestPositions) {
+ if (chestsWithWantedItem.size() > 0) {
+ if (chestsWithWantedItem.contains(chestPos)) {
+ // chest has wanted item
+ GlStateManager.color(55 / 255f, 155 / 255f, 55 / 255f, 200 / 255f);
+ } else {
+ // chest doesn't have wanted item
+ GlStateManager.color(55 / 255f, 155 / 255f, 55 / 255f, 75 / 255f);
+ }
+ } else {
+ // no item search in progress
+ GlStateManager.color(55 / 255f, 155 / 255f, 55 / 255f, 100 / 255f);
+ }
EnumFacing otherChestFacing = main.getChestTracker().getOtherChestFacing(chestPos);
double chestPosXMin = chestPos.getX() - xMinOffset - (otherChestFacing == EnumFacing.WEST ? 1 : 0);
double chestPosXMax = chestPos.getX() - xMaxOffset + 1 + (otherChestFacing == EnumFacing.EAST ? 1 : 0);
diff --git a/src/main/java/de/cowtipper/cowlection/chesttracker/ChestOverviewGui.java b/src/main/java/de/cowtipper/cowlection/chesttracker/ChestOverviewGui.java
index e2be11b..6851779 100644
--- a/src/main/java/de/cowtipper/cowlection/chesttracker/ChestOverviewGui.java
+++ b/src/main/java/de/cowtipper/cowlection/chesttracker/ChestOverviewGui.java
@@ -39,6 +39,8 @@ public class ChestOverviewGui extends GuiScreen {
public ChestOverviewGui(Cowlection main) {
this.screenTitle = Cowlection.MODNAME + " Chest Analyzer";
this.main = main;
+ // clear wanted item chest highlighting
+ main.getChestTracker().getChestsWithWantedItem().clear();
}
@Override
@@ -344,6 +346,14 @@ public class ChestOverviewGui extends GuiScreen {
@Override
protected void elementClicked(int slotIndex, boolean isDoubleClick, int mouseX, int mouseY) {
+ if (!isDoubleClick) {
+ return;
+ }
+ ItemData itemData = itemDataHolder.get(slotIndex);
+ if (itemData != null) {
+ this.mc.displayGuiScreen(null);
+ main.getChestTracker().markChestsWithWantedItem(itemData.getKey(), itemData.getAmount(), itemData.getName());
+ }
}
@Override
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
}
diff --git a/src/main/java/de/cowtipper/cowlection/command/MooCommand.java b/src/main/java/de/cowtipper/cowlection/command/MooCommand.java
index 8bab5ee..396e6d1 100644
--- a/src/main/java/de/cowtipper/cowlection/command/MooCommand.java
+++ b/src/main/java/de/cowtipper/cowlection/command/MooCommand.java
@@ -696,6 +696,7 @@ public class MooCommand extends CommandBase {
main.getChatHelper().sendMessage(new MooChatComponent("Enabled chest tracker! You can now...").green()
.appendFreshSibling(new MooChatComponent(EnumChatFormatting.GREEN + " ❶ " + EnumChatFormatting.YELLOW + "add chests on your island by opening them; deselect chests by Sneaking + Right Click.").yellow())
.appendFreshSibling(new MooChatComponent(EnumChatFormatting.GREEN + " ❷ " + EnumChatFormatting.YELLOW + "use " + EnumChatFormatting.GOLD + analyzeCommand + EnumChatFormatting.YELLOW + " again to run the chest analysis.").yellow().setSuggestCommand(analyzeCommand))
+ .appendFreshSibling(new MooChatComponent(" (You can search for an item inside your chests by double clicking its analysis row)").gray().setSuggestCommand(analyzeCommand))
.appendFreshSibling(new MooChatComponent(EnumChatFormatting.GREEN + " ❸ " + EnumChatFormatting.YELLOW + "use " + EnumChatFormatting.GOLD + analyzeCommand + " stop" + EnumChatFormatting.YELLOW + " to stop the chest tracker and clear current results.").yellow().setSuggestCommand(analyzeCommand + " stop")));
} else {
main.getChatHelper().sendMessage(new MooChatComponent("Enabled chest tracker! " + EnumChatFormatting.GRAY + "Run " + analyzeCommand + " again to run the chest analysis.").green().setSuggestCommand(analyzeCommand));