9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2025-12-30 04:19:13 +00:00
Files
Leaf/leaf-server/minecraft-patches/features/0265-Optimise-getEntities.patch
Dreeam f5b95a6716 Updated Upstream (Paper)
Upstream has released updates that appear to apply and compile correctly

Paper Changes:
PaperMC/Paper@b0da38c2 Repository details in RuntimeException for MavenLibraryResolver#addRepository (#12939)
PaperMC/Paper@1922be90 Update custom tags (#12183)
PaperMC/Paper@79cf1353 Ignore HopperInventorySearchEvent when it has no listeners (#13009)
PaperMC/Paper@ea014f7a feat: add stuckEntityPoiRetryDelay config (#12949)
PaperMC/Paper@a9e76749 Support for showNotification in PlayerRecipeDiscoverEvent (#12992)
PaperMC/Paper@5622c9dd Expose attribute sentiment (#12974)
PaperMC/Paper@42b653b1 Expose more argument types (#12665)
PaperMC/Paper@52d9a221 [ci/skip] Fix typo in Display javadoc (#13010)
PaperMC/Paper@614e9acf Improve APIs around riptide tridents (#12996)
PaperMC/Paper@51706e5a Fixed DyeItem sheep dye hunk
2025-08-25 15:52:00 -04:00

101 lines
5.2 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Taiyou06 <kaandindar21@gmail.com>
Date: Sat, 12 Jul 2025 02:00:43 +0200
Subject: [PATCH] Optimise getEntities
Co-authored by: Martijn Muijsers <martijnmuijsers@live.nl>
diff --git a/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/ChunkEntitySlices.java b/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/ChunkEntitySlices.java
index 7f508c50e451a0689218cd36e6ac993f87092c04..a6c1f450f32fa688b102140963fd5bfb6b4e6ddf 100644
--- a/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/ChunkEntitySlices.java
+++ b/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/ChunkEntitySlices.java
@@ -546,6 +546,15 @@ public final class ChunkEntitySlices {
final BasicEntityList<Entity>[] entitiesBySection = this.entitiesBySection;
+ // Leaf start - Optimise getEntities
+ // Cache AABB fields to local variables to reduce field accesses inside the hot loop.
+ final double boxMinX = box.minX;
+ final double boxMinY = box.minY;
+ final double boxMinZ = box.minZ;
+ final double boxMaxX = box.maxX;
+ final double boxMaxY = box.maxY;
+ final double boxMaxZ = box.maxZ;
+
for (int section = min; section <= max; ++section) {
final BasicEntityList<Entity> list = entitiesBySection[section - minSection];
@@ -554,11 +563,19 @@ public final class ChunkEntitySlices {
}
final Entity[] storage = list.storage;
+ final int len = Math.min(storage.length, list.size());
- for (int i = 0, len = Math.min(storage.length, list.size()); i < len; ++i) {
+ for (int i = 0; i < len; ++i) {
final Entity entity = storage[i];
- if (entity == null || entity == except || !entity.getBoundingBox().intersects(box)) {
+ if (entity == null || entity == except) {
+ continue;
+ }
+
+ // Inline AABB#intersects to avoid a method call and use the cached AABB fields.
+ final AABB entityBB = entity.getBoundingBox();
+ if (entityBB.maxX <= boxMinX || entityBB.minX >= boxMaxX || entityBB.maxY <= boxMinY || entityBB.minY >= boxMaxY || entityBB.maxZ <= boxMinZ || entityBB.minZ >= boxMaxZ) {
+ // Leaf end - Optimise getEntities
continue;
}
@@ -585,19 +602,34 @@ public final class ChunkEntitySlices {
final BasicEntityList<Entity>[] entitiesBySection = this.entitiesBySection;
+ // Leaf start - Optimise getEntities
+ // Cache AABB fields to local variables to reduce field accesses inside the hot loop.
+ final double boxMinX = box.minX;
+ final double boxMinY = box.minY;
+ final double boxMinZ = box.minZ;
+ final double boxMaxX = box.maxX;
+ final double boxMaxY = box.maxY;
+ final double boxMaxZ = box.maxZ;
+
for (int section = min; section <= max; ++section) {
final BasicEntityList<Entity> list = entitiesBySection[section - minSection];
-
if (list == null) {
continue;
}
final Entity[] storage = list.storage;
+ final int len = Math.min(storage.length, list.size());
- for (int i = 0, len = Math.min(storage.length, list.size()); i < len; ++i) {
+ for (int i = 0; i < len; ++i) {
final Entity entity = storage[i];
+ if (entity == null || entity == except) {
+ continue;
+ }
- if (entity == null || entity == except || !entity.getBoundingBox().intersects(box)) {
+ // Inline AABB#intersects to avoid a method call and use the cached AABB fields.
+ final AABB entityBB = entity.getBoundingBox();
+ if (entityBB.maxX <= boxMinX || entityBB.minX >= boxMaxX || entityBB.maxY <= boxMinY || entityBB.minY >= boxMaxY || entityBB.maxZ <= boxMinZ || entityBB.minZ >= boxMaxZ) {
+ // Leaf end - Optimise getEntities
continue;
}
diff --git a/net/minecraft/world/entity/LivingEntity.java b/net/minecraft/world/entity/LivingEntity.java
index 09e0b1bb9f8e4605097af6466681f9aec4e0204f..4ab8e8b4301c4ab474c7c4362b40303627363e82 100644
--- a/net/minecraft/world/entity/LivingEntity.java
+++ b/net/minecraft/world/entity/LivingEntity.java
@@ -2276,7 +2276,7 @@ public abstract class LivingEntity extends Entity implements Attackable, Waypoin
@Override
public boolean isAlive() {
- return !this.isRemoved() && this.getHealth() > 0.0F && !this.dead; // Paper - Check this.dead
+ return !this.dead && !this.isRemoved() && this.getHealth() > 0.0F; // Paper - Check this.dead // Leaf - Optimise getEntities - check the cheapest first
}
public boolean isLookingAtMe(LivingEntity entity, double tolerance, boolean scaleByDistance, boolean visual, double... yValues) {