diff options
30 files changed, 338 insertions, 169 deletions
diff --git a/.github/workflows/illegal-imports.txt b/.github/workflows/illegal-imports.txt index f53a5da78..83354f622 100644 --- a/.github/workflows/illegal-imports.txt +++ b/.github/workflows/illegal-imports.txt @@ -5,7 +5,8 @@ at/hannibal2/skyhanni/ scala. at/hannibal2/skyhanni/ jline. -at/hannibal2/skyhanni/ io.github.moulberry.notenoughupdates.util.Constants at/hannibal2/skyhanni/ io.github.moulberry.notenoughupdates.events.SlotClickEvent at/hannibal2/skyhanni/ io.github.moulberry.notenoughupdates.events.ReplaceItemEvent +at/hannibal2/skyhanni/ io.github.moulberry.notenoughupdates.util.Constants +at/hannibal2/skyhanni/ io.github.moulberry.notenoughupdates.util.Utils at/hannibal2/skyhanni/ java.util.function.Supplier diff --git a/.idea/dictionaries/default_user.xml b/.idea/dictionaries/default_user.xml index cb9130171..a0017ca5e 100644 --- a/.idea/dictionaries/default_user.xml +++ b/.idea/dictionaries/default_user.xml @@ -254,6 +254,7 @@ <w>superpairs</w> <w>tablist</w> <w>terracottas</w> + <w>tessellator</w> <w>thaumaturgist</w> <w>thaumaturgy</w> <w>townsquare</w> @@ -277,4 +278,4 @@ <w>yolkar</w> </words> </dictionary> -</component> +</component>
\ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index 447387f86..add2df4e7 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -160,9 +160,9 @@ dependencies { exclude(module = "unspecified") isTransitive = false } - // June 3, 2024, 9:30 PM AEST - // https://github.com/NotEnoughUpdates/NotEnoughUpdates/tree/2.3.0 - devenvMod("com.github.NotEnoughUpdates:NotEnoughUpdates:2.3.0:all") { + // August 27, 2024, 4:30 PM AEST + // https://github.com/NotEnoughUpdates/NotEnoughUpdates/tree/2.3.3 + devenvMod("com.github.NotEnoughUpdates:NotEnoughUpdates:2.3.3:all") { exclude(module = "unspecified") isTransitive = false } diff --git a/src/main/java/at/hannibal2/skyhanni/events/NeuRepositoryReloadEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/NeuRepositoryReloadEvent.kt index c2bd261ca..97a3f580c 100644 --- a/src/main/java/at/hannibal2/skyhanni/events/NeuRepositoryReloadEvent.kt +++ b/src/main/java/at/hannibal2/skyhanni/events/NeuRepositoryReloadEvent.kt @@ -7,6 +7,7 @@ import at.hannibal2.skyhanni.data.repo.RepoUtils import at.hannibal2.skyhanni.test.command.ErrorManager import at.hannibal2.skyhanni.utils.NEUItems.manager import at.hannibal2.skyhanni.utils.json.fromJson +import at.hannibal2.skyhanni.utils.json.getJson import com.google.gson.Gson import com.google.gson.JsonObject import com.google.gson.JsonSyntaxException @@ -15,7 +16,7 @@ import java.lang.reflect.Type class NeuRepositoryReloadEvent : LorenzEvent() { fun getConstant(file: String): JsonObject? { - return manager.getJsonFromFile(File(manager.repoLocation, "constants/$file.json")) + return File(manager.repoLocation, "constants/$file.json").getJson() } inline fun <reified T : Any> readConstant(file: String, gson: Gson = ConfigManager.gson): T { diff --git a/src/main/java/at/hannibal2/skyhanni/features/chat/ChatFilterGui.kt b/src/main/java/at/hannibal2/skyhanni/features/chat/ChatFilterGui.kt index 0fee71849..6a5f22b66 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/chat/ChatFilterGui.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/chat/ChatFilterGui.kt @@ -5,7 +5,8 @@ import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.KeyboardManager import at.hannibal2.skyhanni.utils.OSUtils import at.hannibal2.skyhanni.utils.StringUtils.stripHypixelMessage -import io.github.moulberry.notenoughupdates.util.Utils +import at.hannibal2.skyhanni.utils.renderables.Renderable +import at.hannibal2.skyhanni.utils.renderables.RenderableTooltips import io.github.notenoughupdates.moulconfig.internal.GlScissorStack import io.github.notenoughupdates.moulconfig.internal.RenderUtils import net.minecraft.client.Minecraft @@ -42,7 +43,7 @@ class ChatFilterGui(private val history: List<ChatManager.MessageFilteringResult GlStateManager.translate(l + 0.0, t + 0.0, 0.0) RenderUtils.drawFloatingRectDark(0, 0, w, h) GlStateManager.translate(5.0, 5.0 - scroll, 0.0) - var mouseX = originalMouseX - l + val mouseX = originalMouseX - l val isMouseButtonDown = mouseX in 0..w && originalMouseY in t..(t + h) && Mouse.isButtonDown(0) var mouseY = originalMouseY - (t - scroll).toInt() val sr = ScaledResolution(mc) @@ -59,7 +60,7 @@ class ChatFilterGui(private val history: List<ChatManager.MessageFilteringResult drawString( mc.fontRendererObj, "§e§lNEW TEXT", - 0, 0, -1 + 0, 0, -1, ) size += drawMultiLineText( msg.modified, @@ -86,8 +87,8 @@ class ChatFilterGui(private val history: List<ChatManager.MessageFilteringResult GlScissorStack.pop(sr) wasMouseButtonDown = isMouseButtonDown GlStateManager.popMatrix() - if (queuedTooltip != null) { - Utils.drawHoveringText(queuedTooltip, originalMouseX, originalMouseY, width, height, -1, mc.fontRendererObj) + queuedTooltip?.let { tooltip -> + RenderableTooltips.setTooltipForRender(tooltip.map { Renderable.string(it) }) } GlStateManager.color(1f, 1f, 1f, 1f) } @@ -98,7 +99,7 @@ class ChatFilterGui(private val history: List<ChatManager.MessageFilteringResult w - (ChatManager.ActionKind.maxLength + reasonMaxLength + 10 + 10), mc.fontRendererObj, false, - true + true, ) } @@ -121,7 +122,7 @@ class ChatFilterGui(private val history: List<ChatManager.MessageFilteringResult line.formattedText, xPos, 0, - -1 + -1, ) GlStateManager.translate(0F, 10F, 0F) } diff --git a/src/main/java/at/hannibal2/skyhanni/features/combat/ghostcounter/GhostCounter.kt b/src/main/java/at/hannibal2/skyhanni/features/combat/ghostcounter/GhostCounter.kt index 664acbc97..85d5778fe 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/combat/ghostcounter/GhostCounter.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/combat/ghostcounter/GhostCounter.kt @@ -56,7 +56,6 @@ import at.hannibal2.skyhanni.utils.StringUtils.removeColor import at.hannibal2.skyhanni.utils.renderables.Renderable import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern import com.google.gson.JsonPrimitive -import io.github.moulberry.notenoughupdates.util.Utils import io.github.moulberry.notenoughupdates.util.XPInformation import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import org.apache.commons.io.FilenameUtils @@ -241,7 +240,7 @@ object GhostCounter { } } - addAsSingletonList(Utils.chromaStringByColourCode(textFormatting.titleFormat.replace("&", "§"))) + addAsSingletonList(textFormatting.titleFormat.replace("&", "§")) addAsSingletonList(textFormatting.ghostKilledFormat.formatText(KILLS)) addAsSingletonList(textFormatting.sorrowsFormat.formatText(Option.SORROWCOUNT)) addAsSingletonList(textFormatting.ghostSinceSorrowFormat.formatText(Option.GHOSTSINCESORROW.getInt())) diff --git a/src/main/java/at/hannibal2/skyhanni/features/combat/ghostcounter/GhostUtil.kt b/src/main/java/at/hannibal2/skyhanni/features/combat/ghostcounter/GhostUtil.kt index 6cf777b48..d568fc492 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/combat/ghostcounter/GhostUtil.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/combat/ghostcounter/GhostUtil.kt @@ -8,7 +8,6 @@ import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators import at.hannibal2.skyhanni.utils.NumberUtil.roundToPrecision import at.hannibal2.skyhanni.utils.NumberUtil.shortFormat -import io.github.moulberry.notenoughupdates.util.Utils import java.io.FileReader object GhostUtil { @@ -71,7 +70,7 @@ object GhostUtil { } val json = ConfigManager.gson.fromJson( FileReader(GhostCounter.ghostCounterV3File), - com.google.gson.JsonObject::class.java + com.google.gson.JsonObject::class.java, ) GhostData.Option.GHOSTSINCESORROW.add(json["ghostsSinceSorrow"].asDouble) GhostData.Option.SORROWCOUNT.add(json["sorrowCount"].asDouble) @@ -91,34 +90,25 @@ object GhostUtil { fun String.formatText(option: GhostData.Option) = formatText(option.getInt(), option.getInt(true)) - fun String.formatText(value: Int, session: Int = -1) = Utils.chromaStringByColourCode( - this.replace("%value%", value.addSeparators()) - .replace("%session%", session.addSeparators()) - .replace("&", "§") - ) + fun String.formatText(value: Int, session: Int = -1) = this.replace("%value%", value.addSeparators()) + .replace("%session%", session.addSeparators()) + .replace("&", "§") - fun String.formatText(t: String) = Utils.chromaStringByColourCode(this.replace("%value%", t).replace("&", "§")) + fun String.formatText(t: String) = this.replace("%value%", t).replace("&", "§") fun String.preFormat(t: String, level: Int, nextLevel: Int) = if (nextLevel == 26) { - Utils.chromaStringByColourCode( - replace("%value%", t) - .replace("%display%", "25") - ) + replace("%value%", t).replace("%display%", "25") } else { - Utils.chromaStringByColourCode( - this.replace("%value%", t) - .replace( - "%display%", - "$level->${if (SkyHanniMod.feature.combat.ghostCounter.showMax) "25" else nextLevel}" - ) - ) + this.replace("%value%", t) + .replace( + "%display%", + "$level->${if (SkyHanniMod.feature.combat.ghostCounter.showMax) "25" else nextLevel}", + ) } - fun String.formatText(value: Double, session: Double) = Utils.chromaStringByColourCode( - this.replace("%value%", value.roundToPrecision(2).addSeparators()) - .replace("%session%", session.roundToPrecision(2).addSeparators()) - .replace("&", "§") - ) + fun String.formatText(value: Double, session: Double) = this.replace("%value%", value.roundToPrecision(2).addSeparators()) + .replace("%session%", session.roundToPrecision(2).addSeparators()) + .replace("&", "§") fun String.formatBestiary(currentKill: Int, killNeeded: Int): String { val bestiaryNextLevel = GhostCounter.storage?.bestiaryNextLevel @@ -127,17 +117,15 @@ object GhostUtil { val nextLevel = bestiaryNextLevel?.let { if (GhostCounter.config.showMax) "25" else "${it.toInt()}" } ?: "§cNo Bestiary Level data!" - return Utils.chromaStringByColourCode( - this.replace( - "%currentKill%", - if (GhostCounter.config.showMax) GhostCounter.bestiaryCurrentKill.addSeparators() else currentKill.addSeparators() - ) - .replace("%percentNumber%", percent(GhostCounter.bestiaryCurrentKill.toDouble())) - .replace("%killNeeded%", killNeeded.shortFormat()) - .replace("%currentLevel%", currentLevel) - .replace("%nextLevel%", nextLevel) - .replace("&", "§") + return this.replace( + "%currentKill%", + if (GhostCounter.config.showMax) GhostCounter.bestiaryCurrentKill.addSeparators() else currentKill.addSeparators(), ) + .replace("%percentNumber%", percent(GhostCounter.bestiaryCurrentKill.toDouble())) + .replace("%killNeeded%", killNeeded.shortFormat()) + .replace("%currentLevel%", currentLevel) + .replace("%nextLevel%", nextLevel) + .replace("&", "§") } private fun percent(number: Double) = diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenNextJacobContest.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenNextJacobContest.kt index 8c2dc9a95..ab8820b40 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenNextJacobContest.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenNextJacobContest.kt @@ -32,10 +32,10 @@ import at.hannibal2.skyhanni.utils.SoundUtils import at.hannibal2.skyhanni.utils.StringUtils.removeColor import at.hannibal2.skyhanni.utils.TabListData import at.hannibal2.skyhanni.utils.TimeUtils.format +import at.hannibal2.skyhanni.utils.json.toJsonArray import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern import com.google.gson.Gson import com.google.gson.JsonPrimitive -import io.github.moulberry.notenoughupdates.util.toJsonArray import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import kotlinx.coroutines.withContext diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/plots/GardenPlotIcon.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/plots/GardenPlotIcon.kt index 1fc378b7e..01e9f87fb 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/plots/GardenPlotIcon.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/plots/GardenPlotIcon.kt @@ -8,10 +8,10 @@ import at.hannibal2.skyhanni.events.render.gui.ReplaceItemEvent import at.hannibal2.skyhanni.features.garden.GardenAPI import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule import at.hannibal2.skyhanni.utils.ChatUtils +import at.hannibal2.skyhanni.utils.ItemUtils.editItemInfo import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.NEUItems.getItemStack -import io.github.moulberry.notenoughupdates.util.Utils import net.minecraft.client.player.inventory.ContainerLocalMenu import net.minecraft.init.Items import net.minecraft.item.ItemStack @@ -51,7 +51,7 @@ object GardenPlotIcon { for ((index, internalName) in plotList) { val old = originalStack[index]!! val new = internalName.getItemStack() - cachedStack[index] = Utils.editItemStackInfo(new, old.displayName, true, *old.getLore().toTypedArray()) + cachedStack[index] = new.editItemInfo(old.displayName, true, old.getLore()) } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorSupercraft.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorSupercraft.kt index 26bfa7f26..f2e4f80fb 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorSupercraft.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorSupercraft.kt @@ -8,12 +8,12 @@ import at.hannibal2.skyhanni.events.render.gui.ReplaceItemEvent import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule import at.hannibal2.skyhanni.test.command.ErrorManager import at.hannibal2.skyhanni.utils.HypixelCommands +import at.hannibal2.skyhanni.utils.ItemUtils import at.hannibal2.skyhanni.utils.NEUInternalName import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName import at.hannibal2.skyhanni.utils.NEUItems import at.hannibal2.skyhanni.utils.NEUItems.getItemStack import at.hannibal2.skyhanni.utils.SimpleTimeMark -import io.github.moulberry.notenoughupdates.util.Utils import net.minecraft.entity.player.InventoryPlayer import net.minecraftforge.fml.common.eventhandler.EventPriority import net.minecraftforge.fml.common.eventhandler.SubscribeEvent @@ -30,11 +30,11 @@ object GardenVisitorSupercraft { private val superCraftItem by lazy { val neuItem = "GOLD_PICKAXE".asInternalName().getItemStack() - Utils.createItemStack( + ItemUtils.createItemStack( neuItem.item, "§bSuper Craft", "§7You have the items to craft", - "§7Click me to open the super crafter!" + "§7Click me to open the super crafter!", ) } diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/HighlightVisitorsOutsideOfGarden.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/HighlightVisitorsOutsideOfGarden.kt index 88ea75b57..8a8c11165 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/HighlightVisitorsOutsideOfGarden.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/HighlightVisitorsOutsideOfGarden.kt @@ -2,6 +2,7 @@ package at.hannibal2.skyhanni.features.garden.visitor import at.hannibal2.skyhanni.api.event.HandleEvent import at.hannibal2.skyhanni.config.features.garden.visitor.VisitorConfig.VisitorBlockBehaviour +import at.hannibal2.skyhanni.data.HypixelData import at.hannibal2.skyhanni.data.jsonobjects.repo.GardenJson import at.hannibal2.skyhanni.data.jsonobjects.repo.GardenVisitor import at.hannibal2.skyhanni.events.RepositoryReloadEvent @@ -19,7 +20,6 @@ import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzVec import at.hannibal2.skyhanni.utils.getLorenzVec import at.hannibal2.skyhanni.utils.toLorenzVec -import io.github.moulberry.notenoughupdates.util.SBInfo import net.minecraft.client.Minecraft import net.minecraft.entity.Entity import net.minecraft.entity.EntityLivingBase @@ -57,7 +57,8 @@ object HighlightVisitorsOutsideOfGarden { } private fun isVisitor(entity: Entity): Boolean { - val mode = SBInfo.getInstance().getLocation() + // todo migrate to Skyhanni IslandType + val mode = HypixelData.mode val possibleJsons = visitorJson[mode] ?: return false val skinOrType = getSkinOrTypeFor(entity) return possibleJsons.any { diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/auctionhouse/AuctionHouseOpenPriceWebsite.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/auctionhouse/AuctionHouseOpenPriceWebsite.kt index b253e0191..7229283ca 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/auctionhouse/AuctionHouseOpenPriceWebsite.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/auctionhouse/AuctionHouseOpenPriceWebsite.kt @@ -6,6 +6,7 @@ import at.hannibal2.skyhanni.events.InventoryCloseEvent import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent import at.hannibal2.skyhanni.events.render.gui.ReplaceItemEvent import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule +import at.hannibal2.skyhanni.utils.ItemUtils import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName import at.hannibal2.skyhanni.utils.NEUItems.getItemStack @@ -13,7 +14,6 @@ import at.hannibal2.skyhanni.utils.OSUtils import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher import at.hannibal2.skyhanni.utils.SimpleTimeMark import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern -import io.github.moulberry.notenoughupdates.util.Utils import net.minecraft.entity.player.InventoryPlayer import net.minecraft.item.ItemStack import net.minecraftforge.fml.common.eventhandler.EventPriority @@ -48,7 +48,7 @@ object AuctionHouseOpenPriceWebsite { } } - private fun createDisplayItem() = Utils.createItemStack( + private fun createDisplayItem() = ItemUtils.createItemStack( "PAPER".asInternalName().getItemStack().item, "§bPrice History", "§7Click here to open", diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/bazaar/BazaarOpenPriceWebsite.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/bazaar/BazaarOpenPriceWebsite.kt index 61606346a..216d3e108 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/bazaar/BazaarOpenPriceWebsite.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/bazaar/BazaarOpenPriceWebsite.kt @@ -4,12 +4,12 @@ import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.events.GuiContainerEvent import at.hannibal2.skyhanni.events.render.gui.ReplaceItemEvent import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule +import at.hannibal2.skyhanni.utils.ItemUtils import at.hannibal2.skyhanni.utils.NEUInternalName import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName import at.hannibal2.skyhanni.utils.NEUItems.getItemStack import at.hannibal2.skyhanni.utils.OSUtils import at.hannibal2.skyhanni.utils.SimpleTimeMark -import io.github.moulberry.notenoughupdates.util.Utils import net.minecraft.entity.player.InventoryPlayer import net.minecraftforge.fml.common.eventhandler.EventPriority import net.minecraftforge.fml.common.eventhandler.SubscribeEvent @@ -23,12 +23,12 @@ object BazaarOpenPriceWebsite { private val item by lazy { val neuItem = "PAPER".asInternalName().getItemStack() - Utils.createItemStack( + ItemUtils.createItemStack( neuItem.item, "§bPrice History", "§7Click here to open", "§7the price history", - "§7on §cskyblock.bz" + "§7on §cskyblock.bz", ) } diff --git a/src/main/java/at/hannibal2/skyhanni/features/mining/ColdOverlay.kt b/src/main/java/at/hannibal2/skyhanni/features/mining/ColdOverlay.kt index 8af757f6e..58ef41ce7 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/mining/ColdOverlay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/mining/ColdOverlay.kt @@ -6,8 +6,8 @@ import at.hannibal2.skyhanni.events.ColdUpdateEvent import at.hannibal2.skyhanni.events.GuiRenderEvent import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule import at.hannibal2.skyhanni.utils.DelayedRun +import at.hannibal2.skyhanni.utils.GuiRenderUtils import at.hannibal2.skyhanni.utils.NumberUtil -import at.hannibal2.skyhanni.utils.RenderUtils import at.hannibal2.skyhanni.utils.SimpleTimeMark import net.minecraft.client.Minecraft import net.minecraft.client.renderer.GlStateManager @@ -42,7 +42,7 @@ object ColdOverlay { GlStateManager.translate(0f, 0f, -500f) GlStateManager.color(1f, 1f, 1f, alpha) - RenderUtils.drawTexturedRect(0f, 0f) + GuiRenderUtils.drawTexturedRect(0f, 0f) GL11.glDepthMask(true) GlStateManager.popMatrix() diff --git a/src/main/java/at/hannibal2/skyhanni/features/mining/DeepCavernsGuide.kt b/src/main/java/at/hannibal2/skyhanni/features/mining/DeepCavernsGuide.kt index 9600fbc20..a1d8f43a8 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/mining/DeepCavernsGuide.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/mining/DeepCavernsGuide.kt @@ -16,12 +16,12 @@ import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.ColorUtils.toChromaColor import at.hannibal2.skyhanni.utils.ConditionalUtils +import at.hannibal2.skyhanni.utils.ItemUtils import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzUtils.isInIsland import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName import at.hannibal2.skyhanni.utils.NEUItems.getItemStack import at.hannibal2.skyhanni.utils.ParkourHelper -import io.github.moulberry.notenoughupdates.util.Utils import net.minecraft.client.player.inventory.ContainerLocalMenu import net.minecraftforge.fml.common.eventhandler.EventPriority import net.minecraftforge.fml.common.eventhandler.SubscribeEvent @@ -37,7 +37,7 @@ object DeepCavernsGuide { private val startIcon by lazy { val neuItem = "MAP".asInternalName().getItemStack() - Utils.createItemStack( + ItemUtils.createItemStack( neuItem.item, "§bDeep Caverns Guide", "§8(From SkyHanni)", diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/UserLuckBreakdown.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/UserLuckBreakdown.kt index d4532a775..7f041bc27 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/UserLuckBreakdown.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/UserLuckBreakdown.kt @@ -10,6 +10,7 @@ import at.hannibal2.skyhanni.events.render.gui.ReplaceItemEvent import at.hannibal2.skyhanni.features.skillprogress.SkillType import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule import at.hannibal2.skyhanni.utils.CollectionUtils.addOrPut +import at.hannibal2.skyhanni.utils.ItemUtils import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.ItemUtils.name import at.hannibal2.skyhanni.utils.LorenzUtils @@ -20,7 +21,6 @@ import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher import at.hannibal2.skyhanni.utils.SimpleTimeMark import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern -import io.github.moulberry.notenoughupdates.util.Utils import net.minecraft.client.player.inventory.ContainerLocalMenu import net.minecraft.item.ItemStack import net.minecraftforge.fml.common.eventhandler.SubscribeEvent @@ -237,9 +237,11 @@ object UserLuckBreakdown { } private fun createItems() { - fillerItem = Utils.createItemStack( + fillerItem = ItemUtils.createItemStack( fillerID.getItemStack().item, fillerName, + listOf(), + 1, 15, ) @@ -247,17 +249,17 @@ object UserLuckBreakdown { val skillLuck = skillOverflowLuck.values.sum() val totalLuck = skillLuck + limboLuck - mainLuckItem = Utils.createItemStack( + mainLuckItem = ItemUtils.createItemStack( mainLuckID.getItemStack().item, "$mainLuckName §f${tryTruncateFloat(totalLuck)}", *createItemLore("mainMenu", totalLuck), ) - limboItem = Utils.createItemStack( + limboItem = ItemUtils.createItemStack( limboID.getItemStack().item, limboName, *createItemLore("limbo", limboLuck), ) - skillsItem = Utils.createItemStack( + skillsItem = ItemUtils.createItemStack( skillsID.getItemStack().item, skillsName, *createItemLore("skills"), diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/limbo/LimboPlaytime.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/limbo/LimboPlaytime.kt index 0996701f2..666671e9c 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/limbo/LimboPlaytime.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/limbo/LimboPlaytime.kt @@ -6,6 +6,7 @@ import at.hannibal2.skyhanni.events.InventoryOpenEvent import at.hannibal2.skyhanni.events.LorenzToolTipEvent import at.hannibal2.skyhanni.events.render.gui.ReplaceItemEvent import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule +import at.hannibal2.skyhanni.utils.ItemUtils import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzUtils.round import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName @@ -14,7 +15,6 @@ import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators import at.hannibal2.skyhanni.utils.RegexUtils.matches import at.hannibal2.skyhanni.utils.SimpleTimeMark import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern -import io.github.moulberry.notenoughupdates.util.Utils import net.minecraft.client.player.inventory.ContainerLocalMenu import net.minecraft.item.ItemStack import net.minecraftforge.fml.common.eventhandler.SubscribeEvent @@ -58,7 +58,7 @@ object LimboPlaytime { if (lastCreateCooldown.passedSince() > 3.seconds) { lastCreateCooldown = SimpleTimeMark.now() - limboItem = Utils.createItemStack( + limboItem = ItemUtils.createItemStack( itemID.getItemStack().item, itemName, *createItemLore() diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/massconfiguration/DefaultConfigOptionGui.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/massconfiguration/DefaultConfigOptionGui.kt index a68978cae..bbe40db5c 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/massconfiguration/DefaultConfigOptionGui.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/massconfiguration/DefaultConfigOptionGui.kt @@ -1,6 +1,7 @@ package at.hannibal2.skyhanni.features.misc.massconfiguration -import io.github.moulberry.notenoughupdates.util.Utils +import at.hannibal2.skyhanni.utils.renderables.Renderable +import at.hannibal2.skyhanni.utils.renderables.RenderableTooltips import io.github.notenoughupdates.moulconfig.internal.GlScissorStack import io.github.notenoughupdates.moulconfig.internal.RenderUtils import io.github.notenoughupdates.moulconfig.internal.TextRenderUtils @@ -66,7 +67,7 @@ class DefaultConfigOptionGui( mc.fontRendererObj.FONT_HEIGHT.toFloat(), false, xSize / 2 - padding, - -1 + -1, ) GlStateManager.popMatrix() @@ -74,7 +75,7 @@ class DefaultConfigOptionGui( GlStateManager.translate( (width - xSize) / 2F + padding, (height + ySize) / 2F - mc.fontRendererObj.FONT_HEIGHT * 2, - 0F + 0F, ) var i = 0 fun button(title: String, tooltip: List<String>, func: () -> Unit) { @@ -95,7 +96,7 @@ class DefaultConfigOptionGui( 2 + i.toFloat(), 0F, if (overMouse) 0xFF00FF00.toInt() else -1, - overMouse + overMouse, ) i += width + 12 } @@ -132,12 +133,12 @@ class DefaultConfigOptionGui( (height - ySize) / 2 + barSize, (width + xSize) / 2, (height + ySize) / 2 - barSize, - scaledResolution + scaledResolution, ) GlStateManager.translate( (width - xSize) / 2F + padding, (height - ySize) / 2F + barSize - currentScrollOffset, - 0F + 0F, ) for ((cat) in orderedOptions.entries) { @@ -157,13 +158,13 @@ class DefaultConfigOptionGui( "§7${cat.description}", "§7Current plan: ${suggestionState.label}", "§aClick to toggle!", - "§7Hold shift to show all options" + "§7Hold shift to show all options", ) if (isShiftKeyDown()) { hoveringTextToDraw = listOf( "§e${cat.name}", - "§7${cat.description}" + "§7${cat.description}", ) + orderedOptions[cat]!!.map { "§7 - §a" + it.name } } @@ -179,8 +180,8 @@ class DefaultConfigOptionGui( GlStateManager.popMatrix() GlScissorStack.pop(scaledResolution) - if (hoveringTextToDraw != null) { - Utils.drawHoveringText(hoveringTextToDraw, mouseX, mouseY, width, height, 100, mc.fontRendererObj) + hoveringTextToDraw?.let { tooltip -> + RenderableTooltips.setTooltipForRender(tooltip.map { Renderable.string(it) }) } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/rift/everywhere/EnigmaSoulWaypoints.kt b/src/main/java/at/hannibal2/skyhanni/features/rift/everywhere/EnigmaSoulWaypoints.kt index d91b4008d..2a4613f7a 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/rift/everywhere/EnigmaSoulWaypoints.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/rift/everywhere/EnigmaSoulWaypoints.kt @@ -14,6 +14,7 @@ import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.ColorUtils.toChromaColor import at.hannibal2.skyhanni.utils.InventoryUtils.getAllItems +import at.hannibal2.skyhanni.utils.ItemUtils import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.LocationUtils.distanceToPlayer import at.hannibal2.skyhanni.utils.LorenzColor @@ -24,7 +25,6 @@ import at.hannibal2.skyhanni.utils.RenderUtils.drawDynamicText import at.hannibal2.skyhanni.utils.RenderUtils.drawWaypointFilled import at.hannibal2.skyhanni.utils.RenderUtils.highlight import at.hannibal2.skyhanni.utils.StringUtils.removeColor -import io.github.moulberry.notenoughupdates.util.Utils import net.minecraft.client.gui.inventory.GuiChest import net.minecraft.client.player.inventory.ContainerLocalMenu import net.minecraft.inventory.ContainerChest @@ -43,7 +43,7 @@ object EnigmaSoulWaypoints { private val item by lazy { val neuItem = "SKYBLOCK_ENIGMA_SOUL".asInternalName().getItemStack() - Utils.createItemStack( + ItemUtils.createItemStack( neuItem.item, "§5Toggle Missing", "§7Click here to toggle", diff --git a/src/main/java/at/hannibal2/skyhanni/features/skillprogress/SkillType.kt b/src/main/java/at/hannibal2/skyhanni/features/skillprogress/SkillType.kt index bd44a63f3..b10bc8cb6 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/skillprogress/SkillType.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/skillprogress/SkillType.kt @@ -1,6 +1,6 @@ package at.hannibal2.skyhanni.features.skillprogress -import io.github.moulberry.notenoughupdates.util.Utils +import at.hannibal2.skyhanni.utils.ItemUtils import net.minecraft.block.Block import net.minecraft.init.Blocks import net.minecraft.init.Items @@ -21,7 +21,7 @@ enum class SkillType(val displayName: String, icon: Item) { constructor(displayName: String, block: Block) : this(displayName, Item.getItemFromBlock(block)) - val item: ItemStack by lazy { Utils.createItemStack(icon, displayName) } + val item: ItemStack by lazy { ItemUtils.createItemStack(icon, displayName) } val lowercaseName = displayName.lowercase() val uppercaseName = displayName.uppercase() diff --git a/src/main/java/at/hannibal2/skyhanni/test/SkyHanniConfigSearchResetCommand.kt b/src/main/java/at/hannibal2/skyhanni/test/SkyHanniConfigSearchResetCommand.kt index 8a7451082..34bf36b5f 100644 --- a/src/main/java/at/hannibal2/skyhanni/test/SkyHanniConfigSearchResetCommand.kt +++ b/src/main/java/at/hannibal2/skyhanni/test/SkyHanniConfigSearchResetCommand.kt @@ -10,8 +10,8 @@ import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators import at.hannibal2.skyhanni.utils.OSUtils import at.hannibal2.skyhanni.utils.ReflectionUtils.makeAccessible +import at.hannibal2.skyhanni.utils.json.Shimmy import com.google.gson.JsonElement -import io.github.moulberry.notenoughupdates.util.Shimmy import kotlinx.coroutines.launch import java.lang.reflect.Field import java.lang.reflect.Modifier diff --git a/src/main/java/at/hannibal2/skyhanni/utils/GuiRenderUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/GuiRenderUtils.kt index 75eb5087e..ba1081a5f 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/GuiRenderUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/GuiRenderUtils.kt @@ -7,16 +7,17 @@ import at.hannibal2.skyhanni.utils.LorenzUtils.round import at.hannibal2.skyhanni.utils.NumberUtil.fractionOf import at.hannibal2.skyhanni.utils.RenderUtils.HorizontalAlignment import at.hannibal2.skyhanni.utils.renderables.Renderable -import io.github.moulberry.notenoughupdates.util.Utils import net.minecraft.client.Minecraft import net.minecraft.client.gui.FontRenderer import net.minecraft.client.gui.GuiScreen +import net.minecraft.client.gui.ScaledResolution import net.minecraft.client.renderer.GlStateManager import net.minecraft.client.renderer.RenderHelper import net.minecraft.client.renderer.Tessellator import net.minecraft.client.renderer.vertex.DefaultVertexFormats import net.minecraft.item.ItemStack import org.lwjgl.opengl.GL11 +import org.lwjgl.opengl.GL14 import java.awt.Color import java.text.DecimalFormat import kotlin.math.ceil @@ -75,7 +76,7 @@ object GuiRenderUtils { fun drawStringCentered(str: String?, x: Int, y: Int) { drawStringCentered( - str, Minecraft.getMinecraft().fontRendererObj, x.toFloat(), y.toFloat(), true, 0xffffff + str, Minecraft.getMinecraft().fontRendererObj, x.toFloat(), y.toFloat(), true, 0xffffff, ) } @@ -125,25 +126,25 @@ object GuiRenderUtils { if (tooltipY + tooltipHeight + 6 > screenHeight) tooltipY = screenHeight - tooltipHeight - 6 // main background GuiScreen.drawRect( - tooltipX - 3, tooltipY - 3, tooltipX + tooltipTextWidth + 3, tooltipY + tooltipHeight + 3, -0xfeffff0 + tooltipX - 3, tooltipY - 3, tooltipX + tooltipTextWidth + 3, tooltipY + tooltipHeight + 3, -0xfeffff0, ) // borders GuiScreen.drawRect( - tooltipX - 3, tooltipY - 3 + 1, tooltipX - 3 + 1, tooltipY + tooltipHeight + 3 - 1, borderColor + tooltipX - 3, tooltipY - 3 + 1, tooltipX - 3 + 1, tooltipY + tooltipHeight + 3 - 1, borderColor, - ) + ) GuiScreen.drawRect( tooltipX + tooltipTextWidth + 2, tooltipY - 3 + 1, tooltipX + tooltipTextWidth + 3, tooltipY + tooltipHeight + 3 - 1, - borderColor + borderColor, ) GuiScreen.drawRect( - tooltipX - 3, tooltipY - 3, tooltipX + tooltipTextWidth + 3, tooltipY - 3 + 1, borderColor + tooltipX - 3, tooltipY - 3, tooltipX + tooltipTextWidth + 3, tooltipY - 3 + 1, borderColor, ) GuiScreen.drawRect( @@ -151,7 +152,7 @@ object GuiRenderUtils { tooltipY + tooltipHeight + 2, tooltipX + tooltipTextWidth + 3, tooltipY + tooltipHeight + 3, - borderColor + borderColor, ) GlStateManager.translate(0f, 0f, -100f) GlStateManager.disableDepth() @@ -188,27 +189,33 @@ object GuiRenderUtils { val current = currentValue.toDouble().coerceAtLeast(0.0) val percent = current.fractionOf(maxValue) val scale = textScale.toDouble() - return Renderable.hoverTips(Renderable.verticalContainer( - listOf( - Renderable.string(label, scale = scale), - Renderable.fixedSizeLine( - listOf( - Renderable.string( - "§2${DecimalFormat("0.##").format(current)} / ${ - DecimalFormat( - "0.##" - ).format(maxValue) - }☘", scale = scale, horizontalAlign = HorizontalAlignment.LEFT + return Renderable.hoverTips( + Renderable.verticalContainer( + listOf( + Renderable.string(label, scale = scale), + Renderable.fixedSizeLine( + listOf( + Renderable.string( + "§2${DecimalFormat("0.##").format(current)} / ${ + DecimalFormat( + "0.##", + ).format(maxValue) + }☘", + scale = scale, horizontalAlign = HorizontalAlignment.LEFT, + ), + Renderable.string( + "§2${(percent * 100).round(1)}%", + scale = scale, + horizontalAlign = HorizontalAlignment.RIGHT, + ), ), - Renderable.string( - "§2${(percent * 100).round(1)}%", - scale = scale, - horizontalAlign = HorizontalAlignment.RIGHT - ), - ), width - ), Renderable.progressBar(percent, width = width) - ) - ), tooltip.split('\n').map { Renderable.string(it) }) + width, + ), + Renderable.progressBar(percent, width = width), + ), + ), + tooltip.split('\n').map { Renderable.string(it) }, + ) } private fun barColorGradient(double: Double): Int { @@ -265,16 +272,14 @@ object GuiRenderUtils { Color.LIGHT_GRAY.darker().red / 255f, Color.LIGHT_GRAY.darker().green / 255f, Color.LIGHT_GRAY.darker().blue / 255f, - 1f + 1f, ) } else { GlStateManager.color(color.darker().red / 255f, color.darker().green / 255f, color.darker().blue / 255f, 1f) } - Utils.drawTexturedRect(x, y, w_2.toFloat(), height, 0f, w_2 / xSize, vMinEmpty, vMaxEmpty, GL11.GL_NEAREST) - Utils.drawTexturedRect( - x + w_2, y, w_2.toFloat(), height, 1 - w_2 / xSize, 1f, vMinEmpty, vMaxEmpty, GL11.GL_NEAREST - ) + drawTexturedRect(x, y, w_2.toFloat(), height, 0f, w_2 / xSize, vMinEmpty, vMaxEmpty, GL11.GL_NEAREST) + drawTexturedRect(x + w_2, y, w_2.toFloat(), height, 1 - w_2 / xSize, 1f, vMinEmpty, vMaxEmpty, GL11.GL_NEAREST) if (useChroma) { GlStateManager.color(Color.WHITE.red / 255f, Color.WHITE.green / 255f, Color.WHITE.blue / 255f, 1f) @@ -285,9 +290,9 @@ object GuiRenderUtils { if (k > 0) { val uMax = w_2.toDouble().coerceAtMost(k.toDouble() / xSize).toFloat() val width = w_2.coerceAtMost(k).toFloat() - Utils.drawTexturedRect(x, y, width, height, 0f, uMax, vMinFilled, vMaxFilled, GL11.GL_NEAREST) + drawTexturedRect(x, y, width, height, 0f, uMax, vMinFilled, vMaxFilled, GL11.GL_NEAREST) if (completed > 0.5f) { - Utils.drawTexturedRect( + drawTexturedRect( x + w_2, y, (k - w_2).toFloat(), @@ -296,7 +301,7 @@ object GuiRenderUtils { 1 + (k - w) / xSize, vMinFilled, vMaxFilled, - GL11.GL_NEAREST + GL11.GL_NEAREST, ) } } @@ -342,4 +347,59 @@ object GuiRenderUtils { GlStateManager.enableAlpha() GlStateManager.enableTexture2D() } + + fun drawTexturedRect(x: Float, y: Float) { + with(ScaledResolution(Minecraft.getMinecraft())) { + drawTexturedRect(x, y, scaledWidth.toFloat(), scaledHeight.toFloat(), filter = GL11.GL_NEAREST) + } + } + + fun drawTexturedRect( + x: Int, + y: Int, + width: Int, + height: Int, + uMin: Float = 0f, + uMax: Float = 1f, + vMin: Float = 0f, + vMax: Float = 1f, + filter: Int = GL11.GL_NEAREST, + ) { + drawTexturedRect(x.toFloat(), y.toFloat(), width.toFloat(), height.toFloat(), uMin, uMax, vMin, vMax, filter) + } + + // Taken from NEU + fun drawTexturedRect( + x: Float, + y: Float, + width: Float, + height: Float, + uMin: Float = 0f, + uMax: Float = 1f, + vMin: Float = 0f, + vMax: Float = 1f, + filter: Int = GL11.GL_NEAREST, + ) { + GlStateManager.enableTexture2D() + GlStateManager.enableBlend() + GlStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA) + GL14.glBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA) + + GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, filter) + GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, filter) + + val tessellator = Tessellator.getInstance() + val worldRenderer = tessellator.worldRenderer + worldRenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX) + worldRenderer.pos(x.toDouble(), (y + height).toDouble(), 0.0).tex(uMin.toDouble(), vMax.toDouble()).endVertex() + worldRenderer.pos((x + width).toDouble(), (y + height).toDouble(), 0.0).tex(uMax.toDouble(), vMax.toDouble()).endVertex() + worldRenderer.pos((x + width).toDouble(), y.toDouble(), 0.0).tex(uMax.toDouble(), vMin.toDouble()).endVertex() + worldRenderer.pos(x.toDouble(), y.toDouble(), 0.0).tex(uMin.toDouble(), vMin.toDouble()).endVertex() + tessellator.draw() + + GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST) + GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST) + + GlStateManager.disableBlend() + } } diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt index ac35c0741..add66cc0a 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt @@ -22,6 +22,7 @@ import com.google.common.collect.Lists import io.github.moulberry.notenoughupdates.util.NotificationHandler import net.minecraft.client.Minecraft import net.minecraft.init.Items +import net.minecraft.item.Item import net.minecraft.item.ItemStack import net.minecraft.nbt.NBTTagCompound import net.minecraft.nbt.NBTTagList @@ -43,9 +44,11 @@ object ItemUtils { fun isSack(stack: ItemStack) = stack.getInternalName().endsWith("_SACK") && stack.cleanName().endsWith(" Sack") - fun ItemStack.getLore(): List<String> { - val tagCompound = this.tagCompound ?: return emptyList() - val tagList = tagCompound.getCompoundTag("display").getTagList("Lore", 8) + fun ItemStack.getLore(): List<String> = this.tagCompound.getLore() + + fun NBTTagCompound?.getLore(): List<String> { + this ?: return emptyList() + val tagList = this.getCompoundTag("display").getTagList("Lore", 8) val list: MutableList<String> = ArrayList() for (i in 0 until tagList.tagCount()) { list.add(tagList.getStringTagAt(i)) @@ -53,6 +56,13 @@ object ItemUtils { return list } + fun getDisplayName(compound: NBTTagCompound?): String? { + compound ?: return null + val name = compound.getCompoundTag("display").getString("Name") + if (name == null || name.isEmpty()) return null + return name + } + fun ItemStack.setLore(lore: List<String>): ItemStack { val tagCompound = this.tagCompound ?: NBTTagCompound() val display = tagCompound.getCompoundTag("display") @@ -67,12 +77,14 @@ object ItemUtils { } var ItemStack.extraAttributes: NBTTagCompound - get() = this.tagCompound?.getCompoundTag("ExtraAttributes") ?: NBTTagCompound() + get() = this.tagCompound?.extraAttributes ?: NBTTagCompound() set(value) { val tag = this.tagCompound ?: NBTTagCompound().also { tagCompound = it } tag.setTag("ExtraAttributes", value) } + val NBTTagCompound.extraAttributes: NBTTagCompound get() = this.getCompoundTag("ExtraAttributes") + fun ItemStack.overrideId(id: String): ItemStack { extraAttributes = extraAttributes.apply { setString("id", id) } return this @@ -183,6 +195,20 @@ object ItemUtils { return render } + fun createItemStack(item: Item, displayName: String, vararg lore: String): ItemStack { + return createItemStack(item, displayName, lore.toList()) + } + + // Taken from NEU + fun createItemStack(item: Item, displayName: String, lore: List<String>, amount: Int = 1, damage: Int = 0): ItemStack { + val stack = ItemStack(item, amount, damage) + val tag = NBTTagCompound() + addNameAndLore(tag, displayName, *lore.toTypedArray()) + tag.setInteger("HideFlags", 254) + stack.tagCompound = tag + return stack + } + // Taken from NEU private fun addNameAndLore(tag: NBTTagCompound, displayName: String, vararg lore: String) { val display = NBTTagCompound() @@ -315,6 +341,28 @@ object ItemUtils { setStackDisplayName(value) } + // Taken from NEU + fun ItemStack.editItemInfo(displayName: String, disableNeuTooltips: Boolean, lore: List<String>): ItemStack { + val tag = this.tagCompound ?: NBTTagCompound() + val display = tag.getCompoundTag("display") + val loreList = NBTTagList() + for (line in lore) { + loreList.appendTag(NBTTagString(line)) + } + + display.setString("Name", displayName) + display.setTag("Lore", loreList) + + tag.setTag("display", display) + tag.setInteger("HideFlags", 254) + if (disableNeuTooltips) { + tag.setBoolean("disableNeuTooltip", true) + } + + this.tagCompound = tag + return this + } + fun isSkyBlockMenuItem(stack: ItemStack?): Boolean = stack?.getInternalName()?.equals("SKYBLOCK_MENU") ?: false private val itemAmountCache = mutableMapOf<String, Pair<String, Int>>() diff --git a/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt b/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt index 34d491cee..198b43a85 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt @@ -31,7 +31,6 @@ import io.github.moulberry.notenoughupdates.events.ProfileDataLoadedEvent import io.github.moulberry.notenoughupdates.overlays.AuctionSearchOverlay import io.github.moulberry.notenoughupdates.overlays.BazaarSearchOverlay import io.github.moulberry.notenoughupdates.util.ItemResolutionQuery -import io.github.moulberry.notenoughupdates.util.Utils import net.minecraft.client.Minecraft import net.minecraft.client.renderer.GLAllocation import net.minecraft.client.renderer.GlStateManager @@ -97,7 +96,7 @@ object NEUItems { val ignoreItemsFilter = MultiFilter() private val fallbackItem by lazy { - Utils.createItemStack( + ItemUtils.createItemStack( ItemStack(Blocks.barrier).item, "§cMissing Repo Item", "§cYour NEU repo seems to be out of date", diff --git a/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt index 08532e0c4..609ccebae 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt @@ -19,11 +19,11 @@ import at.hannibal2.skyhanni.utils.CollectionUtils.zipWithNext3 import at.hannibal2.skyhanni.utils.ColorUtils.getFirstColorCode import at.hannibal2.skyhanni.utils.LorenzColor.Companion.toLorenzColor import at.hannibal2.skyhanni.utils.LorenzUtils.getCorners +import at.hannibal2.skyhanni.utils.compat.GuiScreenUtils import at.hannibal2.skyhanni.utils.renderables.Renderable import at.hannibal2.skyhanni.utils.renderables.RenderableUtils.renderXAligned import at.hannibal2.skyhanni.utils.renderables.RenderableUtils.renderYAligned import at.hannibal2.skyhanni.utils.shader.ShaderManager -import io.github.moulberry.notenoughupdates.util.Utils import io.github.notenoughupdates.moulconfig.internal.TextRenderUtils import net.minecraft.client.Minecraft import net.minecraft.client.gui.FontRenderer @@ -41,6 +41,7 @@ import net.minecraft.item.ItemStack import net.minecraft.util.AxisAlignedBB import net.minecraft.util.MathHelper import net.minecraft.util.ResourceLocation +import org.lwjgl.input.Mouse import org.lwjgl.opengl.GL11 import java.awt.Color import java.nio.FloatBuffer @@ -95,6 +96,15 @@ object RenderUtils { highlight(color, x, y) } + fun getMouseX(): Int { + return Mouse.getX() * GuiScreenUtils.scaledWindowWidth / Minecraft.getMinecraft().displayWidth + } + + fun getMouseY(): Int { + val height = GuiScreenUtils.scaledWindowHeight + return height - Mouse.getY() * height / Minecraft.getMinecraft().displayHeight - 1 + } + fun highlight(color: Color, x: Int, y: Int) { GlStateManager.disableLighting() GlStateManager.disableDepth() @@ -504,8 +514,8 @@ object RenderUtils { fun Position.transform(): Pair<Int, Int> { GlStateManager.translate(getAbsX().toFloat(), getAbsY().toFloat(), 0F) GlStateManager.scale(effectiveScale, effectiveScale, 1F) - val x = ((Utils.getMouseX() - getAbsX()) / effectiveScale).toInt() - val y = ((Utils.getMouseY() - getAbsY()) / effectiveScale).toInt() + val x = ((getMouseX() - getAbsX()) / effectiveScale).toInt() + val y = ((getMouseY() - getAbsY()) / effectiveScale).toInt() return x to y } @@ -1712,7 +1722,7 @@ object RenderUtils { fun drawRoundTexturedRect(x: Int, y: Int, width: Int, height: Int, filter: Int, radius: Int = 10, smoothness: Int = 1) { // if radius is 0 then just draw a normal textured rect if (radius <= 0) { - Utils.drawTexturedRect(x.toFloat(), y.toFloat(), width.toFloat(), height.toFloat(), filter) + GuiRenderUtils.drawTexturedRect(x, y, width, height, filter = filter) return } @@ -1731,7 +1741,7 @@ object RenderUtils { GlStateManager.pushMatrix() ShaderManager.enableShader(ShaderManager.Shaders.ROUNDED_TEXTURE) - Utils.drawTexturedRect(x.toFloat(), y.toFloat(), width.toFloat(), height.toFloat(), filter) + GuiRenderUtils.drawTexturedRect(x, y, width, height, filter = filter) ShaderManager.disableShader() GlStateManager.popMatrix() @@ -1832,6 +1842,7 @@ object RenderUtils { GlStateManager.popMatrix() } + // todo merge with the one in GuiRenderUtils fun drawGradientRect( left: Int, top: Int, @@ -1871,13 +1882,6 @@ object RenderUtils { GlStateManager.enableTexture2D() } - // TODO move off of neu function - fun drawTexturedRect(x: Float, y: Float) { - with(ScaledResolution(Minecraft.getMinecraft())) { - Utils.drawTexturedRect(x, y, scaledWidth.toFloat(), scaledHeight.toFloat(), GL11.GL_NEAREST) - } - } - fun getAlpha(): Float { colorBuffer.clear() GlStateManager.getFloat(GL11.GL_CURRENT_COLOR, colorBuffer) diff --git a/src/main/java/at/hannibal2/skyhanni/utils/SkyBlockItemModifierUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/SkyBlockItemModifierUtils.kt index 4d0cf4468..128b5d11e 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/SkyBlockItemModifierUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/SkyBlockItemModifierUtils.kt @@ -3,6 +3,7 @@ package at.hannibal2.skyhanni.utils import at.hannibal2.skyhanni.config.ConfigManager import at.hannibal2.skyhanni.data.PetAPI import at.hannibal2.skyhanni.mixins.hooks.ItemStackCachedData +import at.hannibal2.skyhanni.utils.ItemUtils.extraAttributes import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.ItemUtils.name @@ -272,7 +273,7 @@ object SkyBlockItemModifierUtils { private fun ItemStack.getAttributeByte(label: String) = getExtraAttributes()?.getByte(label) ?: 0 - fun ItemStack.getExtraAttributes() = tagCompound?.getCompoundTag("ExtraAttributes") + fun ItemStack.getExtraAttributes() = tagCompound?.extraAttributes class GemstoneSlot(val type: GemstoneType, val quality: GemstoneQuality) { diff --git a/src/main/java/at/hannibal2/skyhanni/utils/json/JsonUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/json/JsonUtils.kt index 750bd96aa..ed4a5fbe6 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/json/JsonUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/json/JsonUtils.kt @@ -1,9 +1,11 @@ package at.hannibal2.skyhanni.utils.json +import at.hannibal2.skyhanni.config.ConfigManager import com.google.gson.Gson import com.google.gson.JsonArray import com.google.gson.JsonElement import com.google.gson.JsonObject +import java.io.File import java.io.Reader import kotlin.reflect.jvm.javaType import kotlin.reflect.typeOf @@ -15,6 +17,16 @@ inline fun <reified T : Any> Gson.fromJson(jsonElement: JsonElement): T = inline fun <reified T : Any> Gson.fromJson(reader: Reader): T = this.fromJson(reader, typeOf<T>().javaType) +fun File.getJson(): JsonObject? { + return try { + this.inputStream().use { + ConfigManager.gson.fromJson(it.reader(), JsonObject::class.java) + } + } catch (e: Exception) { + null + } +} + /** * Straight forward deep copy. This is included in gson as well, but different versions have it exposed privately instead of publicly, * so this reimplementation is here as an always public alternative. @@ -35,3 +47,9 @@ fun JsonElement.shDeepCopy(): JsonElement { else -> this } } + +fun Iterable<JsonElement>.toJsonArray(): JsonArray = JsonArray().also { + for (jsonElement in this) { + it.add(jsonElement) + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/utils/json/Shimmy.kt b/src/main/java/at/hannibal2/skyhanni/utils/json/Shimmy.kt new file mode 100644 index 000000000..31022da58 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/utils/json/Shimmy.kt @@ -0,0 +1,64 @@ +package at.hannibal2.skyhanni.utils.json + +import at.hannibal2.skyhanni.config.ConfigManager +import com.google.gson.JsonElement +import java.lang.reflect.Field + +// Copied from NEU +class Shimmy private constructor( + val source: Any, + val field: Field, +) { + companion object { + private fun shimmy(source: Any?, fieldName: String): Any? { + if (source == null) return null + return try { + val declaredField = source.javaClass.getDeclaredField(fieldName) + declaredField.isAccessible = true + declaredField.get(source) + } catch (e: NoSuchFieldException) { + null + } + } + + @JvmStatic + fun makeShimmy(source: Any?, path: List<String>): Shimmy? { + if (path.isEmpty()) + return null + var source = source + for (part in path.dropLast(1)) { + source = shimmy(source, part) + } + if (source == null) return null + val lastName = path.last() + return try { + val field = source.javaClass.getDeclaredField(lastName) + field.isAccessible = true + Shimmy( + source, + field, + ) + } catch (e: NoSuchFieldException) { + null + } + } + + } + + val clazz: Class<*> = field.type + fun get(): Any? { + return field.get(source) + } + + fun set(value: Any?) { + field.set(source, value) + } + + fun getJson(): JsonElement { + return ConfigManager.gson.toJsonTree(get()) + } + + fun setJson(element: JsonElement) { + set(ConfigManager.gson.fromJson(element, clazz)) + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt b/src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt index d161cf2b0..f3f704f37 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt @@ -14,6 +14,7 @@ import at.hannibal2.skyhanni.utils.CollectionUtils.contains import at.hannibal2.skyhanni.utils.ColorUtils import at.hannibal2.skyhanni.utils.ColorUtils.addAlpha import at.hannibal2.skyhanni.utils.ColorUtils.darker +import at.hannibal2.skyhanni.utils.GuiRenderUtils import at.hannibal2.skyhanni.utils.KeyboardManager.isKeyClicked import at.hannibal2.skyhanni.utils.LorenzColor import at.hannibal2.skyhanni.utils.LorenzLogger @@ -29,7 +30,6 @@ import at.hannibal2.skyhanni.utils.renderables.RenderableUtils.renderXAligned import at.hannibal2.skyhanni.utils.renderables.RenderableUtils.renderXYAligned import at.hannibal2.skyhanni.utils.renderables.RenderableUtils.renderYAligned import at.hannibal2.skyhanni.utils.shader.ShaderManager -import io.github.moulberry.notenoughupdates.util.Utils import io.github.notenoughupdates.moulconfig.gui.GuiScreenElementWrapper import net.minecraft.client.Minecraft import net.minecraft.client.gui.Gui @@ -1272,18 +1272,9 @@ interface Renderable { override fun render(posX: Int, posY: Int) { Minecraft.getMinecraft().textureManager.bindTexture(texture) + GlStateManager.color(1f, 1f, 1f, alpha / 255f) - Utils.drawTexturedRect( - 0f, - 0f, - width.toFloat(), - height.toFloat(), - uMin, - uMax, - vMin, - vMax, - GL11.GL_NEAREST, - ) + GuiRenderUtils.drawTexturedRect(0, 0, width, height, uMin, uMax, vMin, vMax) GlStateManager.color(1f, 1f, 1f, 1f) GlStateManager.translate(padding.toFloat(), padding.toFloat(), 0f) @@ -1312,17 +1303,7 @@ interface Renderable { override fun render(posX: Int, posY: Int) { Minecraft.getMinecraft().textureManager.bindTexture(texture) GlStateManager.color(1f, 1f, 1f, alpha / 255f) - Utils.drawTexturedRect( - 0f, - 0f, - width.toFloat(), - height.toFloat(), - uMin, - uMax, - vMin, - vMax, - GL11.GL_NEAREST, - ) + GuiRenderUtils.drawTexturedRect(0, 0, width, height, uMin, uMax, vMin, vMax) GlStateManager.color(1f, 1f, 1f, 1f) } } diff --git a/src/main/java/at/hannibal2/skyhanni/utils/renderables/RenderableTooltips.kt b/src/main/java/at/hannibal2/skyhanni/utils/renderables/RenderableTooltips.kt index b37c89bb5..b6c4225ba 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/renderables/RenderableTooltips.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/renderables/RenderableTooltips.kt @@ -5,7 +5,6 @@ import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.LorenzColor import at.hannibal2.skyhanni.utils.RenderUtils import at.hannibal2.skyhanni.utils.renderables.RenderableUtils.renderXAligned -import io.github.moulberry.notenoughupdates.util.Utils import net.minecraft.client.Minecraft import net.minecraft.client.gui.ScaledResolution import net.minecraft.client.renderer.GlStateManager @@ -44,8 +43,8 @@ object RenderableTooltips { val tips = tooltip.tips if (tips.isEmpty()) return - val x = Utils.getMouseX() + 12 - val y = Utils.getMouseY() - if (tips.size > 1) 1 else -7 + val x = RenderUtils.getMouseX() + 12 + val y = RenderUtils.getMouseY() - if (tips.size > 1) 1 else -7 val borderColorStart = tooltip.getBorderColor() val scaled = ScaledResolution(Minecraft.getMinecraft()) val isSpacedTitle = tooltip.isSpacedTitle() |