9
0
mirror of https://github.com/BX-Team/DivineMC.git synced 2025-12-19 14:59:25 +00:00

Optimize suffocation

This commit is contained in:
NONPLAYT
2025-06-11 16:43:22 +03:00
parent df2f89bd88
commit beb51ae149
2 changed files with 38 additions and 0 deletions

View File

@@ -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();

View File

@@ -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,