Skip to content

Commit

Permalink
Fix Fabric transfer transaction usage (fixes #4486)
Browse files Browse the repository at this point in the history
- access simulated extract operations in transaction as well
- get rid of the inner transaction, as commit or rollback depends on the spark type and thus is identical for all accesses within the outer transaction (as recommended in #4403)
- ensure to commit the outer transaction after iterating over the slots if extracting via non-creative spark
  • Loading branch information
TheRealWormbo committed Dec 13, 2023
1 parent 3dc86fe commit 243f629
Showing 1 changed file with 7 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public List<ItemStack> extractItems(CorporeaRequest request) {
protected List<ItemStack> iterateOverSlots(CorporeaRequest request, boolean doit) {
ImmutableList.Builder<ItemStack> builder = ImmutableList.builder();

try (Transaction outer = Transaction.openOuter()) {
try (Transaction trans = Transaction.openOuter()) {
for (var storageView : inv) {
if (storageView.isResourceBlank()) {
continue;
Expand All @@ -53,21 +53,19 @@ protected List<ItemStack> iterateOverSlots(CorporeaRequest request, boolean doit
request.trackSatisfied(rem);

if (doit) {
try (Transaction trans = Transaction.openNested(outer)) {
builder.addAll(breakDownBigStack(item.toStack((int) inv.extract(item, rem, trans))));
if (!getSpark().isCreative()) {
// only commit if non-creative
trans.commit();
}
}
builder.addAll(breakDownBigStack(item.toStack((int) inv.extract(item, rem, trans))));
getSpark().onItemExtracted(stack);
request.trackExtracted(rem);
} else {
builder.add(item.toStack((int) inv.simulateExtract(item, rem, null)));
builder.add(item.toStack((int) inv.simulateExtract(item, rem, trans)));
}
}
}
}
if (doit && !getSpark().isCreative()) {
// only persist changes for non-creative sparks
trans.commit();
}
}

return builder.build();
Expand Down

0 comments on commit 243f629

Please sign in to comment.