Skip to content

Commit 68de0ed

Browse files
Clear cached chunk packets after block commands
Fixes invisible blocks issue when SetBlockCommand, FillCommand, or CloneCommands modify chunks that aren't being watched by any player. The cached chunk packet is now invalidated so players receive fresh chunk data when they teleport to the affected area.
1 parent d45930a commit 68de0ed

3 files changed

Lines changed: 32 additions & 2 deletions

File tree

shreddedpaper-server/minecraft-patches/sources/net/minecraft/server/commands/CloneCommands.java.patch

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,22 @@
3232
}
3333
}
3434

35+
@@ -329,6 +_,15 @@
36+
}
37+
38+
serverLevel1.getBlockTicks().copyAreaFrom(serverLevel.getBlockTicks(), boundingBox, blockPos4);
39+
+
40+
+ // ShreddedPaper start - clear cached chunk packets for destination chunks
41+
+ for (int chunkX = boundingBox1.minX() >> 4; chunkX <= boundingBox1.maxX() >> 4; chunkX++) {
42+
+ for (int chunkZ = boundingBox1.minZ() >> 4; chunkZ <= boundingBox1.maxZ() >> 4; chunkZ++) {
43+
+ net.minecraft.world.level.chunk.LevelChunk chunk = serverLevel1.getChunkIfLoaded(chunkX, chunkZ);
44+
+ if (chunk != null) chunk.cachedChunkPacket = null;
45+
+ }
46+
+ }
47+
+ // ShreddedPaper end - clear cached chunk packets for destination chunks
48+
} catch (Throwable var35) {
49+
try {
50+
scopedCollector.close();
3551
@@ -336,17 +_,19 @@
3652
var35.addSuppressed(var34);
3753
}

shreddedpaper-server/minecraft-patches/sources/net/minecraft/server/commands/FillCommand.java.patch

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,21 @@
5555
}
5656
}
5757
}
58-
@@ -223,13 +_,15 @@
58+
@@ -223,13 +_,24 @@
5959
level.updateNeighboursOnBlockSet(updatedPosition.pos, updatedPosition.oldState);
6060
}
6161

6262
- if (i2 == 0) {
6363
- throw ERROR_FAILED.create();
64+
+ // ShreddedPaper start - clear cached chunk packets for affected chunks
65+
+ for (int chunkX = box.minX() >> 4; chunkX <= box.maxX() >> 4; chunkX++) {
66+
+ for (int chunkZ = box.minZ() >> 4; chunkZ <= box.maxZ() >> 4; chunkZ++) {
67+
+ net.minecraft.world.level.chunk.LevelChunk chunk = level.getChunkIfLoaded(chunkX, chunkZ);
68+
+ if (chunk != null) chunk.cachedChunkPacket = null;
69+
+ }
70+
+ }
71+
+ // ShreddedPaper end - clear cached chunk packets for affected chunks
72+
+
6473
+ if (counter[0] == 0) {
6574
+ source.sendFailure(Component.translatable("commands.fill.failed")); // ShreddedPaper - send failure message instead of throwing
6675
} else {

shreddedpaper-server/minecraft-patches/sources/net/minecraft/server/commands/SetBlockCommand.java.patch

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
boolean flag;
1818
if (mode == SetBlockCommand.Mode.DESTROY) {
1919
level.destroyBlock(pos, true);
20-
@@ -117,15 +_,17 @@
20+
@@ -117,15 +_,22 @@
2121
BlockState blockState = level.getBlockState(pos);
2222
if (flag
2323
&& !block.place(level, pos, Block.UPDATE_CLIENTS | (strict ? Block.UPDATE_SKIP_ALL_SIDEEFFECTS : Block.UPDATE_SKIP_BLOCK_ENTITY_SIDEEFFECTS))) {
@@ -28,6 +28,11 @@
2828
level.updateNeighboursOnBlockSet(pos, blockState);
2929
}
3030

31+
+ // ShreddedPaper start - clear cached chunk packet
32+
+ net.minecraft.world.level.chunk.LevelChunk chunk = level.getChunkIfLoaded(pos.getX() >> 4, pos.getZ() >> 4);
33+
+ if (chunk != null) chunk.cachedChunkPacket = null;
34+
+ // ShreddedPaper end - clear cached chunk packet
35+
+
3136
source.sendSuccess(() -> Component.translatable("commands.setblock.success", pos.getX(), pos.getY(), pos.getZ()), true);
3237
- return 1;
3338
}

0 commit comments

Comments
 (0)