Skip to content

Commit

Permalink
Fix zero-division error when inserting previously-known items with re…
Browse files Browse the repository at this point in the history
…moved EMC values

Closes #15 and AllTheMods/All-the-mods-9-Sky#500
  • Loading branch information
62832 committed Jul 4, 2024
1 parent b420c33 commit f8111d9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/main/java/gripe/_90/appliede/me/service/EMCStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,11 @@ public long extractItem(AEItemKey what, long amount, Actionable mode, IActionSou
}

var itemEmc = BigInteger.valueOf(IEMCProxy.INSTANCE.getValue(what.toStack()));

if (itemEmc.signum() <= 0) {
return 0;
}

var totalEmc = itemEmc.multiply(BigInteger.valueOf(amount));

var providers = getProvidersForExtraction(source);
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/gripe/_90/appliede/me/service/KnowledgeService.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.entity.player.Player;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.OnDatapackSyncEvent;

import appeng.api.crafting.IPatternDetails;
import appeng.api.networking.IGrid;
Expand All @@ -37,6 +38,7 @@

import moze_intel.projecte.api.capabilities.IKnowledgeProvider;
import moze_intel.projecte.api.event.PlayerKnowledgeChangeEvent;
import moze_intel.projecte.api.proxy.IEMCProxy;
import moze_intel.projecte.api.proxy.ITransmutationProxy;

public class KnowledgeService implements IGridService, IGridServiceProvider {
Expand All @@ -59,6 +61,12 @@ public KnowledgeService(IGrid grid) {
knownItemCache = null;
updatePatterns();
});
MinecraftForge.EVENT_BUS.addListener((OnDatapackSyncEvent event) -> {
if (event.getPlayer() == null) {
knownItemCache = null;
updatePatterns();
}
});
}

@Override
Expand Down Expand Up @@ -167,6 +175,10 @@ public Set<AEItemKey> getKnownItems() {

for (var provider : getProviders()) {
for (var item : provider.getKnowledge()) {
if (!IEMCProxy.INSTANCE.hasValue(item)) {
continue;
}

var key = AEItemKey.of(item.createStack());

if (key != null) {
Expand Down

0 comments on commit f8111d9

Please sign in to comment.