Skip to content

Commit

Permalink
fix: Instantiation error
Browse files Browse the repository at this point in the history
Forge creates an instance of the event for static variable wizardry. This means we cannot listen to an abstract event.
  • Loading branch information
My-Name-Is-Jeff committed Feb 13, 2025
1 parent 4afb44d commit 39356fb
Showing 1 changed file with 54 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,66 +53,66 @@ object QuadLinkLegacySolver {
}

@SubscribeEvent
fun onGuiContainerEvent(event: GuiContainerEvent) {
when (event) {
is GuiContainerEvent.CloseWindowEvent -> reset()
is GuiContainerEvent.ForegroundDrawnEvent -> {
if (!Skytils.config.quadLinkLegacySolver) return
val container = event.container as? ContainerChest ?: return
if (event.chestName != guiTitle) return

if (ourItem == null) {
ourItem = container.getSlot(ourSlot).stack
oppItem = container.getSlot(oppSlot).stack

check(ourItem != null && oppItem != null) { "Our item or opponent's item is null" }
}
fun onCloseWindow(event: GuiContainerEvent.CloseWindowEvent) {
reset()
}

// if null, it means the placing animation is happening
// if painting, it means we are waiting for the move
// if item stack, it means they are waiting for us
// if there is glass, the game is over
if (flatBoardSlots.map { container.getSlot(it).stack }.any {
it == null ||
it.item == Items.painting ||
it.item == Item.getItemFromBlock(Blocks.stained_glass) ||
!(it.getIsItemStackEqual(ourItem) || it.getIsItemStackEqual(oppItem) || it.item == Items.item_frame)
}) {
bestColumn = -1
return
}
@SubscribeEvent
fun onGuiContainerDrawEvent(event: GuiContainerEvent.ForegroundDrawnEvent) {
if (!Skytils.config.quadLinkLegacySolver) return
val container = event.container as? ContainerChest ?: return
if (event.chestName != guiTitle) return

if (bestColumn == -1) {
// read the board in
for (column in 0 until 7) {
for (row in 0 until 6) {
val slot = boardSlots[row].elementAt(column)
val item = container.getSlot(slot).stack
if (item.getIsItemStackEqual(ourItem)) {
board[column][row] = true
} else if (item.getIsItemStackEqual(oppItem)) {
board[column][row] = false
} else if (item.item == Items.item_frame) {
board[column][row] = null
}
}
}
if (ourItem == null) {
ourItem = container.getSlot(ourSlot).stack
oppItem = container.getSlot(oppSlot).stack

val result = negamax(1000, isOurs = true)
bestColumn = result.first
}
check(ourItem != null && oppItem != null) { "Our item or opponent's item is null" }
}

// if null, it means the placing animation is happening
// if painting, it means we are waiting for the move
// if item stack, it means they are waiting for us
// if there is glass, the game is over
if (flatBoardSlots.map { container.getSlot(it).stack }.any {
it == null ||
it.item == Items.painting ||
it.item == Item.getItemFromBlock(Blocks.stained_glass) ||
!(it.getIsItemStackEqual(ourItem) || it.getIsItemStackEqual(oppItem) || it.item == Items.item_frame)
}) {
bestColumn = -1
return
}

if (bestColumn != -1) {
val topSlot = container.getSlot(bestColumn+1)
Gui.drawRect(
topSlot.xDisplayPosition,
topSlot.yDisplayPosition,
topSlot.xDisplayPosition + 16,
topSlot.yDisplayPosition + 16 * 6,
Color.RED.withAlpha(100)
)
if (bestColumn == -1) {
// read the board in
for (column in 0 until 7) {
for (row in 0 until 6) {
val slot = boardSlots[row].elementAt(column)
val item = container.getSlot(slot).stack
if (item.getIsItemStackEqual(ourItem)) {
board[column][row] = true
} else if (item.getIsItemStackEqual(oppItem)) {
board[column][row] = false
} else if (item.item == Items.item_frame) {
board[column][row] = null
}
}
}

val result = negamax(1000, isOurs = true)
bestColumn = result.first
}

if (bestColumn != -1) {
val topSlot = container.getSlot(bestColumn + 1)
Gui.drawRect(
topSlot.xDisplayPosition,
topSlot.yDisplayPosition,
topSlot.xDisplayPosition + 16,
topSlot.yDisplayPosition + 16 * 6,
Color.RED.withAlpha(100)
)
}
}

Expand Down

0 comments on commit 39356fb

Please sign in to comment.