aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/repo/item/SBBreakingPower.kt
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/kotlin/repo/item/SBBreakingPower.kt')
-rw-r--r--src/main/kotlin/repo/item/SBBreakingPower.kt31
1 files changed, 31 insertions, 0 deletions
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<Int>() {
+ private val BREAKING_POWER_REGEX = "Breaking Power (?<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)
+ }
+}