Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added cleanup for the fake essentia items #80

Merged
merged 6 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -29,8 +31,16 @@ public void postChange(final IBaseMonitor<IAEItemStack> monitor, final Iterable<
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;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package thaumicenergistics.common.grid;

import java.util.HashSet;
import java.util.LinkedList;

import net.minecraft.item.ItemStack;

Expand Down Expand Up @@ -104,6 +105,8 @@ protected void updateCacheToMatchNetwork() {
// 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) {
Expand All @@ -118,13 +121,23 @@ protected void updateCacheToMatchNetwork() {
// Add the aspect
craftableAspects.add(aspect);
}

if (stack.getStackSize() > 0) {
toExtract.add(stack);
}
}
}

// Anything added?
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
Expand Down
Loading