From 17a855a4bdfcca00b29f85981d8fb86968d9038c Mon Sep 17 00:00:00 2001 From: Linnea Gräf Date: Tue, 11 Mar 2025 12:44:59 +0100 Subject: feat: add SBItemData implementation --- src/main/kotlin/repo/item/SBBreakingPower.kt | 31 ++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/main/kotlin/repo/item/SBBreakingPower.kt (limited to 'src/main/kotlin/repo/item/SBBreakingPower.kt') diff --git a/src/main/kotlin/repo/item/SBBreakingPower.kt b/src/main/kotlin/repo/item/SBBreakingPower.kt new file mode 100644 index 0000000..4c88a48 --- /dev/null +++ b/src/main/kotlin/repo/item/SBBreakingPower.kt @@ -0,0 +1,31 @@ +package moe.nea.firmament.repo.item + +import com.google.auto.service.AutoService +import io.github.moulberry.repo.data.NEUItem +import net.minecraft.item.ItemStack +import moe.nea.firmament.util.mc.loreAccordingToNbt +import moe.nea.firmament.util.removeColorCodes +import moe.nea.firmament.util.unformattedString +import moe.nea.firmament.util.useMatch + +@AutoService(SBItemProperty::class) +object SBBreakingPower : SBItemProperty() { + private val BREAKING_POWER_REGEX = "Breaking Power (?[0-9]+)".toPattern() + + fun fromLore(string: String?): Int? { + return BREAKING_POWER_REGEX.useMatch(string) { + group("power").toInt() + } + } + + override fun fromNeuItem(neuItem: NEUItem, store: SBItemData): Int? { + return fromLore(neuItem.lore.firstOrNull()?.removeColorCodes()) + } + + override fun fromStack( + stack: ItemStack, + store: SBItemData + ): Int? { + return fromLore(stack.loreAccordingToNbt.firstOrNull()?.unformattedString) + } +} -- cgit