aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/com/ambientaddons/features/dungeon/AutoBuyChest.kt
diff options
context:
space:
mode:
authorAppability <appable@icloud.com>2022-10-12 01:13:04 -0700
committerAppability <appable@icloud.com>2022-10-12 01:13:04 -0700
commit42fb54e0eaedc44d22a8c86fc539e46c68af3dab (patch)
tree1f9b10d705cfee23954777f49afa9f5a58060dd8 /src/main/kotlin/com/ambientaddons/features/dungeon/AutoBuyChest.kt
parent2c0e73deb53f54d78bd5594786313ac82151be1a (diff)
downloadAmbientAddons-42fb54e0eaedc44d22a8c86fc539e46c68af3dab.tar.gz
AmbientAddons-42fb54e0eaedc44d22a8c86fc539e46c68af3dab.tar.bz2
AmbientAddons-42fb54e0eaedc44d22a8c86fc539e46c68af3dab.zip
fix chestqol free chest features, + cancelinteractions and closechest from floppa
Diffstat (limited to 'src/main/kotlin/com/ambientaddons/features/dungeon/AutoBuyChest.kt')
-rw-r--r--src/main/kotlin/com/ambientaddons/features/dungeon/AutoBuyChest.kt54
1 files changed, 39 insertions, 15 deletions
diff --git a/src/main/kotlin/com/ambientaddons/features/dungeon/AutoBuyChest.kt b/src/main/kotlin/com/ambientaddons/features/dungeon/AutoBuyChest.kt
index 36f0b94..3c67c4d 100644
--- a/src/main/kotlin/com/ambientaddons/features/dungeon/AutoBuyChest.kt
+++ b/src/main/kotlin/com/ambientaddons/features/dungeon/AutoBuyChest.kt
@@ -4,6 +4,7 @@ import AmbientAddons.Companion.config
import AmbientAddons.Companion.mc
import AmbientAddons.Companion.persistentData
import com.ambientaddons.events.GuiContainerEvent
+import com.ambientaddons.events.ReceivePacketEvent
import com.ambientaddons.utils.Extensions.chest
import com.ambientaddons.utils.Extensions.enchants
import com.ambientaddons.utils.Extensions.items
@@ -13,7 +14,10 @@ import com.ambientaddons.utils.Extensions.stripControlCodes
import com.ambientaddons.utils.Extensions.withModPrefix
import com.ambientaddons.utils.LocationUtils
import gg.essential.universal.UChat
+import net.minecraft.inventory.ContainerChest
import net.minecraft.item.ItemStack
+import net.minecraft.network.play.client.C0DPacketCloseWindow
+import net.minecraft.network.play.server.S2DPacketOpenWindow
import net.minecraftforge.client.event.GuiOpenEvent
import net.minecraftforge.client.event.GuiScreenEvent
import net.minecraftforge.event.world.WorldEvent
@@ -33,10 +37,13 @@ object AutoBuyChest {
@SubscribeEvent
fun onSlotClick(event: GuiContainerEvent.SlotClickEvent) {
- UChat.chat(event.slotId)
- if (rewardChest == null) return
+ if (LocationUtils.location != "Catacombs" || rewardChest == null) return
if (event.slotId == BUY_SLOT_INDEX) {
hasOpenedChest = true
+ if (rewardChest == RewardChest.Wood) {
+ UChat.chat("§cBlocked purchase! You already opened a chest this run.".withModPrefix())
+ event.isCanceled = true
+ }
} else if (event.slotId == KISMET_SLOT_INDEX) {
if (config.blockLowReroll && rewardChest != RewardChest.Bedrock && (rewardChest != RewardChest.Obsidian || LocationUtils.dungeonFloor.toString() != "M4")) {
UChat.chat("§cBlocked reroll! This low-tier chest should not be rerolled.".withModPrefix())
@@ -53,12 +60,16 @@ object AutoBuyChest {
}
}
+
+
@SubscribeEvent
fun onGuiOpen(event: GuiOpenEvent) {
+ if (LocationUtils.location != "Catacombs") return
if (event.gui == null) return
- val chest = event.gui.chest?.lowerChestInventory?.name
+ val chest = event.gui.chest
+ val chestName = chest?.lowerChestInventory?.name
- rewardChest = when (chest) {
+ rewardChest = when (chestName) {
"Wood Chest" -> RewardChest.Wood
"Gold Chest" -> RewardChest.Gold
"Emerald Chest" -> RewardChest.Emerald
@@ -73,23 +84,29 @@ object AutoBuyChest {
@SubscribeEvent
fun onGuiDraw(event: GuiScreenEvent.DrawScreenEvent) {
- if (config.autoBuyChest != 2 || rewardChest == null || hasLookedAtChest) return
- if (rewardChest == RewardChest.Wood) return
+ if (LocationUtils.location != "Catacombs" || config.autoBuyChest != 2 || rewardChest == null || hasLookedAtChest) return
val chest = event.gui?.chest ?: return
- val items = chest.lowerChestInventory.items
- if (items.last() != null) {
- hasLookedAtChest = true
- if (getShouldOpen(items)) {
- mc.playerController.windowClick(chest.windowId, BUY_SLOT_INDEX, 0, 0, mc.thePlayer)
- hasOpenedChest = true
- mc.thePlayer.closeScreen()
+ if (rewardChest == RewardChest.Wood && !hasOpenedChest) {
+ openChest(chest)
+ } else {
+ val items = chest.lowerChestInventory.items
+ if (items.last() != null) {
+ hasLookedAtChest = true
+ if (getShouldOpen(items)) {
+ openChest(chest)
+ }
}
}
}
private fun getShouldOpen(items: List<ItemStack?>): Boolean {
- val chestPrice =
- items[BUY_SLOT_INDEX]?.lore?.getOrNull(6)?.stripControlCodes()?.filter { it.isDigit() }?.toIntOrNull() ?: 0
+ val chestPrice = items[BUY_SLOT_INDEX]
+ ?.lore
+ ?.getOrNull(6)
+ ?.stripControlCodes()
+ ?.filter { it.isDigit() }
+ ?.toIntOrNull()
+ ?: 0
val lootItems = items.subList(9, 18).mapNotNull { itemStack ->
if (itemStack?.skyblockID == "ENCHANTED_BOOK") {
@@ -107,6 +124,13 @@ object AutoBuyChest {
return chestPrice <= maxPrice
}
+ fun openChest(chest: ContainerChest) {
+ hasLookedAtChest = true
+ mc.playerController.windowClick(chest.windowId, BUY_SLOT_INDEX, 0, 0, mc.thePlayer)
+ hasOpenedChest = true
+ mc.thePlayer.closeScreen()
+ }
+
enum class RewardChest {
Wood, Gold, Emerald, Diamond, Obsidian, Bedrock
}