use of net.minecraft.world.level.levelgen.LegacyRandomSource in project RepurposedStructures by TelepathicGrunt.
the class AdvancedJigsawStructure method generateAdvancedPieces.
public static <CC extends RSAdvancedConfig> Optional<PieceGenerator<CC>> generateAdvancedPieces(PieceGeneratorSupplier.Context<CC> context) {
BlockPos.MutableBlockPos blockpos = new BlockPos.MutableBlockPos(context.chunkPos().getMinBlockX(), 0, context.chunkPos().getMinBlockZ());
CC config = context.config();
if (config.maxY - config.minY <= 0) {
RepurposedStructures.LOGGER.error("MinY should always be less than MaxY or else a crash will occur or no pieces will spawn. Problematic structure is:" + config.startPool.unwrapKey().get().location());
}
WorldgenRandom random = new WorldgenRandom(new LegacyRandomSource(0L));
random.setLargeFeatureSeed(context.seed(), context.chunkPos().x, context.chunkPos().z);
int structureStartHeight = random.nextInt(config.maxY - config.minY) + config.minY;
blockpos.move(Direction.UP, structureStartHeight);
int topClipOff;
int bottomClipOff;
if (config.verticalRange.isEmpty()) {
// Help make sure the Jigsaw Blocks have room to spawn new pieces if structure is right on edge of maxY or topYLimit
topClipOff = config.clipOutOfBoundsPieces ? config.maxY + 5 : Integer.MAX_VALUE;
bottomClipOff = config.clipOutOfBoundsPieces ? config.minY - 5 : Integer.MIN_VALUE;
} else {
topClipOff = structureStartHeight + config.verticalRange.get();
bottomClipOff = structureStartHeight - config.verticalRange.get();
}
return PieceLimitedJigsawManager.assembleJigsawStructure(context, new JigsawConfiguration(config.startPool, config.size), GeneralUtils.getCsfNameForConfig(config, context.registryAccess()), blockpos, false, false, topClipOff, bottomClipOff, config.poolsThatIgnoreBoundaries, (structurePiecesBuilder, pieces) -> {
});
}
use of net.minecraft.world.level.levelgen.LegacyRandomSource in project RepurposedStructures by TelepathicGrunt.
the class AdvancedJigsawStructure method isAdvancedFeatureChunk.
protected static <CC extends RSAdvancedConfig> boolean isAdvancedFeatureChunk(PieceGeneratorSupplier.Context<CC> context) {
ChunkPos chunkPos = context.chunkPos();
CC config = context.config();
if (!(context.biomeSource() instanceof CheckerboardColumnBiomeSource)) {
for (int curChunkX = chunkPos.x - config.biomeRadius; curChunkX <= chunkPos.x + config.biomeRadius; curChunkX++) {
for (int curChunkZ = chunkPos.z - config.biomeRadius; curChunkZ <= chunkPos.z + config.biomeRadius; curChunkZ++) {
WorldgenRandom random = new WorldgenRandom(new LegacyRandomSource(0L));
random.setLargeFeatureSeed(context.seed(), context.chunkPos().x, context.chunkPos().z);
int structureStartHeight = random.nextInt(config.maxY - config.minY) + config.minY;
if (!context.validBiome().test(context.biomeSource().getNoiseBiome(curChunkX << 2, structureStartHeight >> 2, curChunkZ << 2, context.chunkGenerator().climateSampler()))) {
return false;
}
}
}
}
// cannot be near other specified structure
for (ResourceKey<StructureSet> structureSetToAvoid : config.structureSetToAvoid) {
if (context.chunkGenerator().hasFeatureChunkInRange(structureSetToAvoid, context.seed(), chunkPos.x, chunkPos.z, config.structureAvoidRadius)) {
return false;
}
}
return true;
}
use of net.minecraft.world.level.levelgen.LegacyRandomSource in project RepurposedStructures by TelepathicGrunt.
the class MineshaftStructure method generateMineshaftPieces.
public static <CC extends RSMineshaftConfig> Optional<PieceGenerator<CC>> generateMineshaftPieces(PieceGeneratorSupplier.Context<CC> context) {
BlockPos.MutableBlockPos blockpos = new BlockPos.MutableBlockPos(context.chunkPos().getMinBlockX(), 0, context.chunkPos().getMinBlockZ());
CC config = context.config();
if (config.maxY - config.minY <= 0) {
RepurposedStructures.LOGGER.error("MinY should always be less than MaxY or else a crash will occur or no pieces will spawn. Problematic structure is:" + config.startPool.unwrapKey().get().location());
}
WorldgenRandom random = new WorldgenRandom(new LegacyRandomSource(0L));
random.setLargeFeatureSeed(context.seed(), context.chunkPos().x, context.chunkPos().z);
int structureStartHeight = random.nextInt(config.maxY - config.minY) + config.minY;
blockpos.move(Direction.UP, structureStartHeight);
int topClipOff;
int bottomClipOff;
if (config.verticalRange.isEmpty()) {
// Help make sure the Jigsaw Blocks have room to spawn new pieces if structure is right on edge of maxY or topYLimit
topClipOff = config.clipOutOfBoundsPieces ? config.maxY + 5 : Integer.MAX_VALUE;
bottomClipOff = config.clipOutOfBoundsPieces ? config.minY - 5 : Integer.MIN_VALUE;
} else {
topClipOff = structureStartHeight + config.verticalRange.get();
bottomClipOff = structureStartHeight - config.verticalRange.get();
}
return PieceLimitedJigsawManager.assembleJigsawStructure(context, new JigsawConfiguration(config.startPool, config.size), GeneralUtils.getCsfNameForConfig(config, context.registryAccess()), blockpos, false, false, topClipOff, bottomClipOff, config.poolsThatIgnoreBoundaries, (structurePiecesBuilder, pieces) -> {
int justBelowTerrain = getTerrainHeight(context.chunkPos().getMiddleBlockPosition(0), context.chunkGenerator(), context.heightAccessor()) - 15;
int finalJustBelowTerrain = Math.max(justBelowTerrain, bottomClipOff);
Optional<PoolElementStructurePiece> topPiece = pieces.stream().max(Comparator.comparingInt(piece -> piece.getBoundingBox().maxY()));
if (topPiece.isPresent() && finalJustBelowTerrain < topClipOff && finalJustBelowTerrain < topPiece.get().getBoundingBox().maxY()) {
int topPieceMaxY = topPiece.get().getBoundingBox().maxY();
pieces.forEach(piece -> piece.move(0, finalJustBelowTerrain - topPieceMaxY, 0));
}
});
}
use of net.minecraft.world.level.levelgen.LegacyRandomSource in project RepurposedStructures by TelepathicGrunt.
the class MineshaftStructure method isMineshaftFeatureChunk.
protected static <CC extends RSMineshaftConfig> boolean isMineshaftFeatureChunk(PieceGeneratorSupplier.Context<CC> context) {
WorldgenRandom worldgenRandom = new WorldgenRandom(new LegacyRandomSource(0L));
worldgenRandom.setLargeFeatureSeed(context.seed(), context.chunkPos().x, context.chunkPos().z);
double chance = (context.config()).probability;
if (worldgenRandom.nextDouble() >= chance) {
return false;
}
Holder<Biome> biomeAtSpot = context.chunkGenerator().getNoiseBiome(QuartPos.fromBlock(context.chunkPos().getMiddleBlockX()), QuartPos.fromBlock(50), QuartPos.fromBlock(context.chunkPos().getMiddleBlockZ()));
return context.validBiome().test(biomeAtSpot) && AdvancedJigsawStructure.isAdvancedFeatureChunk(context);
}
use of net.minecraft.world.level.levelgen.LegacyRandomSource in project RepurposedStructures by TelepathicGrunt.
the class CeilingVinePostProcessor method processBlock.
@Override
public StructureTemplate.StructureBlockInfo processBlock(LevelReader worldView, BlockPos pos, BlockPos blockPos, StructureTemplate.StructureBlockInfo structureBlockInfoLocal, StructureTemplate.StructureBlockInfo structureBlockInfoWorld, StructurePlaceSettings structurePlacementData) {
// Place vines only in air space
if (structureBlockInfoWorld.state.isAir()) {
Random random = new WorldgenRandom(new LegacyRandomSource(0L));
random.setSeed(structureBlockInfoWorld.pos.asLong() * structureBlockInfoWorld.pos.getY());
ChunkAccess centerChunk = worldView.getChunk(structureBlockInfoWorld.pos);
BlockState centerState = centerChunk.getBlockState(structureBlockInfoWorld.pos);
BlockPos abovePos = structureBlockInfoWorld.pos.above();
BlockState aboveState = centerChunk.getBlockState(abovePos);
if (random.nextFloat() < probability && centerState.isAir() && Block.isFaceFull(aboveState.getCollisionShape(worldView, abovePos), Direction.DOWN)) {
BlockPos.MutableBlockPos mutable = new BlockPos.MutableBlockPos();
List<Direction> shuffledDirectionList = Direction.Plane.HORIZONTAL.stream().collect(Collectors.toList());
Collections.shuffle(shuffledDirectionList);
for (Direction facing : shuffledDirectionList) {
mutable.set(structureBlockInfoWorld.pos).move(facing);
BlockState worldState = worldView.getChunk(mutable).getBlockState(mutable);
// Vines only get placed if side block is empty and top block is solid.
if (!worldState.canOcclude()) {
// side block to hold vine
worldView.getChunk(mutable).setBlockState(mutable, blockState, false);
// ceiling vine
BlockState vineBlock = Blocks.VINE.defaultBlockState().setValue(VineBlock.getPropertyForFace(facing), true).setValue(VineBlock.UP, true);
// Move back to center
mutable.move(facing.getOpposite());
centerChunk.setBlockState(mutable, vineBlock, false);
// hanging vines
vineBlock = vineBlock.setValue(VineBlock.UP, false);
for (int depth = random.nextInt(4); depth < 3; depth++) {
mutable.move(Direction.DOWN);
if (!centerChunk.getBlockState(mutable).isAir()) {
break;
}
centerChunk.setBlockState(mutable, vineBlock, false);
}
break;
}
}
}
}
return structureBlockInfoWorld;
}
Aggregations