-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
94 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
src/main/kotlin/dev/sterner/common/components/VoidBoundPlayerItemAbilityComponent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters