aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/storage/ProfileSpecificStorage.java3
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/CropAccessoryData.kt121
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/fortuneguide/FFStats.kt2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/fortuneguide/FortuneUpgrades.kt2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/inventory/bazaar/BazaarBestSellMethod.kt7
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/minion/MinionFeatures.kt6
7 files changed, 37 insertions, 106 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
index 8dc4d0c2e..36196d912 100644
--- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
+++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
@@ -535,7 +535,7 @@ class SkyHanniMod {
loadModule(GuiEditManager())
loadModule(GetFromSackAPI)
loadModule(UpdateManager)
- loadModule(CropAccessoryData())
+ loadModule(CropAccessoryData)
loadModule(GardenComposterUpgradesData())
loadModule(ActionBarStatsData)
loadModule(GardenCropMilestoneInventory())
diff --git a/src/main/java/at/hannibal2/skyhanni/config/storage/ProfileSpecificStorage.java b/src/main/java/at/hannibal2/skyhanni/config/storage/ProfileSpecificStorage.java
index f08ffddd7..33ad237db 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/storage/ProfileSpecificStorage.java
+++ b/src/main/java/at/hannibal2/skyhanni/config/storage/ProfileSpecificStorage.java
@@ -223,7 +223,8 @@ public class ProfileSpecificStorage {
public Map<CropType, Double> latestTrueFarmingFortune = new HashMap<>();
@Expose
- public CropAccessory savedCropAccessory = null;
+ @Nullable
+ public CropAccessory savedCropAccessory = CropAccessory.NONE;
@Expose
public DicerRngDropTracker.Data dicerDropTracker = new DicerRngDropTracker.Data();
diff --git a/src/main/java/at/hannibal2/skyhanni/data/CropAccessoryData.kt b/src/main/java/at/hannibal2/skyhanni/data/CropAccessoryData.kt
index 321e81e26..d6f1456b4 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/CropAccessoryData.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/CropAccessoryData.kt
@@ -1,7 +1,6 @@
package at.hannibal2.skyhanni.data
-import at.hannibal2.skyhanni.events.InventoryCloseEvent
-import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent
+import at.hannibal2.skyhanni.events.InventoryUpdatedEvent
import at.hannibal2.skyhanni.events.ProfileJoinEvent
import at.hannibal2.skyhanni.events.SecondPassedEvent
import at.hannibal2.skyhanni.features.garden.CropAccessory
@@ -9,128 +8,58 @@ import at.hannibal2.skyhanni.features.garden.GardenAPI
import at.hannibal2.skyhanni.utils.InventoryUtils
import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName
import at.hannibal2.skyhanni.utils.LorenzUtils
-import at.hannibal2.skyhanni.utils.NEUItems
-import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
+import at.hannibal2.skyhanni.utils.StringUtils.matches
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
-import com.google.gson.JsonElement
import net.minecraft.item.ItemStack
-import net.minecraft.nbt.CompressedStreamTools
-import net.minecraftforge.client.event.GuiScreenEvent
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
-import java.io.ByteArrayInputStream
-import java.util.Base64
-class CropAccessoryData {
+object CropAccessoryData {
private val accessoryBagNamePattern by RepoPattern.pattern(
- "data.accessory.bagname",
- "Accessory Bag \\((?<current>\\d)/(?<total>\\d)\\)"
+ "data.accessory.bagname.new",
+ "Accessory Bag.*"
)
- private var loadedAccessoryThisProfile = false
- private var accessoryInBag: CropAccessory? = null
+ private var accessoryInBag = CropAccessory.NONE
private var accessoryInInventory = CropAccessory.NONE
- private var accessoryBagPageNumber = 0
-
- // Handle API detection
@SubscribeEvent
fun onProfileJoin(event: ProfileJoinEvent) {
- loadedAccessoryThisProfile = false
-
- accessoryPage.clear()
- }
-
- // Handle accessory bag detection
- @SubscribeEvent
- fun onInventoryOpen(event: InventoryFullyOpenedEvent) {
-
- // handling accessory bags with only one page
- if (event.inventoryName == "Accessory Bag") {
- isLoadingAccessories = true
- accessoryBagPageCount = 1
- accessoryBagPageNumber = 1
- return
- }
-
- accessoryBagNamePattern.matchMatcher(event.inventoryName) {
- isLoadingAccessories = true
- accessoryBagPageNumber = group("current").toInt()
- accessoryBagPageCount = group("total").toInt()
- } ?: return
+ accessoryInBag = CropAccessory.NONE
+ accessoryInInventory = CropAccessory.NONE
}
@SubscribeEvent
- fun onInventoryClose(event: InventoryCloseEvent) {
- isLoadingAccessories = false
- }
+ fun onInventoryOpen(event: InventoryUpdatedEvent) {
+ if (!accessoryBagNamePattern.matches(event.inventoryName)) return
- @SubscribeEvent
- fun onGuiDraw(event: GuiScreenEvent.DrawScreenEvent) {
- if (!isLoadingAccessories) return
- val items = runCatching {
- InventoryUtils.getItemsInOpenChest()
- }.getOrNull() ?: return
- val bestCropAccessoryPage = bestCropAccessory(items.map { it.stack })
- accessoryPage[accessoryBagPageNumber] = bestCropAccessoryPage
- if (accessoryBagPageCount == accessoryPage.size) {
- accessoryInBag = accessoryPage.values.max().also {
- cropAccessory = maxOf(it, accessoryInInventory)
- }
- loadedAccessoryThisProfile = true
+ val items = event.inventoryItems.mapNotNull { it.value }
+ val bestInPage = bestCropAccessory(items)
+ if (bestInPage > accessoryInBag) {
+ accessoryInBag = bestInPage
}
}
- // Handle inventory detection
@SubscribeEvent
fun onSecondPassed(event: SecondPassedEvent) {
if (!LorenzUtils.inSkyBlock) return
+ if (!event.repeatSeconds(5)) return
+
accessoryInInventory = bestCropAccessory(InventoryUtils.getItemsInOwnInventory())
- if (accessoryInInventory == CropAccessory.NONE) return
- if (accessoryInInventory > (accessoryInBag ?: CropAccessory.NONE)) {
- cropAccessory = accessoryInInventory
+
+ val bestAccessory = maxOf(accessoryInInventory, accessoryInBag)
+ if (bestAccessory > cropAccessory) {
+ cropAccessory = bestAccessory
}
}
- private fun bestCropAccessory(items: Iterable<ItemStack>) =
+ private fun bestCropAccessory(items: List<ItemStack>) =
items.mapNotNull { item -> CropAccessory.getByName(item.getInternalName()) }
.maxOrNull() ?: CropAccessory.NONE
- companion object {
-
- var accessoryBagPageCount = 0
- private set
-
- private var accessoryPage = mutableMapOf<Int, CropAccessory>()
-
- var isLoadingAccessories = false
- private set
-
- val pagesLoaded get() = accessoryPage.size
-
- var cropAccessory: CropAccessory?
- get() = GardenAPI.storage?.savedCropAccessory
- private set(accessory) {
- GardenAPI.storage?.savedCropAccessory = accessory
- }
-
- // Derived partially from NotEnoughUpdates/NotEnoughUpdates, ProfileViewer.Profile#getInventoryInfo
- private fun getCropAccessories(inventory: JsonElement?): MutableList<CropAccessory> {
- if (inventory == null) return mutableListOf()
- val cropAccessories = mutableListOf<CropAccessory>()
- val data = inventory.asJsonObject["data"]?.asString
- val accessoryBagItems = CompressedStreamTools.readCompressed(
- ByteArrayInputStream(Base64.getDecoder().decode(data))
- ).getTagList("i", 10)
- for (j in 0 until accessoryBagItems.tagCount()) {
- val itemStackTag = accessoryBagItems.getCompoundTagAt(j)
- if (!itemStackTag.hasKey("tag")) continue
- val itemTag = itemStackTag.getCompoundTag("tag")
- val itemName = NEUItems.getInternalNameOrNull(itemTag) ?: continue
- val itemAsCropAccessory = CropAccessory.getByName(itemName) ?: continue
- cropAccessories.add(itemAsCropAccessory)
- }
- return cropAccessories
+ var cropAccessory: CropAccessory
+ get() = GardenAPI.storage?.savedCropAccessory ?: CropAccessory.NONE
+ private set(accessory) {
+ GardenAPI.storage?.savedCropAccessory = accessory
}
- }
}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/fortuneguide/FFStats.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/fortuneguide/FFStats.kt
index 0b27856fd..2f1ce1860 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/fortuneguide/FFStats.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/fortuneguide/FFStats.kt
@@ -88,7 +88,7 @@ object FFStats {
cropPage.clear()
cropPage[FortuneStats.BASE] = Pair(totalBaseFF[FFTypes.TOTAL] ?: 100.0, if (usingSpeedBoots) 1373.0 else 1377.0)
cropPage[FortuneStats.CROP_UPGRADE] = Pair((crop.getUpgradeLevel()?.toDouble() ?: 0.0) * 5.0, 45.0)
- cropPage[FortuneStats.ACCESSORY] = Pair(CropAccessoryData.cropAccessory?.getFortune(crop) ?: 0.0, 30.0)
+ cropPage[FortuneStats.ACCESSORY] = Pair(CropAccessoryData.cropAccessory.getFortune(crop), 30.0)
cropPage[FortuneStats.FFD] = Pair((tool.getFarmingForDummiesCount() ?: 0).toDouble(), 5.0)
cropPage[FortuneStats.TURBO] = Pair(FarmingFortuneDisplay.getTurboCropFortune(tool, crop), 25.0)
cropPage[FortuneStats.DEDICATION] = Pair(FarmingFortuneDisplay.getDedicationFortune(tool, crop), 92.0)
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/fortuneguide/FortuneUpgrades.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/fortuneguide/FortuneUpgrades.kt
index 5abc89f80..191b9b7e5 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/fortuneguide/FortuneUpgrades.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/fortuneguide/FortuneUpgrades.kt
@@ -80,7 +80,7 @@ object FortuneUpgrades {
}
private fun getTalismanUpgrade() {
- val currentTalismanTier = CropAccessoryData.cropAccessory?.ordinal ?: return
+ val currentTalismanTier = CropAccessoryData.cropAccessory.ordinal
if (currentTalismanTier < 3) {
val nextTalisman = CropAccessory.entries[currentTalismanTier + 1]
genericUpgrades.add(
diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/bazaar/BazaarBestSellMethod.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/bazaar/BazaarBestSellMethod.kt
index c9fecb44f..5a11084c8 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/inventory/bazaar/BazaarBestSellMethod.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/bazaar/BazaarBestSellMethod.kt
@@ -3,6 +3,7 @@ package at.hannibal2.skyhanni.features.inventory.bazaar
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.events.BazaarOpenedProductEvent
import at.hannibal2.skyhanni.events.GuiContainerEvent
+import at.hannibal2.skyhanni.events.GuiRenderEvent
import at.hannibal2.skyhanni.events.InventoryCloseEvent
import at.hannibal2.skyhanni.features.inventory.bazaar.BazaarApi.Companion.getBazaarDataOrError
import at.hannibal2.skyhanni.utils.InventoryUtils.getAmountInInventory
@@ -13,7 +14,6 @@ import at.hannibal2.skyhanni.utils.NEUInternalName
import at.hannibal2.skyhanni.utils.NumberUtil
import at.hannibal2.skyhanni.utils.RenderUtils.renderString
import net.minecraft.item.ItemStack
-import net.minecraftforge.client.event.GuiScreenEvent
import net.minecraftforge.fml.common.eventhandler.EventPriority
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
@@ -64,9 +64,10 @@ class BazaarBestSellMethod {
return "$name§7 sell difference: §6$result coins"
}
- @SubscribeEvent(priority = EventPriority.LOWEST)
- fun renderOverlay(event: GuiScreenEvent.BackgroundDrawnEvent) {
+ @SubscribeEvent
+ fun onBackgroundDraw(event: GuiRenderEvent.ChestGuiOverlayRenderEvent) {
if (!isEnabled()) return
+ if (display.isEmpty()) return
config.bestSellMethodPos.renderString(display, posLabel = "Bazaar Best Sell Method")
}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/minion/MinionFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/minion/MinionFeatures.kt
index 7fa5700f0..aa9ce88e6 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/minion/MinionFeatures.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/minion/MinionFeatures.kt
@@ -8,6 +8,7 @@ import at.hannibal2.skyhanni.data.IslandType
import at.hannibal2.skyhanni.data.ProfileStorageData
import at.hannibal2.skyhanni.events.BlockClickEvent
import at.hannibal2.skyhanni.events.EntityClickEvent
+import at.hannibal2.skyhanni.events.GuiRenderEvent
import at.hannibal2.skyhanni.events.InventoryCloseEvent
import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent
import at.hannibal2.skyhanni.events.InventoryUpdatedEvent
@@ -53,7 +54,6 @@ import net.minecraft.client.gui.inventory.GuiChest
import net.minecraft.entity.EntityLivingBase
import net.minecraft.entity.item.EntityArmorStand
import net.minecraft.init.Blocks
-import net.minecraftforge.client.event.GuiScreenEvent
import net.minecraftforge.event.entity.player.PlayerInteractEvent
import net.minecraftforge.fml.common.eventhandler.EventPriority
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
@@ -386,8 +386,8 @@ class MinionFeatures {
private fun enableWithHub() = isEnabled() || IslandType.HUB.isInIsland()
- @SubscribeEvent(priority = EventPriority.LOWEST)
- fun renderOverlay(event: GuiScreenEvent.BackgroundDrawnEvent) {
+ @SubscribeEvent
+ fun onBackgroundDraw(event: GuiRenderEvent.ChestGuiOverlayRenderEvent) {
if (!LorenzUtils.inSkyBlock) return
if (!minionInventoryOpen) return