Skip to content

Commit

Permalink
Merge "Optimize getNearestPlayer for high player count"
Browse files Browse the repository at this point in the history
  • Loading branch information
sofianedjerbi committed Jun 21, 2023
1 parent 47979cc commit cb48e11
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 22 deletions.
22 changes: 0 additions & 22 deletions patches/server/0027-Swap-distanceToSqr-and-EntitySelector.patch

This file was deleted.

46 changes: 46 additions & 0 deletions patches/server/0027-Swap-distanceToSqr-and-target-test.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Xymb <[email protected]>
Date: Sat, 17 Jun 2023 19:52:29 +0300
Subject: [PATCH] Swap distanceToSqr and target test


diff --git a/src/main/java/net/minecraft/world/level/EntityGetter.java b/src/main/java/net/minecraft/world/level/EntityGetter.java
index b1a6a66ed02706c1adc36dcedfa415f5a24a25a0..97a5eca200fd606d6102e40f9b8c32c2e7652cf9 100644
--- a/src/main/java/net/minecraft/world/level/EntityGetter.java
+++ b/src/main/java/net/minecraft/world/level/EntityGetter.java
@@ -99,9 +99,9 @@ public interface EntityGetter {
Player player = null;

for(Player player2 : this.getLocalPlayers()) { // Folia - region threading
- if (targetPredicate == null || targetPredicate.test(player2)) {
+ if (true || targetPredicate == null || targetPredicate.test(player2)) { // Kaiiju - Move this down
double e = player2.distanceToSqr(x, y, z);
- if ((maxDistance < 0.0D || e < maxDistance * maxDistance) && (d == -1.0D || e < d)) {
+ if ((maxDistance < 0.0D || e < maxDistance * maxDistance) && (d == -1.0D || e < d) && (targetPredicate == null || targetPredicate.test(player2))) { // Kaiiju
d = e;
player = player2;
}
@@ -147,9 +147,10 @@ public interface EntityGetter {
// Paper start
default boolean hasNearbyAlivePlayerThatAffectsSpawning(double x, double y, double z, double range) {
for (Player player : this.getLocalPlayers()) { // Folia - region threading
- if (EntitySelector.PLAYER_AFFECTS_SPAWNING.test(player)) { // combines NO_SPECTATORS and LIVING_ENTITY_STILL_ALIVE with an "affects spawning" check
+ if (true || EntitySelector.PLAYER_AFFECTS_SPAWNING.test(player)) { // combines NO_SPECTATORS and LIVING_ENTITY_STILL_ALIVE with an "affects spawning" check // Kaiiju - Move this down
double distanceSqr = player.distanceToSqr(x, y, z);
if (range < 0.0D || distanceSqr < range * range) {
+ if (EntitySelector.PLAYER_AFFECTS_SPAWNING.test(player)) // Kaiiju
return true;
}
}
@@ -199,9 +200,9 @@ public interface EntityGetter {
T livingEntity = null;

for(T livingEntity2 : entityList) {
- if (targetPredicate.test(entity, livingEntity2)) {
+ if (true || targetPredicate.test(entity, livingEntity2)) { // Kaiiju - Move this down
double e = livingEntity2.distanceToSqr(x, y, z);
- if (d == -1.0D || e < d) {
+ if ((d == -1.0D || e < d) && targetPredicate.test(entity, livingEntity2)) { // Kaiiju
d = e;
livingEntity = livingEntity2;
}

0 comments on commit cb48e11

Please sign in to comment.