From 9952017a762522ddbf755c98f35992fc41c079bd Mon Sep 17 00:00:00 2001 From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com> Date: Sun, 20 Jul 2025 17:19:24 +0300 Subject: [PATCH] Don't use snapshots for acquiring blockstate --- .../world/level/block/entity/BlockEntity.java.patch | 11 +++++++++++ .../bukkit/craftbukkit/block/CraftBlock.java.patch | 11 +++++++++++ .../craftbukkit/block/CraftBlockStates.java.patch | 11 +++++++++++ .../java/org/bxteam/divinemc/config/DivineConfig.java | 4 ++++ 4 files changed, 37 insertions(+) create mode 100644 divinemc-server/minecraft-patches/sources/net/minecraft/world/level/block/entity/BlockEntity.java.patch create mode 100644 divinemc-server/paper-patches/files/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java.patch create mode 100644 divinemc-server/paper-patches/files/src/main/java/org/bukkit/craftbukkit/block/CraftBlockStates.java.patch diff --git a/divinemc-server/minecraft-patches/sources/net/minecraft/world/level/block/entity/BlockEntity.java.patch b/divinemc-server/minecraft-patches/sources/net/minecraft/world/level/block/entity/BlockEntity.java.patch new file mode 100644 index 0000000..e8548e3 --- /dev/null +++ b/divinemc-server/minecraft-patches/sources/net/minecraft/world/level/block/entity/BlockEntity.java.patch @@ -0,0 +1,11 @@ +--- a/net/minecraft/world/level/block/entity/BlockEntity.java ++++ b/net/minecraft/world/level/block/entity/BlockEntity.java +@@ -386,7 +_,7 @@ + + // CraftBukkit start - add method + public org.bukkit.inventory.InventoryHolder getOwner() { +- return getOwner(true); ++ return getOwner(org.bxteam.divinemc.config.DivineConfig.PerformanceCategory.createSnapshotOnRetrievingBlockState); // DivineMC - EMC: Don't use snapshots for acquiring blockstate + } + + public org.bukkit.inventory.InventoryHolder getOwner(boolean useSnapshot) { diff --git a/divinemc-server/paper-patches/files/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java.patch b/divinemc-server/paper-patches/files/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java.patch new file mode 100644 index 0000000..3e6e3d4 --- /dev/null +++ b/divinemc-server/paper-patches/files/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java.patch @@ -0,0 +1,11 @@ +--- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java ++++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java +@@ -332,7 +_,7 @@ + + @Override + public BlockState getState() { +- return CraftBlockStates.getBlockState(this); ++ return CraftBlockStates.getBlockState(this, org.bxteam.divinemc.config.DivineConfig.PerformanceCategory.createSnapshotOnRetrievingBlockState); // DivineMC - EMC: Don't use snapshots for acquiring blockstate + } + + // Paper start diff --git a/divinemc-server/paper-patches/files/src/main/java/org/bukkit/craftbukkit/block/CraftBlockStates.java.patch b/divinemc-server/paper-patches/files/src/main/java/org/bukkit/craftbukkit/block/CraftBlockStates.java.patch new file mode 100644 index 0000000..054d95e --- /dev/null +++ b/divinemc-server/paper-patches/files/src/main/java/org/bukkit/craftbukkit/block/CraftBlockStates.java.patch @@ -0,0 +1,11 @@ +--- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlockStates.java ++++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlockStates.java +@@ -185,7 +_,7 @@ + } + + public static BlockState getBlockState(Block block) { +- return CraftBlockStates.getBlockState(block, true); ++ return CraftBlockStates.getBlockState(block, org.bxteam.divinemc.config.DivineConfig.PerformanceCategory.createSnapshotOnRetrievingBlockState); // DivineMC - EMC: Don't use snapshots for acquiring blockstate + } + + public static BlockState getBlockState(Block block, boolean useSnapshot) { diff --git a/divinemc-server/src/main/java/org/bxteam/divinemc/config/DivineConfig.java b/divinemc-server/src/main/java/org/bxteam/divinemc/config/DivineConfig.java index 3bff625..c4ff9ef 100644 --- a/divinemc-server/src/main/java/org/bxteam/divinemc/config/DivineConfig.java +++ b/divinemc-server/src/main/java/org/bxteam/divinemc/config/DivineConfig.java @@ -389,6 +389,7 @@ public class DivineConfig { public static boolean sheepOptimization = true; public static boolean optimizedDragonRespawn = false; public static boolean reduceChuckLoadAndLookup = true; + public static boolean createSnapshotOnRetrievingBlockState = true; public static boolean hopperThrottleWhenFull = false; public static int hopperThrottleSkipTicks = 0; @@ -484,6 +485,9 @@ public class DivineConfig { "When enabled, improving performance and reducing lag during the dragon’s resurrection event."); reduceChuckLoadAndLookup = getBoolean(ConfigCategory.PERFORMANCE.key("optimizations.reduce-chunk-load-and-lookup"), reduceChuckLoadAndLookup, "If enabled, optimizes chunk loading and block state lookups by reducing the number of chunk accesses required during operations such as Enderman teleportation."); + createSnapshotOnRetrievingBlockState = getBoolean(ConfigCategory.PERFORMANCE.key("optimizations.create-snapshot-on-retrieving-block-state"), createSnapshotOnRetrievingBlockState, + "Whether to create a snapshot (copy) of BlockState data when plugins retrieve them.", + "If false, plugins get direct BlockState access for better performance but risk data corruption from poor plugin design."); hopperThrottleWhenFull = getBoolean(ConfigCategory.PERFORMANCE.key("optimizations.hopper-throttle-when-full.enabled"), hopperThrottleWhenFull, "When enabled, hoppers will throttle if target container is full.");