From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: violetc <58360096+s-yh-china@users.noreply.github.com> Date: Thu, 18 Aug 2022 16:31:08 +0800 Subject: [PATCH] Cache climbing check for activation This patch is Powered by Pufferfish(https://github.com/pufferfish-gg/Pufferfish) diff --git a/io/papermc/paper/entity/activation/ActivationRange.java b/io/papermc/paper/entity/activation/ActivationRange.java index 2ebee223085fe7926c7f3e555df19ae69f36157e..40f83551c74b594aa5fda82ac67eec72c3cd4942 100644 --- a/io/papermc/paper/entity/activation/ActivationRange.java +++ b/io/papermc/paper/entity/activation/ActivationRange.java @@ -215,7 +215,7 @@ public final class ActivationRange { } // special cases. if (entity instanceof final LivingEntity living) { - if (living.onClimbable() || living.jumping || living.hurtTime > 0 || !living.activeEffects.isEmpty() || living.isFreezing()) { + if (living.onClimableCached() || living.jumping || living.hurtTime > 0 || !living.activeEffects.isEmpty() || living.isFreezing()) { // Leaves - use cached return 1; } if (entity instanceof final Mob mob && mob.getTarget() != null) { diff --git a/net/minecraft/world/entity/LivingEntity.java b/net/minecraft/world/entity/LivingEntity.java index b5f6a76c977bbb5dbb06fb3dd654f0b01aaba692..108430b3934a6f9757e7be50d77e760bbade669c 100644 --- a/net/minecraft/world/entity/LivingEntity.java +++ b/net/minecraft/world/entity/LivingEntity.java @@ -2094,6 +2094,22 @@ public abstract class LivingEntity extends Entity implements Attackable { return this.lastClimbablePos; } + // Leaves start - cache climbing check + private boolean cachedOnClimable = false; + private BlockPos lastClimbingPosition = null; + + public boolean onClimableCached() { + if (!org.leavesmc.leaves.LeavesConfig.performance.cacheClimbCheck) { + return this.onClimbable(); + } + if (!this.blockPosition().equals(this.lastClimbingPosition)) { + this.cachedOnClimable = this.onClimbable(); + this.lastClimbingPosition = this.blockPosition(); + } + return this.cachedOnClimable; + } + // Leaves end - cache climbing check + public boolean onClimbable() { if (this.isSpectator()) { return false;