diff options
author | Lorenz <lo.scherf@gmail.com> | 2022-07-30 23:40:04 +0200 |
---|---|---|
committer | Lorenz <lo.scherf@gmail.com> | 2022-07-30 23:40:04 +0200 |
commit | 6b0c7602ec6d919ae45bd8aa1cc8b8534cb6c6e6 (patch) | |
tree | ae17b542f1104b96e5b06e296242a43cbfd44229 | |
parent | 580d851b50fc62762d7e1e31949298f27d90a99a (diff) | |
download | NotEnoughUpdates-6b0c7602ec6d919ae45bd8aa1cc8b8534cb6c6e6.tar.gz NotEnoughUpdates-6b0c7602ec6d919ae45bd8aa1cc8b8534cb6c6e6.tar.bz2 NotEnoughUpdates-6b0c7602ec6d919ae45bd8aa1cc8b8534cb6c6e6.zip |
lowered MinionSource usage and removed internal minion field
11 files changed, 37 insertions, 50 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/Minion.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/Minion.java index e4307efa..e712b134 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/Minion.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/Minion.java @@ -19,13 +19,14 @@ package io.github.moulberry.notenoughupdates.miscgui.minionhelper; +import io.github.moulberry.notenoughupdates.miscgui.minionhelper.render.renderables.RenderableObject; import io.github.moulberry.notenoughupdates.miscgui.minionhelper.requirements.MinionRequirement; import io.github.moulberry.notenoughupdates.miscgui.minionhelper.sources.MinionSource; import java.util.ArrayList; import java.util.List; -public class Minion { +public class Minion extends RenderableObject { private final String internalName; private final int tier; private String displayName; diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/loaders/repo/MinionHelperRepoLoader.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/loaders/repo/MinionHelperRepoLoader.java index 5e96f377..41ef1118 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/loaders/repo/MinionHelperRepoLoader.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/loaders/repo/MinionHelperRepoLoader.java @@ -113,7 +113,7 @@ public class MinionHelperRepoLoader { String sourceName = entry.getValue(); Minion minion = manager.getMinionById(internalName); if (minion == null) continue; - minion.setMinionSource(new CustomSource(minion, sourceName)); + minion.setMinionSource(new CustomSource(sourceName)); } manager.getMinionById("FLOWER_GENERATOR_1").getRequirements().add(new CustomRequirement( @@ -163,7 +163,7 @@ public class MinionHelperRepoLoader { map.removeAll("SKYBLOCK_COIN"); } - minion.setMinionSource(new NpcSource(minion, npcName, coins, builder.getItems())); + minion.setMinionSource(new NpcSource(npcName, coins, builder.getItems())); minion.setParent(builder.getParent()); } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/loaders/repo/MinionHelperRepoMinionLoader.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/loaders/repo/MinionHelperRepoMinionLoader.java index 3ca88790..6abc5c56 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/loaders/repo/MinionHelperRepoMinionLoader.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/loaders/repo/MinionHelperRepoMinionLoader.java @@ -126,7 +126,7 @@ public class MinionHelperRepoMinionLoader { builder.addLine(minion, rawString); } - minion.setMinionSource(new CraftingSource(minion, builder.getItems())); + minion.setMinionSource(new CraftingSource(builder.getItems())); minion.setParent(builder.getParent()); } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/render/MinionHelperOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/render/MinionHelperOverlay.java index b1d12fe0..1c12bc8e 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/render/MinionHelperOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/render/MinionHelperOverlay.java @@ -105,9 +105,10 @@ public class MinionHelperOverlay { RenderableObject mouseObject = getObjectOverMouse(getRenderMap()); if (mouseObject != null) { - if (mouseObject instanceof MinionSource) { + if (mouseObject instanceof Minion) { + event.setCanceled(true); - Minion minion = ((MinionSource) mouseObject).getMinion(); + Minion minion = ((Minion) mouseObject); NotEnoughUpdates.INSTANCE.manager.displayGuiItemRecipe(minion.getInternalName()); } } @@ -119,7 +120,7 @@ public class MinionHelperOverlay { if (!minion.doesMeetRequirements() && !shift) continue; if (!minion.isCrafted()) { - long price = manager.getPriceCalculation().calculateUpgradeCosts(minion.getMinionSource(), true); + long price = manager.getPriceCalculation().calculateUpgradeCosts(minion, true); prices.put(minion, price); } } @@ -146,8 +147,8 @@ public class MinionHelperOverlay { String line = entry.getKey(); RenderableObject renderableObject = entry.getValue(); String prefix = ""; - if (renderableObject instanceof MinionSource) { - Minion minion = ((MinionSource) renderableObject).getMinion(); + if (renderableObject instanceof Minion) { + Minion minion = (Minion) renderableObject; if (minion == hover.getLastHovered()) { prefix = "§e"; } @@ -190,11 +191,11 @@ public class MinionHelperOverlay { continue; } displayName = displayName.replace(" Minion", ""); - String format = manager.getPriceCalculation().calculateUpgradeCostsFormat(minion.getMinionSource(), true); + String format = manager.getPriceCalculation().calculateUpgradeCostsFormat(minion, true); String requirementFormat = !minion.doesMeetRequirements() ? "§7§o" : ""; renderMap.put( requirementFormat + displayName + "§r " + requirementFormat + minion.getTier() + " §r§8- " + format, - minion.getMinionSource() + minion ); i++; diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/render/MinionHelperOverlayHover.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/render/MinionHelperOverlayHover.java index f04b5200..c7ae6b53 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/render/MinionHelperOverlayHover.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/render/MinionHelperOverlayHover.java @@ -84,14 +84,14 @@ public class MinionHelperOverlayHover { if (renderableObject instanceof RenderableText) { RenderableText renderableText = (RenderableText) renderableObject; lines.addAll(renderableText.getLines()); - } else if (renderableObject instanceof MinionSource) { - MinionSource minionSource = (MinionSource) renderableObject; + } else if (renderableObject instanceof Minion) { - Minion minion = minionSource.getMinion(); + Minion minion = (Minion) renderableObject; + MinionSource minionSource = minion.getMinionSource(); lastHovered = minion; String displayName = minion.getDisplayName(); lines.add("§9" + displayName + " " + minion.getTier()); - List<MinionRequirement> requirements = manager.getRequirementsManager().getRequirements(minionSource.getMinion()); + List<MinionRequirement> requirements = manager.getRequirementsManager().getRequirements(minion); if (!requirements.isEmpty()) { for (MinionRequirement requirement : requirements) { //TODO maybe change the §7 color @@ -108,7 +108,7 @@ public class MinionHelperOverlayHover { if (minionSource instanceof CraftingSource) { CraftingSource craftingSource = (CraftingSource) minionSource; lines.add(""); - String format = manager.getPriceCalculation().calculateUpgradeCostsFormat(craftingSource, true); + String format = manager.getPriceCalculation().calculateUpgradeCostsFormat(minion, true); if (minion.getTier() == 1) { lines.add("§7Full crafting costs: " + format); } else { @@ -122,7 +122,7 @@ public class MinionHelperOverlayHover { lines.add(""); lines.add("§7Buy from: §9" + npcName + " (NPC)"); lines.add(""); - lines.add("§7Buy costs: " + manager.getPriceCalculation().calculateUpgradeCostsFormat(npcSource, true)); + lines.add("§7Buy costs: " + manager.getPriceCalculation().calculateUpgradeCostsFormat(minion, true)); lines.add(" §8- " + manager.getPriceCalculation().formatCoins(npcSource.getCoins())); formatItems(lines, grabAllItems(npcSource.getItems())); } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/render/MinionHelperTooltips.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/render/MinionHelperTooltips.java index f18c6edc..3638b029 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/render/MinionHelperTooltips.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/render/MinionHelperTooltips.java @@ -76,7 +76,7 @@ public class MinionHelperTooltips { System.err.println("minionSource is null for " + minion.getInternalName()); continue; } - String format = manager.getPriceCalculation().calculateUpgradeCostsFormat(minionSource, !showFullCost); + String format = manager.getPriceCalculation().calculateUpgradeCostsFormat(minion, !showFullCost); event.toolTip.set(index, line + " §8- " + format); } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/sources/CraftingSource.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/sources/CraftingSource.java index 1c0f0747..08f27b35 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/sources/CraftingSource.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/sources/CraftingSource.java @@ -26,8 +26,7 @@ public class CraftingSource extends MinionSource { //name -> amount private final ArrayListMultimap<String, Integer> items; - public CraftingSource(Minion minion, ArrayListMultimap<String, Integer> items) { - super(minion); + public CraftingSource(ArrayListMultimap<String, Integer> items) { this.items = items; } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/sources/CustomSource.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/sources/CustomSource.java index 45a8bf08..cf260a88 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/sources/CustomSource.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/sources/CustomSource.java @@ -19,14 +19,11 @@ package io.github.moulberry.notenoughupdates.miscgui.minionhelper.sources; -import io.github.moulberry.notenoughupdates.miscgui.minionhelper.Minion; - public class CustomSource extends MinionSource { private final String sourceName; - public CustomSource(Minion minion, String sourceName) { - super(minion); + public CustomSource(String sourceName) { this.sourceName = sourceName; } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/sources/MinionSource.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/sources/MinionSource.java index fcc6018c..f54f0845 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/sources/MinionSource.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/sources/MinionSource.java @@ -19,18 +19,5 @@ package io.github.moulberry.notenoughupdates.miscgui.minionhelper.sources; -import io.github.moulberry.notenoughupdates.miscgui.minionhelper.Minion; -import io.github.moulberry.notenoughupdates.miscgui.minionhelper.render.renderables.RenderableObject; - -public abstract class MinionSource extends RenderableObject { - private final Minion minion; - - public MinionSource(Minion minion) { - this.minion = minion; - } - - //TODO remove later maybe? - public Minion getMinion() { - return minion; - } +public abstract class MinionSource { } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/sources/NpcSource.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/sources/NpcSource.java index 9bb6d7b4..5acf5841 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/sources/NpcSource.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/sources/NpcSource.java @@ -28,8 +28,7 @@ public class NpcSource extends MinionSource { private final ArrayListMultimap<String, Integer> items; private int coins = 0; - public NpcSource(Minion minion, String npcName, int coins, ArrayListMultimap<String, Integer> items) { - super(minion); + public NpcSource(String npcName, int coins, ArrayListMultimap<String, Integer> items) { this.npcName = npcName; this.coins = coins; this.items = items; diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/util/MinionHelperPriceCalculation.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/util/MinionHelperPriceCalculation.java index f1a92b57..6bcae3a7 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/util/MinionHelperPriceCalculation.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/util/MinionHelperPriceCalculation.java @@ -63,9 +63,11 @@ public class MinionHelperPriceCalculation { fullCostFormatCache.clear(); } - public String calculateUpgradeCostsFormat(MinionSource source, boolean upgradeOnly) { + public String calculateUpgradeCostsFormat(Minion minion, boolean upgradeOnly) { + MinionSource source = minion.getMinionSource(); + if (source == null) return "§c?"; - String internalName = source.getMinion().getInternalName(); + String internalName = minion.getInternalName(); if (upgradeOnly) { if (upgradeCostFormatCache.containsKey(internalName)) { upgradeCostFormatCache.get(internalName); @@ -80,7 +82,7 @@ public class MinionHelperPriceCalculation { return "§f" + ((CustomSource) source).getSourceName(); } - long costs = calculateUpgradeCosts(source, upgradeOnly); + long costs = calculateUpgradeCosts(minion, upgradeOnly); String result = formatCoins(costs, !upgradeOnly ? "§o" : ""); if (source instanceof NpcSource) { @@ -100,14 +102,15 @@ public class MinionHelperPriceCalculation { return result; } - public long calculateUpgradeCosts(MinionSource source, boolean upgradeOnly) { + public long calculateUpgradeCosts(Minion minion, boolean upgradeOnly) { + MinionSource source = minion.getMinionSource(); if (source instanceof CraftingSource) { CraftingSource craftingSource = (CraftingSource) source; - return getCosts(source, upgradeOnly, craftingSource.getItems()); + return getCosts(minion, upgradeOnly, craftingSource.getItems()); } else if (source instanceof NpcSource) { NpcSource npcSource = (NpcSource) source; - long upgradeCost = getCosts(source, upgradeOnly, npcSource.getItems()); + long upgradeCost = getCosts(minion, upgradeOnly, npcSource.getItems()); long coins = npcSource.getCoins(); upgradeCost += coins; @@ -117,7 +120,7 @@ public class MinionHelperPriceCalculation { return 0; } - private long getCosts(MinionSource source, boolean upgradeOnly, ArrayListMultimap<String, Integer> items) { + private long getCosts(Minion minion, boolean upgradeOnly, ArrayListMultimap<String, Integer> items) { long upgradeCost = 0; for (Map.Entry<String, Integer> entry : items.entries()) { String internalName = entry.getKey(); @@ -126,9 +129,9 @@ public class MinionHelperPriceCalculation { upgradeCost += price * amount; } if (!upgradeOnly) { - Minion parent = source.getMinion().getParent(); + Minion parent = minion.getParent(); if (parent != null) { - upgradeCost += calculateUpgradeCosts(parent.getMinionSource(), false); + upgradeCost += calculateUpgradeCosts(parent, false); } } return upgradeCost; @@ -138,7 +141,7 @@ public class MinionHelperPriceCalculation { JsonObject bazaarInfo = NotEnoughUpdates.INSTANCE.manager.auctionManager.getBazaarInfo(internalName); if (bazaarInfo == null) { if (internalName.contains("_GENERATOR_")) { - return calculateUpgradeCosts(manager.getMinionById(internalName).getMinionSource(), false); + return calculateUpgradeCosts(manager.getMinionById(internalName), false); } else { if (!cheapItems.contains(internalName)) { return (long) NotEnoughUpdates.INSTANCE.manager.auctionManager.getItemAvgBin(internalName); |