From 5d0b2c9f7e185849b08046bfed3fb4c20bda8d8b Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Fri, 13 Jan 2023 21:54:52 +0700 Subject: [PATCH] Ore worldgen json datagen Used to place a configuredfeature, tele jigsaw, template or st'ructure at a given location. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ☎️ 🧩 😤 🛣️ 😵 💭 ✨ 🏗️ ⚙️ 🧩 🌎 ⏳ 🧮 🇯 🌞 ☎️ 🧩 😤 🛣️ 😵 💭 ✨ 🏗️ ⚙️ 🧩 🌎 ⏳ 🧮 🇯 🌞 ☎️ 🧩 😤 🛣️ 😵 💭 ✨ 🏗️ ⚙️ 🧩 🌎 ⏳ 🧮 🇯 🌞 ☎️ 🧩 😤 🛣️ 😵 💭 ✨ 🏗️ ⚙️ 🧩 🌎 ⏳ 🧮 🇯 🌞 When the dev team was programming telepathicgrunt, they realized that there was a potential to create something similar inside the tele, causing recursion until the jigsaw crashed. To fix this, they capped the injigsaw grunt available at 2^512 pathics, forcing anything telepathic to be less complex than telepathicgrunt and preventing crashes. Let’s dissect tele jigsaw grunt pathic telepathic st’ructure worldgenjson. Starting from the beginning, tele implies that the whole has remote control capabilities, such as telepathy or telekinesis. Next, jigsaw implies multiple pieces that can be slotted together and rearranged. A grunt is simply a particular sound generated by an animal, implying that it is capable of creating noise. Pathic, similar to pathos, implies that it can affect emotions in some way. Following this, we have the even more direct telepathic, implying it is capable of reading thoughts and emotions. St’ructure is more difficult because the part after the apostrophe must be abbreviated, meaning it is likely two words, “stereospecific technostructure”. This implies it is a synthetic construct with a specific arrangement, meaning it could be a program. With this context in mind, processorjigsaw makes sense: it’s capable of rearranging its components and editing its code. Finally, worldgenjson could mean that it has some ability to manipulate reality through JSON. With all this in mind, I present my theory. tele jigsaw grunt pathic telepathic st’ructure processorjigsaw worldgenjson is a sapient, self-editing AI with telepathic and ontokinetic abilities. Due to its synthetic nature, it is interested in studying the behavior of humans, and using its abilities, created and spread an inside joke within the MCDrama server, giving it its own name in an act of vanity. --- .../ru/dbotthepony/mc/otm/datagen/DataGen.kt | 2 + .../ru/dbotthepony/mc/otm/datagen/Ext.kt | 3 - .../ru/dbotthepony/mc/otm/datagen/OreGen.kt | 93 +++++++++++++++++++ .../mc/otm/OverdriveThatMatters.java | 3 - .../ru/dbotthepony/mc/otm/registry/Ext.kt | 8 +- .../ru/dbotthepony/mc/otm/worldgen/OreGen.kt | 59 ------------ 6 files changed, 99 insertions(+), 69 deletions(-) create mode 100644 src/data/kotlin/ru/dbotthepony/mc/otm/datagen/OreGen.kt delete mode 100644 src/main/kotlin/ru/dbotthepony/mc/otm/worldgen/OreGen.kt diff --git a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/DataGen.kt b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/DataGen.kt index 7b2f9a31a..f4b40cfb3 100644 --- a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/DataGen.kt +++ b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/DataGen.kt @@ -442,6 +442,8 @@ object DataGen { event.generator.addProvider(event.includeServer(), advancementProvider) event.generator.addProvider(event.includeServer(), matterData) + registerOreGen(event) + AddEnglishLanguage(languageProvider) for ((color, door) in MBlocks.TRITANIUM_DOOR) diff --git a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/Ext.kt b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/Ext.kt index 38dc866bb..4878ae37e 100644 --- a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/Ext.kt +++ b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/Ext.kt @@ -1,11 +1,8 @@ package ru.dbotthepony.mc.otm.datagen -import com.google.gson.JsonArray -import com.google.gson.JsonObject import net.minecraft.core.Direction import net.minecraft.world.level.block.state.BlockState import net.minecraft.world.level.block.state.properties.Property -import kotlin.math.roundToInt fun Direction.toYRotBlockstate(): Int { return when (this) { diff --git a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/OreGen.kt b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/OreGen.kt new file mode 100644 index 000000000..6eade58f3 --- /dev/null +++ b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/OreGen.kt @@ -0,0 +1,93 @@ +package ru.dbotthepony.mc.otm.datagen + +import com.mojang.serialization.JsonOps +import net.minecraft.core.Holder +import net.minecraft.core.HolderOwner +import net.minecraft.core.registries.Registries +import net.minecraft.resources.RegistryOps +import net.minecraft.resources.ResourceKey +import net.minecraft.resources.ResourceLocation +import net.minecraft.server.packs.PackType +import net.minecraft.tags.BlockTags +import net.minecraft.world.level.levelgen.VerticalAnchor +import net.minecraft.world.level.levelgen.feature.ConfiguredFeature +import net.minecraft.world.level.levelgen.feature.Feature +import net.minecraft.world.level.levelgen.feature.configurations.OreConfiguration +import net.minecraft.world.level.levelgen.placement.CountPlacement +import net.minecraft.world.level.levelgen.placement.HeightRangePlacement +import net.minecraft.world.level.levelgen.placement.InSquarePlacement +import net.minecraft.world.level.levelgen.placement.PlacedFeature +import net.minecraft.world.level.levelgen.structure.templatesystem.TagMatchTest +import net.minecraftforge.common.data.JsonCodecProvider +import net.minecraftforge.data.event.GatherDataEvent +import ru.dbotthepony.mc.otm.registry.MBlocks + +private object Owner : HolderOwner { + override fun canSerializeIn(p_255875_: HolderOwner): Boolean { + return true // because we can always reference things, even if they are not "registered" at this moment + } +} + +private data class Both(val key: Holder, val value: Holder) + +private fun createHolders(key: ResourceKey, value: T): Both { + val keyOnly = Holder.Reference.createStandAlone(Owner as HolderOwner, key) + val valueOnly = Holder.direct(value) + return Both(keyOnly, valueOnly) +} + +private fun remap(vararg input: Both): Map> { + val result = LinkedHashMap>() + + for (value in input) { + result[value.key.unwrapKey().get().location()] = value.value + } + + return result +} + +fun registerOreGen(event: GatherDataEvent) { + val stone = TagMatchTest(BlockTags.STONE_ORE_REPLACEABLES) + val deepslate = TagMatchTest(BlockTags.DEEPSLATE_ORE_REPLACEABLES) + + val target by lazy { + listOf( + OreConfiguration.target(stone, MBlocks.TRITANIUM_ORE.defaultBlockState()), + OreConfiguration.target(deepslate, MBlocks.DEEPSLATE_TRITANIUM_ORE.defaultBlockState()), + ) + } + + val ops = RegistryOps.create(JsonOps.INSTANCE, event.lookupProvider.join()) + val tritanium = createHolders(ResourceKey.create(Registries.CONFIGURED_FEATURE, modLocation("ore_tritanium")), ConfiguredFeature(Feature.ORE, OreConfiguration(target, 9))) + val configuredFeatures = remap(tritanium) + + event.generator.addProvider(event.includeServer(), JsonCodecProvider( + event.generator.packOutput, event.existingFileHelper, DataGen.MOD_ID, ops, + PackType.SERVER_DATA, "worldgen/configured_feature", ConfiguredFeature.CODEC, configuredFeatures + )) + + val placedTritanium = createHolders(ResourceKey.create(Registries.PLACED_FEATURE, modLocation("normal_tritanium")), PlacedFeature( + tritanium.key, + listOf( + CountPlacement.of(8), + InSquarePlacement.spread(), + HeightRangePlacement.triangle(VerticalAnchor.absolute(0), VerticalAnchor.absolute(50)) + ) + )) + + val placedTritaniumDeep = createHolders(ResourceKey.create(Registries.PLACED_FEATURE, modLocation("deep_tritanium")), PlacedFeature( + tritanium.key, + listOf( + CountPlacement.of(10), + InSquarePlacement.spread(), + HeightRangePlacement.uniform(VerticalAnchor.aboveBottom(8), VerticalAnchor.absolute(0)) + ) + )) + + val placedFeatures = remap(placedTritanium, placedTritaniumDeep) + + event.generator.addProvider(event.includeServer(), JsonCodecProvider( + event.generator.packOutput, event.existingFileHelper, DataGen.MOD_ID, ops, + PackType.SERVER_DATA, "worldgen/placed_feature", PlacedFeature.CODEC, placedFeatures + )) +} diff --git a/src/main/java/ru/dbotthepony/mc/otm/OverdriveThatMatters.java b/src/main/java/ru/dbotthepony/mc/otm/OverdriveThatMatters.java index fad7cc780..46e9e034f 100644 --- a/src/main/java/ru/dbotthepony/mc/otm/OverdriveThatMatters.java +++ b/src/main/java/ru/dbotthepony/mc/otm/OverdriveThatMatters.java @@ -44,7 +44,6 @@ import ru.dbotthepony.mc.otm.matter.MatterManager; import ru.dbotthepony.mc.otm.network.*; import ru.dbotthepony.mc.otm.registry.*; import ru.dbotthepony.mc.otm.storage.*; -import ru.dbotthepony.mc.otm.worldgen.OreGen; import static net.minecraftforge.common.MinecraftForge.EVENT_BUS; @@ -181,8 +180,6 @@ public final class OverdriveThatMatters { if (ModList.get().isLoaded("mekanism")) { EVENT_BUS.addGenericListener(BlockEntity.class, EventPriority.NORMAL, QIOKt::attachCapabilities); } - - OreGen.INSTANCE.register(); } private void setupClient(final FMLClientSetupEvent event) { diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/registry/Ext.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/registry/Ext.kt index 4d3ef11aa..fdbf81a00 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/registry/Ext.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/registry/Ext.kt @@ -32,19 +32,19 @@ private fun DeferredRegister.doColored(prefix: String, factory: (color: D ) } -fun DeferredRegister.colored(prefix: String, factory: (color: DyeColor, name: String) -> T): Map { +internal fun DeferredRegister.colored(prefix: String, factory: (color: DyeColor, name: String) -> T): Map { return SupplierMap(doColored(prefix, factory)) } @Suppress("unchecked_cast") -fun DeferredRegister.allColored(prefix: String, factory: (color: DyeColor?, name: String) -> T): Map { +internal fun DeferredRegister.allColored(prefix: String, factory: (color: DyeColor?, name: String) -> T): Map { return SupplierMap(doColored(prefix, factory).also { (it as MutableCollection T>>).add((null as DyeColor?) to register(prefix) { factory.invoke(null, prefix) }::get) }) } -fun Registry.register(key: String, value: T): Holder { +internal fun Registry.register(key: String, value: T): Holder { return this.register(ResourceLocation(OverdriveThatMatters.MOD_ID, key), value) } -fun Registry.register(key: ResourceLocation, value: T): Holder { +internal fun Registry.register(key: ResourceLocation, value: T): Holder { return (this as WritableRegistry).register(ResourceKey.create(key(), key), value, Lifecycle.stable()) } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/worldgen/OreGen.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/worldgen/OreGen.kt deleted file mode 100644 index aa96fb473..000000000 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/worldgen/OreGen.kt +++ /dev/null @@ -1,59 +0,0 @@ -package ru.dbotthepony.mc.otm.worldgen - -import net.minecraft.core.Holder -import net.minecraft.core.registries.BuiltInRegistries -import net.minecraft.core.registries.Registries -import net.minecraft.data.worldgen.features.OreFeatures -import net.minecraft.tags.BlockTags -import net.minecraft.world.level.levelgen.VerticalAnchor -import net.minecraft.world.level.levelgen.feature.ConfiguredFeature -import net.minecraft.world.level.levelgen.feature.Feature -import net.minecraft.world.level.levelgen.feature.configurations.OreConfiguration -import net.minecraft.world.level.levelgen.placement.CountPlacement -import net.minecraft.world.level.levelgen.placement.HeightRangePlacement -import net.minecraft.world.level.levelgen.placement.InSquarePlacement -import net.minecraft.world.level.levelgen.placement.PlacedFeature -import net.minecraft.world.level.levelgen.structure.templatesystem.TagMatchTest -import ru.dbotthepony.mc.otm.registry.MBlocks -import ru.dbotthepony.mc.otm.core.WriteOnce -import ru.dbotthepony.mc.otm.registry.register - -@Suppress("UNNECESSARY_NOT_NULL_ASSERTION") -object OreGen { - private val STONE_ORE_REPLACEABLES = TagMatchTest(BlockTags.STONE_ORE_REPLACEABLES) - private val DEEPSLATE_ORE_REPLACEABLES = TagMatchTest(BlockTags.DEEPSLATE_ORE_REPLACEABLES) - - val ORE_TRITANIUM_TARGET_LIST = listOf( - OreConfiguration.target(STONE_ORE_REPLACEABLES, MBlocks.TRITANIUM_ORE.defaultBlockState())!!, - OreConfiguration.target(DEEPSLATE_ORE_REPLACEABLES, MBlocks.DEEPSLATE_TRITANIUM_ORE.defaultBlockState())!!, - ) - - var ORE_FEATURE_TRITANIUM_NORMAL by WriteOnce>>() - var ORE_TRITANIUM_NORMAL by WriteOnce>() - var ORE_TRITANIUM_DEEP by WriteOnce>() - - fun register() { - // TODO: 1.19.3 - /*val registry = BuiltInRegistries.REGISTRY.get(Registries.CONFIGURED_FEATURE.location()) - - ORE_FEATURE_TRITANIUM_NORMAL = CONFIGURED_FEATURE.register("ore_tritanium", ConfiguredFeature(Feature.ORE, OreConfiguration(ORE_TRITANIUM_TARGET_LIST, 9))) - - ORE_TRITANIUM_NORMAL = PLACED_FEATURE.register("ore_tritanium_normal", PlacedFeature( - ORE_FEATURE_TRITANIUM_NORMAL, - listOf( - CountPlacement.of(8), - InSquarePlacement.spread(), - HeightRangePlacement.triangle(VerticalAnchor.absolute(0), VerticalAnchor.absolute(50)) - ) - )) - - ORE_TRITANIUM_DEEP = PLACED_FEATURE.register("ore_tritanium_deep", PlacedFeature( - ORE_FEATURE_TRITANIUM_NORMAL, - listOf( - CountPlacement.of(10), - InSquarePlacement.spread(), - HeightRangePlacement.uniform(VerticalAnchor.aboveBottom(8), VerticalAnchor.absolute(0)) - ) - ))*/ - } -}