Public Access
This commit is contained in:
1 parent
58964052c9
commit
b8215f1336
4 files changed
+32
-12
No files matched your search
@@ -121,18 +121,12 @@ public final class AgeDimensionService {
|
||||
|
||||
for (int x = -SURFACE_SEARCH_RADIUS; x <= SURFACE_SEARCH_RADIUS; x++) {
|
||||
for (int z = -SURFACE_SEARCH_RADIUS; z <= SURFACE_SEARCH_RADIUS; z++) {
|
||||
int floorY = level.getHeight(Heightmap.Types.WORLD_SURFACE, x, z) - 1;
|
||||
if (floorY < level.getMinBuildHeight() || floorY > maximumFloorY) {
|
||||
Optional<BlockPos> columnFooting = highestFootingInColumn(level, x, z, maximumFloorY);
|
||||
if (columnFooting.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
BlockPos candidate = new BlockPos(x, floorY, z);
|
||||
var state = level.getBlockState(candidate);
|
||||
if (!level.getFluidState(candidate).isEmpty()
|
||||
|| (!state.is(BlockTags.LEAVES)
|
||||
&& !state.isFaceSturdy(level, candidate, net.minecraft.core.Direction.UP))) {
|
||||
continue;
|
||||
}
|
||||
BlockPos candidate = columnFooting.get();
|
||||
|
||||
if (best == null || candidate.getY() > best.getY()
|
||||
|| (candidate.getY() == best.getY()
|
||||
@@ -145,6 +139,27 @@ public final class AgeDimensionService {
|
||||
return Optional.ofNullable(best);
|
||||
}
|
||||
|
||||
/** Scans downward from the top so cave floors cannot be mistaken for surface footing. */
|
||||
private static Optional<BlockPos> highestFootingInColumn(ServerLevel level, int x, int z, int maximumFloorY) {
|
||||
BlockPos.MutableBlockPos candidate = new BlockPos.MutableBlockPos(x, maximumFloorY, z);
|
||||
for (int y = maximumFloorY; y >= level.getMinBuildHeight(); y--) {
|
||||
candidate.setY(y);
|
||||
if (!level.getFluidState(candidate).isEmpty()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
var state = level.getBlockState(candidate);
|
||||
if (state.isAir()) {
|
||||
continue;
|
||||
}
|
||||
if (state.is(BlockTags.LEAVES)
|
||||
|| state.isFaceSturdy(level, candidate, net.minecraft.core.Direction.UP)) {
|
||||
return Optional.of(candidate.immutable());
|
||||
}
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
private static BlockPos fallbackSpawnFloor(ServerLevel level) {
|
||||
int floorY = Math.clamp(FALLBACK_PLATFORM_Y,
|
||||
level.getMinBuildHeight(), level.getMaxBuildHeight() - 5);
|
||||
|
||||
Reference in new issue
Block a user