| 1 | package net.minecraft.world.level.levelgen.feature;
|
| 2 |
|
| 3 | import com.mojang.serialization.Codec;
|
| 4 | import com.mojang.serialization.MapCodec;
|
| 5 | import com.mojang.serialization.codecs.RecordCodecBuilder;
|
| 6 | import net.minecraft.core.BlockPos;
|
| 7 | import net.minecraft.core.Direction;
|
| 8 | import net.minecraft.util.RandomSource;
|
| 9 | import net.minecraft.world.level.WorldGenLevel;
|
| 10 | import net.minecraft.world.level.block.Block;
|
| 11 | import net.minecraft.world.level.block.Blocks;
|
| 12 | import net.minecraft.world.level.block.WallTorchBlock;
|
| 13 | import net.minecraft.world.level.chunk.ChunkGenerator;
|
| 14 |
|
| 15 | public record EndPodiumFeature(boolean active) implements Feature {
|
| 16 | public static final int PODIUM_RADIUS = 4;
|
| 17 | public static final int PODIUM_PILLAR_HEIGHT = 4;
|
| 18 | public static final int RIM_RADIUS = 1;
|
| 19 | public static final float CORNER_ROUNDING = 0.5F;
|
| 20 | public static final MapCodec<EndPodiumFeature> CODEC = RecordCodecBuilder.mapCodec(
|
| 21 | i -> i.group(Codec.BOOL.optionalFieldOf("active", false).forGetter(EndPodiumFeature::active)).apply(i, EndPodiumFeature::new)
|
| 22 | );
|
| 23 |
|
| 24 | @Override
|
| 25 | public MapCodec<EndPodiumFeature> codec() {
|
| 26 | return CODEC;
|
| 27 | }
|
| 28 |
|
| 29 | @Override
|
| 30 | public boolean place(final WorldGenLevel level, final ChunkGenerator chunkGenerator, final RandomSource random, final BlockPos origin) {
|
| 31 | for (BlockPos pos : BlockPos.betweenClosed(
|
| 32 | new BlockPos(origin.getX() - 4, origin.getY() - 1, origin.getZ() - 4), new BlockPos(origin.getX() + 4, origin.getY() + 32, origin.getZ() + 4)
|
| 33 | )) {
|
| 34 | boolean insideRim = pos.closerThan(origin, 2.5);
|
| 35 | if (insideRim || pos.closerThan(origin, 3.5)) {
|
| 36 | if (pos.getY() < origin.getY()) {
|
| 37 | if (insideRim) {
|
| 38 | this.setBlock(level, pos, Blocks.BEDROCK.defaultBlockState());
|
| 39 | } else if (pos.getY() < origin.getY()) {
|
| 40 | if (this.active) {
|
| 41 | this.dropPreviousAndSetBlock(level, pos, Blocks.END_STONE);
|
| 42 | } else {
|
| 43 | this.setBlock(level, pos, Blocks.END_STONE.defaultBlockState());
|
| 44 | }
|
| 45 | }
|
| 46 | } else if (pos.getY() > origin.getY()) {
|
| 47 | if (this.active) {
|
| 48 | this.dropPreviousAndSetBlock(level, pos, Blocks.AIR);
|
| 49 | } else {
|
| 50 | this.setBlock(level, pos, Blocks.AIR.defaultBlockState());
|
| 51 | }
|
| 52 | } else if (!insideRim) {
|
| 53 | this.setBlock(level, pos, Blocks.BEDROCK.defaultBlockState());
|
| 54 | } else if (this.active) {
|
| 55 | this.dropPreviousAndSetBlock(level, pos, Blocks.END_PORTAL);
|
| 56 | } else {
|
| 57 | this.setBlock(level, pos, Blocks.AIR.defaultBlockState());
|
| 58 | }
|
| 59 | }
|
| 60 | }
|
| 61 |
|
| 62 | for (int y = 0; y < 4; y++) {
|
| 63 | this.setBlock(level, origin.above(y), Blocks.BEDROCK.defaultBlockState());
|
| 64 | }
|
| 65 |
|
| 66 | BlockPos centerOfPillar = origin.above(2);
|
| 67 |
|
| 68 | for (Direction face : Direction.Plane.HORIZONTAL) {
|
| 69 | this.setBlock(level, centerOfPillar.relative(face), Blocks.WALL_TORCH.defaultBlockState().setValue(WallTorchBlock.FACING, face));
|
| 70 | }
|
| 71 |
|
| 72 | return true;
|
| 73 | }
|
| 74 |
|
| 75 | private void dropPreviousAndSetBlock(final WorldGenLevel level, final BlockPos pos, final Block block) {
|
| 76 | if (!level.getBlockState(pos).is(block)) {
|
| 77 | level.destroyBlock(pos, true, null);
|
| 78 | this.setBlock(level, pos, block.defaultBlockState());
|
| 79 | }
|
| 80 | }
|
| 81 | }
|
| 82 |
|