mirror of
https://github.com/PaperMC/Paper.git
synced 2025-05-19 05:30:23 -07:00
Add getHeight method to ChunkData (#12311)
This commit is contained in:
parent
f225858235
commit
7819df10a4
@ -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.
|
||||
* <p>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.</p>
|
||||
*
|
||||
* @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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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<BlockPos> 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");
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user