From b70a7cae14b9bc50b2068303ba9278815fa3d313 Mon Sep 17 00:00:00 2001 From: 90 Date: Tue, 30 Apr 2024 13:56:06 +0100 Subject: [PATCH] Properly update crafting patterns in the event of EMC storage changing tiers --- .../_90/appliede/service/EMCStorage.java | 18 ++++++++++++- .../appliede/service/KnowledgeService.java | 26 +++++++++---------- 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/src/main/java/gripe/_90/appliede/service/EMCStorage.java b/src/main/java/gripe/_90/appliede/service/EMCStorage.java index 568c191..6e4fbe4 100644 --- a/src/main/java/gripe/_90/appliede/service/EMCStorage.java +++ b/src/main/java/gripe/_90/appliede/service/EMCStorage.java @@ -19,7 +19,14 @@ import moze_intel.projecte.api.proxy.IEMCProxy; -public record EMCStorage(KnowledgeService service) implements MEStorage { +public class EMCStorage implements MEStorage { + private final KnowledgeService service; + private int highestTier = 1; + + EMCStorage(KnowledgeService service) { + this.service = service; + } + @Override public void getAvailableStacks(KeyCounter out) { var emc = service.getEmc(); @@ -32,6 +39,11 @@ public void getAvailableStacks(KeyCounter out) { } out.add(EMCKey.tier(currentTier), emc.longValue()); + + if (highestTier != currentTier) { + highestTier = currentTier; + service.updatePatterns(); + } } @Override @@ -158,6 +170,10 @@ public long extractItem(AEItemKey what, long amount, Actionable mode, IActionSou return acquiredItems; } + public int getHighestTier() { + return highestTier; + } + @Override public Component getDescription() { return AppliedE.EMC_MODULE.get().getDescription(); diff --git a/src/main/java/gripe/_90/appliede/service/KnowledgeService.java b/src/main/java/gripe/_90/appliede/service/KnowledgeService.java index 16a026b..9baf50f 100644 --- a/src/main/java/gripe/_90/appliede/service/KnowledgeService.java +++ b/src/main/java/gripe/_90/appliede/service/KnowledgeService.java @@ -27,7 +27,6 @@ import appeng.api.storage.MEStorage; import appeng.me.storage.NullInventory; -import gripe._90.appliede.AppliedE; import gripe._90.appliede.module.EMCModulePart; import gripe._90.appliede.module.TransmutationPattern; @@ -44,11 +43,7 @@ public class KnowledgeService implements IGridService, IGridServiceProvider { private IGrid grid; public KnowledgeService() { - MinecraftForge.EVENT_BUS.addListener((PlayerKnowledgeChangeEvent event) -> { - for (var module : modules) { - ICraftingProvider.requestUpdate(module.getMainNode()); - } - }); + MinecraftForge.EVENT_BUS.addListener((PlayerKnowledgeChangeEvent event) -> updatePatterns()); } @Override @@ -68,6 +63,8 @@ public void addNode(IGridNode gridNode, @Nullable CompoundTag savedData) { if (uuid != null) { providers.put(uuid, () -> ITransmutationProxy.INSTANCE.getKnowledgeProviderFor(uuid)); } + + updatePatterns(); } } @@ -80,6 +77,8 @@ public void removeNode(IGridNode gridNode) { if (uuid != null) { providers.remove(uuid); } + + updatePatterns(); } } @@ -97,15 +96,8 @@ public MEStorage getStorage(EMCModulePart module) { public List getPatterns() { var patterns = new ArrayList(); - var emc = getEmc(); - var highestTier = 1; - - while (emc.divide(AppliedE.TIER_LIMIT).signum() == 1) { - emc = emc.divide(AppliedE.TIER_LIMIT); - highestTier++; - } - for (var tier = highestTier; tier > 1; tier--) { + for (var tier = storage.getHighestTier(); tier > 1; tier--) { patterns.add(new TransmutationPattern(null, tier)); } @@ -121,6 +113,12 @@ public List getPatterns() { return patterns; } + void updatePatterns() { + for (var module : modules) { + ICraftingProvider.requestUpdate(module.getMainNode()); + } + } + @Nullable public IGrid getGrid() { return grid;