Skip to content

Commit 8dbcb8c

Browse files
committed
seal base impl
1 parent eeaba73 commit 8dbcb8c

File tree

4 files changed

+142
-1
lines changed

4 files changed

+142
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package dev.sterner.api.sealer
2+
3+
import com.sammy.malum.core.systems.spirit.MalumSpiritType
4+
import com.sammy.malum.registry.common.SpiritTypeRegistry
5+
import net.minecraft.nbt.CompoundTag
6+
import net.minecraft.nbt.ListTag
7+
import net.minecraft.world.entity.player.Player
8+
9+
data class SealData(val spiritType: MalumSpiritType) {
10+
11+
fun tickEffect(player: Player) {
12+
spiritTickMap[spiritType]?.invoke(player)
13+
}
14+
15+
companion object {
16+
fun readFromNbt(tag: CompoundTag): MutableSet<SealData> {
17+
val dataSet = mutableSetOf<SealData>()
18+
val list = tag.getList("SealDataSet", 10)
19+
for (i in 0 until list.size) {
20+
val spiritTag = list.getCompound(i)
21+
val spiritType = SpiritTypeRegistry.SPIRITS[spiritTag.getString("Type")]!!
22+
dataSet.add(SealData(spiritType))
23+
}
24+
return dataSet
25+
}
26+
27+
fun writeToNbt(dataSet: MutableSet<SealData>, tag: CompoundTag) {
28+
val list = ListTag()
29+
dataSet.forEach { data ->
30+
val spiritTag = CompoundTag()
31+
spiritTag.putString("Type", data.spiritType.identifier)
32+
list.add(spiritTag)
33+
}
34+
tag.put("SealDataSet", list)
35+
}
36+
37+
private fun tickAerial(player: Player) {
38+
39+
}
40+
41+
private fun tickAqueous(player: Player) {
42+
43+
}
44+
45+
private fun tickInfernal(player: Player) {
46+
47+
}
48+
49+
private fun tickEarthen(player: Player) {
50+
51+
}
52+
53+
private fun tickArcane(player: Player) {
54+
55+
}
56+
57+
private fun tickWicked(player: Player) {
58+
59+
}
60+
61+
private fun tickEldritch(player: Player) {
62+
63+
}
64+
65+
private fun tickSacred(player: Player) {
66+
67+
}
68+
69+
private val spiritTickMap = mapOf<MalumSpiritType, (Player) -> Unit>(
70+
SpiritTypeRegistry.AERIAL_SPIRIT to ::tickAerial,
71+
SpiritTypeRegistry.AQUEOUS_SPIRIT to ::tickAqueous,
72+
SpiritTypeRegistry.INFERNAL_SPIRIT to ::tickInfernal,
73+
SpiritTypeRegistry.EARTHEN_SPIRIT to ::tickEarthen,
74+
SpiritTypeRegistry.ARCANE_SPIRIT to ::tickArcane,
75+
SpiritTypeRegistry.WICKED_SPIRIT to ::tickWicked,
76+
SpiritTypeRegistry.ELDRITCH_SPIRIT to ::tickEldritch,
77+
SpiritTypeRegistry.SACRED_SPIRIT to ::tickSacred
78+
)
79+
}
80+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package dev.sterner.common.components
2+
3+
import com.sammy.malum.core.systems.spirit.MalumSpiritType
4+
import dev.onyxstudios.cca.api.v3.component.sync.AutoSyncedComponent
5+
import dev.onyxstudios.cca.api.v3.component.tick.CommonTickingComponent
6+
import dev.sterner.api.sealer.SealData
7+
import dev.sterner.registry.VoidBoundComponentRegistry
8+
import net.minecraft.nbt.CompoundTag
9+
import net.minecraft.world.entity.player.Player
10+
11+
class VoidBoundPlayerSealerComponent(val player: Player): AutoSyncedComponent, CommonTickingComponent {
12+
13+
var sealedSpirits = mutableSetOf<SealData>()
14+
15+
fun trySealSpirit(sealData: SealData) : Boolean {
16+
val added = sealedSpirits.add(sealData)
17+
if (added) {
18+
sync()
19+
return true
20+
}
21+
return false
22+
}
23+
24+
fun hasSealedSpirit(spiritType: MalumSpiritType) : Boolean {
25+
return sealedSpirits.contains(SealData(spiritType))
26+
}
27+
28+
override fun tick() {
29+
for (sealedSpirit in sealedSpirits) {
30+
sealedSpirit.tickEffect(player)
31+
}
32+
}
33+
34+
fun sync(){
35+
VoidBoundComponentRegistry.VOID_BOUND_PLAYER_SEALER_COMPONENT.sync(player)
36+
}
37+
38+
override fun readFromNbt(tag: CompoundTag) {
39+
sealedSpirits.clear()
40+
sealedSpirits = SealData.readFromNbt(tag)
41+
}
42+
43+
override fun writeToNbt(tag: CompoundTag) {
44+
SealData.writeToNbt(sealedSpirits, tag)
45+
}
46+
}

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

+14
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,15 @@ class VoidBoundComponentRegistry : WorldComponentInitializer, EntityComponentIni
5252
)
5353
}, RespawnCopyStrategy.ALWAYS_COPY
5454
)
55+
56+
registry.registerForPlayers(
57+
VOID_BOUND_PLAYER_SEALER_COMPONENT,
58+
{ entity: Player ->
59+
VoidBoundPlayerSealerComponent(
60+
entity
61+
)
62+
}, RespawnCopyStrategy.ALWAYS_COPY
63+
)
5564
}
5665

5766
companion object {
@@ -75,6 +84,11 @@ class VoidBoundComponentRegistry : WorldComponentInitializer, EntityComponentIni
7584
VoidBoundPlayerItemAbilityComponent::class.java
7685
)
7786

87+
val VOID_BOUND_PLAYER_SEALER_COMPONENT: ComponentKey<VoidBoundPlayerSealerComponent> = ComponentRegistry.getOrCreate(
88+
VoidBound.id("player_sealer"),
89+
VoidBoundPlayerSealerComponent::class.java
90+
)
91+
7892
val VOID_BOUND_REVELATION_COMPONENT: ComponentKey<VoidBoundRevelationComponent> = ComponentRegistry.getOrCreate(
7993
VoidBound.id("revelation"),
8094
VoidBoundRevelationComponent::class.java

src/main/resources/fabric.mod.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@
5050
"voidbound:entity",
5151
"voidbound:player",
5252
"voidbound:revelation",
53-
"voidbound:player_item_ability"
53+
"voidbound:player_item_ability",
54+
"voidbound:player_sealer"
5455
]
5556
}
5657
}

0 commit comments

Comments
 (0)