Skip to content

Commit d45930a

Browse files
Fix CloneCommands cross-region block placement
Wraps block-modifying operations in ShreddedPaper.ensureSync() to ensure they run on the correct region thread when a command block executes /clone targeting coordinates in a different region.
1 parent 8f343ac commit d45930a

1 file changed

Lines changed: 60 additions & 0 deletions

File tree

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
--- a/net/minecraft/server/commands/CloneCommands.java
2+
+++ b/net/minecraft/server/commands/CloneCommands.java
3+
@@ -8,6 +_,7 @@
4+
import com.mojang.brigadier.exceptions.Dynamic2CommandExceptionType;
5+
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
6+
import com.mojang.logging.LogUtils;
7+
+import io.multipaper.shreddedpaper.ShreddedPaper;
8+
import java.util.Deque;
9+
import java.util.List;
10+
import java.util.function.Predicate;
11+
@@ -233,11 +_,13 @@
12+
} else if (serverLevel1.isDebug()) {
13+
throw ERROR_FAILED.create();
14+
} else {
15+
+ // ShreddedPaper start - run on correct region thread
16+
+ ShreddedPaper.ensureSync(serverLevel1, blockPos2, () -> {
17+
List<CloneCommands.CloneBlockInfo> list = Lists.newArrayList();
18+
List<CloneCommands.CloneBlockInfo> list1 = Lists.newArrayList();
19+
List<CloneCommands.CloneBlockInfo> list2 = Lists.newArrayList();
20+
Deque<BlockPos> list3 = Lists.newLinkedList();
21+
- int i2 = 0;
22+
+ int[] counter = {0}; // ShreddedPaper - use array to allow modification in lambda
23+
ProblemReporter.ScopedCollector scopedCollector = new ProblemReporter.ScopedCollector(LOGGER);
24+
25+
try {
26+
@@ -303,7 +_,7 @@
27+
28+
for (CloneCommands.CloneBlockInfo cloneBlockInfo : list4) {
29+
if (serverLevel1.setBlock(cloneBlockInfo.pos, cloneBlockInfo.state, z)) {
30+
- i2++;
31+
+ counter[0]++;
32+
}
33+
}
34+
35+
@@ -336,17 +_,19 @@
36+
var35.addSuppressed(var34);
37+
}
38+
39+
- throw var35;
40+
+ throw new RuntimeException(var35); // ShreddedPaper - wrap in RuntimeException for lambda
41+
}
42+
43+
scopedCollector.close();
44+
- if (i2 == 0) {
45+
- throw ERROR_FAILED.create();
46+
+ if (counter[0] == 0) {
47+
+ source.sendFailure(Component.translatable("commands.clone.failed")); // ShreddedPaper - send failure message instead of throwing
48+
} else {
49+
- int i3 = i2;
50+
- source.sendSuccess(() -> Component.translatable("commands.clone.success", i3), true);
51+
- return i2;
52+
+ int finalCount = counter[0];
53+
+ source.sendSuccess(() -> Component.translatable("commands.clone.success", finalCount), true);
54+
}
55+
+ });
56+
+ return 1;
57+
+ // ShreddedPaper end - run on correct region thread
58+
}
59+
}
60+
}

0 commit comments

Comments
 (0)