diff options
author | DoKM <54663875+DoKM@users.noreply.github.com> | 2021-09-27 21:06:35 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-27 21:06:35 +0200 |
commit | 007020ae547a88b2855479f69886bf42e1c4da5a (patch) | |
tree | fd4a98db21c23a14f9e95a0014dddf388a12f16d | |
parent | 4ce3332d0cacdfa6b621d5b60f4f8e9251a9fd40 (diff) | |
parent | 4da2b758d13b8ae443f1b2b84ec39e123c3b29f1 (diff) | |
download | NotEnoughUpdates-007020ae547a88b2855479f69886bf42e1c4da5a.tar.gz NotEnoughUpdates-007020ae547a88b2855479f69886bf42e1c4da5a.tar.bz2 NotEnoughUpdates-007020ae547a88b2855479f69886bf42e1c4da5a.zip |
Merge pull request #37 from Keebler408/master
Update commission location to use commission type stack, not player location
-rw-r--r-- | src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java | 16 | ||||
-rw-r--r-- | src/main/java/io/github/moulberry/notenoughupdates/overlays/MiningOverlay.java | 199 |
2 files changed, 132 insertions, 83 deletions
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..0943f120 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(commTypeStack.getDisplayName()).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); } } } |