From d3a1bce3faf95fdbb2b3f8aa7e75103a33667a49 Mon Sep 17 00:00:00 2001 From: btwonion Date: Fri, 14 Jun 2024 17:47:05 +0200 Subject: [PATCH] improve datagen --- build.gradle.kts | 2 +- gradle/wrapper/gradle-wrapper.properties | 2 +- telekinesis-fabric/build.gradle.kts | 4 +- .../telekinesis/mixins/EnchantmentsMixin.java | 8 +-- .../kotlin/dev/nyon/telekinesis/DropEvent.kt | 2 +- .../telekinesis/TelekinesisEnchantment.kt | 17 +++---- .../TelekinesisEnchantmentGenerator.kt | 50 ++++++++----------- .../versions/1.20.6/gradle.properties | 4 +- .../telekinesis/enchantment/telekinesis.json | 4 +- .../tags/enchantment/auto_move.json | 5 +- 10 files changed, 46 insertions(+), 52 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index afa332b..e89c20e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -4,7 +4,7 @@ plugins { id("me.modmuss50.mod-publish-plugin") version "0.5.+" - id("fabric-loom") version "1.6-SNAPSHOT" apply (false) + id("fabric-loom") version "1.7-SNAPSHOT" apply (false) id("io.papermc.paperweight.userdev") version "1.5.5" apply (false) diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index a8382d7..db4c326 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists \ No newline at end of file diff --git a/telekinesis-fabric/build.gradle.kts b/telekinesis-fabric/build.gradle.kts index 07d20d4..f2ebf62 100644 --- a/telekinesis-fabric/build.gradle.kts +++ b/telekinesis-fabric/build.gradle.kts @@ -1,4 +1,4 @@ -@file:Suppress("SpellCheckingInspection") +@file:Suppress("SpellCheckingInspection", "SENSELESS_COMPARISON") import org.jetbrains.kotlin.gradle.dsl.JvmTarget import org.jetbrains.kotlin.gradle.tasks.KotlinCompile @@ -6,7 +6,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { kotlin("jvm") version "2.0.0" kotlin("plugin.serialization") version "2.0.0" - id("fabric-loom") version "1.6-SNAPSHOT" + id("fabric-loom") version "1.7-SNAPSHOT" id("me.modmuss50.mod-publish-plugin") version "0.5.+" diff --git a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/EnchantmentsMixin.java b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/EnchantmentsMixin.java index 39b5974..0b77e9c 100644 --- a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/EnchantmentsMixin.java +++ b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/EnchantmentsMixin.java @@ -1,7 +1,7 @@ package dev.nyon.telekinesis.mixins; -/*? if <1.21 {*//* -import dev.nyon.telekinesis.MainKt; +/*? if <1.21 {*/ +/*import dev.nyon.telekinesis.MainKt; import dev.nyon.telekinesis.TelekinesisEnchantment; import net.minecraft.core.Registry; import net.minecraft.core.registries.BuiltInRegistries; @@ -18,8 +18,8 @@ @Mixin(Enchantments.class) public abstract class EnchantmentsMixin { - /*? if <1.21 {*//* - @Unique + /*? if <1.21 {*/ + /*@Unique private static boolean isTelekinesisRegistered = false; @Inject( diff --git a/telekinesis-fabric/src/main/kotlin/dev/nyon/telekinesis/DropEvent.kt b/telekinesis-fabric/src/main/kotlin/dev/nyon/telekinesis/DropEvent.kt index c48c35c..6b633de 100644 --- a/telekinesis-fabric/src/main/kotlin/dev/nyon/telekinesis/DropEvent.kt +++ b/telekinesis-fabric/src/main/kotlin/dev/nyon/telekinesis/DropEvent.kt @@ -20,7 +20,7 @@ object DropEvent { @Suppress("unused") private val listener = event.register { items, exp, player, tool -> if (config.needSneak && !player.isCrouching) return@register - if (config.needEnchantment && !EnchantmentHelper.hasTag(tool, tagKey)) return@register + if (config.needEnchantment && !EnchantmentHelper.hasTag(tool, telekinesisEffectId)) return@register if (config.itemsAllowed) items.removeIf(player::addItem) if (config.expAllowed) { diff --git a/telekinesis-fabric/src/main/kotlin/dev/nyon/telekinesis/TelekinesisEnchantment.kt b/telekinesis-fabric/src/main/kotlin/dev/nyon/telekinesis/TelekinesisEnchantment.kt index 78ed8b2..442fb2d 100644 --- a/telekinesis-fabric/src/main/kotlin/dev/nyon/telekinesis/TelekinesisEnchantment.kt +++ b/telekinesis-fabric/src/main/kotlin/dev/nyon/telekinesis/TelekinesisEnchantment.kt @@ -3,17 +3,16 @@ package dev.nyon.telekinesis import net.minecraft.core.registries.Registries import net.minecraft.resources.ResourceLocation import net.minecraft.tags.TagKey +import net.minecraft.world.item.enchantment.Enchantment - - -/*? if <1.21 {*//* -import net.minecraft.network.chat.Component +/*? if <1.21 {*/ +/*import net.minecraft.network.chat.Component import net.minecraft.network.chat.Style import net.minecraft.world.item.enchantment.Enchantment import net.minecraft.world.entity.EquipmentSlot *//*?}*/ /*? >1.20.5 {*/ -import net.minecraft.tags.ItemTags + /*?} else {*//* import net.minecraft.world.damagesource.DamageSource import net.minecraft.world.entity.MobType @@ -22,8 +21,8 @@ import net.minecraft.world.item.enchantment.EnchantmentCategory -/*? if =1.20.6 {*//* -class TelekinesisEnchantment : Enchantment( +/*? if =1.20.6 {*/ +/*class TelekinesisEnchantment : Enchantment( definition( ItemTags.DURABILITY_ENCHANTABLE, 2, @@ -56,5 +55,5 @@ class TelekinesisEnchantment : Enchantment( } *//*?}*/ -val tagKey = TagKey.create(Registries.ENCHANTMENT, ResourceLocation.fromNamespaceAndPath("telekinesis", "auto_move")) -val enchantmentId = ResourceLocation.fromNamespaceAndPath("telekinesis", "telekinesis") \ No newline at end of file +val telekinesisEffectId: TagKey = TagKey.create(Registries.ENCHANTMENT, ResourceLocation.fromNamespaceAndPath("telekinesis", "auto_move")) +val telekinesisEnchantmentId: ResourceLocation = ResourceLocation.fromNamespaceAndPath("telekinesis", "telekinesis") \ No newline at end of file diff --git a/telekinesis-fabric/src/main/kotlin/dev/nyon/telekinesis/TelekinesisEnchantmentGenerator.kt b/telekinesis-fabric/src/main/kotlin/dev/nyon/telekinesis/TelekinesisEnchantmentGenerator.kt index 3f81135..c03d5a3 100644 --- a/telekinesis-fabric/src/main/kotlin/dev/nyon/telekinesis/TelekinesisEnchantmentGenerator.kt +++ b/telekinesis-fabric/src/main/kotlin/dev/nyon/telekinesis/TelekinesisEnchantmentGenerator.kt @@ -5,12 +5,11 @@ import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput import net.fabricmc.fabric.api.datagen.v1.provider.FabricDynamicRegistryProvider import net.fabricmc.fabric.api.datagen.v1.provider.FabricTagProvider.EnchantmentTagProvider +import net.fabricmc.fabric.api.tag.convention.v2.ConventionalItemTags import net.minecraft.core.HolderLookup -import net.minecraft.core.RegistrySetBuilder import net.minecraft.core.registries.Registries import net.minecraft.resources.ResourceKey import net.minecraft.resources.ResourceLocation -import net.minecraft.tags.ItemTags import net.minecraft.world.entity.EquipmentSlotGroup import net.minecraft.world.item.enchantment.Enchantment import net.minecraft.world.item.enchantment.Enchantment.EnchantmentDefinition @@ -22,36 +21,16 @@ class TelekinesisEnchantmentGenerator : DataGeneratorEntrypoint { val pack = generator.createPack() pack.addProvider(::EnchantmentProvider) - pack.addProvider(::TelekinesisTagProvider) - /*?}*/ - } - - override fun buildRegistry(registryBuilder: RegistrySetBuilder) { - registryBuilder.add(Registries.ENCHANTMENT) { context -> - val enchantmentDefinition: EnchantmentDefinition = Enchantment.definition( - context.lookup(Registries.ITEM).getOrThrow(ItemTags.DURABILITY_ENCHANTABLE), // TODO: only tools!! - 2, - 1, - dynamicCost(25, 25), - dynamicCost(75, 25), - 5, - EquipmentSlotGroup.ANY - ) - - context.register( - ResourceKey.create(Registries.ENCHANTMENT, enchantmentId), Enchantment.enchantment(enchantmentDefinition).build( - ResourceLocation.fromNamespaceAndPath("telekinesis", "telekinesis.name") - ) - ) - } + pack.addProvider(::TelekinesisEnchantmentTagProvider)/*?}*/ } } -private class TelekinesisTagProvider( +/*? if >=1.21 {*/ +private class TelekinesisEnchantmentTagProvider( output: FabricDataOutput, completableFuture: CompletableFuture ) : EnchantmentTagProvider(output, completableFuture) { override fun addTags(registries: HolderLookup.Provider) { - getOrCreateTagBuilder(tagKey).add(enchantmentId) + getOrCreateTagBuilder(telekinesisEffectId).addOptional(telekinesisEnchantmentId) } } @@ -59,11 +38,24 @@ private class EnchantmentProvider( output: FabricDataOutput, registriesFuture: CompletableFuture ) : FabricDynamicRegistryProvider(output, registriesFuture) { override fun getName(): String { - return "Enchantment" + return "Telekinesis Enchantment Generation" } override fun configure(registries: HolderLookup.Provider, entries: Entries) { - entries.addAll(registries.lookupOrThrow(Registries.ENCHANTMENT)) + val enchantmentDefinition: EnchantmentDefinition = Enchantment.definition( + registries.lookupOrThrow(Registries.ITEM).getOrThrow(ConventionalItemTags.TOOLS), + 2, + 1, + dynamicCost(25, 25), + dynamicCost(75, 25), + 7, + EquipmentSlotGroup.HAND + ) + + val enchantment = Enchantment.enchantment(enchantmentDefinition).build( + ResourceLocation.fromNamespaceAndPath("telekinesis", "telekinesis.name") + ) + entries.add(ResourceKey.create(Registries.ENCHANTMENT, telekinesisEnchantmentId), enchantment) } } - +/*?}*/ diff --git a/telekinesis-fabric/versions/1.20.6/gradle.properties b/telekinesis-fabric/versions/1.20.6/gradle.properties index 7a02cb9..dea9089 100644 --- a/telekinesis-fabric/versions/1.20.6/gradle.properties +++ b/telekinesis-fabric/versions/1.20.6/gradle.properties @@ -2,8 +2,8 @@ mcVersion=1.20.6 mcVersionRange=>=1.20.5 <=1.20.6 supportedMcVersions=1.20.5,1.20.6 -deps.parchment=1.20.6:2024.05.01 -deps.fapi=0.97.8+1.20.6 +deps.parchment=1.20.6:2024.06.02 +deps.fapi=0.100.0+1.20.6 deps.yacl=3.4.2+1.20.5-fabric deps.modMenu=10.0.0-beta.1 diff --git a/telekinesis-fabric/versions/1.21/src/main/generated/data/telekinesis/enchantment/telekinesis.json b/telekinesis-fabric/versions/1.21/src/main/generated/data/telekinesis/enchantment/telekinesis.json index 7ad5d89..3c411d8 100644 --- a/telekinesis-fabric/versions/1.21/src/main/generated/data/telekinesis/enchantment/telekinesis.json +++ b/telekinesis-fabric/versions/1.21/src/main/generated/data/telekinesis/enchantment/telekinesis.json @@ -13,8 +13,8 @@ "per_level_above_first": 25 }, "slots": [ - "any" + "hand" ], - "supported_items": "#minecraft:enchantable/durability", + "supported_items": "#c:tools", "weight": 2 } \ No newline at end of file diff --git a/telekinesis-fabric/versions/1.21/src/main/generated/data/telekinesis/tags/enchantment/auto_move.json b/telekinesis-fabric/versions/1.21/src/main/generated/data/telekinesis/tags/enchantment/auto_move.json index 18d3b4f..0d9aebf 100644 --- a/telekinesis-fabric/versions/1.21/src/main/generated/data/telekinesis/tags/enchantment/auto_move.json +++ b/telekinesis-fabric/versions/1.21/src/main/generated/data/telekinesis/tags/enchantment/auto_move.json @@ -1,5 +1,8 @@ { "values": [ - "telekinesis:telekinesis" + { + "id": "telekinesis:telekinesis", + "required": false + } ] } \ No newline at end of file