Skip to content

Commit 83041be

Browse files
committed
Optimize AABB intersect
1 parent 93171d9 commit 83041be

File tree

4 files changed

+68
-0
lines changed

4 files changed

+68
-0
lines changed

src/main/java/github/kasuminova/stellarcore/common/config/category/Performance.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,11 @@ public static class Vanilla {
188188
@Config.Name("PropertyEnumHashCodeCache")
189189
public boolean propertyEnumHashCodeCache = true;
190190

191+
@Config.Comment("(Client/Server Performance) Optimize BoundingBox intersect check.")
192+
@Config.RequiresMcRestart
193+
@Config.Name("BoundingBoxIntersectCheck")
194+
public boolean boundingBoxIntersectCheck = true;
195+
191196
@Config.Comment("(Server Performance) Improving BlockStateContainer$BlockStateImplementation#hashCode Performance with hashCode cache.")
192197
@Config.RequiresMcRestart
193198
@Config.Name("BlockStateImplementationHashCodeCache")

src/main/java/github/kasuminova/stellarcore/mixin/StellarCoreEarlyMixinLoader.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public class StellarCoreEarlyMixinLoader implements IFMLLoadingPlugin {
4040
addMixinCFG("mixins.stellar_core_minecraft_nnlist.json", () -> StellarCoreConfig.PERFORMANCE.vanilla.nonNullList);
4141
addMixinCFG("mixins.stellar_core_minecraft_noglerror.json", () -> StellarCoreConfig.PERFORMANCE.vanilla.noGlError);
4242
addMixinCFG("mixins.stellar_core_minecraft_property.json", () -> StellarCoreConfig.PERFORMANCE.vanilla.propertyEnumHashCodeCache);
43+
addMixinCFG("mixins.stellar_core_minecraft_phys.json", () -> StellarCoreConfig.PERFORMANCE.vanilla.boundingBoxIntersectCheck);
4344
addMixinCFG("mixins.stellar_core_minecraft_randomtick.json", () -> StellarCoreConfig.PERFORMANCE.vanilla.parallelRandomBlockTicker);
4445
addMixinCFG("mixins.stellar_core_minecraft_renderglobal.json", () -> StellarCoreConfig.PERFORMANCE.vanilla.alwaysDeferChunkUpdates);
4546
addMixinCFG("mixins.stellar_core_minecraft_resourcelocation.json", () -> StellarCoreConfig.PERFORMANCE.vanilla.resourceLocationCanonicalization && !StellarCoreConfig.PERFORMANCE.vanilla.resourceLocationCanonicalizationAsync);
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package github.kasuminova.stellarcore.mixin.minecraft.phys;
2+
3+
import net.minecraft.util.math.AxisAlignedBB;
4+
import org.spongepowered.asm.mixin.Final;
5+
import org.spongepowered.asm.mixin.Mixin;
6+
import org.spongepowered.asm.mixin.Overwrite;
7+
import org.spongepowered.asm.mixin.Shadow;
8+
9+
@Mixin(value = AxisAlignedBB.class, priority = 999)
10+
public abstract class MixinAxisAlignedBB {
11+
@Shadow @Final public double minX;
12+
13+
@Shadow @Final public double minY;
14+
15+
@Shadow @Final public double minZ;
16+
17+
@Shadow @Final public double maxX;
18+
19+
@Shadow @Final public double maxY;
20+
21+
@Shadow @Final public double maxZ;
22+
23+
/**
24+
* @author Creeam
25+
* @reason Optimize AABB
26+
*/
27+
@Overwrite
28+
public AxisAlignedBB intersect(AxisAlignedBB other) {
29+
return new AxisAlignedBB(
30+
this.minX > other.minX ? this.minX : other.minX,
31+
this.minY > other.minY ? this.minY : other.minY,
32+
this.minZ > other.minZ ? this.minZ : other.minZ,
33+
this.maxX < other.maxX ? this.maxX : other.maxX,
34+
this.maxY < other.maxY ? this.maxY : other.maxY,
35+
this.maxZ < other.maxZ ? this.maxZ : other.maxZ
36+
);
37+
}
38+
39+
/**
40+
* @author Creeam
41+
* @reason Direct comparison, avoid method call
42+
*/
43+
@Overwrite
44+
public boolean intersects(AxisAlignedBB other) {
45+
return this.minX < other.maxX &&
46+
this.maxX > other.minX &&
47+
this.minY < other.maxY &&
48+
this.maxY > other.minY &&
49+
this.minZ < other.maxZ &&
50+
this.maxZ > other.minZ;
51+
}
52+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"package": "github.kasuminova.stellarcore.mixin.minecraft.phys",
3+
"refmap": "mixins.stellar_core.refmap.json",
4+
"target": "@env(DEFAULT)",
5+
"minVersion": "0.8",
6+
"compatibilityLevel": "JAVA_8",
7+
"mixins": [
8+
"MixinAxisAlignedBB"
9+
]
10+
}

0 commit comments

Comments
 (0)