use of net.minecraft.world.level.biome.CheckerboardColumnBiomeSource 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.biome.CheckerboardColumnBiomeSource in project RepurposedStructures by TelepathicGrunt.
the class GenericJigsawStructure method isGenericFeatureChunk.
protected static <CC extends RSGenericConfig> boolean isGenericFeatureChunk(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++) {
int yValue = config.doNotUseHeightmap ? config.setFixedYSpawn : config.setFixedYSpawn + context.chunkGenerator().getFirstFreeHeight(curChunkX << 4, curChunkZ << 4, Heightmap.Types.WORLD_SURFACE_WG, context.heightAccessor());
Holder<Biome> biome = context.biomeSource().getNoiseBiome(curChunkX << 2, yValue >> 2, curChunkZ << 2, context.chunkGenerator().climateSampler());
if (!context.validBiome().test(biome)) {
return false;
}
}
}
}
if (config.cannotSpawnInLiquid) {
BlockPos centerOfChunk = chunkPos.getMiddleBlockPosition(0);
int landHeight = context.chunkGenerator().getFirstOccupiedHeight(centerOfChunk.getX(), centerOfChunk.getZ(), Heightmap.Types.WORLD_SURFACE_WG, context.heightAccessor());
NoiseColumn columnOfBlocks = context.chunkGenerator().getBaseColumn(centerOfChunk.getX(), centerOfChunk.getZ(), context.heightAccessor());
BlockState topBlock = columnOfBlocks.getBlock(centerOfChunk.getY() + landHeight);
if (!topBlock.getFluidState().isEmpty()) {
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;
}
}
if (config.allowedTerrainHeightRange != -1) {
int maxTerrainHeight = Integer.MIN_VALUE;
int minTerrainHeight = Integer.MAX_VALUE;
for (int curChunkX = chunkPos.x - config.terrainHeightCheckRadius; curChunkX <= chunkPos.x + config.terrainHeightCheckRadius; curChunkX++) {
for (int curChunkZ = chunkPos.z - config.terrainHeightCheckRadius; curChunkZ <= chunkPos.z + config.terrainHeightCheckRadius; curChunkZ++) {
int height = context.chunkGenerator().getBaseHeight((curChunkX << 4) + 7, (curChunkZ << 4) + 7, Heightmap.Types.WORLD_SURFACE_WG, context.heightAccessor());
maxTerrainHeight = Math.max(maxTerrainHeight, height);
minTerrainHeight = Math.min(minTerrainHeight, height);
if (minTerrainHeight < config.minYAllowed) {
return false;
}
}
}
if (maxTerrainHeight - minTerrainHeight > config.allowedTerrainHeightRange) {
return false;
}
}
return true;
}
use of net.minecraft.world.level.biome.CheckerboardColumnBiomeSource in project blueprint by team-abnormals.
the class BiomeSourceModificationManager method onServerAboutToStart.
@SuppressWarnings("unchecked")
@SubscribeEvent
public static void onServerAboutToStart(ServerAboutToStartEvent event) {
if (INSTANCE == null)
return;
List<BiomeSourceModifier> modifiers = INSTANCE.modifiers;
if (modifiers.isEmpty())
return;
MinecraftServer server = event.getServer();
WorldGenSettings worldGenSettings = server.getWorldData().worldGenSettings();
var dimensions = worldGenSettings.dimensions();
var keySet = dimensions.keySet();
SelectionSpace selectionSpace = (consumer) -> keySet.forEach(location -> consumer.accept(location, null));
HashMap<ResourceLocation, ArrayList<BiomeUtil.ModdedBiomeProvider>> map = new HashMap<>();
for (BiomeSourceModifier modifier : modifiers) {
BiomeUtil.ModdedBiomeProvider provider = modifier.provider();
if (provider.getWeight() <= 0)
return;
modifier.targetSelector().getTargetNames(selectionSpace).forEach(location -> {
map.computeIfAbsent(location, __ -> new ArrayList<>()).add(provider);
});
}
long seed = worldGenSettings.seed();
RegistryAccess registryAccess = server.registryAccess();
Registry<Biome> biomeRegistry = registryAccess.registryOrThrow(Registry.BIOME_REGISTRY);
Registry<NormalNoise.NoiseParameters> noiseParametersRegistry = registryAccess.registryOrThrow(Registry.NOISE_REGISTRY);
Registry<DensityFunction> densityFunctionRegistry = registryAccess.registryOrThrow(Registry.DENSITY_FUNCTION_REGISTRY);
NoiseSettings defaultNoiseSettings = registryAccess.registryOrThrow(Registry.NOISE_GENERATOR_SETTINGS_REGISTRY).getOrThrow(NoiseGeneratorSettings.OVERWORLD).noiseSettings();
DensityFunction defaultModdedness = densityFunctionRegistry.getOrThrow(ModdedBiomeSource.DEFAULT_MODDEDNESS);
for (Map.Entry<ResourceKey<LevelStem>, LevelStem> entry : dimensions.entrySet()) {
ResourceLocation location = entry.getKey().location();
ArrayList<BiomeUtil.ModdedBiomeProvider> providersForKey = map.get(location);
if (providersForKey != null && !providersForKey.isEmpty()) {
ChunkGenerator chunkGenerator = entry.getValue().generator();
BiomeSource source = chunkGenerator.getBiomeSource();
// TODO: Mostly experimental! Works with Terralith, Biomes O' Plenty, and more, but still needs more testing!
if (!(source instanceof FixedBiomeSource) && !(source instanceof CheckerboardColumnBiomeSource)) {
boolean legacy = false;
boolean noiseBased = chunkGenerator instanceof NoiseBasedChunkGenerator;
NoiseSettings noiseSettings = defaultNoiseSettings;
if (noiseBased) {
try {
NoiseGeneratorSettings settings = ((Holder<NoiseGeneratorSettings>) NOISE_GENERATOR_SETTINGS.get(chunkGenerator)).value();
if (settings != null) {
legacy = settings.useLegacyRandomSource();
noiseSettings = settings.noiseSettings();
}
} catch (IllegalAccessException ignored) {
}
}
DensityFunction moddedness = densityFunctionRegistry.get(new ResourceLocation(Blueprint.MOD_ID, "moddedness/" + location.getNamespace() + "/" + location.getPath()));
ModdedBiomeSource moddedBiomeSource = new ModdedBiomeSource(biomeRegistry, noiseParametersRegistry, densityFunctionRegistry, source, noiseSettings, seed, legacy, moddedness != null ? moddedness : defaultModdedness, new ModdedBiomeSource.WeightedBiomeSlices(providersForKey.toArray(new BiomeUtil.ModdedBiomeProvider[0])));
chunkGenerator.biomeSource = moddedBiomeSource;
chunkGenerator.runtimeBiomeSource = moddedBiomeSource;
if (noiseBased)
((ModdedSurfaceSystem) ((NoiseBasedChunkGenerator) chunkGenerator).surfaceSystem).setModdedBiomeSource(moddedBiomeSource);
}
}
}
}
Aggregations