Skip to content

Commit 5e640a3

Browse files
committed
VAMPIRISM
1 parent 5cdeac4 commit 5e640a3

File tree

5 files changed

+94
-6
lines changed

5 files changed

+94
-6
lines changed

src/main/kotlin/dev/sterner/api/item/ItemAbility.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ enum class ItemAbility : StringRepresentable {
1414
SCORCHING_HEAT,//Fully implemented
1515
EXCAVATOR,//Fully implemented
1616
EARTH_RUMMAGER,
17-
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
17+
VAMPIRISM,
1818
HARVEST,
1919
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
2020
FINALE,//TODO implement. Consumes All stacks of Opening Strike, multiplying damage dealt by the amount of stacks total.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package dev.sterner.common.components
2+
3+
import dev.onyxstudios.cca.api.v3.component.sync.AutoSyncedComponent
4+
import dev.onyxstudios.cca.api.v3.component.tick.CommonTickingComponent
5+
import dev.sterner.api.item.ItemAbility
6+
import dev.sterner.api.util.VoidBoundItemUtils
7+
import dev.sterner.api.util.VoidBoundPlayerUtils
8+
import dev.sterner.api.util.VoidBoundUtils
9+
import dev.sterner.registry.VoidBoundComponentRegistry
10+
import net.minecraft.nbt.CompoundTag
11+
import net.minecraft.sounds.SoundEvents
12+
import net.minecraft.world.entity.LivingEntity
13+
import net.minecraft.world.entity.player.Player
14+
15+
class VoidBoundPlayerItemAbilityComponent(private val player: Player) : AutoSyncedComponent, CommonTickingComponent {
16+
17+
private var vampirismCooldown: Int = 0
18+
19+
fun tryUseVampirism(target: LivingEntity){
20+
if (vampirismCooldown <= 0) {
21+
val healing = performVampirism(target)
22+
if (healing > 0) {
23+
player.heal(healing.toFloat())
24+
player.playSound(SoundEvents.BUBBLE_COLUMN_UPWARDS_INSIDE)
25+
vampirismCooldown = 10 * healing
26+
sync()
27+
}
28+
}
29+
}
30+
31+
private fun performVampirism(target: LivingEntity): Int {
32+
var healing = 0
33+
if (target is Player) {
34+
healing += target.armorValue
35+
} else {
36+
val data = VoidBoundUtils.getSpiritData(target)
37+
if (data.isPresent) {
38+
val d = data.get()
39+
d.forEach {
40+
healing += it.count
41+
}
42+
} else {
43+
healing += 2
44+
}
45+
}
46+
47+
return healing
48+
}
49+
50+
override fun readFromNbt(tag: CompoundTag) {
51+
vampirismCooldown = tag.getInt("vampirm")
52+
}
53+
54+
override fun writeToNbt(tag: CompoundTag) {
55+
tag.putInt("vampirm", vampirismCooldown)
56+
}
57+
58+
override fun tick() {
59+
if (vampirismCooldown > 0 && VoidBoundItemUtils.getActiveAbility(player.mainHandItem) == ItemAbility.VAMPIRISM) {
60+
vampirismCooldown--
61+
sync()
62+
}
63+
}
64+
65+
private fun sync(){
66+
VoidBoundComponentRegistry.VOID_BOUND_PLAYER_ITEM_ABILITY_COMPONENT.sync(player)
67+
}
68+
}

src/main/kotlin/dev/sterner/common/item/equipment/ichor/IchoriumVorpal.kt

+8
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import dev.sterner.api.item.ItemAbility
66
import dev.sterner.api.util.VoidBoundItemUtils
77
import dev.sterner.common.item.equipment.GalesEdgeItem.Companion.ascend
88
import dev.sterner.mixin.HoeItemTillablesAccessor
9+
import dev.sterner.registry.VoidBoundComponentRegistry
910
import io.github.fabricators_of_create.porting_lib.common.util.IPlantable
1011
import io.github.fabricators_of_create.porting_lib.event.common.BlockEvents.BreakEvent
1112
import net.minecraft.core.BlockPos
@@ -47,6 +48,13 @@ class IchoriumVorpal(
4748
return 72000
4849
}
4950

51+
override fun hurtEnemy(stack: ItemStack, target: LivingEntity, attacker: LivingEntity): Boolean {
52+
if (attacker is Player && VoidBoundItemUtils.getActiveAbility(stack) == ItemAbility.VAMPIRISM) {
53+
VoidBoundComponentRegistry.VOID_BOUND_PLAYER_ITEM_ABILITY_COMPONENT.get(attacker).tryUseVampirism(target)
54+
}
55+
return super.hurtEnemy(stack, target, attacker)
56+
}
57+
5058
override fun canAttackBlock(state: BlockState?, level: Level?, pos: BlockPos?, player: Player): Boolean {
5159
return VoidBoundItemUtils.getActiveAbility(player.mainHandItem) == ItemAbility.HARVEST
5260
}

src/main/kotlin/dev/sterner/registry/VoidBoundComponentRegistry.kt

+15-4
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@ import dev.onyxstudios.cca.api.v3.entity.RespawnCopyStrategy
88
import dev.onyxstudios.cca.api.v3.world.WorldComponentFactoryRegistry
99
import dev.onyxstudios.cca.api.v3.world.WorldComponentInitializer
1010
import dev.sterner.VoidBound
11-
import dev.sterner.common.components.VoidBoundEntityComponent
12-
import dev.sterner.common.components.VoidBoundPlayerComponent
13-
import dev.sterner.common.components.VoidBoundRevelationComponent
14-
import dev.sterner.common.components.VoidBoundWorldComponent
11+
import dev.sterner.common.components.*
1512
import net.minecraft.world.entity.LivingEntity
1613
import net.minecraft.world.entity.player.Player
1714

@@ -46,6 +43,15 @@ class VoidBoundComponentRegistry : WorldComponentInitializer, EntityComponentIni
4643
)
4744
}, RespawnCopyStrategy.ALWAYS_COPY
4845
)
46+
47+
registry.registerForPlayers(
48+
VOID_BOUND_PLAYER_ITEM_ABILITY_COMPONENT,
49+
{ entity: Player ->
50+
VoidBoundPlayerItemAbilityComponent(
51+
entity
52+
)
53+
}, RespawnCopyStrategy.ALWAYS_COPY
54+
)
4955
}
5056

5157
companion object {
@@ -64,6 +70,11 @@ class VoidBoundComponentRegistry : WorldComponentInitializer, EntityComponentIni
6470
VoidBoundPlayerComponent::class.java
6571
)
6672

73+
val VOID_BOUND_PLAYER_ITEM_ABILITY_COMPONENT: ComponentKey<VoidBoundPlayerItemAbilityComponent> = ComponentRegistry.getOrCreate(
74+
VoidBound.id("player_item_ability"),
75+
VoidBoundPlayerItemAbilityComponent::class.java
76+
)
77+
6778
val VOID_BOUND_REVELATION_COMPONENT: ComponentKey<VoidBoundRevelationComponent> = ComponentRegistry.getOrCreate(
6879
VoidBound.id("revelation"),
6980
VoidBoundRevelationComponent::class.java

src/main/resources/fabric.mod.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@
4949
"voidbound:world",
5050
"voidbound:entity",
5151
"voidbound:player",
52-
"voidbound:revelation"
52+
"voidbound:revelation",
53+
"voidbound:player_item_ability"
5354
]
5455
}
5556
}

0 commit comments

Comments
 (0)