fixed crafting requests always returning the full crafted items, rather than the requested amount

This commit is contained in:
Ell 2024-12-03 23:11:51 +01:00
parent 21f2727b32
commit fb59109d08

View file

@ -92,6 +92,11 @@ public class CraftingModuleItem extends ModuleItem {
} }
network.endProfile(); network.endProfile();
} else if (craft.travelingIngredients.isEmpty()) { } else if (craft.travelingIngredients.isEmpty()) {
if (craft.resultStackRemain.isEmpty()) {
// the result stack is empty from the start if this was a partial craft whose results shouldn't be delivered anywhere
// (ie someone requested 3 sticks with ensureItemOrder, but the recipe always makes 4, so the 4th recipe has no destination)
crafts.remove(craft);
} else {
// pull requested crafting results from the network once they are stored // pull requested crafting results from the network once they are stored
network.startProfile("crafting_results"); network.startProfile("crafting_results");
var items = network.getOrderedNetworkItems(tile.getBlockPos()); var items = network.getOrderedNetworkItems(tile.getBlockPos());
@ -115,6 +120,7 @@ public class CraftingModuleItem extends ModuleItem {
} }
} }
} }
}
@Override @Override
public List<ItemStack> getAllCraftables(ItemStack module, PipeBlockEntity tile) { public List<ItemStack> getAllCraftables(ItemStack module, PipeBlockEntity tile) {
@ -167,6 +173,7 @@ public class CraftingModuleItem extends ModuleItem {
var craftableCrafts = Mth.ceil(craftableAmount / (float) resultAmount); var craftableCrafts = Mth.ceil(craftableAmount / (float) resultAmount);
var toCraft = Math.min(craftableCrafts, requiredCrafts); var toCraft = Math.min(craftableCrafts, requiredCrafts);
var leftOfRequest = stack.getCount();
var allCrafts = new ArrayList<ActiveCraft>(); var allCrafts = new ArrayList<ActiveCraft>();
// if we're ensuring item order, all items for a single recipe should be sent in order first before starting on the next one! // if we're ensuring item order, all items for a single recipe should be sent in order first before starting on the next one!
for (var c = contents.ensureItemOrder ? toCraft : 1; c > 0; c--) { for (var c = contents.ensureItemOrder ? toCraft : 1; c > 0; c--) {
@ -185,10 +192,11 @@ public class CraftingModuleItem extends ModuleItem {
locks.addAll(ret.getLeft()); locks.addAll(ret.getLeft());
allCrafts.addAll(ret.getRight()); allCrafts.addAll(ret.getRight());
} }
var result = stack.copyWithCount(contents.ensureItemOrder ? resultAmount : resultAmount * toCraft); var crafted = contents.ensureItemOrder ? resultAmount : resultAmount * toCraft;
var activeCraft = new ActiveCraft(tile.getBlockPos(), slot, locks, destPipe, result); var activeCraft = new ActiveCraft(tile.getBlockPos(), slot, locks, destPipe, stack.copyWithCount(Math.min(crafted, leftOfRequest)));
tile.getActiveCrafts().add(activeCraft); tile.getActiveCrafts().add(activeCraft);
allCrafts.add(activeCraft); allCrafts.add(activeCraft);
leftOfRequest -= crafted;
} }
var remain = stack.copy(); var remain = stack.copy();