From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Taiyou06 Date: Sun, 16 Feb 2025 19:03:23 +0100 Subject: [PATCH] Optimize AABB diff --git a/net/minecraft/world/phys/AABB.java b/net/minecraft/world/phys/AABB.java index f64c04b32dd2d0fe143fc8bf9f498e52beb66a58..00daaff66bd26e9ca15a7eb4052ff38f9e662f7b 100644 --- a/net/minecraft/world/phys/AABB.java +++ b/net/minecraft/world/phys/AABB.java @@ -220,13 +220,16 @@ public class AABB { } public AABB intersect(AABB other) { - double max = Math.max(this.minX, other.minX); - double max1 = Math.max(this.minY, other.minY); - double max2 = Math.max(this.minZ, other.minZ); - double min = Math.min(this.maxX, other.maxX); - double min1 = Math.min(this.maxY, other.maxY); - double min2 = Math.min(this.maxZ, other.maxZ); - return new AABB(max, max1, max2, min, min1, min2); + // Leaf start - Optimize AABB + return new AABB( + this.minX > other.minX ? this.minX : other.minX, + this.minY > other.minY ? this.minY : other.minY, + this.minZ > other.minZ ? this.minZ : other.minZ, + this.maxX < other.maxX ? this.maxX : other.maxX, + this.maxY < other.maxY ? this.maxY : other.maxY, + this.maxZ < other.maxZ ? this.maxZ : other.maxZ + ); + // Leaf end - Optimize AABB } public AABB minmax(AABB other) { @@ -258,16 +261,39 @@ public class AABB { } public boolean intersects(AABB other) { - return this.intersects(other.minX, other.minY, other.minZ, other.maxX, other.maxY, other.maxZ); + // Leaf start - Optimize AABB + // Removed redundant method call overhead + return this.minX < other.maxX && + this.maxX > other.minX && + this.minY < other.maxY && + this.maxY > other.minY && + this.minZ < other.maxZ && + this.maxZ > other.minZ; + // Leaf end - Optimize AABB } public boolean intersects(double x1, double y1, double z1, double x2, double y2, double z2) { - return this.minX < x2 && this.maxX > x1 && this.minY < y2 && this.maxY > y1 && this.minZ < z2 && this.maxZ > z1; + // Leaf start - Optimize AABB + // No temporary variables needed, direct comparison + return this.minX < x2 && + this.maxX > x1 && + this.minY < y2 && + this.maxY > y1 && + this.minZ < z2 && + this.maxZ > z1; + // Leaf end - Optimize AABB } public boolean intersects(Vec3 min, Vec3 max) { return this.intersects( - Math.min(min.x, max.x), Math.min(min.y, max.y), Math.min(min.z, max.z), Math.max(min.x, max.x), Math.max(min.y, max.y), Math.max(min.z, max.z) + // Leaf start - Optimize AABB + min.x < max.x ? min.x : max.x, + min.y < max.y ? min.y : max.y, + min.z < max.z ? min.z : max.z, + min.x > max.x ? min.x : max.x, + min.y > max.y ? min.y : max.y, + min.z > max.z ? min.z : max.z + // Leaf end - Optimize AABB ); }