From 511d3ffa98d537bf4b8a8975f8b04b960ee28740 Mon Sep 17 00:00:00 2001 From: "Lukas Rieger (Blue)" Date: Thu, 25 Jul 2024 00:49:36 +0200 Subject: [PATCH] Add iterateBlockEntities method to Chunk --- .../main/java/de/bluecolored/bluemap/core/world/Chunk.java | 4 ++++ .../bluemap/core/world/mca/chunk/Chunk_1_13.java | 6 ++++++ .../bluemap/core/world/mca/chunk/Chunk_1_16.java | 6 ++++++ .../bluemap/core/world/mca/chunk/Chunk_1_18.java | 6 ++++++ 4 files changed, 22 insertions(+) diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/world/Chunk.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/world/Chunk.java index 7cbe0b36..0228becf 100644 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/world/Chunk.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/world/Chunk.java @@ -28,6 +28,8 @@ import de.bluecolored.bluemap.core.world.block.entity.BlockEntity; import org.jetbrains.annotations.Nullable; +import java.util.function.Consumer; + public interface 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 void iterateBlockEntities(Consumer consumer) { } + } diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/world/mca/chunk/Chunk_1_13.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/world/mca/chunk/Chunk_1_13.java index 84f0381d..55e5cc48 100644 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/world/mca/chunk/Chunk_1_13.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/world/mca/chunk/Chunk_1_13.java @@ -41,6 +41,7 @@ import java.util.HashMap; import java.util.Map; +import java.util.function.Consumer; 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); } + @Override + public void iterateBlockEntities(Consumer consumer) { + blockEntities.values().forEach(consumer); + } + private @Nullable Section getSection(int y) { y -= sectionMin; if (y < 0 || y >= this.sections.length) return null; diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/world/mca/chunk/Chunk_1_16.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/world/mca/chunk/Chunk_1_16.java index 3802a06c..6d8a0004 100644 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/world/mca/chunk/Chunk_1_16.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/world/mca/chunk/Chunk_1_16.java @@ -42,6 +42,7 @@ import java.util.HashMap; import java.util.Map; +import java.util.function.Consumer; 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); } + @Override + public void iterateBlockEntities(Consumer consumer) { + blockEntities.values().forEach(consumer); + } + private @Nullable Section getSection(int y) { y -= sectionMin; if (y < 0 || y >= this.sections.length) return null; diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/world/mca/chunk/Chunk_1_18.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/world/mca/chunk/Chunk_1_18.java index 972596cc..7c4eea39 100644 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/world/mca/chunk/Chunk_1_18.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/world/mca/chunk/Chunk_1_18.java @@ -42,6 +42,7 @@ import java.util.HashMap; import java.util.Map; +import java.util.function.Consumer; 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); } + @Override + public void iterateBlockEntities(Consumer consumer) { + blockEntities.values().forEach(consumer); + } + private @Nullable Section getSection(int y) { y -= sectionMin; if (y < 0 || y >= this.sections.length) return null;