diff --git a/src/main/kotlin/dev/sterner/api/item/ItemAbility.kt b/src/main/kotlin/dev/sterner/api/item/ItemAbility.kt index f7be7e9..884a728 100644 --- a/src/main/kotlin/dev/sterner/api/item/ItemAbility.kt +++ b/src/main/kotlin/dev/sterner/api/item/ItemAbility.kt @@ -14,7 +14,7 @@ enum class ItemAbility : StringRepresentable { SCORCHING_HEAT,//Fully implemented EXCAVATOR,//Fully implemented EARTH_RUMMAGER, - VAMPIRISM,//TODO re-implement. Saps the target's lifeforce, healing half a heart for each spirit their soul has / half a heart for each armor point a player has, with a 10 tick cooldown for each half heart + VAMPIRISM, HARVEST, OPENER,//TODO re-implement. First hit on a mob deals increased damage and grants a stack of Wrath, lasting a minute, up to 10 stacks. Transforms into Finale when you reach 10 stacks, or sneak right click FINALE,//TODO implement. Consumes All stacks of Opening Strike, multiplying damage dealt by the amount of stacks total. diff --git a/src/main/kotlin/dev/sterner/common/components/VoidBoundPlayerItemAbilityComponent.kt b/src/main/kotlin/dev/sterner/common/components/VoidBoundPlayerItemAbilityComponent.kt new file mode 100644 index 0000000..2a301b9 --- /dev/null +++ b/src/main/kotlin/dev/sterner/common/components/VoidBoundPlayerItemAbilityComponent.kt @@ -0,0 +1,68 @@ +package dev.sterner.common.components + +import dev.onyxstudios.cca.api.v3.component.sync.AutoSyncedComponent +import dev.onyxstudios.cca.api.v3.component.tick.CommonTickingComponent +import dev.sterner.api.item.ItemAbility +import dev.sterner.api.util.VoidBoundItemUtils +import dev.sterner.api.util.VoidBoundPlayerUtils +import dev.sterner.api.util.VoidBoundUtils +import dev.sterner.registry.VoidBoundComponentRegistry +import net.minecraft.nbt.CompoundTag +import net.minecraft.sounds.SoundEvents +import net.minecraft.world.entity.LivingEntity +import net.minecraft.world.entity.player.Player + +class VoidBoundPlayerItemAbilityComponent(private val player: Player) : AutoSyncedComponent, CommonTickingComponent { + + private var vampirismCooldown: Int = 0 + + fun tryUseVampirism(target: LivingEntity){ + if (vampirismCooldown <= 0) { + val healing = performVampirism(target) + if (healing > 0) { + player.heal(healing.toFloat()) + player.playSound(SoundEvents.BUBBLE_COLUMN_UPWARDS_INSIDE) + vampirismCooldown = 10 * healing + sync() + } + } + } + + private fun performVampirism(target: LivingEntity): Int { + var healing = 0 + if (target is Player) { + healing += target.armorValue + } else { + val data = VoidBoundUtils.getSpiritData(target) + if (data.isPresent) { + val d = data.get() + d.forEach { + healing += it.count + } + } else { + healing += 2 + } + } + + return healing + } + + override fun readFromNbt(tag: CompoundTag) { + vampirismCooldown = tag.getInt("vampirm") + } + + override fun writeToNbt(tag: CompoundTag) { + tag.putInt("vampirm", vampirismCooldown) + } + + override fun tick() { + if (vampirismCooldown > 0 && VoidBoundItemUtils.getActiveAbility(player.mainHandItem) == ItemAbility.VAMPIRISM) { + vampirismCooldown-- + sync() + } + } + + private fun sync(){ + VoidBoundComponentRegistry.VOID_BOUND_PLAYER_ITEM_ABILITY_COMPONENT.sync(player) + } +} \ No newline at end of file diff --git a/src/main/kotlin/dev/sterner/common/item/equipment/ichor/IchoriumVorpal.kt b/src/main/kotlin/dev/sterner/common/item/equipment/ichor/IchoriumVorpal.kt index 8a37e71..c33461c 100644 --- a/src/main/kotlin/dev/sterner/common/item/equipment/ichor/IchoriumVorpal.kt +++ b/src/main/kotlin/dev/sterner/common/item/equipment/ichor/IchoriumVorpal.kt @@ -6,6 +6,7 @@ import dev.sterner.api.item.ItemAbility import dev.sterner.api.util.VoidBoundItemUtils import dev.sterner.common.item.equipment.GalesEdgeItem.Companion.ascend import dev.sterner.mixin.HoeItemTillablesAccessor +import dev.sterner.registry.VoidBoundComponentRegistry import io.github.fabricators_of_create.porting_lib.common.util.IPlantable import io.github.fabricators_of_create.porting_lib.event.common.BlockEvents.BreakEvent import net.minecraft.core.BlockPos @@ -47,6 +48,13 @@ class IchoriumVorpal( return 72000 } + override fun hurtEnemy(stack: ItemStack, target: LivingEntity, attacker: LivingEntity): Boolean { + if (attacker is Player && VoidBoundItemUtils.getActiveAbility(stack) == ItemAbility.VAMPIRISM) { + VoidBoundComponentRegistry.VOID_BOUND_PLAYER_ITEM_ABILITY_COMPONENT.get(attacker).tryUseVampirism(target) + } + return super.hurtEnemy(stack, target, attacker) + } + override fun canAttackBlock(state: BlockState?, level: Level?, pos: BlockPos?, player: Player): Boolean { return VoidBoundItemUtils.getActiveAbility(player.mainHandItem) == ItemAbility.HARVEST } diff --git a/src/main/kotlin/dev/sterner/registry/VoidBoundComponentRegistry.kt b/src/main/kotlin/dev/sterner/registry/VoidBoundComponentRegistry.kt index 6c9372f..991be5f 100644 --- a/src/main/kotlin/dev/sterner/registry/VoidBoundComponentRegistry.kt +++ b/src/main/kotlin/dev/sterner/registry/VoidBoundComponentRegistry.kt @@ -8,10 +8,7 @@ import dev.onyxstudios.cca.api.v3.entity.RespawnCopyStrategy import dev.onyxstudios.cca.api.v3.world.WorldComponentFactoryRegistry import dev.onyxstudios.cca.api.v3.world.WorldComponentInitializer import dev.sterner.VoidBound -import dev.sterner.common.components.VoidBoundEntityComponent -import dev.sterner.common.components.VoidBoundPlayerComponent -import dev.sterner.common.components.VoidBoundRevelationComponent -import dev.sterner.common.components.VoidBoundWorldComponent +import dev.sterner.common.components.* import net.minecraft.world.entity.LivingEntity import net.minecraft.world.entity.player.Player @@ -46,6 +43,15 @@ class VoidBoundComponentRegistry : WorldComponentInitializer, EntityComponentIni ) }, RespawnCopyStrategy.ALWAYS_COPY ) + + registry.registerForPlayers( + VOID_BOUND_PLAYER_ITEM_ABILITY_COMPONENT, + { entity: Player -> + VoidBoundPlayerItemAbilityComponent( + entity + ) + }, RespawnCopyStrategy.ALWAYS_COPY + ) } companion object { @@ -64,6 +70,11 @@ class VoidBoundComponentRegistry : WorldComponentInitializer, EntityComponentIni VoidBoundPlayerComponent::class.java ) + val VOID_BOUND_PLAYER_ITEM_ABILITY_COMPONENT: ComponentKey = ComponentRegistry.getOrCreate( + VoidBound.id("player_item_ability"), + VoidBoundPlayerItemAbilityComponent::class.java + ) + val VOID_BOUND_REVELATION_COMPONENT: ComponentKey = ComponentRegistry.getOrCreate( VoidBound.id("revelation"), VoidBoundRevelationComponent::class.java diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index ffdf2a4..9fa90d2 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -49,7 +49,8 @@ "voidbound:world", "voidbound:entity", "voidbound:player", - "voidbound:revelation" + "voidbound:revelation", + "voidbound:player_item_ability" ] } } \ No newline at end of file