diff options
author | Appability <appable@icloud.com> | 2022-10-12 01:13:04 -0700 |
---|---|---|
committer | Appability <appable@icloud.com> | 2022-10-12 01:13:04 -0700 |
commit | 42fb54e0eaedc44d22a8c86fc539e46c68af3dab (patch) | |
tree | 1f9b10d705cfee23954777f49afa9f5a58060dd8 /src | |
parent | 2c0e73deb53f54d78bd5594786313ac82151be1a (diff) | |
download | AmbientAddons-42fb54e0eaedc44d22a8c86fc539e46c68af3dab.tar.gz AmbientAddons-42fb54e0eaedc44d22a8c86fc539e46c68af3dab.tar.bz2 AmbientAddons-42fb54e0eaedc44d22a8c86fc539e46c68af3dab.zip |
fix chestqol free chest features, + cancelinteractions and closechest from floppa
Diffstat (limited to 'src')
8 files changed, 109 insertions, 26 deletions
diff --git a/src/main/kotlin/com/ambientaddons/AmbientAddons.kt b/src/main/kotlin/com/ambientaddons/AmbientAddons.kt index bf8e503..08cd271 100644 --- a/src/main/kotlin/com/ambientaddons/AmbientAddons.kt +++ b/src/main/kotlin/com/ambientaddons/AmbientAddons.kt @@ -2,6 +2,8 @@ import com.ambientaddons.commands.AmbientCommand import com.ambientaddons.config.Config import com.ambientaddons.config.PersistentData import com.ambientaddons.features.dungeon.AutoBuyChest +import com.ambientaddons.features.dungeon.CancelInteractions +import com.ambientaddons.features.dungeon.CloseChest import com.ambientaddons.utils.LocationUtils import net.minecraft.client.Minecraft import net.minecraft.client.gui.GuiScreen @@ -31,17 +33,18 @@ class AmbientAddons { directory.mkdirs() configDirectory = directory persistentData = PersistentData.load() - config = Config + config = Config.apply { this.initialize() } } @Mod.EventHandler fun onInit(event: FMLInitializationEvent) { ClientCommandHandler.instance.registerCommand(AmbientCommand()) - listOf( this, LocationUtils, - AutoBuyChest + AutoBuyChest, + CloseChest, + CancelInteractions ).forEach(MinecraftForge.EVENT_BUS::register) } diff --git a/src/main/kotlin/com/ambientaddons/commands/AutoBuyCommand.kt b/src/main/kotlin/com/ambientaddons/commands/AutoBuyCommand.kt index c7ff9a7..538485c 100644 --- a/src/main/kotlin/com/ambientaddons/commands/AutoBuyCommand.kt +++ b/src/main/kotlin/com/ambientaddons/commands/AutoBuyCommand.kt @@ -19,8 +19,8 @@ object AutoBuyCommand { if (persistentData.autoBuyItems.contains(item)) { persistentData.autoBuyItems.remove(item) persistentData.save() - UChat.chat("§aRemoved item §a§l$item.".withModPrefix()) - } else UChat.chat("§cItem §a§l$item does not exist!".withModPrefix()) + UChat.chat("§aRemoved item §a§l$item§a.".withModPrefix()) + } else UChat.chat("§cItem §c§l$item §cdoes not exist!".withModPrefix()) } "list" -> { UChat.chat("§2§lItems".withModPrefix()) diff --git a/src/main/kotlin/com/ambientaddons/config/Config.kt b/src/main/kotlin/com/ambientaddons/config/Config.kt index b283abb..19a11a6 100644 --- a/src/main/kotlin/com/ambientaddons/config/Config.kt +++ b/src/main/kotlin/com/ambientaddons/config/Config.kt @@ -12,8 +12,11 @@ object Config : Vigilant( var blockLowReroll = false var autoBuyChest = 0 + var cancelInteractions = false + var closeSecretChests = false + init { - category("Pre/Post Dungeon") { + category("Pre/Post Dungeon") { subcategory("Chest QOL") { switch ( ::blockLowReroll, @@ -27,10 +30,21 @@ object Config : Vigilant( options = listOf("Off", "Block Reroll", "Autobuy") ) } + } + category("Dungeon") { + subcategory("Miscellaneous QOL") { + switch( + ::cancelInteractions, + name = "Cancel block interactions", + description = "Cancels interactions with hoppers that prevent using item abilities." + ) + switch( + ::closeSecretChests, + name = "Block opening secret chests", + description = "Cancels opening chests containing secrets." + ) + } } } - - - }
\ No newline at end of file diff --git a/src/main/kotlin/com/ambientaddons/events/ReceivePacketEvent.kt b/src/main/kotlin/com/ambientaddons/events/ReceivePacketEvent.kt index d69fefe..9fbaf8e 100644 --- a/src/main/kotlin/com/ambientaddons/events/ReceivePacketEvent.kt +++ b/src/main/kotlin/com/ambientaddons/events/ReceivePacketEvent.kt @@ -6,4 +6,4 @@ import net.minecraftforge.fml.common.eventhandler.Event // credit Harry282/Skyblock-Client, under AGPL 3.0 @Cancelable -class ReceivePacketEvent(packet: Packet<*>) : Event()
\ No newline at end of file +class ReceivePacketEvent(val packet: Packet<*>) : Event()
\ No newline at end of file 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 + } + } +} diff --git a/src/main/kotlin/com/ambientaddons/utils/DungeonFloor.kt b/src/main/kotlin/com/ambientaddons/utils/DungeonFloor.kt index a64fed0..ab11d7f 100644 --- a/src/main/kotlin/com/ambientaddons/utils/DungeonFloor.kt +++ b/src/main/kotlin/com/ambientaddons/utils/DungeonFloor.kt @@ -25,8 +25,9 @@ data class DungeonFloor( } } } + + enum class Mode { Normal, Master } } -enum class Mode { Normal, Master } |