diff --git a/src/main/kotlin/gg/skytils/skytilsmod/core/Config.kt b/src/main/kotlin/gg/skytils/skytilsmod/core/Config.kt index 2ff918878..505784c25 100644 --- a/src/main/kotlin/gg/skytils/skytilsmod/core/Config.kt +++ b/src/main/kotlin/gg/skytils/skytilsmod/core/Config.kt @@ -909,6 +909,13 @@ object Config : Vigilant( ) var tankRadiusDisplayColor = Color(100, 255, 0, 50) + @Property( + type = PropertyType.SWITCH, name = "Block Incorrect Terminal Clicks", + description = "Blocks incorrect clicks on terminals.", + category = "Dungeons", subcategory = "Terminal Solvers" + ) + var blockIncorrectTerminalClicks = false + @Property( type = PropertyType.SWITCH, name = "Middle Click on Terminals", description = "Replaces left clicks while on terminals with middle clicks.", diff --git a/src/main/kotlin/gg/skytils/skytilsmod/features/impl/dungeons/solvers/terminals/ChangeAllToSameColorSolver.kt b/src/main/kotlin/gg/skytils/skytilsmod/features/impl/dungeons/solvers/terminals/ChangeAllToSameColorSolver.kt index 40ee309da..90f416741 100644 --- a/src/main/kotlin/gg/skytils/skytilsmod/features/impl/dungeons/solvers/terminals/ChangeAllToSameColorSolver.kt +++ b/src/main/kotlin/gg/skytils/skytilsmod/features/impl/dungeons/solvers/terminals/ChangeAllToSameColorSolver.kt @@ -35,7 +35,8 @@ import kotlin.random.Random object ChangeAllToSameColorSolver { private val ordering = - setOf(EnumDyeColor.RED, + setOf( + EnumDyeColor.RED, EnumDyeColor.ORANGE, EnumDyeColor.YELLOW, EnumDyeColor.GREEN, @@ -43,6 +44,7 @@ object ChangeAllToSameColorSolver { ).withIndex().associate { (i, c) -> c.metadata to i } + private var targetIndex = -1 @SubscribeEvent fun onBackgroundDrawn(event: GuiContainerEvent.BackgroundDrawnEvent) { @@ -50,8 +52,9 @@ object ChangeAllToSameColorSolver { val grid = event.container.inventorySlots.filter { it.inventory == event.container.lowerChestInventory && it.stack?.displayName?.startsWith("§a") == true } - val mostCommon = ordering.keys.maxByOrNull { c -> grid.count { it.stack?.metadata == c } } ?: EnumDyeColor.RED.metadata - val targetIndex = ordering[mostCommon]!! + val mostCommon = + ordering.keys.maxByOrNull { c -> grid.count { it.stack?.metadata == c } } ?: EnumDyeColor.RED.metadata + targetIndex = ordering[mostCommon]!! val mapping = grid.filter { it.stack.metadata != mostCommon }.associateWith { slot -> val stack = slot.stack val myIndex = ordering[stack.metadata]!! @@ -91,6 +94,14 @@ object ChangeAllToSameColorSolver { GlStateManager.translate(0f, 0f, -299f) } + @SubscribeEvent(priority = EventPriority.HIGH) + fun onSlotClick(event: GuiContainerEvent.SlotClickEvent) { + if (!Utils.inDungeons || !Skytils.config.changeAllSameColorTerminalSolver || !Skytils.config.blockIncorrectTerminalClicks) return + if (event.container is ContainerChest && event.chestName == "Change all to same color!") { + if (event.slot?.stack?.metadata == targetIndex) event.isCanceled = true + } + } + @SubscribeEvent(priority = EventPriority.LOWEST) fun onTooltip(event: ItemTooltipEvent) { if (!Utils.inDungeons) return diff --git a/src/main/kotlin/gg/skytils/skytilsmod/features/impl/dungeons/solvers/terminals/SelectAllColorSolver.kt b/src/main/kotlin/gg/skytils/skytilsmod/features/impl/dungeons/solvers/terminals/SelectAllColorSolver.kt index 98d286317..10c5e05b7 100644 --- a/src/main/kotlin/gg/skytils/skytilsmod/features/impl/dungeons/solvers/terminals/SelectAllColorSolver.kt +++ b/src/main/kotlin/gg/skytils/skytilsmod/features/impl/dungeons/solvers/terminals/SelectAllColorSolver.kt @@ -32,8 +32,11 @@ import kotlin.random.Random object SelectAllColorSolver { @JvmField - val shouldClick = ArrayList() + val shouldClick = hashSetOf() private var colorNeeded: String? = null + private val colors by lazy { + EnumDyeColor.entries.associateWith { it.getName().replace("_", " ").uppercase() } + } @SubscribeEvent fun onBackgroundDrawn(event: GuiContainerEvent.BackgroundDrawnEvent) { @@ -41,9 +44,9 @@ object SelectAllColorSolver { "Select all the" ) ) { - val promptColor = EnumDyeColor.entries.find { - event.chestName.contains(it.getName().replace("_", " ").uppercase()) - }?.unlocalizedName + val promptColor = colors.entries.find { (_, name) -> + event.chestName.contains(name) + }?.key?.unlocalizedName if (promptColor != colorNeeded) { colorNeeded = promptColor shouldClick.clear() @@ -79,13 +82,21 @@ object SelectAllColorSolver { if (event.container is ContainerChest) { if (event.chestName.startsWith("Select all the")) { val slot = event.slot - if (shouldClick.size > 0 && !shouldClick.contains(slot.slotNumber) && slot.inventory !== mc.thePlayer.inventory) { + if (shouldClick.isNotEmpty() && slot.slotNumber !in shouldClick && slot.inventory !== mc.thePlayer.inventory) { event.isCanceled = true } } } } + @SubscribeEvent(priority = EventPriority.HIGH) + fun onSlotClick(event: GuiContainerEvent.SlotClickEvent) { + if (!Utils.inDungeons || !Skytils.config.selectAllColorTerminalSolver || !Skytils.config.blockIncorrectTerminalClicks) return + if (event.container is ContainerChest && event.chestName.startsWith("Select all the")) { + if (shouldClick.isNotEmpty() && !shouldClick.contains(event.slotId)) event.isCanceled = true + } + } + @SubscribeEvent(priority = EventPriority.LOWEST) fun onTooltip(event: ItemTooltipEvent) { if (event.toolTip == null || !Utils.inDungeons || !Skytils.config.selectAllColorTerminalSolver) return diff --git a/src/main/kotlin/gg/skytils/skytilsmod/features/impl/dungeons/solvers/terminals/StartsWithSequenceSolver.kt b/src/main/kotlin/gg/skytils/skytilsmod/features/impl/dungeons/solvers/terminals/StartsWithSequenceSolver.kt index 5e58ec4d5..aae78b613 100644 --- a/src/main/kotlin/gg/skytils/skytilsmod/features/impl/dungeons/solvers/terminals/StartsWithSequenceSolver.kt +++ b/src/main/kotlin/gg/skytils/skytilsmod/features/impl/dungeons/solvers/terminals/StartsWithSequenceSolver.kt @@ -33,37 +33,37 @@ object StartsWithSequenceSolver { @JvmField - val shouldClick = mutableListOf() + val shouldClick = hashSetOf() private var sequenceNeeded: String? = null private val titlePattern = Regex("^What starts with: ['\"](.+)['\"]\\?$") @SubscribeEvent fun onBackgroundDrawn(event: GuiContainerEvent.BackgroundDrawnEvent) { - if (Utils.inDungeons && Skytils.config.startsWithSequenceTerminalSolver && event.container is ContainerChest) { - titlePattern.find(event.chestName)?.also { - val sequence = it.groupValues[1] - if (sequence != sequenceNeeded) { - sequenceNeeded = sequence - shouldClick.clear() - } else if (shouldClick.size == 0) { - for (slot in event.container.inventorySlots) { - if (slot.inventory === mc.thePlayer?.inventory || !slot.hasStack) continue - val item = slot.stack ?: continue - if (item.isItemEnchanted) continue - if (slot.slotNumber < 9 || slot.slotNumber > 44 || slot.slotNumber % 9 == 0 || slot.slotNumber % 9 == 8) continue - if (SuperSecretSettings.bennettArthur) { - if (Random.nextInt(3) == 0) shouldClick.add(slot.slotNumber) - } else if (item.displayName.stripControlCodes().startsWith(sequenceNeeded!!)) { - shouldClick.add(slot.slotNumber) - } - } - } else { - shouldClick.removeIf { - val slot = event.container.getSlot(it) - return@removeIf slot.hasStack && slot.stack.isItemEnchanted + if (Utils.inDungeons && Skytils.config.startsWithSequenceTerminalSolver && event.container is ContainerChest && event.chestName.startsWith( + "What starts with:" + ) + ) { + val sequence = titlePattern.find(event.chestName)?.groupValues?.get(1) ?: return + if (sequence != sequenceNeeded) { + sequenceNeeded = sequence + shouldClick.clear() + } else if (shouldClick.size == 0) { + for (slot in event.container.inventorySlots) { + if (slot.inventory === mc.thePlayer?.inventory || !slot.hasStack) continue + val item = slot.stack ?: continue + if (item.isItemEnchanted) continue + if (slot.slotNumber < 9 || slot.slotNumber > 44 || slot.slotNumber % 9 == 0 || slot.slotNumber % 9 == 8) continue + if (SuperSecretSettings.bennettArthur) { + if (Random.nextInt(3) == 0) shouldClick.add(slot.slotNumber) + } else if (item.displayName.stripControlCodes().startsWith(sequenceNeeded!!)) { + shouldClick.add(slot.slotNumber) } } - return + } else { + shouldClick.removeIf { + val slot = event.container.getSlot(it) + return@removeIf slot.hasStack && slot.stack.isItemEnchanted + } } } else { shouldClick.clear() @@ -74,16 +74,22 @@ object StartsWithSequenceSolver { @SubscribeEvent fun onDrawSlot(event: GuiContainerEvent.DrawSlotEvent.Pre) { if (!Utils.inDungeons || !Skytils.config.startsWithSequenceTerminalSolver) return - if (event.container is ContainerChest) { + if (event.container is ContainerChest && event.chestName.startsWith("What starts with:")) { val slot = event.slot - if (event.chestName.startsWith("What starts with:")) { - if (shouldClick.size > 0 && !shouldClick.contains(slot.slotNumber) && slot.inventory !== mc.thePlayer.inventory) { - event.isCanceled = true - } + if (shouldClick.size > 0 && !shouldClick.contains(slot.slotNumber) && slot.inventory !== mc.thePlayer.inventory) { + event.isCanceled = true } } } + @SubscribeEvent(priority = EventPriority.HIGH) + fun onSlotClick(event: GuiContainerEvent.SlotClickEvent) { + if (!Utils.inDungeons || !Skytils.config.startsWithSequenceTerminalSolver || !Skytils.config.blockIncorrectTerminalClicks) return + if (event.container is ContainerChest && event.chestName.startsWith("What starts with:")) { + if (shouldClick.isNotEmpty() && !shouldClick.contains(event.slotId)) event.isCanceled = true + } + } + @SubscribeEvent(priority = EventPriority.LOWEST) fun onTooltip(event: ItemTooltipEvent) { if (event.toolTip == null || !Utils.inDungeons || !Skytils.config.startsWithSequenceTerminalSolver) return diff --git a/src/main/kotlin/gg/skytils/skytilsmod/features/impl/dungeons/solvers/terminals/TerminalFeatures.kt b/src/main/kotlin/gg/skytils/skytilsmod/features/impl/dungeons/solvers/terminals/TerminalFeatures.kt index 4bed1f1a5..2b2574e59 100644 --- a/src/main/kotlin/gg/skytils/skytilsmod/features/impl/dungeons/solvers/terminals/TerminalFeatures.kt +++ b/src/main/kotlin/gg/skytils/skytilsmod/features/impl/dungeons/solvers/terminals/TerminalFeatures.kt @@ -22,12 +22,24 @@ import gg.skytils.skytilsmod.Skytils.Companion.mc import gg.skytils.skytilsmod.events.impl.GuiContainerEvent.SlotClickEvent import gg.skytils.skytilsmod.utils.Utils import gg.skytils.skytilsmod.utils.startsWithAny +import gg.skytils.skytilsmod.utils.stripControlCodes import net.minecraft.inventory.ContainerChest import net.minecraftforge.event.entity.player.ItemTooltipEvent import net.minecraftforge.fml.common.eventhandler.EventPriority import net.minecraftforge.fml.common.eventhandler.SubscribeEvent object TerminalFeatures { + + @SubscribeEvent + fun onSlotClickHigh(event: SlotClickEvent) { + if (!Utils.inDungeons || !Skytils.config.blockIncorrectTerminalClicks || event.container !is ContainerChest) return + if (event.chestName == "Correct all the panes!") { + if (event.slot?.stack?.displayName?.stripControlCodes()?.startsWith("Off") == true) { + event.isCanceled = true + } + } + } + @SubscribeEvent fun onSlotClick(event: SlotClickEvent) { if (!Utils.inDungeons) return