90 lines
4.2 KiB
Diff
90 lines
4.2 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Etil <81570777+etil2jz@users.noreply.github.com>
|
|
Date: Fri, 3 Dec 2021 22:28:16 +0100
|
|
Subject: [PATCH] lithium: entity.fast_retrieval
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/level/entity/EntitySectionStorage.java b/src/main/java/net/minecraft/world/level/entity/EntitySectionStorage.java
|
|
index 984e940a1d8060e5945a6efd10c9f81bed2bf057..32f738cb7df36e66cd22ad604f648d20e6db08b7 100644
|
|
--- a/src/main/java/net/minecraft/world/level/entity/EntitySectionStorage.java
|
|
+++ b/src/main/java/net/minecraft/world/level/entity/EntitySectionStorage.java
|
|
@@ -33,33 +33,56 @@ public class EntitySectionStorage<T extends EntityAccess> {
|
|
}
|
|
|
|
public void forEachAccessibleNonEmptySection(AABB box, Consumer<EntitySection<T>> action) {
|
|
- int i = SectionPos.posToSectionCoord(box.minX - 2.0D);
|
|
- int j = SectionPos.posToSectionCoord(box.minY - 2.0D);
|
|
- int k = SectionPos.posToSectionCoord(box.minZ - 2.0D);
|
|
- int l = SectionPos.posToSectionCoord(box.maxX + 2.0D);
|
|
- int m = SectionPos.posToSectionCoord(box.maxY + 2.0D);
|
|
- int n = SectionPos.posToSectionCoord(box.maxZ + 2.0D);
|
|
-
|
|
- for(int o = i; o <= l; ++o) {
|
|
- long p = SectionPos.asLong(o, 0, 0);
|
|
- long q = SectionPos.asLong(o, -1, -1);
|
|
- LongIterator longIterator = this.sectionIds.subSet(p, q + 1L).iterator();
|
|
-
|
|
- while(longIterator.hasNext()) {
|
|
- long r = longIterator.nextLong();
|
|
- int s = SectionPos.y(r);
|
|
- int t = SectionPos.z(r);
|
|
- if (s >= j && s <= m && t >= k && t <= n) {
|
|
- EntitySection<T> entitySection = this.sections.get(r);
|
|
- if (entitySection != null && !entitySection.isEmpty() && entitySection.getStatus().isAccessible()) {
|
|
- action.accept(entitySection);
|
|
- }
|
|
- }
|
|
+ // Lithium start
|
|
+ int minX = SectionPos.posToSectionCoord(box.minX - 2.0D);
|
|
+ int minY = SectionPos.posToSectionCoord(box.minY - 2.0D);
|
|
+ int minZ = SectionPos.posToSectionCoord(box.minZ - 2.0D);
|
|
+ int maxX = SectionPos.posToSectionCoord(box.maxX + 2.0D);
|
|
+ int maxY = SectionPos.posToSectionCoord(box.maxY + 2.0D);
|
|
+ int maxZ = SectionPos.posToSectionCoord(box.maxZ + 2.0D);
|
|
+
|
|
+ /*
|
|
+ Vanilla order of the AVL long set is sorting by ascending long value. The x, y, z positions are packed into
|
|
+ a long with the x position's lowest 22 bits placed at the MSB.
|
|
+ Therefore the long is negative iff the 22th bit of the x position is set, which happens iff the x position
|
|
+ is negative. A positive x position will never have its 22th bit set, as these big coordinates are far outside
|
|
+ the world. y and z positions are treated as unsigned when sorting by ascending long value, as their sign bits
|
|
+ are placed somewhere inside the packed long
|
|
+ */
|
|
+
|
|
+ for (int x = minX; x <= maxX; x++) {
|
|
+ for (int z = Math.max(minZ, 0); z <= maxZ; z++) {
|
|
+ this.forEachInColumn(x, minY, maxY, z, action);
|
|
}
|
|
+
|
|
+ int bound = Math.min(-1, maxZ);
|
|
+ for (int z = minZ; z <= bound; z++) {
|
|
+ this.forEachInColumn(x, minY, maxY, z, action);
|
|
+ }
|
|
+ }
|
|
+
|
|
+ }
|
|
+
|
|
+ private void forEachInColumn(int x, int minY, int maxY, int z, Consumer<EntitySection<T>> action) {
|
|
+ //y from negative to positive, but y is treated as unsigned
|
|
+ for (int y = Math.max(minY, 0); y <= maxY; y++) {
|
|
+ this.consumeSection(x, y, z, action);
|
|
}
|
|
|
|
+ int bound = Math.min(-1, maxY);
|
|
+ for (int y = minY; y <= bound; y++) {
|
|
+ this.consumeSection(x, y, z, action);
|
|
+ }
|
|
}
|
|
|
|
+ private void consumeSection(int x, int y, int z, Consumer<EntitySection<T>> action) {
|
|
+ EntitySection<T> section = this.getSection(SectionPos.asLong(x, y, z));
|
|
+ if (section != null && section.getStatus().isAccessible()) {
|
|
+ action.accept(section);
|
|
+ }
|
|
+ } // Lithium end
|
|
+
|
|
+
|
|
public LongStream getExistingSectionPositionsInChunk(long chunkPos) {
|
|
int i = ChunkPos.getX(chunkPos);
|
|
int j = ChunkPos.getZ(chunkPos);
|