9
0
mirror of https://github.com/LeavesMC/Leaves.git synced 2025-12-19 14:59:32 +00:00
Files
LeavesMC/leaves-server/minecraft-patches/features/0017-Optimize-suffocation.patch
Lumine1909 f09fbb247d 1.21.5 (#470)
---------

Co-authored-by: violetc <58360096+s-yh-china@users.noreply.github.com>
Co-authored-by: Fortern <blueten.ki@gmail.com>
Co-authored-by: MC_XiaoHei <xor7xiaohei@gmail.com>
Co-authored-by: Helvetica Volubi <88063803+Suisuroru@users.noreply.github.com>
Co-authored-by: MC_XiaoHei <xiaohei.xor7@outlook.com>
2025-06-05 18:41:51 +08:00

34 lines
2.0 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: violetc <58360096+s-yh-china@users.noreply.github.com>
Date: Sun, 14 Aug 2022 08:25:24 +0800
Subject: [PATCH] Optimize suffocation
This patch is Powered by Pufferfish(https://github.com/pufferfish-gg/Pufferfish)
diff --git a/net/minecraft/world/entity/LivingEntity.java b/net/minecraft/world/entity/LivingEntity.java
index 5fc4d97ef421a37158b01864b035385bb7bf5f5f..b5f6a76c977bbb5dbb06fb3dd654f0b01aaba692 100644
--- a/net/minecraft/world/entity/LivingEntity.java
+++ b/net/minecraft/world/entity/LivingEntity.java
@@ -423,7 +423,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.leavesmc.leaves.LeavesConfig.performance.enableSuffocationOptimization || this instanceof WitherBoss || (tickCount % 10 == 0 && couldPossiblyBeHurt(1.0F))) && this.isInWall()) { // Leaves - 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();
@@ -1372,6 +1372,12 @@ public abstract class LivingEntity extends Entity implements Attackable {
return this.getHealth() <= 0.0F;
}
+ // Leaves start - optimize suffocation
+ public boolean couldPossiblyBeHurt(float amount) {
+ return !((float) this.invulnerableTime > (float) this.invulnerableDuration / 2.0F) || !(amount <= this.lastHurt);
+ }
+ // Leaves end - optimize suffocation
+
@Override
public boolean hurtServer(ServerLevel level, DamageSource damageSource, float amount) {
if (this.isInvulnerableTo(level, damageSource)) {