| 1 | package net.minecraft.world.level.levelgen.structure.structures;
|
| 2 |
|
| 3 | import com.mojang.serialization.Codec;
|
| 4 | import com.mojang.serialization.MapCodec;
|
| 5 | import com.mojang.serialization.codecs.RecordCodecBuilder;
|
| 6 | import java.util.Optional;
|
| 7 | import net.minecraft.core.BlockPos;
|
| 8 | import net.minecraft.util.ExtraCodecs;
|
| 9 | import net.minecraft.util.StringRepresentable;
|
| 10 | import net.minecraft.world.level.block.Rotation;
|
| 11 | import net.minecraft.world.level.levelgen.Heightmap;
|
| 12 | import net.minecraft.world.level.levelgen.structure.Structure;
|
| 13 | import net.minecraft.world.level.levelgen.structure.StructureType;
|
| 14 | import net.minecraft.world.level.levelgen.structure.pieces.StructurePiecesBuilder;
|
| 15 |
|
| 16 | public class OceanRuinStructure extends Structure {
|
| 17 | public static final MapCodec<OceanRuinStructure> CODEC = RecordCodecBuilder.mapCodec(
|
| 18 | i -> i.group(
|
| 19 | settingsCodec(i),
|
| 20 | OceanRuinStructure.Type.CODEC.fieldOf("biome_temp").forGetter(c -> c.biomeTemp),
|
| 21 | Codec.floatRange(0.0F, 1.0F).fieldOf("large_probability").forGetter(c -> c.largeProbability),
|
| 22 | Codec.floatRange(0.0F, 1.0F).fieldOf("cluster_probability").forGetter(c -> c.clusterProbability)
|
| 23 | )
|
| 24 | .apply(i, OceanRuinStructure::new)
|
| 25 | );
|
| 26 | public final OceanRuinStructure.Type biomeTemp;
|
| 27 | public final float largeProbability;
|
| 28 | public final float clusterProbability;
|
| 29 |
|
| 30 | public OceanRuinStructure(
|
| 31 | final Structure.StructureSettings settings, final OceanRuinStructure.Type biomeTemp, final float largeProbability, final float clusterProbability
|
| 32 | ) {
|
| 33 | super(settings);
|
| 34 | this.biomeTemp = biomeTemp;
|
| 35 | this.largeProbability = largeProbability;
|
| 36 | this.clusterProbability = clusterProbability;
|
| 37 | }
|
| 38 |
|
| 39 | @Override
|
| 40 | public Optional<Structure.GenerationStub> findGenerationPoint(final Structure.GenerationContext context) {
|
| 41 | return onTopOfChunkCenter(context, Heightmap.Types.OCEAN_FLOOR_WG, builder -> this.generatePieces(builder, context));
|
| 42 | }
|
| 43 |
|
| 44 | private void generatePieces(final StructurePiecesBuilder builder, final Structure.GenerationContext context) {
|
| 45 | BlockPos offset = new BlockPos(context.chunkPos().getMinBlockX(), 90, context.chunkPos().getMinBlockZ());
|
| 46 | Rotation rotation = Rotation.getRandom(context.random());
|
| 47 | OceanRuinPieces.addPieces(context.structureTemplateManager(), offset, rotation, builder, context.random(), this);
|
| 48 | }
|
| 49 |
|
| 50 | @Override
|
| 51 | public StructureType<?> type() {
|
| 52 | return StructureType.OCEAN_RUIN;
|
| 53 | }
|
| 54 |
|
| 55 | public enum Type implements StringRepresentable {
|
| 56 | WARM("warm"),
|
| 57 | COLD("cold");
|
| 58 |
|
| 59 | public static final Codec<OceanRuinStructure.Type> CODEC = StringRepresentable.fromEnum(OceanRuinStructure.Type::values);
|
| 60 | @Deprecated
|
| 61 | public static final Codec<OceanRuinStructure.Type> LEGACY_CODEC = ExtraCodecs.legacyEnum(OceanRuinStructure.Type::valueOf);
|
| 62 | private final String name;
|
| 63 |
|
| 64 | Type(final String name) {
|
| 65 | this.name = name;
|
| 66 | }
|
| 67 |
|
| 68 | public String getName() {
|
| 69 | return this.name;
|
| 70 | }
|
| 71 |
|
| 72 | @Override
|
| 73 | public String getSerializedName() {
|
| 74 | return this.name;
|
| 75 | }
|
| 76 | }
|
| 77 | }
|
| 78 |
|