aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/com/ambientaddons/features
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/kotlin/com/ambientaddons/features')
-rw-r--r--src/main/kotlin/com/ambientaddons/features/dungeon/AutoBuyChest.kt54
-rw-r--r--src/main/kotlin/com/ambientaddons/features/dungeon/CancelInteractions.kt20
-rw-r--r--src/main/kotlin/com/ambientaddons/features/dungeon/CloseChest.kt21
3 files changed, 80 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
}
diff --git a/src/main/kotlin/com/ambientaddons/features/dungeon/CancelInteractions.kt b/src/main/kotlin/com/ambientaddons/features/dungeon/CancelInteractions.kt
new file mode 100644
index 0000000..94626f8
--- /dev/null
+++ b/src/main/kotlin/com/ambientaddons/features/dungeon/CancelInteractions.kt
@@ -0,0 +1,20 @@
+package com.ambientaddons.features.dungeon
+
+import AmbientAddons.Companion.config
+import AmbientAddons.Companion.mc
+import com.ambientaddons.utils.LocationUtils
+import net.minecraft.init.Blocks
+import net.minecraftforge.event.entity.player.PlayerInteractEvent
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+
+object CancelInteractions {
+ @SubscribeEvent
+ fun onPlayerInteract(event: PlayerInteractEvent) {
+ if (!config.cancelInteractions || LocationUtils.location == "Private Island") return
+ if (event.action == PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK) {
+ if (mc.theWorld?.getBlockState(event.pos)?.block == Blocks.hopper) {
+ event.isCanceled = true
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/src/main/kotlin/com/ambientaddons/features/dungeon/CloseChest.kt b/src/main/kotlin/com/ambientaddons/features/dungeon/CloseChest.kt
new file mode 100644
index 0000000..ffaab8d
--- /dev/null
+++ b/src/main/kotlin/com/ambientaddons/features/dungeon/CloseChest.kt
@@ -0,0 +1,21 @@
+package com.ambientaddons.features.dungeon
+
+import AmbientAddons.Companion.config
+import AmbientAddons.Companion.mc
+import com.ambientaddons.events.ReceivePacketEvent
+import com.ambientaddons.utils.LocationUtils
+import net.minecraft.network.play.client.C0DPacketCloseWindow
+import net.minecraft.network.play.server.S2DPacketOpenWindow
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+
+object CloseChest {
+ @SubscribeEvent
+ fun onOpenWindow(event: ReceivePacketEvent) {
+ if (!config.closeSecretChests || LocationUtils.location != "Catacombs") return
+ if (event.packet !is S2DPacketOpenWindow) return
+ if (event.packet.windowTitle.unformattedText == "Chest") {
+ mc.netHandler.networkManager.sendPacket(C0DPacketCloseWindow(event.packet.windowId))
+ event.isCanceled = true
+ }
+ }
+}