aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-01-07 05:39:53 +0100
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-01-07 05:39:53 +0100
commit2b78f5b11d480c632b4a5d5b4a4a8f659d8d3ea7 (patch)
tree569748d134c40fe6fdf941981a6ff847d353033d
parentcdfec7e6849c3a807812515eef26582933fbadd8 (diff)
downloadskyhanni-2b78f5b11d480c632b4a5d5b4a4a8f659d8d3ea7.tar.gz
skyhanni-2b78f5b11d480c632b4a5d5b4a4a8f659d8d3ea7.tar.bz2
skyhanni-2b78f5b11d480c632b4a5d5b4a4a8f659d8d3ea7.zip
Using getInventoryName methods.
-rw-r--r--src/main/java/at/hannibal2/skyhanni/events/GuiContainerEvent.kt17
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/anvil/AnvilCombineHelper.kt6
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarOrderHelper.kt3
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/dungeon/CroesusUnopenedChestTracker.kt7
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonLevelColor.kt9
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/inventory/HideNotClickableItems.kt13
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/inventory/RngMeterInventory.kt15
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/inventory/StatsTuning.kt14
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/InventoryUtils.kt11
9 files changed, 34 insertions, 61 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/events/GuiContainerEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/GuiContainerEvent.kt
index 9a993cb77..437130bdd 100644
--- a/src/main/java/at/hannibal2/skyhanni/events/GuiContainerEvent.kt
+++ b/src/main/java/at/hannibal2/skyhanni/events/GuiContainerEvent.kt
@@ -2,15 +2,10 @@ package at.hannibal2.skyhanni.events
import net.minecraft.client.gui.inventory.GuiContainer
import net.minecraft.inventory.Container
-import net.minecraft.inventory.ContainerChest
import net.minecraft.inventory.Slot
import net.minecraftforge.fml.common.eventhandler.Cancelable
abstract class GuiContainerEvent(open val gui: GuiContainer, open val container: Container) : LorenzEvent() {
- val chestName: String by lazy {
- if (container !is ContainerChest) error("Container is not a chest")
- return@lazy (container as ContainerChest).lowerChestInventory.displayName.unformattedText.trim()
- }
data class BackgroundDrawnEvent(
override val gui: GuiContainer,
@@ -27,10 +22,18 @@ abstract class GuiContainerEvent(open val gui: GuiContainer, open val container:
abstract class DrawSlotEvent(gui: GuiContainer, container: Container, open val slot: Slot) :
GuiContainerEvent(gui, container) {
@Cancelable
- data class GuiContainerDrawSlotPre(override val gui: GuiContainer, override val container: Container, override val slot: Slot) :
+ data class GuiContainerDrawSlotPre(
+ override val gui: GuiContainer,
+ override val container: Container,
+ override val slot: Slot
+ ) :
DrawSlotEvent(gui, container, slot)
- data class GuiContainerDrawSlotPost(override val gui: GuiContainer, override val container: Container, override val slot: Slot) :
+ data class GuiContainerDrawSlotPost(
+ override val gui: GuiContainer,
+ override val container: Container,
+ override val slot: Slot
+ ) :
DrawSlotEvent(gui, container, slot)
}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/anvil/AnvilCombineHelper.kt b/src/main/java/at/hannibal2/skyhanni/features/anvil/AnvilCombineHelper.kt
index 9604cb05c..e03126fde 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/anvil/AnvilCombineHelper.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/anvil/AnvilCombineHelper.kt
@@ -2,6 +2,7 @@ package at.hannibal2.skyhanni.features.anvil
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.events.GuiContainerEvent
+import at.hannibal2.skyhanni.utils.InventoryUtils.getInventoryName
import at.hannibal2.skyhanni.utils.ItemUtils.getLore
import at.hannibal2.skyhanni.utils.LorenzColor
import at.hannibal2.skyhanni.utils.LorenzUtils
@@ -18,9 +19,8 @@ class AnvilCombineHelper {
if (!SkyHanniMod.feature.inventory.anvilCombineHelper) return
if (event.gui !is GuiChest) return
- val guiChest = event.gui
- val chest = guiChest.inventorySlots as ContainerChest
- val chestName = chest.lowerChestInventory.displayName.unformattedText.trim()
+ val chest = event.gui.inventorySlots as ContainerChest
+ val chestName = chest.getInventoryName()
if (chestName != "Anvil") return
diff --git a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarOrderHelper.kt b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarOrderHelper.kt
index 31bc1e978..fb4c3079b 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarOrderHelper.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarOrderHelper.kt
@@ -2,6 +2,7 @@ package at.hannibal2.skyhanni.features.bazaar
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.events.GuiContainerEvent
+import at.hannibal2.skyhanni.utils.InventoryUtils.getInventoryName
import at.hannibal2.skyhanni.utils.ItemUtils.getLore
import at.hannibal2.skyhanni.utils.ItemUtils.name
import at.hannibal2.skyhanni.utils.LorenzColor
@@ -26,7 +27,7 @@ class BazaarOrderHelper {
if (event.gui !is GuiChest) return
val guiChest = event.gui
val chest = guiChest.inventorySlots as ContainerChest
- val inventoryName = chest.lowerChestInventory.displayName.unformattedText.trim()
+ val inventoryName = chest.getInventoryName()
if (!isBazaarOrderInventory(inventoryName)) return
out@ for (slot in chest.inventorySlots) {
diff --git a/src/main/java/at/hannibal2/skyhanni/features/dungeon/CroesusUnopenedChestTracker.kt b/src/main/java/at/hannibal2/skyhanni/features/dungeon/CroesusUnopenedChestTracker.kt
index 024c05c86..20d7207f0 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/dungeon/CroesusUnopenedChestTracker.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/dungeon/CroesusUnopenedChestTracker.kt
@@ -7,8 +7,6 @@ import at.hannibal2.skyhanni.utils.ItemUtils.getLore
import at.hannibal2.skyhanni.utils.LorenzColor
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.RenderUtils.highlight
-import net.minecraft.client.gui.inventory.GuiChest
-import net.minecraft.inventory.ContainerChest
import net.minecraftforge.fml.common.eventhandler.EventPriority
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
@@ -19,10 +17,7 @@ class CroesusUnopenedChestTracker {
if (!LorenzUtils.inSkyBlock) return
if (!SkyHanniMod.feature.dungeon.croesusUnopenedChestTracker) return
- if (event.gui !is GuiChest) return
- val guiChest = event.gui
- val chest = guiChest.inventorySlots as ContainerChest
- val chestName = chest.lowerChestInventory.displayName.unformattedText.trim()
+ val chestName = InventoryUtils.openInventoryName()
if (chestName == "Croesus") {
for (slot in InventoryUtils.getItemsInOpenChest()) {
diff --git a/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonLevelColor.kt b/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonLevelColor.kt
index 9b9027d83..ff334737b 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonLevelColor.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonLevelColor.kt
@@ -1,11 +1,9 @@
package at.hannibal2.skyhanni.features.dungeon
import at.hannibal2.skyhanni.SkyHanniMod
+import at.hannibal2.skyhanni.utils.InventoryUtils
import at.hannibal2.skyhanni.utils.ItemUtils.getLore
import at.hannibal2.skyhanni.utils.LorenzUtils
-import net.minecraft.client.Minecraft
-import net.minecraft.client.gui.inventory.GuiChest
-import net.minecraft.inventory.ContainerChest
import net.minecraftforge.event.entity.player.ItemTooltipEvent
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import java.util.regex.Pattern
@@ -20,10 +18,7 @@ class DungeonLevelColor {
if (!SkyHanniMod.feature.dungeon.partyFinderColoredClassLevel) return
if (event.toolTip == null) return
- val guiChest = Minecraft.getMinecraft().currentScreen
- if (guiChest !is GuiChest) return
- val chest = guiChest.inventorySlots as ContainerChest
- val chestName = chest.lowerChestInventory.displayName.unformattedText.trim()
+ val chestName = InventoryUtils.openInventoryName()
if (chestName != "Party Finder") return
val stack = event.itemStack
diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/HideNotClickableItems.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/HideNotClickableItems.kt
index 4ec29baf2..a72466a66 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/inventory/HideNotClickableItems.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/HideNotClickableItems.kt
@@ -7,12 +7,12 @@ import at.hannibal2.skyhanni.events.GuiContainerEvent
import at.hannibal2.skyhanni.events.RepositoryReloadEvent
import at.hannibal2.skyhanni.features.bazaar.BazaarApi
import at.hannibal2.skyhanni.utils.*
+import at.hannibal2.skyhanni.utils.InventoryUtils.getInventoryName
import at.hannibal2.skyhanni.utils.ItemUtils.cleanName
import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName
import at.hannibal2.skyhanni.utils.ItemUtils.getLore
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
import com.google.gson.JsonObject
-import net.minecraft.client.Minecraft
import net.minecraft.client.gui.inventory.GuiChest
import net.minecraft.inventory.ContainerChest
import net.minecraft.item.ItemStack
@@ -70,7 +70,7 @@ class HideNotClickableItems {
if (event.gui !is GuiChest) return
val guiChest = event.gui
val chest = guiChest.inventorySlots as ContainerChest
- val chestName = chest.lowerChestInventory.displayName.unformattedText.trim()
+ val chestName = chest.getInventoryName()
for (slot in chest.inventorySlots) {
if (slot == null) continue
@@ -92,10 +92,7 @@ class HideNotClickableItems {
fun onTooltip(event: ItemTooltipEvent) {
if (isDisabled()) return
if (event.toolTip == null) return
- val guiChest = Minecraft.getMinecraft().currentScreen
- if (guiChest !is GuiChest) return
- val chest = guiChest.inventorySlots as ContainerChest
- val chestName = chest.lowerChestInventory.displayName.unformattedText.trim()
+ val chestName = InventoryUtils.openInventoryName()
val stack = event.itemStack
if (InventoryUtils.getItemsInOpenChest().map { it.stack }.contains(stack)) return
@@ -119,9 +116,7 @@ class HideNotClickableItems {
fun onSlotClick(event: GuiContainerEvent.SlotClickEvent) {
if (isDisabled()) return
if (event.gui !is GuiChest) return
- val guiChest = event.gui
- val chest = guiChest.inventorySlots as ContainerChest
- val chestName = chest.lowerChestInventory.displayName.unformattedText.trim()
+ val chestName = InventoryUtils.openInventoryName()
val slot = event.slot ?: return
diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/RngMeterInventory.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/RngMeterInventory.kt
index ec381a124..eb2ead1fb 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/inventory/RngMeterInventory.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/RngMeterInventory.kt
@@ -11,9 +11,6 @@ import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.LorenzUtils.between
import at.hannibal2.skyhanni.utils.RenderUtils.highlight
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
-import net.minecraft.client.Minecraft
-import net.minecraft.client.gui.inventory.GuiChest
-import net.minecraft.inventory.ContainerChest
import net.minecraftforge.fml.common.eventhandler.EventPriority
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
@@ -21,11 +18,7 @@ class RngMeterInventory {
@SubscribeEvent
fun onRenderItemTip(event: RenderItemTipEvent) {
- val screen = Minecraft.getMinecraft().currentScreen
- if (screen !is GuiChest) return
- val chest = screen.inventorySlots as ContainerChest
- val chestName = chest.lowerChestInventory.displayName.unformattedText.trim()
-
+ val chestName = InventoryUtils.openInventoryName()
val stack = event.stack
if (SkyHanniMod.feature.inventory.rngMeterFloorName) {
@@ -42,11 +35,7 @@ class RngMeterInventory {
fun onBackgroundDrawn(event: GuiContainerEvent.BackgroundDrawnEvent) {
if (!LorenzUtils.inSkyBlock) return
- if (event.gui !is GuiChest) return
- val guiChest = event.gui
- val chest = guiChest.inventorySlots as ContainerChest
- val chestName = chest.lowerChestInventory.displayName.unformattedText.trim()
-
+ val chestName = InventoryUtils.openInventoryName()
if (SkyHanniMod.feature.inventory.rngMeterNoDrop) {
if (chestName == "Catacombs RNG Meter") {
for (slot in InventoryUtils.getItemsInOpenChest()) {
diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/StatsTuning.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/StatsTuning.kt
index d33f03042..98383bd0c 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/inventory/StatsTuning.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/StatsTuning.kt
@@ -9,9 +9,6 @@ import at.hannibal2.skyhanni.utils.ItemUtils.name
import at.hannibal2.skyhanni.utils.LorenzColor
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.RenderUtils.highlight
-import net.minecraft.client.Minecraft
-import net.minecraft.client.gui.inventory.GuiChest
-import net.minecraft.inventory.ContainerChest
import net.minecraftforge.fml.common.eventhandler.EventPriority
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import java.util.regex.Pattern
@@ -22,10 +19,7 @@ class StatsTuning {
@SubscribeEvent
fun onRenderItemTip(event: RenderInventoryItemTipEvent) {
- val screen = Minecraft.getMinecraft().currentScreen
- if (screen !is GuiChest) return
- val chest = screen.inventorySlots as ContainerChest
- val chestName = chest.lowerChestInventory.displayName.unformattedText.trim()
+ val chestName = InventoryUtils.openInventoryName()
val stack = event.stack
@@ -107,11 +101,7 @@ class StatsTuning {
fun onDrawSelectedTemplate(event: GuiContainerEvent.BackgroundDrawnEvent) {
if (!LorenzUtils.inSkyBlock) return
- if (event.gui !is GuiChest) return
- val guiChest = event.gui
- val chest = guiChest.inventorySlots as ContainerChest
- val chestName = chest.lowerChestInventory.displayName.unformattedText.trim()
-
+ val chestName = InventoryUtils.openInventoryName()
if (SkyHanniMod.feature.inventory.statsTuningSelectedTemplate) {
if (chestName == "Stats Tuning") {
for (slot in InventoryUtils.getItemsInOpenChest()) {
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/InventoryUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/InventoryUtils.kt
index f1f107e2f..feaaaa481 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/InventoryUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/InventoryUtils.kt
@@ -11,9 +11,10 @@ object InventoryUtils {
fun currentlyOpenInventory(): String {
val screen = Minecraft.getMinecraft().currentScreen
if (screen !is GuiChest) return ""
- val chest = screen.inventorySlots as ContainerChest
+ val inventorySlots = screen.inventorySlots
+ val chest = inventorySlots as ContainerChest
- return chest.lowerChestInventory.displayName.unformattedText.trim()
+ return chest.getInventoryName()
}
fun getItemsInOpenChest(): List<Slot> {
@@ -37,10 +38,14 @@ object InventoryUtils {
val guiChest = Minecraft.getMinecraft().currentScreen
val chestName = if (guiChest is GuiChest) {
val chest = guiChest.inventorySlots as ContainerChest
- chest.lowerChestInventory.displayName.unformattedText.trim()
+ chest.getInventoryName()
} else {
""
}
return chestName
}
+
+ fun ContainerChest.getInventoryName(): String {
+ return this.lowerChestInventory.displayName.unformattedText.trim()
+ }
} \ No newline at end of file