Post placement modifiers for enormous placements
This commit is contained in:
parent
25a312b56f
commit
88c3fe24b0
@ -7,6 +7,8 @@ import net.minecraft.resources.ResourceKey
|
|||||||
import net.minecraft.tags.BiomeTags
|
import net.minecraft.tags.BiomeTags
|
||||||
import net.minecraft.tags.BlockTags
|
import net.minecraft.tags.BlockTags
|
||||||
import net.minecraft.util.valueproviders.ClampedNormalFloat
|
import net.minecraft.util.valueproviders.ClampedNormalFloat
|
||||||
|
import net.minecraft.util.valueproviders.ConstantFloat
|
||||||
|
import net.minecraft.util.valueproviders.ConstantInt
|
||||||
import net.minecraft.util.valueproviders.UniformFloat
|
import net.minecraft.util.valueproviders.UniformFloat
|
||||||
import net.minecraft.util.valueproviders.UniformInt
|
import net.minecraft.util.valueproviders.UniformInt
|
||||||
import net.minecraft.world.level.levelgen.GenerationStep
|
import net.minecraft.world.level.levelgen.GenerationStep
|
||||||
@ -32,6 +34,7 @@ import ru.dbotthepony.mc.otm.registry.data.MWorldGenFeatures
|
|||||||
import ru.dbotthepony.mc.otm.worldgen.feature.BlackHolePlacerFeature
|
import ru.dbotthepony.mc.otm.worldgen.feature.BlackHolePlacerFeature
|
||||||
import ru.dbotthepony.mc.otm.worldgen.feature.DebugPlacerFeature
|
import ru.dbotthepony.mc.otm.worldgen.feature.DebugPlacerFeature
|
||||||
import ru.dbotthepony.mc.otm.worldgen.placement.AbstractEnormousPlacement
|
import ru.dbotthepony.mc.otm.worldgen.placement.AbstractEnormousPlacement
|
||||||
|
import ru.dbotthepony.mc.otm.worldgen.placement.EllipsoidPlacement
|
||||||
import ru.dbotthepony.mc.otm.worldgen.placement.EnormousEllipsoidPlacement
|
import ru.dbotthepony.mc.otm.worldgen.placement.EnormousEllipsoidPlacement
|
||||||
import ru.dbotthepony.mc.otm.worldgen.placement.WormPlacement
|
import ru.dbotthepony.mc.otm.worldgen.placement.WormPlacement
|
||||||
|
|
||||||
@ -116,15 +119,26 @@ fun registerPlacedFeatures(context: BootstrapContext<PlacedFeature>) {
|
|||||||
listOf(
|
listOf(
|
||||||
WormPlacement(
|
WormPlacement(
|
||||||
parameters = AbstractEnormousPlacement.Parameters(
|
parameters = AbstractEnormousPlacement.Parameters(
|
||||||
chunkScanRange = 12,
|
chunkScanRange = 24,
|
||||||
seedMix = 9284343575495L,
|
seedMix = 9284343575495L,
|
||||||
placementModifiers = listOf(
|
prePlacementModifiers = listOf(
|
||||||
RarityFilter.onAverageOnceEvery(10),
|
RarityFilter.onAverageOnceEvery(120),
|
||||||
InSquarePlacement.spread(),
|
InSquarePlacement.spread(),
|
||||||
HeightRangePlacement.of(StandardDeviationHeightProvider(VerticalAnchor.absolute(120), 15.0)),
|
HeightRangePlacement.of(StandardDeviationHeightProvider(VerticalAnchor.absolute(120), 15.0)),
|
||||||
|
),
|
||||||
|
postPlacementModifiers = listOf(
|
||||||
|
EllipsoidPlacement(
|
||||||
|
count = UniformInt.of(15, 40),
|
||||||
|
xLength = ConstantFloat.of(14f),
|
||||||
|
yLength = ConstantFloat.of(14f),
|
||||||
|
zLength = ConstantFloat.of(14f),
|
||||||
|
x = ClampedNormalFloat.of(0f, 0.4f, -1f, 1f),
|
||||||
|
y = ClampedNormalFloat.of(0f, 0.4f, -1f, 1f),
|
||||||
|
z = ClampedNormalFloat.of(0f, 0.4f, -1f, 1f),
|
||||||
|
)
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
length = UniformInt.of(40, 200),
|
length = UniformInt.of(120, 400),
|
||||||
turnRateXY = WormPlacement.normalDistributedTurnRate(10f),
|
turnRateXY = WormPlacement.normalDistributedTurnRate(10f),
|
||||||
turnRateXZ = WormPlacement.normalDistributedTurnRate(60f),
|
turnRateXZ = WormPlacement.normalDistributedTurnRate(60f),
|
||||||
turnSpeedXZ = WormPlacement.constantTurnRate(10f),
|
turnSpeedXZ = WormPlacement.constantTurnRate(10f),
|
||||||
@ -151,7 +165,7 @@ fun registerPlacedFeatures(context: BootstrapContext<PlacedFeature>) {
|
|||||||
parameters = AbstractEnormousPlacement.Parameters(
|
parameters = AbstractEnormousPlacement.Parameters(
|
||||||
chunkScanRange = 5,
|
chunkScanRange = 5,
|
||||||
seedMix = 237483209523709234L,
|
seedMix = 237483209523709234L,
|
||||||
placementModifiers = listOf(
|
prePlacementModifiers = listOf(
|
||||||
RarityFilter.onAverageOnceEvery(120),
|
RarityFilter.onAverageOnceEvery(120),
|
||||||
InSquarePlacement.spread(),
|
InSquarePlacement.spread(),
|
||||||
HeightRangePlacement.of(StandardDeviationHeightProvider(VerticalAnchor.absolute(0), 15.0)),
|
HeightRangePlacement.of(StandardDeviationHeightProvider(VerticalAnchor.absolute(0), 15.0)),
|
||||||
|
@ -26,8 +26,10 @@ import kotlin.math.sqrt
|
|||||||
* Enormous placement base, which allows it to span over several chunks without issues.
|
* Enormous placement base, which allows it to span over several chunks without issues.
|
||||||
*
|
*
|
||||||
* MUST come as first placement modifier, other placement modifiers (such as rarity and
|
* MUST come as first placement modifier, other placement modifiers (such as rarity and
|
||||||
* shuffle of center point within chunks) must be provided inside [Parameters.placementModifiers] list, in same order as if they were
|
* shuffle of center point within chunks) must be provided inside [Parameters.prePlacementModifiers] list, in same order as if they were
|
||||||
* *before* this placement
|
* *before* this placement
|
||||||
|
*
|
||||||
|
* If "post-processing" placements are required, better provide them as [Parameters.postPlacementModifiers].
|
||||||
*/
|
*/
|
||||||
abstract class AbstractEnormousPlacement(val parameters: Parameters) : PlacementModifier() {
|
abstract class AbstractEnormousPlacement(val parameters: Parameters) : PlacementModifier() {
|
||||||
data class Parameters(
|
data class Parameters(
|
||||||
@ -42,7 +44,14 @@ abstract class AbstractEnormousPlacement(val parameters: Parameters) : Placement
|
|||||||
/**
|
/**
|
||||||
* Baseline placement modifiers, dictating how to appear in chunk
|
* Baseline placement modifiers, dictating how to appear in chunk
|
||||||
*/
|
*/
|
||||||
val placementModifiers: List<PlacementModifier>,
|
val prePlacementModifiers: List<PlacementModifier> = listOf(),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Post placement modifiers, operating on positions returned by this placement
|
||||||
|
*
|
||||||
|
* Generally, using this will yield better results
|
||||||
|
*/
|
||||||
|
val postPlacementModifiers: List<PlacementModifier> = listOf(),
|
||||||
)
|
)
|
||||||
|
|
||||||
private class GeneratedChunk(positions: Stream<BlockPos>) {
|
private class GeneratedChunk(positions: Stream<BlockPos>) {
|
||||||
@ -86,8 +95,10 @@ abstract class AbstractEnormousPlacement(val parameters: Parameters) : Placement
|
|||||||
|
|
||||||
val random = PCG32RandomSource(hash.digestAsLong())
|
val random = PCG32RandomSource(hash.digestAsLong())
|
||||||
var stream = Stream.of(BlockPos(pos.minBlockX, 0, pos.minBlockZ))
|
var stream = Stream.of(BlockPos(pos.minBlockX, 0, pos.minBlockZ))
|
||||||
parameters.placementModifiers.forEach { modifier -> stream = stream.flatMap { modifier.getPositions(context, random, it).sequential() } }
|
parameters.prePlacementModifiers.forEach { modifier -> stream = stream.flatMap { modifier.getPositions(context, random, it).sequential() } }
|
||||||
return GeneratedChunk(stream.flatMap { getPositions(it, random) })
|
stream = stream.flatMap { getPositions(it, random) }
|
||||||
|
parameters.postPlacementModifiers.forEach { modifier -> stream = stream.flatMap { modifier.getPositions(context, random, it).sequential() } }
|
||||||
|
return GeneratedChunk(stream)
|
||||||
}
|
}
|
||||||
|
|
||||||
final override fun getPositions(context: PlacementContext, random: RandomSource, pos: BlockPos): Stream<BlockPos> {
|
final override fun getPositions(context: PlacementContext, random: RandomSource, pos: BlockPos): Stream<BlockPos> {
|
||||||
@ -115,7 +126,8 @@ abstract class AbstractEnormousPlacement(val parameters: Parameters) : Placement
|
|||||||
it.group(
|
it.group(
|
||||||
Codec.INT.minRange(0).fieldOf("chunk_scan_range").forGetter(Parameters::chunkScanRange),
|
Codec.INT.minRange(0).fieldOf("chunk_scan_range").forGetter(Parameters::chunkScanRange),
|
||||||
Codec.LONG.fieldOf("seed_mix").forGetter(Parameters::seedMix),
|
Codec.LONG.fieldOf("seed_mix").forGetter(Parameters::seedMix),
|
||||||
CODEC.listOf().fieldOf("placement").forGetter(Parameters::placementModifiers),
|
CODEC.listOf().optionalFieldOf("placement", listOf()).forGetter(Parameters::prePlacementModifiers),
|
||||||
|
CODEC.listOf().optionalFieldOf("post_placement", listOf()).forGetter(Parameters::postPlacementModifiers),
|
||||||
).apply(it, ::Parameters)
|
).apply(it, ::Parameters)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user