From 8757c3617b604851d8b4e4e5aa8f5c2c67bad6c3 Mon Sep 17 00:00:00 2001 From: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com> Date: Sun, 12 Oct 2025 23:40:58 -0400 Subject: [PATCH] Backport changes from ver/1.21.8 See https://github.com/Winds-Studio/Leaf/commit/667f15c1247dbab03b79ed53afccabaabdb0b47a Co-Authored-By: MrlingXD <90316914+wling-art@users.noreply.github.com> --- ...-SparklyPaper-Parallel-world-ticking.patch | 4 +- ...-SparklyPaper-Parallel-world-ticking.patch | 50 ++++++++++++------- 2 files changed, 34 insertions(+), 20 deletions(-) diff --git a/leaf-server/minecraft-patches/features/0127-SparklyPaper-Parallel-world-ticking.patch b/leaf-server/minecraft-patches/features/0127-SparklyPaper-Parallel-world-ticking.patch index 2a4844b8..fcb7cb05 100644 --- a/leaf-server/minecraft-patches/features/0127-SparklyPaper-Parallel-world-ticking.patch +++ b/leaf-server/minecraft-patches/features/0127-SparklyPaper-Parallel-world-ticking.patch @@ -604,7 +604,7 @@ index d4048661575ebfaf128ba25da365843774364e0e..33dd16a26edd2974f04d9a868d3e58e8 // Gale start - Pufferfish - SIMD support diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java -index a66e5f6652d9633c856490de36d8d8fdf8a5298a..d6524d5c442555eaeb4d90f6a101262ee669f0d9 100644 +index a66e5f6652d9633c856490de36d8d8fdf8a5298a..81f891a26dd7fd1be87d1488aaf58863d66481c5 100644 --- a/net/minecraft/server/level/ServerLevel.java +++ b/net/minecraft/server/level/ServerLevel.java @@ -182,7 +182,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe @@ -696,7 +696,7 @@ index a66e5f6652d9633c856490de36d8d8fdf8a5298a..d6524d5c442555eaeb4d90f6a101262e + } + + // Executes the actual read operation based on the request type -+ private Object executeReadRequest(org.dreeam.leaf.async.world.WorldReadRequest request) { ++ public Object executeReadRequest(org.dreeam.leaf.async.world.WorldReadRequest request) { + Object[] params = request.params(); + BlockPos pos; // Declare pos outside the switch + diff --git a/leaf-server/paper-patches/features/0030-SparklyPaper-Parallel-world-ticking.patch b/leaf-server/paper-patches/features/0030-SparklyPaper-Parallel-world-ticking.patch index fccb0eec..a4ec30c1 100644 --- a/leaf-server/paper-patches/features/0030-SparklyPaper-Parallel-world-ticking.patch +++ b/leaf-server/paper-patches/features/0030-SparklyPaper-Parallel-world-ticking.patch @@ -5,6 +5,8 @@ Subject: [PATCH] SparklyPaper: Parallel world ticking Original project: https://github.com/SparklyPower/SparklyPaper +Co-authored-by: MrlingXD <90316914+wling-art@users.noreply.github.com> + diff --git a/src/main/java/ca/spottedleaf/moonrise/common/util/TickThread.java b/src/main/java/ca/spottedleaf/moonrise/common/util/TickThread.java index a4aa2615823d77920ff55b8aa0bcc27a54b8c3e1..2fb65ce228da94eb7d9364ee0f94582300178f1d 100644 --- a/src/main/java/ca/spottedleaf/moonrise/common/util/TickThread.java @@ -315,10 +317,10 @@ index af33cab59932f4ec135caf94dc5828930833daf6..caa92e48d031cb54950e6613a82f407d } // Paper end diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java -index 811823a1a7e24a19a7e37eb4c08efdfa19e839ed..839cfe99c028c596e15ba63c8a6e4a515b0a5764 100644 +index 811823a1a7e24a19a7e37eb4c08efdfa19e839ed..d3935cfe0ef5d6e8df6f3bb9894a1b7a165c3561 100644 --- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java +++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java -@@ -74,13 +74,98 @@ public class CraftBlock implements Block { +@@ -74,13 +74,110 @@ public class CraftBlock implements Block { return new CraftBlock(world, position); } @@ -345,6 +347,18 @@ index 811823a1a7e24a19a7e37eb4c08efdfa19e839ed..839cfe99c028c596e15ba63c8a6e4a51 + return defaultValue; + } + ++ // Leaf start - SparklyPaper - parallel world ticking - Deadlock prevention ++ if (Thread.currentThread() instanceof ca.spottedleaf.moonrise.common.util.TickThread.ServerLevelTickThread) { ++ try { ++ org.dreeam.leaf.async.world.WorldReadRequest request = new org.dreeam.leaf.async.world.WorldReadRequest(type, params, null); ++ Object result = level.executeReadRequest(request); ++ return (T) result; ++ } catch (Exception e) { ++ return defaultValue; ++ } ++ } ++ // Leaf end - SparklyPaper - parallel world ticking - Deadlock prevention ++ + java.util.concurrent.CompletableFuture future = new java.util.concurrent.CompletableFuture<>(); + + // Leaf start - SparklyPaper - parallel world ticking - Shutdown handling for async reads @@ -419,7 +433,7 @@ index 811823a1a7e24a19a7e37eb4c08efdfa19e839ed..839cfe99c028c596e15ba63c8a6e4a51 } // Paper end -@@ -144,10 +229,12 @@ public class CraftBlock implements Block { +@@ -144,10 +241,12 @@ public class CraftBlock implements Block { return this.getWorld().getChunkAt(this); } @@ -432,7 +446,7 @@ index 811823a1a7e24a19a7e37eb4c08efdfa19e839ed..839cfe99c028c596e15ba63c8a6e4a51 public void setData(final byte data, boolean applyPhysics) { if (applyPhysics) { this.setData(data, 3); -@@ -157,12 +244,18 @@ public class CraftBlock implements Block { +@@ -157,12 +256,18 @@ public class CraftBlock implements Block { } private void setData(final byte data, int flag) { @@ -452,7 +466,7 @@ index 811823a1a7e24a19a7e37eb4c08efdfa19e839ed..839cfe99c028c596e15ba63c8a6e4a51 return CraftMagicNumbers.toLegacyData(blockData); } -@@ -179,6 +272,7 @@ public class CraftBlock implements Block { +@@ -179,6 +284,7 @@ public class CraftBlock implements Block { @Override public void setType(Material type, boolean applyPhysics) { Preconditions.checkArgument(type != null, "Material cannot be null"); @@ -460,7 +474,7 @@ index 811823a1a7e24a19a7e37eb4c08efdfa19e839ed..839cfe99c028c596e15ba63c8a6e4a51 this.setBlockData(type.createBlockData(), applyPhysics); } -@@ -198,6 +292,12 @@ public class CraftBlock implements Block { +@@ -198,6 +304,12 @@ public class CraftBlock implements Block { } public static boolean setTypeAndData(LevelAccessor world, BlockPos position, net.minecraft.world.level.block.state.BlockState old, net.minecraft.world.level.block.state.BlockState blockData, boolean applyPhysics) { @@ -473,7 +487,7 @@ index 811823a1a7e24a19a7e37eb4c08efdfa19e839ed..839cfe99c028c596e15ba63c8a6e4a51 // SPIGOT-611: need to do this to prevent glitchiness. Easier to handle this here (like /setblock) than to fix weirdness in tile entity cleanup if (old.hasBlockEntity() && blockData.getBlock() != old.getBlock()) { // SPIGOT-3725 remove old tile entity if block changes // SPIGOT-4612: faster - just clear tile -@@ -226,22 +326,62 @@ public class CraftBlock implements Block { +@@ -226,22 +338,62 @@ public class CraftBlock implements Block { @Override public Material getType() { @@ -540,7 +554,7 @@ index 811823a1a7e24a19a7e37eb4c08efdfa19e839ed..839cfe99c028c596e15ba63c8a6e4a51 } public Block getFace(final BlockFace face) { -@@ -282,51 +422,36 @@ public class CraftBlock implements Block { +@@ -282,51 +434,36 @@ public class CraftBlock implements Block { @Override public String toString() { @@ -616,7 +630,7 @@ index 811823a1a7e24a19a7e37eb4c08efdfa19e839ed..839cfe99c028c596e15ba63c8a6e4a51 } @Override -@@ -343,18 +468,65 @@ public class CraftBlock implements Block { +@@ -343,18 +480,65 @@ public class CraftBlock implements Block { @Override public Biome getBiome() { @@ -684,7 +698,7 @@ index 811823a1a7e24a19a7e37eb4c08efdfa19e839ed..839cfe99c028c596e15ba63c8a6e4a51 this.getWorld().setBiome(this.getX(), this.getY(), this.getZ(), bio); } -@@ -370,12 +542,50 @@ public class CraftBlock implements Block { +@@ -370,12 +554,50 @@ public class CraftBlock implements Block { @Override public boolean isBlockPowered() { @@ -737,7 +751,7 @@ index 811823a1a7e24a19a7e37eb4c08efdfa19e839ed..839cfe99c028c596e15ba63c8a6e4a51 } @Override -@@ -397,46 +607,101 @@ public class CraftBlock implements Block { +@@ -397,46 +619,101 @@ public class CraftBlock implements Block { @Override public boolean isBlockFacePowered(BlockFace face) { @@ -866,7 +880,7 @@ index 811823a1a7e24a19a7e37eb4c08efdfa19e839ed..839cfe99c028c596e15ba63c8a6e4a51 @Override public int getBlockPower() { -@@ -479,105 +744,179 @@ public class CraftBlock implements Block { +@@ -479,105 +756,179 @@ public class CraftBlock implements Block { @Override public PistonMoveReaction getPistonMoveReaction() { @@ -953,14 +967,14 @@ index 811823a1a7e24a19a7e37eb4c08efdfa19e839ed..839cfe99c028c596e15ba63c8a6e4a51 + int eventData = (eventId == net.minecraft.world.level.block.LevelEvent.PARTICLES_DESTROY_BLOCK) + ? net.minecraft.world.level.block.Block.getId(iblockdata) : 0; + this.world.levelEvent(eventId, this.position, eventData); - } ++ } + // Drop experience using ServerLevel + if (dropExperience) { + int xp = block.getExpDrop(iblockdata, serverLevelForDrops, this.position, nmsItem, true); + if (xp > 0) { // Only pop if there's XP to drop + block.popExperience(serverLevelForDrops, this.position, xp); + } -+ } + } + droppedItems = true; + } + } else { @@ -1087,7 +1101,7 @@ index 811823a1a7e24a19a7e37eb4c08efdfa19e839ed..839cfe99c028c596e15ba63c8a6e4a51 } @Override -@@ -592,31 +931,70 @@ public class CraftBlock implements Block { +@@ -592,31 +943,70 @@ public class CraftBlock implements Block { @Override public Collection getDrops(ItemStack item, Entity entity) { @@ -1168,7 +1182,7 @@ index 811823a1a7e24a19a7e37eb4c08efdfa19e839ed..839cfe99c028c596e15ba63c8a6e4a51 @Override public void setMetadata(String metadataKey, MetadataValue newMetadataValue) { this.getCraftWorld().getBlockMetadata().setMetadata(this, metadataKey, newMetadataValue); -@@ -639,57 +1017,147 @@ public class CraftBlock implements Block { +@@ -639,57 +1029,147 @@ public class CraftBlock implements Block { @Override public boolean isPassable() { @@ -1340,7 +1354,7 @@ index 811823a1a7e24a19a7e37eb4c08efdfa19e839ed..839cfe99c028c596e15ba63c8a6e4a51 } @Override -@@ -700,7 +1168,10 @@ public class CraftBlock implements Block { +@@ -700,7 +1180,10 @@ public class CraftBlock implements Block { // Paper start @Override public com.destroystokyo.paper.block.BlockSoundGroup getSoundGroup() { @@ -1352,7 +1366,7 @@ index 811823a1a7e24a19a7e37eb4c08efdfa19e839ed..839cfe99c028c596e15ba63c8a6e4a51 } @Override -@@ -713,26 +1184,76 @@ public class CraftBlock implements Block { +@@ -713,26 +1196,76 @@ public class CraftBlock implements Block { return this.getNMS().getBlock().getDescriptionId(); }