item builder DSL framework completed and seems to work. custom tag and model generation don't work yet. don't uncomment the tag generation code as it causes a stack overflow crash ⚠️
This commit is contained in:
@@ -1,24 +1,16 @@
|
||||
package dev.zxq5.items.core
|
||||
package dev.zxq5.items.template
|
||||
|
||||
import dev.zxq5.util.resourceKey
|
||||
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.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.core.Holder
|
||||
import net.minecraft.resources.ResourceKey
|
||||
import net.minecraft.sounds.SoundEvent
|
||||
import net.minecraft.tags.TagKey
|
||||
import net.minecraft.world.entity.EquipmentSlot
|
||||
import net.minecraft.world.entity.player.Player
|
||||
import net.minecraft.world.item.Item
|
||||
import net.minecraft.world.item.crafting.Ingredient
|
||||
import net.minecraft.world.item.equipment.ArmorMaterial
|
||||
import net.minecraft.world.item.equipment.ArmorMaterials
|
||||
import net.minecraft.world.item.equipment.ArmorType
|
||||
import net.minecraft.world.item.equipment.EquipmentAsset
|
||||
|
||||
abstract class GenericGearSet: GenericItemSet() {
|
||||
@@ -36,58 +28,64 @@ abstract class GenericGearSet: GenericItemSet() {
|
||||
materialDefinition.toArmorMaterial()
|
||||
}
|
||||
|
||||
private val itemRecipes = mutableMapOf<Item, List<RecipeSpec>>()
|
||||
|
||||
private val itemTags = mutableMapOf<Item, 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
|
||||
itemTags[item] = tags
|
||||
itemModels[item] = model
|
||||
}
|
||||
|
||||
|
||||
val modelSpecs: Map<Item, ModelSpec> get() = itemModels
|
||||
|
||||
override fun generateRecipes(registries: HolderLookup.Provider, exporter: RecipeOutput) {
|
||||
val itemLookup: HolderGetter<Item> = registries.lookupOrThrow(Registries.ITEM)
|
||||
|
||||
itemRecipes.forEach { (item, specs) ->
|
||||
specs.forEach { spec ->
|
||||
when (spec) {
|
||||
is RecipeSpec.Smithing -> SmithingTransformRecipeBuilder.smithing(
|
||||
Ingredient.of(spec.template), Ingredient.of(spec.base), Ingredient.of(spec.addition),
|
||||
RecipeCategory.COMBAT, item
|
||||
).unlocks("has_addition", InventoryChangeTrigger.TriggerInstance.hasItems(spec.addition))
|
||||
.save(exporter, BuiltInRegistries.ITEM.getKey(item).path)
|
||||
|
||||
is RecipeSpec.Shaped -> {
|
||||
val builder = ShapedRecipeBuilder.shaped(itemLookup, RecipeCategory.MISC, item)
|
||||
spec.pattern.forEach { builder.pattern(it) }
|
||||
spec.key.forEach { (char, ingredientItem) ->
|
||||
builder.define(char, ingredientItem)
|
||||
|
||||
}
|
||||
builder
|
||||
.unlockedBy("has_ingredient", RecipeProvider.inventoryTrigger(
|
||||
ItemPredicate.Builder().of(itemLookup, *spec.key.values.toTypedArray() )
|
||||
))
|
||||
.save(exporter)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun generateItemTags(tags: ItemTagAdder) {
|
||||
itemTags.forEach { (item, tagList) -> tagList.forEach { tags.add(it, item) } }
|
||||
}
|
||||
|
||||
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 &&
|
||||
p.getItemBySlot(EquipmentSlot.FEET).item == armorSet.boots
|
||||
}
|
||||
}
|
||||
|
||||
data class ArmorSet(
|
||||
val helmet: Item,
|
||||
val chestplate: Item,
|
||||
val leggings: Item,
|
||||
val boots: Item,
|
||||
)
|
||||
|
||||
data class GearMaterialDef(
|
||||
val durability: Int = ArmorMaterials.NETHERITE.durability,
|
||||
val defence: Map<ArmorType, Int> = ArmorMaterials.NETHERITE.defense,
|
||||
val enchantability: Int = ArmorMaterials.NETHERITE.enchantmentValue,
|
||||
val equipSound: Holder<SoundEvent> = ArmorMaterials.NETHERITE.equipSound,
|
||||
val toughness: Float = ArmorMaterials.NETHERITE.toughness,
|
||||
val knockbackResistance: Float = ArmorMaterials.NETHERITE.knockbackResistance,
|
||||
val repairIngredient: TagKey<Item> = ArmorMaterials.NETHERITE.repairIngredient,
|
||||
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 {
|
||||
return ArmorMaterial(
|
||||
durability,
|
||||
defence,
|
||||
enchantability,
|
||||
equipSound,
|
||||
toughness,
|
||||
knockbackResistance,
|
||||
repairIngredient,
|
||||
assetId,
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user