Skip to content

Commit 7819df1

Browse files
authored
Add getHeight method to ChunkData (#12311)
1 parent f225858 commit 7819df1

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

paper-api/src/main/java/org/bukkit/generator/ChunkGenerator.java

+14
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.bukkit.material.MaterialData;
1515
import org.jetbrains.annotations.NotNull;
1616
import org.jetbrains.annotations.Nullable;
17+
import org.jetbrains.annotations.Range;
1718

1819
/**
1920
* A chunk generator is responsible for the initial shaping of an entire
@@ -777,5 +778,18 @@ public static interface ChunkData {
777778
*/
778779
@Deprecated(since = "1.8.8")
779780
public byte getData(int x, int y, int z);
781+
782+
/**
783+
* Get the current height of a position in the chunk data.
784+
* <p>This will differ based on which state generation of the chunk is currently at.
785+
* If for example the chunk is in the generate surface stage,
786+
* this will return what was already generated in the noise stage.</p>
787+
*
788+
* @param heightMap Heightmap to determine where to grab height
789+
* @param x the x location in the chunk from 0-15 inclusive
790+
* @param z the z location in the chunk from 0-15 inclusive
791+
* @return Y coordinate at highest position
792+
*/
793+
int getHeight(@NotNull HeightMap heightMap, @Range(from = 0L, to = 15L) int x, @Range(from = 0L, to = 15L) int z);
780794
}
781795
}

paper-server/src/main/java/org/bukkit/craftbukkit/generator/CraftChunkData.java

+10-1
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@
88
import net.minecraft.world.level.block.entity.BlockEntity;
99
import net.minecraft.world.level.block.state.BlockState;
1010
import net.minecraft.world.level.chunk.ChunkAccess;
11+
import org.bukkit.HeightMap;
1112
import org.bukkit.Material;
1213
import org.bukkit.World;
1314
import org.bukkit.block.Biome;
1415
import org.bukkit.block.data.BlockData;
16+
import org.bukkit.craftbukkit.CraftHeightMap;
1517
import org.bukkit.craftbukkit.block.CraftBiome;
16-
import org.bukkit.craftbukkit.block.CraftBlockType;
1718
import org.bukkit.craftbukkit.block.data.CraftBlockData;
1819
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
1920
import org.bukkit.generator.ChunkGenerator;
@@ -180,4 +181,12 @@ private void setBlock(int x, int y, int z, BlockState type) {
180181
access.removeBlockEntity(blockPosition);
181182
}
182183
}
184+
185+
@Override
186+
public int getHeight(final HeightMap heightMap, final int x, final int z) {
187+
Preconditions.checkArgument(heightMap != null, "HeightMap cannot be null");
188+
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);
189+
190+
return getHandle().getHeight(CraftHeightMap.toNMS(heightMap), x, z);
191+
}
183192
}

paper-server/src/main/java/org/bukkit/craftbukkit/generator/OldCraftChunkData.java

+6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import net.minecraft.world.level.block.Blocks;
99
import net.minecraft.world.level.block.state.BlockState;
1010
import net.minecraft.world.level.chunk.LevelChunkSection;
11+
import org.bukkit.HeightMap;
1112
import org.bukkit.Material;
1213
import org.bukkit.block.Biome;
1314
import org.bukkit.block.data.BlockData;
@@ -200,4 +201,9 @@ Set<BlockPos> getTiles() {
200201
Set<BlockPos> getLights() {
201202
return this.lights;
202203
}
204+
205+
@Override
206+
public int getHeight(HeightMap heightMap, final int x, final int z) {
207+
throw new UnsupportedOperationException("Unsupported, in older chunk generator api");
208+
}
203209
}

0 commit comments

Comments
 (0)