Add iterateBlockEntities method to Chunk

This commit is contained in:
Lukas Rieger (Blue) 2024-07-25 00:49:36 +02:00
parent 809847f0b0
commit 511d3ffa98
No known key found for this signature in database
GPG Key ID: AA33883B1BBA03E6
4 changed files with 22 additions and 0 deletions

View File

@ -28,6 +28,8 @@
import de.bluecolored.bluemap.core.world.block.entity.BlockEntity; import de.bluecolored.bluemap.core.world.block.entity.BlockEntity;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.util.function.Consumer;
public interface Chunk { public interface Chunk {
Chunk EMPTY_CHUNK = new Chunk() {}; Chunk EMPTY_CHUNK = new Chunk() {};
@ -79,4 +81,6 @@ default boolean hasOceanFloorHeights() {
default @Nullable BlockEntity getBlockEntity(int x, int y, int z) { return null; } default @Nullable BlockEntity getBlockEntity(int x, int y, int z) { return null; }
default void iterateBlockEntities(Consumer<BlockEntity> consumer) { }
} }

View File

@ -41,6 +41,7 @@
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.function.Consumer;
public class Chunk_1_13 extends MCAChunk { public class Chunk_1_13 extends MCAChunk {
@ -219,6 +220,11 @@ public int getOceanFloorY(int x, int z) {
return blockEntities.get((long) y << 8 | (x & 0xF) << 4 | z & 0xF); return blockEntities.get((long) y << 8 | (x & 0xF) << 4 | z & 0xF);
} }
@Override
public void iterateBlockEntities(Consumer<BlockEntity> consumer) {
blockEntities.values().forEach(consumer);
}
private @Nullable Section getSection(int y) { private @Nullable Section getSection(int y) {
y -= sectionMin; y -= sectionMin;
if (y < 0 || y >= this.sections.length) return null; if (y < 0 || y >= this.sections.length) return null;

View File

@ -42,6 +42,7 @@
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.function.Consumer;
public class Chunk_1_16 extends MCAChunk { public class Chunk_1_16 extends MCAChunk {
@ -214,6 +215,11 @@ public int getOceanFloorY(int x, int z) {
return blockEntities.get((long) y << 8 | (x & 0xF) << 4 | z & 0xF); return blockEntities.get((long) y << 8 | (x & 0xF) << 4 | z & 0xF);
} }
@Override
public void iterateBlockEntities(Consumer<BlockEntity> consumer) {
blockEntities.values().forEach(consumer);
}
private @Nullable Section getSection(int y) { private @Nullable Section getSection(int y) {
y -= sectionMin; y -= sectionMin;
if (y < 0 || y >= this.sections.length) return null; if (y < 0 || y >= this.sections.length) return null;

View File

@ -42,6 +42,7 @@
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.function.Consumer;
public class Chunk_1_18 extends MCAChunk { public class Chunk_1_18 extends MCAChunk {
@ -205,6 +206,11 @@ public int getOceanFloorY(int x, int z) {
return blockEntities.get((long) y << 8 | (x & 0xF) << 4 | z & 0xF); return blockEntities.get((long) y << 8 | (x & 0xF) << 4 | z & 0xF);
} }
@Override
public void iterateBlockEntities(Consumer<BlockEntity> consumer) {
blockEntities.values().forEach(consumer);
}
private @Nullable Section getSection(int y) { private @Nullable Section getSection(int y) {
y -= sectionMin; y -= sectionMin;
if (y < 0 || y >= this.sections.length) return null; if (y < 0 || y >= this.sections.length) return null;