9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2025-12-26 18:39:23 +00:00
Files
Leaf/leaf-server/minecraft-patches/features/0230-Optimise-MobEffectUtil-getDigSpeedAmplification.patch
Dreeam 9a4efaa230 Drop patch that causes performance regression
Originally vanilla logic is to use stream, and Mojang switched it to Guava's Collections2
since 1.21.4. It is much faster than using stream or manually adding to a new ArrayList.
Manually adding to a new ArrayList requires allocating a new object array. However, the Collections2
lazy handles filter condition on iteration, so much better.
2025-08-04 19:25:56 +08:00

40 lines
1.7 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Taiyou06 <kaandindar21@gmail.com>
Date: Mon, 14 Apr 2025 18:07:21 +0200
Subject: [PATCH] Optimise MobEffectUtil#getDigSpeedAmplification
diff --git a/net/minecraft/world/effect/MobEffectUtil.java b/net/minecraft/world/effect/MobEffectUtil.java
index 93a07a96f74e3ba73986324b39923c6a2802f8ee..e900c91c8eb36029726f7833df1d9be4030b3ad8 100644
--- a/net/minecraft/world/effect/MobEffectUtil.java
+++ b/net/minecraft/world/effect/MobEffectUtil.java
@@ -27,17 +27,21 @@ public final class MobEffectUtil {
}
public static int getDigSpeedAmplification(LivingEntity entity) {
- int i = 0;
- int i1 = 0;
- if (entity.hasEffect(MobEffects.HASTE)) {
- i = entity.getEffect(MobEffects.HASTE).getAmplifier();
+ // Leaf start - Optimise MobEffectUtil#getDigSpeedAmplification
+ int digAmplifier = 0;
+ int conduitAmplifier = 0;
+ MobEffectInstance digEffect = entity.getEffect(MobEffects.HASTE);
+ if (digEffect != null) {
+ digAmplifier = digEffect.getAmplifier();
}
- if (entity.hasEffect(MobEffects.CONDUIT_POWER)) {
- i1 = entity.getEffect(MobEffects.CONDUIT_POWER).getAmplifier();
+ MobEffectInstance conduitEffect = entity.getEffect(MobEffects.CONDUIT_POWER);
+ if (conduitEffect != null) {
+ conduitAmplifier = conduitEffect.getAmplifier();
}
- return Math.max(i, i1);
+ return Math.max(digAmplifier, conduitAmplifier);
+ // Leaf end - Optimise MobEffectUtil#getDigSpeedAmplification
}
public static boolean hasWaterBreathing(LivingEntity entity) {