diff --git a/src/main/java/de/ellpeck/prettypipes/network/PipeNetwork.java b/src/main/java/de/ellpeck/prettypipes/network/PipeNetwork.java index 8a90589..ac53498 100644 --- a/src/main/java/de/ellpeck/prettypipes/network/PipeNetwork.java +++ b/src/main/java/de/ellpeck/prettypipes/network/PipeNetwork.java @@ -217,7 +217,7 @@ public class PipeNetwork extends SavedData implements GraphListener(), equalityTypes).getLeft(); } - public Triple, ItemStack, Collection> requestLocksAndCrafts(BlockPos destPipe, Collection locations, Consumer unavailableConsumer, ItemStack stack, Stack dependencyChain, ItemEquality... equalityTypes) { + public Triple, ItemStack, Collection> requestLocksAndStartCrafting(BlockPos destPipe, Collection locations, Consumer unavailableConsumer, ItemStack stack, Stack dependencyChain, ItemEquality... equalityTypes) { List requests = new ArrayList<>(); var remain = stack.copy(); // check for existing items diff --git a/src/main/java/de/ellpeck/prettypipes/pipe/modules/craft/CraftingModuleItem.java b/src/main/java/de/ellpeck/prettypipes/pipe/modules/craft/CraftingModuleItem.java index 43c1a16..ccf9d03 100644 --- a/src/main/java/de/ellpeck/prettypipes/pipe/modules/craft/CraftingModuleItem.java +++ b/src/main/java/de/ellpeck/prettypipes/pipe/modules/craft/CraftingModuleItem.java @@ -15,7 +15,6 @@ import de.ellpeck.prettypipes.network.PipeNetwork; import de.ellpeck.prettypipes.pipe.PipeBlockEntity; import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer; import de.ellpeck.prettypipes.terminal.CraftingTerminalBlockEntity; -import de.ellpeck.prettypipes.terminal.ItemTerminalBlockEntity; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.core.component.DataComponentType; @@ -197,11 +196,14 @@ public class CraftingModuleItem extends ModuleItem { var copy = in.copy(); if (!contents.ensureItemOrder) copy.setCount(in.getCount() * toCraft); - var ret = network.requestLocksAndCrafts(tile.getBlockPos(), items, unavailableConsumer, copy, CraftingModuleItem.addDependency(dependencyChain, module), equalityTypes); + var ret = network.requestLocksAndStartCrafting(tile.getBlockPos(), items, unavailableConsumer, copy, CraftingModuleItem.addDependency(dependencyChain, module), equalityTypes); locks.addAll(ret.getLeft()); crafts.addAll(ret.getRight()); } } + // set crafting dependencies as in progress immediately so that, when canceling, they don't leave behind half-crafted inbetween dependencies + // TODO to be more optimal, we should really do this when setting the main craft as in progress, but that would require storing references to all of the dependencies + crafts.forEach(c -> c.inProgress = true); var remain = stack.copy(); remain.shrink(resultAmount * toCraft); diff --git a/src/main/java/de/ellpeck/prettypipes/terminal/ItemTerminalBlockEntity.java b/src/main/java/de/ellpeck/prettypipes/terminal/ItemTerminalBlockEntity.java index 3d43b8a..76d2e4f 100644 --- a/src/main/java/de/ellpeck/prettypipes/terminal/ItemTerminalBlockEntity.java +++ b/src/main/java/de/ellpeck/prettypipes/terminal/ItemTerminalBlockEntity.java @@ -32,7 +32,6 @@ import net.minecraft.world.level.block.state.BlockState; import net.neoforged.neoforge.items.ItemHandlerHelper; import net.neoforged.neoforge.items.ItemStackHandler; import org.apache.commons.lang3.tuple.Pair; -import org.apache.commons.lang3.tuple.Triple; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -171,7 +170,7 @@ public class ItemTerminalBlockEntity extends BlockEntity implements IPipeConnect var item = this.networkItems.get(new EquatableItemStack(stack, ItemEquality.NBT)); Collection locations = item == null ? Collections.emptyList() : item.getLocations(); var network = PipeNetwork.get(this.level); - var ret = network.requestLocksAndCrafts(this.getConnectedPipe().getBlockPos(), locations, unavailableConsumer, stack, new Stack<>(), ItemEquality.NBT); + var ret = network.requestLocksAndStartCrafting(this.getConnectedPipe().getBlockPos(), locations, unavailableConsumer, stack, new Stack<>(), ItemEquality.NBT); this.existingRequests.addAll(ret.getLeft()); return stack.getCount() - ret.getMiddle().getCount(); }