new item builder kinda works. making sure everything is moved across, then i gotta start on the new set
build / build (push) Failing after 3m33s

This commit is contained in:
2026-07-08 00:34:10 +01:00
parent 08c1800cac
commit 5f6350943e
26 changed files with 458 additions and 99 deletions
+2 -1
View File
@@ -49,6 +49,7 @@ tasks.processResources {
val version = version val version = version
inputs.property("version", version) inputs.property("version", version)
duplicatesStrategy = DuplicatesStrategy.INCLUDE
filesMatching("fabric.mod.json") { filesMatching("fabric.mod.json") {
expand("version" to version) expand("version" to version)
} }
@@ -78,7 +79,7 @@ tasks.jar {
val projectName = project.name val projectName = project.name
inputs.property("projectName", projectName) inputs.property("projectName", projectName)
duplicatesStrategy = DuplicatesStrategy.EXCLUDE duplicatesStrategy = DuplicatesStrategy.INCLUDE
from("LICENSE") { from("LICENSE") {
rename { "${it}_$projectName" } rename { "${it}_$projectName" }
} }
@@ -2,6 +2,7 @@ package dev.zxq5.client
import dev.zxq5.ModItemTagProvider import dev.zxq5.ModItemTagProvider
import dev.zxq5.ModRecipeProvider import dev.zxq5.ModRecipeProvider
import dev.zxq5.items.GenericGearSet
import dev.zxq5.items.ItemImplementation import dev.zxq5.items.ItemImplementation
import net.fabricmc.fabric.api.client.datagen.v1.provider.FabricModelProvider import net.fabricmc.fabric.api.client.datagen.v1.provider.FabricModelProvider
import net.fabricmc.fabric.api.datagen.v1.DataGeneratorEntrypoint import net.fabricmc.fabric.api.datagen.v1.DataGeneratorEntrypoint
@@ -9,21 +10,34 @@ import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator
import net.fabricmc.fabric.api.datagen.v1.FabricPackOutput 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
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) // main-safe, can live in either sourceSet
pack.addProvider(::ModItemTagProvider) // main-safe // pack.addProvider(::ModItemTagProvider) // main-safe
pack.addProvider(::ModModelProvider) // needs client, since ItemModelGenerators is client-only // pack.addProvider(::ModModelProvider) // needs client, since ItemModelGenerators is client-only
} }
} }
// client sourceSet // client sourceSet
class ModModelProvider(output: FabricPackOutput) : FabricModelProvider(output) { //class ModModelProvider(output: FabricPackOutput) : FabricModelProvider(output) {
override fun generateBlockStateModels(blockModels: BlockModelGenerators) {} // override fun generateBlockStateModels(blockModels: BlockModelGenerators) {}
//
// override fun generateItemModels(itemModels: ItemModelGenerators) {
// ItemImplementation.all.forEach { it.generateModels(itemModels) }
// }
//}
override fun generateItemModels(itemModels: ItemModelGenerators) { // client sourceSet
ItemImplementation.all.forEach { it.generateItemModels(itemModels) } //fun ItemImplementation.generateModels(itemModels: ItemModelGenerators) {
} // if (this !is GenericGearSet) return
} // modelSpecs.forEach { (item, spec) ->
// when (spec) {
// ModelSpec.Generated -> itemModels.generateFlatItem(item, ModelTemplates.FLAT_ITEM)
// ModelSpec.Handheld -> itemModels.generateFlatItem(item, ModelTemplates.FLAT_HANDHELD_ITEM)
// ModelSpec.None -> {} // nothing to do — hand-authored JSON covers it
// }
// }
//}
@@ -0,0 +1,32 @@
{
"parent": "minecraft:recipes/root",
"criteria": {
"has_addition": {
"conditions": {
"items": [
{
"items": "minecraft:wither_skeleton_skull"
}
]
},
"trigger": "minecraft:inventory_changed"
},
"has_the_recipe": {
"conditions": {
"recipe": "fantasysmp:witherite_axe"
},
"trigger": "minecraft:recipe_unlocked"
}
},
"requirements": [
[
"has_the_recipe",
"has_addition"
]
],
"rewards": {
"recipes": [
"fantasysmp:witherite_axe"
]
}
}
@@ -0,0 +1,32 @@
{
"parent": "minecraft:recipes/root",
"criteria": {
"has_addition": {
"conditions": {
"items": [
{
"items": "minecraft:wither_skeleton_skull"
}
]
},
"trigger": "minecraft:inventory_changed"
},
"has_the_recipe": {
"conditions": {
"recipe": "fantasysmp:witherite_boots"
},
"trigger": "minecraft:recipe_unlocked"
}
},
"requirements": [
[
"has_the_recipe",
"has_addition"
]
],
"rewards": {
"recipes": [
"fantasysmp:witherite_boots"
]
}
}
@@ -0,0 +1,32 @@
{
"parent": "minecraft:recipes/root",
"criteria": {
"has_addition": {
"conditions": {
"items": [
{
"items": "minecraft:wither_skeleton_skull"
}
]
},
"trigger": "minecraft:inventory_changed"
},
"has_the_recipe": {
"conditions": {
"recipe": "fantasysmp:witherite_chestplate"
},
"trigger": "minecraft:recipe_unlocked"
}
},
"requirements": [
[
"has_the_recipe",
"has_addition"
]
],
"rewards": {
"recipes": [
"fantasysmp:witherite_chestplate"
]
}
}
@@ -0,0 +1,32 @@
{
"parent": "minecraft:recipes/root",
"criteria": {
"has_addition": {
"conditions": {
"items": [
{
"items": "minecraft:wither_skeleton_skull"
}
]
},
"trigger": "minecraft:inventory_changed"
},
"has_the_recipe": {
"conditions": {
"recipe": "fantasysmp:witherite_helmet"
},
"trigger": "minecraft:recipe_unlocked"
}
},
"requirements": [
[
"has_the_recipe",
"has_addition"
]
],
"rewards": {
"recipes": [
"fantasysmp:witherite_helmet"
]
}
}
@@ -0,0 +1,32 @@
{
"parent": "minecraft:recipes/root",
"criteria": {
"has_addition": {
"conditions": {
"items": [
{
"items": "minecraft:wither_skeleton_skull"
}
]
},
"trigger": "minecraft:inventory_changed"
},
"has_the_recipe": {
"conditions": {
"recipe": "fantasysmp:witherite_leggings"
},
"trigger": "minecraft:recipe_unlocked"
}
},
"requirements": [
[
"has_the_recipe",
"has_addition"
]
],
"rewards": {
"recipes": [
"fantasysmp:witherite_leggings"
]
}
}
@@ -0,0 +1,32 @@
{
"parent": "minecraft:recipes/root",
"criteria": {
"has_addition": {
"conditions": {
"items": [
{
"items": "minecraft:wither_skeleton_skull"
}
]
},
"trigger": "minecraft:inventory_changed"
},
"has_the_recipe": {
"conditions": {
"recipe": "fantasysmp:witherite_sword"
},
"trigger": "minecraft:recipe_unlocked"
}
},
"requirements": [
[
"has_the_recipe",
"has_addition"
]
],
"rewards": {
"recipes": [
"fantasysmp:witherite_sword"
]
}
}
@@ -0,0 +1,9 @@
{
"type": "minecraft:smithing_transform",
"addition": "minecraft:wither_skeleton_skull",
"base": "minecraft:netherite_axe",
"result": {
"id": "fantasysmp:witherite_axe"
},
"template": "minecraft:netherite_upgrade_smithing_template"
}
@@ -0,0 +1,9 @@
{
"type": "minecraft:smithing_transform",
"addition": "minecraft:wither_skeleton_skull",
"base": "minecraft:netherite_boots",
"result": {
"id": "fantasysmp:witherite_boots"
},
"template": "minecraft:netherite_upgrade_smithing_template"
}
@@ -0,0 +1,9 @@
{
"type": "minecraft:smithing_transform",
"addition": "minecraft:wither_skeleton_skull",
"base": "minecraft:netherite_chestplate",
"result": {
"id": "fantasysmp:witherite_chestplate"
},
"template": "minecraft:netherite_upgrade_smithing_template"
}
@@ -0,0 +1,9 @@
{
"type": "minecraft:smithing_transform",
"addition": "minecraft:wither_skeleton_skull",
"base": "minecraft:netherite_helmet",
"result": {
"id": "fantasysmp:witherite_helmet"
},
"template": "minecraft:netherite_upgrade_smithing_template"
}
@@ -0,0 +1,9 @@
{
"type": "minecraft:smithing_transform",
"addition": "minecraft:wither_skeleton_skull",
"base": "minecraft:netherite_leggings",
"result": {
"id": "fantasysmp:witherite_leggings"
},
"template": "minecraft:netherite_upgrade_smithing_template"
}
@@ -0,0 +1,9 @@
{
"type": "minecraft:smithing_transform",
"addition": "minecraft:wither_skeleton_skull",
"base": "minecraft:netherite_sword",
"result": {
"id": "fantasysmp:witherite_sword"
},
"template": "minecraft:netherite_upgrade_smithing_template"
}
+6 -1
View File
@@ -4,6 +4,7 @@ import dev.zxq5.items.ItemImplementation
import dev.zxq5.items.ItemTagAdder import dev.zxq5.items.ItemTagAdder
import dev.zxq5.items.ModItems import dev.zxq5.items.ModItems
import dev.zxq5.items.Witherite import dev.zxq5.items.Witherite
//import dev.zxq5.items.Witherite
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.FabricRecipeProvider import net.fabricmc.fabric.api.datagen.v1.provider.FabricRecipeProvider
@@ -49,7 +50,11 @@ class ModRecipeProvider(
): RecipeProvider { ): RecipeProvider {
return object : RecipeProvider(registries, exporter) { return object : RecipeProvider(registries, exporter) {
override fun buildRecipes() { override fun buildRecipes() {
ItemImplementation.all.forEach { it.generateRecipes(registries, exporter) } print("GENERATING ALL RECIPES")
ItemImplementation.all.forEach {
print("GENERATING RECIPES FOR" + it.items.toString())
it.generateRecipes(registries, exporter)
}
} }
} }
} }
+15 -33
View File
@@ -22,29 +22,10 @@ import net.minecraft.world.item.equipment.*
import net.minecraft.world.level.Level import net.minecraft.world.level.Level
object Dragonite { object Dragonite: GenericGearSet() {
const val BASE_DURABILITY = 40; override val materialName = "dragonite"
val MATERIAL: ResourceKey<EquipmentAsset> = ResourceKey.create<EquipmentAsset>( override val materialDefinition
EquipmentAssets.ROOT_ID, get() = super.materialDefinition.copy(assetId = materialKey)
Identifier.fromNamespaceAndPath(Fantasysmp.MOD_ID, "dragonite")
)
val armorMaterial = ArmorMaterial(
BASE_DURABILITY,
mapOf(
ArmorType.HELMET to 3,
ArmorType.CHESTPLATE to 8,
ArmorType.LEGGINGS to 6,
ArmorType.BOOTS to 3,
ArmorType.BODY to 19,
),
5,
SoundEvents.ARMOR_EQUIP_NETHERITE,
3.0f,
0.1f,
ItemTags.REPAIRS_NETHERITE_ARMOR,
MATERIAL,
)
val SWORD = register("dragonite_sword", ::DragoniteSword, val SWORD = register("dragonite_sword", ::DragoniteSword,
Item.Properties() Item.Properties()
@@ -56,7 +37,7 @@ object Dragonite {
"dragonite_helmet", "dragonite_helmet",
::Item, ::Item,
Item.Properties() Item.Properties()
.enchantable(Witherite.armorMaterial.enchantmentValue) .enchantable(armorMaterial.enchantmentValue)
.humanoidArmor(armorMaterial , ArmorType.HELMET) .humanoidArmor(armorMaterial , ArmorType.HELMET)
.durability(ArmorType.HELMET.getDurability(armorMaterial.durability)) .durability(ArmorType.HELMET.getDurability(armorMaterial.durability))
) )
@@ -65,7 +46,7 @@ object Dragonite {
"dragonite_chestplate", "dragonite_chestplate",
::Item, ::Item,
Item.Properties() Item.Properties()
.enchantable(Witherite.armorMaterial.enchantmentValue) .enchantable(armorMaterial.enchantmentValue)
.humanoidArmor(armorMaterial , ArmorType.CHESTPLATE) .humanoidArmor(armorMaterial , ArmorType.CHESTPLATE)
.component(DataComponents.GLIDER, Unit.INSTANCE) .component(DataComponents.GLIDER, Unit.INSTANCE)
.durability(ArmorType.CHESTPLATE.getDurability(armorMaterial.durability)) .durability(ArmorType.CHESTPLATE.getDurability(armorMaterial.durability))
@@ -75,7 +56,7 @@ object Dragonite {
"dragonite_leggings", "dragonite_leggings",
::Item, ::Item,
Item.Properties() Item.Properties()
.enchantable(Witherite.armorMaterial.enchantmentValue) .enchantable(armorMaterial.enchantmentValue)
.humanoidArmor(armorMaterial , ArmorType.LEGGINGS) .humanoidArmor(armorMaterial , ArmorType.LEGGINGS)
.durability(ArmorType.LEGGINGS.getDurability(armorMaterial.durability)) .durability(ArmorType.LEGGINGS.getDurability(armorMaterial.durability))
) )
@@ -84,7 +65,7 @@ object Dragonite {
"dragonite_boots", "dragonite_boots",
::Item, ::Item,
Item.Properties() Item.Properties()
.enchantable(Witherite.armorMaterial.enchantmentValue) .enchantable(armorMaterial.enchantmentValue)
.humanoidArmor(armorMaterial , ArmorType.BOOTS) .humanoidArmor(armorMaterial , ArmorType.BOOTS)
.durability(ArmorType.BOOTS.getDurability(armorMaterial.durability)) .durability(ArmorType.BOOTS.getDurability(armorMaterial.durability))
) )
@@ -101,18 +82,19 @@ object Dragonite {
Item.Properties() Item.Properties()
) )
val ITEMS = listOf(SWORD, HELMET, CHESTPLATE, LEGGINGS, BOOTS, INGOT, SCALE) override val armorSet: ArmorSet = ArmorSet(HELMET, CHESTPLATE, LEGGINGS, BOOTS)
val ARMOUR_SET = ArmorSet(HELMET, CHESTPLATE, LEGGINGS, BOOTS) override val items = listOf(SWORD, HELMET, CHESTPLATE, LEGGINGS, BOOTS, SCALE, INGOT)
override fun onLoad() {}
fun init() {}
} }
class DragoniteSword(properties: Properties) : Item(properties) { class DragoniteSword(properties: Properties) : Item(properties) {
override fun use(level: Level, user: Player, hand: InteractionHand): InteractionResult { override fun use(level: Level, user: Player, hand: InteractionHand): InteractionResult {
// if (level.isClientSide || !user.isWearingFullSet(Dragonite.ARMOUR_SET)) return InteractionResult.PASS if (level.isClientSide || !Dragonite.fullSetEquippedBy(user)) return InteractionResult.PASS
val direction = user.lookAngle val direction = user.lookAngle
user.deltaMovement = direction.scale(2.0)
val scale = if (user.isFallFlying) { 4.0 } else { 1.5 }
user.deltaMovement = direction.scale(scale)
user.hurtMarked = true user.hurtMarked = true
level.playSound(null, user.x, user.y, user.z, level.playSound(null, user.x, user.y, user.z,
+60 -9
View File
@@ -3,11 +3,11 @@ package dev.zxq5.items
import dev.zxq5.Fantasysmp import dev.zxq5.Fantasysmp
import dev.zxq5.util.id import dev.zxq5.util.id
import dev.zxq5.util.resourceKey import dev.zxq5.util.resourceKey
import kotlinx.serialization.descriptors.StructureKind
import net.fabricmc.fabric.api.creativetab.v1.FabricCreativeModeTab import net.fabricmc.fabric.api.creativetab.v1.FabricCreativeModeTab
import net.fabricmc.fabric.api.datagen.v1.provider.FabricTagsProvider import net.fabricmc.fabric.api.datagen.v1.provider.FabricTagsProvider
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.client.data.models.ItemModelGenerators
import net.minecraft.core.Holder import net.minecraft.core.Holder
import net.minecraft.core.HolderGetter import net.minecraft.core.HolderGetter
import net.minecraft.core.HolderLookup import net.minecraft.core.HolderLookup
@@ -41,8 +41,9 @@ abstract class ItemImplementation {
abstract fun onLoad() abstract fun onLoad()
open fun generateRecipes(registries: HolderLookup.Provider, exporter: RecipeOutput) {} open fun generateRecipes(registries: HolderLookup.Provider, exporter: RecipeOutput) {}
open fun generateItemTags(tags: ItemTagAdder) {} open fun generateItemTags(tags: ItemTagAdder) {}
open fun generateItemModels(models: ItemModelGenerators) {} // open fun generateItemModels(models: ItemModelGenerators) {}
init { init {
register(this) register(this)
@@ -50,30 +51,43 @@ abstract class ItemImplementation {
companion object { companion object {
private val _all = mutableListOf<ItemImplementation>() private val _all = mutableListOf<ItemImplementation>()
val all: List<ItemImplementation> get() = _all val all: List<ItemImplementation> get() = _all
fun register(impl: ItemImplementation) = _all.add(impl) fun register(impl: ItemImplementation) = _all.add(impl)
} }
} }
abstract class GenericGearSet: ItemImplementation() { abstract class GenericGearSet: ItemImplementation() {
abstract val materialName: String abstract val materialName: String
abstract val armorSet: ArmorSet abstract val armorSet: ArmorSet
open val materialKey: ResourceKey<EquipmentAsset> = materialName.resourceKey() open val materialKey: ResourceKey<EquipmentAsset>
get() = materialName.resourceKey()
open val materialDefinition: GearMaterialDef
get() = GearMaterialDef.NETHERITE
open val materialDefinition: GearMaterialDef = GearMaterialDef()
val armorMaterial: ArmorMaterial by lazy { val armorMaterial: ArmorMaterial by lazy {
materialDefinition.toArmorMaterial() materialDefinition.toArmorMaterial()
} }
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>>>()
internal fun registerDatagen(item: Item, recipes: List<RecipeSpec>, tags: List<TagKey<Item>>) { private val itemModels = mutableMapOf<Item, ModelSpec>()
internal fun registerDatagen(item: Item, recipes: List<RecipeSpec>, tags: List<TagKey<Item>>, model: ModelSpec) {
itemRecipes[item] = recipes itemRecipes[item] = recipes
itemTags[item] = tags itemTags[item] = tags
itemModels[item] = model
} }
val modelSpecs: Map<Item, ModelSpec> get() = itemModels
override fun generateRecipes(registries: HolderLookup.Provider, exporter: RecipeOutput) { override fun generateRecipes(registries: HolderLookup.Provider, exporter: RecipeOutput) {
val itemLookup: HolderGetter<Item> = registries.lookupOrThrow(Registries.ITEM) val itemLookup: HolderGetter<Item> = registries.lookupOrThrow(Registries.ITEM)
@@ -148,13 +162,15 @@ object ModItems {
} }
.build() .build()
private val eagerLoad = listOf(Witherite, Dragonite) private val eagerLoad = listOf<GenericGearSet>(
Witherite,
Dragonite,
)
fun onLoad() { fun onLoad() {
// ensure that implementations such as creative tab are loaded and initialised // ensure that implementations such as creative tab are loaded and initialised
eagerLoad eagerLoad
ItemImplementation.all.forEach { it.onLoad() } ItemImplementation.all.forEach { it.onLoad() }
Registry.register(BuiltInRegistries.CREATIVE_MODE_TAB, CUSTOM_CREATIVE_TAB_KEY, CUSTOM_CREATIVE_TAB); Registry.register(BuiltInRegistries.CREATIVE_MODE_TAB, CUSTOM_CREATIVE_TAB_KEY, CUSTOM_CREATIVE_TAB);
} }
} }
@@ -168,7 +184,31 @@ data class GearMaterialDef(
val knockbackResistance: Float = ArmorMaterials.NETHERITE.knockbackResistance, val knockbackResistance: Float = ArmorMaterials.NETHERITE.knockbackResistance,
val repairIngredient: TagKey<Item> = ArmorMaterials.NETHERITE.repairIngredient, val repairIngredient: TagKey<Item> = ArmorMaterials.NETHERITE.repairIngredient,
val assetId: ResourceKey<EquipmentAsset> = ArmorMaterials.NETHERITE.assetId, val assetId: ResourceKey<EquipmentAsset> = ArmorMaterials.NETHERITE.assetId,
) ) {
companion object {
val NETHERITE = GearMaterialDef(
durability = ArmorMaterials.NETHERITE.durability,
defence = ArmorMaterials.NETHERITE.defense,
enchantability = ArmorMaterials.NETHERITE.enchantmentValue,
equipSound = ArmorMaterials.NETHERITE.equipSound,
toughness = ArmorMaterials.NETHERITE.toughness,
knockbackResistance = ArmorMaterials.NETHERITE.knockbackResistance,
repairIngredient = ArmorMaterials.NETHERITE.repairIngredient,
assetId = ArmorMaterials.NETHERITE.assetId,
)
val DIAMOND = GearMaterialDef(
durability = ArmorMaterials.DIAMOND.durability,
defence = ArmorMaterials.DIAMOND.defense,
enchantability = ArmorMaterials.DIAMOND.enchantmentValue,
equipSound = ArmorMaterials.DIAMOND.equipSound,
toughness = ArmorMaterials.DIAMOND.toughness,
knockbackResistance = ArmorMaterials.DIAMOND.knockbackResistance,
repairIngredient = ArmorMaterials.DIAMOND.repairIngredient,
assetId = ArmorMaterials.DIAMOND.assetId,
)
}
}
fun GearMaterialDef.toArmorMaterial(): ArmorMaterial { fun GearMaterialDef.toArmorMaterial(): ArmorMaterial {
return ArmorMaterial( return ArmorMaterial(
@@ -194,6 +234,12 @@ sealed interface RecipeSpec {
data class Shaped(val pattern: List<String>, val key: Map<Char, Item>) : RecipeSpec data class Shaped(val pattern: List<String>, val key: Map<Char, Item>) : RecipeSpec
} }
sealed interface ModelSpec {
data object Generated : ModelSpec // plain flat 2D item icon
data object Handheld : ModelSpec // flat icon, held like a tool
data object None : ModelSpec // hand-written JSON already exists, skip auto-gen
}
class GearItemBuilder<T : Item>( class GearItemBuilder<T : Item>(
private val owner: GenericGearSet, private val owner: GenericGearSet,
val name: String, val name: String,
@@ -202,6 +248,11 @@ class GearItemBuilder<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
fun model(spec: ModelSpec) {
modelSpec = spec
}
fun properties(block: Item.Properties.() -> Item.Properties) { fun properties(block: Item.Properties.() -> Item.Properties) {
properties = properties.block() properties = properties.block()
@@ -221,7 +272,7 @@ class GearItemBuilder<T : Item>(
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) owner.registerDatagen(item, recipes, tags, modelSpec)
return item return item
} }
} }
+98 -46
View File
@@ -1,8 +1,11 @@
package dev.zxq5.items package dev.zxq5.items
import dev.zxq5.items.ModItems.register import dev.zxq5.items.ModItems.register
import dev.zxq5.util.mcItemTag
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.tags.ItemTags
import net.minecraft.tags.TagKey
import net.minecraft.world.InteractionHand import net.minecraft.world.InteractionHand
import net.minecraft.world.InteractionResult import net.minecraft.world.InteractionResult
import net.minecraft.world.effect.MobEffectInstance import net.minecraft.world.effect.MobEffectInstance
@@ -13,6 +16,7 @@ import net.minecraft.world.entity.player.Player
import net.minecraft.world.entity.projectile.hurtingprojectile.WitherSkull import net.minecraft.world.entity.projectile.hurtingprojectile.WitherSkull
import net.minecraft.world.item.Item import net.minecraft.world.item.Item
import net.minecraft.world.item.ItemStack import net.minecraft.world.item.ItemStack
import net.minecraft.world.item.Items
import net.minecraft.world.item.ToolMaterial import net.minecraft.world.item.ToolMaterial
import net.minecraft.world.item.component.BlocksAttacks import net.minecraft.world.item.component.BlocksAttacks
import net.minecraft.world.item.component.UseCooldown import net.minecraft.world.item.component.UseCooldown
@@ -23,6 +27,10 @@ import java.util.*
object Witherite: GenericGearSet() { object Witherite: GenericGearSet() {
override val materialName = "witherite"
override val materialDefinition
get() = super.materialDefinition.copy(assetId = materialKey)
val SHIELD = register("witherite_shield", ::Item, val SHIELD = register("witherite_shield", ::Item,
Item.Properties() Item.Properties()
.component(DataComponents.BLOCKS_ATTACKS, BlocksAttacks( .component(DataComponents.BLOCKS_ATTACKS, BlocksAttacks(
@@ -43,63 +51,107 @@ object Witherite: GenericGearSet() {
)) ))
) )
val SWORD = register("witherite_sword", ::WitheriteSword, // val SWORD = register("witherite_sword", ::WitheriteSword,
Item.Properties() // Item.Properties()
.enchantable(armorMaterial.enchantmentValue) // .enchantable(armorMaterial.enchantmentValue)
// .component(DataComponents.USE_COOLDOWN, UseCooldown(2f))
// .sword(ToolMaterial.NETHERITE, 3F, -2.4F)
// )
// val AXE = register("witherite_axe", ::WitheriteWeapon,
// Item.Properties()
// .enchantable(armorMaterial.enchantmentValue)
// .axe(ToolMaterial.NETHERITE, 5F, -3F))
val SWORD by gearItem("witherite_sword", ::WitheriteSword) {
properties {
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)
}
val AXE by gearItem("witherite_axe", ::WitheriteWeapon) {
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(
mcItemTag("axes")
) )
}
val AXE = register("witherite_axe", ::WitheriteWeapon, val HELMET by gearItem("witherite_helmet", ::Item) {
Item.Properties() properties {
.enchantable(armorMaterial.enchantmentValue) humanoidArmor(armorMaterial, ArmorType.HELMET)
.axe(ToolMaterial.NETHERITE, 5F, -3F)) }
smithingUpgrade(Items.NETHERITE_UPGRADE_SMITHING_TEMPLATE, Items.NETHERITE_HELMET, Items.WITHER_SKELETON_SKULL)
}
val CHESTPLATE by gearItem("witherite_chestplate", ::Item) {
properties {
humanoidArmor(armorMaterial, ArmorType.CHESTPLATE)
}
smithingUpgrade(Items.NETHERITE_UPGRADE_SMITHING_TEMPLATE, Items.NETHERITE_CHESTPLATE, Items.WITHER_SKELETON_SKULL)
}
val HELMET = register( val LEGGINGS by gearItem("witherite_leggings", ::Item) {
"witherite_helmet", properties {
::Item, humanoidArmor(armorMaterial, ArmorType.LEGGINGS)
Item.Properties().humanoidArmor(armorMaterial , ArmorType.HELMET) }
.enchantable(armorMaterial.enchantmentValue) smithingUpgrade(Items.NETHERITE_UPGRADE_SMITHING_TEMPLATE, Items.NETHERITE_LEGGINGS, Items.WITHER_SKELETON_SKULL)
.durability(ArmorType.HELMET.getDurability(armorMaterial.durability)) }
)
val CHESTPLATE = register( val BOOTS by gearItem("witherite_boots", ::Item) {
"witherite_chestplate", properties {
::Item, humanoidArmor(armorMaterial, ArmorType.BOOTS)
}
smithingUpgrade(Items.NETHERITE_UPGRADE_SMITHING_TEMPLATE, Items.NETHERITE_BOOTS, Items.WITHER_SKELETON_SKULL)
}
Item.Properties() //
.enchantable(armorMaterial.enchantmentValue) // val HELMET = register(
.humanoidArmor(armorMaterial , ArmorType.CHESTPLATE) // "witherite_helmet",
.durability(ArmorType.CHESTPLATE.getDurability(armorMaterial.durability)) // ::Item,
) // Item.Properties().humanoidArmor(armorMaterial , ArmorType.HELMET)
// .enchantable(armorMaterial.enchantmentValue)
// .durability(ArmorType.HELMET.getDurability(armorMaterial.durability))
// )
//
// val CHESTPLATE = register(
// "witherite_chestplate",
// ::Item,
//
// Item.Properties()
// .enchantable(armorMaterial.enchantmentValue)
// .humanoidArmor(armorMaterial , ArmorType.CHESTPLATE)
// .durability(ArmorType.CHESTPLATE.getDurability(armorMaterial.durability))
// )
//
// val LEGGINGS = register(
// "witherite_leggings",
// ::Item,
// Item.Properties()
// .enchantable(armorMaterial.enchantmentValue)
// .humanoidArmor(armorMaterial , ArmorType.LEGGINGS)
// .durability(ArmorType.LEGGINGS.getDurability(armorMaterial.durability))
// )
//
// val BOOTS = register(
// "witherite_boots",
// ::Item,
// Item.Properties()
// .enchantable(armorMaterial.enchantmentValue)
// .humanoidArmor(armorMaterial , ArmorType.BOOTS)
// .durability(ArmorType.BOOTS.getDurability(armorMaterial.durability))
// )
val LEGGINGS = register(
"witherite_leggings",
::Item,
Item.Properties()
.enchantable(armorMaterial.enchantmentValue)
.humanoidArmor(armorMaterial , ArmorType.LEGGINGS)
.durability(ArmorType.LEGGINGS.getDurability(armorMaterial.durability))
)
val BOOTS = register(
"witherite_boots",
::Item,
Item.Properties()
.enchantable(armorMaterial.enchantmentValue)
.humanoidArmor(armorMaterial , ArmorType.BOOTS)
.durability(ArmorType.BOOTS.getDurability(armorMaterial.durability))
)
override val materialName = "witherite"
override val materialDefinition = super.materialDefinition.copy(assetId = materialKey)
override val armorSet: ArmorSet = ArmorSet(HELMET, CHESTPLATE, LEGGINGS, BOOTS) override val armorSet: ArmorSet = ArmorSet(HELMET, CHESTPLATE, LEGGINGS, BOOTS)
override val items = listOf(SWORD, AXE, SHIELD, HELMET, CHESTPLATE, LEGGINGS, BOOTS) override val items = listOf(SWORD, AXE, SHIELD, HELMET, CHESTPLATE, LEGGINGS, BOOTS)
override fun onLoad() {}
override fun onLoad() {
TODO("Not yet implemented")
}
} }
open class WitheriteWeapon(properties: Properties): Item(properties) { open class WitheriteWeapon(properties: Properties): Item(properties) {
+8
View File
@@ -1,7 +1,10 @@
package dev.zxq5.util package dev.zxq5.util
import dev.zxq5.Fantasysmp import dev.zxq5.Fantasysmp
import net.minecraft.core.registries.Registries
import net.minecraft.resources.Identifier import net.minecraft.resources.Identifier
import net.minecraft.resources.ResourceKey import net.minecraft.resources.ResourceKey
import net.minecraft.tags.TagKey
import net.minecraft.world.item.Item
import net.minecraft.world.item.equipment.EquipmentAsset import net.minecraft.world.item.equipment.EquipmentAsset
import net.minecraft.world.item.equipment.EquipmentAssets import net.minecraft.world.item.equipment.EquipmentAssets
@@ -10,3 +13,8 @@ fun String.resourceKey(): ResourceKey<EquipmentAsset> = ResourceKey.create(
EquipmentAssets.ROOT_ID, EquipmentAssets.ROOT_ID,
Identifier.fromNamespaceAndPath(Fantasysmp.MOD_ID, this), Identifier.fromNamespaceAndPath(Fantasysmp.MOD_ID, this),
) )
fun mcItemTag(path: String): TagKey<Item> = TagKey.create(
Registries.ITEM,
Identifier.withDefaultNamespace(path)
)