private Vector3i getSafeSpawnPosition(Vector3i spawnPos) {
World world = worldGenerator.getWorld();
if (world != null) {
// try and find somewhere in this chunk a spot to land
Region worldRegion = world.getWorldData(Region3i.createFromMinAndSize(new Vector3i(0, 0, 0), ChunkConstants.CHUNK_SIZE));
SurfaceHeightFacet surfaceHeightFacet = worldRegion.getFacet(SurfaceHeightFacet.class);
SeaLevelFacet seaLevelFacet = worldRegion.getFacet(SeaLevelFacet.class);
int seaLevel = seaLevelFacet.getSeaLevel();
for (Vector3i pos : ChunkConstants.CHUNK_REGION) {
int height = TeraMath.floorToInt(surfaceHeightFacet.get(pos.x, pos.z));
if (height > seaLevel) {