basically done with data generation now. model generation is pretty much fully working/automated
build / build (push) Failing after 3m31s

This commit is contained in:
2026-07-13 23:28:54 +01:00
parent e58470c0cc
commit e7af04418b
167 changed files with 840 additions and 792 deletions
@@ -1,6 +1,13 @@
package dev.zxq5.client package dev.zxq5.client
import com.google.gson.JsonArray
import com.google.gson.JsonObject
import dev.zxq5.Fantasysmp
import dev.zxq5.ModItemTagProvider
import dev.zxq5.ModLanguageProvider
import dev.zxq5.ModRecipeProvider import dev.zxq5.ModRecipeProvider
import dev.zxq5.items.template.CustomItemBuilder
import dev.zxq5.items.template.GenericGearSet
import dev.zxq5.items.template.GenericItemSet import dev.zxq5.items.template.GenericItemSet
import dev.zxq5.items.template.ModelSpec import dev.zxq5.items.template.ModelSpec
import net.fabricmc.fabric.api.client.datagen.v1.provider.FabricModelProvider import net.fabricmc.fabric.api.client.datagen.v1.provider.FabricModelProvider
@@ -10,13 +17,21 @@ import net.fabricmc.fabric.api.datagen.v1.FabricPackOutput
import net.minecraft.client.data.models.BlockModelGenerators import net.minecraft.client.data.models.BlockModelGenerators
import net.minecraft.client.data.models.ItemModelGenerators import net.minecraft.client.data.models.ItemModelGenerators
import net.minecraft.client.data.models.model.ModelTemplates import net.minecraft.client.data.models.model.ModelTemplates
import net.minecraft.data.CachedOutput
import net.minecraft.data.DataProvider
import net.minecraft.data.PackOutput
import java.util.concurrent.CompletableFuture
object FantasysmpDataGenerator : DataGeneratorEntrypoint { object FantasysmpDataGenerator : DataGeneratorEntrypoint {
override fun onInitializeDataGenerator(fabricDataGenerator: FabricDataGenerator) { override fun onInitializeDataGenerator(fabricDataGenerator: FabricDataGenerator) {
val pack = fabricDataGenerator.createPack() val pack = fabricDataGenerator.createPack()
pack.addProvider(::ModRecipeProvider) // main-safe, can live in either sourceSet pack.addProvider(::ModRecipeProvider)
// pack.addProvider(::ModItemTagProvider) // main-safe pack.addProvider(::ModItemTagProvider) // TODO! fix impl.
pack.addProvider(::ModModelProvider) // needs client, since ItemModelGenerators is client-only pack.addProvider(::ModLanguageProvider)
// runs only in the client as it requires client only libs!
pack.addProvider(::ModModelProvider)
pack.addProvider(::ModEquipmentAssetProvider)
} }
} }
@@ -25,13 +40,48 @@ class ModModelProvider(output: FabricPackOutput) : FabricModelProvider(output) {
override fun generateBlockStateModels(blockModels: BlockModelGenerators) {} override fun generateBlockStateModels(blockModels: BlockModelGenerators) {}
override fun generateItemModels(itemModels: ItemModelGenerators) { override fun generateItemModels(itemModels: ItemModelGenerators) {
GenericItemSet.all.forEach { it.generateModels(itemModels) } println("Generating item models")
GenericItemSet.all.forEach {
println("doing $it")
it.generateModels(itemModels)
}
} }
} }
class ModEquipmentAssetProvider(private val output: FabricPackOutput) : DataProvider {
override fun run(writer: CachedOutput): CompletableFuture<*> {
val futures = GenericItemSet.all
.filterIsInstance<GenericGearSet>()
.map { set -> writeAsset(writer, set) }
return CompletableFuture.allOf(*futures.toTypedArray())
}
private fun writeAsset(writer: CachedOutput, set: GenericGearSet): CompletableFuture<*> {
val json = JsonObject()
val layersJson = JsonObject()
set.equipmentAssetSpec.layers.forEach { (layerType, layers) ->
val arr = JsonArray()
layers.forEach { layer ->
val entry = JsonObject()
entry.addProperty("texture", layer.texture)
if (!layer.usePlayerTexture) entry.addProperty("use_player_texture", false)
arr.add(entry)
}
layersJson.add(layerType, arr)
}
json.add("layers", layersJson)
val path = output.outputFolder
.resolve("assets/${Fantasysmp.MOD_ID}/equipment/${set.materialName}.json")
return DataProvider.saveStable(writer, json, path)
}
override fun getName() = "Fantasysmp Equipment Assets"
}
// client sourceSet // client sourceSet
fun GenericItemSet.generateModels(itemModels: ItemModelGenerators) { fun GenericItemSet.generateModels(itemModels: ItemModelGenerators) {
if (this !is GenericItemSet) return
modelSpecs.forEach { (item, spec) -> modelSpecs.forEach { (item, spec) ->
when (spec) { when (spec) {
ModelSpec.Generated -> itemModels.generateFlatItem(item, ModelTemplates.FLAT_ITEM) ModelSpec.Generated -> itemModels.generateFlatItem(item, ModelTemplates.FLAT_ITEM)
@@ -0,0 +1,20 @@
{
"layers": {
"humanoid": [
{
"texture": "fantasysmp:dragonite"
}
],
"humanoid_leggings": [
{
"texture": "fantasysmp:dragonite"
}
],
"wings": [
{
"texture": "fantasysmp:dragonite",
"use_player_texture": false
}
]
}
}
@@ -2,12 +2,12 @@
"layers": { "layers": {
"humanoid": [ "humanoid": [
{ {
"texture": "fantasysmp:blazing" "texture": "fantasysmp:ender"
} }
], ],
"humanoid_leggings": [ "humanoid_leggings": [
{ {
"texture": "fantasysmp:blazing" "texture": "fantasysmp:ender"
} }
] ]
} }
@@ -2,12 +2,12 @@
"layers": { "layers": {
"humanoid": [ "humanoid": [
{ {
"texture": "fantasysmp:alchemist" "texture": "fantasysmp:witherite"
} }
], ],
"humanoid_leggings": [ "humanoid_leggings": [
{ {
"texture": "fantasysmp:alchemist" "texture": "fantasysmp:witherite"
} }
] ]
} }
@@ -1,6 +1,6 @@
{ {
"model": { "model": {
"type": "minecraft:model", "type": "minecraft:model",
"model": "fantasysmp:item/alchemist_boots" "model": "fantasysmp:item/dragon_scale"
} }
} }
@@ -1,6 +1,6 @@
{ {
"model": { "model": {
"type": "minecraft:model", "type": "minecraft:model",
"model": "fantasysmp:item/alchemist_sword" "model": "fantasysmp:item/dragonite_boots"
} }
} }
@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "fantasysmp:item/dragonite_chestplate"
}
}
@@ -1,6 +1,6 @@
{ {
"model": { "model": {
"type": "minecraft:model", "type": "minecraft:model",
"model": "fantasysmp:item/alchemist_helmet" "model": "fantasysmp:item/dragonite_helmet"
} }
} }
@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "fantasysmp:item/dragonite_ingot"
}
}
@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "fantasysmp:item/dragonite_leggings"
}
}
@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "fantasysmp:item/dragonite_sword"
}
}
@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "fantasysmp:item/ender_boots"
}
}
@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "fantasysmp:item/ender_chestplate"
}
}
@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "fantasysmp:item/ender_helmet"
}
}
@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "fantasysmp:item/ender_ingot"
}
}
@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "fantasysmp:item/ender_leggings"
}
}
@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "fantasysmp:item/ender_sword"
}
}
@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "fantasysmp:item/witherite_axe"
}
}
@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "fantasysmp:item/witherite_boots"
}
}
@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "fantasysmp:item/witherite_chestplate"
}
}
@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "fantasysmp:item/witherite_helmet"
}
}
@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "fantasysmp:item/witherite_leggings"
}
}
@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "fantasysmp:item/witherite_shield"
}
}
@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "fantasysmp:item/witherite_sword"
}
}
@@ -0,0 +1,40 @@
{
"item.fantasysmp.dragon_scale": "Dragon Scale",
"item.fantasysmp.dragonite_boots": "Dragonite Boots",
"item.fantasysmp.dragonite_boots.lore.line1": "Boots forged from the essence of dragons",
"item.fantasysmp.dragonite_chestplate": "Dragonite Chestplate",
"item.fantasysmp.dragonite_chestplate.lore.line1": "A chestplate forged from the essence of dragons",
"item.fantasysmp.dragonite_helmet": "Dragonite Helmet",
"item.fantasysmp.dragonite_helmet.lore.line1": "A helmet forged from the essence of dragons",
"item.fantasysmp.dragonite_ingot": "Dragonite Ingot",
"item.fantasysmp.dragonite_leggings": "Dragonite Leggings",
"item.fantasysmp.dragonite_leggings.lore.line1": "Leggings forged from the essence of dragons",
"item.fantasysmp.dragonite_sword": "Dragonite Sword",
"item.fantasysmp.dragonite_sword.lore.line1": "A sword forged from the essence of dragons",
"item.fantasysmp.ender_boots": "Ender Boots",
"item.fantasysmp.ender_boots.lore.line1": "Crafted from the essence of endermen",
"item.fantasysmp.ender_chestplate": "Ender Chestplate",
"item.fantasysmp.ender_chestplate.lore.line1": "Crafted from the essence of endermen",
"item.fantasysmp.ender_helmet": "Ender Helmet",
"item.fantasysmp.ender_helmet.lore.line1": "Crafted from the essence of endermen",
"item.fantasysmp.ender_ingot": "Ender Ingot",
"item.fantasysmp.ender_ingot.lore.line1": "Crafted from the essence of endermen",
"item.fantasysmp.ender_leggings": "Ender Leggings",
"item.fantasysmp.ender_leggings.lore.line1": "Crafted from the essence of endermen",
"item.fantasysmp.ender_sword": "Ender Sword",
"item.fantasysmp.ender_sword.lore.line1": "Crafted from the essence of endermen",
"item.fantasysmp.witherite_axe": "Witherite Axe",
"item.fantasysmp.witherite_axe.lore.line1": "An axe forged with the skulls of wither skeletons.",
"item.fantasysmp.witherite_boots": "Witherite Boots",
"item.fantasysmp.witherite_boots.lore.line1": "Boots forged with the skulls of wither skeletons.",
"item.fantasysmp.witherite_chestplate": "Witherite Chestplate",
"item.fantasysmp.witherite_chestplate.lore.line1": "A chestplate forged with the skulls of wither skeletons.",
"item.fantasysmp.witherite_helmet": "Witherite Helmet",
"item.fantasysmp.witherite_helmet.lore.line1": "A helmet forged with the skulls of wither skeletons.",
"item.fantasysmp.witherite_leggings": "Witherite Leggings",
"item.fantasysmp.witherite_leggings.lore.line1": "Leggings forged with the skulls of wither skeletons.",
"item.fantasysmp.witherite_shield": "Witherite Shield",
"item.fantasysmp.witherite_shield.lore.line1": "A shield forged with the skulls of wither skeletons.",
"item.fantasysmp.witherite_sword": "Witherite Sword",
"item.fantasysmp.witherite_sword.lore.line1": "A sword forged with the skulls of wither skeletons."
}
@@ -0,0 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "fantasysmp:item/dragon_scale"
}
}
@@ -0,0 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "fantasysmp:item/dragonite_boots"
}
}
@@ -0,0 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "fantasysmp:item/dragonite_chestplate"
}
}
@@ -0,0 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "fantasysmp:item/dragonite_helmet"
}
}
@@ -0,0 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "fantasysmp:item/dragonite_ingot"
}
}
@@ -0,0 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "fantasysmp:item/dragonite_leggings"
}
}
@@ -0,0 +1,6 @@
{
"parent": "minecraft:item/handheld",
"textures": {
"layer0": "fantasysmp:item/dragonite_sword"
}
}
@@ -0,0 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "fantasysmp:item/ender_boots"
}
}
@@ -0,0 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "fantasysmp:item/ender_chestplate"
}
}
@@ -0,0 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "fantasysmp:item/ender_helmet"
}
}
@@ -0,0 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "fantasysmp:item/ender_ingot"
}
}
@@ -0,0 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "fantasysmp:item/ender_leggings"
}
}
@@ -0,0 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "fantasysmp:item/ender_sword"
}
}
@@ -0,0 +1,6 @@
{
"parent": "minecraft:item/handheld",
"textures": {
"layer0": "fantasysmp:item/witherite_axe"
}
}
@@ -0,0 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "fantasysmp:item/witherite_boots"
}
}
@@ -0,0 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "fantasysmp:item/witherite_chestplate"
}
}
@@ -0,0 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "fantasysmp:item/witherite_helmet"
}
}
@@ -0,0 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "fantasysmp:item/witherite_leggings"
}
}
@@ -0,0 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "fantasysmp:item/witherite_shield"
}
}
@@ -0,0 +1,6 @@
{
"parent": "minecraft:item/handheld",
"textures": {
"layer0": "fantasysmp:item/witherite_sword"
}
}
@@ -0,0 +1,32 @@
{
"parent": "minecraft:recipes/root",
"criteria": {
"has_addition": {
"conditions": {
"items": [
{
"items": "fantasysmp:ender_ingot"
}
]
},
"trigger": "minecraft:inventory_changed"
},
"has_the_recipe": {
"conditions": {
"recipe": "fantasysmp:ender_boots"
},
"trigger": "minecraft:recipe_unlocked"
}
},
"requirements": [
[
"has_the_recipe",
"has_addition"
]
],
"rewards": {
"recipes": [
"fantasysmp:ender_boots"
]
}
}
@@ -0,0 +1,32 @@
{
"parent": "minecraft:recipes/root",
"criteria": {
"has_addition": {
"conditions": {
"items": [
{
"items": "fantasysmp:ender_ingot"
}
]
},
"trigger": "minecraft:inventory_changed"
},
"has_the_recipe": {
"conditions": {
"recipe": "fantasysmp:ender_chestplate"
},
"trigger": "minecraft:recipe_unlocked"
}
},
"requirements": [
[
"has_the_recipe",
"has_addition"
]
],
"rewards": {
"recipes": [
"fantasysmp:ender_chestplate"
]
}
}
@@ -0,0 +1,32 @@
{
"parent": "minecraft:recipes/root",
"criteria": {
"has_addition": {
"conditions": {
"items": [
{
"items": "fantasysmp:ender_ingot"
}
]
},
"trigger": "minecraft:inventory_changed"
},
"has_the_recipe": {
"conditions": {
"recipe": "fantasysmp:ender_helmet"
},
"trigger": "minecraft:recipe_unlocked"
}
},
"requirements": [
[
"has_the_recipe",
"has_addition"
]
],
"rewards": {
"recipes": [
"fantasysmp:ender_helmet"
]
}
}
@@ -0,0 +1,32 @@
{
"parent": "minecraft:recipes/root",
"criteria": {
"has_addition": {
"conditions": {
"items": [
{
"items": "fantasysmp:ender_ingot"
}
]
},
"trigger": "minecraft:inventory_changed"
},
"has_the_recipe": {
"conditions": {
"recipe": "fantasysmp:ender_leggings"
},
"trigger": "minecraft:recipe_unlocked"
}
},
"requirements": [
[
"has_the_recipe",
"has_addition"
]
],
"rewards": {
"recipes": [
"fantasysmp:ender_leggings"
]
}
}
@@ -0,0 +1,32 @@
{
"parent": "minecraft:recipes/root",
"criteria": {
"has_addition": {
"conditions": {
"items": [
{
"items": "fantasysmp:ender_ingot"
}
]
},
"trigger": "minecraft:inventory_changed"
},
"has_the_recipe": {
"conditions": {
"recipe": "fantasysmp:ender_sword"
},
"trigger": "minecraft:recipe_unlocked"
}
},
"requirements": [
[
"has_the_recipe",
"has_addition"
]
],
"rewards": {
"recipes": [
"fantasysmp:ender_sword"
]
}
}
@@ -0,0 +1,35 @@
{
"parent": "minecraft:recipes/root",
"criteria": {
"has_ingredient": {
"conditions": {
"items": [
{
"items": [
"minecraft:ender_eye",
"minecraft:diamond"
]
}
]
},
"trigger": "minecraft:inventory_changed"
},
"has_the_recipe": {
"conditions": {
"recipe": "fantasysmp:ender_ingot"
},
"trigger": "minecraft:recipe_unlocked"
}
},
"requirements": [
[
"has_the_recipe",
"has_ingredient"
]
],
"rewards": {
"recipes": [
"fantasysmp:ender_ingot"
]
}
}
@@ -0,0 +1,9 @@
{
"type": "minecraft:smithing_transform",
"addition": "fantasysmp:ender_ingot",
"base": "minecraft:diamond_boots",
"result": {
"id": "fantasysmp:ender_boots"
},
"template": "minecraft:netherite_upgrade_smithing_template"
}
@@ -0,0 +1,9 @@
{
"type": "minecraft:smithing_transform",
"addition": "fantasysmp:ender_ingot",
"base": "minecraft:diamond_chestplate",
"result": {
"id": "fantasysmp:ender_chestplate"
},
"template": "minecraft:netherite_upgrade_smithing_template"
}
@@ -0,0 +1,9 @@
{
"type": "minecraft:smithing_transform",
"addition": "fantasysmp:ender_ingot",
"base": "minecraft:diamond_helmet",
"result": {
"id": "fantasysmp:ender_helmet"
},
"template": "minecraft:netherite_upgrade_smithing_template"
}
@@ -0,0 +1,16 @@
{
"type": "minecraft:crafting_shaped",
"category": "misc",
"key": {
"D": "minecraft:diamond",
"E": "minecraft:ender_eye"
},
"pattern": [
"EDE",
"DED",
"EDE"
],
"result": {
"id": "fantasysmp:ender_ingot"
}
}
@@ -0,0 +1,9 @@
{
"type": "minecraft:smithing_transform",
"addition": "fantasysmp:ender_ingot",
"base": "minecraft:diamond_leggings",
"result": {
"id": "fantasysmp:ender_leggings"
},
"template": "minecraft:netherite_upgrade_smithing_template"
}
@@ -0,0 +1,9 @@
{
"type": "minecraft:smithing_transform",
"addition": "fantasysmp:ender_ingot",
"base": "minecraft:diamond_sword",
"result": {
"id": "fantasysmp:ender_sword"
},
"template": "minecraft:netherite_upgrade_smithing_template"
}
@@ -0,0 +1,7 @@
{
"values": [
"fantasysmp:witherite_chestplate",
"fantasysmp:dragonite_chestplate",
"fantasysmp:ender_chestplate"
]
}
@@ -0,0 +1,7 @@
{
"values": [
"fantasysmp:witherite_boots",
"fantasysmp:dragonite_boots",
"fantasysmp:ender_boots"
]
}
@@ -0,0 +1,7 @@
{
"values": [
"fantasysmp:witherite_helmet",
"fantasysmp:dragonite_helmet",
"fantasysmp:ender_helmet"
]
}
@@ -0,0 +1,7 @@
{
"values": [
"fantasysmp:witherite_leggings",
"fantasysmp:dragonite_leggings",
"fantasysmp:ender_leggings"
]
}
@@ -0,0 +1,7 @@
{
"values": [
"fantasysmp:witherite_sword",
"fantasysmp:dragonite_sword",
"fantasysmp:ender_sword"
]
}
+25 -6
View File
@@ -1,15 +1,18 @@
package dev.zxq5 package dev.zxq5
import dev.zxq5.items.template.GenericItemSet
import dev.zxq5.items.template.ItemTagAdder
import dev.zxq5.items.ModItems import dev.zxq5.items.ModItems
import dev.zxq5.items.template.GenericItemSet
import net.fabricmc.api.ModInitializer import net.fabricmc.api.ModInitializer
import net.fabricmc.fabric.api.datagen.v1.FabricPackOutput 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.FabricRecipeProvider
import net.fabricmc.fabric.api.datagen.v1.provider.FabricTagsProvider import net.fabricmc.fabric.api.datagen.v1.provider.FabricTagsProvider
import net.minecraft.core.HolderLookup 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.RecipeOutput
import net.minecraft.data.recipes.RecipeProvider import net.minecraft.data.recipes.RecipeProvider
import net.minecraft.resources.ResourceKey
import org.slf4j.LoggerFactory import org.slf4j.LoggerFactory
import java.util.concurrent.CompletableFuture import java.util.concurrent.CompletableFuture
@@ -34,9 +37,7 @@ class ModRecipeProvider(
): RecipeProvider { ): RecipeProvider {
return object : RecipeProvider(registries, exporter) { return object : RecipeProvider(registries, exporter) {
override fun buildRecipes() { override fun buildRecipes() {
print("GENERATING ALL RECIPES")
GenericItemSet.all.forEach { GenericItemSet.all.forEach {
print("GENERATING RECIPES FOR" + it.items.toString())
it.generateRecipes(registries, exporter) it.generateRecipes(registries, exporter)
} }
} }
@@ -49,7 +50,25 @@ class ModRecipeProvider(
class ModItemTagProvider(output: FabricPackOutput, registriesFuture: CompletableFuture<HolderLookup.Provider>) : class ModItemTagProvider(output: FabricPackOutput, registriesFuture: CompletableFuture<HolderLookup.Provider>) :
FabricTagsProvider.ItemTagsProvider(output, registriesFuture) { FabricTagsProvider.ItemTagsProvider(output, registriesFuture) {
override fun addTags(provider: HolderLookup.Provider) { override fun addTags(provider: HolderLookup.Provider) {
val adder = ItemTagAdder(this) GenericItemSet.all.forEach {
GenericItemSet.all.forEach { it.generateItemTags(adder) } 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 package dev.zxq5.items
import dev.zxq5.Fantasysmp import dev.zxq5.Fantasysmp
import dev.zxq5.items.template.GenericItemSet
import dev.zxq5.items.sets.Dragonite import dev.zxq5.items.sets.Dragonite
import dev.zxq5.items.sets.Ender import dev.zxq5.items.sets.Ender
import dev.zxq5.items.sets.Witherite import dev.zxq5.items.sets.Witherite
import dev.zxq5.items.template.GenericItemSet
import net.fabricmc.fabric.api.creativetab.v1.FabricCreativeModeTab import net.fabricmc.fabric.api.creativetab.v1.FabricCreativeModeTab
import net.minecraft.core.Registry import net.minecraft.core.Registry
import net.minecraft.core.registries.BuiltInRegistries import net.minecraft.core.registries.BuiltInRegistries
@@ -1,11 +1,12 @@
package dev.zxq5.items.sets package dev.zxq5.items.sets
import dev.zxq5.Fantasysmp
import dev.zxq5.items.template.ArmorSet import dev.zxq5.items.template.ArmorSet
import dev.zxq5.items.template.EquipmentLayer
import dev.zxq5.items.template.GenericGearSet import dev.zxq5.items.template.GenericGearSet
import dev.zxq5.items.ModItems.register import dev.zxq5.items.template.ModelSpec
import dev.zxq5.items.template.registerItem
import dev.zxq5.items.template.provideDelegate
import net.fabricmc.fabric.api.entity.event.v1.ServerLivingEntityEvents import net.fabricmc.fabric.api.entity.event.v1.ServerLivingEntityEvents
import net.minecraft.ChatFormatting
import net.minecraft.core.component.DataComponents import net.minecraft.core.component.DataComponents
import net.minecraft.core.particles.ParticleTypes import net.minecraft.core.particles.ParticleTypes
import net.minecraft.core.particles.PowerParticleOption import net.minecraft.core.particles.PowerParticleOption
@@ -16,7 +17,6 @@ import net.minecraft.util.Unit
import net.minecraft.world.InteractionHand import net.minecraft.world.InteractionHand
import net.minecraft.world.InteractionResult import net.minecraft.world.InteractionResult
import net.minecraft.world.damagesource.DamageSource import net.minecraft.world.damagesource.DamageSource
import net.minecraft.world.damagesource.DamageSources
import net.minecraft.world.damagesource.DamageTypes import net.minecraft.world.damagesource.DamageTypes
import net.minecraft.world.entity.Entity import net.minecraft.world.entity.Entity
import net.minecraft.world.entity.player.Player 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.Items
import net.minecraft.world.item.ToolMaterial import net.minecraft.world.item.ToolMaterial
import net.minecraft.world.item.component.UseCooldown 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 net.minecraft.world.level.Level
import kotlin.getValue
object Dragonite: GenericGearSet() { object Dragonite: GenericGearSet() {
@@ -34,9 +33,24 @@ object Dragonite: GenericGearSet() {
override val materialDefinition override val materialDefinition
get() = super.materialDefinition.copy(assetId = materialKey) 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) { val INGOT by registerItem("dragonite_ingot", ::Item) {
name("Dragonite Ingot")
shapedRecipe("SBS", "CXC", "SBS", key=mapOf<Char, Item>( shapedRecipe("SBS", "CXC", "SBS", key=mapOf<Char, Item>(
'S' to Items.SHULKER_SHELL, 'S' to Items.SHULKER_SHELL,
'X' to SCALE, 'X' to SCALE,
@@ -46,42 +60,58 @@ object Dragonite: GenericGearSet() {
} }
val SWORD by registerItem("dragonite_sword", ::DragoniteSword) { val SWORD by registerItem("dragonite_sword", ::DragoniteSword) {
name("Dragonite Sword")
lore("A sword$LORE")
model(ModelSpec.Handheld)
properties { properties {
enchantable(armorMaterial.enchantmentValue) enchantable(armorMaterial.enchantmentValue)
.component(DataComponents.USE_COOLDOWN, UseCooldown(2f)) .component(DataComponents.USE_COOLDOWN, UseCooldown(2f))
.sword(ToolMaterial.NETHERITE, 3F, -2.4F) .sword(ToolMaterial.NETHERITE, 3F, -2.4F)
} }
smithingUpgrade(Items.END_CRYSTAL, Items.NETHERITE_SWORD, INGOT) smithingUpgrade(Items.END_CRYSTAL, Items.NETHERITE_SWORD, INGOT)
tags("swords")
} }
val HELMET by registerItem("dragonite_helmet", ::Item) { val HELMET by registerItem("dragonite_helmet", ::Item) {
name("Dragonite Helmet")
lore("A helmet$LORE")
properties { properties {
humanoidArmor(armorMaterial, ArmorType.HELMET) humanoidArmor(armorMaterial, ArmorType.HELMET)
} }
smithingUpgrade(Items.DRAGON_HEAD, Items.NETHERITE_HELMET, INGOT) smithingUpgrade(Items.DRAGON_HEAD, Items.NETHERITE_HELMET, INGOT)
tags("head_armor")
} }
val CHESTPLATE by registerItem("dragonite_chestplate", ::Item) { val CHESTPLATE by registerItem("dragonite_chestplate", ::Item) {
name("Dragonite Chestplate")
lore("A chestplate$LORE")
properties { properties {
humanoidArmor(armorMaterial, ArmorType.CHESTPLATE) humanoidArmor(armorMaterial, ArmorType.CHESTPLATE)
.component(DataComponents.GLIDER, Unit.INSTANCE) .component(DataComponents.GLIDER, Unit.INSTANCE)
.component(DataComponents.UNBREAKABLE, Unit.INSTANCE) .component(DataComponents.UNBREAKABLE, Unit.INSTANCE)
} }
smithingUpgrade(Items.ELYTRA, Items.NETHERITE_CHESTPLATE, INGOT) smithingUpgrade(Items.ELYTRA, Items.NETHERITE_CHESTPLATE, INGOT)
tags("chest_armor")
} }
val LEGGINGS by registerItem("dragonite_leggings", ::Item) { val LEGGINGS by registerItem("dragonite_leggings", ::Item) {
name("Dragonite Leggings")
lore("Leggings$LORE")
properties { properties {
humanoidArmor(armorMaterial, ArmorType.LEGGINGS) humanoidArmor(armorMaterial, ArmorType.LEGGINGS)
} }
smithingUpgrade(Items.CRYING_OBSIDIAN, Items.NETHERITE_LEGGINGS, INGOT) smithingUpgrade(Items.CRYING_OBSIDIAN, Items.NETHERITE_LEGGINGS, INGOT)
tags("leg_armor")
} }
val BOOTS by registerItem("dragonite_boots", ::Item) { val BOOTS by registerItem("dragonite_boots", ::Item) {
name("Dragonite Boots")
lore("Boots$LORE")
properties { properties {
humanoidArmor(armorMaterial, ArmorType.BOOTS) humanoidArmor(armorMaterial, ArmorType.BOOTS)
} }
smithingUpgrade(Items.CRYING_OBSIDIAN, Items.NETHERITE_BOOTS, INGOT) smithingUpgrade(Items.CRYING_OBSIDIAN, Items.NETHERITE_BOOTS, INGOT)
tags("foot_armor")
} }
override val armorSet: ArmorSet = ArmorSet(HELMET, CHESTPLATE, LEGGINGS, BOOTS) override val armorSet: ArmorSet = ArmorSet(HELMET, CHESTPLATE, LEGGINGS, BOOTS)
+22 -2
View File
@@ -3,9 +3,8 @@ package dev.zxq5.items.sets
import dev.zxq5.items.template.ArmorSet import dev.zxq5.items.template.ArmorSet
import dev.zxq5.items.template.GearMaterialDef import dev.zxq5.items.template.GearMaterialDef
import dev.zxq5.items.template.GenericGearSet 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.fabricmc.fabric.api.entity.event.v1.ServerLivingEntityEvents
import net.minecraft.ChatFormatting
import net.minecraft.core.BlockPos import net.minecraft.core.BlockPos
import net.minecraft.core.component.DataComponents import net.minecraft.core.component.DataComponents
import net.minecraft.core.particles.ParticleTypes import net.minecraft.core.particles.ParticleTypes
@@ -32,7 +31,13 @@ object Ender: GenericGearSet() {
override val materialDefinition override val materialDefinition
get() = GearMaterialDef.DIAMOND.copy(assetId = materialKey) 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) { val ENDER_INGOT by registerItem("ender_ingot", ::Item) {
name("Ender Ingot")
lore(LORE)
shapedRecipe("EDE", "DED", "EDE", key=mapOf( shapedRecipe("EDE", "DED", "EDE", key=mapOf(
'E' to Items.ENDER_EYE, 'E' to Items.ENDER_EYE,
'D' to Items.DIAMOND, 'D' to Items.DIAMOND,
@@ -40,40 +45,55 @@ object Ender: GenericGearSet() {
} }
val SWORD by registerItem("ender_sword", ::EnderSword) { val SWORD by registerItem("ender_sword", ::EnderSword) {
name("Ender Sword")
lore(LORE)
properties { properties {
enchantable(armorMaterial.enchantmentValue) enchantable(armorMaterial.enchantmentValue)
.component(DataComponents.USE_COOLDOWN, UseCooldown(3f)) .component(DataComponents.USE_COOLDOWN, UseCooldown(3f))
.sword(ToolMaterial.DIAMOND, 3F, -2.4F) .sword(ToolMaterial.DIAMOND, 3F, -2.4F)
} }
smithingUpgrade(Items.NETHERITE_UPGRADE_SMITHING_TEMPLATE, Items.DIAMOND_SWORD, ENDER_INGOT) smithingUpgrade(Items.NETHERITE_UPGRADE_SMITHING_TEMPLATE, Items.DIAMOND_SWORD, ENDER_INGOT)
tags("swords")
} }
val HELMET by registerItem("ender_helmet", ::Item) { val HELMET by registerItem("ender_helmet", ::Item) {
name("Ender Helmet")
lore(LORE)
properties { properties {
humanoidArmor(armorMaterial, ArmorType.HELMET) humanoidArmor(armorMaterial, ArmorType.HELMET)
} }
smithingUpgrade(Items.NETHERITE_UPGRADE_SMITHING_TEMPLATE, Items.DIAMOND_HELMET, ENDER_INGOT) smithingUpgrade(Items.NETHERITE_UPGRADE_SMITHING_TEMPLATE, Items.DIAMOND_HELMET, ENDER_INGOT)
tags("head_armor")
} }
val CHESTPLATE by registerItem("ender_chestplate", ::Item) { val CHESTPLATE by registerItem("ender_chestplate", ::Item) {
name("Ender Chestplate")
lore(LORE)
properties { properties {
humanoidArmor(armorMaterial, ArmorType.CHESTPLATE) humanoidArmor(armorMaterial, ArmorType.CHESTPLATE)
} }
smithingUpgrade(Items.NETHERITE_UPGRADE_SMITHING_TEMPLATE, Items.DIAMOND_CHESTPLATE, ENDER_INGOT) smithingUpgrade(Items.NETHERITE_UPGRADE_SMITHING_TEMPLATE, Items.DIAMOND_CHESTPLATE, ENDER_INGOT)
tags("chest_armor")
} }
val LEGGINGS by registerItem("ender_leggings", ::Item) { val LEGGINGS by registerItem("ender_leggings", ::Item) {
name("Ender Leggings")
lore(LORE)
properties { properties {
humanoidArmor(armorMaterial, ArmorType.LEGGINGS) humanoidArmor(armorMaterial, ArmorType.LEGGINGS)
} }
smithingUpgrade(Items.NETHERITE_UPGRADE_SMITHING_TEMPLATE, Items.DIAMOND_LEGGINGS, ENDER_INGOT) smithingUpgrade(Items.NETHERITE_UPGRADE_SMITHING_TEMPLATE, Items.DIAMOND_LEGGINGS, ENDER_INGOT)
tags("leg_armor")
} }
val BOOTS by registerItem("ender_boots", ::Item) { val BOOTS by registerItem("ender_boots", ::Item) {
name("Ender Boots")
lore(LORE)
properties { properties {
humanoidArmor(armorMaterial, ArmorType.BOOTS) humanoidArmor(armorMaterial, ArmorType.BOOTS)
} }
smithingUpgrade(Items.NETHERITE_UPGRADE_SMITHING_TEMPLATE, Items.DIAMOND_BOOTS, ENDER_INGOT) smithingUpgrade(Items.NETHERITE_UPGRADE_SMITHING_TEMPLATE, Items.DIAMOND_BOOTS, ENDER_INGOT)
tags("foot_armor")
} }
override val armorSet: ArmorSet = ArmorSet(HELMET, CHESTPLATE, LEGGINGS, BOOTS) 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.ArmorSet
import dev.zxq5.items.template.GenericGearSet import dev.zxq5.items.template.GenericGearSet
import dev.zxq5.items.template.registerItem import dev.zxq5.items.template.ModelSpec
import dev.zxq5.items.template.provideDelegate
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents
import net.minecraft.ChatFormatting
import net.minecraft.core.component.DataComponents import net.minecraft.core.component.DataComponents
import net.minecraft.sounds.SoundEvents import net.minecraft.sounds.SoundEvents
import net.minecraft.world.InteractionHand import net.minecraft.world.InteractionHand
@@ -31,7 +31,14 @@ object Witherite: GenericGearSet() {
override val materialDefinition override val materialDefinition
get() = super.materialDefinition.copy(assetId = materialKey) 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) { val SHIELD by registerItem("witherite_shield", ::Item) {
name("Witherite Shield")
lore("A shield$LORE")
properties { properties {
component(DataComponents.BLOCKS_ATTACKS, BlocksAttacks( component(DataComponents.BLOCKS_ATTACKS, BlocksAttacks(
0.25f, // 5 tick warmup 0.25f, // 5 tick warmup
@@ -54,49 +61,69 @@ object Witherite: GenericGearSet() {
} }
val SWORD by registerItem("witherite_sword", ::WitheriteSword) { val SWORD by registerItem("witherite_sword", ::WitheriteSword) {
name("Witherite Sword")
lore("A sword$LORE")
model(ModelSpec.Handheld)
properties { properties {
enchantable(armorMaterial.enchantmentValue) enchantable(armorMaterial.enchantmentValue)
.component(DataComponents.USE_COOLDOWN, UseCooldown(2f)) .component(DataComponents.USE_COOLDOWN, UseCooldown(2f))
.sword(ToolMaterial.NETHERITE, 3F, -2.4F) .sword(ToolMaterial.NETHERITE, 3F, -2.4F)
} }
smithingUpgrade(Items.NETHERITE_UPGRADE_SMITHING_TEMPLATE, Items.NETHERITE_SWORD, Items.WITHER_SKELETON_SKULL) smithingUpgrade(Items.NETHERITE_UPGRADE_SMITHING_TEMPLATE, Items.NETHERITE_SWORD, Items.WITHER_SKELETON_SKULL)
tags("swords")
} }
val AXE by registerItem("witherite_axe", ::WitheriteWeapon) { val AXE by registerItem("witherite_axe", ::WitheriteWeapon) {
name("Witherite Axe")
lore("An axe$LORE")
model(ModelSpec.Handheld)
properties { properties {
enchantable(armorMaterial.enchantmentValue) enchantable(armorMaterial.enchantmentValue)
.component(DataComponents.USE_COOLDOWN, UseCooldown(2f)) .component(DataComponents.USE_COOLDOWN, UseCooldown(2f))
.axe(ToolMaterial.NETHERITE, 3F, -3F) .axe(ToolMaterial.NETHERITE, 3F, -3F)
} }
smithingUpgrade(Items.NETHERITE_UPGRADE_SMITHING_TEMPLATE, Items.NETHERITE_AXE, Items.WITHER_SKELETON_SKULL) smithingUpgrade(Items.NETHERITE_UPGRADE_SMITHING_TEMPLATE, Items.NETHERITE_AXE, Items.WITHER_SKELETON_SKULL)
tags("axes")
} }
val HELMET by registerItem("witherite_helmet", ::Item) { val HELMET by registerItem("witherite_helmet", ::Item) {
name("Witherite Helmet")
lore("A helmet$LORE")
properties { properties {
humanoidArmor(armorMaterial, ArmorType.HELMET) humanoidArmor(armorMaterial, ArmorType.HELMET)
} }
smithingUpgrade(Items.NETHERITE_UPGRADE_SMITHING_TEMPLATE, Items.NETHERITE_HELMET, Items.WITHER_SKELETON_SKULL) smithingUpgrade(Items.NETHERITE_UPGRADE_SMITHING_TEMPLATE, Items.NETHERITE_HELMET, Items.WITHER_SKELETON_SKULL)
tags("head_armor")
} }
val CHESTPLATE by registerItem("witherite_chestplate", ::Item) { val CHESTPLATE by registerItem("witherite_chestplate", ::Item) {
name("Witherite Chestplate")
lore("A chestplate$LORE")
properties { properties {
humanoidArmor(armorMaterial, ArmorType.CHESTPLATE) humanoidArmor(armorMaterial, ArmorType.CHESTPLATE)
} }
smithingUpgrade(Items.NETHERITE_UPGRADE_SMITHING_TEMPLATE, Items.NETHERITE_CHESTPLATE, Items.WITHER_SKELETON_SKULL) smithingUpgrade(Items.NETHERITE_UPGRADE_SMITHING_TEMPLATE, Items.NETHERITE_CHESTPLATE, Items.WITHER_SKELETON_SKULL)
tags("chest_armor")
} }
val LEGGINGS by registerItem("witherite_leggings", ::Item) { val LEGGINGS by registerItem("witherite_leggings", ::Item) {
name("Witherite Leggings")
lore("Leggings$LORE")
properties { properties {
humanoidArmor(armorMaterial, ArmorType.LEGGINGS) humanoidArmor(armorMaterial, ArmorType.LEGGINGS)
} }
smithingUpgrade(Items.NETHERITE_UPGRADE_SMITHING_TEMPLATE, Items.NETHERITE_LEGGINGS, Items.WITHER_SKELETON_SKULL) smithingUpgrade(Items.NETHERITE_UPGRADE_SMITHING_TEMPLATE, Items.NETHERITE_LEGGINGS, Items.WITHER_SKELETON_SKULL)
tags("leg_armor")
} }
val BOOTS by registerItem("witherite_boots", ::Item) { val BOOTS by registerItem("witherite_boots", ::Item) {
name("Witherite Boots")
lore("Boots$LORE")
properties { properties {
humanoidArmor(armorMaterial, ArmorType.BOOTS) humanoidArmor(armorMaterial, ArmorType.BOOTS)
} }
smithingUpgrade(Items.NETHERITE_UPGRADE_SMITHING_TEMPLATE, Items.NETHERITE_BOOTS, Items.WITHER_SKELETON_SKULL) 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) override val armorSet: ArmorSet = ArmorSet(HELMET, CHESTPLATE, LEGGINGS, BOOTS)
@@ -1,5 +1,6 @@
package dev.zxq5.items.template package dev.zxq5.items.template
import dev.zxq5.Fantasysmp
import dev.zxq5.util.resourceKey import dev.zxq5.util.resourceKey
import net.minecraft.core.Holder import net.minecraft.core.Holder
import net.minecraft.resources.ResourceKey import net.minecraft.resources.ResourceKey
@@ -19,6 +20,14 @@ abstract class GenericGearSet: GenericItemSet() {
abstract val armorSet: ArmorSet 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> open val materialKey: ResourceKey<EquipmentAsset>
get() = materialName.resourceKey() get() = materialName.resourceKey()
@@ -33,7 +42,7 @@ abstract class GenericGearSet: GenericItemSet() {
materialDefinition.toArmorMaterial() materialDefinition.toArmorMaterial()
} }
fun fullSetEquippedBy(p: Player) = open fun fullSetEquippedBy(p: Player) =
p.getItemBySlot(EquipmentSlot.HEAD).item == armorSet.helmet && p.getItemBySlot(EquipmentSlot.HEAD).item == armorSet.helmet &&
p.getItemBySlot(EquipmentSlot.CHEST).item == armorSet.chestplate && p.getItemBySlot(EquipmentSlot.CHEST).item == armorSet.chestplate &&
p.getItemBySlot(EquipmentSlot.LEGS).item == armorSet.leggings && p.getItemBySlot(EquipmentSlot.LEGS).item == armorSet.leggings &&
@@ -1,27 +1,29 @@
package dev.zxq5.items.template package dev.zxq5.items.template
import dev.zxq5.Fantasysmp
import dev.zxq5.items.ModItems 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.InventoryChangeTrigger
import net.minecraft.advancements.criterion.ItemPredicate import net.minecraft.advancements.criterion.ItemPredicate
import net.minecraft.core.HolderGetter import net.minecraft.core.HolderGetter
import net.minecraft.core.HolderLookup import net.minecraft.core.HolderLookup
import net.minecraft.core.component.DataComponents
import net.minecraft.core.registries.BuiltInRegistries import net.minecraft.core.registries.BuiltInRegistries
import net.minecraft.core.registries.Registries import net.minecraft.core.registries.Registries
import net.minecraft.data.recipes.RecipeCategory import net.minecraft.data.recipes.*
import net.minecraft.data.recipes.RecipeOutput import net.minecraft.network.chat.Component
import net.minecraft.data.recipes.RecipeProvider
import net.minecraft.data.recipes.ShapedRecipeBuilder
import net.minecraft.data.recipes.SmithingTransformRecipeBuilder
import net.minecraft.tags.TagKey import net.minecraft.tags.TagKey
import net.minecraft.world.item.Item import net.minecraft.world.item.Item
import net.minecraft.world.item.component.ItemLore
import net.minecraft.world.item.crafting.Ingredient import net.minecraft.world.item.crafting.Ingredient
import kotlin.collections.component1
import kotlin.collections.component2
import kotlin.reflect.KProperty import kotlin.reflect.KProperty
abstract class GenericItemSet { abstract class GenericItemSet {
// list of all items part of the class // list of all items part of the class
open val lore_style = ChatFormatting.GRAY
abstract val items: List<Item> abstract val items: List<Item>
open fun onLoad() {} open fun onLoad() {}
@@ -29,15 +31,28 @@ abstract class GenericItemSet {
private val itemRecipes = mutableMapOf<Item, List<RecipeSpec>>() private val itemRecipes = mutableMapOf<Item, List<RecipeSpec>>()
private val itemTags = mutableMapOf<Item, List<TagKey<Item>>>() private val itemTags = mutableMapOf<Item, List<TagKey<Item>>>()
private val itemModels = mutableMapOf<Item, ModelSpec>() private val itemModels = mutableMapOf<Item, ModelSpec>()
private val itemTranslations = mutableMapOf<String, String>()
val modelSpecs: Map<Item, ModelSpec> get() = itemModels 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 itemRecipes[item] = recipes
itemTags[item] = tags itemTags[item] = tags
itemModels[item] = model itemModels[item] = model
itemTranslations.putAll(translations)
} }
open fun generateItemTags(tags: ItemTagAdder) { open fun generateItemTags(provider: HolderLookup.Provider): Map<Item, List<TagKey<Item>>> {
itemTags.forEach { (item, tagList) -> tagList.forEach { tags.add(it, 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) { open fun generateRecipes(registries: HolderLookup.Provider, exporter: RecipeOutput) {
@@ -68,12 +83,20 @@ abstract class GenericItemSet {
} }
} }
} }
} };
init { init {
register(this) 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 { companion object {
private val _all = mutableListOf<GenericItemSet>() 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>( class CustomItemBuilder<T : Item>(
private val owner: GenericItemSet, private val owner: GenericItemSet,
val name: String, val name: String,
@@ -92,12 +122,35 @@ class CustomItemBuilder<T : Item>(
private var properties = Item.Properties() private var properties = Item.Properties()
private val recipes = mutableListOf<RecipeSpec>() private val recipes = mutableListOf<RecipeSpec>()
private val tags = mutableListOf<TagKey<Item>>() 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) { fun model(spec: ModelSpec) {
modelSpec = spec 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) { fun properties(block: Item.Properties.() -> Item.Properties) {
properties = properties.block() properties = properties.block()
} }
@@ -110,21 +163,25 @@ class CustomItemBuilder<T : Item>(
recipes += RecipeSpec.Shaped(pattern.toList(), key) recipes += RecipeSpec.Shaped(pattern.toList(), key)
} }
fun tags(vararg tag: String) {
tag.forEach {
tags += mcItemTag(it)
}
}
fun tags(vararg tag: TagKey<Item>) { fun tags(vararg tag: TagKey<Item>) {
tags += tag tags += tag
} }
internal fun build(): T { internal fun build(): T {
val item = ModItems.register(name, itemFactory, properties) val item = ModItems.register(name, itemFactory, properties)
owner.registerDatagen(item, recipes, tags, modelSpec) owner.registerDatagen(item, recipes, tags, modelSpec, translations)
return item return item
} }
}
class ItemTagAdder(private val provider: FabricTagsProvider.ItemTagsProvider) { operator fun provideDelegate(
fun add(tag: TagKey<Item>, vararg items: Item) { thisRef: Any?, property: KProperty<*>
provider.apply { items.forEach { add(tag, it) } } ): Lazy<T> = lazy { build() }
}
} }
sealed interface RecipeSpec { sealed interface RecipeSpec {
@@ -138,14 +195,4 @@ sealed interface ModelSpec {
data object None : ModelSpec // handwritten JSON already exists, skip auto-gen 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 operator fun <T : Item> Lazy<T>.getValue(thisRef: Any?, property: KProperty<*>): T = value
@@ -1,14 +0,0 @@
{
"layers": {
"humanoid": [
{
"texture": "fantasysmp:crimson"
}
],
"humanoid_leggings": [
{
"texture": "fantasysmp:crimson"
}
]
}
}
@@ -1,20 +0,0 @@
{
"layers": {
"humanoid": [
{
"texture": "fantasysmp:dragonite"
}
],
"humanoid_leggings": [
{
"texture": "fantasysmp:dragonite"
}
],
"wings": [
{
"texture": "fantasysmp:dragonite",
"use_player_texture": false
}
]
}
}
@@ -1,14 +0,0 @@
{
"layers": {
"humanoid": [
{
"texture": "fantasysmp:ender"
}
],
"humanoid_leggings": [
{
"texture": "fantasysmp:ender"
}
]
}
}
@@ -1,14 +0,0 @@
{
"layers": {
"humanoid": [
{
"texture": "fantasysmp:mechanist"
}
],
"humanoid_leggings": [
{
"texture": "fantasysmp:mechanist"
}
]
}
}
@@ -1,14 +0,0 @@
{
"layers": {
"humanoid": [
{
"texture": "fantasysmp:poseidon"
}
],
"humanoid_leggings": [
{
"texture": "fantasysmp:poseidon"
}
]
}
}
@@ -1,14 +0,0 @@
{
"layers": {
"humanoid": [
{
"texture": "fantasysmp:true_netherite"
}
],
"humanoid_leggings": [
{
"texture": "fantasysmp:true_netherite"
}
]
}
}
@@ -1,14 +0,0 @@
{
"layers": {
"humanoid": [
{
"texture": "fantasysmp:witherite"
}
],
"humanoid_leggings": [
{
"texture": "fantasysmp:witherite"
}
]
}
}
BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.6 KiB

After

Width:  |  Height:  |  Size: 113 KiB

@@ -1,6 +0,0 @@
{
"model": {
"type": "minecraft:model",
"model": "fantasysmp:item/alchemist_chestplate"
}
}
@@ -1,6 +0,0 @@
{
"model": {
"type": "minecraft:model",
"model": "fantasysmp:item/alchemist_leggings"
}
}
@@ -1,6 +0,0 @@
{
"model": {
"type": "minecraft:model",
"model": "fantasysmp:item/blazing_boots"
}
}
@@ -1,6 +0,0 @@
{
"model": {
"type": "minecraft:model",
"model": "fantasysmp:item/blazing_chestplate"
}
}
@@ -1,6 +0,0 @@
{
"model": {
"type": "minecraft:model",
"model": "fantasysmp:item/blazing_helmet"
}
}
@@ -1,6 +0,0 @@
{
"model": {
"type": "minecraft:model",
"model": "fantasysmp:item/blazing_leggings"
}
}
@@ -1,6 +0,0 @@
{
"model": {
"type": "minecraft:model",
"model": "fantasysmp:item/blazing_sword"
}
}
@@ -1,6 +0,0 @@
{
"model": {
"type": "minecraft:model",
"model": "fantasysmp:item/crimson_sword"
}
}
@@ -1,6 +0,0 @@
{
"model": {
"type": "minecraft:model",
"model": "fantasysmp:item/dragon_scale"
}
}
@@ -1,6 +0,0 @@
{
"model": {
"type": "minecraft:model",
"model": "fantasysmp:item/dragonite_boots"
}
}
@@ -1,6 +0,0 @@
{
"model": {
"type": "minecraft:model",
"model": "fantasysmp:item/dragonite_chestplate"
}
}
@@ -1,6 +0,0 @@
{
"model": {
"type": "minecraft:model",
"model": "fantasysmp:item/dragonite_helmet"
}
}
@@ -1,6 +0,0 @@
{
"model": {
"type": "minecraft:model",
"model": "fantasysmp:item/dragonite_ingot"
}
}
@@ -1,6 +0,0 @@
{
"model": {
"type": "minecraft:model",
"model": "fantasysmp:item/dragonite_leggings"
}
}
@@ -1,6 +0,0 @@
{
"model": {
"type": "minecraft:model",
"model": "fantasysmp:item/dragonite_sword"
}
}
@@ -1,6 +0,0 @@
{
"model": {
"type": "minecraft:model",
"model": "fantasysmp:item/ender_boots"
}
}
@@ -1,6 +0,0 @@
{
"model": {
"type": "minecraft:model",
"model": "fantasysmp:item/ender_chestplate"
}
}
@@ -1,6 +0,0 @@
{
"model": {
"type": "minecraft:model",
"model": "fantasysmp:item/ender_helmet"
}
}
@@ -1,6 +0,0 @@
{
"model": {
"type": "minecraft:model",
"model": "fantasysmp:item/ender_leggings"
}
}
@@ -1,6 +0,0 @@
{
"model": {
"type": "minecraft:model",
"model": "fantasysmp:item/ender_sword"
}
}
@@ -1,6 +0,0 @@
{
"model": {
"type": "minecraft:model",
"model": "fantasysmp:item/lightning_sword"
}
}
@@ -1,6 +0,0 @@
{
"model": {
"type": "minecraft:model",
"model": "fantasysmp:item/poseidons_boots"
}
}

Some files were not shown because too many files have changed in this diff Show More