Move biome classes to world subpackage

This commit is contained in:
DBotThePony 2024-03-28 13:32:21 +07:00
parent b8a8e79819
commit 1d5953eb36
Signed by: DBot
GPG Key ID: DCC23B5715498507
9 changed files with 257 additions and 192 deletions

View File

@ -3,11 +3,9 @@ package ru.dbotthepony.kstarbound
import com.google.gson.GsonBuilder import com.google.gson.GsonBuilder
import com.google.gson.JsonElement import com.google.gson.JsonElement
import com.google.gson.JsonObject import com.google.gson.JsonObject
import com.google.gson.TypeAdapter
import com.google.gson.TypeAdapterFactory import com.google.gson.TypeAdapterFactory
import com.google.gson.stream.JsonReader import com.google.gson.stream.JsonReader
import org.apache.logging.log4j.LogManager import org.apache.logging.log4j.LogManager
import ru.dbotthepony.kommons.util.Either
import ru.dbotthepony.kstarbound.defs.Json2Function import ru.dbotthepony.kstarbound.defs.Json2Function
import ru.dbotthepony.kstarbound.defs.JsonConfigFunction import ru.dbotthepony.kstarbound.defs.JsonConfigFunction
import ru.dbotthepony.kstarbound.defs.JsonFunction import ru.dbotthepony.kstarbound.defs.JsonFunction
@ -40,15 +38,13 @@ import ru.dbotthepony.kstarbound.defs.tile.TileDefinition
import ru.dbotthepony.kstarbound.defs.world.BushVariant import ru.dbotthepony.kstarbound.defs.world.BushVariant
import ru.dbotthepony.kstarbound.defs.world.GrassVariant import ru.dbotthepony.kstarbound.defs.world.GrassVariant
import ru.dbotthepony.kstarbound.defs.world.TreeVariant import ru.dbotthepony.kstarbound.defs.world.TreeVariant
import ru.dbotthepony.kstarbound.defs.world.terrain.BiomeDefinition import ru.dbotthepony.kstarbound.defs.world.BiomeDefinition
import ru.dbotthepony.kstarbound.defs.world.terrain.TerrainSelectorFactory import ru.dbotthepony.kstarbound.defs.world.terrain.TerrainSelectorFactory
import ru.dbotthepony.kstarbound.defs.world.terrain.TerrainSelectorType import ru.dbotthepony.kstarbound.defs.world.terrain.TerrainSelectorType
import ru.dbotthepony.kstarbound.util.AssetPathStack import ru.dbotthepony.kstarbound.util.AssetPathStack
import java.util.* import java.util.*
import java.util.concurrent.CompletableFuture import java.util.concurrent.CompletableFuture
import java.util.concurrent.ExecutorService
import java.util.concurrent.Future import java.util.concurrent.Future
import java.util.function.Supplier
import kotlin.collections.ArrayList import kotlin.collections.ArrayList
object Registries { object Registries {

View File

@ -37,9 +37,9 @@ import ru.dbotthepony.kstarbound.defs.animation.Particle
import ru.dbotthepony.kstarbound.defs.item.ItemDescriptor import ru.dbotthepony.kstarbound.defs.item.ItemDescriptor
import ru.dbotthepony.kstarbound.defs.world.CelestialParameters import ru.dbotthepony.kstarbound.defs.world.CelestialParameters
import ru.dbotthepony.kstarbound.defs.world.VisitableWorldParametersType import ru.dbotthepony.kstarbound.defs.world.VisitableWorldParametersType
import ru.dbotthepony.kstarbound.defs.world.terrain.BiomePlaceables import ru.dbotthepony.kstarbound.defs.world.BiomePlaceables
import ru.dbotthepony.kstarbound.defs.world.terrain.BiomePlacementDistributionType import ru.dbotthepony.kstarbound.defs.world.BiomePlacementDistributionType
import ru.dbotthepony.kstarbound.defs.world.terrain.BiomePlacementItemType import ru.dbotthepony.kstarbound.defs.world.BiomePlacementItemType
import ru.dbotthepony.kstarbound.defs.world.terrain.TerrainSelectorType import ru.dbotthepony.kstarbound.defs.world.terrain.TerrainSelectorType
import ru.dbotthepony.kstarbound.io.* import ru.dbotthepony.kstarbound.io.*
import ru.dbotthepony.kstarbound.json.factory.MapsTypeAdapterFactory import ru.dbotthepony.kstarbound.json.factory.MapsTypeAdapterFactory

View File

@ -0,0 +1,23 @@
package ru.dbotthepony.kstarbound.defs.world
import com.google.common.collect.ImmutableList
import ru.dbotthepony.kstarbound.Registry
import ru.dbotthepony.kstarbound.defs.tile.MaterialModifier
import ru.dbotthepony.kstarbound.defs.tile.TileDefinition
import ru.dbotthepony.kstarbound.defs.world.AmbientNoisesDefinition
import ru.dbotthepony.kstarbound.defs.world.BiomePlaceables
import ru.dbotthepony.kstarbound.defs.world.Parallax
data class Biome(
val hueShift: Double = 0.0,
val baseName: String,
val description: String,
val mainBlock: Registry.Entry<TileDefinition>? = null,
val subBlocks: ImmutableList<Registry.Entry<TileDefinition>> = ImmutableList.of(),
val ores: ImmutableList<Pair<Registry.Entry<MaterialModifier>, Double>> = ImmutableList.of(),
val musicTrack: AmbientNoisesDefinition? = null,
val ambientNoises: AmbientNoisesDefinition? = null,
val surfacePlaceables: BiomePlaceables = BiomePlaceables(),
val undergroundPlaceables: BiomePlaceables = BiomePlaceables(),
val parallax: Parallax? = null,
)

View File

@ -0,0 +1,92 @@
package ru.dbotthepony.kstarbound.defs.world
import com.google.common.collect.ImmutableList
import com.google.common.collect.ImmutableSet
import ru.dbotthepony.kommons.collect.filterNotNull
import ru.dbotthepony.kstarbound.Registries
import ru.dbotthepony.kstarbound.Registry
import ru.dbotthepony.kstarbound.Starbound
import ru.dbotthepony.kstarbound.collect.WeightedList
import ru.dbotthepony.kstarbound.defs.AssetReference
import ru.dbotthepony.kstarbound.defs.JsonConfigFunction
import ru.dbotthepony.kstarbound.defs.tile.MaterialModifier
import ru.dbotthepony.kstarbound.defs.tile.TileDefinition
import ru.dbotthepony.kstarbound.json.builder.JsonFactory
import ru.dbotthepony.kstarbound.json.pairListAdapter
import ru.dbotthepony.kstarbound.util.random.random
import java.util.random.RandomGenerator
@JsonFactory
data class BiomeDefinition(
val airless: Boolean = false,
val name: String,
val statusEffects: ImmutableSet<String> = ImmutableSet.of(),
val weather: ImmutableList<Pair<Double, ImmutableList<AssetReference<WeightedList<String>>>>> = ImmutableList.of(), // binned reference to other assets
val hueShiftOptions: ImmutableList<Double> = ImmutableList.of(),
val skyOptions: ImmutableList<SkyColoring> = ImmutableList.of(),
val description: String = "...",
val mainBlock: Registry.Ref<TileDefinition>? = null,
val subBlocks: ImmutableList<Registry.Ref<TileDefinition>>? = null,
val ores: Registry.Ref<JsonConfigFunction>? = null,
val musicTrack: AmbientNoisesDefinition? = null,
val ambientNoises: AmbientNoisesDefinition? = null,
val surfacePlaceables: BiomePlaceablesDefinition = BiomePlaceablesDefinition(),
val undergroundPlaceables: BiomePlaceablesDefinition = BiomePlaceablesDefinition(),
val parallax: AssetReference<Parallax.Data>? = null,
) {
data class CreationParams(
val hueShift: Double,
val random: RandomGenerator
)
fun skyColoring(random: RandomGenerator): SkyColoring {
if (skyOptions.isEmpty())
return SkyColoring.BLACK
return skyOptions.random(random)
}
fun hueShift(random: RandomGenerator): Double {
if (hueShiftOptions.isEmpty())
return 0.0
return hueShiftOptions.random(random)
}
fun create(random: RandomGenerator, verticalMidPoint: Int, threatLevel: Double): Biome {
val hueShift = hueShift(random)
val data = CreationParams(hueShift = hueShift, random = random)
val surfacePlaceables = surfacePlaceables.create(data)
val undergroundPlaceables = undergroundPlaceables.create(data)
return Biome(
baseName = name,
description = description,
hueShift = hueShift,
mainBlock = mainBlock?.entry,
subBlocks = subBlocks?.stream()?.map { it.entry }?.filterNotNull()?.collect(ImmutableList.toImmutableList()) ?: ImmutableList.of(),
musicTrack = musicTrack,
ambientNoises = ambientNoises,
surfacePlaceables = surfacePlaceables,
undergroundPlaceables = undergroundPlaceables,
parallax = parallax?.value?.create(random, verticalMidPoint.toDouble(), hueShift, surfacePlaceables.firstTreeVariant()),
ores = (ores?.value?.evaluate(threatLevel, oresAdapter)?.map {
it.stream()
.filter { it.second > 0.0 }
.map { Registries.tileModifiers[it.first] to it.second }
.filter { it.first != null }
.collect(ImmutableList.toImmutableList())
}?.orElse(ImmutableList.of()) ?: ImmutableList.of()) as ImmutableList<Pair<Registry.Entry<MaterialModifier>, Double>>
)
}
companion object {
private val oresAdapter by lazy {
Starbound.gson.pairListAdapter<String, Double>()
}
}
}

View File

@ -1,4 +1,4 @@
package ru.dbotthepony.kstarbound.defs.world.terrain package ru.dbotthepony.kstarbound.defs.world
import com.google.common.collect.ImmutableList import com.google.common.collect.ImmutableList
import com.google.common.collect.ImmutableSet import com.google.common.collect.ImmutableSet
@ -20,15 +20,8 @@ import ru.dbotthepony.kstarbound.Registry
import ru.dbotthepony.kstarbound.Starbound import ru.dbotthepony.kstarbound.Starbound
import ru.dbotthepony.kstarbound.collect.WeightedList import ru.dbotthepony.kstarbound.collect.WeightedList
import ru.dbotthepony.kstarbound.defs.tile.MaterialModifier import ru.dbotthepony.kstarbound.defs.tile.MaterialModifier
import ru.dbotthepony.kstarbound.defs.tile.TileDefinition
import ru.dbotthepony.kstarbound.defs.world.AmbientNoisesDefinition
import ru.dbotthepony.kstarbound.defs.world.BushVariant
import ru.dbotthepony.kstarbound.defs.world.GrassVariant
import ru.dbotthepony.kstarbound.defs.world.Parallax
import ru.dbotthepony.kstarbound.defs.world.TreeVariant
import ru.dbotthepony.kstarbound.json.builder.JsonFactory import ru.dbotthepony.kstarbound.json.builder.JsonFactory
import ru.dbotthepony.kstarbound.json.builder.JsonFlat import ru.dbotthepony.kstarbound.json.builder.JsonFlat
import ru.dbotthepony.kstarbound.json.builder.JsonImplementation
import ru.dbotthepony.kstarbound.json.listAdapter import ru.dbotthepony.kstarbound.json.listAdapter
import ru.dbotthepony.kstarbound.util.random.AbstractPerlinNoise import ru.dbotthepony.kstarbound.util.random.AbstractPerlinNoise
import java.util.stream.Stream import java.util.stream.Stream
@ -109,7 +102,9 @@ data class BiomePlaceables(
// Truly our hero here. // Truly our hero here.
val obj = when (val type = `in`.nextString()) { val obj = when (val type = `in`.nextString()) {
"treasureBoxSet" -> TreasureBox(`in`.nextString()) "treasureBoxSet" -> TreasureBox(`in`.nextString())
"microDungeon" -> MicroDungeon(arrays.read(`in`).stream().map { it.asString }.collect(ImmutableSet.toImmutableSet())) "microDungeon" -> MicroDungeon(arrays.read(`in`).stream().map { it.asString }.collect(
ImmutableSet.toImmutableSet()
))
"grass" -> Grass(grassVariant.read(`in`)) "grass" -> Grass(grassVariant.read(`in`))
"bush" -> Bush(bushVariant.read(`in`)) "bush" -> Bush(bushVariant.read(`in`))
"tree" -> Tree(trees.read(`in`)) "tree" -> Tree(trees.read(`in`))
@ -171,7 +166,10 @@ data class BiomePlaceables(
get() = BiomePlacementItemType.TREE get() = BiomePlacementItemType.TREE
override fun toJson(): JsonElement { override fun toJson(): JsonElement {
return Starbound.gson.toJsonTree(trees, TypeToken.getParameterized(ImmutableList::class.java, TreeVariant::class.java).type) return Starbound.gson.toJsonTree(trees, TypeToken.getParameterized(
ImmutableList::class.java,
TreeVariant::class.java
).type)
} }
} }
@ -224,18 +222,4 @@ data class BiomePlaceables(
return weightedItems.stream().map { it.first } return weightedItems.stream().map { it.first }
} }
} }
} }
data class Biome(
val hueShift: Double = 0.0,
val baseName: String,
val description: String,
val mainBlock: Registry.Entry<TileDefinition>? = null,
val subBlocks: ImmutableList<Registry.Entry<TileDefinition>> = ImmutableList.of(),
val ores: ImmutableList<Pair<Registry.Entry<MaterialModifier>, Double>> = ImmutableList.of(),
val musicTrack: AmbientNoisesDefinition? = null,
val ambientNoises: AmbientNoisesDefinition? = null,
val surfacePlaceables: BiomePlaceables = BiomePlaceables(),
val undergroundPlaceables: BiomePlaceables = BiomePlaceables(),
val parallax: Parallax? = null,
)

View File

@ -1,81 +1,24 @@
package ru.dbotthepony.kstarbound.defs.world.terrain package ru.dbotthepony.kstarbound.defs.world
import com.google.common.collect.ImmutableList import com.google.common.collect.ImmutableList
import com.google.common.collect.ImmutableSet import com.google.common.collect.ImmutableSet
import com.google.gson.JsonElement import com.google.gson.JsonElement
import com.google.gson.JsonObject import com.google.gson.JsonObject
import com.google.gson.reflect.TypeToken
import com.google.gson.stream.JsonWriter
import ru.dbotthepony.kommons.collect.filterNotNull import ru.dbotthepony.kommons.collect.filterNotNull
import ru.dbotthepony.kommons.vector.Vector2i import ru.dbotthepony.kommons.vector.Vector2i
import ru.dbotthepony.kstarbound.Registries
import ru.dbotthepony.kstarbound.Registry import ru.dbotthepony.kstarbound.Registry
import ru.dbotthepony.kstarbound.Starbound
import ru.dbotthepony.kstarbound.collect.WeightedList import ru.dbotthepony.kstarbound.collect.WeightedList
import ru.dbotthepony.kstarbound.defs.AssetReference import ru.dbotthepony.kstarbound.defs.AssetReference
import ru.dbotthepony.kstarbound.defs.JsonConfigFunction
import ru.dbotthepony.kstarbound.defs.PerlinNoiseParameters import ru.dbotthepony.kstarbound.defs.PerlinNoiseParameters
import ru.dbotthepony.kstarbound.defs.tile.MaterialModifier import ru.dbotthepony.kstarbound.defs.tile.MaterialModifier
import ru.dbotthepony.kstarbound.defs.tile.TileDefinition
import ru.dbotthepony.kstarbound.defs.world.AmbientNoisesDefinition
import ru.dbotthepony.kstarbound.defs.world.BushVariant
import ru.dbotthepony.kstarbound.defs.world.GrassVariant
import ru.dbotthepony.kstarbound.defs.world.Parallax
import ru.dbotthepony.kstarbound.defs.world.SkyColoring
import ru.dbotthepony.kstarbound.defs.world.TreeVariant
import ru.dbotthepony.kstarbound.json.builder.DispatchingAdapter
import ru.dbotthepony.kstarbound.json.builder.IStringSerializable
import ru.dbotthepony.kstarbound.json.builder.JsonFactory import ru.dbotthepony.kstarbound.json.builder.JsonFactory
import ru.dbotthepony.kstarbound.json.builder.JsonFlat import ru.dbotthepony.kstarbound.json.builder.JsonFlat
import ru.dbotthepony.kstarbound.json.builder.JsonSingleton import ru.dbotthepony.kstarbound.json.builder.JsonSingleton
import ru.dbotthepony.kstarbound.json.pairListAdapter
import ru.dbotthepony.kstarbound.util.random.AbstractPerlinNoise import ru.dbotthepony.kstarbound.util.random.AbstractPerlinNoise
import ru.dbotthepony.kstarbound.util.random.nextRange import ru.dbotthepony.kstarbound.util.random.nextRange
import ru.dbotthepony.kstarbound.util.random.random import ru.dbotthepony.kstarbound.util.random.random
import java.util.random.RandomGenerator
import java.util.stream.IntStream import java.util.stream.IntStream
enum class BiomePlacementDistributionType(
override val jsonName: String,
val def: TypeToken<out BiomePlaceablesDefinition.DistributionData>,
val data: TypeToken<out BiomePlaceables.DistributionData>,
) : IStringSerializable {
RANDOM("random", TypeToken.get(BiomePlaceablesDefinition.RandomDistribution::class.java), TypeToken.get(BiomePlaceables.RandomDistribution::class.java)),
PERIODIC("periodic", TypeToken.get(BiomePlaceablesDefinition.PeriodicDistribution::class.java), TypeToken.get(BiomePlaceables.PeriodicDistribution::class.java));
override fun match(name: String): Boolean {
return name.lowercase() == jsonName
}
companion object {
val DEFINITION_ADAPTER = DispatchingAdapter("type", { type }, { def }, entries)
val DATA_ADAPTER = DispatchingAdapter("type", { type }, { data }, entries)
}
}
enum class BiomePlacementItemType(
override val jsonName: String,
val def: TypeToken<out BiomePlaceablesDefinition.DistributionItemData>,
val data: TypeToken<out BiomePlaceables.Item>,
) : IStringSerializable {
MICRO_DUNGEON("microdungeon", TypeToken.get(BiomePlaceablesDefinition.MicroDungeon::class.java), TypeToken.get(BiomePlaceables.MicroDungeon::class.java)),
TREASURE_BOX_SET("treasurebox", TypeToken.get(BiomePlaceablesDefinition.TreasureBox::class.java), TypeToken.get(BiomePlaceables.TreasureBox::class.java)),
GRASS("grass", TypeToken.get(BiomePlaceablesDefinition.Grass::class.java), TypeToken.get(BiomePlaceables.Grass::class.java)),
BUSH("bush", TypeToken.get(BiomePlaceablesDefinition.Bush::class.java), TypeToken.get(BiomePlaceables.Bush::class.java)),
TREE("tree", TypeToken.get(BiomePlaceablesDefinition.Tree::class.java), TypeToken.get(BiomePlaceables.Tree::class.java)),
OBJECT("object", TypeToken.get(BiomePlaceablesDefinition.Object::class.java), TypeToken.get(BiomePlaceables.Object::class.java)),
;
override fun match(name: String): Boolean {
return name.lowercase() == jsonName
}
companion object {
val DEFINITION_ADAPTER = DispatchingAdapter("type", { type }, { def }, entries)
val DATA_ADAPTER = DispatchingAdapter("type", { type }, { data }, entries)
}
}
@JsonFactory @JsonFactory
data class BiomePlaceablesDefinition( data class BiomePlaceablesDefinition(
val grassMod: ImmutableList<Registry.Ref<MaterialModifier>> = ImmutableList.of(), val grassMod: ImmutableList<Registry.Ref<MaterialModifier>> = ImmutableList.of(),
@ -149,7 +92,7 @@ data class BiomePlaceablesDefinition(
throw NoSuchElementException("None of grass variants are valid (candidates: $grasses)") throw NoSuchElementException("None of grass variants are valid (candidates: $grasses)")
} }
return BiomePlaceables.Grass(GrassVariant.create(valid.random(biome.random), biome.hueShift)) return BiomePlaceables.Grass(GrassVariant.Companion.create(valid.random(biome.random), biome.hueShift))
} }
} }
@ -211,14 +154,32 @@ data class BiomePlaceablesDefinition(
if (foliage == null) { if (foliage == null) {
for (i2 in 0 until subTreeVariants) { for (i2 in 0 until subTreeVariants) {
trees.add(TreeVariant.create(stem, if (sameStemHueShift) treeStemHueShift else treeStemHueShiftMax * biome.random.nextDouble(-1.0, 1.0))) trees.add(
TreeVariant.create(
stem,
if (sameStemHueShift) treeStemHueShift else treeStemHueShiftMax * biome.random.nextDouble(
-1.0,
1.0
)
)
)
} }
} else { } else {
for (i2 in 0 until subTreeVariants) { for (i2 in 0 until subTreeVariants) {
trees.add(TreeVariant.create( trees.add(
stem, if (sameStemHueShift) treeStemHueShift else treeStemHueShiftMax * biome.random.nextDouble(-1.0, 1.0), TreeVariant.create(
foliage, if (sameFoliageHueShift) treeFoliageHueShift else treeFoliageHueShiftMax * biome.random.nextDouble(-1.0, 1.0) stem,
)) if (sameStemHueShift) treeStemHueShift else treeStemHueShiftMax * biome.random.nextDouble(
-1.0,
1.0
),
foliage,
if (sameFoliageHueShift) treeFoliageHueShift else treeFoliageHueShiftMax * biome.random.nextDouble(
-1.0,
1.0
)
)
)
} }
} }
} }
@ -250,7 +211,14 @@ data class BiomePlaceablesDefinition(
val data = name.entry!!.value val data = name.entry!!.value
val mod = if (data.mods.isNotEmpty()) data.mods.random(biome.random) else "" val mod = if (data.mods.isNotEmpty()) data.mods.random(biome.random) else ""
return BiomePlaceables.Bush(BushVariant.create(name.entry!!, biome.random.nextDouble(-1.0, 1.0) * baseHueShiftMax, mod, biome.random.nextDouble(-1.0 * 1.0) * modHueShiftMax)) return BiomePlaceables.Bush(
BushVariant.create(
name.entry!!,
biome.random.nextDouble(-1.0, 1.0) * baseHueShiftMax,
mod,
biome.random.nextDouble(-1.0 * 1.0) * modHueShiftMax
)
)
} }
} }
@ -268,7 +236,12 @@ data class BiomePlaceablesDefinition(
} }
val rand = objectSets.random(biome.random) val rand = objectSets.random(biome.random)
return BiomePlaceables.Object(WeightedList(rand.pool.stream().map { it.first to (it.second to rand.parameters) }.collect(ImmutableList.toImmutableList()))) return BiomePlaceables.Object(
WeightedList(
rand.pool.stream().map { it.first to (it.second to rand.parameters) }
.collect(ImmutableList.toImmutableList())
)
)
} }
} }
@ -354,20 +327,22 @@ data class BiomePlaceablesDefinition(
weightedItems = IntStream.range(0, self.variants) weightedItems = IntStream.range(0, self.variants)
.mapToObj { self.data.create(biome) } .mapToObj { self.data.create(biome) }
.map { it to AbstractPerlinNoise.of( .map {
PerlinNoiseParameters( it to AbstractPerlinNoise.of(
type = noiseType, PerlinNoiseParameters(
scale = noiseScale, type = noiseType,
octaves = octaves, scale = noiseScale,
alpha = alpha, octaves = octaves,
beta = beta, alpha = alpha,
beta = beta,
frequency = 1.0 / typePeriod, frequency = 1.0 / typePeriod,
amplitude = 1.0, amplitude = 1.0,
bias = 0.0, bias = 0.0,
seed = biome.random.nextLong(), seed = biome.random.nextLong(),
)
) )
) } }
.collect(ImmutableList.toImmutableList()) .collect(ImmutableList.toImmutableList())
) )
} }
@ -384,79 +359,4 @@ data class BiomePlaceablesDefinition(
.collect(ImmutableList.toImmutableList()) .collect(ImmutableList.toImmutableList())
) )
} }
} }
@JsonFactory
data class BiomeDefinition(
val airless: Boolean = false,
val name: String,
val statusEffects: ImmutableSet<String> = ImmutableSet.of(),
val weather: ImmutableList<Pair<Double, ImmutableList<AssetReference<WeightedList<String>>>>> = ImmutableList.of(), // binned reference to other assets
val hueShiftOptions: ImmutableList<Double> = ImmutableList.of(),
val skyOptions: ImmutableList<SkyColoring> = ImmutableList.of(),
val description: String = "...",
val mainBlock: Registry.Ref<TileDefinition>? = null,
val subBlocks: ImmutableList<Registry.Ref<TileDefinition>>? = null,
val ores: Registry.Ref<JsonConfigFunction>? = null,
val musicTrack: AmbientNoisesDefinition? = null,
val ambientNoises: AmbientNoisesDefinition? = null,
val surfacePlaceables: BiomePlaceablesDefinition = BiomePlaceablesDefinition(),
val undergroundPlaceables: BiomePlaceablesDefinition = BiomePlaceablesDefinition(),
val parallax: AssetReference<Parallax.Data>? = null,
) {
data class CreationParams(
val hueShift: Double,
val random: RandomGenerator
)
fun skyColoring(random: RandomGenerator): SkyColoring {
if (skyOptions.isEmpty())
return SkyColoring.BLACK
return skyOptions.random(random)
}
fun hueShift(random: RandomGenerator): Double {
if (hueShiftOptions.isEmpty())
return 0.0
return hueShiftOptions.random(random)
}
fun create(random: RandomGenerator, verticalMidPoint: Int, threatLevel: Double): Biome {
val hueShift = hueShift(random)
val data = CreationParams(hueShift = hueShift, random = random)
val surfacePlaceables = surfacePlaceables.create(data)
val undergroundPlaceables = undergroundPlaceables.create(data)
return Biome(
baseName = name,
description = description,
hueShift = hueShift,
mainBlock = mainBlock?.entry,
subBlocks = subBlocks?.stream()?.map { it.entry }?.filterNotNull()?.collect(ImmutableList.toImmutableList()) ?: ImmutableList.of(),
musicTrack = musicTrack,
ambientNoises = ambientNoises,
surfacePlaceables = surfacePlaceables,
undergroundPlaceables = undergroundPlaceables,
parallax = parallax?.value?.create(random, verticalMidPoint.toDouble(), hueShift, surfacePlaceables.firstTreeVariant()),
ores = (ores?.value?.evaluate(threatLevel, oresAdapter)?.map {
it.stream()
.filter { it.second > 0.0 }
.map { Registries.tileModifiers[it.first] to it.second }
.filter { it.first != null }
.collect(ImmutableList.toImmutableList())
}?.orElse(ImmutableList.of()) ?: ImmutableList.of()) as ImmutableList<Pair<Registry.Entry<MaterialModifier>, Double>>
)
}
companion object {
private val oresAdapter by lazy {
Starbound.gson.pairListAdapter<String, Double>()
}
}
}

View File

@ -0,0 +1,29 @@
package ru.dbotthepony.kstarbound.defs.world
import com.google.gson.reflect.TypeToken
import ru.dbotthepony.kstarbound.json.builder.DispatchingAdapter
import ru.dbotthepony.kstarbound.json.builder.IStringSerializable
enum class BiomePlacementDistributionType(
override val jsonName: String,
val def: TypeToken<out BiomePlaceablesDefinition.DistributionData>,
val data: TypeToken<out BiomePlaceables.DistributionData>,
) : IStringSerializable {
RANDOM("random",
TypeToken.get(BiomePlaceablesDefinition.RandomDistribution::class.java),
TypeToken.get(BiomePlaceables.RandomDistribution::class.java)
),
PERIODIC("periodic",
TypeToken.get(BiomePlaceablesDefinition.PeriodicDistribution::class.java),
TypeToken.get(BiomePlaceables.PeriodicDistribution::class.java)
);
override fun match(name: String): Boolean {
return name.lowercase() == jsonName
}
companion object {
val DEFINITION_ADAPTER = DispatchingAdapter("type", { type }, { def }, entries)
val DATA_ADAPTER = DispatchingAdapter("type", { type }, { data }, entries)
}
}

View File

@ -0,0 +1,46 @@
package ru.dbotthepony.kstarbound.defs.world
import com.google.gson.reflect.TypeToken
import ru.dbotthepony.kstarbound.json.builder.DispatchingAdapter
import ru.dbotthepony.kstarbound.json.builder.IStringSerializable
enum class BiomePlacementItemType(
override val jsonName: String,
val def: TypeToken<out BiomePlaceablesDefinition.DistributionItemData>,
val data: TypeToken<out BiomePlaceables.Item>,
) : IStringSerializable {
MICRO_DUNGEON("microdungeon",
TypeToken.get(BiomePlaceablesDefinition.MicroDungeon::class.java),
TypeToken.get(BiomePlaceables.MicroDungeon::class.java)
),
TREASURE_BOX_SET("treasurebox",
TypeToken.get(BiomePlaceablesDefinition.TreasureBox::class.java),
TypeToken.get(BiomePlaceables.TreasureBox::class.java)
),
GRASS("grass",
TypeToken.get(BiomePlaceablesDefinition.Grass::class.java),
TypeToken.get(BiomePlaceables.Grass::class.java)
),
BUSH("bush",
TypeToken.get(BiomePlaceablesDefinition.Bush::class.java),
TypeToken.get(BiomePlaceables.Bush::class.java)
),
TREE("tree",
TypeToken.get(BiomePlaceablesDefinition.Tree::class.java),
TypeToken.get(BiomePlaceables.Tree::class.java)
),
OBJECT("object",
TypeToken.get(BiomePlaceablesDefinition.Object::class.java),
TypeToken.get(BiomePlaceables.Object::class.java)
),
;
override fun match(name: String): Boolean {
return name.lowercase() == jsonName
}
companion object {
val DEFINITION_ADAPTER = DispatchingAdapter("type", { type }, { def }, entries)
val DATA_ADAPTER = DispatchingAdapter("type", { type }, { data }, entries)
}
}

View File

@ -9,9 +9,6 @@ import it.unimi.dsi.fastutil.doubles.DoubleArrayList
import it.unimi.dsi.fastutil.ints.IntArrayList import it.unimi.dsi.fastutil.ints.IntArrayList
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet
import ru.dbotthepony.kommons.gson.JsonArrayCollector import ru.dbotthepony.kommons.gson.JsonArrayCollector
import ru.dbotthepony.kommons.gson.contains
import ru.dbotthepony.kommons.gson.get
import ru.dbotthepony.kommons.gson.getArray
import ru.dbotthepony.kommons.gson.set import ru.dbotthepony.kommons.gson.set
import ru.dbotthepony.kommons.math.RGBAColor import ru.dbotthepony.kommons.math.RGBAColor
import ru.dbotthepony.kommons.util.AABBi import ru.dbotthepony.kommons.util.AABBi
@ -22,10 +19,8 @@ import ru.dbotthepony.kstarbound.GlobalDefaults
import ru.dbotthepony.kstarbound.Registries import ru.dbotthepony.kstarbound.Registries
import ru.dbotthepony.kstarbound.Starbound import ru.dbotthepony.kstarbound.Starbound
import ru.dbotthepony.kstarbound.defs.world.terrain.AbstractTerrainSelector import ru.dbotthepony.kstarbound.defs.world.terrain.AbstractTerrainSelector
import ru.dbotthepony.kstarbound.defs.world.terrain.Biome
import ru.dbotthepony.kstarbound.defs.world.terrain.TerrainSelectorParameters import ru.dbotthepony.kstarbound.defs.world.terrain.TerrainSelectorParameters
import ru.dbotthepony.kstarbound.defs.world.terrain.createNamedTerrainSelector import ru.dbotthepony.kstarbound.defs.world.terrain.createNamedTerrainSelector
import ru.dbotthepony.kstarbound.fromJson
import ru.dbotthepony.kstarbound.json.builder.JsonFactory import ru.dbotthepony.kstarbound.json.builder.JsonFactory
import ru.dbotthepony.kstarbound.util.ListInterner import ru.dbotthepony.kstarbound.util.ListInterner
import ru.dbotthepony.kstarbound.util.random.AbstractPerlinNoise import ru.dbotthepony.kstarbound.util.random.AbstractPerlinNoise