Fix entity.fast_retrieval

This commit is contained in:
Etil
2021-10-05 13:18:16 +02:00
parent 5dc48b0622
commit d5edaed251

View File

@@ -0,0 +1,64 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Etil <81570777+etil2jz@users.noreply.github.com>
Date: Tue, 5 Oct 2021 13:17:14 +0200
Subject: [PATCH] Fix entity.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 fb572ccd5f2058e1e6ccb6e745e9ad71025c8998..418c3a4e8d38e6836b665f1f33306dcb470cd4b6 100644
--- a/src/main/java/net/minecraft/world/level/entity/EntitySectionStorage.java
+++ b/src/main/java/net/minecraft/world/level/entity/EntitySectionStorage.java
@@ -34,7 +34,7 @@ public class EntitySectionStorage<T extends EntityAccess> {
}
public void forEachAccessibleSection(AABB box, Consumer<EntitySection<T>> action) {
- // Yatopia start - port lithium
+ // Yatopia start - port lithium // Mirai start - fix entity.fast_retrieval
int minX = SectionPos.posToSectionCoord(box.minX - 2.0D);
int minY = SectionPos.posToSectionCoord(box.minY - 2.0D);
int minZ = SectionPos.posToSectionCoord(box.minZ - 2.0D);
@@ -43,18 +43,34 @@ public class EntitySectionStorage<T extends EntityAccess> {
int maxZ = SectionPos.posToSectionCoord(box.maxZ + 2.0D);
for (int x = minX; x <= maxX; x++) {
- for (int z = minZ; z <= maxZ; z++) {
- for (int y = minY; y <= maxY; y++) {
- EntitySection<T> section = this.getSection(SectionPos.asLong(x, y, z));
- if (section != null && section.getStatus().isAccessible()) {
- action.accept(section);
- }
- }
+ 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<EntityTrackingSection<T>> action) {
+ 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);
+ }
+ }
- // Yatopia end
+ private void consumeSection(int x, int y, int z, Consumer<EntityTrackingSection<T>> action) {
+ EntityTrackingSection<T> section = this.findTrackingSection(ChunkSectionPos.asLong(x, y, z));
+ if (section != null && section.getStatus().shouldTrack()) {
+ action.accept(section);
+ }
}
+ // Yatopia end - port lithium // Mirai end - fix entity.fast_retrieval
public LongStream getExistingSectionPositionsInChunk(long chunkPos) {
int i = ChunkPos.getX(chunkPos);