Skip to content

Commit

Permalink
feat: re-add block incorrect terminal clicks
Browse files Browse the repository at this point in the history
missing new terminals
  • Loading branch information
My-Name-Is-Jeff committed Jan 17, 2024
1 parent 59617da commit 95ebab6
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 37 deletions.
7 changes: 7 additions & 0 deletions src/main/kotlin/gg/skytils/skytilsmod/core/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,26 @@ import kotlin.random.Random

object ChangeAllToSameColorSolver {
private val ordering =
setOf(EnumDyeColor.RED,
setOf(
EnumDyeColor.RED,
EnumDyeColor.ORANGE,
EnumDyeColor.YELLOW,
EnumDyeColor.GREEN,
EnumDyeColor.BLUE
).withIndex().associate { (i, c) ->
c.metadata to i
}
private var targetIndex = -1

@SubscribeEvent
fun onBackgroundDrawn(event: GuiContainerEvent.BackgroundDrawnEvent) {
if (!Utils.inDungeons || !Skytils.config.changeAllSameColorTerminalSolver || event.container !is ContainerChest || event.chestName != "Change all to same color!") return
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]!!
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,21 @@ import kotlin.random.Random
object SelectAllColorSolver {

@JvmField
val shouldClick = ArrayList<Int>()
val shouldClick = hashSetOf<Int>()
private var colorNeeded: String? = null
private val colors by lazy {
EnumDyeColor.entries.associateWith { it.getName().replace("_", " ").uppercase() }
}

@SubscribeEvent
fun onBackgroundDrawn(event: GuiContainerEvent.BackgroundDrawnEvent) {
if (Skytils.config.selectAllColorTerminalSolver && Utils.inDungeons && event.container is ContainerChest && event.chestName.startsWith(
"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()
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,37 +33,37 @@ object StartsWithSequenceSolver {


@JvmField
val shouldClick = mutableListOf<Int>()
val shouldClick = hashSetOf<Int>()
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()
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 95ebab6

Please sign in to comment.