diff options
Diffstat (limited to 'patches/removed/1.21.3')
3 files changed, 437 insertions, 0 deletions
diff --git a/patches/removed/1.21.3/0451-Fix-harming-potion-dupe.patch b/patches/removed/1.21.3/0451-Fix-harming-potion-dupe.patch new file mode 100644 index 0000000000..b184bf641c --- /dev/null +++ b/patches/removed/1.21.3/0451-Fix-harming-potion-dupe.patch @@ -0,0 +1,47 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: PepperCode1 <[email protected]> +Date: Thu, 23 Jul 2020 14:25:07 -0700 +Subject: [PATCH] Fix harming potion dupe + +EntityLiving#applyInstantEffect() immediately kills the player and drops their inventory. +Before this patch, instant effects would be applied before the potion ItemStack is removed and replaced with a glass bottle. This caused the potion ItemStack to be dropped before it was supposed to be removed from the inventory. It also caused the glass bottle to be put into a dead player's inventory. +This patch makes it so that instant effects are applied after the potion ItemStack is removed, and the glass bottle is only put into the player's inventory if the player is not dead. Otherwise, the glass bottle is dropped on the ground. + +diff --git a/src/main/java/net/minecraft/world/item/PotionItem.java b/src/main/java/net/minecraft/world/item/PotionItem.java +index 017b0745753ea1907bad7022405db9a5a487d069..92fa6523f2bba105a74fff228e36e58666ed56ae 100644 +--- a/src/main/java/net/minecraft/world/item/PotionItem.java ++++ b/src/main/java/net/minecraft/world/item/PotionItem.java +@@ -55,12 +55,13 @@ public class PotionItem extends Item { + CriteriaTriggers.CONSUME_ITEM.trigger((ServerPlayer) entityhuman, stack); + } + ++ List<net.minecraft.world.effect.MobEffectInstance> instantLater = new java.util.ArrayList<>(); // Paper - Fix harming potion dupe + if (!world.isClientSide) { + PotionContents potioncontents = (PotionContents) stack.getOrDefault(DataComponents.POTION_CONTENTS, PotionContents.EMPTY); + + potioncontents.forEachEffect((mobeffect) -> { + if (((MobEffect) mobeffect.getEffect().value()).isInstantenous()) { +- ((MobEffect) mobeffect.getEffect().value()).applyInstantenousEffect(entityhuman, entityhuman, user, mobeffect.getAmplifier(), 1.0D); ++ instantLater.add(mobeffect); // Paper + } else { + user.addEffect(mobeffect, org.bukkit.event.entity.EntityPotionEffectEvent.Cause.POTION_DRINK); // CraftBukkit + } +@@ -73,7 +74,18 @@ public class PotionItem extends Item { + stack.consume(1, entityhuman); + } + ++ // Paper start - Fix harming potion dupe ++ for (net.minecraft.world.effect.MobEffectInstance mobeffect : instantLater) { ++ mobeffect.getEffect().value().applyInstantenousEffect(entityhuman, entityhuman, user, mobeffect.getAmplifier(), 1.0D); ++ } ++ // Paper end - Fix harming potion dupe + if (entityhuman == null || !entityhuman.hasInfiniteMaterials()) { ++ // Paper start - Fix harming potion dupe ++ if (user.getHealth() <= 0 && !user.level().getGameRules().getBoolean(net.minecraft.world.level.GameRules.RULE_KEEPINVENTORY)) { ++ user.spawnAtLocation(new ItemStack(Items.GLASS_BOTTLE), 0); ++ return ItemStack.EMPTY; ++ } ++ // Paper end - Fix harming potion dupe + if (stack.isEmpty()) { + return new ItemStack(Items.GLASS_BOTTLE); + } diff --git a/patches/removed/1.21.3/0986-Strip-raytracing-for-EntityLiving-hasLineOfSight.patch b/patches/removed/1.21.3/0986-Strip-raytracing-for-EntityLiving-hasLineOfSight.patch new file mode 100644 index 0000000000..c591371af8 --- /dev/null +++ b/patches/removed/1.21.3/0986-Strip-raytracing-for-EntityLiving-hasLineOfSight.patch @@ -0,0 +1,160 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Paul Sauve <[email protected]> +Date: Sat, 31 Oct 2020 18:43:02 -0500 +Subject: [PATCH] Strip raytracing for EntityLiving#hasLineOfSight + +The BlockGetter#clip method is very wasteful in both allocations, +and in logic. While EntityLiving#hasLineOfSight provides static +parameters for collisions with blocks and fluids, the method still does +a lot of dynamic checks for both of these, which result in extra work. +As well, since the fluid collision option is set to NONE, the entire +fluid collision system is completely unneeded, yet used anyways. + +Copyright (C) 2020 Technove LLC + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <http://www.gnu.org/licenses/>. + +Feature patch + +diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java +index 5f1c585c819d25319a4fefd30abde3de7620cf6d..340c4452c09a98bc0220e6fe68dc65afc946986b 100644 +--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java ++++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java +@@ -3774,7 +3774,7 @@ public abstract class LivingEntity extends Entity implements Attackable { + Vec3 vec3d1 = new Vec3(entity.getX(), entity.getEyeY(), entity.getZ()); + + // Paper - diff on change - used in CraftLivingEntity#hasLineOfSight(Location) and CraftWorld#lineOfSightExists +- return vec3d1.distanceToSqr(vec3d) > 128.0D * 128.0D ? false : this.level().clip(new ClipContext(vec3d, vec3d1, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, this)).getType() == HitResult.Type.MISS; // Paper - Perf: Use distance squared ++ return vec3d1.distanceToSqr(vec3d) > 128.0D * 128.0D ? false : this.level().clipDirect(vec3d, vec3d1, net.minecraft.world.phys.shapes.CollisionContext.of(this)) == HitResult.Type.MISS; // Paper - Perf: Use distance squared & strip raytracing + } + } + +diff --git a/src/main/java/net/minecraft/world/level/BlockGetter.java b/src/main/java/net/minecraft/world/level/BlockGetter.java +index bb8e962e63c7a2d931f9bd7f7c002aa35cfa5fd3..0fa131a6c98adb498fc8d534e0e39647e80c6923 100644 +--- a/src/main/java/net/minecraft/world/level/BlockGetter.java ++++ b/src/main/java/net/minecraft/world/level/BlockGetter.java +@@ -68,6 +68,18 @@ public interface BlockGetter extends LevelHeightAccessor { + }); + } + ++ // Paper start - Broken down variant of the method below, used by Level#clipDirect ++ @Nullable ++ default BlockHitResult.Type clipDirect(Vec3 start, Vec3 end, BlockPos pos, BlockState state, net.minecraft.world.phys.shapes.CollisionContext collisionContext) { ++ if (state.isAir()) { ++ return null; ++ } ++ ++ final VoxelShape voxelshape = ClipContext.Block.COLLIDER.get(state, this, pos, collisionContext); ++ final BlockHitResult hitResult = this.clipWithInteractionOverride(start, end, pos, voxelshape, state); ++ return hitResult == null ? null : hitResult.getType(); ++ } ++ // Paper end + // CraftBukkit start - moved block handling into separate method for use by Block#rayTrace + default BlockHitResult clip(ClipContext raytrace1, BlockPos blockposition) { + // Paper start - Add predicate for blocks when raytracing +diff --git a/src/main/java/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.java +index c69ed3e899fc8d48afeb731bb3b2d97b5969e6e3..574175449af5b767f28e95ff8708ed37fedf4c7d 100644 +--- a/src/main/java/net/minecraft/world/level/Level.java ++++ b/src/main/java/net/minecraft/world/level/Level.java +@@ -816,10 +816,87 @@ public abstract class Level implements LevelAccessor, AutoCloseable, ca.spottedl + return null; + } + +- // Paper start ++ // Paper start - Broken down method of raytracing for EntityLiving#hasLineOfSight, replaces BlockGetter#clip(CollisionContext) + public net.minecraft.world.phys.BlockHitResult.Type clipDirect(Vec3 start, Vec3 end, net.minecraft.world.phys.shapes.CollisionContext context) { +- // To be patched over +- return this.clip(new ClipContext(start, end, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, context)).getType(); ++ // most of this code comes from BlockGetter#clip(CollisionContext, BiFunction, Function), but removes the needless functions ++ if (start.equals(end)) { ++ return net.minecraft.world.phys.BlockHitResult.Type.MISS; ++ } ++ ++ final double endX = Mth.lerp(-1.0E-7D, end.x, start.x); ++ final double endY = Mth.lerp(-1.0E-7D, end.y, start.y); ++ final double endZ = Mth.lerp(-1.0E-7D, end.z, start.z); ++ ++ final double startX = Mth.lerp(-1.0E-7D, start.x, end.x); ++ final double startY = Mth.lerp(-1.0E-7D, start.y, end.y); ++ final double startZ = Mth.lerp(-1.0E-7D, start.z, end.z); ++ ++ int currentX = Mth.floor(startX); ++ int currentY = Mth.floor(startY); ++ int currentZ = Mth.floor(startZ); ++ ++ final BlockPos.MutableBlockPos currentBlock = new BlockPos.MutableBlockPos(currentX, currentY, currentZ); ++ ++ LevelChunk chunk = this.getChunkIfLoaded(currentBlock); ++ if (chunk == null) { ++ return net.minecraft.world.phys.BlockHitResult.Type.MISS; ++ } ++ ++ final net.minecraft.world.phys.BlockHitResult.Type initialCheck = this.clipDirect(start, end, currentBlock, chunk.getBlockState(currentBlock), context); ++ if (initialCheck != null) { ++ return initialCheck; ++ } ++ ++ final double diffX = endX - startX; ++ final double diffY = endY - startY; ++ final double diffZ = endZ - startZ; ++ ++ final int xDirection = Mth.sign(diffX); ++ final int yDirection = Mth.sign(diffY); ++ final int zDirection = Mth.sign(diffZ); ++ ++ final double normalizedX = xDirection == 0 ? Double.MAX_VALUE : (double) xDirection / diffX; ++ final double normalizedY = yDirection == 0 ? Double.MAX_VALUE : (double) yDirection / diffY; ++ final double normalizedZ = zDirection == 0 ? Double.MAX_VALUE : (double) zDirection / diffZ; ++ ++ double normalizedXDirection = normalizedX * (xDirection > 0 ? 1.0D - Mth.frac(startX) : Mth.frac(startX)); ++ double normalizedYDirection = normalizedY * (yDirection > 0 ? 1.0D - Mth.frac(startY) : Mth.frac(startY)); ++ double normalizedZDirection = normalizedZ * (zDirection > 0 ? 1.0D - Mth.frac(startZ) : Mth.frac(startZ)); ++ ++ net.minecraft.world.phys.BlockHitResult.Type result; ++ ++ do { ++ if (normalizedXDirection > 1.0D && normalizedYDirection > 1.0D && normalizedZDirection > 1.0D) { ++ return net.minecraft.world.phys.BlockHitResult.Type.MISS; ++ } ++ ++ if (normalizedXDirection < normalizedYDirection) { ++ if (normalizedXDirection < normalizedZDirection) { ++ currentX += xDirection; ++ normalizedXDirection += normalizedX; ++ } else { ++ currentZ += zDirection; ++ normalizedZDirection += normalizedZ; ++ } ++ } else if (normalizedYDirection < normalizedZDirection) { ++ currentY += yDirection; ++ normalizedYDirection += normalizedY; ++ } else { ++ currentZ += zDirection; ++ normalizedZDirection += normalizedZ; ++ } ++ ++ currentBlock.set(currentX, currentY, currentZ); ++ if (chunk.getPos().x != currentBlock.getX() >> 4 || chunk.getPos().z != currentBlock.getZ() >> 4) { ++ chunk = this.getChunkIfLoaded(currentBlock); ++ if (chunk == null) { ++ return net.minecraft.world.phys.BlockHitResult.Type.MISS; ++ } ++ } ++ result = this.clipDirect(start, end, currentBlock, chunk.getBlockState(currentBlock), context); ++ } while (result == null); ++ ++ return result; + } + // Paper end + diff --git a/patches/removed/1.21.3/9999-Optimise-nearby-player-retrieval.patch b/patches/removed/1.21.3/9999-Optimise-nearby-player-retrieval.patch new file mode 100644 index 0000000000..d3e18e7c39 --- /dev/null +++ b/patches/removed/1.21.3/9999-Optimise-nearby-player-retrieval.patch @@ -0,0 +1,230 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Spottedleaf <[email protected]> +Date: Sat, 23 Sep 2023 23:15:52 -0700 +Subject: [PATCH] Optimise nearby player retrieval + +Instead of searching/testing every player online on the server, +we can instead use the nearby player tracking system to reduce +the number of tests per search. + +Feature patch + +diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java +index d4376ed215d97066a21e462fae2a0e25ad8a16a1..aab652174a8175765cad548f7c61ce353ca74803 100644 +--- a/src/main/java/net/minecraft/server/level/ServerLevel.java ++++ b/src/main/java/net/minecraft/server/level/ServerLevel.java +@@ -581,6 +581,115 @@ public class ServerLevel extends Level implements WorldGenLevel { + this.lagCompensationTick = (System.nanoTime() - net.minecraft.server.MinecraftServer.SERVER_INIT) / (java.util.concurrent.TimeUnit.MILLISECONDS.toNanos(50L)); + } + // Paper end - lag compensation ++ // Paper start - optimise nearby player retrieval ++ @Override ++ public java.util.List<net.minecraft.world.entity.player.Player> getNearbyPlayers(net.minecraft.world.entity.ai.targeting.TargetingConditions targetPredicate, ++ net.minecraft.world.entity.LivingEntity entity, ++ net.minecraft.world.phys.AABB box) { ++ return this.getNearbyEntities(Player.class, targetPredicate, entity, box); ++ } ++ ++ @Override ++ public Player getNearestPlayer(double x, double y, double z, double maxDistance, @Nullable Predicate<Entity> targetPredicate) { ++ if (maxDistance > 0.0D) { ++ io.papermc.paper.util.player.NearbyPlayers players = this.chunkSource.chunkMap.getNearbyPlayers(); ++ ++ com.destroystokyo.paper.util.maplist.ReferenceList<ServerPlayer> nearby = players.getPlayersByBlock( ++ io.papermc.paper.util.CoordinateUtils.getBlockCoordinate(x), ++ io.papermc.paper.util.CoordinateUtils.getBlockCoordinate(z), ++ io.papermc.paper.util.player.NearbyPlayers.NearbyMapType.GENERAL ++ ); ++ ++ if (nearby == null) { ++ return null; ++ } ++ ++ ServerPlayer nearest = null; ++ double nearestDist = maxDistance * maxDistance; ++ Object[] rawData = nearby.getRawData(); ++ for (int i = 0, len = nearby.size(); i < len; ++i) { ++ ServerPlayer player = (ServerPlayer)rawData[i]; ++ double dist = player.distanceToSqr(x, y, z); ++ if (dist >= nearestDist) { ++ continue; ++ } ++ ++ if (targetPredicate == null || targetPredicate.test(player)) { ++ nearest = player; ++ nearestDist = dist; ++ } ++ } ++ ++ return nearest; ++ } else { ++ ServerPlayer nearest = null; ++ double nearestDist = Double.MAX_VALUE; ++ ++ for (ServerPlayer player : this.players()) { ++ double dist = player.distanceToSqr(x, y, z); ++ if (dist >= nearestDist) { ++ continue; ++ } ++ ++ if (targetPredicate == null || targetPredicate.test(player)) { ++ nearest = player; ++ nearestDist = dist; ++ } ++ } ++ ++ return nearest; ++ } ++ } ++ ++ @Override ++ public Player getNearestPlayer(net.minecraft.world.entity.ai.targeting.TargetingConditions targetPredicate, LivingEntity entity) { ++ return this.getNearestPlayer(targetPredicate, entity, entity.getX(), entity.getY(), entity.getZ()); ++ } ++ ++ @Override ++ public Player getNearestPlayer(net.minecraft.world.entity.ai.targeting.TargetingConditions targetPredicate, LivingEntity entity, ++ double x, double y, double z) { ++ double range = targetPredicate.range; ++ if (range > 0.0D) { ++ io.papermc.paper.util.player.NearbyPlayers players = this.chunkSource.chunkMap.getNearbyPlayers(); ++ ++ com.destroystokyo.paper.util.maplist.ReferenceList<ServerPlayer> nearby = players.getPlayersByBlock( ++ io.papermc.paper.util.CoordinateUtils.getBlockCoordinate(x), ++ io.papermc.paper.util.CoordinateUtils.getBlockCoordinate(z), ++ io.papermc.paper.util.player.NearbyPlayers.NearbyMapType.GENERAL ++ ); ++ ++ if (nearby == null) { ++ return null; ++ } ++ ++ ServerPlayer nearest = null; ++ double nearestDist = Double.MAX_VALUE; ++ Object[] rawData = nearby.getRawData(); ++ for (int i = 0, len = nearby.size(); i < len; ++i) { ++ ServerPlayer player = (ServerPlayer)rawData[i]; ++ double dist = player.distanceToSqr(x, y, z); ++ if (dist >= nearestDist) { ++ continue; ++ } ++ ++ if (targetPredicate.test(entity, player)) { ++ nearest = player; ++ nearestDist = dist; ++ } ++ } ++ ++ return nearest; ++ } else { ++ return this.getNearestEntity(this.players(), targetPredicate, entity, x, y, z); ++ } ++ } ++ ++ @Nullable ++ public Player getNearestPlayer(net.minecraft.world.entity.ai.targeting.TargetingConditions targetPredicate, double x, double y, double z) { ++ return this.getNearestPlayer(targetPredicate, null, x, y, z); ++ } ++ // Paper end - optimise nearby player retrieval + + // Add env and gen to constructor, IWorldDataServer -> WorldDataServer + public ServerLevel(MinecraftServer minecraftserver, Executor executor, LevelStorageSource.LevelStorageAccess convertable_conversionsession, PrimaryLevelData iworlddataserver, ResourceKey<Level> resourcekey, LevelStem worlddimension, ChunkProgressListener worldloadlistener, boolean flag, long i, List<CustomSpawner> list, boolean flag1, @Nullable RandomSequences randomsequences, org.bukkit.World.Environment env, org.bukkit.generator.ChunkGenerator gen, org.bukkit.generator.BiomeProvider biomeProvider) { +diff --git a/src/main/java/net/minecraft/world/entity/ai/sensing/PlayerSensor.java b/src/main/java/net/minecraft/world/entity/ai/sensing/PlayerSensor.java +index 2e887e426dcd79e2dda401f127d0e01ca537e80e..65cd42ce9f553e0aa5bf248bdbf902f9d1f55460 100644 +--- a/src/main/java/net/minecraft/world/entity/ai/sensing/PlayerSensor.java ++++ b/src/main/java/net/minecraft/world/entity/ai/sensing/PlayerSensor.java +@@ -21,17 +21,50 @@ public class PlayerSensor extends Sensor<LivingEntity> { + + @Override + protected void doTick(ServerLevel world, LivingEntity entity) { +- List<Player> list = world.players() +- .stream() +- .filter(EntitySelector.NO_SPECTATORS) +- .filter(player -> entity.closerThan(player, 16.0)) +- .sorted(Comparator.comparingDouble(entity::distanceToSqr)) +- .collect(Collectors.toList()); ++ // Paper start - Perf: optimise nearby player retrieval & remove streams from hot code ++ io.papermc.paper.util.player.NearbyPlayers nearbyPlayers = world.chunkSource.chunkMap.getNearbyPlayers(); ++ net.minecraft.world.phys.Vec3 entityPos = entity.position(); ++ com.destroystokyo.paper.util.maplist.ReferenceList<net.minecraft.server.level.ServerPlayer> nearby = nearbyPlayers.getPlayersByChunk( ++ entity.chunkPosition().x, ++ entity.chunkPosition().z, ++ io.papermc.paper.util.player.NearbyPlayers.NearbyMapType.GENERAL_REALLY_SMALL ++ ); ++ ++ List<Player> players = new java.util.ArrayList<>(nearby == null ? 0 : nearby.size()); ++ if (nearby != null) { ++ Object[] rawData = nearby.getRawData(); ++ for (int index = 0, len = nearby.size(); index < len; ++index) { ++ net.minecraft.server.level.ServerPlayer player = (net.minecraft.server.level.ServerPlayer) rawData[index]; ++ if (player.isSpectator()) { ++ continue; ++ } ++ if (player.distanceToSqr(entityPos.x, entityPos.y, entityPos.z) >= (16.0 * 16.0)) { ++ continue; ++ } ++ players.add(player); ++ } ++ } ++ players.sort(Comparator.comparingDouble(entity::distanceToSqr)); + Brain<?> brain = entity.getBrain(); +- brain.setMemory(MemoryModuleType.NEAREST_PLAYERS, list); +- List<Player> list2 = list.stream().filter(player -> isEntityTargetable(entity, player)).collect(Collectors.toList()); +- brain.setMemory(MemoryModuleType.NEAREST_VISIBLE_PLAYER, list2.isEmpty() ? null : list2.get(0)); +- Optional<Player> optional = list2.stream().filter(player -> isEntityAttackable(entity, player)).findFirst(); +- brain.setMemory(MemoryModuleType.NEAREST_VISIBLE_ATTACKABLE_PLAYER, optional); ++ ++ brain.setMemory(MemoryModuleType.NEAREST_PLAYERS, players); ++ ++ Player firstTargetable = null; ++ Player firstAttackable = null; ++ for (Player player : players) { ++ if (firstTargetable == null && Sensor.isEntityTargetable(entity, player)) { ++ firstTargetable = player; ++ } ++ if (firstAttackable == null && Sensor.isEntityAttackable(entity, player)) { ++ firstAttackable = player; ++ } ++ ++ if (firstAttackable != null && firstTargetable != null) { ++ break; ++ } ++ } ++ brain.setMemory(MemoryModuleType.NEAREST_VISIBLE_PLAYER, firstTargetable); ++ brain.setMemory(MemoryModuleType.NEAREST_VISIBLE_ATTACKABLE_PLAYER, Optional.ofNullable(firstAttackable)); ++ // Paper end - Perf: optimise nearby player retrieval & remove streams from hot code + } + } +diff --git a/src/main/java/net/minecraft/world/entity/ai/targeting/TargetingConditions.java b/src/main/java/net/minecraft/world/entity/ai/targeting/TargetingConditions.java +index aecb0ad814586bfc5e56755ee14379a69388b38c..d2f0c3b26d4beedb49d86e0242d843590d469d02 100644 +--- a/src/main/java/net/minecraft/world/entity/ai/targeting/TargetingConditions.java ++++ b/src/main/java/net/minecraft/world/entity/ai/targeting/TargetingConditions.java +@@ -10,7 +10,7 @@ public class TargetingConditions { + public static final TargetingConditions DEFAULT = forCombat(); + private static final double MIN_VISIBILITY_DISTANCE_FOR_INVISIBLE_TARGET = 2.0; + private final boolean isCombat; +- private double range = -1.0; ++ public double range = -1.0; // Paper - public + private boolean checkLineOfSight = true; + private boolean testInvisible = true; + @Nullable +diff --git a/src/main/java/net/minecraft/world/level/EntityGetter.java b/src/main/java/net/minecraft/world/level/EntityGetter.java +index 21843501355a0c0c8d594e3e5312e97861c9a777..ea0aee88c7d901034427db201c1b2430f8a1d522 100644 +--- a/src/main/java/net/minecraft/world/level/EntityGetter.java ++++ b/src/main/java/net/minecraft/world/level/EntityGetter.java +@@ -233,9 +233,13 @@ public interface EntityGetter { + T livingEntity = null; + + for (T livingEntity2 : entityList) { ++ // Paper start - optimise nearby player retrieval; move up ++ // don't check entities outside closest range ++ double e = livingEntity2.distanceToSqr(x, y, z); ++ if (d == -1.0 || e < d) { ++ // Paper end - move up + if (targetPredicate.test(entity, livingEntity2)) { +- double e = livingEntity2.distanceToSqr(x, y, z); +- if (d == -1.0 || e < d) { ++ // Paper - optimise nearby player retrieval; move up + d = e; + livingEntity = livingEntity2; + } |