| 1 | package net.minecraft.world.level.levelgen.structure.structures;
|
| 2 |
|
| 3 | import net.minecraft.core.BlockPos;
|
| 4 | import net.minecraft.nbt.CompoundTag;
|
| 5 | import net.minecraft.resources.Identifier;
|
| 6 | import net.minecraft.util.RandomSource;
|
| 7 | import net.minecraft.util.Util;
|
| 8 | import net.minecraft.world.level.ChunkPos;
|
| 9 | import net.minecraft.world.level.ServerLevelAccessor;
|
| 10 | import net.minecraft.world.level.StructureManager;
|
| 11 | import net.minecraft.world.level.WorldGenLevel;
|
| 12 | import net.minecraft.world.level.block.Blocks;
|
| 13 | import net.minecraft.world.level.block.Mirror;
|
| 14 | import net.minecraft.world.level.block.Rotation;
|
| 15 | import net.minecraft.world.level.chunk.ChunkGenerator;
|
| 16 | import net.minecraft.world.level.levelgen.structure.BoundingBox;
|
| 17 | import net.minecraft.world.level.levelgen.structure.TemplateStructurePiece;
|
| 18 | import net.minecraft.world.level.levelgen.structure.pieces.StructurePieceSerializationContext;
|
| 19 | import net.minecraft.world.level.levelgen.structure.pieces.StructurePieceType;
|
| 20 | import net.minecraft.world.level.levelgen.structure.pieces.StructurePiecesBuilder;
|
| 21 | import net.minecraft.world.level.levelgen.structure.templatesystem.BlockIgnoreProcessor;
|
| 22 | import net.minecraft.world.level.levelgen.structure.templatesystem.StructurePlaceSettings;
|
| 23 | import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplateManager;
|
| 24 |
|
| 25 | public class NetherFossilPieces {
|
| 26 | private static final Identifier[] FOSSILS = new Identifier[]{
|
| 27 | Identifier.withDefaultNamespace("nether_fossils/fossil_1"),
|
| 28 | Identifier.withDefaultNamespace("nether_fossils/fossil_2"),
|
| 29 | Identifier.withDefaultNamespace("nether_fossils/fossil_3"),
|
| 30 | Identifier.withDefaultNamespace("nether_fossils/fossil_4"),
|
| 31 | Identifier.withDefaultNamespace("nether_fossils/fossil_5"),
|
| 32 | Identifier.withDefaultNamespace("nether_fossils/fossil_6"),
|
| 33 | Identifier.withDefaultNamespace("nether_fossils/fossil_7"),
|
| 34 | Identifier.withDefaultNamespace("nether_fossils/fossil_8"),
|
| 35 | Identifier.withDefaultNamespace("nether_fossils/fossil_9"),
|
| 36 | Identifier.withDefaultNamespace("nether_fossils/fossil_10"),
|
| 37 | Identifier.withDefaultNamespace("nether_fossils/fossil_11"),
|
| 38 | Identifier.withDefaultNamespace("nether_fossils/fossil_12"),
|
| 39 | Identifier.withDefaultNamespace("nether_fossils/fossil_13"),
|
| 40 | Identifier.withDefaultNamespace("nether_fossils/fossil_14")
|
| 41 | };
|
| 42 |
|
| 43 | public static void addPieces(
|
| 44 | final StructureTemplateManager structureTemplateManager, final StructurePiecesBuilder builder, final RandomSource random, final BlockPos position
|
| 45 | ) {
|
| 46 | Rotation nextRotation = Rotation.getRandom(random);
|
| 47 | builder.addPiece(new NetherFossilPieces.NetherFossilPiece(structureTemplateManager, Util.getRandom(FOSSILS, random), position, nextRotation));
|
| 48 | }
|
| 49 |
|
| 50 | public static class NetherFossilPiece extends TemplateStructurePiece {
|
| 51 | public NetherFossilPiece(
|
| 52 | final StructureTemplateManager structureTemplateManager, final Identifier templateLocation, final BlockPos position, final Rotation rotation
|
| 53 | ) {
|
| 54 | super(StructurePieceType.NETHER_FOSSIL, 0, structureTemplateManager, templateLocation, templateLocation.toString(), makeSettings(rotation), position);
|
| 55 | }
|
| 56 |
|
| 57 | public NetherFossilPiece(final StructureTemplateManager structureTemplateManager, final CompoundTag tag) {
|
| 58 | super(StructurePieceType.NETHER_FOSSIL, tag, structureTemplateManager, location -> makeSettings(tag.read("Rot", Rotation.LEGACY_CODEC).orElseThrow()));
|
| 59 | }
|
| 60 |
|
| 61 | private static StructurePlaceSettings makeSettings(final Rotation rotation) {
|
| 62 | return new StructurePlaceSettings().setRotation(rotation).setMirror(Mirror.NONE).addProcessor(BlockIgnoreProcessor.STRUCTURE_AND_AIR);
|
| 63 | }
|
| 64 |
|
| 65 | @Override
|
| 66 | protected void addAdditionalSaveData(final StructurePieceSerializationContext context, final CompoundTag tag) {
|
| 67 | super.addAdditionalSaveData(context, tag);
|
| 68 | tag.store("Rot", Rotation.LEGACY_CODEC, this.placeSettings.getRotation());
|
| 69 | }
|
| 70 |
|
| 71 | @Override
|
| 72 | protected void handleDataMarker(
|
| 73 | final String markerId, final BlockPos position, final ServerLevelAccessor level, final RandomSource random, final BoundingBox chunkBB
|
| 74 | ) {
|
| 75 | }
|
| 76 |
|
| 77 | @Override
|
| 78 | public void postProcess(
|
| 79 | final WorldGenLevel level,
|
| 80 | final StructureManager structureManager,
|
| 81 | final ChunkGenerator generator,
|
| 82 | final RandomSource random,
|
| 83 | final BoundingBox chunkBB,
|
| 84 | final ChunkPos chunkPos,
|
| 85 | final BlockPos referencePos
|
| 86 | ) {
|
| 87 | BoundingBox fossilBB = this.template.getBoundingBox(this.placeSettings, this.templatePosition);
|
| 88 | chunkBB.encapsulate(fossilBB);
|
| 89 | super.postProcess(level, structureManager, generator, random, chunkBB, chunkPos, referencePos);
|
| 90 | this.placeDriedGhast(level, random, fossilBB, chunkBB);
|
| 91 | }
|
| 92 |
|
| 93 | private void placeDriedGhast(final WorldGenLevel level, final RandomSource random, final BoundingBox fossilBB, final BoundingBox chunkBB) {
|
| 94 | RandomSource positionalRandom = RandomSource.createThreadLocalInstance(level.getSeed()).forkPositional().at(fossilBB.getCenter());
|
| 95 | if (positionalRandom.nextFloat() < 0.5F) {
|
| 96 | int x = fossilBB.minX() + positionalRandom.nextInt(fossilBB.getXSpan());
|
| 97 | int y = fossilBB.minY();
|
| 98 | int z = fossilBB.minZ() + positionalRandom.nextInt(fossilBB.getZSpan());
|
| 99 | BlockPos randomPos = new BlockPos(x, y, z);
|
| 100 | if (level.getBlockState(randomPos).isAir() && chunkBB.isInside(randomPos)) {
|
| 101 | level.setBlock(randomPos, Blocks.DRIED_GHAST.defaultBlockState().rotate(Rotation.getRandom(positionalRandom)), 2);
|
| 102 | }
|
| 103 | }
|
| 104 | }
|
| 105 | }
|
| 106 | }
|
| 107 |
|