Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
odtheking committed Dec 30, 2024
1 parent b9404ed commit 7a4f3e0
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,6 @@ object TerminalSolver : Module(
var lastTermOpened = Terminal(TerminalTypes.NONE)
private var lastRubixSolution: Int? = null

fun canClick(slotIndex: Int, button: Int, needed: Int = currentTerm.solution.count { it == slotIndex }): Boolean = when {
slotIndex !in currentTerm.solution -> false
currentTerm.type == TerminalTypes.ORDER && slotIndex != currentTerm.solution.firstOrNull() -> false
currentTerm.type == TerminalTypes.RUBIX && ((needed < 3 && button != 0) || (needed >= 3 && button != 1)) -> false
else -> true
}

init {
onPacket(S2DPacketOpenWindow::class.java) { packet ->
val windowName = packet.windowTitle?.formattedText?.noControlCodes ?: return@onPacket
Expand Down Expand Up @@ -242,7 +235,7 @@ object TerminalSolver : Module(
}
}
currentTerm.type == TerminalTypes.ORDER -> {
val index = if (currentTerm.clickedSlot?.second?.let { System.currentTimeMillis() - it < 600} == true && hideClicked) currentTerm.solution.indexOf(event.slot.slotIndex) -1 else currentTerm.solution.indexOf(event.slot.slotIndex)
val index = currentTerm.solution.indexOf(event.slot.slotIndex) + if (currentTerm.clickedSlot?.second?.let { System.currentTimeMillis() - it < 600 } == true && hideClicked) -1 else 0
if (index != -1) {
if (index < 3) {
val color = when (index) {
Expand All @@ -267,7 +260,6 @@ object TerminalSolver : Module(
}.rgba
Gui.drawRect(event.x, event.y, event.x + 16, event.y + 16, colorMelody)
}

}
GlStateManager.enableLighting()
translate(0f, 0f, -zLevel)
Expand Down Expand Up @@ -295,7 +287,7 @@ object TerminalSolver : Module(
event.isCanceled = true
return
}
if (currentTerm.clickedSlot?.second?.let { System.currentTimeMillis() - it < 600} != true) currentTerm.clickedSlot = slotIndex to System.currentTimeMillis()
if (currentTerm.clickedSlot?.second?.let { System.currentTimeMillis() - it < 600 } != true) currentTerm.clickedSlot = slotIndex to System.currentTimeMillis()
}

if (middleClickGUI) {
Expand All @@ -322,9 +314,7 @@ object TerminalSolver : Module(

init {
onMessage(terminalActivatedRegex) { message ->
if (terminalActivatedRegex.find(message)?.groupValues?.get(1) == mc.thePlayer.name) {
TerminalEvent.Solved(lastTermOpened).postAndCatch()
}
if (terminalActivatedRegex.find(message)?.groupValues?.get(1) == mc.thePlayer.name) TerminalEvent.Solved(lastTermOpened).postAndCatch()
}
}

Expand All @@ -335,6 +325,13 @@ object TerminalSolver : Module(
currentTerm = Terminal(TerminalTypes.NONE)
}

fun canClick(slotIndex: Int, button: Int, needed: Int = currentTerm.solution.count { it == slotIndex }): Boolean = when {
slotIndex !in currentTerm.solution -> false
currentTerm.type == TerminalTypes.ORDER && slotIndex != currentTerm.solution.firstOrNull() -> false
currentTerm.type == TerminalTypes.RUBIX && ((needed < 3 && button != 0) || (needed >= 3 && button != 1)) -> false
else -> true
}

private val colorOrder = listOf(1, 4, 13, 11, 14)
private fun solveColor(items: Array<ItemStack?>): List<Int> {
val panes = items.mapNotNull { item -> if (item?.metadata != 15 && Item.getIdFromItem(item?.item) == 160) item else null }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import me.odinmain.utils.render.scale
import me.odinmain.utils.render.translate
import me.odinmain.utils.skyblock.ClickType
import me.odinmain.utils.skyblock.PlayerUtils.windowClick
import me.odinmain.utils.skyblock.modMessage
import net.minecraft.client.gui.ScaledResolution

object CustomTermGui {
Expand All @@ -35,10 +34,8 @@ abstract class TermGui {

fun mouseClicked(x: Int, y: Int, button: Int) {
itemIndexMap.entries.find { it.value.isPointWithin(x, y) }?.let { (slot, _) ->
if (System.currentTimeMillis() - currentTerm.timeOpened < 300) return
if (!canClick(slot , button)) return
if (GuiEvent.CustomTermGuiClick(slot , if (button == 0) 3 else 0, button).postAndCatch()) return
if (currentTerm.clickedSlot?.second?.let { System.currentTimeMillis() - it < 600} != true) currentTerm.clickedSlot = slot to System.currentTimeMillis()
if (System.currentTimeMillis() - currentTerm.timeOpened < 300 || !canClick(slot, button) || (GuiEvent.CustomTermGuiClick(slot, if (button == 0) 3 else 0, button).postAndCatch())) return
if (currentTerm.clickedSlot?.second?.let { System.currentTimeMillis() - it < 600 } != true) currentTerm.clickedSlot = slot to System.currentTimeMillis()
windowClick(slot, if (button == 1) ClickType.Right else ClickType.Middle, true)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ object OrderGui : TermGui() {
currentTerm.solution.forEach { pane ->
val row = pane / 9 - 1
val col = pane % 9 - 2
val slot = mc.thePlayer.openContainer.inventorySlots[pane]
val amount = slot?.stack?.stackSize ?: return@forEach
val index = if (currentTerm.clickedSlot?.second?.let { System.currentTimeMillis() - it < 600 } == true && hideClicked) currentTerm.solution.indexOf(slot.slotIndex) -1 else currentTerm.solution.indexOf(slot.slotIndex)
val amount = currentTerm.items[pane]?.stackSize ?: return@forEach
val index = if (currentTerm.clickedSlot?.second?.let { System.currentTimeMillis() - it < 600 } == true && hideClicked) currentTerm.solution.indexOf(pane) -1 else currentTerm.solution.indexOf(pane)
if (index > -1 && index < 3) {
val color = when (index) {
0 -> orderColor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ object PanesGui : TermGui() {
roundedRectangle(-getTextWidth("Correct All the Panes", 20f) / 2, -110, getTextWidth("Correct All the Panes", 20f), 3, Color.WHITE, radius = 5f)
}
currentTerm.solution.forEach { pane ->
if (hideClicked) {
val slot = mc.thePlayer?.inventoryContainer?.inventorySlots?.get(pane) ?: return@forEach
if (slot.slotIndex == currentTerm.clickedSlot?.first && currentTerm.clickedSlot?.second?.let { System.currentTimeMillis() - it < 600 } == true) return@forEach
}
if (hideClicked && pane == currentTerm.clickedSlot?.first && currentTerm.clickedSlot?.second?.let { System.currentTimeMillis() - it < 600 } == true) return@forEach
val row = pane / 9 - 1
val col = pane % 9 - 2
val box = BoxWithClass((-168 + ((gap - 20).unaryPlus() * 0.5)) + col * 70, -85 + row * 70, 70 - gap, 70 - gap)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@ object RubixGui : TermGui() {
roundedRectangle(-getTextWidth("Change all to same color!", 20f) / 2, -135, getTextWidth("Change all to same color!", 20f), 3, Color.WHITE, radius = 5f)
}
currentTerm.solution.toSet().forEach { pane ->
val slot = mc.thePlayer?.inventoryContainer?.inventorySlots?.get(pane) ?: return@forEach

val needed = currentTerm.solution.count {it == slot.slotIndex}
val adjusted = if (slot.slotIndex == currentTerm.clickedSlot?.first && currentTerm.clickedSlot?.second?.let { System.currentTimeMillis() - it < 600 } == true && hideClicked) when (needed) {
val needed = currentTerm.solution.count { it == pane }
val adjusted = if (pane == currentTerm.clickedSlot?.first && currentTerm.clickedSlot?.second?.let { System.currentTimeMillis() - it < 600 } == true && hideClicked) when (needed) {
3 -> 4
4 -> 0
else -> needed - 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ object SelectAllGui : TermGui() {
roundedRectangle(-getTextWidth("Select All the \"*\" Items!", 20f) / 2, -135, getTextWidth("Select All the \"*\" Items!", 20f), 3, Color.WHITE, radius = 5f)
}
currentTerm.solution.forEach { pane ->
if (hideClicked) {
val slot = mc.thePlayer?.inventoryContainer?.inventorySlots?.get(pane) ?: return@forEach
if (slot.slotIndex == currentTerm.clickedSlot?.first && currentTerm.clickedSlot?.second?.let { System.currentTimeMillis() - it < 600 } == true) return@forEach
}
if (hideClicked && pane == currentTerm.clickedSlot?.first && currentTerm.clickedSlot?.second?.let { System.currentTimeMillis() - it < 600 } == true) return@forEach
val row = pane / 9 - 1
val col = pane % 9 - 2
val box = BoxWithClass((-168 + ((gap -20).unaryPlus() * 0.5)) + col * 70, -115 + row * 70, 70 - gap, 70 - gap)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ object StartsWithGui : TermGui() {
roundedRectangle(-getTextWidth("What Starts With \"*\"?", 20f) / 2, -135, getTextWidth("What Starts With \"*\"?", 20f), 3, Color.WHITE, radius = 5f)
}
currentTerm.solution.forEach { pane ->
if (hideClicked) {
val slot = mc.thePlayer?.inventoryContainer?.inventorySlots?.get(pane) ?: return@forEach
if (slot.slotIndex == currentTerm.clickedSlot?.first && currentTerm.clickedSlot?.second?.let { System.currentTimeMillis() - it < 600 } == true) return@forEach
}
if (hideClicked && pane == currentTerm.clickedSlot?.first && currentTerm.clickedSlot?.second?.let { System.currentTimeMillis() - it < 600 } == true) return@forEach
val row = pane / 9 - 1
val col = pane % 9 - 2
val box = BoxWithClass((-168 + ((gap -20).unaryPlus() * 0.5)) + col * 70, -115 + row * 70, 70 - gap, 70 - gap)
Expand Down

0 comments on commit 7a4f3e0

Please sign in to comment.