Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Custom Ah Menu Crash #452

Merged
merged 3 commits into from
Aug 4, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ class PartlySaneSkies {
.chatGUI
.printChatMessage(skyclientMessage)
val githubMessage =
ChatComponentText("§9If you are not using SkyClient, click here go to the github and download the latest version.")
ChatComponentText("§9If you are not using SkyClient, click here go to the GitHub and download the latest version.")
githubMessage.chatStyle.setChatClickEvent(
ClickEvent(
ClickEvent.Action.OPEN_URL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ import gg.essential.elementa.dsl.constraint
import gg.essential.elementa.dsl.pixels
import gg.essential.universal.UMatrixStack
import me.partlysanestudios.partlysaneskies.PartlySaneSkies
import me.partlysanestudios.partlysaneskies.features.debug.DebugKey
import me.partlysanestudios.partlysaneskies.features.themes.ThemeManager
import me.partlysanestudios.partlysaneskies.utils.ChatUtils
import me.partlysanestudios.partlysaneskies.utils.MinecraftUtils.containerInventory
import me.partlysanestudios.partlysaneskies.utils.StringUtils.removeColorCodes
import net.minecraft.client.gui.inventory.GuiChest
import net.minecraft.inventory.IInventory
import net.minecraft.item.Item
import java.awt.Color

class AuctionHouseGui(defaultAuctionInventory: IInventory) : WindowScreen(ElementaVersion.V2) {
class AuctionHouseGui(defaultAuctionInventory: IInventory) : WindowScreen(ElementaVersion.V5) {
private val heightPercent = PartlySaneSkies.config.masterAuctionHouseScale
private val sideBarHeightPercent = PartlySaneSkies.config.auctionHouseSideBarHeight
private val sideBarWidthPercent = PartlySaneSkies.config.auctionHouseSideBarWidth
Expand Down Expand Up @@ -109,8 +109,8 @@ class AuctionHouseGui(defaultAuctionInventory: IInventory) : WindowScreen(Elemen

for (row in 0 until 4) {
for (column in 0 until 6) {
val x = ((boxSide + pad) * column + pad).toFloat()
val y = ((boxSide + pad) * row + pad).toFloat()
val x = (boxSide + pad) * column + pad
val y = (boxSide + pad) * row + pad

try {
auctions[row][column]
Expand Down Expand Up @@ -179,35 +179,18 @@ class AuctionHouseGui(defaultAuctionInventory: IInventory) : WindowScreen(Elemen

companion object {
fun tick() {
if (!PartlySaneSkies.config.customAhGui) {
return
}
if (!PartlySaneSkies.config.customAhGui) return

val gui = PartlySaneSkies.minecraft.currentScreen ?: return
// ChatUtils.sendClientMessage("A gui has been opened")

if (gui !is GuiChest) {
return
}
if (gui !is GuiChest) return

if (!isAhGui(gui.containerInventory)) {
// ChatUtils.sendClientMessage("Not AH Gui")
return
}
if (!isAhGui(gui.containerInventory)) return
val guiAlreadyOpen = PartlySaneSkies.minecraft.currentScreen is AuctionHouseGui

if (guiAlreadyOpen) {
return
}

if (DebugKey.isDebugMode()) {
return
}
// val inventory = MinecraftUtils.getSeparateUpperLowerInventories(event.gui)[0]
if (guiAlreadyOpen) return

// ChatUtils.sendClientMessage("Opening menu")
val inventory = gui.containerInventory
// event.isCanceled = true
if (isAuctionHouseFullyLoaded(inventory)) {
val ahGui = AuctionHouseGui(inventory)
PartlySaneSkies.minecraft.displayGuiScreen(ahGui)
Expand All @@ -216,35 +199,39 @@ class AuctionHouseGui(defaultAuctionInventory: IInventory) : WindowScreen(Elemen
openMenu()
}

fun isAhGui(inventory: IInventory?): Boolean {
if (inventory == null) {
return true
}

if (PartlySaneSkies.minecraft.currentScreen !is GuiChest) {
return false
}
return inventory.displayName.formattedText
fun isAhGui(inventory: IInventory): Boolean = inventory.displayName.formattedText
.removeColorCodes()
.contains("Auctions Browser") ||
inventory.displayName.formattedText
.removeColorCodes()
.contains("Auctions: \"")
}

private fun openMenu(): AuctionHouseGui {
var inventory = (PartlySaneSkies.minecraft.currentScreen as GuiChest).containerInventory
private fun openMenu(): AuctionHouseGui? {
var attempts = 0
val maxAttempts = 5
j10a1n15 marked this conversation as resolved.
Show resolved Hide resolved

return if (isAuctionHouseFullyLoaded(inventory)) {
inventory = (PartlySaneSkies.minecraft.currentScreen as GuiChest).containerInventory
AuctionHouseGui(inventory)
} else {
openMenu()
while (attempts < maxAttempts) {
val gui = PartlySaneSkies.minecraft.currentScreen
if (gui is GuiChest) {
val inventory = gui.containerInventory
if (isAuctionHouseFullyLoaded(inventory)) {
return AuctionHouseGui(inventory)
}
}
attempts++
try {
Thread.sleep(100)
} catch (e: InterruptedException) {
e.printStackTrace()
}
}

ChatUtils.sendClientMessage("§cUnable to open Auction House menu after $maxAttempts attempts")
return null
}


private fun isAuctionHouseFullyLoaded(inventory: IInventory): Boolean {
// ChatUtils.sendClientMessage("Checking if is loaded")
for (i in 0..53) {
if (convertSlotToChestCoordinate(i)[0] <= 2 ||
convertSlotToChestCoordinate(i)[0] == 9 ||
Expand All @@ -258,13 +245,11 @@ class AuctionHouseGui(defaultAuctionInventory: IInventory) : WindowScreen(Elemen
// Then Return false
if (inventory.getStackInSlot(i) == null) {
if (inventory.getStackInSlot(53) == null) {
// ChatUtils.sendClientMessage("Slot $i is broken")

return false
} else if (Item.getIdFromItem(inventory.getStackInSlot(53).item) != 264) {
continue
}
// ChatUtils.sendClientMessage("Slot $i is broken")
return false
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ class PSSMainMenu : WindowScreen(ElementaVersion.V5) {
try {
val factInfo = JsonParser().parse(request.getResponse()).getAsJsonObject()
val fact = factInfo["funFact"].asString
log("Response: $factInfo")
log("Fun Fact: $fact")

cachedFunFact = FunFact("Fact of the Day", fact)
Expand Down
Loading