use of com.telepathicgrunt.repurposedstructures.world.structures.configs.RSMineshaftEndConfig in project RepurposedStructures by TelepathicGrunt.
the class MineshaftEndStructure method generateMineshaftEndPieces.
public static <CC extends RSMineshaftEndConfig> Optional<PieceGenerator<CC>> generateMineshaftEndPieces(PieceGeneratorSupplier.Context<CC> context) {
CC config = context.config();
BlockPos.MutableBlockPos blockpos = new BlockPos.MutableBlockPos(context.chunkPos().getMinBlockX(), 0, context.chunkPos().getMinBlockZ());
BlockPos.MutableBlockPos islandTopBottomThickness = new BlockPos.MutableBlockPos(Integer.MAX_VALUE, Integer.MIN_VALUE, Integer.MAX_VALUE);
analyzeLand(context.chunkGenerator(), blockpos.getX(), blockpos.getZ(), islandTopBottomThickness, context.heightAccessor());
int minThickness = config.minIslandThickness;
int maxY = 53;
int minY = 15;
if (minThickness == 0) {
blockpos.move(Direction.UP, 35);
} else {
WorldgenRandom random = new WorldgenRandom(new LegacyRandomSource(0L));
random.setLargeFeatureSeed(context.seed(), context.chunkPos().x, context.chunkPos().z);
int structureStartHeight = random.nextInt(Math.max(islandTopBottomThickness.getZ() - minThickness + 1, 1)) + islandTopBottomThickness.getY() + (minThickness / 2);
blockpos.move(Direction.UP, structureStartHeight);
maxY = islandTopBottomThickness.getX() - 5;
minY = islandTopBottomThickness.getY();
if (maxY - minY <= 5) {
minY = maxY - 5;
}
}
int finalMaxY = maxY;
return PieceLimitedJigsawManager.assembleJigsawStructure(context, new JigsawConfiguration(config.startPool, config.size), GeneralUtils.getCsfNameForConfig(config, context.registryAccess()), blockpos, false, false, maxY, minY, config.poolsThatIgnoreBoundaries, (structurePiecesBuilder, pieces) -> {
Optional<PoolElementStructurePiece> highestPiece = pieces.stream().max(Comparator.comparingInt(p -> p.getBoundingBox().maxY()));
int topY = highestPiece.map(poolElementStructurePiece -> poolElementStructurePiece.getBoundingBox().maxY()).orElseGet(blockpos::getY);
if (topY > finalMaxY) {
int newOffset = finalMaxY - topY;
for (StructurePiece piece : pieces) {
piece.move(0, newOffset, 0);
}
}
});
}
Aggregations