Skip to content

Commit 1a183d4

Browse files
authored
optimize collidedAlongVector (#541)
1 parent e48953e commit 1a183d4

File tree

1 file changed

+103
-0
lines changed

1 file changed

+103
-0
lines changed
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2+
From: hayanesuru <[email protected]>
3+
Date: Tue, 21 Oct 2025 10:45:21 +0900
4+
Subject: [PATCH] optimize collidedAlongVector
5+
6+
7+
diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java
8+
index f6d619709d4e5b0e6d1b943226579d7388835cdb..dea7ebe75a043b509e49a589a66ec99abb32d6ed 100644
9+
--- a/net/minecraft/world/entity/Entity.java
10+
+++ b/net/minecraft/world/entity/Entity.java
11+
@@ -1749,7 +1749,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
12+
}
13+
VoxelShape entityInsideCollisionShape = blockState.getEntityInsideCollisionShape(level, pos, this);
14+
boolean flag = entityInsideCollisionShape == Shapes.block()
15+
- || this.collidedWithShapeMovingFrom(vec3, vec31, entityInsideCollisionShape.move(new Vec3(pos)).toAabbs());
16+
+ || this.collidedWithShapeMovingFrom(vec3, vec31, entityInsideCollisionShape.move(new Vec3(pos))); // Leaf - optimize collidedAlongVector
17+
if (flag) {
18+
try {
19+
stepBasedCollector.advanceStep(index, pos); // Paper - track position inside effect was triggered on
20+
@@ -1783,15 +1783,30 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
21+
22+
public boolean collidedWithFluid(FluidState fluid, BlockPos pos, Vec3 from, Vec3 to) {
23+
AABB aabb = fluid.getAABB(this.level(), pos);
24+
- return aabb != null && this.collidedWithShapeMovingFrom(from, to, List.of(aabb));
25+
+ return aabb != null && this.collidedWithShapeMovingFrom(from, to, aabb); // Leaf - optimize collidedAlongVector
26+
}
27+
28+
public boolean collidedWithShapeMovingFrom(Vec3 from, Vec3 to, List<AABB> boxes) {
29+
+ // Leaf - optimize collidedAlongVector - diff on change
30+
AABB aabb = this.makeBoundingBox(from);
31+
Vec3 vec3 = to.subtract(from);
32+
return aabb.collidedAlongVector(vec3, boxes);
33+
}
34+
35+
+ // Leaf start - optimize collidedAlongVector
36+
+ public final boolean collidedWithShapeMovingFrom(Vec3 from, Vec3 to, AABB boxes) {
37+
+ AABB aabb = this.makeBoundingBox(from);
38+
+ Vec3 vec3 = to.subtract(from);
39+
+ return aabb.collidedAlongVector(vec3, boxes);
40+
+ }
41+
+ public final boolean collidedWithShapeMovingFrom(Vec3 from, Vec3 to, VoxelShape boxes) {
42+
+ AABB aabb = this.makeBoundingBox(from);
43+
+ Vec3 vec3 = to.subtract(from);
44+
+ AABB box = boxes.moonrise$getSingleAABBRepresentation();
45+
+ return box != null ? aabb.collidedAlongVector(vec3, box) : aabb.collidedAlongVector(vec3, boxes.toAabbs());
46+
+ }
47+
+ // Leaf end - optimize collidedAlongVector
48+
+
49+
protected void onInsideBlock(BlockState state) {
50+
}
51+
52+
diff --git a/net/minecraft/world/entity/monster/Ghast.java b/net/minecraft/world/entity/monster/Ghast.java
53+
index c249946248a5465fd9b08eac07a306ad2aee2ae6..671b6874b8c322f1ccc85163e9c38a79e1da93ed 100644
54+
--- a/net/minecraft/world/entity/monster/Ghast.java
55+
+++ b/net/minecraft/world/entity/monster/Ghast.java
56+
@@ -357,7 +357,7 @@ public class Ghast extends Mob implements Enemy {
57+
} else {
58+
boolean flag = from != null && to != null;
59+
boolean flag1 = flag
60+
- ? !this.ghast.collidedWithShapeMovingFrom(from, to, blockState.getCollisionShape(level, pos).move(new Vec3(pos)).toAabbs())
61+
+ ? !this.ghast.collidedWithShapeMovingFrom(from, to, blockState.getCollisionShape(level, pos).move(new Vec3(pos))) // Leaf - optimize collidedAlongVector
62+
: blockState.getCollisionShape(level, pos).isEmpty();
63+
if (!this.careful) {
64+
return flag1;
65+
diff --git a/net/minecraft/world/phys/AABB.java b/net/minecraft/world/phys/AABB.java
66+
index 2010b30bf1050273694db707b0059ed8251a41f8..67f1b17e4ecfe1bea469faf0d776ae1626fe9b28 100644
67+
--- a/net/minecraft/world/phys/AABB.java
68+
+++ b/net/minecraft/world/phys/AABB.java
69+
@@ -418,21 +418,34 @@ public class AABB {
70+
}
71+
}
72+
73+
+ // Leaf start - optimize collidedAlongVector
74+
+ public final boolean collidedAlongVector(Vec3 vector, AABB aabb) {
75+
+ Vec3 center = this.getCenter();
76+
+ Vec3 vec3 = center.add(vector);
77+
+ AABB aabb1 = aabb.inflate(this.getXsize() * 0.5, this.getYsize() * 0.5, this.getZsize() * 0.5);
78+
+ return aabb1.contains(vec3) || aabb1.contains(center) || aabb1.clip(center, vec3).isPresent();
79+
+ }
80+
+ // Leaf end - optimize collidedAlongVector
81+
+
82+
public boolean collidedAlongVector(Vec3 vector, List<AABB> boxes) {
83+
+ // Leaf - optimize collidedAlongVector - diff on change
84+
Vec3 center = this.getCenter();
85+
Vec3 vec3 = center.add(vector);
86+
87+
for (AABB aabb : boxes) {
88+
+ // Leaf - optimize collidedAlongVector - diff on change
89+
AABB aabb1 = aabb.inflate(this.getXsize() * 0.5, this.getYsize() * 0.5, this.getZsize() * 0.5);
90+
if (aabb1.contains(vec3) || aabb1.contains(center)) {
91+
return true;
92+
}
93+
94+
+ // Leaf - optimize collidedAlongVector - diff on change
95+
if (aabb1.clip(center, vec3).isPresent()) {
96+
return true;
97+
}
98+
}
99+
100+
+ // Leaf - optimize collidedAlongVector - diff on change
101+
return false;
102+
}
103+

0 commit comments

Comments
 (0)