[Change] Template Structures perform a biome test at random height before checking the noise columns
This commit is contained in:
parent
ced356d19c
commit
ac4b1e08e3
1 changed files with 34 additions and 6 deletions
|
@ -3,11 +3,14 @@ package org.betterx.bclib.api.v2.levelgen.structures;
|
||||||
import com.mojang.serialization.Codec;
|
import com.mojang.serialization.Codec;
|
||||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.core.Holder;
|
||||||
|
import net.minecraft.core.QuartPos;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.util.ExtraCodecs;
|
import net.minecraft.util.ExtraCodecs;
|
||||||
import net.minecraft.util.RandomSource;
|
import net.minecraft.util.RandomSource;
|
||||||
import net.minecraft.world.level.ChunkPos;
|
import net.minecraft.world.level.ChunkPos;
|
||||||
import net.minecraft.world.level.NoiseColumn;
|
import net.minecraft.world.level.NoiseColumn;
|
||||||
|
import net.minecraft.world.level.biome.Biome;
|
||||||
import net.minecraft.world.level.block.Blocks;
|
import net.minecraft.world.level.block.Blocks;
|
||||||
import net.minecraft.world.level.block.Mirror;
|
import net.minecraft.world.level.block.Mirror;
|
||||||
import net.minecraft.world.level.block.Rotation;
|
import net.minecraft.world.level.block.Rotation;
|
||||||
|
@ -92,17 +95,21 @@ public abstract class TemplateStructure extends Structure {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<GenerationStub> findGenerationPoint(GenerationContext ctx) {
|
public Optional<GenerationStub> findGenerationPoint(GenerationContext ctx) {
|
||||||
|
final Config config = randomConfig(ctx.random());
|
||||||
|
if (config == null) return Optional.empty();
|
||||||
|
|
||||||
|
ChunkPos chunkPos = ctx.chunkPos();
|
||||||
|
final int x = chunkPos.getMinBlockX();
|
||||||
|
final int z = chunkPos.getMinBlockZ();
|
||||||
|
if (!hasValidBiomeAtRandomHeight(ctx, x, z))
|
||||||
|
return Optional.empty();
|
||||||
|
|
||||||
WorldGenerationContext worldGenerationContext = new WorldGenerationContext(
|
WorldGenerationContext worldGenerationContext = new WorldGenerationContext(
|
||||||
ctx.chunkGenerator(),
|
ctx.chunkGenerator(),
|
||||||
ctx.heightAccessor()
|
ctx.heightAccessor()
|
||||||
);
|
);
|
||||||
final Config config = randomConfig(ctx.random());
|
|
||||||
if (config == null) return Optional.empty();
|
|
||||||
ChunkPos chunkPos = ctx.chunkPos();
|
|
||||||
final int x = chunkPos.getMinBlockX();
|
|
||||||
final int z = chunkPos.getMinBlockZ();
|
|
||||||
StructureTemplate structureTemplate = ctx.structureTemplateManager().getOrCreate(config.location);
|
|
||||||
|
|
||||||
|
StructureTemplate structureTemplate = ctx.structureTemplateManager().getOrCreate(config.location);
|
||||||
|
|
||||||
final BiPredicate<BlockState, BlockState> isCorrectBase;
|
final BiPredicate<BlockState, BlockState> isCorrectBase;
|
||||||
final int searchStep;
|
final int searchStep;
|
||||||
|
@ -215,6 +222,27 @@ public abstract class TemplateStructure extends Structure {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean hasValidBiomeAtRandomHeight(GenerationContext ctx, int x, int z) {
|
||||||
|
final int randomY = ctx.random()
|
||||||
|
.nextIntBetweenInclusive(
|
||||||
|
ctx.heightAccessor().getMinBuildHeight(),
|
||||||
|
ctx.heightAccessor().getMaxBuildHeight()
|
||||||
|
);
|
||||||
|
|
||||||
|
Holder<Biome> holder = ctx.chunkGenerator()
|
||||||
|
.getBiomeSource()
|
||||||
|
.getNoiseBiome(
|
||||||
|
QuartPos.fromBlock(x),
|
||||||
|
QuartPos.fromBlock(randomY),
|
||||||
|
QuartPos.fromBlock(z),
|
||||||
|
ctx.randomState().sampler()
|
||||||
|
);
|
||||||
|
if (!ctx.validBiome().test(holder)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
private float airRatio(NoiseColumn column, int y, int height, int searchStep) {
|
private float airRatio(NoiseColumn column, int y, int height, int searchStep) {
|
||||||
int airCount = 0;
|
int airCount = 0;
|
||||||
for (int i = y; i < y + height && i > y - height; i += searchStep) {
|
for (int i = y; i < y + height && i > y - height; i += searchStep) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue