mirror of
https://github.com/GTNewHorizons/Applied-Energistics-2-Unofficial.git
synced 2026-10-25 20:22:23 +00:00
Fix crash when a crafting job completes with the crafting log enabled (#1698)
This commit is contained in:
1 parent
ab15e3a725
commit
4071b0fa29
2 files changed
+53
-2
No files matched your search
+52
-1
@@ -24,9 +24,12 @@ import appeng.api.networking.crafting.ICraftingGrid;
|
||||
import appeng.api.networking.crafting.ICraftingMedium;
|
||||
import appeng.api.networking.crafting.ICraftingPatternDetails;
|
||||
import appeng.api.networking.energy.IEnergyGrid;
|
||||
import appeng.api.networking.security.BaseActionSource;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
import appeng.api.util.WorldCoord;
|
||||
import appeng.core.AEConfig;
|
||||
import appeng.core.features.AEFeature;
|
||||
import appeng.helpers.PatternHelper;
|
||||
import appeng.me.cache.CraftingGridCache;
|
||||
import appeng.me.cluster.implementations.CraftingCPUCluster;
|
||||
@@ -169,10 +172,50 @@ public class CraftingCPUClusterFunctionalTest {
|
||||
assertEquals(2, cpu.core.dirtyNotifications, "Notifications outside the update must remain immediate");
|
||||
}
|
||||
|
||||
@Test
|
||||
void craftingLogDoesNotBreakJobCompletion() {
|
||||
cpu.prepare(pattern, 64, 128);
|
||||
cpu.trackFinalOutput(64);
|
||||
cpu.setStartItemCount(7);
|
||||
final long[] reportedCount = { -1 };
|
||||
cpu.addOnCompleteListener((output, count, elapsedTime) -> reportedCount[0] = count);
|
||||
tick();
|
||||
|
||||
withCraftingLog(
|
||||
() -> cpu.injectItems(
|
||||
AEItemStack.create(new ItemStack(Blocks.stone)).setStackSize(512),
|
||||
Actionable.MODULATE,
|
||||
new BaseActionSource()));
|
||||
|
||||
assertAll(
|
||||
() -> assertTrue(cpu.completed()),
|
||||
() -> assertEquals(512, reportedCount[0], "The crafting log must not change the reported output"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void craftingLogDoesNotBreakFakeCraftingCompletion() {
|
||||
cpu.prepare(pattern, 64, 128);
|
||||
cpu.enableFakeCrafting(64);
|
||||
|
||||
withCraftingLog(this::tick);
|
||||
|
||||
assertTrue(cpu.completed());
|
||||
}
|
||||
|
||||
private void tick() {
|
||||
cpu.updateCraftingLogic(grid, energy, cache);
|
||||
}
|
||||
|
||||
private static void withCraftingLog(Runnable action) {
|
||||
final boolean wasEnabled = AEConfig.instance.isFeatureEnabled(AEFeature.CraftingLog);
|
||||
AEConfig.instance.featureFlags.add(AEFeature.CraftingLog);
|
||||
try {
|
||||
action.run();
|
||||
} finally {
|
||||
if (!wasEnabled) AEConfig.instance.featureFlags.remove(AEFeature.CraftingLog);
|
||||
}
|
||||
}
|
||||
|
||||
private static ICraftingPatternDetails processingPattern() {
|
||||
final ItemStack encoded = AEApi.instance().definitions().items().encodedPattern().maybeStack(1).get();
|
||||
final NBTTagCompound tag = new NBTTagCompound();
|
||||
@@ -207,8 +250,16 @@ public class CraftingCPUClusterFunctionalTest {
|
||||
Actionable.MODULATE);
|
||||
}
|
||||
|
||||
private void enableFakeCrafting(int crafts) {
|
||||
private void setStartItemCount(long count) {
|
||||
startItemCount = count;
|
||||
}
|
||||
|
||||
private void trackFinalOutput(int crafts) {
|
||||
finalOutput.init(AEItemStack.create(new ItemStack(Blocks.stone)).setStackSize(crafts * 8L));
|
||||
}
|
||||
|
||||
private void enableFakeCrafting(int crafts) {
|
||||
trackFinalOutput(crafts);
|
||||
finalOutput.setFakeCrafting();
|
||||
}
|
||||
|
||||
|
||||
@@ -576,7 +576,7 @@ public class CraftingCPUCluster implements IAECluster, ICraftingCPU {
|
||||
}
|
||||
|
||||
if (AELog.isCraftingLogEnabled()) {
|
||||
final IAEStack<?> logStack = this.finalOutput.get();
|
||||
final IAEStack<?> logStack = this.finalOutput.getOriginalOutput().copy();
|
||||
logStack.setStackSize(this.startItemCount);
|
||||
AELog.crafting(LOG_MARK_AS_COMPLETE, logStack);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user