Skip to content

Commit

Permalink
improve datagen
Browse files Browse the repository at this point in the history
  • Loading branch information
btwonion committed Jun 14, 2024
1 parent f554bbd commit d3a1bce
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 52 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions telekinesis-fabric/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
@file:Suppress("SpellCheckingInspection")
@file:Suppress("SpellCheckingInspection", "SENSELESS_COMPARISON")

import org.jetbrains.kotlin.gradle.dsl.JvmTarget
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.+"

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -56,5 +55,5 @@ class TelekinesisEnchantment : Enchantment(
}
*//*?}*/

val tagKey = TagKey.create(Registries.ENCHANTMENT, ResourceLocation.fromNamespaceAndPath("telekinesis", "auto_move"))
val enchantmentId = ResourceLocation.fromNamespaceAndPath("telekinesis", "telekinesis")
val telekinesisEffectId: TagKey<Enchantment> = TagKey.create(Registries.ENCHANTMENT, ResourceLocation.fromNamespaceAndPath("telekinesis", "auto_move"))
val telekinesisEnchantmentId: ResourceLocation = ResourceLocation.fromNamespaceAndPath("telekinesis", "telekinesis")
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -22,48 +21,41 @@ 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<HolderLookup.Provider>
) : EnchantmentTagProvider(output, completableFuture) {
override fun addTags(registries: HolderLookup.Provider) {
getOrCreateTagBuilder(tagKey).add(enchantmentId)
getOrCreateTagBuilder(telekinesisEffectId).addOptional(telekinesisEnchantmentId)
}
}

private class EnchantmentProvider(
output: FabricDataOutput, registriesFuture: CompletableFuture<HolderLookup.Provider>
) : 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)
}
}

/*?}*/
4 changes: 2 additions & 2 deletions telekinesis-fabric/versions/1.20.6/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"per_level_above_first": 25
},
"slots": [
"any"
"hand"
],
"supported_items": "#minecraft:enchantable/durability",
"supported_items": "#c:tools",
"weight": 2
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"values": [
"telekinesis:telekinesis"
{
"id": "telekinesis:telekinesis",
"required": false
}
]
}

0 comments on commit d3a1bce

Please sign in to comment.