11package io.github.frostzie.skyfall.features.inventory
22
3- import com.google.gson.Gson
3+ import com.google.gson.GsonBuilder
44import com.google.gson.reflect.TypeToken
55import io.github.frostzie.skyfall.SkyFall
66import io.github.frostzie.skyfall.utils.events.SlotRenderEvents
@@ -9,8 +9,7 @@ import net.minecraft.client.MinecraftClient
99import net.minecraft.client.gui.DrawContext
1010import net.minecraft.client.gui.screen.ingame.HandledScreen
1111import net.minecraft.client.util.InputUtil
12- import net.minecraft.item.Items
13- import net.minecraft.screen.GenericContainerScreenHandler
12+ import net.minecraft.entity.player.PlayerInventory
1413import net.minecraft.screen.slot.Slot
1514import org.lwjgl.glfw.GLFW
1615import java.awt.Color
@@ -21,12 +20,10 @@ import kotlin.text.contains
2120
2221object FavoritePowerStone {
2322 private val configFile = File (" config/skyfall/favorite-power-stones.json" )
24- private val gson = Gson ()
23+ private val gson = GsonBuilder ().setPrettyPrinting().create ()
2524 private var keyWasPressed = false
2625 private var highlightedItems = mutableSetOf<String >()
2726
28- private val highlightKey = SkyFall .feature.inventory.powerStone.favoriteKey
29-
3027 private val validSlotRanges = setOf (
3128 10 .. 16 ,
3229 19 .. 25 ,
@@ -40,6 +37,7 @@ object FavoritePowerStone {
4037 ClientTickEvents .END_CLIENT_TICK .register { client ->
4138 val currentScreen = client.currentScreen
4239 if (currentScreen is HandledScreen <* > && isAccessoryBagThaumaturgy(currentScreen)) {
40+ val highlightKey = SkyFall .feature.inventory.powerStone.favoriteKey
4341 val window = MinecraftClient .getInstance().window.handle
4442
4543 if (highlightKey != GLFW .GLFW_KEY_UNKNOWN ) {
@@ -65,22 +63,21 @@ object FavoritePowerStone {
6563
6664 private fun isAccessoryBagThaumaturgy (screen : HandledScreen <* >): Boolean {
6765 val title = screen.title.string
68- if (! title.contains(" Accessory Bag Thaumaturgy" )) {
69- return false
70- }
66+ return title.contains(" Accessory Bag Thaumaturgy" )
67+ }
7168
72- val handler = screen.screenHandler
73- if (handler is GenericContainerScreenHandler && handler.slots.size > 49 ) {
74- val slot49 = handler.slots[49 ]
75- return slot49.stack.item == Items .BARRIER
76- }
77- return false
69+ private fun isSlotInChestInventory (slot : Slot ): Boolean {
70+ return slot.inventory !is PlayerInventory
7871 }
7972
8073 private fun handleKeyPress (screen : HandledScreen <* >) {
8174 val hoveredSlot = getHoveredSlot(screen) ? : return
8275 val slotIndex = hoveredSlot.index
8376
77+ if (! FavoriteAbiContact .isSlotInChestInventory(hoveredSlot)) {
78+ return
79+ }
80+
8481 if (! validSlotRanges.any { slotIndex in it }) {
8582 return
8683 }
@@ -131,6 +128,10 @@ object FavoritePowerStone {
131128
132129 val slotIndex = slot.index
133130
131+ if (! FavoriteAbiContact .isSlotInChestInventory(slot)) {
132+ return
133+ }
134+
134135 if (! validSlotRanges.any { slotIndex in it } || slot.stack.isEmpty) {
135136 return
136137 }
0 commit comments