100 lines
4.8 KiB
Diff
100 lines
4.8 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: 2No2Name <2No2Name@web.de>
|
|
Date: Wed, 15 Dec 2021 11:20:48 -0500
|
|
Subject: [PATCH] lithium: fast retrieval
|
|
|
|
Original code by CaffeineMC, licensed under GNU Lesser General Public License v3.0
|
|
You can find the original code on https://github.com/CaffeineMC/lithium-fabric (Yarn mappings)
|
|
|
|
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 2ad47b33aea2493b2cdc0431849ecd50a12f9146..ba8aef74c0c23a39b0e4387916a904e14d41a25a 100644
|
|
--- a/src/main/java/net/minecraft/world/level/entity/EntitySectionStorage.java
|
|
+++ b/src/main/java/net/minecraft/world/level/entity/EntitySectionStorage.java
|
|
@@ -32,33 +32,66 @@ public class EntitySectionStorage<T extends EntityAccess> {
|
|
this.intialSectionVisibility = chunkStatusDiscriminator;
|
|
}
|
|
|
|
+ // JettPack start - lithium: entity.fast_retrieval
|
|
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);
|
|
+ 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);
|
|
+
|
|
+ if (maxX >= minX + 4 || maxZ >= minZ + 4) {
|
|
+ // [VanillaCopy]
|
|
+ for(int o = minX; o <= maxX; ++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 >= minY && s <= maxY && t >= minZ && t <= maxZ) {
|
|
+ EntitySection<T> entitySection = this.sections.get(r);
|
|
+ if (entitySection != null && !entitySection.isEmpty() && entitySection.getStatus().isAccessible()) {
|
|
+ action.accept(entitySection);
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
+ } else {
|
|
+ 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(SectionPos.asLong(x, y, z), action);
|
|
+ }
|
|
+ int bound = Math.min(-1, maxY);
|
|
+ for (int y = minY; y <= bound; y++) {
|
|
+ this.consumeSection(SectionPos.asLong(x, y, z), action);
|
|
+ }
|
|
+ }
|
|
+
|
|
+ private void consumeSection(long pos, Consumer<EntitySection<T>> action) {
|
|
+ EntitySection<T> section = this.getSection(pos);
|
|
+ if (section != null && 0 != section.size() && section.getStatus().isAccessible()) {
|
|
+ action.accept(section);
|
|
+ }
|
|
}
|
|
+ // JettPack end
|
|
|
|
public LongStream getExistingSectionPositionsInChunk(long chunkPos) {
|
|
int i = ChunkPos.getX(chunkPos);
|