aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/repo/item/SBBreakingPower.kt
blob: 4c88a4892adb1eb1d4b61893579eb21d1863a6b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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)
	}
}