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,25 +92,31 @@ public class CraftingModuleItem extends ModuleItem {
} }
network.endProfile(); network.endProfile();
} else if (craft.travelingIngredients.isEmpty()) { } else if (craft.travelingIngredients.isEmpty()) {
// pull requested crafting results from the network once they are stored if (craft.resultStackRemain.isEmpty()) {
network.startProfile("crafting_results"); // the result stack is empty from the start if this was a partial craft whose results shouldn't be delivered anywhere
var items = network.getOrderedNetworkItems(tile.getBlockPos()); // (ie someone requested 3 sticks with ensureItemOrder, but the recipe always makes 4, so the 4th recipe has no destination)
var equalityTypes = ItemFilter.getEqualityTypes(tile); crafts.remove(craft);
var destPipe = network.getPipe(craft.resultDestPipe); } else {
if (destPipe != null) { // pull requested crafting results from the network once they are stored
var dest = destPipe.getAvailableDestinationOrConnectable(craft.resultStackRemain, true, true); network.startProfile("crafting_results");
if (dest != null) { var items = network.getOrderedNetworkItems(tile.getBlockPos());
for (var item : items) { var equalityTypes = ItemFilter.getEqualityTypes(tile);
var requestRemain = network.requestExistingItem(item, craft.resultDestPipe, dest.getLeft(), null, dest.getRight(), equalityTypes); var destPipe = network.getPipe(craft.resultDestPipe);
craft.resultStackRemain.shrink(dest.getRight().getCount() - requestRemain.getCount()); if (destPipe != null) {
if (craft.resultStackRemain.isEmpty()) { var dest = destPipe.getAvailableDestinationOrConnectable(craft.resultStackRemain, true, true);
crafts.remove(craft); if (dest != null) {
break; for (var item : items) {
var requestRemain = network.requestExistingItem(item, craft.resultDestPipe, dest.getLeft(), null, dest.getRight(), equalityTypes);
craft.resultStackRemain.shrink(dest.getRight().getCount() - requestRemain.getCount());
if (craft.resultStackRemain.isEmpty()) {
crafts.remove(craft);
break;
}
} }
} }
} }
network.endProfile();
} }
network.endProfile();
} }
} }
} }
@ -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();