diff options
author | inglettronald <71849533+inglettronald@users.noreply.github.com> | 2023-03-21 18:08:57 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-21 18:08:57 -0500 |
commit | 2cb6f4cffee0ab505b35938cf71518e4640a229a (patch) | |
tree | 02224acacc7e7823079a8e2cc24377eafe33700c /src/main/kotlin/dulkirmod/features/Croesus.kt | |
parent | 05c6b155f1de3a96ef081627ff7805238742162f (diff) | |
parent | 3968c49ccfb1fb3b0c6a8274f4d45ed0ba50ec48 (diff) | |
download | DulkirMod-2cb6f4cffee0ab505b35938cf71518e4640a229a.tar.gz DulkirMod-2cb6f4cffee0ab505b35938cf71518e4640a229a.tar.bz2 DulkirMod-2cb6f4cffee0ab505b35938cf71518e4640a229a.zip |
Merge pull request #11 from IlmarsXd/master
refactor modules (class -> object), add memory leak fix
Diffstat (limited to 'src/main/kotlin/dulkirmod/features/Croesus.kt')
-rw-r--r-- | src/main/kotlin/dulkirmod/features/Croesus.kt | 143 |
1 files changed, 72 insertions, 71 deletions
diff --git a/src/main/kotlin/dulkirmod/features/Croesus.kt b/src/main/kotlin/dulkirmod/features/Croesus.kt index 36bf3ee..ea8b022 100644 --- a/src/main/kotlin/dulkirmod/features/Croesus.kt +++ b/src/main/kotlin/dulkirmod/features/Croesus.kt @@ -9,75 +9,76 @@ import net.minecraft.nbt.NBTTagList import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import net.minecraftforge.fml.common.gameevent.TickEvent -class Croesus { - - var lastGuiOpenEvent: Long = 0 - var lastPageNumber = 1 - - @SubscribeEvent - fun onTick(event: TickEvent.ClientTickEvent) { - val lastInCroesus = inCroesusBool - var pageNumber = 1 - - if (!Config.hideOpenedChests) return - if (mc.currentScreen == null || !(mc.currentScreen is GuiChest)) { - inCroesusBool = false - return - } - inCroesusBool = (ContainerNameUtil.currentGuiChestName == "Croesus") - - if (inCroesusBool) { - pageNumber = findPageNumber() - } - - // weird way of detecting page turn - if(lastPageNumber != pageNumber) - lastGuiOpenEvent = System.currentTimeMillis() - - if (inCroesusBool && !lastInCroesus) { - lastGuiOpenEvent = System.currentTimeMillis() - } - - if (inCroesusBool && System.currentTimeMillis() - lastGuiOpenEvent < 300) { - for (i in 9..44) { - boolArray[i - 9] = false - val slotIn = mc.thePlayer.openContainer.getSlot(i) - - if (slotIn.stack == null) continue - val stack = slotIn.stack - - val tagList: NBTTagList = stack.getSubCompound("display", false)?.getTagList("Lore", 8) ?: continue - for (j in 0 until tagList.tagCount()) { - if (tagList.getStringTagAt(j) == "§aChests have been opened!") boolArray[i - 9] = true - } - } - } - } - - private fun findPageNumber(): Int { - val stackPrev = mc.thePlayer.openContainer.getSlot(45).stack ?: return lastPageNumber - - val stackPrevLore = stackPrev.getSubCompound("display", false)?.getTagList("Lore", 8) ?: return 1 - - if (stackPrevLore.getStringTagAt(0).contains("1")) return 2 - - return 3 - } - - companion object { - var inCroesusBool: Boolean = false - var boolArray = BooleanArray(36) { false } - - fun inCroesus(): Boolean { - return inCroesusBool - } - - fun isChestOpened(slotIn: Slot): Boolean { - if (!inCroesusBool) return false - if (slotIn.inventory == mc.thePlayer.inventory) return false - val slotindex = slotIn.slotIndex - if (slotindex !in 9..44) return false - return boolArray[slotindex - 9] - } - } +object Croesus { + + var lastGuiOpenEvent: Long = 0 + var lastPageNumber = 1 + + @SubscribeEvent + fun onTick(event: TickEvent.ClientTickEvent) { + val lastInCroesus = inCroesusBool + var pageNumber = 1 + + if (!Config.hideOpenedChests) return + if (mc.currentScreen == null || !(mc.currentScreen is GuiChest)) { + inCroesusBool = false + return + } + inCroesusBool = (ContainerNameUtil.currentGuiChestName == "Croesus") + + if (inCroesusBool) { + pageNumber = findPageNumber() + } + + // weird way of detecting page turn + if (lastPageNumber != pageNumber) + lastGuiOpenEvent = System.currentTimeMillis() + + if (inCroesusBool && !lastInCroesus) { + lastGuiOpenEvent = System.currentTimeMillis() + } + + if (inCroesusBool && System.currentTimeMillis() - lastGuiOpenEvent < 300) { + for (i in 9..44) { + boolArray[i - 9] = false + val slotIn = mc.thePlayer.openContainer.getSlot(i) + + if (slotIn.stack == null) continue + val stack = slotIn.stack + + val tagList: NBTTagList = stack.getSubCompound("display", false)?.getTagList("Lore", 8) ?: continue + for (j in 0 until tagList.tagCount()) { + if (tagList.getStringTagAt(j) == "§aChests have been opened!") boolArray[i - 9] = true + } + } + } + } + + private fun findPageNumber(): Int { + val stackPrev = mc.thePlayer.openContainer.getSlot(45).stack ?: return lastPageNumber + + val stackPrevLore = stackPrev.getSubCompound("display", false)?.getTagList("Lore", 8) ?: return 1 + + if (stackPrevLore.getStringTagAt(0).contains("1")) return 2 + + return 3 + } + + var inCroesusBool: Boolean = false + + var boolArray = BooleanArray(36) { false } + + @JvmStatic + fun inCroesus(): Boolean { + return inCroesusBool + } + + @JvmStatic + fun isChestOpened(slotIn: Slot): Boolean { + if (!inCroesusBool) return false + if (slotIn.inventory == mc.thePlayer.inventory) return false + val slotindex = slotIn.slotIndex + if (slotindex !in 9..44) return false + return boolArray[slotindex - 9] + } }
\ No newline at end of file |