aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-11-15 11:09:36 +0100
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-11-15 11:09:36 +0100
commitaa9fe2a83cf65fcd28026db8f0bc9ed1723d49d5 (patch)
tree2c96bd35b9ae1742492882ff9b5e4cdecb829802 /src/main/java
parent05acdf4a23666d576500d5fc32479c20cad2571a (diff)
downloadskyhanni-aa9fe2a83cf65fcd28026db8f0bc9ed1723d49d5.tar.gz
skyhanni-aa9fe2a83cf65fcd28026db8f0bc9ed1723d49d5.tar.bz2
skyhanni-aa9fe2a83cf65fcd28026db8f0bc9ed1723d49d5.zip
Using fungi_cutter_mode instead of reading item lore
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/farming/WrongFungiCutterWarning.kt25
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/SkyBlockItemModifierUtils.kt2
2 files changed, 14 insertions, 13 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/WrongFungiCutterWarning.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/WrongFungiCutterWarning.kt
index 03a48d820..e7bdce1db 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/WrongFungiCutterWarning.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/WrongFungiCutterWarning.kt
@@ -6,8 +6,9 @@ import at.hannibal2.skyhanni.events.CropClickEvent
import at.hannibal2.skyhanni.events.GardenToolChangeEvent
import at.hannibal2.skyhanni.events.LorenzChatEvent
import at.hannibal2.skyhanni.features.garden.CropType
-import at.hannibal2.skyhanni.utils.ItemUtils.getLore
+import at.hannibal2.skyhanni.utils.ItemUtils.name
import at.hannibal2.skyhanni.utils.LorenzUtils
+import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getFungiCutterMode
import at.hannibal2.skyhanni.utils.SoundUtils
import net.minecraft.item.ItemStack
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
@@ -55,28 +56,26 @@ class WrongFungiCutterWarning {
@SubscribeEvent
fun onGardenToolChange(event: GardenToolChangeEvent) {
if (event.crop == CropType.MUSHROOM) {
- readItem(event.toolItem!!)
+ readItem(event.toolItem ?: error("Tool item is null"))
} else {
mode = FungiMode.UNKNOWN
}
}
private fun readItem(item: ItemStack) {
- // TODO Update to use NBT data: fungi_cutter_mode: "BROWN"
- for (line in item.getLore()) {
- if (line == "§eMode: §cRed Mushrooms") {
- mode = FungiMode.RED
- }
-
- if (line == "§eMode: §6Brown Mushrooms") {
- mode = FungiMode.BROWN
- }
- }
+ val rawMode = item.getFungiCutterMode() ?: error("Tool without fungi cutter mode: '${item.name}'")
+ mode = FungiMode.getOrNull(rawMode)
}
enum class FungiMode {
RED,
BROWN,
- UNKNOWN
+ UNKNOWN,
+ ;
+
+ companion object {
+ fun getOrNull(mode: String) =
+ entries.firstOrNull { it.name == mode } ?: error("Unknown fungi mode: '$mode'")
+ }
}
}
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/SkyBlockItemModifierUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/SkyBlockItemModifierUtils.kt
index 7f6cc7623..8d600f70e 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/SkyBlockItemModifierUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/SkyBlockItemModifierUtils.kt
@@ -117,6 +117,8 @@ object SkyBlockItemModifierUtils {
fun ItemStack.getArmorDye() = getAttributeString("dye_item")?.asInternalName()
+ fun ItemStack.getFungiCutterMode() = getAttributeString("fungi_cutter_mode")
+
fun ItemStack.getRune(): NEUInternalName? {
val runesMap = getExtraAttributes()?.getCompoundTag("runes") ?: return null
val runesList = runesMap.keySet.associateWith { runesMap.getInteger(it) }.toList()