Skip to content

Commit

Permalink
Properly update crafting patterns in the event of EMC storage changin…
Browse files Browse the repository at this point in the history
…g tiers
  • Loading branch information
62832 committed Apr 30, 2024
1 parent 3e5d855 commit b70a7ca
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 15 deletions.
18 changes: 17 additions & 1 deletion src/main/java/gripe/_90/appliede/service/EMCStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -32,6 +39,11 @@ public void getAvailableStacks(KeyCounter out) {
}

out.add(EMCKey.tier(currentTier), emc.longValue());

if (highestTier != currentTier) {
highestTier = currentTier;
service.updatePatterns();
}
}

@Override
Expand Down Expand Up @@ -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();
Expand Down
26 changes: 12 additions & 14 deletions src/main/java/gripe/_90/appliede/service/KnowledgeService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
Expand All @@ -68,6 +63,8 @@ public void addNode(IGridNode gridNode, @Nullable CompoundTag savedData) {
if (uuid != null) {
providers.put(uuid, () -> ITransmutationProxy.INSTANCE.getKnowledgeProviderFor(uuid));
}

updatePatterns();
}
}

Expand All @@ -80,6 +77,8 @@ public void removeNode(IGridNode gridNode) {
if (uuid != null) {
providers.remove(uuid);
}

updatePatterns();
}
}

Expand All @@ -97,15 +96,8 @@ public MEStorage getStorage(EMCModulePart module) {

public List<IPatternDetails> getPatterns() {
var patterns = new ArrayList<IPatternDetails>();
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));
}

Expand All @@ -121,6 +113,12 @@ public List<IPatternDetails> getPatterns() {
return patterns;
}

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

@Nullable
public IGrid getGrid() {
return grid;
Expand Down

0 comments on commit b70a7ca

Please sign in to comment.