minecraft-src/net/minecraft/world/level/levelgen/feature/VoidStartPlatformFeature.java
2025-07-04 01:41:11 +03:00

53 lines
2.1 KiB
Java

package net.minecraft.world.level.levelgen.feature;
import com.mojang.serialization.Codec;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration;
public class VoidStartPlatformFeature extends Feature<NoneFeatureConfiguration> {
private static final BlockPos PLATFORM_OFFSET = new BlockPos(8, 3, 8);
private static final ChunkPos PLATFORM_ORIGIN_CHUNK = new ChunkPos(PLATFORM_OFFSET);
private static final int PLATFORM_RADIUS = 16;
private static final int PLATFORM_RADIUS_CHUNKS = 1;
public VoidStartPlatformFeature(Codec<NoneFeatureConfiguration> codec) {
super(codec);
}
/**
* Returns the Manhattan distance between the two points.
*/
private static int checkerboardDistance(int firstX, int firstZ, int secondX, int secondZ) {
return Math.max(Math.abs(firstX - secondX), Math.abs(firstZ - secondZ));
}
@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> context) {
WorldGenLevel worldGenLevel = context.level();
ChunkPos chunkPos = new ChunkPos(context.origin());
if (checkerboardDistance(chunkPos.x, chunkPos.z, PLATFORM_ORIGIN_CHUNK.x, PLATFORM_ORIGIN_CHUNK.z) > 1) {
return true;
} else {
BlockPos blockPos = PLATFORM_OFFSET.atY(context.origin().getY() + PLATFORM_OFFSET.getY());
BlockPos.MutableBlockPos mutableBlockPos = new BlockPos.MutableBlockPos();
for (int i = chunkPos.getMinBlockZ(); i <= chunkPos.getMaxBlockZ(); i++) {
for (int j = chunkPos.getMinBlockX(); j <= chunkPos.getMaxBlockX(); j++) {
if (checkerboardDistance(blockPos.getX(), blockPos.getZ(), j, i) <= 16) {
mutableBlockPos.set(j, blockPos.getY(), i);
if (mutableBlockPos.equals(blockPos)) {
worldGenLevel.setBlock(mutableBlockPos, Blocks.COBBLESTONE.defaultBlockState(), 2);
} else {
worldGenLevel.setBlock(mutableBlockPos, Blocks.STONE.defaultBlockState(), 2);
}
}
}
}
return true;
}
}
}