Skip to content

Commit

Permalink
VAMPIRISM
Browse files Browse the repository at this point in the history
  • Loading branch information
mrsterner committed Sep 16, 2024
1 parent 5cdeac4 commit 5e640a3
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/main/kotlin/dev/sterner/api/item/ItemAbility.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
19 changes: 15 additions & 4 deletions src/main/kotlin/dev/sterner/registry/VoidBoundComponentRegistry.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 {
Expand All @@ -64,6 +70,11 @@ class VoidBoundComponentRegistry : WorldComponentInitializer, EntityComponentIni
VoidBoundPlayerComponent::class.java
)

val VOID_BOUND_PLAYER_ITEM_ABILITY_COMPONENT: ComponentKey<VoidBoundPlayerItemAbilityComponent> = ComponentRegistry.getOrCreate(
VoidBound.id("player_item_ability"),
VoidBoundPlayerItemAbilityComponent::class.java
)

val VOID_BOUND_REVELATION_COMPONENT: ComponentKey<VoidBoundRevelationComponent> = ComponentRegistry.getOrCreate(
VoidBound.id("revelation"),
VoidBoundRevelationComponent::class.java
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@
"voidbound:world",
"voidbound:entity",
"voidbound:player",
"voidbound:revelation"
"voidbound:revelation",
"voidbound:player_item_ability"
]
}
}

0 comments on commit 5e640a3

Please sign in to comment.