From beb51ae1497b4d3a213b4407b29fe15d41676ff5 Mon Sep 17 00:00:00 2001 From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com> Date: Wed, 11 Jun 2025 16:43:22 +0300 Subject: [PATCH] Optimize suffocation --- .../features/0053-Optimize-suffocation.patch | 34 +++++++++++++++++++ .../org/bxteam/divinemc/DivineConfig.java | 4 +++ 2 files changed, 38 insertions(+) create mode 100644 divinemc-server/minecraft-patches/features/0053-Optimize-suffocation.patch diff --git a/divinemc-server/minecraft-patches/features/0053-Optimize-suffocation.patch b/divinemc-server/minecraft-patches/features/0053-Optimize-suffocation.patch new file mode 100644 index 0000000..2a252ab --- /dev/null +++ b/divinemc-server/minecraft-patches/features/0053-Optimize-suffocation.patch @@ -0,0 +1,34 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com> +Date: Wed, 11 Jun 2025 16:40:43 +0300 +Subject: [PATCH] Optimize suffocation + +Original license: GPL v3 +Original project: https://github.com/pufferfish-gg/Pufferfish + +diff --git a/net/minecraft/world/entity/LivingEntity.java b/net/minecraft/world/entity/LivingEntity.java +index f598c6ae03977998f1cbf79cf3faf7997c2ba9e2..8b89a11aa0040b0d6104a4056d70d9d2ac74e331 100644 +--- a/net/minecraft/world/entity/LivingEntity.java ++++ b/net/minecraft/world/entity/LivingEntity.java +@@ -406,6 +406,12 @@ public abstract class LivingEntity extends Entity implements Attackable { + return this.getDeltaMovement().y() < 1.0E-5F && this.isInLiquid(); + } + ++ // DivineMC start - Optimize suffocation ++ public boolean couldPossiblyBeHurt(float amount) { ++ return !((float) this.invulnerableTime > (float) this.invulnerableDuration / 2.0F) || !(amount <= this.lastHurt); ++ } ++ // DivineMC end - Optimize suffocation ++ + @Override + public void baseTick() { + this.oAttackAnim = this.attackAnim; +@@ -424,7 +430,7 @@ public abstract class LivingEntity extends Entity implements Attackable { + + if (this.isAlive() && this.level() instanceof ServerLevel serverLevel1) { + boolean flag = this instanceof Player; +- if (this.isInWall()) { ++ if ((!org.bxteam.divinemc.DivineConfig.enableSuffocationOptimization || this instanceof WitherBoss || (tickCount % 10 == 0 && couldPossiblyBeHurt(1.0F))) && this.isInWall()) { // DivineMC - Optimize suffocation + this.hurtServer(serverLevel1, this.damageSources().inWall(), 1.0F); + } else if (flag && !serverLevel1.getWorldBorder().isWithinBounds(this.getBoundingBox())) { + double d = serverLevel1.getWorldBorder().getDistanceToBorder(this) + serverLevel1.getWorldBorder().getDamageSafeZone(); diff --git a/divinemc-server/src/main/java/org/bxteam/divinemc/DivineConfig.java b/divinemc-server/src/main/java/org/bxteam/divinemc/DivineConfig.java index 6b5fc89..d5a3426 100644 --- a/divinemc-server/src/main/java/org/bxteam/divinemc/DivineConfig.java +++ b/divinemc-server/src/main/java/org/bxteam/divinemc/DivineConfig.java @@ -265,6 +265,7 @@ public class DivineConfig { public static boolean ignoreMovedTooQuicklyWhenLagging = true; public static boolean alwaysAllowWeirdMovement = true; public static boolean updateSuppressionCrashFix = true; + public static boolean enableSuffocationOptimization = true; public static boolean useCompactBitStorage = false; public static boolean fixIncorrectBounceLogic = false; public static boolean forceMinecraftCommand = false; @@ -283,6 +284,9 @@ public class DivineConfig { alwaysAllowWeirdMovement = getBoolean("settings.misc.always-allow-weird-movement", alwaysAllowWeirdMovement, "Means ignoring messages like 'moved too quickly' and 'moved wrongly'"); updateSuppressionCrashFix = getBoolean("settings.misc.update-suppression-crash-fix", updateSuppressionCrashFix); + enableSuffocationOptimization = getBoolean("settings.misc.enable-suffocation-optimization", enableSuffocationOptimization, + "Optimizes the suffocation check by selectively skipping the check in a way that still appears vanilla.", + "This option should be left enabled on most servers, but is provided as a configuration option if the vanilla deviation is undesirable."); useCompactBitStorage = getBoolean("settings.misc.use-compact-bit-storage", useCompactBitStorage, "Fixes memory waste caused by sending empty chunks as if they contain blocks. Can significantly reduce memory usage."); fixIncorrectBounceLogic = getBoolean("settings.misc.fix-incorrect-bounce-logic", fixIncorrectBounceLogic,