9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2025-12-30 20:39:21 +00:00
Files
Leaf/leaf-server/minecraft-patches/features/0162-Configurable-player-knockback-zombie.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

41 lines
2.0 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com>
Date: Sun, 4 Aug 2024 19:34:29 +0800
Subject: [PATCH] Configurable player knockback zombie
diff --git a/net/minecraft/world/entity/LivingEntity.java b/net/minecraft/world/entity/LivingEntity.java
index f30d24136e5f47c9be79e2c0b4b98d0e796d868b..4d4efd979c4478c1571e7044f639afe08a7118d6 100644
--- a/net/minecraft/world/entity/LivingEntity.java
+++ b/net/minecraft/world/entity/LivingEntity.java
@@ -2111,6 +2111,8 @@ public abstract class LivingEntity extends Entity implements Attackable, Waypoin
}
public void knockback(double strength, double x, double z, @Nullable Entity attacker, io.papermc.paper.event.entity.EntityKnockbackEvent.Cause eventCause) { // Paper - knockback events
+ if (!canKnockback(attacker, this)) return; // Leaf - Configurable player knockback zombie
+
strength *= 1.0 - this.getAttributeValue(Attributes.KNOCKBACK_RESISTANCE);
if (true || !(strength <= 0.0)) { // CraftBukkit - Call event even when force is 0
// this.hasImpulse = true; // CraftBukkit - Move down
@@ -2141,6 +2143,20 @@ public abstract class LivingEntity extends Entity implements Attackable, Waypoin
}
}
+ // Leaf start - Configurable player knockback zombie
+ private boolean canKnockback(@Nullable Entity attacker, LivingEntity target) {
+ if (!org.dreeam.leaf.config.modules.gameplay.Knockback.canPlayerKnockbackZombie) {
+ if (attacker instanceof ServerPlayer && target.getType() == EntityType.ZOMBIE) { // Player -> Zombie
+ return false;
+ } else if (attacker instanceof Projectile projectile && projectile.getOwner() instanceof ServerPlayer && target.getType() == EntityType.ZOMBIE) { // Player -> projectile -> Zombie
+ return false;
+ }
+ }
+
+ return true;
+ }
+ // Leaf end - Configurable player knockback zombie
+
public void indicateDamage(double xDistance, double zDistance) {
}