From 6713adcfe96eacefde7e0c379dcfe47b2b7c3ac1 Mon Sep 17 00:00:00 2001 From: YuRaNnNzZZ Date: Thu, 14 Nov 2024 08:25:50 +0300 Subject: [PATCH 1/2] =?UTF-8?q?=D0=93=D0=95=D0=9D=D0=95=D0=A0=D0=90=D0=A6?= =?UTF-8?q?=D0=98=D0=AF=20=D0=A7=D0=81=D0=A0=D0=9D=D0=AB=D0=A5=20=D0=94?= =?UTF-8?q?=D0=AB=D0=A0=20=D0=9F=D0=9E=D0=AF=D0=92=D0=98=D0=9B=D0=90=D0=A1?= =?UTF-8?q?=D0=AC=20=D0=A0=D0=90=D0=9D=D0=AC=D0=A8=D0=95=20=D0=A7=D0=95?= =?UTF-8?q?=D0=9C=20=D0=9C=D0=90=D0=9D=D0=93=D0=90=D0=9B=20=D0=94=D0=98?= =?UTF-8?q?=D0=9F=D0=9B=D0=9E=D0=9C=D0=90=D0=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit // TODO: ЭТО НЕ РУДА // TODO: твикнуть значения (очевидно) --- .../ru/dbotthepony/mc/otm/datagen/OreGen.kt | 38 ++++++++++++++ .../mc/otm/OverdriveThatMatters.java | 1 + .../mc/otm/registry/MWorldGenFeatures.kt | 19 +++++++ .../otm/worldgen/feature/BlackHolePlacer.kt | 49 +++++++++++++++++++ 4 files changed, 107 insertions(+) create mode 100644 src/main/kotlin/ru/dbotthepony/mc/otm/registry/MWorldGenFeatures.kt create mode 100644 src/main/kotlin/ru/dbotthepony/mc/otm/worldgen/feature/BlackHolePlacer.kt diff --git a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/OreGen.kt b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/OreGen.kt index 42c075079..8d3b4e32d 100644 --- a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/OreGen.kt +++ b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/OreGen.kt @@ -19,11 +19,17 @@ import net.minecraft.world.level.levelgen.placement.PlacedFeature import net.minecraft.world.level.levelgen.structure.templatesystem.TagMatchTest import net.neoforged.neoforge.common.world.BiomeModifier 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 private object ConfiguredFeatures { val TRITANIUM_ORE = key("tritanium_ore") + // TODO: ЭТО НЕ РУДА + val BLACK_HOLE = key("black_hole") + private fun key(name: String): ResourceKey> { return ResourceKey.create(Registries.CONFIGURED_FEATURE, modLocation(name)) } @@ -39,12 +45,19 @@ fun registerConfiguredFeatures(context: BootstrapContext ) context.register(ConfiguredFeatures.TRITANIUM_ORE, ConfiguredFeature(Feature.ORE, OreConfiguration(target, 9))) + + // TODO: ЭТО НЕ РУДА + context.register(ConfiguredFeatures.BLACK_HOLE, ConfiguredFeature(MWorldGenFeatures.BLACK_HOLE_PLACER, + BlackHolePlacerConfiguration(0.005f, Decimal(2048), Decimal(2048 + 8192)))) } private object PlacedFeatures { val NORMAL_TRITANIUM = key("normal_tritanium") val DEEP_TRITANIUM = key("deep_tritanium") + // TODO: ЭТО НЕ РУДА + val BLACK_HOLE = key("black_hole") + private fun key(name: String): ResourceKey { return ResourceKey.create(Registries.PLACED_FEATURE, modLocation(name)) } @@ -71,11 +84,24 @@ fun registerPlacedFeatures(context: BootstrapContext) { HeightRangePlacement.uniform(VerticalAnchor.aboveBottom(8), VerticalAnchor.absolute(0)) ) )) + + // TODO: ЭТО НЕ РУДА + val blackHole = configured.getOrThrow(ConfiguredFeatures.BLACK_HOLE) + context.register(PlacedFeatures.BLACK_HOLE, PlacedFeature( + blackHole, + listOf( + CountPlacement.of(1), + HeightRangePlacement.uniform(VerticalAnchor.absolute(64), VerticalAnchor.absolute(128)) + ) + )) } private object BiomeModifiers { val TRITANIUM_ORE = key("tritanium_ore") + // TODO: ЭТО НЕ РУДА + val BLACK_HOLE = key("black_hole") + private fun key(name: String): ResourceKey { return ResourceKey.create(NeoForgeRegistries.Keys.BIOME_MODIFIERS, modLocation(name)) } @@ -96,4 +122,16 @@ fun registerBiomeModifiers(context: BootstrapContext) { GenerationStep.Decoration.UNDERGROUND_ORES ) ) + + // TODO: ЭТО НЕ РУДА + context.register( + BiomeModifiers.BLACK_HOLE, + net.neoforged.neoforge.common.world.BiomeModifiers.AddFeaturesBiomeModifier( + biomes.getOrThrow(BiomeTags.IS_OVERWORLD), + HolderSet.direct( + placed.getOrThrow(PlacedFeatures.BLACK_HOLE) + ), + GenerationStep.Decoration.SURFACE_STRUCTURES + ) + ) } diff --git a/src/main/java/ru/dbotthepony/mc/otm/OverdriveThatMatters.java b/src/main/java/ru/dbotthepony/mc/otm/OverdriveThatMatters.java index 87ac9a543..c4707e8c6 100644 --- a/src/main/java/ru/dbotthepony/mc/otm/OverdriveThatMatters.java +++ b/src/main/java/ru/dbotthepony/mc/otm/OverdriveThatMatters.java @@ -127,6 +127,7 @@ public final class OverdriveThatMatters { MArmorMaterials.INSTANCE.register(bus); MCriteriaTriggers.INSTANCE.register(bus); MStats.INSTANCE.register(bus); + MWorldGenFeatures.INSTANCE.register(bus); CommandArgumentTypes.INSTANCE.register(bus); StorageStack.Companion.register(bus); diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/registry/MWorldGenFeatures.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/registry/MWorldGenFeatures.kt new file mode 100644 index 000000000..e6d47f33d --- /dev/null +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/registry/MWorldGenFeatures.kt @@ -0,0 +1,19 @@ +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 { + private val registry = MDeferredRegister(BuiltInRegistries.FEATURE) + + fun register(bus: IEventBus) { + registry.register(bus) + } + + val BLACK_HOLE_PLACER: Feature by registry.register("black_hole_placer") { + BlackHolePlacerFeature(BlackHolePlacerConfiguration.CODEC) + } +} 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 new file mode 100644 index 000000000..099ecf94a --- /dev/null +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/worldgen/feature/BlackHolePlacer.kt @@ -0,0 +1,49 @@ +package ru.dbotthepony.mc.otm.worldgen.feature + +import com.mojang.serialization.Codec +import com.mojang.serialization.codecs.RecordCodecBuilder +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.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) + } + } +} + +class BlackHolePlacerFeature(val codec: Codec) : Feature(codec) { + 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) + } + + return true + } + } + + return false + } +} From 0d250dea2f9c810dd48fd8feac24b6d851db8c6f Mon Sep 17 00:00:00 2001 From: YuRaNnNzZZ Date: Thu, 14 Nov 2024 21:46:19 +0300 Subject: [PATCH 2/2] =?UTF-8?q?=D1=8D=D1=82=D0=BE=20=D0=BD=D0=B5=20=D1=80?= =?UTF-8?q?=D1=83=D0=B4=D0=B0,=20=D1=8D=D1=82=D0=BE=20=D0=B2=D0=BE=D1=80?= =?UTF-8?q?=D0=BB=D0=B4=D0=B3=D0=B5=D0=BD.=20=D0=BF=D0=BE=D1=82=D0=B2?= =?UTF-8?q?=D0=B8=D0=BA=D0=B0=D0=BB=20=D0=B7=D0=BD=D0=B0=D1=87=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D1=8F=20(=D0=BD=D0=BE=20=D1=88=D0=B0=D0=BD=D1=81=20?= =?UTF-8?q?=D0=BD=D0=B0=D0=B2=D0=B5=D1=80=D0=BD=D0=BE=D0=B5=20=D0=B2=D1=81?= =?UTF-8?q?=D1=91=20=D1=80=D0=B0=D0=B2=D0=BD=D0=BE=20=D1=83=D0=BC=D0=B5?= =?UTF-8?q?=D0=BD=D1=8C=D1=88=D0=B8=D1=82=D1=8C=20=D0=BD=D0=B0=D0=B4=D0=BE?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mc/otm/datagen/{OreGen.kt => WorldGen.kt} | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) rename src/data/kotlin/ru/dbotthepony/mc/otm/datagen/{OreGen.kt => WorldGen.kt} (94%) diff --git a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/OreGen.kt b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/WorldGen.kt similarity index 94% rename from src/data/kotlin/ru/dbotthepony/mc/otm/datagen/OreGen.kt rename to src/data/kotlin/ru/dbotthepony/mc/otm/datagen/WorldGen.kt index 8d3b4e32d..4bb408e4a 100644 --- a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/OreGen.kt +++ b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/WorldGen.kt @@ -26,8 +26,6 @@ import ru.dbotthepony.mc.otm.worldgen.feature.BlackHolePlacerConfiguration private object ConfiguredFeatures { val TRITANIUM_ORE = key("tritanium_ore") - - // TODO: ЭТО НЕ РУДА val BLACK_HOLE = key("black_hole") private fun key(name: String): ResourceKey> { @@ -45,17 +43,13 @@ fun registerConfiguredFeatures(context: BootstrapContext ) context.register(ConfiguredFeatures.TRITANIUM_ORE, ConfiguredFeature(Feature.ORE, OreConfiguration(target, 9))) - - // TODO: ЭТО НЕ РУДА context.register(ConfiguredFeatures.BLACK_HOLE, ConfiguredFeature(MWorldGenFeatures.BLACK_HOLE_PLACER, - BlackHolePlacerConfiguration(0.005f, Decimal(2048), Decimal(2048 + 8192)))) + BlackHolePlacerConfiguration(0.001f, Decimal(125_000), Decimal(500_000)))) } private object PlacedFeatures { val NORMAL_TRITANIUM = key("normal_tritanium") val DEEP_TRITANIUM = key("deep_tritanium") - - // TODO: ЭТО НЕ РУДА val BLACK_HOLE = key("black_hole") private fun key(name: String): ResourceKey { @@ -85,8 +79,8 @@ fun registerPlacedFeatures(context: BootstrapContext) { ) )) - // TODO: ЭТО НЕ РУДА val blackHole = configured.getOrThrow(ConfiguredFeatures.BLACK_HOLE) + context.register(PlacedFeatures.BLACK_HOLE, PlacedFeature( blackHole, listOf( @@ -98,8 +92,6 @@ fun registerPlacedFeatures(context: BootstrapContext) { private object BiomeModifiers { val TRITANIUM_ORE = key("tritanium_ore") - - // TODO: ЭТО НЕ РУДА val BLACK_HOLE = key("black_hole") private fun key(name: String): ResourceKey { @@ -123,7 +115,6 @@ fun registerBiomeModifiers(context: BootstrapContext) { ) ) - // TODO: ЭТО НЕ РУДА context.register( BiomeModifiers.BLACK_HOLE, net.neoforged.neoforge.common.world.BiomeModifiers.AddFeaturesBiomeModifier(