Added cleanup for the fake essentia items (#80)

Co-authored-by: Martin Robertz <dream-master@gmx.net>
This commit is contained in:
RecursivePineappleandMartin Robertz authored and GitHub committed 2025-01-09 12:43:25 +01:00
1 parent bc8b7c0579
commit 0ac86e377c
2 files changed
+24 -1

No files matched your search

@@ -1,7 +1,9 @@
package thaumicenergistics.common.grid;
import appeng.api.config.Actionable;
import appeng.api.networking.security.BaseActionSource;
import appeng.api.networking.storage.IBaseMonitor;
import appeng.api.storage.IMEMonitor;
import appeng.api.storage.IMEMonitorHandlerReceiver;
import appeng.api.storage.data.IAEItemStack;
import thaumicenergistics.common.items.ItemCraftingAspect;
@@ -29,8 +31,16 @@ class CraftingAspect_ItemWatcher implements IMEMonitorHandlerReceiver<IAEItemSta
final BaseActionSource actionSource) {
for (IAEItemStack stack : change) {
// Is the stack craftable, has NBT tag, and is a crafting aspect?
if (stack.isCraftable() && stack.hasTagCompound() && (stack.getItem() instanceof ItemCraftingAspect)) {
if (stack.hasTagCompound() && (stack.getItem() instanceof ItemCraftingAspect)) {
this.gridCache.markForUpdate();
// Remove any fake aspect stacks in the ME system immediately
// We'll also try to remove any that snuck in another way (legacy items, etc) when updating the essentia
// cache
if (monitor instanceof IMEMonitor) {
((IMEMonitor<IAEItemStack>) monitor)
.extractItems(stack, Actionable.MODULATE, new BaseActionSource());
}
break;
}
}
@@ -1,6 +1,7 @@
package thaumicenergistics.common.grid;
import java.util.HashSet;
import java.util.LinkedList;
import net.minecraft.item.ItemStack;
@@ -104,6 +105,8 @@ public class GridEssentiaCache extends EssentiaMonitor implements IEssentiaGrid
// Create the aspect list
HashSet<Aspect> craftableAspects = new HashSet<Aspect>();
LinkedList<IAEItemStack> toExtract = new LinkedList<>();
// Check each item for craftability and type
for (IAEItemStack stack : storedItems) {
if (stack == null) {
@@ -118,6 +121,10 @@ public class GridEssentiaCache extends EssentiaMonitor implements IEssentiaGrid
// Add the aspect
craftableAspects.add(aspect);
}
if (stack.getStackSize() > 0) {
toExtract.add(stack);
}
}
}
@@ -125,6 +132,12 @@ public class GridEssentiaCache extends EssentiaMonitor implements IEssentiaGrid
if (craftableAspects.size() > 0) {
this.setCraftableAspects(craftableAspects);
}
// Remove any fake essentia stacks that snuck in somehow
BaseActionSource dummyActionSource = new BaseActionSource();
for (IAEItemStack stack : toExtract) {
itemMonitor.extractItems(stack, Actionable.MODULATE, dummyActionSource);
}
}
@Override