use of net.minecraft.world.level.levelgen.structure.PoolElementStructurePiece 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);
}
}
});
}
use of net.minecraft.world.level.levelgen.structure.PoolElementStructurePiece in project Beyond-Earth by MrScautHD.
the class AlienVillage method createPiecesGenerator.
public static Optional<PieceGenerator<JigsawConfiguration>> createPiecesGenerator(PieceGeneratorSupplier.Context<JigsawConfiguration> context) {
if (!AlienVillage.isFeatureChunk(context)) {
return Optional.empty();
}
BlockPos blockpos = context.chunkPos().getMiddleBlockPosition(0);
int topLandY = context.chunkGenerator().getFirstFreeHeight(blockpos.getX(), blockpos.getZ(), Heightmap.Types.WORLD_SURFACE_WG, context.heightAccessor());
blockpos = blockpos.above(topLandY - 20);
Optional<PieceGenerator<JigsawConfiguration>> structurePiecesGenerator = JigsawPlacement.addPieces(context, PoolElementStructurePiece::new, blockpos, false, false);
return structurePiecesGenerator;
}
use of net.minecraft.world.level.levelgen.structure.PoolElementStructurePiece in project Beyond-Earth by MrScautHD.
the class PygroTower method createPiecesGenerator.
public static Optional<PieceGenerator<JigsawConfiguration>> createPiecesGenerator(PieceGeneratorSupplier.Context<JigsawConfiguration> context) {
if (!PygroTower.isFeatureChunk(context)) {
return Optional.empty();
}
BlockPos blockpos = context.chunkPos().getMiddleBlockPosition(0);
int topLandY = context.chunkGenerator().getFirstFreeHeight(blockpos.getX(), blockpos.getZ(), Heightmap.Types.WORLD_SURFACE_WG, context.heightAccessor());
blockpos = blockpos.above(topLandY);
Optional<PieceGenerator<JigsawConfiguration>> structurePiecesGenerator = JigsawPlacement.addPieces(context, PoolElementStructurePiece::new, blockpos, false, false);
return structurePiecesGenerator;
}
use of net.minecraft.world.level.levelgen.structure.PoolElementStructurePiece in project Beyond-Earth by MrScautHD.
the class VenusBullet method createPiecesGenerator.
public static Optional<PieceGenerator<JigsawConfiguration>> createPiecesGenerator(PieceGeneratorSupplier.Context<JigsawConfiguration> context) {
if (!VenusBullet.isFeatureChunk(context)) {
return Optional.empty();
}
BlockPos blockpos = context.chunkPos().getMiddleBlockPosition(0);
int topLandY = context.chunkGenerator().getFirstFreeHeight(blockpos.getX(), blockpos.getZ(), Heightmap.Types.WORLD_SURFACE_WG, context.heightAccessor());
blockpos = blockpos.above(topLandY);
Optional<PieceGenerator<JigsawConfiguration>> structurePiecesGenerator = JigsawPlacement.addPieces(context, PoolElementStructurePiece::new, blockpos, false, false);
return structurePiecesGenerator;
}
use of net.minecraft.world.level.levelgen.structure.PoolElementStructurePiece in project Brass_Amber_BattleTowers by BrassAmber-Mods.
the class BTLandJigsawPlacement method addPieces.
public static Optional<PieceGenerator<BTJigsawConfiguration>> addPieces(PieceGeneratorSupplier.Context<BTJigsawConfiguration> context, BTLandJigsawPlacement.PieceFactory pieceFactory, BlockPos placementPos, boolean boundaryAdjust, boolean useHeightMap, boolean water) {
WorldgenRandom worldgenrandom = new WorldgenRandom(new LegacyRandomSource(0L));
worldgenrandom.setLargeFeatureSeed(context.seed(), context.chunkPos().x, context.chunkPos().z);
RegistryAccess registryaccess = context.registryAccess();
BTJigsawConfiguration jigsawconfiguration = context.config();
ChunkGenerator chunkgenerator = context.chunkGenerator();
StructureManager structuremanager = context.structureManager();
LevelHeightAccessor levelheightaccessor = context.heightAccessor();
Predicate<Biome> predicate = context.validBiome();
StructureFeature.bootstrap();
Registry<StructureTemplatePool> registry = registryaccess.registryOrThrow(Registry.TEMPLATE_POOL_REGISTRY);
Rotation rotation = Rotation.getRandom(worldgenrandom);
watered = water;
StructureTemplatePool structuretemplatepool = jigsawconfiguration.startPool().get();
StructurePoolElement structurepoolelement = structuretemplatepool.getRandomTemplate(worldgenrandom);
if (structurepoolelement == EmptyPoolElement.INSTANCE) {
return Optional.empty();
} else {
PoolElementStructurePiece poolelementstructurepiece = pieceFactory.create(structuremanager, structurepoolelement, placementPos, structurepoolelement.getGroundLevelDelta(), rotation, structurepoolelement.getBoundingBox(structuremanager, placementPos, rotation));
BoundingBox boundingbox = poolelementstructurepiece.getBoundingBox();
int bbX = (boundingbox.maxX() + boundingbox.minX()) / 2;
int bbZ = (boundingbox.maxZ() + boundingbox.minZ()) / 2;
int ppY;
if (useHeightMap) {
ppY = placementPos.getY() + chunkgenerator.getFirstFreeHeight(bbX, bbZ, Heightmap.Types.WORLD_SURFACE_WG, levelheightaccessor);
} else {
ppY = placementPos.getY();
}
if (watered) {
poolelementstructurepiece.move(0, -5, 0);
}
if (!predicate.test(chunkgenerator.getNoiseBiome(QuartPos.fromBlock(bbX), QuartPos.fromBlock(ppY), QuartPos.fromBlock(bbZ)))) {
return Optional.empty();
} else {
int pieceYlevel = boundingbox.minY() + poolelementstructurepiece.getGroundLevelDelta();
poolelementstructurepiece.move(0, ppY - pieceYlevel, 0);
return Optional.of((piecesBuilder, pieceGenContext) -> {
List<PoolElementStructurePiece> list = Lists.newArrayList();
list.add(poolelementstructurepiece);
if (jigsawconfiguration.maxDepth() > 0) {
int sizeLimit = 120;
AABB aabb = new AABB(bbX - sizeLimit, ppY - sizeLimit, bbZ - sizeLimit, bbX + sizeLimit + 1, ppY + sizeLimit + 1, bbZ + sizeLimit + 1);
BTLandJigsawPlacement.Placer BTLandJigsawPlacement$placer = new BTLandJigsawPlacement.Placer(registry, jigsawconfiguration.maxDepth(), pieceFactory, chunkgenerator, structuremanager, list, worldgenrandom);
BTLandJigsawPlacement$placer.placing.addLast(new BTLandJigsawPlacement.PieceState(poolelementstructurepiece, new MutableObject<>(Shapes.join(Shapes.create(aabb), Shapes.create(AABB.of(boundingbox)), BooleanOp.ONLY_FIRST)), 0));
while (!BTLandJigsawPlacement$placer.placing.isEmpty()) {
BTLandJigsawPlacement.PieceState BTLandJigsawPlacement$piecestate = BTLandJigsawPlacement$placer.placing.removeFirst();
BTLandJigsawPlacement$placer.tryPlacingChildren(BTLandJigsawPlacement$piecestate.piece, BTLandJigsawPlacement$piecestate.free, BTLandJigsawPlacement$piecestate.depth, boundaryAdjust, levelheightaccessor);
}
list.forEach(piecesBuilder::addPiece);
}
});
}
}
}
Aggregations