diff --git a/paper-api/src/main/java/org/bukkit/generator/ChunkGenerator.java b/paper-api/src/main/java/org/bukkit/generator/ChunkGenerator.java index 4e8d0b2f73..8aca905b09 100644 --- a/paper-api/src/main/java/org/bukkit/generator/ChunkGenerator.java +++ b/paper-api/src/main/java/org/bukkit/generator/ChunkGenerator.java @@ -14,6 +14,7 @@ import org.bukkit.block.data.BlockData; import org.bukkit.material.MaterialData; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.Range; /** * A chunk generator is responsible for the initial shaping of an entire @@ -777,5 +778,18 @@ public abstract class ChunkGenerator { */ @Deprecated(since = "1.8.8") public byte getData(int x, int y, int z); + + /** + * Get the current height of a position in the chunk data. + *

This will differ based on which state generation of the chunk is currently at. + * If for example the chunk is in the generate surface stage, + * this will return what was already generated in the noise stage.

+ * + * @param heightMap Heightmap to determine where to grab height + * @param x the x location in the chunk from 0-15 inclusive + * @param z the z location in the chunk from 0-15 inclusive + * @return Y coordinate at highest position + */ + int getHeight(@NotNull HeightMap heightMap, @Range(from = 0L, to = 15L) int x, @Range(from = 0L, to = 15L) int z); } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/generator/CraftChunkData.java b/paper-server/src/main/java/org/bukkit/craftbukkit/generator/CraftChunkData.java index 0fb580530d..679cc7a7d1 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/generator/CraftChunkData.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/generator/CraftChunkData.java @@ -8,12 +8,13 @@ import net.minecraft.world.level.block.EntityBlock; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.chunk.ChunkAccess; +import org.bukkit.HeightMap; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Biome; import org.bukkit.block.data.BlockData; +import org.bukkit.craftbukkit.CraftHeightMap; import org.bukkit.craftbukkit.block.CraftBiome; -import org.bukkit.craftbukkit.block.CraftBlockType; import org.bukkit.craftbukkit.block.data.CraftBlockData; import org.bukkit.craftbukkit.util.CraftMagicNumbers; import org.bukkit.generator.ChunkGenerator; @@ -180,4 +181,12 @@ public final class CraftChunkData implements ChunkGenerator.ChunkData { access.removeBlockEntity(blockPosition); } } + + @Override + public int getHeight(final HeightMap heightMap, final int x, final int z) { + Preconditions.checkArgument(heightMap != null, "HeightMap cannot be null"); + Preconditions.checkArgument(x >= 0 && x <= 15 && z >= 0 && z <= 15, "Cannot get height outside of a chunks bounds, must be between 0 and 15, got x: %s, z: %s", x, z); + + return getHandle().getHeight(CraftHeightMap.toNMS(heightMap), x, z); + } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/generator/OldCraftChunkData.java b/paper-server/src/main/java/org/bukkit/craftbukkit/generator/OldCraftChunkData.java index 719fe4cbe9..78c3025816 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/generator/OldCraftChunkData.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/generator/OldCraftChunkData.java @@ -8,6 +8,7 @@ import net.minecraft.core.Registry; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.chunk.LevelChunkSection; +import org.bukkit.HeightMap; import org.bukkit.Material; import org.bukkit.block.Biome; import org.bukkit.block.data.BlockData; @@ -200,4 +201,9 @@ public final class OldCraftChunkData implements ChunkGenerator.ChunkData { Set getLights() { return this.lights; } + + @Override + public int getHeight(HeightMap heightMap, final int x, final int z) { + throw new UnsupportedOperationException("Unsupported, in older chunk generator api"); + } }