| 1 | package net.minecraft.world.level.levelgen.feature;
|
| 2 |
|
| 3 | import com.mojang.serialization.MapCodec;
|
| 4 | import net.minecraft.core.BlockPos;
|
| 5 | import net.minecraft.util.RandomSource;
|
| 6 | import net.minecraft.world.level.ChunkPos;
|
| 7 | import net.minecraft.world.level.WorldGenLevel;
|
| 8 | import net.minecraft.world.level.block.Blocks;
|
| 9 | import net.minecraft.world.level.chunk.ChunkGenerator;
|
| 10 |
|
| 11 | public record VoidStartPlatformFeature() implements Feature {
|
| 12 | private static final BlockPos PLATFORM_OFFSET = new BlockPos(8, 3, 8);
|
| 13 | private static final ChunkPos PLATFORM_ORIGIN_CHUNK = ChunkPos.containing(PLATFORM_OFFSET);
|
| 14 | private static final int PLATFORM_RADIUS = 16;
|
| 15 | private static final int PLATFORM_RADIUS_CHUNKS = 1;
|
| 16 | public static final MapCodec<VoidStartPlatformFeature> CODEC = MapCodec.unit(VoidStartPlatformFeature::new);
|
| 17 |
|
| 18 | @Override
|
| 19 | public MapCodec<VoidStartPlatformFeature> codec() {
|
| 20 | return CODEC;
|
| 21 | }
|
| 22 |
|
| 23 | private static int checkerboardDistance(final int xa, final int za, final int xb, final int zb) {
|
| 24 | return Math.max(Math.abs(xa - xb), Math.abs(za - zb));
|
| 25 | }
|
| 26 |
|
| 27 | @Override
|
| 28 | public boolean place(final WorldGenLevel level, final ChunkGenerator chunkGenerator, final RandomSource random, final BlockPos origin) {
|
| 29 | ChunkPos currentChunkPos = ChunkPos.containing(origin);
|
| 30 | if (checkerboardDistance(currentChunkPos.x(), currentChunkPos.z(), PLATFORM_ORIGIN_CHUNK.x(), PLATFORM_ORIGIN_CHUNK.z()) > 1) {
|
| 31 | return true;
|
| 32 | }
|
| 33 |
|
| 34 | BlockPos platformOrigin = PLATFORM_OFFSET.atY(origin.getY() + PLATFORM_OFFSET.getY());
|
| 35 | BlockPos.MutableBlockPos blockPos = new BlockPos.MutableBlockPos();
|
| 36 |
|
| 37 | for (int z = currentChunkPos.getMinBlockZ(); z <= currentChunkPos.getMaxBlockZ(); z++) {
|
| 38 | for (int x = currentChunkPos.getMinBlockX(); x <= currentChunkPos.getMaxBlockX(); x++) {
|
| 39 | if (checkerboardDistance(platformOrigin.getX(), platformOrigin.getZ(), x, z) <= 16) {
|
| 40 | blockPos.set(x, platformOrigin.getY(), z);
|
| 41 | if (blockPos.equals(platformOrigin)) {
|
| 42 | level.setBlock(blockPos, Blocks.COBBLESTONE.defaultBlockState(), 2);
|
| 43 | } else {
|
| 44 | level.setBlock(blockPos, Blocks.STONE.defaultBlockState(), 2);
|
| 45 | }
|
| 46 | }
|
| 47 | }
|
| 48 | }
|
| 49 |
|
| 50 | return true;
|
| 51 | }
|
| 52 | }
|
| 53 |
|