Skip to content

Commit

Permalink
Fix EMC storage not staying mounted when removing first-added module
Browse files Browse the repository at this point in the history
  • Loading branch information
62832 committed Apr 30, 2024
1 parent 751440d commit fc108fd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/main/java/gripe/_90/appliede/module/EMCModulePart.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}
}

Expand Down
29 changes: 18 additions & 11 deletions src/main/java/gripe/_90/appliede/service/KnowledgeService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -35,7 +37,7 @@
import moze_intel.projecte.api.proxy.ITransmutationProxy;

public class KnowledgeService implements IGridService, IGridServiceProvider {
private final List<EMCModulePart> modules = new ArrayList<>();
private final List<IManagedGridNode> moduleNodes = new ArrayList<>();
private final Map<UUID, Supplier<IKnowledgeProvider>> providers = new HashMap<>();
private final EMCStorage storage = new EMCStorage(this);

Expand All @@ -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) {
Expand All @@ -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();
}
}
Expand All @@ -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<IPatternDetails> getPatterns() {
Expand All @@ -114,9 +123,7 @@ public List<IPatternDetails> getPatterns() {
}

void updatePatterns() {
for (var module : modules) {
ICraftingProvider.requestUpdate(module.getMainNode());
}
moduleNodes.forEach(ICraftingProvider::requestUpdate);
}

@Nullable
Expand Down

0 comments on commit fc108fd

Please sign in to comment.