From 9820505c0d3c7100122db93cdceb66a4dc42937b Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Fri, 15 Nov 2024 16:56:33 +0700 Subject: [PATCH] Update black hole placement code --- .../ru/dbotthepony/mc/otm/datagen/WorldGen.kt | 5 ++-- .../mc/otm/registry/MWorldGenFeatures.kt | 6 +---- .../otm/worldgen/feature/BlackHolePlacer.kt | 26 +++++++++---------- 3 files changed, 15 insertions(+), 22 deletions(-) diff --git a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/WorldGen.kt b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/WorldGen.kt index 4bb408e4a..09e1328a8 100644 --- a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/WorldGen.kt +++ b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/WorldGen.kt @@ -1,7 +1,6 @@ package ru.dbotthepony.mc.otm.datagen import net.minecraft.core.HolderSet -import net.minecraft.core.RegistrySetBuilder import net.minecraft.core.registries.Registries import net.minecraft.data.worldgen.BootstrapContext 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.registry.MBlocks 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 { val TRITANIUM_ORE = key("tritanium_ore") @@ -44,7 +43,7 @@ fun registerConfiguredFeatures(context: BootstrapContext context.register(ConfiguredFeatures.TRITANIUM_ORE, ConfiguredFeature(Feature.ORE, OreConfiguration(target, 9))) 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 { diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/registry/MWorldGenFeatures.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/registry/MWorldGenFeatures.kt index e6d47f33d..d771e032e 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/registry/MWorldGenFeatures.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/registry/MWorldGenFeatures.kt @@ -1,9 +1,7 @@ package ru.dbotthepony.mc.otm.registry import net.minecraft.core.registries.BuiltInRegistries -import net.minecraft.world.level.levelgen.feature.Feature import net.neoforged.bus.api.IEventBus -import ru.dbotthepony.mc.otm.worldgen.feature.BlackHolePlacerConfiguration import ru.dbotthepony.mc.otm.worldgen.feature.BlackHolePlacerFeature object MWorldGenFeatures { @@ -13,7 +11,5 @@ object MWorldGenFeatures { registry.register(bus) } - val BLACK_HOLE_PLACER: Feature by registry.register("black_hole_placer") { - BlackHolePlacerFeature(BlackHolePlacerConfiguration.CODEC) - } + val BLACK_HOLE_PLACER by registry.register("black_hole_placer") { BlackHolePlacerFeature } } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/worldgen/feature/BlackHolePlacer.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/worldgen/feature/BlackHolePlacer.kt index 099ecf94a..ae74b6f1f 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/worldgen/feature/BlackHolePlacer.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/worldgen/feature/BlackHolePlacer.kt @@ -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.configurations.FeatureConfiguration 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.nextDecimal import ru.dbotthepony.mc.otm.data.DecimalCodec import ru.dbotthepony.mc.otm.registry.MBlocks -class BlackHolePlacerConfiguration(val chance: Float, val minMatter: Decimal, val maxMatter: Decimal) : FeatureConfiguration { - companion object { - val CODEC: Codec = RecordCodecBuilder.create { - t -> t.group( - Codec.floatRange(0.0F, 1.0F).fieldOf("chance").forGetter(BlackHolePlacerConfiguration::chance), - DecimalCodec.fieldOf("matter_min").forGetter(BlackHolePlacerConfiguration::minMatter), - DecimalCodec.fieldOf("matter_max").forGetter(BlackHolePlacerConfiguration::maxMatter) - ).apply(t, ::BlackHolePlacerConfiguration) - } +object BlackHolePlacerFeature : Feature( + RecordCodecBuilder.create { + it.group( + Codec.floatRange(0.0F, 1.0F).fieldOf("chance").forGetter(Config::chance), + DecimalCodec.fieldOf("matter_min").forGetter(Config::minMatter), + DecimalCodec.fieldOf("matter_max").forGetter(Config::maxMatter) + ).apply(it, ::Config) } -} +) { + data class Config(val chance: Float, val minMatter: Decimal, val maxMatter: Decimal) : FeatureConfiguration -class BlackHolePlacerFeature(val codec: Codec) : Feature(codec) { - override fun place(context: FeaturePlaceContext): Boolean { + override fun place(context: FeaturePlaceContext): Boolean { val random = context.random() val level = context.level() val pos = context.origin() val config = context.config() - if (config == null) return false if (level.getBlockState(pos).isAir && random.nextDouble() < config.chance.toDouble()) { if (level.setBlock(pos, MBlocks.BLACK_HOLE.defaultBlockState(), 2)) { val entity = level.getBlockEntity(pos) 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