use of net.minecraft.world.level.levelgen.feature.configurations.JigsawConfiguration in project RepurposedStructures by TelepathicGrunt.
the class BuriableStructure method generatePieces.
public static <CC extends RSBuriableConfig> Optional<PieceGenerator<CC>> generatePieces(PieceGeneratorSupplier.Context<CC> context) {
BlockPos blockpos = new BlockPos(context.chunkPos().getMinBlockX(), context.chunkGenerator().getSeaLevel(), context.chunkPos().getMinBlockZ());
CC config = context.config();
return PieceLimitedJigsawManager.assembleJigsawStructure(context, new JigsawConfiguration(config.startPool, config.size), GeneralUtils.getCsfNameForConfig(config, context.registryAccess()), blockpos, false, false, Integer.MAX_VALUE, Integer.MIN_VALUE, (structurePiecesBuilder, pieces) -> {
GeneralUtils.centerAllPieces(blockpos, pieces);
Heightmap.Types heightMapToUse = config.useOceanHeightmap ? Heightmap.Types.OCEAN_FLOOR_WG : Heightmap.Types.WORLD_SURFACE_WG;
BoundingBox box = pieces.get(0).getBoundingBox();
int highestLandPos = context.chunkGenerator().getFirstOccupiedHeight(box.minX(), box.minZ(), heightMapToUse, context.heightAccessor());
highestLandPos = Math.min(highestLandPos, context.chunkGenerator().getFirstOccupiedHeight(box.minX(), box.maxZ(), heightMapToUse, context.heightAccessor()));
highestLandPos = Math.min(highestLandPos, context.chunkGenerator().getFirstOccupiedHeight(box.maxX(), box.minZ(), heightMapToUse, context.heightAccessor()));
highestLandPos = Math.min(highestLandPos, context.chunkGenerator().getFirstOccupiedHeight(box.maxX(), box.maxZ(), heightMapToUse, context.heightAccessor()));
if (config.useOceanHeightmap) {
int maxHeightForSubmerging = context.chunkGenerator().getSeaLevel() - box.getYSpan();
highestLandPos = Math.min(highestLandPos, maxHeightForSubmerging);
}
WorldgenRandom random = new WorldgenRandom(new LegacyRandomSource(0L));
random.setLargeFeatureSeed(context.seed(), context.chunkPos().x, context.chunkPos().z);
int heightDiff = highestLandPos - box.minY();
for (StructurePiece structurePiece : pieces) {
structurePiece.move(0, heightDiff + (config.offsetAmount), 0);
}
});
}
use of net.minecraft.world.level.levelgen.feature.configurations.JigsawConfiguration in project RepurposedStructures by TelepathicGrunt.
the class CityNetherStructure method generateCityNetherPieces.
public static <CC extends RSGenericNetherConfig> Optional<PieceGenerator<CC>> generateCityNetherPieces(PieceGeneratorSupplier.Context<CC> context) {
CC config = context.config();
BlockPos blockpos = new BlockPos(context.chunkPos().getMinBlockX(), context.chunkGenerator().getSeaLevel(), context.chunkPos().getMinBlockZ());
return PieceLimitedJigsawManager.assembleJigsawStructure(context, new JigsawConfiguration(config.startPool, config.size), GeneralUtils.getCsfNameForConfig(config, context.registryAccess()), blockpos, false, false, Integer.MAX_VALUE, Integer.MIN_VALUE, config.poolsThatIgnoreBoundaries, (structurePiecesBuilder, pieces) -> pieces.get(0).move(0, config.centerYOffset, 0));
}
use of net.minecraft.world.level.levelgen.feature.configurations.JigsawConfiguration in project RepurposedStructures by TelepathicGrunt.
the class GenericJigsawStructure method generateGenericPieces.
public static <CC extends RSGenericConfig> Optional<PieceGenerator<CC>> generateGenericPieces(PieceGeneratorSupplier.Context<CC> context) {
CC config = context.config();
BlockPos blockpos = new BlockPos(context.chunkPos().getMinBlockX(), config.setFixedYSpawn, context.chunkPos().getMinBlockZ());
return PieceLimitedJigsawManager.assembleJigsawStructure(context, new JigsawConfiguration(config.startPool, config.size), GeneralUtils.getCsfNameForConfig(config, context.registryAccess()), blockpos, !config.doNotUseHeightmap, !config.doNotUseHeightmap, Integer.MAX_VALUE, Integer.MIN_VALUE, config.poolsThatIgnoreBoundaries, (structurePiecesBuilder, pieces) -> {
GeneralUtils.centerAllPieces(blockpos, pieces);
pieces.get(0).move(0, config.centerYOffset, 0);
});
}
use of net.minecraft.world.level.levelgen.feature.configurations.JigsawConfiguration in project RepurposedStructures by TelepathicGrunt.
the class GenericNetherJigsawStructure method generateNetherPieces.
public static <CC extends RSGenericNetherConfig> Optional<PieceGenerator<CC>> generateNetherPieces(PieceGeneratorSupplier.Context<CC> context) {
CC config = context.config();
BlockPos blockpos = new BlockPos(context.chunkPos().getMinBlockX(), config.setFixedYSpawn, context.chunkPos().getMinBlockZ());
return PieceLimitedJigsawManager.assembleJigsawStructure(context, new JigsawConfiguration(config.startPool, config.size), GeneralUtils.getCsfNameForConfig(config, context.registryAccess()), blockpos, !config.doNotUseHeightmap, !config.doNotUseHeightmap, Integer.MAX_VALUE, Integer.MIN_VALUE, config.poolsThatIgnoreBoundaries, (structurePiecesBuilder, pieces) -> {
GeneralUtils.centerAllPieces(blockpos, pieces);
WorldgenRandom random = new WorldgenRandom(new LegacyRandomSource(0L));
random.setLargeFeatureSeed(context.seed(), context.chunkPos().x, context.chunkPos().z);
BlockPos placementPos;
if (config.highestLandSearch) {
placementPos = GeneralUtils.getHighestLand(context.chunkGenerator(), structurePiecesBuilder.getBoundingBox(), context.heightAccessor(), !config.cannotSpawnInLiquid);
} else {
placementPos = GeneralUtils.getLowestLand(context.chunkGenerator(), structurePiecesBuilder.getBoundingBox(), context.heightAccessor(), !config.cannotSpawnInLiquid);
}
if (placementPos.getY() >= GeneralUtils.getMaxTerrainLimit(context.chunkGenerator()) || placementPos.getY() <= context.chunkGenerator().getSeaLevel() + 1) {
int yDiff = (context.chunkGenerator().getSeaLevel() + config.ledgeSpotOffset) - pieces.get(0).getBoundingBox().minY();
pieces.forEach(piece -> piece.move(0, yDiff, 0));
} else {
int yDiff = (placementPos.getY() + config.ledgeSpotOffset) - pieces.get(0).getBoundingBox().minY();
pieces.forEach(piece -> piece.move(0, yDiff, 0));
}
pieces.forEach(piece -> piece.move(0, config.centerYOffset, 0));
});
}
use of net.minecraft.world.level.levelgen.feature.configurations.JigsawConfiguration in project RepurposedStructures by TelepathicGrunt.
the class LandBasedEndStructure method generateLandPieces.
public static <CC extends RSGenericConfig> Optional<PieceGenerator<CC>> generateLandPieces(PieceGeneratorSupplier.Context<CC> context) {
CC config = context.config();
BlockPos blockpos = new BlockPos(context.chunkPos().getMinBlockX(), config.setFixedYSpawn, context.chunkPos().getMinBlockZ());
return PieceLimitedJigsawManager.assembleJigsawStructure(context, new JigsawConfiguration(config.startPool, config.size), GeneralUtils.getCsfNameForConfig(config, context.registryAccess()), blockpos, !config.doNotUseHeightmap, !config.doNotUseHeightmap, Integer.MAX_VALUE, Integer.MIN_VALUE, config.poolsThatIgnoreBoundaries, (structurePiecesBuilder, pieces) -> {
GeneralUtils.centerAllPieces(blockpos, pieces);
BoundingBox box = pieces.get(0).getBoundingBox();
BlockPos centerPos = new BlockPos(box.getCenter());
int radius = (int) Math.sqrt((box.getLength().getX() * box.getLength().getX()) + (box.getLength().getZ() * box.getLength().getZ())) / 2;
List<Integer> landHeights = new ArrayList<>();
for (int xOffset = -radius; xOffset <= radius; xOffset += (radius / 2)) {
for (int zOffset = -radius; zOffset <= radius; zOffset += (radius / 2)) {
int landHeight = context.chunkGenerator().getFirstOccupiedHeight(centerPos.getX() + xOffset, centerPos.getZ() + zOffset, Heightmap.Types.WORLD_SURFACE_WG, context.heightAccessor());
landHeights.add(landHeight);
}
}
// Offset structure to average land around it
int avgHeight = (int) Math.max(landHeights.stream().mapToInt(Integer::intValue).average().orElse(0), 50);
int parentHeight = pieces.get(0).getBoundingBox().minY();
int offsetAmount = (avgHeight - parentHeight) + config.centerYOffset;
pieces.forEach(child -> child.move(0, offsetAmount, 0));
});
}
Aggregations