Update black hole placement code
This commit is contained in:
parent
89aa300b9b
commit
9820505c0d
@ -1,7 +1,6 @@
|
|||||||
package ru.dbotthepony.mc.otm.datagen
|
package ru.dbotthepony.mc.otm.datagen
|
||||||
|
|
||||||
import net.minecraft.core.HolderSet
|
import net.minecraft.core.HolderSet
|
||||||
import net.minecraft.core.RegistrySetBuilder
|
|
||||||
import net.minecraft.core.registries.Registries
|
import net.minecraft.core.registries.Registries
|
||||||
import net.minecraft.data.worldgen.BootstrapContext
|
import net.minecraft.data.worldgen.BootstrapContext
|
||||||
import net.minecraft.resources.ResourceKey
|
import net.minecraft.resources.ResourceKey
|
||||||
@ -22,7 +21,7 @@ import net.neoforged.neoforge.registries.NeoForgeRegistries
|
|||||||
import ru.dbotthepony.mc.otm.core.math.Decimal
|
import ru.dbotthepony.mc.otm.core.math.Decimal
|
||||||
import ru.dbotthepony.mc.otm.registry.MBlocks
|
import ru.dbotthepony.mc.otm.registry.MBlocks
|
||||||
import ru.dbotthepony.mc.otm.registry.MWorldGenFeatures
|
import ru.dbotthepony.mc.otm.registry.MWorldGenFeatures
|
||||||
import ru.dbotthepony.mc.otm.worldgen.feature.BlackHolePlacerConfiguration
|
import ru.dbotthepony.mc.otm.worldgen.feature.BlackHolePlacerFeature
|
||||||
|
|
||||||
private object ConfiguredFeatures {
|
private object ConfiguredFeatures {
|
||||||
val TRITANIUM_ORE = key("tritanium_ore")
|
val TRITANIUM_ORE = key("tritanium_ore")
|
||||||
@ -44,7 +43,7 @@ fun registerConfiguredFeatures(context: BootstrapContext<ConfiguredFeature<*, *>
|
|||||||
|
|
||||||
context.register(ConfiguredFeatures.TRITANIUM_ORE, ConfiguredFeature(Feature.ORE, OreConfiguration(target, 9)))
|
context.register(ConfiguredFeatures.TRITANIUM_ORE, ConfiguredFeature(Feature.ORE, OreConfiguration(target, 9)))
|
||||||
context.register(ConfiguredFeatures.BLACK_HOLE, ConfiguredFeature(MWorldGenFeatures.BLACK_HOLE_PLACER,
|
context.register(ConfiguredFeatures.BLACK_HOLE, ConfiguredFeature(MWorldGenFeatures.BLACK_HOLE_PLACER,
|
||||||
BlackHolePlacerConfiguration(0.001f, Decimal(125_000), Decimal(500_000))))
|
BlackHolePlacerFeature.Config(0.001f, Decimal("0.25"), Decimal(1))))
|
||||||
}
|
}
|
||||||
|
|
||||||
private object PlacedFeatures {
|
private object PlacedFeatures {
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
package ru.dbotthepony.mc.otm.registry
|
package ru.dbotthepony.mc.otm.registry
|
||||||
|
|
||||||
import net.minecraft.core.registries.BuiltInRegistries
|
import net.minecraft.core.registries.BuiltInRegistries
|
||||||
import net.minecraft.world.level.levelgen.feature.Feature
|
|
||||||
import net.neoforged.bus.api.IEventBus
|
import net.neoforged.bus.api.IEventBus
|
||||||
import ru.dbotthepony.mc.otm.worldgen.feature.BlackHolePlacerConfiguration
|
|
||||||
import ru.dbotthepony.mc.otm.worldgen.feature.BlackHolePlacerFeature
|
import ru.dbotthepony.mc.otm.worldgen.feature.BlackHolePlacerFeature
|
||||||
|
|
||||||
object MWorldGenFeatures {
|
object MWorldGenFeatures {
|
||||||
@ -13,7 +11,5 @@ object MWorldGenFeatures {
|
|||||||
registry.register(bus)
|
registry.register(bus)
|
||||||
}
|
}
|
||||||
|
|
||||||
val BLACK_HOLE_PLACER: Feature<BlackHolePlacerConfiguration> by registry.register("black_hole_placer") {
|
val BLACK_HOLE_PLACER by registry.register("black_hole_placer") { BlackHolePlacerFeature }
|
||||||
BlackHolePlacerFeature(BlackHolePlacerConfiguration.CODEC)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -6,38 +6,36 @@ import net.minecraft.world.level.levelgen.feature.Feature
|
|||||||
import net.minecraft.world.level.levelgen.feature.FeaturePlaceContext
|
import net.minecraft.world.level.levelgen.feature.FeaturePlaceContext
|
||||||
import net.minecraft.world.level.levelgen.feature.configurations.FeatureConfiguration
|
import net.minecraft.world.level.levelgen.feature.configurations.FeatureConfiguration
|
||||||
import ru.dbotthepony.mc.otm.block.entity.blackhole.BlackHoleBlockEntity
|
import ru.dbotthepony.mc.otm.block.entity.blackhole.BlackHoleBlockEntity
|
||||||
|
import ru.dbotthepony.mc.otm.config.ServerConfig
|
||||||
import ru.dbotthepony.mc.otm.core.math.Decimal
|
import ru.dbotthepony.mc.otm.core.math.Decimal
|
||||||
import ru.dbotthepony.mc.otm.core.math.nextDecimal
|
import ru.dbotthepony.mc.otm.core.math.nextDecimal
|
||||||
import ru.dbotthepony.mc.otm.data.DecimalCodec
|
import ru.dbotthepony.mc.otm.data.DecimalCodec
|
||||||
import ru.dbotthepony.mc.otm.registry.MBlocks
|
import ru.dbotthepony.mc.otm.registry.MBlocks
|
||||||
|
|
||||||
class BlackHolePlacerConfiguration(val chance: Float, val minMatter: Decimal, val maxMatter: Decimal) : FeatureConfiguration {
|
object BlackHolePlacerFeature : Feature<BlackHolePlacerFeature.Config>(
|
||||||
companion object {
|
RecordCodecBuilder.create {
|
||||||
val CODEC: Codec<BlackHolePlacerConfiguration> = RecordCodecBuilder.create {
|
it.group(
|
||||||
t -> t.group(
|
Codec.floatRange(0.0F, 1.0F).fieldOf("chance").forGetter(Config::chance),
|
||||||
Codec.floatRange(0.0F, 1.0F).fieldOf("chance").forGetter(BlackHolePlacerConfiguration::chance),
|
DecimalCodec.fieldOf("matter_min").forGetter(Config::minMatter),
|
||||||
DecimalCodec.fieldOf("matter_min").forGetter(BlackHolePlacerConfiguration::minMatter),
|
DecimalCodec.fieldOf("matter_max").forGetter(Config::maxMatter)
|
||||||
DecimalCodec.fieldOf("matter_max").forGetter(BlackHolePlacerConfiguration::maxMatter)
|
).apply(it, ::Config)
|
||||||
).apply(t, ::BlackHolePlacerConfiguration)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
) {
|
||||||
|
data class Config(val chance: Float, val minMatter: Decimal, val maxMatter: Decimal) : FeatureConfiguration
|
||||||
|
|
||||||
class BlackHolePlacerFeature(val codec: Codec<BlackHolePlacerConfiguration>) : Feature<BlackHolePlacerConfiguration>(codec) {
|
override fun place(context: FeaturePlaceContext<Config>): Boolean {
|
||||||
override fun place(context: FeaturePlaceContext<BlackHolePlacerConfiguration?>): Boolean {
|
|
||||||
val random = context.random()
|
val random = context.random()
|
||||||
val level = context.level()
|
val level = context.level()
|
||||||
val pos = context.origin()
|
val pos = context.origin()
|
||||||
|
|
||||||
val config = context.config()
|
val config = context.config()
|
||||||
if (config == null) return false
|
|
||||||
|
|
||||||
if (level.getBlockState(pos).isAir && random.nextDouble() < config.chance.toDouble()) {
|
if (level.getBlockState(pos).isAir && random.nextDouble() < config.chance.toDouble()) {
|
||||||
if (level.setBlock(pos, MBlocks.BLACK_HOLE.defaultBlockState(), 2)) {
|
if (level.setBlock(pos, MBlocks.BLACK_HOLE.defaultBlockState(), 2)) {
|
||||||
val entity = level.getBlockEntity(pos)
|
val entity = level.getBlockEntity(pos)
|
||||||
|
|
||||||
if (entity is BlackHoleBlockEntity) {
|
if (entity is BlackHoleBlockEntity) {
|
||||||
entity.mass = random.nextDecimal(config.minMatter, config.maxMatter)
|
entity.mass = random.nextDecimal(config.minMatter, config.maxMatter) * ServerConfig.Blackhole.BASELINE_MASS
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
Loading…
Reference in New Issue
Block a user