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:
2026-07-11 22:21:17 +01:00
parent 5b57baafb1
commit fe04526040
23 changed files with 524 additions and 166 deletions
@@ -1,20 +1,29 @@
package dev.zxq5.items.sets
import dev.zxq5.items.core.ArmorSet
import dev.zxq5.items.core.GenericGearSet
import dev.zxq5.items.template.ArmorSet
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 net.minecraft.core.component.DataComponents
import net.minecraft.core.particles.ParticleTypes
import net.minecraft.core.particles.PowerParticleOption
import net.minecraft.server.level.ServerLevel
import net.minecraft.sounds.SoundEvents
import net.minecraft.sounds.SoundSource
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.entity.Entity
import net.minecraft.world.entity.player.Player
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.level.Level
import kotlin.getValue
object Dragonite: GenericGearSet() {
@@ -22,60 +31,55 @@ object Dragonite: GenericGearSet() {
override val materialDefinition
get() = super.materialDefinition.copy(assetId = materialKey)
val SWORD = register("dragonite_sword", ::DragoniteSword,
Item.Properties()
.enchantable(armorMaterial.enchantmentValue)
.component(DataComponents.USE_COOLDOWN, UseCooldown(2f))
.sword(ToolMaterial.NETHERITE, 3.0F, -2.4F)
)
val HELMET = register(
"dragonite_helmet",
::Item,
Item.Properties()
.enchantable(armorMaterial.enchantmentValue)
.humanoidArmor(armorMaterial , ArmorType.HELMET)
.durability(ArmorType.HELMET.getDurability(armorMaterial.durability))
)
val SCALE by registerItem("dragon_scale", ::Item)
val INGOT by registerItem("dragonite_ingot", ::Item) {
shapedRecipe("SBS", "CXC", "SBS", key=mapOf<Char, Item>(
'S' to Items.SHULKER_SHELL,
'X' to SCALE,
'B' to Items.DRAGON_BREATH,
'C' to Items.CHORUS_FRUIT
))
}
val CHESTPLATE = register(
"dragonite_chestplate",
::Item,
Item.Properties()
.enchantable(armorMaterial.enchantmentValue)
.humanoidArmor(armorMaterial , ArmorType.CHESTPLATE)
.component(DataComponents.GLIDER, Unit.INSTANCE)
.durability(ArmorType.CHESTPLATE.getDurability(armorMaterial.durability))
)
val SWORD by registerItem("dragonite_sword", ::DragoniteSword) {
properties {
enchantable(armorMaterial.enchantmentValue)
.component(DataComponents.USE_COOLDOWN, UseCooldown(2f))
.sword(ToolMaterial.NETHERITE, 3F, -2.4F)
}
smithingUpgrade(Items.END_CRYSTAL, Items.NETHERITE_SWORD, INGOT)
}
val LEGGINGS = register(
"dragonite_leggings",
::Item,
Item.Properties()
.enchantable(armorMaterial.enchantmentValue)
.humanoidArmor(armorMaterial , ArmorType.LEGGINGS)
.durability(ArmorType.LEGGINGS.getDurability(armorMaterial.durability))
)
val HELMET by registerItem("dragonite_helmet", ::Item) {
properties {
humanoidArmor(armorMaterial, ArmorType.HELMET)
}
smithingUpgrade(Items.DRAGON_HEAD, Items.NETHERITE_HELMET, INGOT)
}
val BOOTS = register(
"dragonite_boots",
::Item,
Item.Properties()
.enchantable(armorMaterial.enchantmentValue)
.humanoidArmor(armorMaterial , ArmorType.BOOTS)
.durability(ArmorType.BOOTS.getDurability(armorMaterial.durability))
)
val CHESTPLATE by registerItem("dragonite_chestplate", ::Item) {
properties {
humanoidArmor(armorMaterial, ArmorType.CHESTPLATE)
.component(DataComponents.GLIDER, Unit.INSTANCE)
.component(DataComponents.UNBREAKABLE, Unit.INSTANCE)
}
smithingUpgrade(Items.ELYTRA, Items.NETHERITE_CHESTPLATE, INGOT)
}
val INGOT = register(
"dragonite_ingot",
::Item,
Item.Properties()
)
val LEGGINGS by registerItem("dragonite_leggings", ::Item) {
properties {
humanoidArmor(armorMaterial, ArmorType.LEGGINGS)
}
smithingUpgrade(Items.CRYING_OBSIDIAN, Items.NETHERITE_LEGGINGS, INGOT)
}
val SCALE = register(
"dragon_scale",
::Item,
Item.Properties()
)
val BOOTS by registerItem("dragonite_boots", ::Item) {
properties {
humanoidArmor(armorMaterial, ArmorType.BOOTS)
}
smithingUpgrade(Items.CRYING_OBSIDIAN, Items.NETHERITE_BOOTS, INGOT)
}
override val armorSet: ArmorSet = ArmorSet(HELMET, CHESTPLATE, LEGGINGS, BOOTS)
override val items = listOf(SWORD, HELMET, CHESTPLATE, LEGGINGS, BOOTS, SCALE, INGOT)
@@ -95,13 +99,41 @@ class DragoniteSword(properties: Properties) : Item(properties) {
level.playSound(null, user.x, user.y, user.z,
SoundEvents.ENDER_DRAGON_FLAP, SoundSource.PLAYERS, 1.0f, 1.0f)
// TODO("fix this broken ahh code. WHY TF DOES FABRIC HAVE NO DOCUMENTATION FOR BASICALLY ANYTHING.")
// (level as? ServerLevel)?.sendParticles(
// ParticleTypes.DRAGON_BREATH as ParticleOptions,
// user.x, user.y, user.z,
// 100, 0.5, 0.5, 0.5, 0.5
// )
(level as? ServerLevel)?.sendParticles(
PowerParticleOption.create(ParticleTypes.DRAGON_BREATH, 1.0f),
user.x, user.y, user.z,
100, 0.5, 0.5, 0.5, 0.5
)
return InteractionResult.SUCCESS
}
override fun getAttackDamageBonus(victim: Entity, damage: Float, damageSource: DamageSource): Float {
val superBonus = super.getAttackDamageBonus(victim, damage, damageSource) // 0f from vanilla, but respect it anyway
val attacker = damageSource.entity as? Player ?: return superBonus
if (Dragonite.fullSetEquippedBy(attacker)) return superBonus
if (attacker.level().isClientSide) return superBonus
if (!attacker.isFallFlying) return superBonus
val speed = attacker.deltaMovement.length()
if (speed < MIN_DIVE_SPEED) return superBonus
val clampedSpeed = speed.coerceAtMost(MAX_DIVE_SPEED)
val t = (clampedSpeed - MIN_DIVE_SPEED) / (MAX_DIVE_SPEED - MIN_DIVE_SPEED)
val multiplier = 1.0f + (t * MAX_BONUS_MULTIPLIER).toFloat()
// damage is the current total (base + crit + whatever ran before this hook).
// We want final = damage * multiplier, and this method adds its return value on top of damage,
// so the bonus we need to return is exactly (damage * multiplier) - damage.
val extraBonus = damage * (multiplier - 1f)
println("base: $damage bonus: ${superBonus + extraBonus}")
return superBonus + extraBonus
}
companion object {
const val MIN_DIVE_SPEED = 0.3
const val MAX_DIVE_SPEED = 1.1
const val MAX_BONUS_MULTIPLIER = 2.0f
}
}