Skip to content

Commit e48953e

Browse files
authored
merge Sakura check inside blocks optimizations (#542)
* merge Sakura check inside blocks * add end comment * [ci/skip] Reorder patches
1 parent 0ddbeae commit e48953e

27 files changed

+66
-52
lines changed

leaf-server/minecraft-patches/features/0291-optimize-checkInsideBlocks.patch renamed to leaf-server/minecraft-patches/features/0264-optimize-checkInsideBlocks.patch

Lines changed: 52 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,15 @@ Subject: [PATCH] optimize checkInsideBlocks
55

66

77
diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java
8-
index 4689764a580d7dca468cdfa2b0fef7e70c57687f..e4c2c0b4ea2b153266c2bb35574167364029bc7c 100644
8+
index ea137958c70f80349041cd27d1503f7b8def2a69..a198c696e474372f49706b2758879b116cf9bc82 100644
99
--- a/net/minecraft/world/entity/Entity.java
1010
+++ b/net/minecraft/world/entity/Entity.java
11-
@@ -1723,72 +1723,57 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
11+
@@ -1700,76 +1700,61 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
12+
}
13+
}
14+
15+
- // Leaf start - optimize checkInsideBlocks calls
16+
+ // Leaf start - optimize checkInsideBlocks
1217
private void checkInsideBlocks(Vec3 vec3, Vec3 vec31, InsideBlockEffectApplier.StepBasedCollector stepBasedCollector, LongSet set) {
1318
final Level level = this.level();
1419
AABB aabb = this.getBoundingBox().move(vec31.subtract(this.position())).deflate(1.0E-5F);
@@ -115,7 +120,7 @@ index 4689764a580d7dca468cdfa2b0fef7e70c57687f..e4c2c0b4ea2b153266c2bb3557416736
115120
);
116121
}
117122
-// Leaf end - optimize checkInsideBlocks calls
118-
+ // Leaf end - optimize checkInsideBlocks calls
123+
+ // Leaf end - optimize checkInsideBlocks
119124

120125
private void debugBlockIntersection(BlockPos blockPos, boolean flag, boolean flag1) {
121126
}
@@ -202,14 +207,14 @@ index 92b9c324cb6aab415abe2e77c5844b74c251a42f..eba3896b73c70f29732388373e89bf7c
202207

203208
// Paper start - track position inside effect was triggered on
204209
diff --git a/net/minecraft/world/level/BlockGetter.java b/net/minecraft/world/level/BlockGetter.java
205-
index eeddffbe6a47dc1a42c07f286bfec0cbde33fc17..b0da274c944fcef6aaae39b43f05a79110e4bb16 100644
210+
index eeddffbe6a47dc1a42c07f286bfec0cbde33fc17..b953bbccbbc357724adf8f368ad5893fcbd635fc 100644
206211
--- a/net/minecraft/world/level/BlockGetter.java
207212
+++ b/net/minecraft/world/level/BlockGetter.java
208-
@@ -255,6 +255,81 @@ public interface BlockGetter extends LevelHeightAccessor {
213+
@@ -255,6 +255,90 @@ public interface BlockGetter extends LevelHeightAccessor {
209214
}
210215
}
211216

212-
+ // Leaf start
217+
+ // Leaf start - optimize checkInsideBlocks
213218
+ static boolean leaf$forEachBlockIntersectedBetween(it.unimi.dsi.fastutil.longs.LongSet set, Vec3 from, Vec3 to, AABB boundingBox, BlockGetter.BlockStepVisitor visitor) {
214219
+ Vec3 vec3 = to.subtract(from);
215220
+ BlockPos.MutableBlockPos cursor = new BlockPos.MutableBlockPos();
@@ -243,46 +248,55 @@ index eeddffbe6a47dc1a42c07f286bfec0cbde33fc17..b0da274c944fcef6aaae39b43f05a791
243248
+ }
244249
+
245250
+ return true;
251+
+ }
252+
+ int i;
253+
+ final boolean xZero = vec3.x == 0.0;
254+
+ final boolean yZero = vec3.y == 0.0;
255+
+ final boolean zZero = vec3.z == 0.0;
256+
+ if (xZero && yZero || yZero && zZero || xZero && zZero) {
257+
+ i = 0;
258+
+ double fac = Math.min(16.0 / vec3.length(), 1.0);
259+
+ boundingBox = boundingBox.move(-vec3.x, -vec3.y, -vec3.z)
260+
+ .expandTowards(vec3.x * fac, vec3.y * fac, vec3.z * fac);
246261
+ } else {
247262
+ Vec3 minPosition = boundingBox.getMinPosition();
248263
+ Vec3 vec31 = minPosition.subtract(vec3);
249-
+ int i = addCollisionsAlongTravel(set, vec31, minPosition, boundingBox, visitor);
264+
+ i = addCollisionsAlongTravel(set, vec31, minPosition, boundingBox, visitor);
250265
+ if (i < 0) {
251266
+ return false;
252-
+ } else {
253-
+ int pos1x = Mth.floor(boundingBox.minX);
254-
+ int pos1y = Mth.floor(boundingBox.minY);
255-
+ int pos1z = Mth.floor(boundingBox.minZ);
256-
+ int pos2x = Mth.floor(boundingBox.maxX);
257-
+ int pos2y = Mth.floor(boundingBox.maxY);
258-
+ int pos2z = Mth.floor(boundingBox.maxZ);
259-
+ int x1 = Math.min(pos1x, pos2x);
260-
+ int y1 = Math.min(pos1y, pos2y);
261-
+ int z1 = Math.min(pos1z, pos2z);
262-
+ int j = Math.max(pos1x, pos2x) - x1 + 1;
263-
+ int i1 = Math.max(pos1y, pos2y) - y1 + 1;
264-
+ int i2 = Math.max(pos1z, pos2z) - z1 + 1;
265-
+ int i3 = j * i1 * i2;
266-
+ int index = 0;
267-
+ while (index != i3) {
268-
+ int i4 = index % j;
269-
+ int i5 = index / j;
270-
+ int i6 = i5 % i1;
271-
+ int i7 = i5 / i1;
272-
+ index++;
273-
+ int x0 = x1 + i4;
274-
+ int y0 = y1 + i6;
275-
+ int z0 = z1 + i7;
276-
+ if (set.add(BlockPos.asLong(x0, y0, z0)) && !visitor.visit(cursor.set(x0, y0, z0), i + 1)) {
277-
+ return false;
278-
+ }
279-
+ }
280-
+
281-
+ return true;
282267
+ }
283268
+ }
269+
+ int pos1x = Mth.floor(boundingBox.minX);
270+
+ int pos1y = Mth.floor(boundingBox.minY);
271+
+ int pos1z = Mth.floor(boundingBox.minZ);
272+
+ int pos2x = Mth.floor(boundingBox.maxX);
273+
+ int pos2y = Mth.floor(boundingBox.maxY);
274+
+ int pos2z = Mth.floor(boundingBox.maxZ);
275+
+ int x1 = Math.min(pos1x, pos2x);
276+
+ int y1 = Math.min(pos1y, pos2y);
277+
+ int z1 = Math.min(pos1z, pos2z);
278+
+ int j = Math.max(pos1x, pos2x) - x1 + 1;
279+
+ int i1 = Math.max(pos1y, pos2y) - y1 + 1;
280+
+ int i2 = Math.max(pos1z, pos2z) - z1 + 1;
281+
+ int i3 = j * i1 * i2;
282+
+ int index = 0;
283+
+ while (index != i3) {
284+
+ int i4 = index % j;
285+
+ int i5 = index / j;
286+
+ int i6 = i5 % i1;
287+
+ int i7 = i5 / i1;
288+
+ index++;
289+
+ int x0 = x1 + i4;
290+
+ int y0 = y1 + i6;
291+
+ int z0 = z1 + i7;
292+
+ if (set.add(BlockPos.asLong(x0, y0, z0)) && !visitor.visit(cursor.set(x0, y0, z0), i + 1)) {
293+
+ return false;
294+
+ }
295+
+ }
296+
+
297+
+ return true;
284298
+ }
285-
+ // Leaf end
299+
+ // Leaf end - optimize checkInsideBlocks
286300
+
287301
private static int addCollisionsAlongTravel(LongSet output, Vec3 from, Vec3 to, AABB boundingBox, BlockGetter.BlockStepVisitor stepVisitor) {
288302
Vec3 vec3 = to.subtract(from);

leaf-server/minecraft-patches/features/0264-Optimise-TextColor.patch renamed to leaf-server/minecraft-patches/features/0265-Optimise-TextColor.patch

File renamed without changes.

leaf-server/minecraft-patches/features/0265-Do-not-create-fire-if-explosion-was-cancelled.patch renamed to leaf-server/minecraft-patches/features/0266-Do-not-create-fire-if-explosion-was-cancelled.patch

File renamed without changes.

leaf-server/minecraft-patches/features/0266-Skip-BlockPhysicsEvent-if-no-listeners.patch renamed to leaf-server/minecraft-patches/features/0267-Skip-BlockPhysicsEvent-if-no-listeners.patch

File renamed without changes.

leaf-server/minecraft-patches/features/0267-Lithium-equipment-tracking.patch renamed to leaf-server/minecraft-patches/features/0268-Lithium-equipment-tracking.patch

File renamed without changes.

leaf-server/minecraft-patches/features/0268-fix-purpur-attribute-base-patch.patch renamed to leaf-server/minecraft-patches/features/0269-fix-purpur-attribute-base-patch.patch

File renamed without changes.

leaf-server/minecraft-patches/features/0269-Bump-netty-to-4.2.x.patch renamed to leaf-server/minecraft-patches/features/0270-Bump-netty-to-4.2.x.patch

File renamed without changes.

leaf-server/minecraft-patches/features/0270-Paper-PR-Optimise-temptation-lookups.patch renamed to leaf-server/minecraft-patches/features/0271-Paper-PR-Optimise-temptation-lookups.patch

File renamed without changes.

leaf-server/minecraft-patches/features/0271-Paper-PR-Fix-async-command-building-throwing-CME-in-.patch renamed to leaf-server/minecraft-patches/features/0272-Paper-PR-Fix-async-command-building-throwing-CME-in-.patch

File renamed without changes.

leaf-server/minecraft-patches/features/0272-fix-temptation-lookups.patch renamed to leaf-server/minecraft-patches/features/0273-fix-temptation-lookups.patch

File renamed without changes.

0 commit comments

Comments
 (0)