From 99ede25877ea785981f0ca101ac50254b21e3467 Mon Sep 17 00:00:00 2001 From: solonovamax Date: Mon, 7 Oct 2024 00:09:06 -0400 Subject: [PATCH 1/2] Add useful extensions for registering things This also includes functions for creating things that are part of a registry Signed-off-by: solonovamax --- buildSrc/src/main/kotlin/BuildConstants.kt | 7 +- .../kotlin/kotlin-project-script.gradle.kts | 2 +- silk-all/build.gradle.kts | 3 +- silk-fabric/build.gradle.kts | 18 + .../fabric/client/KeyMappingExtensions.kt | 13 + .../fabric/registry/ArmorMaterialRegistry.kt | 68 ++++ .../fabric/registry/BlockEntityRegistry.kt | 25 ++ .../silk/fabric/registry/BlockRegistry.kt | 32 ++ .../registry/CreativeModeTabRegistry.kt | 33 ++ .../silk/fabric/registry/CriterionRegistry.kt | 11 + .../fabric/registry/DataComponentRegistry.kt | 14 + .../fabric/registry/EntityTypeRegistry.kt | 27 ++ .../silk/fabric/registry/FluidRegistry.kt | 10 + .../silk/fabric/registry/GameRuleRegistry.kt | 63 ++++ .../silk/fabric/registry/HolderExtensions.kt | 11 + .../silk/fabric/registry/ItemRegistry.kt | 62 ++++ .../silk/fabric/registry/MobEffectRegistry.kt | 20 ++ .../fabric/registry/ParticleTypeRegistry.kt | 10 + .../silk/fabric/registry/PotionRegistry.kt | 46 +++ .../silk/fabric/registry/RecipeRegistry.kt | 26 ++ .../fabric/registry/RegistryExtensions.kt | 40 +++ .../fabric/registry/ScreenHandlerRegistry.kt | 19 + .../silk/fabric/registry/SimpleRegistries.kt | 335 ++++++++++++++++++ .../fabric/registry/SountEventRegistry.kt | 44 +++ silk-paper/build.gradle.kts | 2 +- 25 files changed, 937 insertions(+), 4 deletions(-) create mode 100644 silk-fabric/build.gradle.kts create mode 100644 silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/client/KeyMappingExtensions.kt create mode 100644 silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/ArmorMaterialRegistry.kt create mode 100644 silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/BlockEntityRegistry.kt create mode 100644 silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/BlockRegistry.kt create mode 100644 silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/CreativeModeTabRegistry.kt create mode 100644 silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/CriterionRegistry.kt create mode 100644 silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/DataComponentRegistry.kt create mode 100644 silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/EntityTypeRegistry.kt create mode 100644 silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/FluidRegistry.kt create mode 100644 silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/GameRuleRegistry.kt create mode 100644 silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/HolderExtensions.kt create mode 100644 silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/ItemRegistry.kt create mode 100644 silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/MobEffectRegistry.kt create mode 100644 silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/ParticleTypeRegistry.kt create mode 100644 silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/PotionRegistry.kt create mode 100644 silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/RecipeRegistry.kt create mode 100644 silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/RegistryExtensions.kt create mode 100644 silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/ScreenHandlerRegistry.kt create mode 100644 silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/SimpleRegistries.kt create mode 100644 silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/SountEventRegistry.kt diff --git a/buildSrc/src/main/kotlin/BuildConstants.kt b/buildSrc/src/main/kotlin/BuildConstants.kt index dafa929a..df36e955 100644 --- a/buildSrc/src/main/kotlin/BuildConstants.kt +++ b/buildSrc/src/main/kotlin/BuildConstants.kt @@ -20,11 +20,12 @@ object BuildConstants { const val paperMinecraftVersion = "1.21.1" const val fabricLoaderVersion = "0.16.10" const val fabricLanguageKotlinVersion = "1.12.3+kotlin.2.0.21" + const val fabricApiVersion = "0.100.8+1.21" const val kotestVersion = "5.9.1" const val mockkVersion = "1.13.12" - val uploadModules = listOf( + val commonModules = listOf( "commands", "core", "game", @@ -33,4 +34,8 @@ object BuildConstants { "network", "persistence", ) + val uploadModules = commonModules + listOf( + "paper", + "fabric" + ) } diff --git a/buildSrc/src/main/kotlin/kotlin-project-script.gradle.kts b/buildSrc/src/main/kotlin/kotlin-project-script.gradle.kts index 90557a5a..50799981 100644 --- a/buildSrc/src/main/kotlin/kotlin-project-script.gradle.kts +++ b/buildSrc/src/main/kotlin/kotlin-project-script.gradle.kts @@ -29,7 +29,7 @@ kotlin { sourceSets.all { languageSettings { - val whitelistModules = BuildConstants.uploadModules.plus("paper") + val whitelistModules = BuildConstants.uploadModules if (project.name.removePrefix(rootProject.name + "-") in whitelistModules) { listOf("InternalSilkApi", "DelicateSilkApi", "ExperimentalSilkApi").forEach { optIn("net.silkmc.silk.core.annotations.${it}") diff --git a/silk-all/build.gradle.kts b/silk-all/build.gradle.kts index ebb4008c..48892441 100644 --- a/silk-all/build.gradle.kts +++ b/silk-all/build.gradle.kts @@ -7,9 +7,10 @@ plugins { } dependencies { - BuildConstants.uploadModules.forEach { + BuildConstants.commonModules.forEach { implementation(include(project(":${rootProject.name}-${it}"))!!) } + implementation(include(modProject(":${rootProject.name}-fabric"))!!) } val modName by extra("$projectTitle (All modules)") diff --git a/silk-fabric/build.gradle.kts b/silk-fabric/build.gradle.kts new file mode 100644 index 00000000..f621221a --- /dev/null +++ b/silk-fabric/build.gradle.kts @@ -0,0 +1,18 @@ +import BuildConstants.fabricApiVersion +import BuildConstants.projectTitle + +description = "Silk Core provides a simple and stable Kotlin API for working with Minecraft" + +plugins { + `kotlin-project-script` + `mod-build-script` + `project-publish-script` + `kotest-script` + `dokka-script` +} + +dependencies { + modApi("net.fabricmc.fabric-api:fabric-api:$fabricApiVersion") +} + +val modName by extra("$projectTitle Fabric") diff --git a/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/client/KeyMappingExtensions.kt b/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/client/KeyMappingExtensions.kt new file mode 100644 index 00000000..90040adf --- /dev/null +++ b/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/client/KeyMappingExtensions.kt @@ -0,0 +1,13 @@ +@file:Suppress("unused") + +package net.silkmc.silk.fabric.client + +import com.mojang.blaze3d.platform.InputConstants +import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper +import net.minecraft.client.KeyMapping + +fun keyMappingOf(translationKey: String, type: InputConstants.Type = InputConstants.Type.KEYSYM, code: Int, category: String): KeyMapping { + return KeyBindingHelper.registerKeyBinding(KeyMapping(translationKey, type, code, category)) +} + +fun KeyMapping.asKey(): InputConstants.Key = KeyBindingHelper.getBoundKeyOf(this) diff --git a/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/ArmorMaterialRegistry.kt b/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/ArmorMaterialRegistry.kt new file mode 100644 index 00000000..ebf0190b --- /dev/null +++ b/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/ArmorMaterialRegistry.kt @@ -0,0 +1,68 @@ +@file:Suppress("unused") + +package net.silkmc.silk.fabric.registry + +import net.minecraft.core.Holder +import net.minecraft.core.registries.BuiltInRegistries +import net.minecraft.resources.ResourceLocation +import net.minecraft.sounds.SoundEvent +import net.minecraft.world.item.ArmorItem +import net.minecraft.world.item.ArmorMaterial +import net.minecraft.world.item.crafting.Ingredient + + +fun armorMaterialOf( + defensePoints: Map, + enchantability: Int, + equipSound: Holder, + repairIngredientSupplier: () -> Ingredient, + toughness: Float, + knockbackResistance: Float, + layerId: String, + dyeable: Boolean = false, + layerSuffix: String = "", +): Holder { + // Get the supported layers for the armor material + val layers = listOf( + ArmorMaterial.Layer(ResourceLocation.parse(layerId), layerSuffix, dyeable) + ) + return armorMaterialOf(defensePoints, enchantability, equipSound, repairIngredientSupplier, toughness, knockbackResistance, layers) +} + +fun armorMaterialOf( + defensePoints: Map, + enchantability: Int, + equipSound: Holder, + repairIngredientSupplier: () -> Ingredient, + toughness: Float, + knockbackResistance: Float, + layers: List, +): Holder { + return Holder.direct( + ArmorMaterial( + defensePoints, + enchantability, + equipSound, + repairIngredientSupplier, + layers, + toughness, + knockbackResistance, + ) + ) +} + +fun ArmorMaterial.register(id: ResourceLocation): Holder.Reference { + return BuiltInRegistries.ARMOR_MATERIAL.registerForHolder(id, this) +} + +fun ArmorMaterial.register(id: String): Holder.Reference { + return BuiltInRegistries.ARMOR_MATERIAL.registerForHolder(id, this) +} + +fun Holder.register(id: ResourceLocation): Holder { + return BuiltInRegistries.ARMOR_MATERIAL.registerForHolder(id, this.value) +} + +fun Holder.register(id: String): Holder { + return BuiltInRegistries.ARMOR_MATERIAL.registerForHolder(id, this.value) +} diff --git a/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/BlockEntityRegistry.kt b/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/BlockEntityRegistry.kt new file mode 100644 index 00000000..b510ed92 --- /dev/null +++ b/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/BlockEntityRegistry.kt @@ -0,0 +1,25 @@ +@file:Suppress("unused") + +package net.silkmc.silk.fabric.registry + +import net.minecraft.core.registries.BuiltInRegistries +import net.minecraft.resources.ResourceLocation +import net.minecraft.world.level.block.Block +import net.minecraft.world.level.block.entity.BlockEntity +import net.minecraft.world.level.block.entity.BlockEntityType + +fun blockEntityTypeOf( + vararg blocks: Block, + factory: BlockEntityType.BlockEntitySupplier, +): BlockEntityType { + return BlockEntityType.Builder.of(factory, *blocks).build() +} + +fun , V> T.register(id: ResourceLocation): T { + return BuiltInRegistries.BLOCK_ENTITY_TYPE.register(id, this) +} + +fun , V> T.register(id: String): T { + return BuiltInRegistries.BLOCK_ENTITY_TYPE.register(id, this) +} + diff --git a/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/BlockRegistry.kt b/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/BlockRegistry.kt new file mode 100644 index 00000000..5e7a8938 --- /dev/null +++ b/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/BlockRegistry.kt @@ -0,0 +1,32 @@ +@file:Suppress("unused") + +package net.silkmc.silk.fabric.registry + +import net.minecraft.core.registries.BuiltInRegistries +import net.minecraft.resources.ResourceLocation +import net.minecraft.world.level.block.Block +import net.minecraft.world.level.block.state.BlockBehaviour + + +inline fun blockPropertiesOf( + copiedBlock: BlockBehaviour? = null, + builder: BlockBehaviour.Properties.() -> Unit, +): BlockBehaviour.Properties { + return if (copiedBlock != null) + BlockBehaviour.Properties.ofFullCopy(copiedBlock).apply(builder) + else + BlockBehaviour.Properties.of().apply(builder) +} + +fun T.register(id: ResourceLocation): T { + for (blockState in stateDefinition.possibleStates) { + Block.BLOCK_STATE_REGISTRY.add(blockState) + blockState.initCache() + } + + return BuiltInRegistries.BLOCK.register(id, this) +} + +fun T.register(id: String): T { + return BuiltInRegistries.BLOCK.register(id, this) +} diff --git a/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/CreativeModeTabRegistry.kt b/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/CreativeModeTabRegistry.kt new file mode 100644 index 00000000..f4b65dee --- /dev/null +++ b/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/CreativeModeTabRegistry.kt @@ -0,0 +1,33 @@ +@file:Suppress("unused") + +package net.silkmc.silk.fabric.registry + +import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroup +import net.minecraft.core.registries.BuiltInRegistries +import net.minecraft.network.chat.Component +import net.minecraft.resources.ResourceLocation +import net.minecraft.world.item.CreativeModeTab +import net.minecraft.world.item.ItemStack + +fun creativeModeTabOf( + displayName: Component? = null, + icon: ItemStack? = null, + builder: CreativeModeTab.Builder.() -> Unit, +): CreativeModeTab { + val itemGroupBuilder = FabricItemGroup.builder() + if (displayName != null) + itemGroupBuilder.title(displayName) + + if (icon != null) + itemGroupBuilder.icon { icon } + + return itemGroupBuilder.apply(builder).build() +} + +fun T.register(id: ResourceLocation): T { + return BuiltInRegistries.CREATIVE_MODE_TAB.register(id, this) +} + +fun T.register(id: String): T { + return BuiltInRegistries.CREATIVE_MODE_TAB.register(id, this) +} diff --git a/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/CriterionRegistry.kt b/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/CriterionRegistry.kt new file mode 100644 index 00000000..889946cb --- /dev/null +++ b/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/CriterionRegistry.kt @@ -0,0 +1,11 @@ +@file:Suppress("unused") + +package net.silkmc.silk.fabric.registry + +import net.minecraft.advancements.CriterionTrigger +import net.minecraft.core.registries.BuiltInRegistries +import net.minecraft.resources.ResourceLocation + +fun > T.register(id: ResourceLocation): T = BuiltInRegistries.TRIGGER_TYPES.register(id, this) +fun > T.register(id: String): T = BuiltInRegistries.TRIGGER_TYPES.register(id, this) + diff --git a/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/DataComponentRegistry.kt b/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/DataComponentRegistry.kt new file mode 100644 index 00000000..9df2d2ba --- /dev/null +++ b/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/DataComponentRegistry.kt @@ -0,0 +1,14 @@ +@file:Suppress("unused") + +package net.silkmc.silk.fabric.registry + +import net.minecraft.core.component.DataComponentType +import kotlin.experimental.ExperimentalTypeInference + + +@OptIn(ExperimentalTypeInference::class) +fun dataComponentTypeOf(@BuilderInference builder: DataComponentType.Builder.() -> Unit): DataComponentType { + val dataComponentTypeBuilder = DataComponentType.builder() + + return dataComponentTypeBuilder.apply(builder).build() +} diff --git a/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/EntityTypeRegistry.kt b/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/EntityTypeRegistry.kt new file mode 100644 index 00000000..29d9a882 --- /dev/null +++ b/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/EntityTypeRegistry.kt @@ -0,0 +1,27 @@ +@file:Suppress("unused") + +package net.silkmc.silk.fabric.registry + +import net.minecraft.core.registries.BuiltInRegistries +import net.minecraft.resources.ResourceLocation +import net.minecraft.world.entity.Entity +import net.minecraft.world.entity.EntityType +import net.minecraft.world.entity.MobCategory + +fun entityTypeOf( + category: MobCategory, + factory: EntityType.EntityFactory, + builder: EntityType.Builder.() -> Unit, +): EntityType { + val entityTypeBuilder = EntityType.Builder.of(factory, category) + + return entityTypeBuilder.apply(builder).build() +} + +fun EntityType.register(id: ResourceLocation): EntityType { + return BuiltInRegistries.ENTITY_TYPE.register(id, this) +} + +fun EntityType.register(id: String): EntityType { + return BuiltInRegistries.ENTITY_TYPE.register(id, this) +} diff --git a/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/FluidRegistry.kt b/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/FluidRegistry.kt new file mode 100644 index 00000000..c7ff0329 --- /dev/null +++ b/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/FluidRegistry.kt @@ -0,0 +1,10 @@ +@file:Suppress("unused") + +package net.silkmc.silk.fabric.registry + +import net.minecraft.core.registries.BuiltInRegistries +import net.minecraft.resources.ResourceLocation +import net.minecraft.world.level.material.Fluid + +fun T.register(id: ResourceLocation): T = BuiltInRegistries.FLUID.register(id, this) +fun T.register(id: String): T = BuiltInRegistries.FLUID.register(id, this) diff --git a/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/GameRuleRegistry.kt b/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/GameRuleRegistry.kt new file mode 100644 index 00000000..555f4cc3 --- /dev/null +++ b/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/GameRuleRegistry.kt @@ -0,0 +1,63 @@ +@file:Suppress("unused") + +package net.silkmc.silk.fabric.registry + +import net.fabricmc.fabric.api.gamerule.v1.CustomGameRuleCategory +import net.fabricmc.fabric.api.gamerule.v1.GameRuleFactory +import net.fabricmc.fabric.api.gamerule.v1.GameRuleRegistry +import net.fabricmc.fabric.api.gamerule.v1.rule.DoubleRule +import net.fabricmc.fabric.api.gamerule.v1.rule.EnumRule +import net.minecraft.network.chat.Component +import net.minecraft.resources.ResourceLocation +import net.minecraft.server.MinecraftServer +import net.minecraft.world.level.GameRules +import kotlin.enums.enumEntries + +fun > gameruleOf(name: String, category: GameRules.Category, type: GameRules.Type): GameRules.Key { + return GameRuleRegistry.register(name, category, type) +} + +fun > gameruleOf(name: String, category: CustomGameRuleCategory, type: GameRules.Type): GameRules.Key { + return GameRuleRegistry.register(name, category, type) +} + +fun gameruleCategoryOf(id: ResourceLocation, name: Component): CustomGameRuleCategory { + return CustomGameRuleCategory(id, name) +} + +fun gameruleCategoryOf(id: String, name: Component): CustomGameRuleCategory { + return CustomGameRuleCategory(ResourceLocation.parse(id), name) +} + +fun booleanGamerule( + default: Boolean, + callback: (MinecraftServer, GameRules.BooleanValue) -> Unit = { _, _ -> }, +): GameRules.Type { + return GameRuleFactory.createBooleanRule(default, callback) +} + +fun intGamerule( + default: Int, + min: Int = Int.MIN_VALUE, + max: Int = Int.MAX_VALUE, + callback: (MinecraftServer, GameRules.IntegerValue) -> Unit = { _, _ -> }, +): GameRules.Type { + return GameRuleFactory.createIntRule(default, min, max, callback) +} + +fun doubleGamerule( + default: Double, + min: Double = Double.MIN_VALUE, + max: Double = Double.MAX_VALUE, + callback: (MinecraftServer, DoubleRule) -> Unit = { _, _ -> }, +): GameRules.Type { + return GameRuleFactory.createDoubleRule(default, min, max, callback) +} + +inline fun > createEnumRule( + default: E, + values: List = enumEntries(), + noinline callback: (MinecraftServer, EnumRule) -> Unit = { _, _ -> }, +): GameRules.Type> { + return GameRuleFactory.createEnumRule(default, values.toTypedArray(), callback) +} diff --git a/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/HolderExtensions.kt b/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/HolderExtensions.kt new file mode 100644 index 00000000..17ca9dbd --- /dev/null +++ b/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/HolderExtensions.kt @@ -0,0 +1,11 @@ +@file:Suppress("unused") + +package net.silkmc.silk.fabric.registry + +import net.minecraft.core.Holder + +fun T.asHolder(): Holder = Holder.direct(this) + +val Holder.value: T + get() = value() + diff --git a/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/ItemRegistry.kt b/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/ItemRegistry.kt new file mode 100644 index 00000000..84ed0826 --- /dev/null +++ b/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/ItemRegistry.kt @@ -0,0 +1,62 @@ +@file:Suppress("unused") + +package net.silkmc.silk.fabric.registry + +import net.minecraft.core.registries.BuiltInRegistries +import net.minecraft.resources.ResourceLocation +import net.minecraft.world.food.FoodProperties +import net.minecraft.world.item.Item +import net.minecraft.world.item.Rarity + + +inline fun itemPropertiesOf( + maxCount: Int? = null, + maxDamage: Int? = null, + rarity: Rarity? = null, + builder: Item.Properties.() -> Unit = {}, +): Item.Properties { + val properties = Item.Properties() + + if (maxCount != null) + properties.stacksTo(maxCount) + + if (maxDamage != null) + properties.durability(maxDamage) + + if (rarity != null) + properties.rarity(rarity) + + return properties.apply(builder) +} + +inline fun foodPropertiesOf( + nutrition: Int? = null, + saturation: Float? = null, + alwaysEdible: Boolean = false, + snack: Boolean = false, + builder: FoodProperties.Builder.() -> Unit = {}, +): FoodProperties { + val foodPropertiesBuilder = FoodProperties.Builder() + + if (nutrition != null) + foodPropertiesBuilder.nutrition(nutrition) + + if (saturation != null) + foodPropertiesBuilder.saturationModifier(saturation) + + if (alwaysEdible) + foodPropertiesBuilder.alwaysEdible() + + if (snack) + foodPropertiesBuilder.fast() + + return foodPropertiesBuilder.apply(builder).build() +} + +fun T.register(id: ResourceLocation): T { + return BuiltInRegistries.ITEM.register(id, this) +} + +fun T.register(id: String): T { + return BuiltInRegistries.ITEM.register(id, this) +} diff --git a/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/MobEffectRegistry.kt b/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/MobEffectRegistry.kt new file mode 100644 index 00000000..ebbd95a8 --- /dev/null +++ b/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/MobEffectRegistry.kt @@ -0,0 +1,20 @@ +@file:Suppress("unused") + +package net.silkmc.silk.fabric.registry + +import net.minecraft.core.Holder +import net.minecraft.core.registries.BuiltInRegistries +import net.minecraft.resources.ResourceLocation +import net.minecraft.world.effect.MobEffect + +fun T.register(id: ResourceLocation): Holder.Reference { + return BuiltInRegistries.MOB_EFFECT.registerForHolder(id, this) +} + +fun T.register(id: String): Holder.Reference { + return BuiltInRegistries.MOB_EFFECT.registerForHolder(id, this) +} + +fun T.asHolder(): Holder { + return BuiltInRegistries.MOB_EFFECT.wrapAsHolder(this) as Holder +} diff --git a/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/ParticleTypeRegistry.kt b/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/ParticleTypeRegistry.kt new file mode 100644 index 00000000..e025fc70 --- /dev/null +++ b/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/ParticleTypeRegistry.kt @@ -0,0 +1,10 @@ +@file:Suppress("unused") + +package net.silkmc.silk.fabric.registry + +import net.minecraft.core.particles.ParticleType +import net.minecraft.core.registries.BuiltInRegistries +import net.minecraft.resources.ResourceLocation + +fun > T.register(id: ResourceLocation): T = BuiltInRegistries.PARTICLE_TYPE.register(id, this) +fun > T.register(id: String): T = BuiltInRegistries.PARTICLE_TYPE.register(id, this) diff --git a/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/PotionRegistry.kt b/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/PotionRegistry.kt new file mode 100644 index 00000000..0d228e9d --- /dev/null +++ b/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/PotionRegistry.kt @@ -0,0 +1,46 @@ +@file:Suppress("unused") + +package net.silkmc.silk.fabric.registry + +import net.minecraft.core.Holder +import net.minecraft.core.registries.BuiltInRegistries +import net.minecraft.resources.ResourceLocation +import net.minecraft.world.effect.MobEffect +import net.minecraft.world.effect.MobEffectInstance +import net.minecraft.world.item.alchemy.Potion + +fun potionOf( + potionName: String? = null, + effect: Holder, + duration: Int = 0, + amplifier: Int = 0, + ambient: Boolean = false, + showParticles: Boolean = true, + showIcon: Boolean = showParticles, +): Potion { + val effectInstance = MobEffectInstance(effect, duration, amplifier, ambient, showParticles, showIcon) + return Potion(potionName, effectInstance) +} + +fun potionOf( + potionName: String? = null, + vararg effectInstances: MobEffectInstance, +): Potion { + return Potion(potionName, *effectInstances) +} + +fun potionOf( + potionName: String? = null, + effectsBuilder: MutableList.() -> Unit, +): Potion { + return Potion(potionName, *buildList(effectsBuilder).toTypedArray()) +} + +fun Potion.register(id: ResourceLocation): Potion { + return BuiltInRegistries.POTION.register(id, this) +} + +fun Potion.register(id: String): Potion { + return BuiltInRegistries.POTION.register(id, this) +} + diff --git a/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/RecipeRegistry.kt b/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/RecipeRegistry.kt new file mode 100644 index 00000000..a5436c1b --- /dev/null +++ b/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/RecipeRegistry.kt @@ -0,0 +1,26 @@ +@file:Suppress("unused") + +package net.silkmc.silk.fabric.registry + +import net.minecraft.core.registries.BuiltInRegistries +import net.minecraft.resources.ResourceLocation +import net.minecraft.world.item.crafting.RecipeSerializer +import net.minecraft.world.item.crafting.RecipeType + +fun > T.register(id: ResourceLocation): T { + return BuiltInRegistries.RECIPE_SERIALIZER.register(id, this) +} + +fun > T.register(id: String): T { + return BuiltInRegistries.RECIPE_SERIALIZER.register(id, this) +} + + +fun > T.register(id: ResourceLocation): T { + return BuiltInRegistries.RECIPE_TYPE.register(id, this) +} + +fun > T.register(id: String): T { + return BuiltInRegistries.RECIPE_TYPE.register(id, this) +} + diff --git a/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/RegistryExtensions.kt b/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/RegistryExtensions.kt new file mode 100644 index 00000000..15eb43a7 --- /dev/null +++ b/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/RegistryExtensions.kt @@ -0,0 +1,40 @@ +@file:Suppress("unused") + +package net.silkmc.silk.fabric.registry + +import net.minecraft.core.Holder +import net.minecraft.core.HolderSet +import net.minecraft.core.Registry +import net.minecraft.resources.ResourceKey +import net.minecraft.resources.ResourceLocation +import net.minecraft.tags.TagKey +import net.minecraft.world.level.block.Block +import net.minecraft.world.level.block.state.BlockState + +fun Registry.register(id: ResourceLocation, entry: T): T { + return Registry.register(this, id, entry) +} + +fun Registry.register(id: String, entry: T): T { + return Registry.register(this, ResourceLocation.parse(id), entry) +} + +fun Registry.register(key: ResourceKey, entry: T): T { + return Registry.register(this, key, entry) +} + +fun Registry.registerForHolder(id: ResourceLocation, entry: T): Holder.Reference { + return Registry.registerForHolder(this, id, entry) +} + +fun Registry.registerForHolder(id: String, entry: T): Holder.Reference { + return Registry.registerForHolder(this, ResourceLocation.parse(id), entry) +} + +fun Registry.registerForHolder(key: ResourceKey, entry: T): Holder.Reference { + return Registry.registerForHolder(this, key, entry) +} + +operator fun HolderSet.contains(state: BlockState): Boolean = state.`is`(this) + +operator fun TagKey.contains(state: BlockState): Boolean = state.`is`(this) diff --git a/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/ScreenHandlerRegistry.kt b/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/ScreenHandlerRegistry.kt new file mode 100644 index 00000000..e73157e3 --- /dev/null +++ b/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/ScreenHandlerRegistry.kt @@ -0,0 +1,19 @@ +@file:Suppress("unused") + +package net.silkmc.silk.fabric.registry + +import net.minecraft.client.gui.screens.MenuScreens +import net.minecraft.client.gui.screens.Screen +import net.minecraft.client.gui.screens.inventory.MenuAccess +import net.minecraft.core.registries.BuiltInRegistries +import net.minecraft.resources.ResourceLocation +import net.minecraft.world.inventory.AbstractContainerMenu +import net.minecraft.world.inventory.MenuType + +fun , V> T.register(id: ResourceLocation): T { + return BuiltInRegistries.MENU.register(id, this) +} + +fun MenuType.registerClient(factory: MenuScreens.ScreenConstructor) where U : Screen, U : MenuAccess { + MenuScreens.register(this, factory) +} diff --git a/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/SimpleRegistries.kt b/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/SimpleRegistries.kt new file mode 100644 index 00000000..64c03386 --- /dev/null +++ b/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/SimpleRegistries.kt @@ -0,0 +1,335 @@ +@file:Suppress("unused") + +package net.silkmc.silk.fabric.registry + +import net.minecraft.advancements.critereon.ItemSubPredicate +import net.minecraft.core.registries.BuiltInRegistries +import net.minecraft.network.chat.numbers.NumberFormat +import net.minecraft.network.chat.numbers.NumberFormatType +import net.minecraft.resources.ResourceLocation +import net.minecraft.util.valueproviders.FloatProvider +import net.minecraft.util.valueproviders.FloatProviderType +import net.minecraft.util.valueproviders.IntProvider +import net.minecraft.util.valueproviders.IntProviderType +import net.minecraft.world.entity.ai.attributes.Attribute +import net.minecraft.world.entity.ai.memory.MemoryModuleType +import net.minecraft.world.entity.ai.sensing.Sensor +import net.minecraft.world.entity.ai.sensing.SensorType +import net.minecraft.world.entity.ai.village.poi.PoiType +import net.minecraft.world.entity.animal.CatVariant +import net.minecraft.world.entity.animal.FrogVariant +import net.minecraft.world.entity.npc.VillagerProfession +import net.minecraft.world.entity.npc.VillagerType +import net.minecraft.world.entity.schedule.Activity +import net.minecraft.world.entity.schedule.Schedule +import net.minecraft.world.item.Instrument +import net.minecraft.world.level.block.entity.DecoratedPotPattern +import net.minecraft.world.level.gameevent.GameEvent +import net.minecraft.world.level.levelgen.blockpredicates.BlockPredicate +import net.minecraft.world.level.levelgen.blockpredicates.BlockPredicateType +import net.minecraft.world.level.levelgen.carver.CarverConfiguration +import net.minecraft.world.level.levelgen.carver.WorldCarver +import net.minecraft.world.level.levelgen.feature.Feature +import net.minecraft.world.level.levelgen.feature.configurations.FeatureConfiguration +import net.minecraft.world.level.levelgen.feature.featuresize.FeatureSize +import net.minecraft.world.level.levelgen.feature.featuresize.FeatureSizeType +import net.minecraft.world.level.levelgen.feature.foliageplacers.FoliagePlacer +import net.minecraft.world.level.levelgen.feature.foliageplacers.FoliagePlacerType +import net.minecraft.world.level.levelgen.feature.rootplacers.RootPlacer +import net.minecraft.world.level.levelgen.feature.rootplacers.RootPlacerType +import net.minecraft.world.level.levelgen.feature.stateproviders.BlockStateProvider +import net.minecraft.world.level.levelgen.feature.stateproviders.BlockStateProviderType +import net.minecraft.world.level.levelgen.feature.treedecorators.TreeDecorator +import net.minecraft.world.level.levelgen.feature.treedecorators.TreeDecoratorType +import net.minecraft.world.level.levelgen.feature.trunkplacers.TrunkPlacer +import net.minecraft.world.level.levelgen.feature.trunkplacers.TrunkPlacerType +import net.minecraft.world.level.levelgen.heightproviders.HeightProvider +import net.minecraft.world.level.levelgen.heightproviders.HeightProviderType +import net.minecraft.world.level.levelgen.placement.PlacementModifier +import net.minecraft.world.level.levelgen.placement.PlacementModifierType +import net.minecraft.world.level.levelgen.structure.Structure +import net.minecraft.world.level.levelgen.structure.StructureType +import net.minecraft.world.level.levelgen.structure.pieces.StructurePieceType +import net.minecraft.world.level.levelgen.structure.placement.StructurePlacement +import net.minecraft.world.level.levelgen.structure.placement.StructurePlacementType +import net.minecraft.world.level.levelgen.structure.pools.StructurePoolElement +import net.minecraft.world.level.levelgen.structure.pools.StructurePoolElementType +import net.minecraft.world.level.levelgen.structure.templatesystem.StructureProcessor +import net.minecraft.world.level.levelgen.structure.templatesystem.StructureProcessorType +import net.minecraft.world.level.saveddata.maps.MapDecorationType +import net.minecraft.world.level.storage.loot.entries.LootPoolEntryType +import net.minecraft.world.level.storage.loot.functions.LootItemFunction +import net.minecraft.world.level.storage.loot.functions.LootItemFunctionType +import net.minecraft.world.level.storage.loot.predicates.LootItemConditionType +import net.minecraft.world.level.storage.loot.providers.nbt.LootNbtProviderType +import net.minecraft.world.level.storage.loot.providers.number.LootNumberProviderType +import net.minecraft.world.level.storage.loot.providers.score.LootScoreProviderType + +fun GameEvent.register(id: ResourceLocation): GameEvent = BuiltInRegistries.GAME_EVENT.register(id, this) +fun GameEvent.register(id: String): GameEvent = BuiltInRegistries.GAME_EVENT.register(id, this) + + +fun Attribute.register(id: ResourceLocation): Attribute = BuiltInRegistries.ATTRIBUTE.register(id, this) +fun Attribute.register(id: String): Attribute = BuiltInRegistries.ATTRIBUTE.register(id, this) + + +fun VillagerType.register(id: ResourceLocation): VillagerType = BuiltInRegistries.VILLAGER_TYPE.register(id, this) +fun VillagerType.register(id: String): VillagerType = BuiltInRegistries.VILLAGER_TYPE.register(id, this) + + +fun VillagerProfession.register(id: ResourceLocation): VillagerProfession = BuiltInRegistries.VILLAGER_PROFESSION.register(id, this) +fun VillagerProfession.register(id: String): VillagerProfession = BuiltInRegistries.VILLAGER_PROFESSION.register(id, this) + + +fun PoiType.register(id: ResourceLocation): PoiType = BuiltInRegistries.POINT_OF_INTEREST_TYPE.register(id, this) +fun PoiType.register(id: String): PoiType = BuiltInRegistries.POINT_OF_INTEREST_TYPE.register(id, this) + + +fun MemoryModuleType.register(id: ResourceLocation): MemoryModuleType = BuiltInRegistries.MEMORY_MODULE_TYPE.register(id, this) +fun MemoryModuleType.register(id: String): MemoryModuleType = BuiltInRegistries.MEMORY_MODULE_TYPE.register(id, this) + + +fun > SensorType.register(id: ResourceLocation): SensorType = BuiltInRegistries.SENSOR_TYPE.register(id, this) +fun > SensorType.register(id: String): SensorType = BuiltInRegistries.SENSOR_TYPE.register(id, this) + + +fun Schedule.register(id: ResourceLocation): Schedule = BuiltInRegistries.SCHEDULE.register(id, this) +fun Schedule.register(id: String): Schedule = BuiltInRegistries.SCHEDULE.register(id, this) + + +fun Activity.register(id: ResourceLocation): Activity = BuiltInRegistries.ACTIVITY.register(id, this) +fun Activity.register(id: String): Activity = BuiltInRegistries.ACTIVITY.register(id, this) + + +fun LootPoolEntryType.register(id: ResourceLocation): LootPoolEntryType = BuiltInRegistries.LOOT_POOL_ENTRY_TYPE.register(id, this) +fun LootPoolEntryType.register(id: String): LootPoolEntryType = BuiltInRegistries.LOOT_POOL_ENTRY_TYPE.register(id, this) + + +fun LootItemFunctionType.register(id: ResourceLocation): LootItemFunctionType { + return BuiltInRegistries.LOOT_FUNCTION_TYPE.register(id, this) +} + +fun LootItemFunctionType.register(id: String): LootItemFunctionType { + return BuiltInRegistries.LOOT_FUNCTION_TYPE.register(id, this) +} + + +fun LootItemConditionType.register(id: ResourceLocation): LootItemConditionType = BuiltInRegistries.LOOT_CONDITION_TYPE.register(id, this) +fun LootItemConditionType.register(id: String): LootItemConditionType = BuiltInRegistries.LOOT_CONDITION_TYPE.register(id, this) + + +fun LootNumberProviderType.register(id: ResourceLocation): LootNumberProviderType { + return BuiltInRegistries.LOOT_NUMBER_PROVIDER_TYPE.register(id, this) +} + +fun LootNumberProviderType.register(id: String): LootNumberProviderType { + return BuiltInRegistries.LOOT_NUMBER_PROVIDER_TYPE.register(id, this) +} + + +fun LootNbtProviderType.register(id: ResourceLocation): LootNbtProviderType = BuiltInRegistries.LOOT_NBT_PROVIDER_TYPE.register(id, this) +fun LootNbtProviderType.register(id: String): LootNbtProviderType = BuiltInRegistries.LOOT_NBT_PROVIDER_TYPE.register(id, this) + + +fun LootScoreProviderType.register(id: ResourceLocation): LootScoreProviderType { + return BuiltInRegistries.LOOT_SCORE_PROVIDER_TYPE.register(id, this) +} + +fun LootScoreProviderType.register(id: String): LootScoreProviderType { + return BuiltInRegistries.LOOT_SCORE_PROVIDER_TYPE.register(id, this) +} + + +fun FloatProviderType.register(id: ResourceLocation): FloatProviderType { + return BuiltInRegistries.FLOAT_PROVIDER_TYPE.register(id, this) +} + +fun FloatProviderType.register(id: String): FloatProviderType { + return BuiltInRegistries.FLOAT_PROVIDER_TYPE.register(id, this) +} + + +fun IntProviderType.register(id: ResourceLocation): IntProviderType { + return BuiltInRegistries.INT_PROVIDER_TYPE.register(id, this) +} + +fun IntProviderType.register(id: String): IntProviderType { + return BuiltInRegistries.INT_PROVIDER_TYPE.register(id, this) +} + + +fun HeightProviderType.register(id: ResourceLocation): HeightProviderType { + return BuiltInRegistries.HEIGHT_PROVIDER_TYPE.register(id, this) +} + +fun HeightProviderType.register(id: String): HeightProviderType { + return BuiltInRegistries.HEIGHT_PROVIDER_TYPE.register(id, this) +} + + +fun BlockPredicateType.register(id: ResourceLocation): BlockPredicateType { + return BuiltInRegistries.BLOCK_PREDICATE_TYPE.register(id, this) +} + +fun BlockPredicateType.register(id: String): BlockPredicateType { + return BuiltInRegistries.BLOCK_PREDICATE_TYPE.register(id, this) +} + + +fun WorldCarver.register(id: ResourceLocation): WorldCarver { + return BuiltInRegistries.CARVER.register(id, this) +} + +fun WorldCarver.register(id: String): WorldCarver { + return BuiltInRegistries.CARVER.register(id, this) +} + + +fun Feature.register(id: ResourceLocation): Feature { + return BuiltInRegistries.FEATURE.register(id, this) +} + +fun Feature.register(id: String): Feature { + return BuiltInRegistries.FEATURE.register(id, this) +} + + +fun StructurePlacementType.register(id: ResourceLocation): StructurePlacementType { + return BuiltInRegistries.STRUCTURE_PLACEMENT.register(id, this) +} + +fun StructurePlacementType.register(id: String): StructurePlacementType { + return BuiltInRegistries.STRUCTURE_PLACEMENT.register(id, this) +} + + +fun StructurePieceType.register(id: ResourceLocation): StructurePieceType = BuiltInRegistries.STRUCTURE_PIECE.register(id, this) +fun StructurePieceType.register(id: String): StructurePieceType = BuiltInRegistries.STRUCTURE_PIECE.register(id, this) + + +fun StructureType.register(id: ResourceLocation): StructureType { + return BuiltInRegistries.STRUCTURE_TYPE.register(id, this) +} + +fun StructureType.register(id: String): StructureType { + return BuiltInRegistries.STRUCTURE_TYPE.register(id, this) +} + + +fun PlacementModifierType.register(id: ResourceLocation): PlacementModifierType { + return BuiltInRegistries.PLACEMENT_MODIFIER_TYPE.register(id, this) +} + +fun PlacementModifierType.register(id: String): PlacementModifierType { + return BuiltInRegistries.PLACEMENT_MODIFIER_TYPE.register(id, this) +} + + +fun BlockStateProviderType.register(id: ResourceLocation): BlockStateProviderType { + return BuiltInRegistries.BLOCKSTATE_PROVIDER_TYPE.register(id, this) +} + +fun BlockStateProviderType.register(id: String): BlockStateProviderType { + return BuiltInRegistries.BLOCKSTATE_PROVIDER_TYPE.register(id, this) +} + + +fun FoliagePlacerType.register(id: ResourceLocation): FoliagePlacerType { + return BuiltInRegistries.FOLIAGE_PLACER_TYPE.register(id, this) +} + +fun FoliagePlacerType.register(id: String): FoliagePlacerType { + return BuiltInRegistries.FOLIAGE_PLACER_TYPE.register(id, this) +} + + +fun TrunkPlacerType.register(id: ResourceLocation): TrunkPlacerType { + return BuiltInRegistries.TRUNK_PLACER_TYPE.register(id, this) +} + +fun TrunkPlacerType.register(id: String): TrunkPlacerType { + return BuiltInRegistries.TRUNK_PLACER_TYPE.register(id, this) +} + + +fun RootPlacerType.register(id: ResourceLocation): RootPlacerType { + return BuiltInRegistries.ROOT_PLACER_TYPE.register(id, this) +} + +fun RootPlacerType.register(id: String): RootPlacerType { + return BuiltInRegistries.ROOT_PLACER_TYPE.register(id, this) +} + + +fun TreeDecoratorType.register(id: ResourceLocation): TreeDecoratorType { + return BuiltInRegistries.TREE_DECORATOR_TYPE.register(id, this) +} + +fun TreeDecoratorType.register(id: String): TreeDecoratorType { + return BuiltInRegistries.TREE_DECORATOR_TYPE.register(id, this) +} + + +fun FeatureSizeType.register(id: ResourceLocation): FeatureSizeType { + return BuiltInRegistries.FEATURE_SIZE_TYPE.register(id, this) +} + +fun FeatureSizeType.register(id: String): FeatureSizeType { + return BuiltInRegistries.FEATURE_SIZE_TYPE.register(id, this) +} + + +fun StructureProcessorType.register(id: ResourceLocation): StructureProcessorType { + return BuiltInRegistries.STRUCTURE_PROCESSOR.register(id, this) +} + +fun StructureProcessorType.register(id: String): StructureProcessorType { + return BuiltInRegistries.STRUCTURE_PROCESSOR.register(id, this) +} + + +fun StructurePoolElementType.register(id: ResourceLocation): StructurePoolElementType { + return BuiltInRegistries.STRUCTURE_POOL_ELEMENT.register(id, this) +} + +fun StructurePoolElementType.register(id: String): StructurePoolElementType { + return BuiltInRegistries.STRUCTURE_POOL_ELEMENT.register(id, this) +} + + +fun CatVariant.register(id: ResourceLocation): CatVariant = BuiltInRegistries.CAT_VARIANT.register(id, this) +fun CatVariant.register(id: String): CatVariant = BuiltInRegistries.CAT_VARIANT.register(id, this) + + +fun FrogVariant.register(id: ResourceLocation): FrogVariant = BuiltInRegistries.FROG_VARIANT.register(id, this) +fun FrogVariant.register(id: String): FrogVariant = BuiltInRegistries.FROG_VARIANT.register(id, this) + + +fun Instrument.register(id: ResourceLocation): Instrument = BuiltInRegistries.INSTRUMENT.register(id, this) +fun Instrument.register(id: String): Instrument = BuiltInRegistries.INSTRUMENT.register(id, this) + + +fun DecoratedPotPattern.register(id: ResourceLocation): DecoratedPotPattern = BuiltInRegistries.DECORATED_POT_PATTERN.register(id, this) +fun DecoratedPotPattern.register(id: String): DecoratedPotPattern = BuiltInRegistries.DECORATED_POT_PATTERN.register(id, this) + + +fun NumberFormatType.register(id: ResourceLocation): NumberFormatType { + return BuiltInRegistries.NUMBER_FORMAT_TYPE.register(id, this) +} + +fun NumberFormatType.register(id: String): NumberFormatType { + return BuiltInRegistries.NUMBER_FORMAT_TYPE.register(id, this) +} + + +fun ItemSubPredicate.Type.register(id: ResourceLocation): ItemSubPredicate.Type { + return BuiltInRegistries.ITEM_SUB_PREDICATE_TYPE.register(id, this) +} + +fun ItemSubPredicate.Type.register(id: String): ItemSubPredicate.Type { + return BuiltInRegistries.ITEM_SUB_PREDICATE_TYPE.register(id, this) +} + + +fun MapDecorationType.register(id: ResourceLocation): MapDecorationType = BuiltInRegistries.MAP_DECORATION_TYPE.register(id, this) +fun MapDecorationType.register(id: String): MapDecorationType = BuiltInRegistries.MAP_DECORATION_TYPE.register(id, this) diff --git a/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/SountEventRegistry.kt b/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/SountEventRegistry.kt new file mode 100644 index 00000000..66605e0d --- /dev/null +++ b/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/SountEventRegistry.kt @@ -0,0 +1,44 @@ +@file:Suppress("unused") + +package net.silkmc.silk.fabric.registry + +import net.minecraft.core.Holder +import net.minecraft.core.registries.BuiltInRegistries +import net.minecraft.resources.ResourceLocation +import net.minecraft.server.level.ServerPlayer +import net.minecraft.sounds.SoundEvent + +fun soundEventOf( + id: ResourceLocation, + range: Float? = null, +): SoundEvent { + return if (range != null) + SoundEvent.createFixedRangeEvent(id, range) + else + SoundEvent.createVariableRangeEvent(id) +} + +fun soundEventOf( + id: String, + range: Float? = null, +): SoundEvent { + val entity: ServerPlayer + return soundEventOf(ResourceLocation.parse(id), range) +} + +fun SoundEvent.register(id: ResourceLocation = this.location): SoundEvent { + return BuiltInRegistries.SOUND_EVENT.register(id, this) +} + +fun SoundEvent.register(id: String): SoundEvent { + return BuiltInRegistries.SOUND_EVENT.register(id, this) +} + + +fun SoundEvent.registerForHolder(id: ResourceLocation = this.location): Holder.Reference { + return BuiltInRegistries.SOUND_EVENT.registerForHolder(id, this) +} + +fun SoundEvent.registerForHolder(id: String): Holder.Reference { + return BuiltInRegistries.SOUND_EVENT.registerForHolder(id, this) +} diff --git a/silk-paper/build.gradle.kts b/silk-paper/build.gradle.kts index 50b435ec..e93dec96 100644 --- a/silk-paper/build.gradle.kts +++ b/silk-paper/build.gradle.kts @@ -27,7 +27,7 @@ dependencies { paperweight.paperDevBundle("${paperMinecraftVersion}-R0.1-SNAPSHOT") // include all regular silk modules in their dev jar form - for (module in BuildConstants.uploadModules) { + for (module in BuildConstants.commonModules) { if (project.version != rootProject.version) { val moduleDep = implementation("net.silkmc:silk-${module}:${project.version}:dev") { artifacts.removeIf { it.classifier != "dev" } From 395a4ee97e115deb424d9fbf3f844f17322c7c47 Mon Sep 17 00:00:00 2001 From: solonovamax Date: Mon, 27 Jan 2025 13:28:53 -0500 Subject: [PATCH 2/2] Update to 1.21.4, enable silk-fabric module Signed-off-by: solonovamax --- buildSrc/src/main/kotlin/BuildConstants.kt | 2 +- settings.gradle.kts | 1 + .../fabric/registry/ArmorMaterialRegistry.kt | 74 +++++++------------ .../fabric/registry/BlockEntityRegistry.kt | 5 +- .../fabric/registry/EntityTypeRegistry.kt | 4 +- .../silk/fabric/registry/ItemRegistry.kt | 4 - .../silk/fabric/registry/ResourceKey.kt | 15 ++++ .../silk/fabric/registry/SimpleRegistries.kt | 6 -- .../fabric/registry/SountEventRegistry.kt | 2 - 9 files changed, 48 insertions(+), 65 deletions(-) create mode 100644 silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/ResourceKey.kt diff --git a/buildSrc/src/main/kotlin/BuildConstants.kt b/buildSrc/src/main/kotlin/BuildConstants.kt index df36e955..b034e2b1 100644 --- a/buildSrc/src/main/kotlin/BuildConstants.kt +++ b/buildSrc/src/main/kotlin/BuildConstants.kt @@ -20,7 +20,7 @@ object BuildConstants { const val paperMinecraftVersion = "1.21.1" const val fabricLoaderVersion = "0.16.10" const val fabricLanguageKotlinVersion = "1.12.3+kotlin.2.0.21" - const val fabricApiVersion = "0.100.8+1.21" + const val fabricApiVersion = "0.115.0+$minecraftVersion" const val kotestVersion = "5.9.1" const val mockkVersion = "1.13.12" diff --git a/settings.gradle.kts b/settings.gradle.kts index a4d32d17..6e213a72 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -20,5 +20,6 @@ include("$projectName-network") include("$projectName-persistence") include("$projectName-paper") +include("$projectName-fabric") include("$projectName-testmod") diff --git a/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/ArmorMaterialRegistry.kt b/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/ArmorMaterialRegistry.kt index ebf0190b..e02af0b7 100644 --- a/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/ArmorMaterialRegistry.kt +++ b/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/ArmorMaterialRegistry.kt @@ -3,66 +3,42 @@ package net.silkmc.silk.fabric.registry import net.minecraft.core.Holder -import net.minecraft.core.registries.BuiltInRegistries +import net.minecraft.resources.ResourceKey import net.minecraft.resources.ResourceLocation import net.minecraft.sounds.SoundEvent -import net.minecraft.world.item.ArmorItem -import net.minecraft.world.item.ArmorMaterial -import net.minecraft.world.item.crafting.Ingredient - +import net.minecraft.tags.TagKey +import net.minecraft.world.item.Item +import net.minecraft.world.item.equipment.ArmorMaterial +import net.minecraft.world.item.equipment.ArmorType +import net.minecraft.world.item.equipment.EquipmentAsset +import net.minecraft.world.item.equipment.EquipmentAssets fun armorMaterialOf( - defensePoints: Map, + baseDurability: Int, + defensePoints: Map, enchantability: Int, equipSound: Holder, - repairIngredientSupplier: () -> Ingredient, toughness: Float, knockbackResistance: Float, - layerId: String, - dyeable: Boolean = false, - layerSuffix: String = "", -): Holder { - // Get the supported layers for the armor material - val layers = listOf( - ArmorMaterial.Layer(ResourceLocation.parse(layerId), layerSuffix, dyeable) + repairIngredient: TagKey, + layers: ResourceKey, +): ArmorMaterial { + return ArmorMaterial( + baseDurability, + defensePoints, + enchantability, + equipSound, + toughness, + knockbackResistance, + repairIngredient, + layers, ) - return armorMaterialOf(defensePoints, enchantability, equipSound, repairIngredientSupplier, toughness, knockbackResistance, layers) } -fun armorMaterialOf( - defensePoints: Map, - enchantability: Int, - equipSound: Holder, - repairIngredientSupplier: () -> Ingredient, - toughness: Float, - knockbackResistance: Float, - layers: List, -): Holder { - return Holder.direct( - ArmorMaterial( - defensePoints, - enchantability, - equipSound, - repairIngredientSupplier, - layers, - toughness, - knockbackResistance, - ) - ) -} - -fun ArmorMaterial.register(id: ResourceLocation): Holder.Reference { - return BuiltInRegistries.ARMOR_MATERIAL.registerForHolder(id, this) -} +fun armorMaterialKeyOf(id: ResourceLocation): ResourceKey = resourceKeyOf(EquipmentAssets.ROOT_ID, id) -fun ArmorMaterial.register(id: String): Holder.Reference { - return BuiltInRegistries.ARMOR_MATERIAL.registerForHolder(id, this) -} - -fun Holder.register(id: ResourceLocation): Holder { - return BuiltInRegistries.ARMOR_MATERIAL.registerForHolder(id, this.value) -} +fun armorMaterialKeyOf(id: String): ResourceKey = armorMaterialKeyOf(ResourceLocation.parse(id)) -fun Holder.register(id: String): Holder { - return BuiltInRegistries.ARMOR_MATERIAL.registerForHolder(id, this.value) +fun armorMaterialKeyOf(namespace: String, path: String): ResourceKey { + return armorMaterialKeyOf(ResourceLocation.fromNamespaceAndPath(namespace, path)) } diff --git a/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/BlockEntityRegistry.kt b/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/BlockEntityRegistry.kt index b510ed92..099a9736 100644 --- a/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/BlockEntityRegistry.kt +++ b/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/BlockEntityRegistry.kt @@ -2,6 +2,7 @@ package net.silkmc.silk.fabric.registry +import net.fabricmc.fabric.api.`object`.builder.v1.block.entity.FabricBlockEntityTypeBuilder import net.minecraft.core.registries.BuiltInRegistries import net.minecraft.resources.ResourceLocation import net.minecraft.world.level.block.Block @@ -10,9 +11,9 @@ import net.minecraft.world.level.block.entity.BlockEntityType fun blockEntityTypeOf( vararg blocks: Block, - factory: BlockEntityType.BlockEntitySupplier, + factory: FabricBlockEntityTypeBuilder.Factory, ): BlockEntityType { - return BlockEntityType.Builder.of(factory, *blocks).build() + return FabricBlockEntityTypeBuilder.create(factory, *blocks).build() } fun , V> T.register(id: ResourceLocation): T { diff --git a/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/EntityTypeRegistry.kt b/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/EntityTypeRegistry.kt index 29d9a882..93cd7a44 100644 --- a/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/EntityTypeRegistry.kt +++ b/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/EntityTypeRegistry.kt @@ -3,19 +3,21 @@ package net.silkmc.silk.fabric.registry import net.minecraft.core.registries.BuiltInRegistries +import net.minecraft.core.registries.Registries import net.minecraft.resources.ResourceLocation import net.minecraft.world.entity.Entity import net.minecraft.world.entity.EntityType import net.minecraft.world.entity.MobCategory fun entityTypeOf( + id: ResourceLocation, category: MobCategory, factory: EntityType.EntityFactory, builder: EntityType.Builder.() -> Unit, ): EntityType { val entityTypeBuilder = EntityType.Builder.of(factory, category) - return entityTypeBuilder.apply(builder).build() + return entityTypeBuilder.apply(builder).build(resourceKeyOf(Registries.ENTITY_TYPE, id)) } fun EntityType.register(id: ResourceLocation): EntityType { diff --git a/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/ItemRegistry.kt b/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/ItemRegistry.kt index 84ed0826..1e6c0c59 100644 --- a/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/ItemRegistry.kt +++ b/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/ItemRegistry.kt @@ -33,7 +33,6 @@ inline fun foodPropertiesOf( nutrition: Int? = null, saturation: Float? = null, alwaysEdible: Boolean = false, - snack: Boolean = false, builder: FoodProperties.Builder.() -> Unit = {}, ): FoodProperties { val foodPropertiesBuilder = FoodProperties.Builder() @@ -47,9 +46,6 @@ inline fun foodPropertiesOf( if (alwaysEdible) foodPropertiesBuilder.alwaysEdible() - if (snack) - foodPropertiesBuilder.fast() - return foodPropertiesBuilder.apply(builder).build() } diff --git a/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/ResourceKey.kt b/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/ResourceKey.kt new file mode 100644 index 00000000..4db0a1d0 --- /dev/null +++ b/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/ResourceKey.kt @@ -0,0 +1,15 @@ +@file:Suppress("unused") + +package net.silkmc.silk.fabric.registry + +import net.minecraft.core.Registry +import net.minecraft.resources.ResourceKey +import net.minecraft.resources.ResourceLocation + +fun resourceKeyOf(resourceKey: ResourceKey>, resourceLocation: ResourceLocation): ResourceKey { + return ResourceKey.create(resourceKey, resourceLocation) +} + +fun registryKeyOf(resourceLocation: ResourceLocation): ResourceKey> { + return ResourceKey.createRegistryKey(resourceLocation) +} \ No newline at end of file diff --git a/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/SimpleRegistries.kt b/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/SimpleRegistries.kt index 64c03386..73270336 100644 --- a/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/SimpleRegistries.kt +++ b/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/SimpleRegistries.kt @@ -22,7 +22,6 @@ import net.minecraft.world.entity.npc.VillagerProfession import net.minecraft.world.entity.npc.VillagerType import net.minecraft.world.entity.schedule.Activity import net.minecraft.world.entity.schedule.Schedule -import net.minecraft.world.item.Instrument import net.minecraft.world.level.block.entity.DecoratedPotPattern import net.minecraft.world.level.gameevent.GameEvent import net.minecraft.world.level.levelgen.blockpredicates.BlockPredicate @@ -304,11 +303,6 @@ fun CatVariant.register(id: String): CatVariant = BuiltInRegistries.CAT_VARIANT. fun FrogVariant.register(id: ResourceLocation): FrogVariant = BuiltInRegistries.FROG_VARIANT.register(id, this) fun FrogVariant.register(id: String): FrogVariant = BuiltInRegistries.FROG_VARIANT.register(id, this) - -fun Instrument.register(id: ResourceLocation): Instrument = BuiltInRegistries.INSTRUMENT.register(id, this) -fun Instrument.register(id: String): Instrument = BuiltInRegistries.INSTRUMENT.register(id, this) - - fun DecoratedPotPattern.register(id: ResourceLocation): DecoratedPotPattern = BuiltInRegistries.DECORATED_POT_PATTERN.register(id, this) fun DecoratedPotPattern.register(id: String): DecoratedPotPattern = BuiltInRegistries.DECORATED_POT_PATTERN.register(id, this) diff --git a/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/SountEventRegistry.kt b/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/SountEventRegistry.kt index 66605e0d..bc006db8 100644 --- a/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/SountEventRegistry.kt +++ b/silk-fabric/src/main/kotlin/net/silkmc/silk/fabric/registry/SountEventRegistry.kt @@ -5,7 +5,6 @@ package net.silkmc.silk.fabric.registry import net.minecraft.core.Holder import net.minecraft.core.registries.BuiltInRegistries import net.minecraft.resources.ResourceLocation -import net.minecraft.server.level.ServerPlayer import net.minecraft.sounds.SoundEvent fun soundEventOf( @@ -22,7 +21,6 @@ fun soundEventOf( id: String, range: Float? = null, ): SoundEvent { - val entity: ServerPlayer return soundEventOf(ResourceLocation.parse(id), range) }