Guest User

SecretRoomStructure

a guest
Feb 5th, 2023
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.91 KB | None | 0 0
  1. public class SecretRoomStructure extends Structure<NoFeatureConfig> {
  2.     public SecretRoomStructure(Codec<NoFeatureConfig> codec) {
  3.         super(codec);
  4.     }
  5.  
  6.     @Override
  7.     public  IStartFactory<NoFeatureConfig> getStartFactory()
  8.     {
  9.         return SecretRoomStructure.Start::new;
  10.     }
  11.  
  12.     @Override
  13.     public GenerationStage.Decoration step()
  14.     {
  15.         return GenerationStage.Decoration.UNDERGROUND_STRUCTURES;
  16.     }
  17.  
  18.     @Override
  19.     protected boolean isFeatureChunk(ChunkGenerator chunkGenerator, BiomeProvider biomeSource, long seed, SharedSeedRandom chunkRandom, int chunkX, int chunkZ, Biome biome, ChunkPos chunkPos, NoFeatureConfig featureConfig)
  20.     {
  21.         BlockPos centerOfChunk = new BlockPos(chunkX * 16, 0, chunkZ * 16);
  22.  
  23.         int landHeight = chunkGenerator.getFirstOccupiedHeight(centerOfChunk.getX(), centerOfChunk.getZ(), Heightmap.Type.WORLD_SURFACE_WG);
  24.         IBlockReader columnOfBlocks = chunkGenerator.getBaseColumn(centerOfChunk.getX(), centerOfChunk.getZ());
  25.  
  26.         BlockState topBlock = columnOfBlocks.getBlockState(centerOfChunk.above(landHeight));
  27.  
  28.         return topBlock.getFluidState().isEmpty(); //landHeight > 100;
  29.     }
  30.  
  31.     /**
  32.      * Handles calling up the structure's pieces class and height that structure will spawn at.
  33.      */
  34.     public static class Start extends StructureStart<NoFeatureConfig>  {
  35.         public Start(Structure<NoFeatureConfig> structureIn, int chunkX, int chunkZ, MutableBoundingBox mutableBoundingBox, int referenceIn, long seedIn) {
  36.             super(structureIn, chunkX, chunkZ, mutableBoundingBox, referenceIn, seedIn);
  37.         }
  38.  
  39.         @Override
  40.         public void generatePieces(DynamicRegistries dynamicRegistryManager, ChunkGenerator chunkGenerator, TemplateManager templateManagerIn, int chunkX, int chunkZ, Biome biomeIn, NoFeatureConfig config) {
  41.  
  42.             int x = chunkX * 16;
  43.             int z = chunkZ * 16;
  44.  
  45.             BlockPos centerPos = new BlockPos(x,0, z);
  46.             int j = 20 + random.nextInt(20);
  47.            
  48.             Rotation rotation = Rotation.getRandom(this.random);
  49.             SecretRoomPiece.start(templateManagerIn, centerPos, rotation, this.pieces, random);
  50.  
  51.             Vector3i structureCenter = this.pieces.get(0).getBoundingBox().getCenter();
  52.             int xOffset = centerPos.getX() - structureCenter.getX();
  53.             int zOffset = centerPos.getZ() - structureCenter.getZ();
  54.             for(StructurePiece structurePiece : this.pieces)
  55.             {
  56.                 structurePiece.move(xOffset, +j, zOffset);
  57.             }
  58.  
  59.             this.calculateBoundingBox();
  60.  
  61.             Necromod.LOGGER.log(Level.DEBUG, "Secret room at " +
  62.                             this.pieces.get(0).getBoundingBox().x0 + " " +
  63.                             this.pieces.get(0).getBoundingBox().y0 + " " +
  64.                             this.pieces.get(0).getBoundingBox().z0);
  65.         }
  66.  
  67.     }
  68. }
Add Comment
Please, Sign In to add comment