diff options
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/garden/farming/WrongFungiCutterWarning.kt | 25 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/utils/SkyBlockItemModifierUtils.kt | 2 |
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() |