mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2026-01-03 14:22:26 +00:00
* Fix TE Lag * Sepals Rearrange the attackable conditions * Cache ItemStack max stack size * fix build * extra: Skip dirty stats copy when requesting player stats * extra: Reset dirty flag when loading maps from the disk * extra: Supporting block cache * extra: Avoid useless deque clear on - credit: @MachineBreaker * experimental/draft: Optimize SortedArraySet * experimental/draft: Simplify SortedArraySet - sometime complex stuff doesnt mean faster. * extra: Change maps/sets in brain + remove streams from villagers * extra: Remove 'copyOf' from Baby Villager Sensor * experimental: Rewrite trigger in SimpleCriterionTrigger * [ci/skip] fix comments * Faster setter for SimpleCriterionTrigger * extra: Cache and optimize fluidOnEyes * Sync changes * [ci/skip] cleanup * extra: QuadTree implementation for isChunkNearPlayer * [ci/skip] cleanup * [ci/skip] cleanup * [ci/skip] clean up * [ci/skip] cleanup * Only player pushable * Store chunkPos with keys * [ci/skip] cleanup * [ci/skip] cleanup * cleanup * rebuild patches * cache some more stuff * extra: optimize collectTickingChunks * remove quadTree optimization for now (will open a new PR just for that) * temp: Lazily optimize isChunkNearPlayer * Inline filter & merge as a single loop * [ci/skip] Add diff on change * extra: optimize everything but the testing itself on getEntities * [ci/skip] cleanup * Optimize chunkUnloadQueue * Remove iterators from inventory * [ci/skip] Add TODOs * i hate programming * remove forEach * extra: Alternative Brain Behaviour * remove: opt getEntities + cache fluidOnEyes * extra: Improve checkDespawn - credits: @kidofcubes * extra: Improve pushEntity and getEntities * yeet this * VERY EXPERIMENTAL: getEntities Optimization * fix bunch of issues from getEntities patch * extra: slightly optimize getNearestPlayer - credits: @kidofcubes * drop a patch for now (will open a new pr) * move these to a new branch * fix and optimize checkDespawn patches * Rebuild Patches * [ci/skip] Update benchmark * [ci/skip] cleanup * Drop * [ci/skip] Drop * Rebuild * [ci/skip] * Add configurable brain running behavior cache update interval * Move to new pr * [ci/skip] Update benchmark --------- Co-authored-by: MachineBreaker <saltspigotpp@gmail.com> Co-authored-by: kidofcubes <kidofcubes@gmail.com> Co-authored-by: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com>
59 lines
2.3 KiB
Diff
59 lines
2.3 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Taiyou06 <kaandindar21@gmail.com>
|
|
Date: Sun, 16 Feb 2025 09:21:50 +0100
|
|
Subject: [PATCH] Slightly optimise getNearestPlayer
|
|
|
|
|
|
diff --git a/net/minecraft/world/level/EntityGetter.java b/net/minecraft/world/level/EntityGetter.java
|
|
index 670860df81a3abfc1b8b53be505fce0ee32ee2c4..083a2b5da246113913bcd5d0b2b9be42cf0554d9 100644
|
|
--- a/net/minecraft/world/level/EntityGetter.java
|
|
+++ b/net/minecraft/world/level/EntityGetter.java
|
|
@@ -201,23 +201,42 @@ public interface EntityGetter extends ca.spottedleaf.moonrise.patches.chunk_syst
|
|
}
|
|
// Paper end - Affects Spawning API
|
|
|
|
+ // Leaf start - Slightly optimise getNearestPlayer
|
|
@Nullable
|
|
default Player getNearestPlayer(double x, double y, double z, double distance, @Nullable Predicate<Entity> predicate) {
|
|
- double d = -1.0;
|
|
+ if (distance < 0.0) {
|
|
+ distance = Double.MAX_VALUE;
|
|
+ } else {
|
|
+ distance = distance * distance;
|
|
+ }
|
|
+
|
|
Player player = null;
|
|
|
|
- for (Player player1 : this.players()) {
|
|
- if (predicate == null || predicate.test(player1)) {
|
|
+ if (predicate == null) {
|
|
+ for (int i = 0; i < this.players().size(); i++) {
|
|
+ Player player1 = this.players().get(i);
|
|
double d1 = player1.distanceToSqr(x, y, z);
|
|
- if ((distance < 0.0 || d1 < distance * distance) && (d == -1.0 || d1 < d)) {
|
|
- d = d1;
|
|
+ if (d1 < distance) {
|
|
+ distance = d1;
|
|
player = player1;
|
|
}
|
|
}
|
|
+ } else {
|
|
+ for (int i = 0; i < this.players().size(); i++) {
|
|
+ Player player1 = this.players().get(i);
|
|
+ if (predicate.test(player1)) {
|
|
+ double d1 = player1.distanceToSqr(x, y, z);
|
|
+ if (d1 < distance) {
|
|
+ distance = d1;
|
|
+ player = player1;
|
|
+ }
|
|
+ }
|
|
+ }
|
|
}
|
|
|
|
return player;
|
|
}
|
|
+ // Leaf end - Slightly optimise getNearestPlayer
|
|
|
|
// Paper start
|
|
default List<org.bukkit.entity.HumanEntity> findNearbyBukkitPlayers(double x, double y, double z, double radius, boolean notSpectator) {
|