diff options
author | David Mills <85420839+Keebler408@users.noreply.github.com> | 2021-09-27 13:43:38 -0500 |
---|---|---|
committer | David Mills <85420839+Keebler408@users.noreply.github.com> | 2021-09-27 13:43:38 -0500 |
commit | 6a61e4e97006c8fe85581bea9d5f3fc0409ecfac (patch) | |
tree | 1aef72342490097dd9b024a21603eacc920b64b9 /src/main/java | |
parent | 4ce3332d0cacdfa6b621d5b60f4f8e9251a9fd40 (diff) | |
download | NotEnoughUpdates-6a61e4e97006c8fe85581bea9d5f3fc0409ecfac.tar.gz NotEnoughUpdates-6a61e4e97006c8fe85581bea9d5f3fc0409ecfac.tar.bz2 NotEnoughUpdates-6a61e4e97006c8fe85581bea9d5f3fc0409ecfac.zip |
Update per-location commissions to read commission type stack, not current player location
Diffstat (limited to 'src/main/java')
3 files changed, 137 insertions, 83 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java index 5fef4c62..40ae9899 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java @@ -723,6 +723,11 @@ public class NEUManager { return lore; } + public String getNameFromNBT(NBTTagCompound tag) { + NBTTagCompound display = tag.getCompoundTag("display"); + return display.getString("Name"); + } + public JsonObject getJsonFromNBT(NBTTagCompound tag) { return getJsonFromNBTEntry(tag.getTagList("i", 10).getCompoundTagAt(0)); } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java b/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java index d4a078a9..06619ffd 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java @@ -365,13 +365,19 @@ public class NEUConfig extends Config { } public HiddenLocationSpecific getLocationSpecific() { - if(SBInfo.getInstance().location == null) { - return null; - } - return hidden.locationSpecific.computeIfAbsent(SBInfo.getInstance().getLocation(), k-> new HiddenLocationSpecific()); + String location = SBInfo.getInstance().getLocation(); + if(location == null || location.isEmpty()) { + return null; } - public static class HiddenLocationSpecific { + return getLocationSpecific(location); + } + + public HiddenLocationSpecific getLocationSpecific(String location) { + return hidden.locationSpecific.computeIfAbsent(location, k-> new HiddenLocationSpecific()); + } + + public static class HiddenLocationSpecific { @Expose public Map<String, Integer> commissionMaxes = new HashMap<>(); } 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 7a888191..889647a8 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/overlays/MiningOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/overlays/MiningOverlay.java @@ -44,105 +44,148 @@ public class MiningOverlay extends TextOverlay { @Override public void updateFrequent() { - NEUConfig.HiddenProfileSpecific hidden = NotEnoughUpdates.INSTANCE.config.getProfileSpecific(); if(Minecraft.getMinecraft().currentScreen instanceof GuiChest) { GuiChest chest = (GuiChest) Minecraft.getMinecraft().currentScreen; ContainerChest container = (ContainerChest) chest.inventorySlots; IInventory lower = container.getLowerChestInventory(); String containerName = lower.getDisplayName().getUnformattedText(); - if(containerName.equals("Commissions") && lower.getSizeInventory() >= 18) { - for(int i=9; i<18; i++) { - ItemStack stack = lower.getStackInSlot(i); - if(stack != null && stack.hasTagCompound()) { - String[] lore = NotEnoughUpdates.INSTANCE.manager.getLoreFromNBT(stack.getTagCompound()); - String name = null; - int numberValue = -1; - for(String line : lore) { - if(name != null) { - String clean = Utils.cleanColour(line).trim(); - if(clean.isEmpty()) { - break; - } else { - Matcher matcher = NUMBER_PATTERN.matcher(clean); - if(matcher.find()) { - try { - numberValue = Integer.parseInt(matcher.group("number").replace(",", "")); - } catch(NumberFormatException ignored) {} - } + if(containerName.equals("Commissions") && lower.getSizeInventory() >= 27) { + UpdateCommissions(lower); + } else if(containerName.equals("Forge") && lower.getSizeInventory() >= 36) { + updateForge(lower); + } + } + } + + private void updateForge(IInventory lower) { + NEUConfig.HiddenProfileSpecific hidden = NotEnoughUpdates.INSTANCE.config.getProfileSpecific(); + if (hidden == null) { + return; + } + + itemLoop: + for (int i = 0; i < 5; i++) { + ItemStack stack = lower.getStackInSlot(i + 11); + if (stack != null) { + String[] lore = NotEnoughUpdates.INSTANCE.manager.getLoreFromNBT(stack.getTagCompound()); + + for (int i1 = 0; i1 < lore.length; i1++) { + String line = lore[i1]; + Matcher matcher = timeRemainingForge.matcher(line); + if (stack.getDisplayName().matches("\\xA7cSlot #([1-5])")) { + ForgeItem newForgeItem = new ForgeItem(i, 1, false); + replaceForgeOrAdd(newForgeItem, hidden.forgeItems, true); + //empty Slot + } else if (stack.getDisplayName().matches("\\xA7aSlot #([1-5])")) { + ForgeItem newForgeItem = new ForgeItem(i, 0, false); + replaceForgeOrAdd(newForgeItem, hidden.forgeItems, true); + } else if (matcher.matches()) { + String timeremainingString = matcher.group(1); + + long duration = 0; + + if (matcher.group("Completed") != null && !matcher.group("Completed").equals("")) { + ForgeItem newForgeItem = new ForgeItem(Utils.cleanColour(stack.getDisplayName()), 0, i, false); + replaceForgeOrAdd(newForgeItem, hidden.forgeItems, true); + } else { + + try { + if (matcher.group("days") != null && !matcher.group("days").equals("")) { + duration = duration + (long) Integer.parseInt(matcher.group("days")) * 24 * 60 * 60 * 1000; } - } - if(line.startsWith("\u00a77\u00a79")) { - String textAfter = line.substring(4); - if(!textAfter.contains("\u00a7") && !textAfter.equals("Rewards") && !textAfter.equals("Progress")) { - name = textAfter; + if (matcher.group("hours") != null && !matcher.group("hours").equals("")) { + duration = duration + (long) Integer.parseInt(matcher.group("hours")) * 60 * 60 * 1000; + } + if (matcher.group("minutes") != null && !matcher.group("minutes").equals("")) { + duration = duration + (long) Integer.parseInt(matcher.group("minutes")) * 60 * 1000; } + if (matcher.group("seconds") != null && !matcher.group("seconds").equals("")) { + duration = duration + (long) Integer.parseInt(matcher.group("seconds")) * 1000; + } + } catch (Exception ignored) { + } + if (duration > 0) { + ForgeItem newForgeItem = new ForgeItem(Utils.cleanColour(stack.getDisplayName()), System.currentTimeMillis() + duration, i, false); + replaceForgeOrAdd(newForgeItem, hidden.forgeItems, true); } } - NEUConfig.HiddenLocationSpecific locationSpecific = NotEnoughUpdates.INSTANCE.config.getLocationSpecific(); - if(name != null && numberValue > 0) { - locationSpecific.commissionMaxes.put(name, numberValue); - } + continue itemLoop; } } - } else if(containerName.equals("Forge") && lower.getSizeInventory() >= 36 && hidden != null) { - - itemLoop: - for (int i = 0; i < 5; i++) { - ItemStack stack = lower.getStackInSlot(i + 11); - if (stack != null) { - - String[] lore = NotEnoughUpdates.INSTANCE.manager.getLoreFromNBT(stack.getTagCompound()); - - for (int i1 = 0; i1 < lore.length; i1++) { - String line = lore[i1]; - Matcher matcher = timeRemainingForge.matcher(line); - if (stack.getDisplayName().matches("\\xA7cSlot #([1-5])")) { - ForgeItem newForgeItem = new ForgeItem(i, 1, false); - replaceForgeOrAdd(newForgeItem, hidden.forgeItems, true); - //empty Slot - } else if (stack.getDisplayName().matches("\\xA7aSlot #([1-5])")) { - ForgeItem newForgeItem = new ForgeItem(i, 0, false); - replaceForgeOrAdd(newForgeItem, hidden.forgeItems, true); - } else if (matcher.matches()) { - String timeremainingString = matcher.group(1); + //Locked Slot + } + } + } - long duration = 0; + private void UpdateCommissions(IInventory lower) { + // Get the location (type) of the currently shown commissions + ItemStack commTypeStack = lower.getStackInSlot(27); + if (commTypeStack == null || !commTypeStack.hasTagCompound()) + { + return; + } - if (matcher.group("Completed") != null && !matcher.group("Completed").equals("")) { - ForgeItem newForgeItem = new ForgeItem(Utils.cleanColour(stack.getDisplayName()), 0, i, false); - replaceForgeOrAdd(newForgeItem, hidden.forgeItems, true); - } else { + String name = Utils.cleanColour(NotEnoughUpdates.INSTANCE.manager.getNameFromNBT((commTypeStack.getTagCompound()))).trim(); + if (!name.equals("Switch Type")) + { + return; + } - try { - if (matcher.group("days") != null && !matcher.group("days").equals("")) { - duration = duration + (long) Integer.parseInt(matcher.group("days")) * 24 * 60 * 60 * 1000; - } - if (matcher.group("hours") != null && !matcher.group("hours").equals("")) { - duration = duration + (long) Integer.parseInt(matcher.group("hours")) * 60 * 60 * 1000; - } - if (matcher.group("minutes") != null && !matcher.group("minutes").equals("")) { - duration = duration + (long) Integer.parseInt(matcher.group("minutes")) * 60 * 1000; - } - if (matcher.group("seconds") != null && !matcher.group("seconds").equals("")) { - duration = duration + (long) Integer.parseInt(matcher.group("seconds")) * 1000; - } - } catch (Exception ignored) { - } - if (duration > 0) { - ForgeItem newForgeItem = new ForgeItem(Utils.cleanColour(stack.getDisplayName()), System.currentTimeMillis() + duration, i, false); - replaceForgeOrAdd(newForgeItem, hidden.forgeItems, true); - } - } + String commLocation = null; + String[] lore = NotEnoughUpdates.INSTANCE.manager.getLoreFromNBT(commTypeStack.getTagCompound()); + for(String line : lore) { + if (line == null) { + continue; + } + String cleanLine = Utils.cleanColour(line).trim(); + if (cleanLine.equals("Dwarven Mines")) { + commLocation = "mining_3"; + } else if (cleanLine.equals("Crystal Hollows")) { + commLocation = "crystal_hollows"; + } else { + continue; + } + break; + } + if (commLocation == null) { + return; + } - continue itemLoop; + // Now get the commission info + for(int i=9; i<18; i++) { + ItemStack stack = lower.getStackInSlot(i); + if(stack != null && stack.hasTagCompound()) { + lore = NotEnoughUpdates.INSTANCE.manager.getLoreFromNBT(stack.getTagCompound()); + String commName = null; + int numberValue = -1; + for(String line : lore) { + if(commName != null) { + String clean = Utils.cleanColour(line).trim(); + if(clean.isEmpty()) { + break; + } else { + Matcher matcher = NUMBER_PATTERN.matcher(clean); + if(matcher.find()) { + try { + numberValue = Integer.parseInt(matcher.group("number").replace(",", "")); + } catch(NumberFormatException ignored) {} } } - //Locked Slot - } + if(line.startsWith("\u00a77\u00a79")) { + String textAfter = line.substring(4); + if(!textAfter.contains("\u00a7") && !textAfter.equals("Rewards") && !textAfter.equals("Progress")) { + commName = textAfter; + } + } + } + + NEUConfig.HiddenLocationSpecific locationSpecific = NotEnoughUpdates.INSTANCE.config.getLocationSpecific(commLocation); + if(commName != null && numberValue > 0) { + locationSpecific.commissionMaxes.put(commName, numberValue); } } } |