From 7d090afad3c9fa3b1e1abb3308378d1acdcad369 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Sun, 19 Mar 2023 13:06:41 +0100 Subject: Created getSBMonthByName and addGardenCropToList utils methods --- .../at/hannibal2/skyhanni/features/garden/GardenAPI.kt | 14 ++++++++++++++ .../skyhanni/features/garden/GardenCropMilestoneDisplay.kt | 10 +--------- .../features/inventory/JacobFarmingContestsInventory.kt | 10 ++-------- src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt | 12 ++++++++++++ 4 files changed, 29 insertions(+), 17 deletions(-) (limited to 'src/main') diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt index 37d2e1f18..3281bf39c 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt @@ -9,6 +9,7 @@ import at.hannibal2.skyhanni.events.PacketEvent import at.hannibal2.skyhanni.events.ProfileJoinEvent import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.NEUItems import net.minecraft.client.Minecraft import net.minecraft.item.ItemStack import net.minecraft.network.play.client.C09PacketHeldItemChange @@ -122,5 +123,18 @@ class GardenAPI { } return itemName } + + private fun getItemStackForCrop(crop: String): ItemStack { + val internalName = NEUItems.getInternalName(if (crop == "Mushroom") "Red Mushroom" else crop) + return NEUItems.getItemStack(internalName) + } + + fun addGardenCropToList(crop: String, list: MutableList) { + try { + list.add(getItemStackForCrop(crop)) + } catch (e: NullPointerException) { + e.printStackTrace() + } + } } } \ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneDisplay.kt index 1913406e8..c4e8bf484 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneDisplay.kt @@ -5,7 +5,6 @@ import at.hannibal2.skyhanni.data.GardenCropMilestones import at.hannibal2.skyhanni.data.SendTitleHelper import at.hannibal2.skyhanni.events.* import at.hannibal2.skyhanni.utils.LorenzUtils -import at.hannibal2.skyhanni.utils.NEUItems import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems import at.hannibal2.skyhanni.utils.SoundUtils.playSound import at.hannibal2.skyhanni.utils.TimeUtils @@ -163,14 +162,7 @@ class GardenCropMilestoneDisplay { progressDisplay.add(Collections.singletonList("ยง6Crop Milestones")) val list = mutableListOf() - - try { - val internalName = NEUItems.getInternalName(if (it == "Mushroom") "Red Mushroom" else it) - val itemStack = NEUItems.getItemStack(internalName) - list.add(itemStack) - } catch (e: NullPointerException) { - e.printStackTrace() - } + GardenAPI.addGardenCropToList(it, list) list.add(it) progressDisplay.add(list) diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/JacobFarmingContestsInventory.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/JacobFarmingContestsInventory.kt index c4da66bcc..d2b0a1138 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/JacobFarmingContestsInventory.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/JacobFarmingContestsInventory.kt @@ -75,14 +75,8 @@ class JacobFarmingContestsInventory { val day = matcher.group(2).toInt() val year = matcher.group(3).toInt() - var monthNr = 0 - for (i in 1..12) { - val monthName = SkyBlockTime.monthName(i) - if (month == monthName) { - monthNr = i - } - } - val time = SkyBlockTime(year, monthNr, day, 0, 0, 0) + val monthNr = LorenzUtils.getSBMonthByName(month) + val time = SkyBlockTime(year, monthNr, day) val toMillis = time.toMillis() val dayFormat = formatDay.format(toMillis) val startTimeFormat = formatTime.format(toMillis) diff --git a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt index b85250841..4d7d423b3 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt @@ -5,6 +5,7 @@ import at.hannibal2.skyhanni.data.HyPixelData import at.hannibal2.skyhanni.data.IslandType import at.hannibal2.skyhanni.features.dungeon.DungeonData import at.hannibal2.skyhanni.utils.StringUtils.removeColor +import io.github.moulberry.notenoughupdates.util.SkyBlockTime import net.minecraft.client.Minecraft import net.minecraft.entity.EntityLivingBase import net.minecraft.entity.SharedMonsterAttributes @@ -151,4 +152,15 @@ object LorenzUtils { fun > Map.sortedDesc(): Map { return toList().sorted().reversed().toMap() } + + fun getSBMonthByName(month: String): Int { + var monthNr = 0 + for (i in 1..12) { + val monthName = SkyBlockTime.monthName(i) + if (month == monthName) { + monthNr = i + } + } + return monthNr + } } \ No newline at end of file -- cgit