basically done with data generation now. model generation is pretty much fully working/automated
build / build (push) Failing after 3m31s
build / build (push) Failing after 3m31s
This commit is contained in:
@@ -1,15 +1,18 @@
|
||||
package dev.zxq5
|
||||
|
||||
import dev.zxq5.items.template.GenericItemSet
|
||||
import dev.zxq5.items.template.ItemTagAdder
|
||||
import dev.zxq5.items.ModItems
|
||||
import dev.zxq5.items.template.GenericItemSet
|
||||
import net.fabricmc.api.ModInitializer
|
||||
import net.fabricmc.fabric.api.datagen.v1.FabricPackOutput
|
||||
import net.fabricmc.fabric.api.datagen.v1.provider.FabricLanguageProvider
|
||||
import net.fabricmc.fabric.api.datagen.v1.provider.FabricRecipeProvider
|
||||
import net.fabricmc.fabric.api.datagen.v1.provider.FabricTagsProvider
|
||||
import net.minecraft.core.HolderLookup
|
||||
import net.minecraft.core.registries.BuiltInRegistries
|
||||
import net.minecraft.core.registries.Registries
|
||||
import net.minecraft.data.recipes.RecipeOutput
|
||||
import net.minecraft.data.recipes.RecipeProvider
|
||||
import net.minecraft.resources.ResourceKey
|
||||
import org.slf4j.LoggerFactory
|
||||
import java.util.concurrent.CompletableFuture
|
||||
|
||||
@@ -34,9 +37,7 @@ class ModRecipeProvider(
|
||||
): RecipeProvider {
|
||||
return object : RecipeProvider(registries, exporter) {
|
||||
override fun buildRecipes() {
|
||||
print("GENERATING ALL RECIPES")
|
||||
GenericItemSet.all.forEach {
|
||||
print("GENERATING RECIPES FOR" + it.items.toString())
|
||||
it.generateRecipes(registries, exporter)
|
||||
}
|
||||
}
|
||||
@@ -49,7 +50,25 @@ class ModRecipeProvider(
|
||||
class ModItemTagProvider(output: FabricPackOutput, registriesFuture: CompletableFuture<HolderLookup.Provider>) :
|
||||
FabricTagsProvider.ItemTagsProvider(output, registriesFuture) {
|
||||
override fun addTags(provider: HolderLookup.Provider) {
|
||||
val adder = ItemTagAdder(this)
|
||||
GenericItemSet.all.forEach { it.generateItemTags(adder) }
|
||||
GenericItemSet.all.forEach {
|
||||
it.generateItemTags(provider).forEach { (item, keys) ->
|
||||
keys.forEach { key ->
|
||||
builder(key)
|
||||
.add(ResourceKey.create(Registries.ITEM, BuiltInRegistries.ITEM.getKey(item)))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class ModLanguageProvider(
|
||||
output: FabricPackOutput, registriesFuture: CompletableFuture<HolderLookup.Provider>) :
|
||||
FabricLanguageProvider(output, registriesFuture) {
|
||||
|
||||
override fun generateTranslations(
|
||||
registryLookup: HolderLookup.Provider,
|
||||
translationBuilder: TranslationBuilder
|
||||
) {
|
||||
GenericItemSet.all.forEach { it.generateTranslations(translationBuilder) }
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
package dev.zxq5.items
|
||||
|
||||
import dev.zxq5.Fantasysmp
|
||||
import dev.zxq5.items.template.GenericItemSet
|
||||
import dev.zxq5.items.sets.Dragonite
|
||||
import dev.zxq5.items.sets.Ender
|
||||
import dev.zxq5.items.sets.Witherite
|
||||
import dev.zxq5.items.template.GenericItemSet
|
||||
import net.fabricmc.fabric.api.creativetab.v1.FabricCreativeModeTab
|
||||
import net.minecraft.core.Registry
|
||||
import net.minecraft.core.registries.BuiltInRegistries
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
package dev.zxq5.items.sets
|
||||
|
||||
import dev.zxq5.Fantasysmp
|
||||
import dev.zxq5.items.template.ArmorSet
|
||||
import dev.zxq5.items.template.EquipmentLayer
|
||||
import dev.zxq5.items.template.GenericGearSet
|
||||
import dev.zxq5.items.ModItems.register
|
||||
import dev.zxq5.items.template.registerItem
|
||||
import dev.zxq5.items.template.provideDelegate
|
||||
import dev.zxq5.items.template.ModelSpec
|
||||
import net.fabricmc.fabric.api.entity.event.v1.ServerLivingEntityEvents
|
||||
import net.minecraft.ChatFormatting
|
||||
import net.minecraft.core.component.DataComponents
|
||||
import net.minecraft.core.particles.ParticleTypes
|
||||
import net.minecraft.core.particles.PowerParticleOption
|
||||
@@ -16,7 +17,6 @@ import net.minecraft.util.Unit
|
||||
import net.minecraft.world.InteractionHand
|
||||
import net.minecraft.world.InteractionResult
|
||||
import net.minecraft.world.damagesource.DamageSource
|
||||
import net.minecraft.world.damagesource.DamageSources
|
||||
import net.minecraft.world.damagesource.DamageTypes
|
||||
import net.minecraft.world.entity.Entity
|
||||
import net.minecraft.world.entity.player.Player
|
||||
@@ -24,9 +24,8 @@ import net.minecraft.world.item.Item
|
||||
import net.minecraft.world.item.Items
|
||||
import net.minecraft.world.item.ToolMaterial
|
||||
import net.minecraft.world.item.component.UseCooldown
|
||||
import net.minecraft.world.item.equipment.*
|
||||
import net.minecraft.world.item.equipment.ArmorType
|
||||
import net.minecraft.world.level.Level
|
||||
import kotlin.getValue
|
||||
|
||||
|
||||
object Dragonite: GenericGearSet() {
|
||||
@@ -34,9 +33,24 @@ object Dragonite: GenericGearSet() {
|
||||
override val materialDefinition
|
||||
get() = super.materialDefinition.copy(assetId = materialKey)
|
||||
|
||||
val SCALE by registerItem("dragon_scale", ::Item)
|
||||
override val equipmentAssetSpec = super.equipmentAssetSpec.copy(
|
||||
layers = super.equipmentAssetSpec.layers + ("wings" to listOf(
|
||||
EquipmentLayer(
|
||||
"${Fantasysmp.MOD_ID}:dragonite",
|
||||
usePlayerTexture = false
|
||||
)
|
||||
))
|
||||
)
|
||||
|
||||
const val LORE = " forged from the essence of dragons"
|
||||
override val lore_style = ChatFormatting.DARK_PURPLE
|
||||
|
||||
val SCALE by registerItem("dragon_scale", ::Item) {
|
||||
name("Dragon Scale")
|
||||
}
|
||||
|
||||
val INGOT by registerItem("dragonite_ingot", ::Item) {
|
||||
name("Dragonite Ingot")
|
||||
shapedRecipe("SBS", "CXC", "SBS", key=mapOf<Char, Item>(
|
||||
'S' to Items.SHULKER_SHELL,
|
||||
'X' to SCALE,
|
||||
@@ -46,42 +60,58 @@ object Dragonite: GenericGearSet() {
|
||||
}
|
||||
|
||||
val SWORD by registerItem("dragonite_sword", ::DragoniteSword) {
|
||||
name("Dragonite Sword")
|
||||
lore("A sword$LORE")
|
||||
model(ModelSpec.Handheld)
|
||||
properties {
|
||||
enchantable(armorMaterial.enchantmentValue)
|
||||
.component(DataComponents.USE_COOLDOWN, UseCooldown(2f))
|
||||
.sword(ToolMaterial.NETHERITE, 3F, -2.4F)
|
||||
}
|
||||
smithingUpgrade(Items.END_CRYSTAL, Items.NETHERITE_SWORD, INGOT)
|
||||
tags("swords")
|
||||
}
|
||||
|
||||
val HELMET by registerItem("dragonite_helmet", ::Item) {
|
||||
name("Dragonite Helmet")
|
||||
lore("A helmet$LORE")
|
||||
properties {
|
||||
humanoidArmor(armorMaterial, ArmorType.HELMET)
|
||||
}
|
||||
smithingUpgrade(Items.DRAGON_HEAD, Items.NETHERITE_HELMET, INGOT)
|
||||
tags("head_armor")
|
||||
}
|
||||
|
||||
val CHESTPLATE by registerItem("dragonite_chestplate", ::Item) {
|
||||
name("Dragonite Chestplate")
|
||||
lore("A chestplate$LORE")
|
||||
properties {
|
||||
humanoidArmor(armorMaterial, ArmorType.CHESTPLATE)
|
||||
.component(DataComponents.GLIDER, Unit.INSTANCE)
|
||||
.component(DataComponents.UNBREAKABLE, Unit.INSTANCE)
|
||||
}
|
||||
smithingUpgrade(Items.ELYTRA, Items.NETHERITE_CHESTPLATE, INGOT)
|
||||
tags("chest_armor")
|
||||
}
|
||||
|
||||
val LEGGINGS by registerItem("dragonite_leggings", ::Item) {
|
||||
name("Dragonite Leggings")
|
||||
lore("Leggings$LORE")
|
||||
properties {
|
||||
humanoidArmor(armorMaterial, ArmorType.LEGGINGS)
|
||||
}
|
||||
smithingUpgrade(Items.CRYING_OBSIDIAN, Items.NETHERITE_LEGGINGS, INGOT)
|
||||
tags("leg_armor")
|
||||
}
|
||||
|
||||
val BOOTS by registerItem("dragonite_boots", ::Item) {
|
||||
name("Dragonite Boots")
|
||||
lore("Boots$LORE")
|
||||
properties {
|
||||
humanoidArmor(armorMaterial, ArmorType.BOOTS)
|
||||
}
|
||||
smithingUpgrade(Items.CRYING_OBSIDIAN, Items.NETHERITE_BOOTS, INGOT)
|
||||
tags("foot_armor")
|
||||
}
|
||||
|
||||
override val armorSet: ArmorSet = ArmorSet(HELMET, CHESTPLATE, LEGGINGS, BOOTS)
|
||||
|
||||
@@ -3,9 +3,8 @@ package dev.zxq5.items.sets
|
||||
import dev.zxq5.items.template.ArmorSet
|
||||
import dev.zxq5.items.template.GearMaterialDef
|
||||
import dev.zxq5.items.template.GenericGearSet
|
||||
import dev.zxq5.items.template.provideDelegate
|
||||
import dev.zxq5.items.template.registerItem
|
||||
import net.fabricmc.fabric.api.entity.event.v1.ServerLivingEntityEvents
|
||||
import net.minecraft.ChatFormatting
|
||||
import net.minecraft.core.BlockPos
|
||||
import net.minecraft.core.component.DataComponents
|
||||
import net.minecraft.core.particles.ParticleTypes
|
||||
@@ -32,7 +31,13 @@ object Ender: GenericGearSet() {
|
||||
override val materialDefinition
|
||||
get() = GearMaterialDef.DIAMOND.copy(assetId = materialKey)
|
||||
|
||||
const val LORE = "Crafted from the essence of endermen"
|
||||
override val lore_style: ChatFormatting
|
||||
get() = ChatFormatting.AQUA
|
||||
|
||||
val ENDER_INGOT by registerItem("ender_ingot", ::Item) {
|
||||
name("Ender Ingot")
|
||||
lore(LORE)
|
||||
shapedRecipe("EDE", "DED", "EDE", key=mapOf(
|
||||
'E' to Items.ENDER_EYE,
|
||||
'D' to Items.DIAMOND,
|
||||
@@ -40,40 +45,55 @@ object Ender: GenericGearSet() {
|
||||
}
|
||||
|
||||
val SWORD by registerItem("ender_sword", ::EnderSword) {
|
||||
name("Ender Sword")
|
||||
lore(LORE)
|
||||
properties {
|
||||
enchantable(armorMaterial.enchantmentValue)
|
||||
.component(DataComponents.USE_COOLDOWN, UseCooldown(3f))
|
||||
.sword(ToolMaterial.DIAMOND, 3F, -2.4F)
|
||||
}
|
||||
smithingUpgrade(Items.NETHERITE_UPGRADE_SMITHING_TEMPLATE, Items.DIAMOND_SWORD, ENDER_INGOT)
|
||||
tags("swords")
|
||||
}
|
||||
|
||||
val HELMET by registerItem("ender_helmet", ::Item) {
|
||||
name("Ender Helmet")
|
||||
lore(LORE)
|
||||
properties {
|
||||
humanoidArmor(armorMaterial, ArmorType.HELMET)
|
||||
}
|
||||
smithingUpgrade(Items.NETHERITE_UPGRADE_SMITHING_TEMPLATE, Items.DIAMOND_HELMET, ENDER_INGOT)
|
||||
tags("head_armor")
|
||||
}
|
||||
|
||||
val CHESTPLATE by registerItem("ender_chestplate", ::Item) {
|
||||
name("Ender Chestplate")
|
||||
lore(LORE)
|
||||
properties {
|
||||
humanoidArmor(armorMaterial, ArmorType.CHESTPLATE)
|
||||
}
|
||||
smithingUpgrade(Items.NETHERITE_UPGRADE_SMITHING_TEMPLATE, Items.DIAMOND_CHESTPLATE, ENDER_INGOT)
|
||||
tags("chest_armor")
|
||||
}
|
||||
|
||||
val LEGGINGS by registerItem("ender_leggings", ::Item) {
|
||||
name("Ender Leggings")
|
||||
lore(LORE)
|
||||
properties {
|
||||
humanoidArmor(armorMaterial, ArmorType.LEGGINGS)
|
||||
}
|
||||
smithingUpgrade(Items.NETHERITE_UPGRADE_SMITHING_TEMPLATE, Items.DIAMOND_LEGGINGS, ENDER_INGOT)
|
||||
tags("leg_armor")
|
||||
}
|
||||
|
||||
val BOOTS by registerItem("ender_boots", ::Item) {
|
||||
name("Ender Boots")
|
||||
lore(LORE)
|
||||
properties {
|
||||
humanoidArmor(armorMaterial, ArmorType.BOOTS)
|
||||
}
|
||||
smithingUpgrade(Items.NETHERITE_UPGRADE_SMITHING_TEMPLATE, Items.DIAMOND_BOOTS, ENDER_INGOT)
|
||||
tags("foot_armor")
|
||||
}
|
||||
|
||||
override val armorSet: ArmorSet = ArmorSet(HELMET, CHESTPLATE, LEGGINGS, BOOTS)
|
||||
|
||||
@@ -2,9 +2,9 @@ package dev.zxq5.items.sets
|
||||
|
||||
import dev.zxq5.items.template.ArmorSet
|
||||
import dev.zxq5.items.template.GenericGearSet
|
||||
import dev.zxq5.items.template.registerItem
|
||||
import dev.zxq5.items.template.provideDelegate
|
||||
import dev.zxq5.items.template.ModelSpec
|
||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents
|
||||
import net.minecraft.ChatFormatting
|
||||
import net.minecraft.core.component.DataComponents
|
||||
import net.minecraft.sounds.SoundEvents
|
||||
import net.minecraft.world.InteractionHand
|
||||
@@ -31,7 +31,14 @@ object Witherite: GenericGearSet() {
|
||||
override val materialDefinition
|
||||
get() = super.materialDefinition.copy(assetId = materialKey)
|
||||
|
||||
const val LORE = " forged with the skulls of wither skeletons."
|
||||
|
||||
override val lore_style
|
||||
get() = ChatFormatting.BLACK
|
||||
|
||||
val SHIELD by registerItem("witherite_shield", ::Item) {
|
||||
name("Witherite Shield")
|
||||
lore("A shield$LORE")
|
||||
properties {
|
||||
component(DataComponents.BLOCKS_ATTACKS, BlocksAttacks(
|
||||
0.25f, // 5 tick warmup
|
||||
@@ -54,49 +61,69 @@ object Witherite: GenericGearSet() {
|
||||
}
|
||||
|
||||
val SWORD by registerItem("witherite_sword", ::WitheriteSword) {
|
||||
name("Witherite Sword")
|
||||
lore("A sword$LORE")
|
||||
model(ModelSpec.Handheld)
|
||||
properties {
|
||||
enchantable(armorMaterial.enchantmentValue)
|
||||
.component(DataComponents.USE_COOLDOWN, UseCooldown(2f))
|
||||
.sword(ToolMaterial.NETHERITE, 3F, -2.4F)
|
||||
}
|
||||
smithingUpgrade(Items.NETHERITE_UPGRADE_SMITHING_TEMPLATE, Items.NETHERITE_SWORD, Items.WITHER_SKELETON_SKULL)
|
||||
tags("swords")
|
||||
}
|
||||
|
||||
val AXE by registerItem("witherite_axe", ::WitheriteWeapon) {
|
||||
name("Witherite Axe")
|
||||
lore("An axe$LORE")
|
||||
model(ModelSpec.Handheld)
|
||||
properties {
|
||||
enchantable(armorMaterial.enchantmentValue)
|
||||
.component(DataComponents.USE_COOLDOWN, UseCooldown(2f))
|
||||
.axe(ToolMaterial.NETHERITE, 3F, -3F)
|
||||
}
|
||||
smithingUpgrade(Items.NETHERITE_UPGRADE_SMITHING_TEMPLATE, Items.NETHERITE_AXE, Items.WITHER_SKELETON_SKULL)
|
||||
tags("axes")
|
||||
}
|
||||
|
||||
val HELMET by registerItem("witherite_helmet", ::Item) {
|
||||
name("Witherite Helmet")
|
||||
lore("A helmet$LORE")
|
||||
properties {
|
||||
humanoidArmor(armorMaterial, ArmorType.HELMET)
|
||||
}
|
||||
smithingUpgrade(Items.NETHERITE_UPGRADE_SMITHING_TEMPLATE, Items.NETHERITE_HELMET, Items.WITHER_SKELETON_SKULL)
|
||||
tags("head_armor")
|
||||
}
|
||||
|
||||
val CHESTPLATE by registerItem("witherite_chestplate", ::Item) {
|
||||
name("Witherite Chestplate")
|
||||
lore("A chestplate$LORE")
|
||||
properties {
|
||||
humanoidArmor(armorMaterial, ArmorType.CHESTPLATE)
|
||||
}
|
||||
smithingUpgrade(Items.NETHERITE_UPGRADE_SMITHING_TEMPLATE, Items.NETHERITE_CHESTPLATE, Items.WITHER_SKELETON_SKULL)
|
||||
tags("chest_armor")
|
||||
}
|
||||
|
||||
val LEGGINGS by registerItem("witherite_leggings", ::Item) {
|
||||
name("Witherite Leggings")
|
||||
lore("Leggings$LORE")
|
||||
properties {
|
||||
humanoidArmor(armorMaterial, ArmorType.LEGGINGS)
|
||||
}
|
||||
smithingUpgrade(Items.NETHERITE_UPGRADE_SMITHING_TEMPLATE, Items.NETHERITE_LEGGINGS, Items.WITHER_SKELETON_SKULL)
|
||||
tags("leg_armor")
|
||||
}
|
||||
|
||||
val BOOTS by registerItem("witherite_boots", ::Item) {
|
||||
name("Witherite Boots")
|
||||
lore("Boots$LORE")
|
||||
properties {
|
||||
humanoidArmor(armorMaterial, ArmorType.BOOTS)
|
||||
}
|
||||
smithingUpgrade(Items.NETHERITE_UPGRADE_SMITHING_TEMPLATE, Items.NETHERITE_BOOTS, Items.WITHER_SKELETON_SKULL)
|
||||
tags("foot_armor")
|
||||
}
|
||||
|
||||
override val armorSet: ArmorSet = ArmorSet(HELMET, CHESTPLATE, LEGGINGS, BOOTS)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package dev.zxq5.items.template
|
||||
|
||||
import dev.zxq5.Fantasysmp
|
||||
import dev.zxq5.util.resourceKey
|
||||
import net.minecraft.core.Holder
|
||||
import net.minecraft.resources.ResourceKey
|
||||
@@ -19,6 +20,14 @@ abstract class GenericGearSet: GenericItemSet() {
|
||||
|
||||
abstract val armorSet: ArmorSet
|
||||
|
||||
open val equipmentAssetSpec: EquipmentAssetSpec
|
||||
get() = EquipmentAssetSpec(
|
||||
layers = mapOf(
|
||||
"humanoid" to listOf(EquipmentLayer("${Fantasysmp.MOD_ID}:$materialName")),
|
||||
"humanoid_leggings" to listOf(EquipmentLayer("${Fantasysmp.MOD_ID}:$materialName")),
|
||||
)
|
||||
)
|
||||
|
||||
open val materialKey: ResourceKey<EquipmentAsset>
|
||||
get() = materialName.resourceKey()
|
||||
|
||||
@@ -33,7 +42,7 @@ abstract class GenericGearSet: GenericItemSet() {
|
||||
materialDefinition.toArmorMaterial()
|
||||
}
|
||||
|
||||
fun fullSetEquippedBy(p: Player) =
|
||||
open fun fullSetEquippedBy(p: Player) =
|
||||
p.getItemBySlot(EquipmentSlot.HEAD).item == armorSet.helmet &&
|
||||
p.getItemBySlot(EquipmentSlot.CHEST).item == armorSet.chestplate &&
|
||||
p.getItemBySlot(EquipmentSlot.LEGS).item == armorSet.leggings &&
|
||||
|
||||
@@ -1,27 +1,29 @@
|
||||
package dev.zxq5.items.template
|
||||
|
||||
import dev.zxq5.Fantasysmp
|
||||
import dev.zxq5.items.ModItems
|
||||
import net.fabricmc.fabric.api.datagen.v1.provider.FabricTagsProvider
|
||||
import dev.zxq5.util.mcItemTag
|
||||
import net.fabricmc.fabric.api.datagen.v1.provider.FabricLanguageProvider
|
||||
import net.minecraft.ChatFormatting
|
||||
import net.minecraft.advancements.criterion.InventoryChangeTrigger
|
||||
import net.minecraft.advancements.criterion.ItemPredicate
|
||||
import net.minecraft.core.HolderGetter
|
||||
import net.minecraft.core.HolderLookup
|
||||
import net.minecraft.core.component.DataComponents
|
||||
import net.minecraft.core.registries.BuiltInRegistries
|
||||
import net.minecraft.core.registries.Registries
|
||||
import net.minecraft.data.recipes.RecipeCategory
|
||||
import net.minecraft.data.recipes.RecipeOutput
|
||||
import net.minecraft.data.recipes.RecipeProvider
|
||||
import net.minecraft.data.recipes.ShapedRecipeBuilder
|
||||
import net.minecraft.data.recipes.SmithingTransformRecipeBuilder
|
||||
import net.minecraft.data.recipes.*
|
||||
import net.minecraft.network.chat.Component
|
||||
import net.minecraft.tags.TagKey
|
||||
import net.minecraft.world.item.Item
|
||||
import net.minecraft.world.item.component.ItemLore
|
||||
import net.minecraft.world.item.crafting.Ingredient
|
||||
import kotlin.collections.component1
|
||||
import kotlin.collections.component2
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
|
||||
abstract class GenericItemSet {
|
||||
// list of all items part of the class
|
||||
open val lore_style = ChatFormatting.GRAY
|
||||
abstract val items: List<Item>
|
||||
|
||||
open fun onLoad() {}
|
||||
@@ -29,15 +31,28 @@ abstract class GenericItemSet {
|
||||
private val itemRecipes = mutableMapOf<Item, List<RecipeSpec>>()
|
||||
private val itemTags = mutableMapOf<Item, List<TagKey<Item>>>()
|
||||
private val itemModels = mutableMapOf<Item, ModelSpec>()
|
||||
private val itemTranslations = mutableMapOf<String, String>()
|
||||
|
||||
val modelSpecs: Map<Item, ModelSpec> get() = itemModels
|
||||
internal fun registerDatagen(item: Item, recipes: List<RecipeSpec>, tags: List<TagKey<Item>>, model: ModelSpec) {
|
||||
internal fun registerDatagen(
|
||||
item: Item,
|
||||
recipes: List<RecipeSpec>,
|
||||
tags: List<TagKey<Item>>,
|
||||
model: ModelSpec,
|
||||
translations: Map<String, String>
|
||||
) {
|
||||
itemRecipes[item] = recipes
|
||||
itemTags[item] = tags
|
||||
itemModels[item] = model
|
||||
itemTranslations.putAll(translations)
|
||||
}
|
||||
|
||||
open fun generateItemTags(tags: ItemTagAdder) {
|
||||
itemTags.forEach { (item, tagList) -> tagList.forEach { tags.add(it, item) } }
|
||||
open fun generateItemTags(provider: HolderLookup.Provider): Map<Item, List<TagKey<Item>>> {
|
||||
return itemTags
|
||||
}
|
||||
|
||||
open fun generateTranslations(builder: FabricLanguageProvider.TranslationBuilder) {
|
||||
itemTranslations.forEach { (key, value) -> builder.add(key, value) }
|
||||
}
|
||||
|
||||
open fun generateRecipes(registries: HolderLookup.Provider, exporter: RecipeOutput) {
|
||||
@@ -68,12 +83,20 @@ abstract class GenericItemSet {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
init {
|
||||
register(this)
|
||||
}
|
||||
|
||||
fun <T : Item> registerItem(
|
||||
name: String,
|
||||
itemFactory: (Item.Properties) -> T,
|
||||
block: CustomItemBuilder<T>.() -> Unit = {},
|
||||
): CustomItemBuilder<T> {
|
||||
return CustomItemBuilder(this, name, itemFactory).apply(block)
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val _all = mutableListOf<GenericItemSet>()
|
||||
|
||||
@@ -84,6 +107,13 @@ abstract class GenericItemSet {
|
||||
|
||||
}
|
||||
|
||||
data class EquipmentLayer(val texture: String, val usePlayerTexture: Boolean = true)
|
||||
|
||||
data class EquipmentAssetSpec(
|
||||
val layers: Map<String, List<EquipmentLayer>> // "humanoid", "humanoid_leggings", "wings", etc.
|
||||
)
|
||||
|
||||
|
||||
class CustomItemBuilder<T : Item>(
|
||||
private val owner: GenericItemSet,
|
||||
val name: String,
|
||||
@@ -92,12 +122,35 @@ class CustomItemBuilder<T : Item>(
|
||||
private var properties = Item.Properties()
|
||||
private val recipes = mutableListOf<RecipeSpec>()
|
||||
private val tags = mutableListOf<TagKey<Item>>()
|
||||
private var modelSpec: ModelSpec = ModelSpec.None
|
||||
private val translations = mutableMapOf<String, String>()
|
||||
private var modelSpec: ModelSpec = ModelSpec.Generated
|
||||
|
||||
fun model(spec: ModelSpec) {
|
||||
modelSpec = spec
|
||||
}
|
||||
|
||||
fun name(displayName: String) {
|
||||
translations["item.${Fantasysmp.MOD_ID}.$name"] = displayName
|
||||
}
|
||||
|
||||
fun lore(vararg lines: String, style: ChatFormatting = owner.lore_style) {
|
||||
val components = lines.mapIndexed { index, line ->
|
||||
val key = "item.${Fantasysmp.MOD_ID}.$name.lore.line${index + 1}"
|
||||
translations[key] = line
|
||||
Component.translatable(key).withStyle(style)
|
||||
}
|
||||
properties = properties.component(DataComponents.LORE, ItemLore(components))
|
||||
}
|
||||
|
||||
fun lore(vararg lines: Pair<String, ChatFormatting>) {
|
||||
val components = lines.mapIndexed { index, (line, style) ->
|
||||
val key = "item.${Fantasysmp.MOD_ID}.$name.lore.line${index + 1}"
|
||||
translations[key] = line
|
||||
Component.translatable(key).withStyle(style)
|
||||
}
|
||||
properties = properties.component(DataComponents.LORE, ItemLore(components))
|
||||
}
|
||||
|
||||
fun properties(block: Item.Properties.() -> Item.Properties) {
|
||||
properties = properties.block()
|
||||
}
|
||||
@@ -110,21 +163,25 @@ class CustomItemBuilder<T : Item>(
|
||||
recipes += RecipeSpec.Shaped(pattern.toList(), key)
|
||||
}
|
||||
|
||||
fun tags(vararg tag: String) {
|
||||
tag.forEach {
|
||||
tags += mcItemTag(it)
|
||||
}
|
||||
}
|
||||
|
||||
fun tags(vararg tag: TagKey<Item>) {
|
||||
tags += tag
|
||||
}
|
||||
|
||||
internal fun build(): T {
|
||||
val item = ModItems.register(name, itemFactory, properties)
|
||||
owner.registerDatagen(item, recipes, tags, modelSpec)
|
||||
owner.registerDatagen(item, recipes, tags, modelSpec, translations)
|
||||
return item
|
||||
}
|
||||
}
|
||||
|
||||
class ItemTagAdder(private val provider: FabricTagsProvider.ItemTagsProvider) {
|
||||
fun add(tag: TagKey<Item>, vararg items: Item) {
|
||||
provider.apply { items.forEach { add(tag, it) } }
|
||||
}
|
||||
operator fun provideDelegate(
|
||||
thisRef: Any?, property: KProperty<*>
|
||||
): Lazy<T> = lazy { build() }
|
||||
}
|
||||
|
||||
sealed interface RecipeSpec {
|
||||
@@ -138,14 +195,4 @@ sealed interface ModelSpec {
|
||||
data object None : ModelSpec // handwritten JSON already exists, skip auto-gen
|
||||
}
|
||||
|
||||
fun <T : Item> GenericItemSet.registerItem(
|
||||
name: String,
|
||||
itemFactory: (Item.Properties) -> T,
|
||||
block: CustomItemBuilder<T>.() -> Unit = {},
|
||||
): CustomItemBuilder<T> = CustomItemBuilder(this, name, itemFactory).apply(block)
|
||||
|
||||
operator fun <T : Item> CustomItemBuilder<T>.provideDelegate(
|
||||
thisRef: Any?, property: KProperty<*>
|
||||
): Lazy<T> = lazy { build() }
|
||||
|
||||
operator fun <T : Item> Lazy<T>.getValue(thisRef: Any?, property: KProperty<*>): T = value
|
||||
Reference in New Issue
Block a user