use of net.minecraft.world.level.levelgen.LegacyRandomSource in project Valhelsia-Structures by ValhelsiaTeam.
the class AbstractValhelsiaStructure method isFeatureChunk.
protected boolean isFeatureChunk(PieceGeneratorSupplier.Context<JigsawConfiguration> context) {
ChunkPos chunkPos = context.chunkPos();
BlockPos pos = chunkPos.getWorldPosition();
ChunkGenerator generator = context.chunkGenerator();
WorldgenRandom random = new WorldgenRandom(new LegacyRandomSource(0L));
// Check if the surface is flat
if (this.checkSurface() && !StructureUtils.isSurfaceFlat(context, this.getSize())) {
return false;
}
// Check for water
if (!this.canGenerateOnWater()) {
int landHeight = generator.getFirstOccupiedHeight(pos.getX(), pos.getZ(), Heightmap.Types.WORLD_SURFACE_WG, context.heightAccessor());
NoiseColumn columnOfBlocks = generator.getBaseColumn(pos.getX(), pos.getZ(), context.heightAccessor());
BlockState topBlock = columnOfBlocks.getBlock(landHeight);
if (!topBlock.getFluidState().isEmpty()) {
return false;
}
}
// Check for other structures
List<ResourceKey<StructureSet>> structures = ModStructures.MOD_STRUCTURES.stream().filter(structure -> structure.step() == this.step() && structure.getStructureSetResourceKey() != this.getStructureSetResourceKey()).map(AbstractValhelsiaStructure::getStructureSetResourceKey).toList();
if (StructureUtils.isStructureInDistance(generator, context.seed(), context.chunkPos(), structures)) {
return false;
}
// Check the spawn chance
random.setSeed((long) (chunkPos.x >> 4 ^ chunkPos.z >> 4 << 4) ^ context.seed());
return random.nextDouble() < this.getSpawnChance();
}
use of net.minecraft.world.level.levelgen.LegacyRandomSource in project bygone-nether by izofar.
the class NetherFortressStructure method checkChunk.
private static boolean checkChunk(PieceGeneratorSupplier.Context<JigsawConfiguration> context) {
WorldgenRandom worldgenrandom = new WorldgenRandom(new LegacyRandomSource(0L));
worldgenrandom.setLargeFeatureSeed(context.seed(), context.chunkPos().x, context.chunkPos().z);
return context.validBiome().test(context.chunkGenerator().getNoiseBiome(QuartPos.fromBlock(context.chunkPos().getMiddleBlockX()), QuartPos.fromBlock(64), QuartPos.fromBlock(context.chunkPos().getMiddleBlockZ())));
}
use of net.minecraft.world.level.levelgen.LegacyRandomSource in project Applied-Energistics-2 by AppliedEnergistics.
the class MeteoriteStructure method checkLocation.
private static boolean checkLocation(PieceGeneratorSupplier.Context<NoneFeatureConfiguration> context) {
if (!context.validBiomeOnTop(Heightmap.Types.WORLD_SURFACE_WG)) {
return false;
}
WorldgenRandom worldgenRandom = new WorldgenRandom(new LegacyRandomSource(0L));
worldgenRandom.setLargeFeatureSeed(context.seed(), context.chunkPos().x, context.chunkPos().z);
return worldgenRandom.nextBoolean();
}
use of net.minecraft.world.level.levelgen.LegacyRandomSource in project TutorialV3 by McJty.
the class PortalStructure method findSuitableSpot.
@NotNull
private static BlockPos findSuitableSpot(PieceGeneratorSupplier.Context<JigsawConfiguration> context, BlockPos blockpos) {
LevelHeightAccessor heightAccessor = context.heightAccessor();
// Get the top y location that is solid
int y = context.chunkGenerator().getBaseHeight(blockpos.getX(), blockpos.getZ(), Heightmap.Types.WORLD_SURFACE_WG, heightAccessor);
// Create a randomgenerator that depends on the current chunk location. That way if the world is recreated
// with the same seed the feature will end up at the same spot
WorldgenRandom worldgenrandom = new WorldgenRandom(new LegacyRandomSource(context.seed()));
worldgenrandom.setLargeFeatureSeed(context.seed(), context.chunkPos().x, context.chunkPos().z);
// Pick a random y location between a low and a high point
y = worldgenrandom.nextIntBetweenInclusive(heightAccessor.getMinBuildHeight() + 20, y - 10);
// Go down until we find a spot that has air. Then go down until we find a spot that is solid again
NoiseColumn baseColumn = context.chunkGenerator().getBaseColumn(blockpos.getX(), blockpos.getZ(), heightAccessor);
// Remember 'y' because we will just use this if we can't find an air bubble
int yy = y;
// Lower limit, don't go below this
int lower = heightAccessor.getMinBuildHeight() + 3;
while (yy > lower && !baseColumn.getBlock(yy).isAir()) {
yy--;
}
// If we found air we go down until we find a non-air block
if (yy > lower) {
while (yy > lower && baseColumn.getBlock(yy).isAir()) {
yy--;
}
if (yy > lower) {
// We found a possible spawn spot
y = yy + 1;
}
}
return blockpos.atY(y);
}
use of net.minecraft.world.level.levelgen.LegacyRandomSource in project RepurposedStructures by TelepathicGrunt.
the class AdvancedDistanceJigsawStructure method generateDistancePieces.
public static <CC extends RSAdvancedDistanceConfig> Optional<PieceGenerator<CC>> generateDistancePieces(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) -> {
Optional<PoolElementStructurePiece> lowestPiece = pieces.stream().min(Comparator.comparingInt(p -> p.getBoundingBox().minY()));
int minY = lowestPiece.map(poolElementStructurePiece -> poolElementStructurePiece.getBoundingBox().minY()).orElseGet(blockpos::getY);
if (minY < context.chunkGenerator().getMinY()) {
int newOffset = context.chunkGenerator().getMinY() - minY;
for (StructurePiece piece : pieces) {
piece.move(0, newOffset, 0);
}
}
});
}
Aggregations