Files
fantasysmp_fabric/src/main/kotlin/dev/zxq5/items/sets/Witherite.kt
T

135 lines
5.6 KiB
Kotlin

package dev.zxq5.items.sets
import dev.zxq5.items.template.ArmorSet
import dev.zxq5.items.template.GenericGearSet
import dev.zxq5.items.template.registerItem
import dev.zxq5.items.template.provideDelegate
import net.minecraft.core.component.DataComponents
import net.minecraft.sounds.SoundEvents
import net.minecraft.world.InteractionHand
import net.minecraft.world.InteractionResult
import net.minecraft.world.effect.MobEffectInstance
import net.minecraft.world.effect.MobEffects
import net.minecraft.world.entity.EntityType
import net.minecraft.world.entity.LivingEntity
import net.minecraft.world.entity.player.Player
import net.minecraft.world.entity.projectile.hurtingprojectile.WitherSkull
import net.minecraft.world.item.Item
import net.minecraft.world.item.ItemStack
import net.minecraft.world.item.Items
import net.minecraft.world.item.ToolMaterial
import net.minecraft.world.item.component.BlocksAttacks
import net.minecraft.world.item.component.UseCooldown
import net.minecraft.world.item.equipment.ArmorType
import net.minecraft.world.level.Level
import java.util.*
object Witherite: GenericGearSet() {
override val materialName = "witherite"
override val materialDefinition
get() = super.materialDefinition.copy(assetId = materialKey)
val SHIELD by registerItem("witherite_shield", ::Item) {
properties {
component(DataComponents.BLOCKS_ATTACKS, BlocksAttacks(
0.25f, // 5 tick warmup
1.0f, // standard disable cooldown
listOf(
BlocksAttacks.DamageReduction(
90.0f, // horizontalBlockingAngle — 90° arc each side (180° total, same as vanilla)
Optional.empty(), // type — empty = blocks all damage types
0.0f, // base — flat damage reduction
1.0f // factor — multiplier (1.0 = block 100% of damage)
)
), // full block — check if this constant exists, else build the list manually
BlocksAttacks.ItemDamageFunction.DEFAULT, // check for this constant too
Optional.empty(), // no bypass
Optional.empty(), // default block sound
Optional.empty() // default disable sound
))
}
smithingUpgrade(Items.NETHERITE_UPGRADE_SMITHING_TEMPLATE, Items.NETHERITE_SWORD, Items.WITHER_SKELETON_SKULL)
}
val SWORD by registerItem("witherite_sword", ::WitheriteSword) {
properties {
enchantable(armorMaterial.enchantmentValue)
.component(DataComponents.USE_COOLDOWN, UseCooldown(2f))
.sword(ToolMaterial.NETHERITE, 3F, -2.4F)
}
smithingUpgrade(Items.NETHERITE_UPGRADE_SMITHING_TEMPLATE, Items.NETHERITE_SWORD, Items.WITHER_SKELETON_SKULL)
}
val AXE by registerItem("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)
}
val HELMET by registerItem("witherite_helmet", ::Item) {
properties {
humanoidArmor(armorMaterial, ArmorType.HELMET)
}
smithingUpgrade(Items.NETHERITE_UPGRADE_SMITHING_TEMPLATE, Items.NETHERITE_HELMET, Items.WITHER_SKELETON_SKULL)
}
val CHESTPLATE by registerItem("witherite_chestplate", ::Item) {
properties {
humanoidArmor(armorMaterial, ArmorType.CHESTPLATE)
}
smithingUpgrade(Items.NETHERITE_UPGRADE_SMITHING_TEMPLATE, Items.NETHERITE_CHESTPLATE, Items.WITHER_SKELETON_SKULL)
}
val LEGGINGS by registerItem("witherite_leggings", ::Item) {
properties {
humanoidArmor(armorMaterial, ArmorType.LEGGINGS)
}
smithingUpgrade(Items.NETHERITE_UPGRADE_SMITHING_TEMPLATE, Items.NETHERITE_LEGGINGS, Items.WITHER_SKELETON_SKULL)
}
val BOOTS by registerItem("witherite_boots", ::Item) {
properties {
humanoidArmor(armorMaterial, ArmorType.BOOTS)
}
smithingUpgrade(Items.NETHERITE_UPGRADE_SMITHING_TEMPLATE, Items.NETHERITE_BOOTS, Items.WITHER_SKELETON_SKULL)
}
override val armorSet: ArmorSet = ArmorSet(HELMET, CHESTPLATE, LEGGINGS, BOOTS)
override val items = listOf(SWORD, AXE, SHIELD, HELMET, CHESTPLATE, LEGGINGS, BOOTS)
override fun onLoad() {
// empty function - this must be called to initialise the above properties ^
}
}
open class WitheriteWeapon(properties: Properties): Item(properties) {
override fun hurtEnemy(itemStack: ItemStack, mob: LivingEntity, attacker: LivingEntity) {
super.hurtEnemy(itemStack, mob, attacker)
if (attacker.level().isClientSide) return
val amplifier = if (attacker is Player) { 0 } else { 2 }
mob.addEffect(MobEffectInstance(MobEffects.WITHER, 60, amplifier), attacker)
}
}
class WitheriteSword(properties: Properties) : WitheriteWeapon(properties) {
override fun use(level: Level, user: Player, hand: InteractionHand): InteractionResult {
if (level.isClientSide
|| !user.isCrouching
|| !Witherite.fullSetEquippedBy(user)
) return InteractionResult.PASS;
val skull = WitherSkull(EntityType.WITHER_SKULL, level)
skull.setPos(user.eyePosition)
skull.deltaMovement = user.lookAngle
level.addFreshEntity(skull)
skull.playSound(SoundEvents.WITHER_SHOOT)
return InteractionResult.SUCCESS;
}
}