diff --git a/src/main/java/gripe/_90/appliede/module/EMCModulePart.java b/src/main/java/gripe/_90/appliede/module/EMCModulePart.java index d26a352..281ff90 100644 --- a/src/main/java/gripe/_90/appliede/module/EMCModulePart.java +++ b/src/main/java/gripe/_90/appliede/module/EMCModulePart.java @@ -89,7 +89,7 @@ public void mountInventories(IStorageMounts mounts) { var grid = getMainNode().getGrid(); if (grid != null) { - mounts.mount(grid.getService(KnowledgeService.class).getStorage(this)); + mounts.mount(grid.getService(KnowledgeService.class).getStorage(getMainNode())); } } diff --git a/src/main/java/gripe/_90/appliede/service/KnowledgeService.java b/src/main/java/gripe/_90/appliede/service/KnowledgeService.java index 9baf50f..956755d 100644 --- a/src/main/java/gripe/_90/appliede/service/KnowledgeService.java +++ b/src/main/java/gripe/_90/appliede/service/KnowledgeService.java @@ -22,8 +22,10 @@ import appeng.api.networking.IGridNode; import appeng.api.networking.IGridService; import appeng.api.networking.IGridServiceProvider; +import appeng.api.networking.IManagedGridNode; import appeng.api.networking.crafting.ICraftingProvider; import appeng.api.stacks.AEItemKey; +import appeng.api.storage.IStorageProvider; import appeng.api.storage.MEStorage; import appeng.me.storage.NullInventory; @@ -35,7 +37,7 @@ import moze_intel.projecte.api.proxy.ITransmutationProxy; public class KnowledgeService implements IGridService, IGridServiceProvider { - private final List modules = new ArrayList<>(); + private final List moduleNodes = new ArrayList<>(); private final Map> providers = new HashMap<>(); private final EMCStorage storage = new EMCStorage(this); @@ -57,7 +59,7 @@ public void addNode(IGridNode gridNode, @Nullable CompoundTag savedData) { } if (gridNode.getOwner() instanceof EMCModulePart module) { - modules.add(module); + moduleNodes.add(module.getMainNode()); var uuid = gridNode.getOwningPlayerProfileId(); if (uuid != null) { @@ -71,13 +73,20 @@ public void addNode(IGridNode gridNode, @Nullable CompoundTag savedData) { @Override public void removeNode(IGridNode gridNode) { if (gridNode.getOwner() instanceof EMCModulePart module) { - modules.remove(module); - var uuid = gridNode.getOwningPlayerProfileId(); + moduleNodes.remove(module.getMainNode()); + providers.clear(); - if (uuid != null) { - providers.remove(uuid); + for (var mainNode : moduleNodes) { + var node = mainNode.getNode(); + if (node == null) continue; + + var uuid = node.getOwningPlayerProfileId(); + if (uuid == null) continue; + + providers.put(uuid, () -> ITransmutationProxy.INSTANCE.getKnowledgeProviderFor(uuid)); } + moduleNodes.forEach(IStorageProvider::requestUpdate); updatePatterns(); } } @@ -90,8 +99,8 @@ public EMCStorage getStorage() { return storage; } - public MEStorage getStorage(EMCModulePart module) { - return !modules.isEmpty() && module.equals(modules.get(0)) ? storage : NullInventory.of(); + public MEStorage getStorage(IManagedGridNode node) { + return !moduleNodes.isEmpty() && node.equals(moduleNodes.get(0)) ? storage : NullInventory.of(); } public List getPatterns() { @@ -114,9 +123,7 @@ public List getPatterns() { } void updatePatterns() { - for (var module : modules) { - ICraftingProvider.requestUpdate(module.getMainNode()); - } + moduleNodes.forEach(ICraftingProvider::requestUpdate); } @Nullable