From 3d9a03ff4f1e542339950be6a77cb4c59a46ab77 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal002@users.noreply.github.com> Date: Mon, 13 Feb 2023 14:03:22 +0100 Subject: Fix Muscle Memory (#581) * Added old SkyBlock Menu. * Execution! * Add cache. * Bingo has already enough to do. * Typo. * Revert "Typo." This reverts commit b4a1c385e0c410b1e111797b8d39e7ff64b09ef5. * Revert "Bingo has already enough to do." This reverts commit 6e004d2d65dff47ea3bee5c5789cb725724df6ed. * I am lazy. * The map is lazy too. * Hypixel moving features behind paywall. * Add red text to the setting too. * SEALED * Fixed Booster Cookie checks. Reworked CookieWarning, kept same logic but accidentally added profile switch support. * /trades does not require booster cookie. * Allowing middle clicks (and any other mouse click combination) --------- Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> --- .../miscfeatures/OldSkyBlockMenu.kt | 195 +++++++++++++++++++++ 1 file changed, 195 insertions(+) create mode 100644 src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/OldSkyBlockMenu.kt (limited to 'src/main/kotlin') diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/OldSkyBlockMenu.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/OldSkyBlockMenu.kt new file mode 100644 index 00000000..b871a672 --- /dev/null +++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/OldSkyBlockMenu.kt @@ -0,0 +1,195 @@ +/* + * Copyright (C) 2023 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see . + */ + +package io.github.moulberry.notenoughupdates.miscfeatures + +import io.github.moulberry.notenoughupdates.NotEnoughUpdates +import io.github.moulberry.notenoughupdates.autosubscribe.NEUAutoSubscribe +import io.github.moulberry.notenoughupdates.events.ReplaceItemEvent +import io.github.moulberry.notenoughupdates.events.SlotClickEvent +import io.github.moulberry.notenoughupdates.util.Utils +import net.minecraft.client.player.inventory.ContainerLocalMenu +import net.minecraft.init.Items +import net.minecraft.item.Item +import net.minecraft.item.ItemStack +import net.minecraftforge.fml.common.eventhandler.EventPriority +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +@NEUAutoSubscribe +object OldSkyBlockMenu { + + val map: Map by lazy { + val map = mutableMapOf() + for (button in SkyBlockButton.values()) { + map[button.slot] = button + } + map + } + + @SubscribeEvent + fun replaceItem(event: ReplaceItemEvent) { + if (!isRightInventory()) return + if (event.inventory !is ContainerLocalMenu) return + + val skyBlockButton = map[event.slotNumber] ?: return + + if (skyBlockButton.requiresBoosterCookie && !CookieWarning.hasActiveBoosterCookie()) { + event.replaceWith(skyBlockButton.itemWithCookieWarning) + } else { + event.replaceWith(skyBlockButton.itemWithoutCookieWarning) + } + } + + @SubscribeEvent(priority = EventPriority.HIGH) + fun onStackClick(event: SlotClickEvent) { + if (!isRightInventory()) return + + val skyBlockButton = map[event.slotId] ?: return + event.isCanceled = true + + if (!skyBlockButton.requiresBoosterCookie || CookieWarning.hasActiveBoosterCookie()) { + NotEnoughUpdates.INSTANCE.sendChatMessage("/" + skyBlockButton.command) + } + } + + private fun isRightInventory(): Boolean { + return NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard() && + NotEnoughUpdates.INSTANCE.config.misc.oldSkyBlockMenu && + Utils.getOpenChestName() == "SkyBlock Menu" + } + + enum class SkyBlockButton( + val command: String, + val slot: Int, + private val displayName: String, + private vararg val displayDescription: String, + private val itemData: ItemData, + val requiresBoosterCookie: Boolean = true, + ) { + TRADES( + "trades", 40, + "Trades", + "View your available trades.", + "These trades are always", + "available and accessible through", + "the SkyBlock Menu.", + itemData = NormalItemData(Items.emerald), + requiresBoosterCookie = false + ), + ACCESSORY( + "accessories", 53, + "Accessory Bag", + "A special bag which can hold", + "Talismans, Rings, Artifacts, Relics, and", + "Orbs within it. All will still", + "work while in this bag!", + itemData = SkullItemData( + "2b73dd76-5fc1-4ac3-8139-6a8992f8ce80", + "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvOTYxYTkxOGMw" + + "YzQ5YmE4ZDA1M2U1MjJjYjkxYWJjNzQ2ODkzNjdiNGQ4YWEwNmJmYzFiYTkxNTQ3MzA5ODVmZiJ9fX0=" + ) + ), + POTION( + "potionbag", 52, + "Potion Bag", + "A handy bag for holding your", + "Potions in.", + itemData = SkullItemData( + "991c4a18-3283-4629-b0fc-bbce23cd658c", + "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvOWY4Yjg" + + "yNDI3YjI2MGQwYTYxZTY0ODNmYzNiMmMzNWE1ODU4NTFlMDhhOWE5ZGYzNzI1NDhiNDE2OGNjODE3YyJ9fX0=" + ) + ), + QUIVER( + "quiver", 44, + "Quiver", + "A masterfully crafted Quiver", + "which holds any kind of", + "projectile you can think of!", + itemData = SkullItemData( + "41758912-e6b1-4700-9de5-04f2cfb9c422", + "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNGNiM2FjZ" + + "GMxMWNhNzQ3YmY3MTBlNTlmNGM4ZTliM2Q5NDlmZGQzNjRjNjg2OTgzMWNhODc4ZjA3NjNkMTc4NyJ9fX0=" + ) + ), + FISHING( + "fishingbag", 43, + "Fishing Bag", + "A useful bag which can hold all", + "types of fish, baits, and fishing", + "loot!", + itemData = SkullItemData( + "508c01d6-eabe-430b-9811-874691ee7ee4", + "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZWI4ZT" + + "I5N2RmNmI4ZGZmY2YxMzVkYmE4NGVjNzkyZDQyMGFkOGVjYjQ1OGQxNDQyODg1NzJhODQ2MDNiMTYzMSJ9fX0=" + ) + ), + SACK_OF_SACKS( + "sacks", 35, + "Sack of Sacks", + "A sack which contains other", + "sacks. Sackception!", + itemData = SkullItemData( + "a206a7eb-70fc-4f9f-8316-c3f69d6ba2ca", + "ewogICJ0aW1lc3RhbXAiIDogMTU5MTMxMDU4NTYwOSwKICAicHJvZmlsZUlkIiA6ICI0MWQzYWJjMmQ3NDk0MDBjOTA5MGQ1NDM0" + + "ZDAzODMxYiIsCiAgInByb2ZpbGVOYW1lIiA6ICJNZWdha2xvb24iLAogICJzaWduYXR1cmVSZXF1aXJlZCIgOiB0cnVl" + + "LAogICJ0ZXh0dXJlcyIgOiB7CiAgICAiU0tJTiIgOiB7CiAgICAgICJ1cmwiIDogImh0dHA6Ly90ZXh0dXJlcy5taW5l" + + "Y3JhZnQubmV0L3RleHR1cmUvODBhMDc3ZTI0OGQxNDI3NzJlYTgwMDg2NGY4YzU3OGI5ZDM2ODg1YjI5ZGFmODM2YjY0" + + "YTcwNjg4MmI2ZWMxMCIKICAgIH0KICB9Cn0=" + ), + requiresBoosterCookie = false + ), + ; + + val itemWithCookieWarning: ItemStack by lazy { createItem(true) } + val itemWithoutCookieWarning: ItemStack by lazy { createItem(false) } + + private fun createItem(showCookieWarning: Boolean): ItemStack { + val lore = mutableListOf() + for (line in displayDescription) { + lore.add("§7$line") + } + lore.add("") + + if (showCookieWarning) { + lore.add("§cYou need a booster cookie active") + lore.add("§cto use this shortcut!") + } else { + lore.add("§eClick to execute /${command}") + } + val array = lore.toTypedArray() + val name = "§a${displayName}" + return when (itemData) { + is NormalItemData -> Utils.createItemStackArray(itemData.displayIcon, name, array) + is SkullItemData -> Utils.createSkull( + name, + itemData.uuid, + itemData.value, + array + ) + } + } + } + + sealed interface ItemData + + class NormalItemData(val displayIcon: Item) : ItemData + + class SkullItemData(val uuid: String, val value: String) : ItemData +} -- cgit From 5c58e19436f2935ae20cfb351ac6661b2dab1992 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal002@users.noreply.github.com> Date: Wed, 15 Feb 2023 18:48:11 +0100 Subject: API errors in console (#610) * Print api errors in console. * No reason not to just append. * Censor API Key --------- Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Co-authored-by: nea --- .../core/config/annotations/ConfigOption.java | 1 + .../moulberry/notenoughupdates/util/ApiUtil.java | 7 +++- .../moulberry/notenoughupdates/util/ErrorUtil.kt | 43 ++++++++++++++++++++++ 3 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 src/main/kotlin/io/github/moulberry/notenoughupdates/util/ErrorUtil.kt (limited to 'src/main/kotlin') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/config/annotations/ConfigOption.java b/src/main/java/io/github/moulberry/notenoughupdates/core/config/annotations/ConfigOption.java index 920cb326..ddd1e71f 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/core/config/annotations/ConfigOption.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/config/annotations/ConfigOption.java @@ -30,6 +30,7 @@ public @interface ConfigOption { String name(); String desc(); + String[] searchTags() default ""; int subcategoryId() default -1; diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/ApiUtil.java b/src/main/java/io/github/moulberry/notenoughupdates/util/ApiUtil.java index 023be060..45522329 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/util/ApiUtil.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/util/ApiUtil.java @@ -213,7 +213,12 @@ public class ApiUtil { } catch (IOException e) { throw new RuntimeException(e); // We can rethrow, since supplyAsync catches exceptions. } - }, executorService); + }, executorService).handle((obj, t) -> { + if (t != null) { + System.err.println(ErrorUtil.printStackTraceWithoutApiKey(t)); + } + return obj; + }); } public CompletableFuture requestJson() { diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/util/ErrorUtil.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/util/ErrorUtil.kt new file mode 100644 index 00000000..f849a40d --- /dev/null +++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/util/ErrorUtil.kt @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2023 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see . + */ + +package io.github.moulberry.notenoughupdates.util + +import io.github.moulberry.notenoughupdates.NotEnoughUpdates +import java.io.ByteArrayOutputStream +import java.io.PrintStream +import java.nio.charset.StandardCharsets + +object ErrorUtil { + @JvmStatic + fun printCensoredStackTrace(e: Throwable, toCensor: List): String { + val baos = ByteArrayOutputStream() + e.printStackTrace(PrintStream(baos, true, StandardCharsets.UTF_8.name())) + var string = String(baos.toByteArray(), StandardCharsets.UTF_8) + toCensor.forEach { + string = string.replace(it, "*".repeat(it.length)) + } + return string + } + + @JvmStatic + fun printStackTraceWithoutApiKey(e: Throwable): String { + return printCensoredStackTrace(e, listOf(NotEnoughUpdates.INSTANCE.config.apiData.apiKey)) + } +} -- cgit From d3ca199f904cd72e419c6320eda261f023c71937 Mon Sep 17 00:00:00 2001 From: Roman / Linnea Gräf Date: Wed, 15 Feb 2023 18:50:56 +0100 Subject: ApiUtil: Add cache with per request timeout and per class histogram (#592) * ApiUtil: Add cache with per request timeout and per class histogram * MinionHelper: Only load minion helper data when needed * Api: Make api response processing more async. * Lower cache for /pv to 30 seconds and rename cacheDuration to max age * Disk cache for the API --- .../notenoughupdates/auction/APIManager.java | 14 +- .../commands/dev/DevTestCommand.java | 20 ++ .../commands/misc/PronounsCommand.java | 2 +- .../notenoughupdates/cosmetics/CapeManager.java | 4 +- .../loaders/MinionHelperApiLoader.java | 7 +- .../options/customtypes/NEUDebugFlag.java | 5 + .../profileviewer/ProfileViewer.java | 2 + .../moulberry/notenoughupdates/util/ApiUtil.java | 38 +++- .../notenoughupdates/util/MinecraftExecutor.java | 37 ---- .../moulberry/notenoughupdates/util/ApiCache.kt | 215 +++++++++++++++++++++ .../notenoughupdates/util/MinecraftExecutor.kt | 47 +++++ 11 files changed, 335 insertions(+), 56 deletions(-) delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/util/MinecraftExecutor.java create mode 100644 src/main/kotlin/io/github/moulberry/notenoughupdates/util/ApiCache.kt create mode 100644 src/main/kotlin/io/github/moulberry/notenoughupdates/util/MinecraftExecutor.kt (limited to 'src/main/kotlin') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/auction/APIManager.java b/src/main/java/io/github/moulberry/notenoughupdates/auction/APIManager.java index 5ec3724a..ac60ffd9 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/auction/APIManager.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/auction/APIManager.java @@ -292,7 +292,7 @@ public class APIManager { .newMoulberryRequest("lowestbin.json.gz") .gunzip() .requestJson() - .thenAccept(jsonObject -> { + .thenAcceptAsync(jsonObject -> { if (lowestBins == null) { lowestBins = new JsonObject(); } @@ -465,12 +465,12 @@ public class APIManager { }; manager.apiUtils.newMoulberryRequest("auctionLast.json.gz") - .gunzip().requestJson().thenAccept(process); + .gunzip().requestJson().thenAcceptAsync(process); manager.apiUtils .newMoulberryRequest("auction.json.gz") .gunzip().requestJson() - .thenAccept(jsonObject -> { + .thenAcceptAsync(jsonObject -> { if (jsonObject.get("success").getAsBoolean()) { long apiUpdate = (long) jsonObject.get("time").getAsFloat(); if (lastApiUpdate == apiUpdate) { @@ -683,7 +683,7 @@ public class APIManager { manager.apiUtils .newAnonymousHypixelApiRequest("skyblock/auctions") .requestJson() - .thenAccept(jsonObject -> { + .thenAcceptAsync(jsonObject -> { if (jsonObject == null) return; if (jsonObject.get("success").getAsBoolean()) { @@ -733,7 +733,7 @@ public class APIManager { manager.apiUtils .newAnonymousHypixelApiRequest("skyblock/bazaar") .requestJson() - .thenAccept(jsonObject -> { + .thenAcceptAsync(jsonObject -> { if (!jsonObject.get("success").getAsBoolean()) return; craftCost.clear(); @@ -789,7 +789,7 @@ public class APIManager { public void updateAvgPrices() { manager.apiUtils .newMoulberryRequest("auction_averages/3day.json.gz") - .gunzip().requestJson().thenAccept((jsonObject) -> { + .gunzip().requestJson().thenAcceptAsync((jsonObject) -> { craftCost.clear(); auctionPricesJson = jsonObject; lastAuctionAvgUpdate = System.currentTimeMillis(); @@ -797,7 +797,7 @@ public class APIManager { manager.apiUtils .newMoulberryRequest("auction_averages_lbin/1day.json.gz") .gunzip().requestJson() - .thenAccept((jsonObject) -> { + .thenAcceptAsync((jsonObject) -> { auctionPricesAvgLowestBinJson = jsonObject; }); } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.java index 35474ff3..8dda864a 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.java @@ -33,11 +33,13 @@ import io.github.moulberry.notenoughupdates.miscfeatures.customblockzones.Locati import io.github.moulberry.notenoughupdates.miscfeatures.customblockzones.SpecialBlockZone; import io.github.moulberry.notenoughupdates.miscgui.GuiPriceGraph; import io.github.moulberry.notenoughupdates.miscgui.minionhelper.MinionHelperManager; +import io.github.moulberry.notenoughupdates.util.ApiCache; import io.github.moulberry.notenoughupdates.util.PronounDB; import io.github.moulberry.notenoughupdates.util.SBInfo; import io.github.moulberry.notenoughupdates.util.TabListUtils; import io.github.moulberry.notenoughupdates.util.Utils; import io.github.moulberry.notenoughupdates.util.hypixelapi.ProfileCollectionInfo; +import lombok.var; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiScreen; import net.minecraft.command.CommandException; @@ -126,6 +128,24 @@ public class DevTestCommand extends ClientCommandBase { Utils.addChatMessage(EnumChatFormatting.RED + DEV_FAIL_STRINGS[devFailIndex++]); return; } + if (args.length == 1 && args[0].equalsIgnoreCase("dumpapihistogram")) { + synchronized (ApiCache.INSTANCE) { + Utils.addChatMessage("§e[NEU] API Request Histogram"); + Utils.addChatMessage("§e[NEU] §bClass Name§e: §aCached§e/§cNonCached§e/§dTotal"); + ApiCache.INSTANCE.getHistogramTotalRequests().forEach((className, totalRequests) -> { + var nonCachedRequests = ApiCache.INSTANCE.getHistogramNonCachedRequests().getOrDefault(className, 0); + var cachedRequests = totalRequests - nonCachedRequests; + Utils.addChatMessage( + String.format( + "§e[NEU] §b%s §a%d§e/§c%d§e/§d%d", + className, + cachedRequests, + nonCachedRequests, + totalRequests + )); + }); + } + } if (args.length == 1 && args[0].equalsIgnoreCase("testprofile")) { NotEnoughUpdates.INSTANCE.manager.apiUtils.newHypixelApiRequest("skyblock/profiles") .queryArgument( diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/misc/PronounsCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/misc/PronounsCommand.java index 5a4f1400..cf0d0c56 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/commands/misc/PronounsCommand.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/commands/misc/PronounsCommand.java @@ -88,7 +88,7 @@ public class PronounsCommand extends ClientCommandBase { "§e[NEU] Pronouns for §b" + user + " §eon §b" + platform + "§e:"), id); betterPronounChoice.render().forEach(it -> nc.printChatMessage(new ChatComponentText("§e[NEU] §a" + it))); return null; - }, MinecraftExecutor.INSTANCE); + }, MinecraftExecutor.OnThread); } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/cosmetics/CapeManager.java b/src/main/java/io/github/moulberry/notenoughupdates/cosmetics/CapeManager.java index 4a7c1939..984a7931 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/cosmetics/CapeManager.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/cosmetics/CapeManager.java @@ -150,7 +150,7 @@ public class CapeManager { NotEnoughUpdates.INSTANCE.manager.apiUtils .newMoulberryRequest("activecapes.json") .requestJson() - .thenAccept(jsonObject -> { + .thenAcceptAsync(jsonObject -> { if (jsonObject.get("success").getAsBoolean()) { lastJsonSync = jsonObject; @@ -171,7 +171,7 @@ public class CapeManager { NotEnoughUpdates.INSTANCE.manager.apiUtils .newMoulberryRequest("permscapes.json") .requestJson() - .thenAccept(jsonObject -> { + .thenAcceptAsync(jsonObject -> { if (!jsonObject.get("success").getAsBoolean()) return; permSyncTries = 0; diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/loaders/MinionHelperApiLoader.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/loaders/MinionHelperApiLoader.java index aaa398f4..ecf02236 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/loaders/MinionHelperApiLoader.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/loaders/MinionHelperApiLoader.java @@ -47,7 +47,6 @@ import java.util.Map; public class MinionHelperApiLoader { private final MinionHelperManager manager; private boolean dirty = true; - private int ticks = 0; private boolean collectionApiEnabled = true; private boolean ignoreWorldSwitches = false; private boolean readyToUse = false; @@ -72,11 +71,7 @@ public class MinionHelperApiLoader { if (Minecraft.getMinecraft().thePlayer == null) return; if (!NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard()) return; if (!NotEnoughUpdates.INSTANCE.config.minionHelper.gui) return; - ticks++; - - if (ticks % 20 != 0) return; - - if (dirty) { + if (dirty && "Crafted Minions".equals(Utils.getOpenChestName())) { load(); } else { if (System.currentTimeMillis() > lastLoaded + 60_000 * 3) { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/customtypes/NEUDebugFlag.java b/src/main/java/io/github/moulberry/notenoughupdates/options/customtypes/NEUDebugFlag.java index 50f459c0..90ef93bb 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/options/customtypes/NEUDebugFlag.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/customtypes/NEUDebugFlag.java @@ -31,6 +31,7 @@ public enum NEUDebugFlag { WISHING("Wishing Compass Solver"), MAP("Dungeon Map Player Information"), SEARCH("SearchString Matches"), + API_CACHE("Api Cache"), ; private final String description; @@ -43,6 +44,10 @@ public enum NEUDebugFlag { return description; } + public void log(String message) { + NEUDebugLogger.log(this, message); + } + public boolean isSet() { return NEUDebugLogger.isFlagEnabled(this); } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ProfileViewer.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ProfileViewer.java index 17a14d1f..6f8427ae 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ProfileViewer.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ProfileViewer.java @@ -42,6 +42,7 @@ import net.minecraft.util.EnumChatFormatting; import javax.annotation.Nullable; import java.io.ByteArrayInputStream; import java.io.IOException; +import java.time.Duration; import java.util.ArrayList; import java.util.Arrays; import java.util.Base64; @@ -537,6 +538,7 @@ public class ProfileViewer { manager.apiUtils .newHypixelApiRequest("player") .queryArgument("name", nameF) + .maxCacheAge(Duration.ofSeconds(30)) .requestJson() .thenAccept(jsonObject -> { if ( diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/ApiUtil.java b/src/main/java/io/github/moulberry/notenoughupdates/util/ApiUtil.java index 45522329..28298fe0 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/util/ApiUtil.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/util/ApiUtil.java @@ -48,18 +48,26 @@ import java.security.KeyStoreException; import java.security.NoSuchAlgorithmException; import java.security.UnrecoverableKeyException; import java.security.cert.CertificateException; +import java.time.Duration; import java.util.ArrayList; import java.util.Collection; +import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.concurrent.CompletableFuture; +import java.util.concurrent.CompletionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.zip.GZIPInputStream; public class ApiUtil { private static final Gson gson = new Gson(); + + private static final Comparator nameValuePairComparator = Comparator + .comparing(NameValuePair::getName) + .thenComparing(NameValuePair::getValue); + private static final ExecutorService executorService = Executors.newFixedThreadPool(3); private static String getUserAgent() { if (NotEnoughUpdates.INSTANCE.config.hidden.customUserAgent != null) { @@ -110,6 +118,7 @@ public class ApiUtil { private final List queryArguments = new ArrayList<>(); private String baseUrl = null; private boolean shouldGunzip = false; + private Duration maxCacheAge = Duration.ofSeconds(500); private String method = "GET"; private String postData = null; private String postContentType = null; @@ -119,6 +128,15 @@ public class ApiUtil { return this; } + /** + * Specify a cache timeout of {@code null} to signify an uncacheable request. + * Non {@code GET} requests are always uncacheable. + */ + public Request maxCacheAge(Duration maxCacheAge) { + this.maxCacheAge = maxCacheAge; + return this; + } + public Request url(String baseUrl) { this.baseUrl = baseUrl; return this; @@ -160,7 +178,17 @@ public class ApiUtil { return fut; } - public CompletableFuture requestString() { + public String getBaseUrl() { + return baseUrl; + } + + private ApiCache.CacheKey getCacheKey() { + if (!"GET".equals(method)) return null; + queryArguments.sort(nameValuePairComparator); + return new ApiCache.CacheKey(baseUrl, queryArguments, shouldGunzip); + } + + private CompletableFuture requestString0() { return buildUrl().thenApplyAsync(url -> { try { InputStream inputStream = null; @@ -183,7 +211,7 @@ public class ApiUtil { conn.setDoOutput(true); OutputStream os = conn.getOutputStream(); try { - os.write(this.postData.getBytes("utf-8")); + os.write(this.postData.getBytes(StandardCharsets.UTF_8)); } finally { os.close(); } @@ -221,12 +249,16 @@ public class ApiUtil { }); } + public CompletableFuture requestString() { + return ApiCache.INSTANCE.cacheRequest(this, getCacheKey(), this::requestString0, maxCacheAge); + } + public CompletableFuture requestJson() { return requestJson(JsonObject.class); } public CompletableFuture requestJson(Class clazz) { - return requestString().thenApply(str -> gson.fromJson(str, clazz)); + return requestString().thenApplyAsync(str -> gson.fromJson(str, clazz)); } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/MinecraftExecutor.java b/src/main/java/io/github/moulberry/notenoughupdates/util/MinecraftExecutor.java deleted file mode 100644 index bf973b76..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/util/MinecraftExecutor.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (C) 2022 NotEnoughUpdates contributors - * - * This file is part of NotEnoughUpdates. - * - * NotEnoughUpdates is free software: you can redistribute it - * and/or modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation, either - * version 3 of the License, or (at your option) any later version. - * - * NotEnoughUpdates is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with NotEnoughUpdates. If not, see . - */ - -package io.github.moulberry.notenoughupdates.util; - -import net.minecraft.client.Minecraft; -import org.jetbrains.annotations.NotNull; - -import java.util.concurrent.Executor; - -public class MinecraftExecutor implements Executor { - - public static MinecraftExecutor INSTANCE = new MinecraftExecutor(); - - private MinecraftExecutor() {} - - @Override - public void execute(@NotNull Runnable runnable) { - Minecraft.getMinecraft().addScheduledTask(runnable); - } -} diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/util/ApiCache.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/util/ApiCache.kt new file mode 100644 index 00000000..c14df425 --- /dev/null +++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/util/ApiCache.kt @@ -0,0 +1,215 @@ +/* + * Copyright (C) 2023 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see . + */ + +package io.github.moulberry.notenoughupdates.util + +import io.github.moulberry.notenoughupdates.NotEnoughUpdates +import io.github.moulberry.notenoughupdates.options.customtypes.NEUDebugFlag +import io.github.moulberry.notenoughupdates.util.ApiUtil.Request +import org.apache.http.NameValuePair +import java.nio.file.Files +import java.nio.file.Path +import java.time.Duration +import java.util.* +import java.util.concurrent.CompletableFuture +import java.util.function.Supplier +import kotlin.io.path.deleteIfExists +import kotlin.io.path.readText +import kotlin.io.path.writeText +import kotlin.time.Duration.Companion.hours +import kotlin.time.Duration.Companion.seconds +import kotlin.time.ExperimentalTime +import kotlin.time.TimeSource +import kotlin.time.toKotlinDuration + +@OptIn(ExperimentalTime::class) + +object ApiCache { + data class CacheKey( + val baseUrl: String, + val requestParameters: List, + val shouldGunzip: Boolean, + ) + + data class CacheResult( + private var future: CompletableFuture?, + val firedAt: TimeSource.Monotonic.ValueTimeMark, + private var file: Path? = null, + private var disposed: Boolean = false, + ) { + init { + future!!.thenAcceptAsync { text -> + synchronized(this) { + if (disposed) { + return@synchronized + } + future = null + val f = Files.createTempFile(cacheBaseDir, "api-cache", ".bin") + log("Writing cache to disk: $f") + f.toFile().deleteOnExit() + f.writeText(text) + file = f + } + } + } + + val isAvailable get() = file != null && !disposed + + fun getCachedFuture(): CompletableFuture { + synchronized(this) { + if (disposed) { + return CompletableFuture.supplyAsync { + throw IllegalStateException("Attempting to read from a disposed future at $file. Most likely caused by non synchronized access to ApiCache.cachedRequests") + } + } + val fut = future + if (fut != null) { + return fut + } else { + val text = file!!.readText() + return CompletableFuture.completedFuture(text) + } + } + } + + /** + * Should be called when removing / replacing a request from [cachedRequests]. + * Should only be called while holding a lock on [ApiCache]. + * This deletes the disk cache and smashes the internal state for it to be GCd. + * After calling this method no other method may be called on this object. + */ + internal fun dispose() { + synchronized(this) { + if (disposed) return + log("Disposing cache for $file") + disposed = true + file?.deleteIfExists() + future = null + } + } + } + + private val cacheBaseDir by lazy { + val d = Files.createTempDirectory("neu-cache") + d.toFile().deleteOnExit() + d + } + private val cachedRequests = mutableMapOf() + val histogramTotalRequests: MutableMap = mutableMapOf() + val histogramNonCachedRequests: MutableMap = mutableMapOf() + + private val timeout = 10.seconds + private val globalMaxCacheAge = 1.hours + + private fun log(message: String) { + NEUDebugFlag.API_CACHE.log(message) + } + + private fun traceApiRequest( + request: Request, + failReason: String?, + ) { + if (!NotEnoughUpdates.INSTANCE.config.hidden.dev) return + val callingClass = Thread.currentThread().stackTrace + .find { + !it.className.startsWith("java.") && + !it.className.startsWith("kotlin.") && + it.className != ApiCache::class.java.name && + it.className != ApiUtil::class.java.name && + it.className != Request::class.java.name + } + val callingClassText = callingClass?.let { + "${it.className}.${it.methodName} (${it.fileName}:${it.lineNumber})" + } ?: "no calling class found" + callingClass?.className?.let { + histogramTotalRequests[it] = (histogramTotalRequests[it] ?: 0) + 1 + if (failReason != null) + histogramNonCachedRequests[it] = (histogramNonCachedRequests[it] ?: 0) + 1 + } + if (failReason != null) { + log("Executing api request for url ${request.baseUrl} by $callingClassText: $failReason") + } else { + log("Cache hit for api request for url ${request.baseUrl} by $callingClassText.") + } + } + + private fun evictCache() { + synchronized(this) { + val it = cachedRequests.iterator() + while (it.hasNext()) { + val next = it.next() + if (next.value.firedAt.elapsedNow() >= globalMaxCacheAge) { + next.value.dispose() + it.remove() + } + } + } + } + + fun cacheRequest( + request: Request, + cacheKey: CacheKey?, + futureSupplier: Supplier>, + maxAge: Duration? + ): CompletableFuture { + evictCache() + if (cacheKey == null) { + traceApiRequest(request, "uncacheable request (probably POST)") + return futureSupplier.get() + } + if (maxAge == null) { + traceApiRequest(request, "manually specified as uncacheable") + return futureSupplier.get() + } + fun recache(): CompletableFuture { + return futureSupplier.get().also { + cachedRequests[cacheKey]?.dispose() // Safe to dispose like this because this function is always called in a synchronized block + cachedRequests[cacheKey] = CacheResult(it, TimeSource.Monotonic.markNow()) + } + } + synchronized(this) { + val cachedRequest = cachedRequests[cacheKey] + if (cachedRequest == null) { + traceApiRequest(request, "no cache found") + return recache() + } + + return if (cachedRequest.isAvailable) { + if (cachedRequest.firedAt.elapsedNow() > maxAge.toKotlinDuration()) { + traceApiRequest(request, "outdated cache") + recache() + } else { + // Using local cached request + traceApiRequest(request, null) + cachedRequest.getCachedFuture() + } + } else { + if (cachedRequest.firedAt.elapsedNow() > timeout) { + traceApiRequest(request, "suspiciously slow api response") + recache() + } else { + // Joining ongoing request + traceApiRequest(request, null) + cachedRequest.getCachedFuture() + } + } + } + } + +} diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/util/MinecraftExecutor.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/util/MinecraftExecutor.kt new file mode 100644 index 00000000..bb0bc8b4 --- /dev/null +++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/util/MinecraftExecutor.kt @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2023 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see . + */ + +package io.github.moulberry.notenoughupdates.util + +import net.minecraft.client.Minecraft +import java.util.concurrent.Executor +import java.util.concurrent.ForkJoinPool + +object MinecraftExecutor { + + @JvmField + val OnThread = Executor { + val mc = Minecraft.getMinecraft() + if (mc.isCallingFromMinecraftThread) { + it.run() + } else { + Minecraft.getMinecraft().addScheduledTask(it) + } + } + + @JvmField + val OffThread = Executor { + val mc = Minecraft.getMinecraft() + if (mc.isCallingFromMinecraftThread) { + ForkJoinPool.commonPool().execute(it) + } else { + it.run() + } + } +} -- cgit From 0d281d483909d71272783033b2aba8f33dcbce36 Mon Sep 17 00:00:00 2001 From: Roman / Linnea Gräf Date: Sat, 18 Feb 2023 15:24:52 +0100 Subject: ApiCache: Fix apparent NullPointerException (#619) `CacheResult` should in theory have either a `file != null` a `future != null` or be `disposed`. Apparently this invariant of `CacheResult` is either being violated somewhere, or the `synchronized` blocks arent as synchronized as id hoped they were. In fact, `dispose()` does not even delete the file, so i can really only see this happening because the first `synchronized` block that writes the file and the second `synchronized` block that reads from the file hold the same lock. I have no idea how this would happen, but hopefully this fixes it (since the dispose didn't have a threading issue reported so far, i feel more confident leaving the .deleteOnExit in there, but I'm also wrapping any potential IOExceptions during access, because I am just so confused how the internal state was broken. --- .../moulberry/notenoughupdates/util/ApiCache.kt | 52 +++++++++++----------- .../util/kotlin/completablefuture.kt | 33 ++++++++++++++ 2 files changed, 60 insertions(+), 25 deletions(-) create mode 100644 src/main/kotlin/io/github/moulberry/notenoughupdates/util/kotlin/completablefuture.kt (limited to 'src/main/kotlin') diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/util/ApiCache.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/util/ApiCache.kt index c14df425..59fc2dd5 100644 --- a/src/main/kotlin/io/github/moulberry/notenoughupdates/util/ApiCache.kt +++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/util/ApiCache.kt @@ -22,6 +22,7 @@ package io.github.moulberry.notenoughupdates.util import io.github.moulberry.notenoughupdates.NotEnoughUpdates import io.github.moulberry.notenoughupdates.options.customtypes.NEUDebugFlag import io.github.moulberry.notenoughupdates.util.ApiUtil.Request +import io.github.moulberry.notenoughupdates.util.kotlin.supplyImmediate import org.apache.http.NameValuePair import java.nio.file.Files import java.nio.file.Path @@ -47,43 +48,45 @@ object ApiCache { val shouldGunzip: Boolean, ) - data class CacheResult( - private var future: CompletableFuture?, + data class CacheResult internal constructor( + var cacheState: CacheState, val firedAt: TimeSource.Monotonic.ValueTimeMark, - private var file: Path? = null, - private var disposed: Boolean = false, ) { - init { - future!!.thenAcceptAsync { text -> + constructor(future: CompletableFuture, firedAt: TimeSource.Monotonic.ValueTimeMark) : this( + CacheState.WaitingForFuture(future), + firedAt + ) { + future.thenAccept { text -> synchronized(this) { - if (disposed) { - return@synchronized - } - future = null val f = Files.createTempFile(cacheBaseDir, "api-cache", ".bin") log("Writing cache to disk: $f") f.toFile().deleteOnExit() f.writeText(text) - file = f + cacheState = CacheState.FileCached(f) } } } - val isAvailable get() = file != null && !disposed + sealed interface CacheState { + object Disposed : CacheState + data class WaitingForFuture(val future: CompletableFuture) : CacheState + data class FileCached(val file: Path) : CacheState + } + + val isAvailable get() = cacheState is CacheState.FileCached fun getCachedFuture(): CompletableFuture { synchronized(this) { - if (disposed) { - return CompletableFuture.supplyAsync { - throw IllegalStateException("Attempting to read from a disposed future at $file. Most likely caused by non synchronized access to ApiCache.cachedRequests") + return when (val cs = cacheState) { + CacheState.Disposed -> supplyImmediate { + throw IllegalStateException("Attempting to read from a disposed future. Most likely caused by non synchronized access to ApiCache.cachedRequests") } - } - val fut = future - if (fut != null) { - return fut - } else { - val text = file!!.readText() - return CompletableFuture.completedFuture(text) + + is CacheState.FileCached -> supplyImmediate { + cs.file.readText() + } + + is CacheState.WaitingForFuture -> cs.future } } } @@ -96,11 +99,10 @@ object ApiCache { */ internal fun dispose() { synchronized(this) { - if (disposed) return + val file = (cacheState as? CacheState.FileCached)?.file log("Disposing cache for $file") - disposed = true + cacheState = CacheState.Disposed file?.deleteIfExists() - future = null } } } diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/util/kotlin/completablefuture.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/util/kotlin/completablefuture.kt new file mode 100644 index 00000000..de45c1e3 --- /dev/null +++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/util/kotlin/completablefuture.kt @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2023 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see . + */ + +package io.github.moulberry.notenoughupdates.util.kotlin + +import java.util.concurrent.CompletableFuture + +inline fun supplyImmediate(block: () -> R): CompletableFuture { + val cf = CompletableFuture() + try { + cf.complete(block()) + } catch (t: Throwable) { + cf.completeExceptionally(t) + } + return cf +} + -- cgit From 30bd46e46aab73e2927fa5631c49ace84708e590 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal002@users.noreply.github.com> Date: Wed, 22 Feb 2023 18:30:38 +0100 Subject: HotmInformation rework (#611) * Rename .java to .kt * hotm rework. * Moved class to kotlin directory. * Removed debug. * Support for maxed out levels. * Fun fact of the day: Developer waste more time on the name of a variable than actual coding. * default is 0 --------- Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> --- .../moulberry/notenoughupdates/NEUManager.java | 3 - .../notenoughupdates/options/NEUConfig.java | 4 +- .../notenoughupdates/recipes/ForgeRecipe.java | 51 +++-- .../notenoughupdates/util/HotmInformation.java | 208 --------------------- .../notenoughupdates/util/HotmInformation.kt | 116 ++++++++++++ 5 files changed, 142 insertions(+), 240 deletions(-) delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/util/HotmInformation.java create mode 100644 src/main/kotlin/io/github/moulberry/notenoughupdates/util/HotmInformation.kt (limited to 'src/main/kotlin') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java index 5c3083a3..a001850e 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java @@ -37,7 +37,6 @@ import io.github.moulberry.notenoughupdates.recipes.NeuRecipe; import io.github.moulberry.notenoughupdates.recipes.RecipeHistory; import io.github.moulberry.notenoughupdates.util.ApiUtil; import io.github.moulberry.notenoughupdates.util.Constants; -import io.github.moulberry.notenoughupdates.util.HotmInformation; import io.github.moulberry.notenoughupdates.util.ItemResolutionQuery; import io.github.moulberry.notenoughupdates.util.ItemUtils; import io.github.moulberry.notenoughupdates.util.SBInfo; @@ -144,7 +143,6 @@ public class NEUManager { public File configLocation; public File repoLocation; public File configFile; - public HotmInformation hotm; public KatSitterOverlay katSitterOverlay; @@ -154,7 +152,6 @@ public class NEUManager { this.neu = neu; this.configLocation = configLocation; this.auctionManager = new APIManager(this); - this.hotm = new HotmInformation(neu); this.craftingOverlay = new CraftingOverlay(this); this.katSitterOverlay = new KatSitterOverlay(); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java b/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java index 6d6963e3..552cb5b1 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java @@ -75,7 +75,6 @@ import io.github.moulberry.notenoughupdates.overlays.TextOverlay; import io.github.moulberry.notenoughupdates.util.NotificationHandler; import io.github.moulberry.notenoughupdates.util.SBInfo; import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.Gui; import net.minecraft.client.gui.GuiScreen; import net.minecraftforge.client.ClientCommandHandler; @@ -603,6 +602,9 @@ public class NEUConfig extends Config { @Expose public boolean abiphoneShowOnlyFavourites = false; + + @Expose + public Map hotmTree = new HashMap<>(); } public HiddenLocationSpecific getLocationSpecific() { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/recipes/ForgeRecipe.java b/src/main/java/io/github/moulberry/notenoughupdates/recipes/ForgeRecipe.java index 47eb0d11..73b4f32d 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/recipes/ForgeRecipe.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/recipes/ForgeRecipe.java @@ -25,7 +25,9 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonPrimitive; import io.github.moulberry.notenoughupdates.NEUManager; +import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.miscgui.GuiItemRecipe; +import io.github.moulberry.notenoughupdates.options.NEUConfig; import io.github.moulberry.notenoughupdates.util.HotmInformation; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; @@ -35,7 +37,6 @@ import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.ResourceLocation; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Set; @@ -88,10 +89,6 @@ public class ForgeRecipe implements NeuRecipe { return output; } - public int getHotmLevel() { - return hotmLevel; - } - public int getTimeInSeconds() { return timeInSeconds; } @@ -166,30 +163,28 @@ public class ForgeRecipe implements NeuRecipe { @Override public void drawHoverInformation(GuiItemRecipe gui, int mouseX, int mouseY) { - manager.hotm.getInformationOnCurrentProfile().ifPresent(hotmTree -> { - if (timeInSeconds > 0 && gui.isWithinRect( - mouseX, mouseY, - gui.guiLeft + EXTRA_INFO_X - EXTRA_INFO_MAX_WIDTH / 2, - gui.guiTop + EXTRA_INFO_Y - 8, - EXTRA_INFO_MAX_WIDTH, 16 - )) { - int qf = hotmTree.getLevel("forge_time"); - int reducedTime = getReducedTime(qf); - if (qf > 0) { + NEUConfig.HiddenProfileSpecific profileSpecific = NotEnoughUpdates.INSTANCE.config.getProfileSpecific(); + if (profileSpecific == null) return; + + if (timeInSeconds <= 0 || !gui.isWithinRect( + mouseX, mouseY, + gui.guiLeft + EXTRA_INFO_X - EXTRA_INFO_MAX_WIDTH / 2, + gui.guiTop + EXTRA_INFO_Y - 8, + EXTRA_INFO_MAX_WIDTH, 16 + )) return; - Utils.drawHoveringText( - Arrays.asList( - EnumChatFormatting.YELLOW + formatDuration(reducedTime) + " with Quick Forge (Level " + qf + ")"), - mouseX, - mouseY, - gui.width, - gui.height, - 500, - Minecraft.getMinecraft().fontRendererObj - ); - } - } - }); + int level = profileSpecific.hotmTree.getOrDefault("Quick Forge", 0); + if (level == 0) return; + int reducedTime = getReducedTime(level); + + Utils.drawHoveringText( + Collections.singletonList( + EnumChatFormatting.YELLOW + formatDuration(reducedTime) + " with Quick Forge (Level " + level + ")"), + mouseX, mouseY, + gui.width, gui.height, + 500, + Minecraft.getMinecraft().fontRendererObj + ); } public int getReducedTime(int quickForgeUpgradeLevel) { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/HotmInformation.java b/src/main/java/io/github/moulberry/notenoughupdates/util/HotmInformation.java deleted file mode 100644 index 57c4ae3b..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/util/HotmInformation.java +++ /dev/null @@ -1,208 +0,0 @@ -/* - * Copyright (C) 2022 NotEnoughUpdates contributors - * - * This file is part of NotEnoughUpdates. - * - * NotEnoughUpdates is free software: you can redistribute it - * and/or modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation, either - * version 3 of the License, or (at your option) any later version. - * - * NotEnoughUpdates is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with NotEnoughUpdates. If not, see . - */ - -package io.github.moulberry.notenoughupdates.util; - -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import io.github.moulberry.notenoughupdates.NotEnoughUpdates; -import io.github.moulberry.notenoughupdates.events.ProfileDataLoadedEvent; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.inventory.GuiChest; -import net.minecraft.inventory.ContainerChest; -import net.minecraftforge.client.event.ClientChatReceivedEvent; -import net.minecraftforge.client.event.GuiOpenEvent; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.event.world.WorldEvent; -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; - -import java.util.HashMap; -import java.util.Map; -import java.util.Optional; -import java.util.Set; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.ConcurrentHashMap; - -public class HotmInformation { - private final NotEnoughUpdates neu; - public static final int[] EXPERIENCE_FOR_HOTM_LEVEL = { - // Taken from the wiki: https://hypixel-skyblock.fandom.com/wiki/Heart_of_the_Mountain#Experience_for_Each_Tier - 0, - 3000, - 12000, - 37000, - 97000, - 197000, - 347000 - }; - public static final int[] QUICK_FORGE_MULTIPLIERS = { - 985, - 970, - 955, - 940, - 925, - 910, - 895, - 880, - 865, - 850, - 845, - 840, - 835, - 830, - 825, - 820, - 815, - 810, - 805, - 700 - }; - private final Map profiles = new ConcurrentHashMap<>(); - - public static class Tree { - private final Map levels = new HashMap<>(); - private int totalMithrilPowder; - private int totalGemstonePowder; - private int hotmExp; - - public int getHotmExp() { - return hotmExp; - } - - public int getTotalGemstonePowder() { - return totalGemstonePowder; - } - - public int getTotalMithrilPowder() { - return totalMithrilPowder; - } - - public Set getAllUnlockedNodes() { - return levels.keySet(); - } - - public int getHotmLevel() { - for (int i = EXPERIENCE_FOR_HOTM_LEVEL.length - 1; i >= 0; i--) { - if (EXPERIENCE_FOR_HOTM_LEVEL[i] >= this.hotmExp) - return i; - } - return 0; - } - - public int getLevel(String node) { - return levels.getOrDefault(node, 0); - } - - } - - private CompletableFuture updateTask = CompletableFuture.completedFuture(null); - - private boolean shouldReloadSoon = false; - - public HotmInformation(NotEnoughUpdates neu) { - this.neu = neu; - MinecraftForge.EVENT_BUS.register(this); - } - - public Optional getInformationOn(String profile) { - if (profile == null) { - return Optional.empty(); - } - return Optional.ofNullable(this.profiles.get(profile)); - } - - public Optional getInformationOnCurrentProfile() { - return getInformationOn(neu.manager.getCurrentProfile()); - } - - @SubscribeEvent - public synchronized void onLobbyJoin(WorldEvent.Load event) { - if (shouldReloadSoon) { - shouldReloadSoon = false; - neu.manager.apiUtils.updateProfileData(); - } - } - - @SubscribeEvent - public synchronized void onGuiOpen(GuiOpenEvent event) { - if (event.gui instanceof GuiChest) { - String containerName = ((ContainerChest) ((GuiChest) event.gui).inventorySlots) - .getLowerChestInventory() - .getDisplayName() - .getUnformattedText(); - if (containerName.equals("Heart of the Mountain")) - shouldReloadSoon = true; - } - } - - @SubscribeEvent - public synchronized void onChat(ClientChatReceivedEvent event) { - if (event.message.getUnformattedText().equals("Welcome to Hypixel SkyBlock!")) - neu.manager.apiUtils.updateProfileData(); - } - - /* - * 1000 = 100% of the time left - * 700 = 70% of the time left - * */ - public static int getQuickForgeMultiplier(int level) { - if (level <= 0) return 1000; - if (level > 20) return -1; - return QUICK_FORGE_MULTIPLIERS[level - 1]; - } - @SubscribeEvent - public void onApiDataLoaded(ProfileDataLoadedEvent event) { - JsonObject data = event.getData(); - if (data == null) return; - - if (!data.has("success") || !data.get("success").getAsBoolean()) return; - JsonArray profiles = data.getAsJsonArray("profiles"); - for (JsonElement element : profiles) { - JsonObject profile = element.getAsJsonObject(); - String profileName = profile.get("cute_name").getAsString(); - JsonObject player = profile.getAsJsonObject("members").getAsJsonObject(Minecraft.getMinecraft().thePlayer - .getUniqueID() - .toString() - .replace("-", "")); - if (!player.has("mining_core")) - continue; - JsonObject miningCore = player.getAsJsonObject("mining_core"); - Tree tree = new Tree(); - JsonObject nodes = miningCore.getAsJsonObject("nodes"); - for (Map.Entry node : nodes.entrySet()) { - String key = node.getKey(); - if (!key.startsWith("toggle_")) { - tree.levels.put(key, node.getValue().getAsInt()); - } - } - if (miningCore.has("powder_mithril_total")) { - tree.totalMithrilPowder = miningCore.get("powder_mithril_total").getAsInt(); - } - if (miningCore.has("powder_gemstone_total")) { - tree.totalGemstonePowder = miningCore.get("powder_gemstone_total").getAsInt(); - } - if (miningCore.has("experience")) { - tree.hotmExp = miningCore.get("experience").getAsInt(); - } - this.profiles.put(profileName, tree); - } - } - -} diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/util/HotmInformation.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/util/HotmInformation.kt new file mode 100644 index 00000000..a2a61064 --- /dev/null +++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/util/HotmInformation.kt @@ -0,0 +1,116 @@ +/* + * Copyright (C) 2023 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see . + */ + +package io.github.moulberry.notenoughupdates.util + +import io.github.moulberry.notenoughupdates.NotEnoughUpdates +import io.github.moulberry.notenoughupdates.autosubscribe.NEUAutoSubscribe +import io.github.moulberry.notenoughupdates.core.util.StringUtils +import net.minecraft.client.Minecraft +import net.minecraft.client.gui.inventory.GuiChest +import net.minecraft.inventory.ContainerChest +import net.minecraftforge.client.event.GuiOpenEvent +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import net.minecraftforge.fml.common.gameevent.TickEvent +import java.util.regex.Pattern + +@NEUAutoSubscribe +class HotmInformation { + private var ticksTillReload = 0 + private val pattern = Pattern.compile("§[7b]Level (\\d*)(?:§8/.*)?") + + @SubscribeEvent + fun onGuiOpen(event: GuiOpenEvent) { + val gui = event.gui + if (gui !is GuiChest) return + + val containerName = (gui.inventorySlots as ContainerChest).lowerChestInventory.displayName.unformattedText + if (containerName == "Heart of the Mountain") { + ticksTillReload = 5 + } + } + + @SubscribeEvent + fun onTick(event: TickEvent.ClientTickEvent) { + if (event.phase != TickEvent.Phase.START) return + if (ticksTillReload == 0) return + ticksTillReload-- + if (ticksTillReload == 0) { + loadDataFromInventory() + } + } + + private fun loadDataFromInventory() { + val profileSpecific = NotEnoughUpdates.INSTANCE.config.profileSpecific ?: return + + for (slot in Minecraft.getMinecraft().thePlayer.openContainer.inventorySlots) { + val stack = slot.stack ?: continue + val displayName = stack.displayName + val lore = ItemUtils.getLore(stack) + if (!lore.any { it.contains("Right click to") }) continue + + val perkName = StringUtils.cleanColour(displayName) + profileSpecific.hotmTree[perkName] = getLevel(lore[0]) + } + } + + private fun getLevel(string: String): Int { + val matcher = pattern.matcher(string) + val level = if (matcher.matches()) matcher.group(1).toInt() else 1 + + val withBlueCheeseGoblinOmelette = string.contains("§b") + val isNotMaxed = string.contains("§8/") + return if (withBlueCheeseGoblinOmelette && (isNotMaxed || level > 1)) level - 1 else level + } + + companion object { + private val QUICK_FORGE_MULTIPLIERS = intArrayOf( + 985, + 970, + 955, + 940, + 925, + 910, + 895, + 880, + 865, + 850, + 845, + 840, + 835, + 830, + 825, + 820, + 815, + 810, + 805, + 700 + ) + + /* + * 1000 = 100% of the time left + * 700 = 70% of the time left + * */ + @JvmStatic + fun getQuickForgeMultiplier(level: Int): Int { + if (level <= 0) return 1000 + return if (level > 20) -1 else QUICK_FORGE_MULTIPLIERS[level - 1] + } + } +} -- cgit From cf3f08e4fd340ab331a4b61c1159fb527027ade7 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal002@users.noreply.github.com> Date: Wed, 22 Feb 2023 18:33:20 +0100 Subject: Added Sky Mall to Dwarven Overlay (#604) * Added Sky Mall to Dwarven Overlay. * Made SkyBlockTime a data object. * Added color to names and display item per different perk variant. * Added daySuffix support for days greater 10. * Data classes have a copy method already. * Green color does not work. * Fixed a bug in monthName. * Add Unit Tests and make use of Instant * Fixed Sky Mall overlay showing in crystal hollows. * 11st 12nd 13rd --------- Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Co-authored-by: nea Co-authored-by: nopo --- .../notenoughupdates/miscgui/CalendarOverlay.java | 8 +- .../options/seperateSections/Mining.java | 15 +-- .../notenoughupdates/overlays/MiningOverlay.java | 32 ++++-- .../notenoughupdates/guifeatures/SkyMallDisplay.kt | 103 +++++++++++++++++ .../notenoughupdates/util/SkyBlockTime.kt | 122 +++++++++++++++++++++ .../notenoughupdates/util/SkyBlockTimeTest.kt | 66 +++++++++++ 6 files changed, 325 insertions(+), 21 deletions(-) create mode 100644 src/main/kotlin/io/github/moulberry/notenoughupdates/guifeatures/SkyMallDisplay.kt create mode 100644 src/main/kotlin/io/github/moulberry/notenoughupdates/util/SkyBlockTime.kt create mode 100644 src/test/kotlin/io/github/moulberry/notenoughupdates/util/SkyBlockTimeTest.kt (limited to 'src/main/kotlin') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/CalendarOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/CalendarOverlay.java index 301a90b9..baea367c 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/CalendarOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/CalendarOverlay.java @@ -129,11 +129,11 @@ public class CalendarOverlay { private static final long HOUR = MINUTE * 60; private static final long DAY = HOUR * 24; - private static final long DA_OFFSET = 1000 * 60 * 55; - private static final long JF_OFFSET = 1000 * 60 * 15; + private static final long DA_OFFSET = 1000 * 60 * 55; // Dark Auction + private static final long JF_OFFSET = 1000 * 60 * 15; // Jacob's Farming Contest - private static final ItemStack DA_STACK; - private static final ItemStack JF_STACK; + private static final ItemStack DA_STACK; // Dark Auction + private static final ItemStack JF_STACK; // Jacob's Farming Contest static { NBTTagCompound tag = new NBTTagCompound(); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Mining.java b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Mining.java index 74400f59..e1b2662a 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Mining.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Mining.java @@ -152,16 +152,17 @@ public class Mining { ) @ConfigEditorDraggableList( exampleText = { - "\u00a73Goblin Slayer: \u00a7626.5%\n\u00a73Lucky Raffle: \u00a7c0.0%", - "\u00a73Mithril Powder: \u00a726,243", - "\u00a73Gemstone Powder: \u00a7d6,243", - "\u00a73Forge 1) \u00a79Diamonite\u00a77: \u00a7aReady!", - "\u00a73Pickaxe CD: \u00a7a78s", - "\u00a73Star Cult: \u00a7a78s" + "§3Goblin Slayer: §626.5%\n§3Lucky Raffle: §c0.0%", + "§3Mithril Powder: §26,243", + "§3Gemstone Powder: §d6,243", + "§3Forge 1) §9Diamonite§7: §aReady!", + "§3Pickaxe CD: §a78s", + "§3Star Cult: §a78s", + "§3Sky Mall: §a5x Titanium (78s)" } ) @ConfigAccordionId(id = 2) - public List dwarvenText2 = new ArrayList<>(Arrays.asList(0, 1, 2, 3, 4, 5)); + public List dwarvenText2 = new ArrayList<>(Arrays.asList(0, 1, 2, 3, 4, 5, 6)); @Expose public Position overlayPosition = new Position(10, 100); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/overlays/MiningOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/overlays/MiningOverlay.java index ea253e94..db1a7755 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/overlays/MiningOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/overlays/MiningOverlay.java @@ -24,6 +24,7 @@ import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.core.config.Position; import io.github.moulberry.notenoughupdates.core.util.StringUtils; import io.github.moulberry.notenoughupdates.core.util.lerp.LerpUtils; +import io.github.moulberry.notenoughupdates.guifeatures.SkyMallDisplay; import io.github.moulberry.notenoughupdates.miscfeatures.ItemCooldowns; import io.github.moulberry.notenoughupdates.options.NEUConfig; import io.github.moulberry.notenoughupdates.util.SBInfo; @@ -45,6 +46,7 @@ import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.function.Supplier; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -439,6 +441,12 @@ public class MiningOverlay extends TextTabOverlay { DARK_AQUA + "Star Cult: " + GREEN + StarCultCalculator.getNextStarCult()); break; + case 6: + + if (Objects.equals(SBInfo.getInstance().getLocation(), "mining_3")) { + overlayStrings.add("§3Sky Mall: §a" + SkyMallDisplay.Companion.getDisplayText()); + } + break; } } } else { @@ -714,17 +722,17 @@ public class MiningOverlay extends TextTabOverlay { String cleaned = Utils.cleanColour(line); String beforeColon = cleaned.split(":")[0]; - if (miningOverlayCommisionItems == null) { - setupMiningOverlayCommisionItems(); + if (miningOverlayCommissionItems == null) { + setupMiningOverlayCommissionItems(); } - if (miningOverlayCommisionItems.containsKey(beforeColon)) { - icon = miningOverlayCommisionItems.get(beforeColon); + if (miningOverlayCommissionItems.containsKey(beforeColon)) { + icon = miningOverlayCommissionItems.get(beforeColon); } else { if (beforeColon.startsWith("Forge")) { - icon = miningOverlayCommisionItems.get("Forge"); + icon = miningOverlayCommissionItems.get("Forge"); } else if (beforeColon.contains("Mithril")) { - icon = miningOverlayCommisionItems.get("Mithril"); + icon = miningOverlayCommissionItems.get("Mithril"); } else if (beforeColon.endsWith(" Gemstone Collector")) { String gemName = "ROUGH_" + beforeColon.replace(" Gemstone Collector", "").toUpperCase() + "_GEM"; @@ -748,7 +756,11 @@ public class MiningOverlay extends TextTabOverlay { miningOverlayPerfectGems.put(gemName, icon); } } else if (beforeColon.contains("Titanium")) { - icon = miningOverlayCommisionItems.get("Titanium"); + icon = miningOverlayCommissionItems.get("Titanium"); + } else if (beforeColon.contains("Sky Mall")) { + if (Objects.equals(SBInfo.getInstance().getLocation(), "mining_3")) { + icon = SkyMallDisplay.Companion.getDisplayItem(); + } } } @@ -768,10 +780,10 @@ public class MiningOverlay extends TextTabOverlay { private static final HashMap miningOverlayRoughGems = new HashMap() {}; private static final HashMap miningOverlayPerfectGems = new HashMap() {}; - private static HashMap miningOverlayCommisionItems; + private static HashMap miningOverlayCommissionItems; - private static void setupMiningOverlayCommisionItems() { - miningOverlayCommisionItems = new HashMap() {{ + private static void setupMiningOverlayCommissionItems() { + miningOverlayCommissionItems = new HashMap() {{ put( "Mithril Powder", NotEnoughUpdates.INSTANCE.manager.jsonToStack(NotEnoughUpdates.INSTANCE.manager diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/guifeatures/SkyMallDisplay.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/guifeatures/SkyMallDisplay.kt new file mode 100644 index 00000000..2821473b --- /dev/null +++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/guifeatures/SkyMallDisplay.kt @@ -0,0 +1,103 @@ +/* + * Copyright (C) 2023 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see . + */ + +package io.github.moulberry.notenoughupdates.guifeatures + +import io.github.moulberry.notenoughupdates.NotEnoughUpdates +import io.github.moulberry.notenoughupdates.autosubscribe.NEUAutoSubscribe +import io.github.moulberry.notenoughupdates.util.SBInfo +import io.github.moulberry.notenoughupdates.util.SkyBlockTime +import io.github.moulberry.notenoughupdates.util.Utils +import net.minecraft.init.Items +import net.minecraft.item.ItemStack +import net.minecraftforge.client.event.ClientChatReceivedEvent +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import java.time.Duration +import java.time.Instant +import java.util.regex.Pattern + +@NEUAutoSubscribe +class SkyMallDisplay { + + private val pattern = Pattern.compile("§r§eNew buff§r§r§r: (.*)§r") + + @SubscribeEvent(receiveCanceled = true) + fun onChatReceive(event: ClientChatReceivedEvent) { + if (!NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard()) return + if (SBInfo.getInstance().getLocation() != "mining_3") return + + val matcher = pattern.matcher(event.message.formattedText) + if (!matcher.matches()) return + + val message = matcher.group(1) ?: return + currentPerk = SkyMallPerk.values().find { it.chatMessage == message } + + currentPerk?.let { + val manager = NotEnoughUpdates.INSTANCE.manager + displayItem = manager.jsonToStack(manager.itemInformation[it.displayItemId]) + } + } + + companion object { + private var displayText = "" + private var displayItem: ItemStack? = null + private var lastUpdated = 0L + private var currentPerk: SkyMallPerk? = null + + fun getDisplayText(): String { + return if (lastUpdated + 1_000 > System.currentTimeMillis()) { + displayText + } else { + update() + displayText + } + } + + fun getDisplayItem(): ItemStack { + return displayItem ?: ItemStack(Items.apple) + } + + private fun update() { + val nextDayBeginning = SkyBlockTime.now() + .let { it.copy(day = it.day + 1, hour = 0, minute = 0, second = 0) } + .toInstant() + val untilNextDay = Duration.between(Instant.now(), nextDayBeginning) + displayText = (currentPerk?.displayName ?: "?") + " §a(${ + Utils.prettyTime(untilNextDay.toMillis()) + })" + lastUpdated = System.currentTimeMillis() + } + } + + enum class SkyMallPerk(val displayName: String, val displayItemId: String, val chatMessage: String) { + PICKAXE_COOLDOWN( + "20% §6Pickaxe Ability cooldown", "DIAMOND_PICKAXE", + "§r§fReduce Pickaxe Ability cooldown by §r§a20%§r§f." + ), + MORE_POWDER("+15% more §6Powder", "MITHRIL_ORE", "§r§fGain §r§a+15% §r§fmore Powder while mining."), + MINING_FORTUNE("+50 §6☘ Mining Fortune", "ENCHANTED_RABBIT_FOOT", "§r§fGain §r§a+50 §r§6☘ Mining Fortune§r§f."), + MINING_SPEED("+100 §6⸕ Mining Speed", "ENCHANTED_FEATHER", "§r§fGain §r§a+100 §r§6⸕ Mining Speed§r§f."), + MORE_GOBLINS("10x §6Goblin chance", "GOBLIN_HELMET", "§r§f§r§a10x §r§fchance to find Goblins while mining."), + TITANIUM_DROPS("5x §9Titanium drops", "TITANIUM_ORE", "§r§fGain §r§a5x §r§9Titanium §r§fdrops"), + + // In case hypixel finds some day the missing dot at the end. + TITANIUM_DROPS_WITH_DOT("5x §9Titanium drops", "TITANIUM_ORE", "§r§fGain §r§a5x §r§9Titanium §r§fdrops."), + ; + } +} diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/util/SkyBlockTime.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/util/SkyBlockTime.kt new file mode 100644 index 00000000..8ceb1c51 --- /dev/null +++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/util/SkyBlockTime.kt @@ -0,0 +1,122 @@ +/* + * Copyright (C) 2023 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see . + */ + +package io.github.moulberry.notenoughupdates.util + +import java.time.Instant + +data class SkyBlockTime( + val year: Int = 1, + val month: Int = 1, + val day: Int = 1, + val hour: Int = 0, + val minute: Int = 0, + val second: Int = 0, +) { + + val monthName get() = monthName(month) + val dayName get() = "$day${daySuffix(day)}" + + + fun toInstant(): Instant? { + return Instant.ofEpochMilli(toMillis()) + } + + fun toMillis(): Long { + val skyBlockYear = 124 * 60 * 60.0 + val skyBlockMonth = skyBlockYear / 12 + val skyBlockDay = skyBlockMonth / 31 + val skyBlockHour = skyBlockDay / 24 + val skyBlockMinute = skyBlockHour / 60 + val skyBlockSecond = skyBlockMinute / 60 + + var time = 0.0 + time += year * skyBlockYear + time += (month - 1) * skyBlockMonth + time += (day - 1) * skyBlockDay + time += hour * skyBlockHour + time += minute * skyBlockMinute + time += second * skyBlockSecond + time += 1559829300 + return time.toLong() * 1000 + } + + companion object { + fun fromInstant(instant: Instant): SkyBlockTime { + val skyBlockTimeZero = 1559829300000 // Day 1, Year 1 + var realMillis = (instant.toEpochMilli() - skyBlockTimeZero) + + val skyBlockYear = 124 * 60 * 60 * 1000 + val skyBlockMonth = skyBlockYear / 12 + val skyBlockDay = skyBlockMonth / 31 + val skyBlockHour = skyBlockDay / 24 + val skyBlockMinute = skyBlockHour / 60 + val skyBlockSecond = skyBlockMinute / 60 + + fun getUnit(factor: Int): Int { + val result = realMillis / factor + realMillis %= factor + return result.toInt() + } + + val year = getUnit(skyBlockYear) + val month = getUnit(skyBlockMonth) + 1 + val day = getUnit(skyBlockDay) + 1 + val hour = getUnit(skyBlockHour) + val minute = getUnit(skyBlockMinute) + val second = getUnit(skyBlockSecond) + return SkyBlockTime(year, month, day, hour, minute, second) + + } + + fun now(): SkyBlockTime { + return fromInstant(Instant.now()) + } + + fun monthName(month: Int): String { + val prefix = when ((month - 1) % 3) { + 0 -> "Early " + 1 -> "" + 2 -> "Late " + else -> "Undefined!" + } + + val name = when ((month - 1) / 3) { + 0 -> "Spring" + 1 -> "Summer" + 2 -> "Autumn" + 3 -> "Winter" + else -> "lol" + } + + return prefix + name + } + + fun daySuffix(n: Int): String { + return if (n in 11..13) { + "th" + } else when (n % 10) { + 1 -> "st" + 2 -> "nd" + 3 -> "rd" + else -> "th" + } + } + } +} diff --git a/src/test/kotlin/io/github/moulberry/notenoughupdates/util/SkyBlockTimeTest.kt b/src/test/kotlin/io/github/moulberry/notenoughupdates/util/SkyBlockTimeTest.kt new file mode 100644 index 00000000..8d762460 --- /dev/null +++ b/src/test/kotlin/io/github/moulberry/notenoughupdates/util/SkyBlockTimeTest.kt @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2023 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see . + */ + +package io.github.moulberry.notenoughupdates.util + +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test +import java.time.Instant + +class SkyBlockTimeTest { + @Test + fun someRandomTimestamp() { + val sbt = SkyBlockTime.fromInstant(Instant.ofEpochSecond(1676236163L)) + assertEquals(SkyBlockTime(260, 10, 7, 17, 15, 38), sbt) + assertEquals("Early Winter", sbt.monthName) + } + + @Test + fun isReversibleEquivalent() { + val ts = 167623132230L + val someTimeStamp = Instant.ofEpochSecond(ts) + assertEquals(someTimeStamp.toEpochMilli(), SkyBlockTime.fromInstant(someTimeStamp).toMillis()) + } + + @Test + fun monthNames() { + assertEquals( + listOf( + "Early Spring", + "Spring", + "Late Spring", + "Early Summer", + "Summer", + "Late Summer", + "Early Autumn", + "Autumn", + "Late Autumn", + "Early Winter", + "Winter", + "Late Winter" + ), (1..12).map { SkyBlockTime.monthName(it) }) + } + + @Test + fun theOriginOfTime() { + assertEquals(SkyBlockTime(year = 0), SkyBlockTime.fromInstant(Instant.ofEpochMilli(1559829300000L))) + } + + +} -- cgit From df945f9d58d4f40f9adc4727c4f8d548b21fa4b0 Mon Sep 17 00:00:00 2001 From: Roman / Linnea Gräf Date: Fri, 24 Feb 2023 15:17:10 +0100 Subject: Museum: Display hydrated items for items taken outside of the repo (#621) Co-authored-by: Lulonaut --- Update Notes/2.1.1.md | 1 - .../moulberry/notenoughupdates/NEUManager.java | 14 +-- .../events/GuiContainerBackgroundDrawnEvent.java | 29 +++++ .../notenoughupdates/mixins/MixinGuiContainer.java | 3 +- .../notenoughupdates/options/NEUConfig.java | 8 ++ .../options/seperateSections/Museum.java | 45 ++++++++ .../notenoughupdates/util/ItemResolutionQuery.java | 74 +++++++++---- .../moulberry/notenoughupdates/util/LRUCache.java | 11 +- .../inventory/MuseumItemHighlighter.kt | 121 +++++++++++++++++++++ .../notenoughupdates/util/KotlinStringUtils.kt | 24 ++++ .../moulberry/notenoughupdates/util/MuseumUtil.kt | 113 +++++++++++++++++++ 11 files changed, 410 insertions(+), 33 deletions(-) create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/events/GuiContainerBackgroundDrawnEvent.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Museum.java create mode 100644 src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/inventory/MuseumItemHighlighter.kt create mode 100644 src/main/kotlin/io/github/moulberry/notenoughupdates/util/KotlinStringUtils.kt create mode 100644 src/main/kotlin/io/github/moulberry/notenoughupdates/util/MuseumUtil.kt (limited to 'src/main/kotlin') diff --git a/Update Notes/2.1.1.md b/Update Notes/2.1.1.md index eb6fcc31..47a0d207 100644 --- a/Update Notes/2.1.1.md +++ b/Update Notes/2.1.1.md @@ -8,7 +8,6 @@ - Added universal GUI editor - nopo - Added Essenceupgrades GUI - Lulonaut - Added Katsitting recipe upgrade - nea89 -- Added cheapest museum item overlay - Lulonaut - Added Frozen Treasure Highlighter - heyngra - Added SkyBlock levels to PV - efefury diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java index a001850e..5eab77f9 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java @@ -102,7 +102,7 @@ public class NEUManager { private final TreeMap itemMap = new TreeMap<>(); private boolean hasBeenLoadedBefore = false; - private final TreeMap>> titleWordMap = new TreeMap<>(); + public final TreeMap>> titleWordMap = new TreeMap<>(); private final TreeMap>> loreWordMap = new TreeMap<>(); public final KeyBinding keybindGive = @@ -320,7 +320,7 @@ public class NEUManager { synchronized (titleWordMap) { int wordIndex = 0; for (String str : json.get("displayname").getAsString().split(" ")) { - str = clean(str); + str = cleanForTitleMapSearch(str); if (!titleWordMap.containsKey(str)) { titleWordMap.put(str, new HashMap<>()); } @@ -338,7 +338,7 @@ public class NEUManager { int wordIndex = 0; for (JsonElement element : json.get("lore").getAsJsonArray()) { for (String str : element.getAsString().split(" ")) { - str = clean(str); + str = cleanForTitleMapSearch(str); if (!loreWordMap.containsKey(str)) { loreWordMap.put(str, new HashMap<>()); } @@ -466,8 +466,8 @@ public class NEUManager { int lastStringMatch = -1; ArrayList debugMatches = new ArrayList<>(); - toSearch = clean(toSearch).toLowerCase(); - query = clean(query).toLowerCase(); + toSearch = cleanForTitleMapSearch(toSearch).toLowerCase(); + query = cleanForTitleMapSearch(query).toLowerCase(); String[] splitToSearch = toSearch.split(" "); String[] queryArray = query.split(" "); @@ -684,7 +684,7 @@ public class NEUManager { public Set search(String query, TreeMap>> wordMap) { HashMap> matches = null; - query = clean(query).toLowerCase(); + query = cleanForTitleMapSearch(query).toLowerCase(); for (String queryWord : query.split(" ")) { HashMap> matchesToKeep = new HashMap<>(); for (HashMap> wordMatches : subMapWithKeysThatAreSuffixes(queryWord, wordMap).values()) { @@ -859,7 +859,7 @@ public class NEUManager { return item; } - private String clean(String str) { + public static String cleanForTitleMapSearch(String str) { return str.replaceAll("(\u00a7.)|[^0-9a-zA-Z ]", "").toLowerCase().trim(); } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/events/GuiContainerBackgroundDrawnEvent.java b/src/main/java/io/github/moulberry/notenoughupdates/events/GuiContainerBackgroundDrawnEvent.java new file mode 100644 index 00000000..bdb6d1a1 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/events/GuiContainerBackgroundDrawnEvent.java @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see . + */ + +package io.github.moulberry.notenoughupdates.events; + +import lombok.Value; +import net.minecraft.client.gui.inventory.GuiContainer; + +@Value +public class GuiContainerBackgroundDrawnEvent extends NEUEvent { + public GuiContainer container; + public float partialTicks; +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiContainer.java b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiContainer.java index a5bb99b8..8aca73d1 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiContainer.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiContainer.java @@ -21,6 +21,7 @@ package io.github.moulberry.notenoughupdates.mixins; import io.github.moulberry.notenoughupdates.NEUOverlay; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; +import io.github.moulberry.notenoughupdates.events.GuiContainerBackgroundDrawnEvent; import io.github.moulberry.notenoughupdates.events.SlotClickEvent; import io.github.moulberry.notenoughupdates.listener.RenderListener; import io.github.moulberry.notenoughupdates.miscfeatures.AbiphoneFavourites; @@ -330,6 +331,6 @@ public abstract class MixinGuiContainer extends GuiScreen { @Inject(method = "drawScreen", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/GlStateManager;color(FFFF)V", ordinal = 1)) private void drawBackground(int mouseX, int mouseY, float partialTicks, CallbackInfo ci) { - AbiphoneFavourites.getInstance().onDrawBackground(this); + new GuiContainerBackgroundDrawnEvent(((GuiContainer) (Object) this), partialTicks).post(); } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java b/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java index 552cb5b1..e9c34e03 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java @@ -56,6 +56,7 @@ import io.github.moulberry.notenoughupdates.options.seperateSections.Mining; import io.github.moulberry.notenoughupdates.options.seperateSections.MinionHelper; import io.github.moulberry.notenoughupdates.options.seperateSections.Misc; import io.github.moulberry.notenoughupdates.options.seperateSections.MiscOverlays; +import io.github.moulberry.notenoughupdates.options.seperateSections.Museum; import io.github.moulberry.notenoughupdates.options.seperateSections.NeuAuctionHouse; import io.github.moulberry.notenoughupdates.options.seperateSections.Notifications; import io.github.moulberry.notenoughupdates.options.seperateSections.PetOverlay; @@ -385,6 +386,13 @@ public class NEUConfig extends Config { ) public AccessoryBag accessoryBag = new AccessoryBag(); + @Expose + @Category( + name = "Museum", + desc = "Museum overlays" + ) + public Museum museum = new Museum(); + @Expose @Category( name = "Profile Viewer", diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Museum.java b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Museum.java new file mode 100644 index 00000000..c476fc3b --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Museum.java @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2023 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see . + */ + +package io.github.moulberry.notenoughupdates.options.seperateSections; + +import com.google.gson.annotations.Expose; +import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigEditorBoolean; +import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigEditorColour; +import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigOption; + +public class Museum { + + @Expose + @ConfigOption( + name = "Show Museum Items", + desc = "Show real items instead of green dye in the museum" + ) + @ConfigEditorBoolean + public boolean museumItemShow = false; + + @Expose + @ConfigOption( + name = "Highlight virtual museum items", + desc = "Highlight virtual museum items with a background color" + ) + @ConfigEditorColour + public String museumItemColor = "0:255:0:255:0"; + +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/ItemResolutionQuery.java b/src/main/java/io/github/moulberry/notenoughupdates/util/ItemResolutionQuery.java index ea5e13ab..280a0d3d 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/util/ItemResolutionQuery.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/util/ItemResolutionQuery.java @@ -24,6 +24,7 @@ import com.google.gson.JsonParseException; import io.github.moulberry.notenoughupdates.NEUManager; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.core.util.StringUtils; +import lombok.var; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Gui; import net.minecraft.client.gui.inventory.GuiChest; @@ -36,9 +37,10 @@ import net.minecraft.nbt.NBTTagCompound; import javax.annotation.Nullable; import java.util.Arrays; +import java.util.HashSet; import java.util.List; import java.util.Locale; -import java.util.Map; +import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -188,31 +190,63 @@ public class ItemResolutionQuery { return null; } + /** + * Search for an item by the display name + * + * @param displayName The display name of the item we are searching + * @param mayBeMangled Whether the item name may be mangled (for example: reforges, stars) + * @return the internal neu item id of that item, or null + */ + public static String findInternalNameByDisplayName(String displayName, boolean mayBeMangled) { + var cleanDisplayName = StringUtils.cleanColour(displayName); + var manager = NotEnoughUpdates.INSTANCE.manager; + String bestMatch = null; + int bestMatchLength = -1; + for (String internalName : findInternalNameCandidatesForDisplayName(cleanDisplayName)) { + var item = manager.createItem(internalName); + if (item.getDisplayName() == null) continue; + var cleanItemDisplayName = StringUtils.cleanColour(item.getDisplayName()); + if (cleanItemDisplayName.length() == 0) continue; + if (mayBeMangled + ? !cleanDisplayName.contains(cleanItemDisplayName) + : !cleanItemDisplayName.equals(cleanDisplayName)) { + continue; + } + if (cleanItemDisplayName.length() > bestMatchLength) { + bestMatchLength = cleanItemDisplayName.length(); + bestMatch = internalName; + } + } + return bestMatch; + } + + /** + * Find potential item ids for a given display name. This function is over eager to give results, + * and may give invalid results, but if there is a matching item in the repository it will return at least + * that item. This should be used as a first filtering pass. Use {@link #findInternalNameByDisplayName} for a more + * user-friendly API. + * + * @param displayName The display name of the item we are searching + * @return a list of internal neu item ids some of which may have a matching display name + */ + public static Set findInternalNameCandidatesForDisplayName(String displayName) { + var cleanDisplayName = NEUManager.cleanForTitleMapSearch(displayName); + var titleWordMap = NotEnoughUpdates.INSTANCE.manager.titleWordMap; + var candidates = new HashSet(); + for (var partialDisplayName : cleanDisplayName.split(" ")) { + if (!titleWordMap.containsKey(partialDisplayName)) continue; + candidates.addAll(titleWordMap.get(partialDisplayName).keySet()); + } + return candidates; + } + private String resolveItemInCatacombsRngMeter() { List lore = ItemUtils.getLore(compound); if (lore.size() > 16) { String s = lore.get(15); if (s.equals("§7Selected Drop")) { String displayName = lore.get(16); - return getInternalNameByDisplayName(displayName); - } - } - - return null; - } - - private String getInternalNameByDisplayName(String displayName) { - String cleanDisplayName = StringUtils.cleanColour(displayName); - for (Map.Entry entry : NotEnoughUpdates.INSTANCE.manager - .getItemInformation() - .entrySet()) { - - JsonObject object = entry.getValue(); - if (object.has("displayname")) { - String name = object.get("displayname").getAsString(); - if (StringUtils.cleanColour(name).equals(cleanDisplayName)) { - return entry.getKey(); - } + return findInternalNameByDisplayName(displayName, false); } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/LRUCache.java b/src/main/java/io/github/moulberry/notenoughupdates/util/LRUCache.java index f107d522..6adbc30d 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/util/LRUCache.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/util/LRUCache.java @@ -32,13 +32,15 @@ public interface LRUCache extends Function { } static LRUCache memoize(Function mapper, IntSupplier maxCacheSize) { - Map cache = new LinkedHashMap(10, 0.75F, true) { + Map cache = new LinkedHashMap(10, 0.75F, true) { @Override - protected boolean removeEldestEntry(Map.Entry eldest) { + protected boolean removeEldestEntry(Map.Entry eldest) { return this.size() > maxCacheSize.getAsInt(); } }; - Map synchronizedCache = Collections.synchronizedMap(cache); + Object SENTINEL_CACHE_RESULT_NULL = new Object(); + Function sentinelAwareMapper = mapper.andThen(it -> it == null ? SENTINEL_CACHE_RESULT_NULL : it); + Map synchronizedCache = Collections.synchronizedMap(cache); return new LRUCache() { @Override public void clearCache() { @@ -52,7 +54,8 @@ public interface LRUCache extends Function { @Override public V apply(K k) { - return synchronizedCache.computeIfAbsent(k, mapper); + Object value = synchronizedCache.computeIfAbsent(k, sentinelAwareMapper); + return value == SENTINEL_CACHE_RESULT_NULL ? null : (V) value; } }; } diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/inventory/MuseumItemHighlighter.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/inventory/MuseumItemHighlighter.kt new file mode 100644 index 00000000..945449ba --- /dev/null +++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/inventory/MuseumItemHighlighter.kt @@ -0,0 +1,121 @@ +/* + * Copyright (C) 2022 Linnea Gräf + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see . + */ + +package io.github.moulberry.notenoughupdates.miscfeatures.inventory + +import io.github.moulberry.notenoughupdates.NotEnoughUpdates +import io.github.moulberry.notenoughupdates.autosubscribe.NEUAutoSubscribe +import io.github.moulberry.notenoughupdates.core.ChromaColour +import io.github.moulberry.notenoughupdates.core.util.StringUtils +import io.github.moulberry.notenoughupdates.events.GuiContainerBackgroundDrawnEvent +import io.github.moulberry.notenoughupdates.events.ReplaceItemEvent +import io.github.moulberry.notenoughupdates.events.RepositoryReloadEvent +import io.github.moulberry.notenoughupdates.util.ItemResolutionQuery +import io.github.moulberry.notenoughupdates.util.ItemUtils +import io.github.moulberry.notenoughupdates.util.LRUCache +import io.github.moulberry.notenoughupdates.util.MuseumUtil +import net.minecraft.client.gui.Gui +import net.minecraft.init.Items +import net.minecraft.inventory.ContainerChest +import net.minecraft.inventory.IInventory +import net.minecraft.item.EnumDyeColor +import net.minecraft.item.ItemStack +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +@NEUAutoSubscribe +object MuseumItemHighlighter { + + private val manager get() = NotEnoughUpdates.INSTANCE.manager + private val config get() = NotEnoughUpdates.INSTANCE.config.museum + + private fun getHighlightColor() = ChromaColour.specialToChromaRGB(config.museumItemColor) + + + private val findRawItemForName = LRUCache.memoize(::findRawItemForName0, 4 * 7 * 2) + + @SubscribeEvent + fun onRepositoryReload(event: RepositoryReloadEvent) { + findRawItemForName.clearCache() + } + + private fun findRawItemForName0(arg: Pair): ItemStack? { + val (name, armor) = arg + return MuseumUtil.findItemsByName(name, armor).firstOrNull()?.let { manager.createItem(it) } + } + + + @SubscribeEvent + fun onItemOverride(event: ReplaceItemEvent) { + if (!config.museumItemShow) return + if (!isMuseumInventory(event.inventory)) return + val original = event.original ?: return + if (!isCompletedRetrievedItem(original)) return + val armor = StringUtils.cleanColour(event.inventory.displayName.unformattedText).endsWith("Armor Sets") + val rawItem = findRawItemForName.apply(original.displayName to armor) ?: return + val hydratedItem = hydrateMuseumItem(rawItem, original) + event.replaceWith(hydratedItem) + } + + fun isCompletedRetrievedItem(itemStack: ItemStack): Boolean { + return itemStack.hasDisplayName() && itemStack.item == Items.dye && EnumDyeColor.byDyeDamage(itemStack.itemDamage) == EnumDyeColor.LIME + } + + fun isMuseumInventory(inventory: IInventory): Boolean { + return StringUtils.cleanColour(inventory.displayName.unformattedText).startsWith("Museum ➜") + } + + @SubscribeEvent + fun onBackgroundDrawn(event: GuiContainerBackgroundDrawnEvent) { + val egui = event.container ?: return + val chest = egui.inventorySlots as? ContainerChest ?: return + if (!config.museumItemShow) return + if (!isMuseumInventory(chest.lowerChestInventory)) return + val fixedHighlightColor = getHighlightColor() + for (slot in chest.inventorySlots) { + if (slot == null || slot.stack == null) continue + if (isHydratedMuseumItem(slot.stack) || isCompletedRetrievedItem(slot.stack)) { + val left = slot.xDisplayPosition + val top = slot.yDisplayPosition + Gui.drawRect( + left, top, + left + 16, top + 16, + fixedHighlightColor + ) + } + } + } + + fun hydrateMuseumItem(rawItem: ItemStack, original: ItemStack) = rawItem.copy().apply { + setStackDisplayName(original.displayName) + val originalLore = ItemUtils.getLore(original).toMutableList() + ItemUtils.setLore(this, originalLore) + val data = ItemUtils.getOrCreateTag(this) + val extraAttributes = data.getCompoundTag("ExtraAttributes") + extraAttributes.setByte("donated_museum", 1) + data.setTag("ExtraAttributes", extraAttributes) + data.setBoolean(MUSEUM_HYDRATED_ITEM_TAG, true) + } + + fun isHydratedMuseumItem(stack: ItemStack): Boolean { + return ItemUtils.getOrCreateTag(stack).getBoolean(MUSEUM_HYDRATED_ITEM_TAG) + } + + const val MUSEUM_HYDRATED_ITEM_TAG = "NEU_HYDRATED_MUSEUM_ITEM" + +} diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/util/KotlinStringUtils.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/util/KotlinStringUtils.kt new file mode 100644 index 00000000..dc1e800c --- /dev/null +++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/util/KotlinStringUtils.kt @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see . + */ + +package io.github.moulberry.notenoughupdates.util + +import net.minecraft.util.StringUtils + +fun String.stripControlCodes(): String = StringUtils.stripControlCodes(this) diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/util/MuseumUtil.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/util/MuseumUtil.kt new file mode 100644 index 00000000..dd52d175 --- /dev/null +++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/util/MuseumUtil.kt @@ -0,0 +1,113 @@ +/* + * Copyright (C) 2023 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see . + */ + +package io.github.moulberry.notenoughupdates.util + +import io.github.moulberry.notenoughupdates.NEUManager +import io.github.moulberry.notenoughupdates.NotEnoughUpdates +import net.minecraft.item.EnumDyeColor +import net.minecraft.item.ItemDye +import net.minecraft.item.ItemStack + +object MuseumUtil { + + data class MuseumItem( + /** + * A potentially non-exhaustive list of item ids that are required for this museum donation. + */ + val skyblockItemIds: List, + val state: DonationState, + ) + + enum class DonationState { + /** + * Donated armor only shows one piece, so we use that for id resolution, which might result in incomplete + * results (hence the separate state). This still means that the entire set is donated, but it is guaranteed to + * be only a partial result. Other values of this enum do not guarantee a full result, but at least they do not + * guarantee a partial one. + */ + DONATED_PRESENT_PARTIAL, + DONATED_PRESENT, + DONATED_VACANT, + MISSING, + } + + fun findMuseumItem(stack: ItemStack, isOnArmorPage: Boolean): MuseumItem? { + val item = stack.item ?: return null + val items by lazy { findItemsByName(stack.displayName, isOnArmorPage)} + if (item is ItemDye) { + val dyeColor = EnumDyeColor.byDyeDamage(stack.itemDamage) + if (dyeColor == EnumDyeColor.LIME) { + // Item is donated, but not present in the museum + return MuseumItem(items, DonationState.DONATED_VACANT) + } else if (dyeColor == EnumDyeColor.GRAY) { + // Item is not donated + return MuseumItem(items, DonationState.MISSING) + } + // Otherwise unknown item, try to analyze as normal item. + } + val skyblockId = NotEnoughUpdates.INSTANCE.manager.createItemResolutionQuery().withItemStack(stack) + .resolveInternalName() + if (skyblockId != null) { + return MuseumItem( + listOf(skyblockId), + if (isOnArmorPage) DonationState.DONATED_PRESENT_PARTIAL else DonationState.DONATED_PRESENT + ) + } + return MuseumItem( + items, + DonationState.DONATED_PRESENT + ) + } + + fun findItemsByName(displayName: String, armor: Boolean): List { + return (if (armor) + findMuseumArmorSetByName(displayName) + else + listOf(findMuseumItemByName(displayName))).filterNotNull() + + } + + fun findMuseumItemByName(displayName: String): String? = + ItemResolutionQuery.findInternalNameByDisplayName(displayName, true) + + + fun findMuseumArmorSetByName(displayName: String): List { + val armorSlots = arrayOf( + "HELMET", + "LEGGINGS", + "CHESTPLATE", + "BOOTS" + ) + val monochromeName = NEUManager.cleanForTitleMapSearch(displayName) + val results = ItemResolutionQuery.findInternalNameCandidatesForDisplayName(displayName) + .asSequence() + .filter { + val item = NotEnoughUpdates.INSTANCE.manager.createItem(it) + val name = NEUManager.cleanForTitleMapSearch(item.displayName) + monochromeName.replace("armor", "") in name + } + .toSet() + return armorSlots.map { armorSlot -> + results.singleOrNull { armorSlot in it } + } + } + + +} -- cgit From 991854cd34f0fa9cb8b85a091df33c459df415a6 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal002@users.noreply.github.com> Date: Sat, 25 Feb 2023 15:25:10 +0100 Subject: Magical power in SkyBlock Menu icon again (#588) Show magical power at accessory bag in skyblock menu. Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> --- .../miscfeatures/OldSkyBlockMenu.kt | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'src/main/kotlin') diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/OldSkyBlockMenu.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/OldSkyBlockMenu.kt index b871a672..4782ab0f 100644 --- a/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/OldSkyBlockMenu.kt +++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/OldSkyBlockMenu.kt @@ -23,6 +23,7 @@ import io.github.moulberry.notenoughupdates.NotEnoughUpdates import io.github.moulberry.notenoughupdates.autosubscribe.NEUAutoSubscribe import io.github.moulberry.notenoughupdates.events.ReplaceItemEvent import io.github.moulberry.notenoughupdates.events.SlotClickEvent +import io.github.moulberry.notenoughupdates.util.ItemUtils import io.github.moulberry.notenoughupdates.util.Utils import net.minecraft.client.player.inventory.ContainerLocalMenu import net.minecraft.init.Items @@ -30,9 +31,13 @@ import net.minecraft.item.Item import net.minecraft.item.ItemStack import net.minecraftforge.fml.common.eventhandler.EventPriority import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import java.text.DecimalFormat +import java.text.DecimalFormatSymbols +import java.util.* @NEUAutoSubscribe object OldSkyBlockMenu { + private val decimalFormat = DecimalFormat("##,##0", DecimalFormatSymbols(Locale.US)) val map: Map by lazy { val map = mutableMapOf() @@ -48,11 +53,22 @@ object OldSkyBlockMenu { if (event.inventory !is ContainerLocalMenu) return val skyBlockButton = map[event.slotNumber] ?: return + val showWarning = skyBlockButton.requiresBoosterCookie && !CookieWarning.hasActiveBoosterCookie() + val item = if (showWarning) skyBlockButton.itemWithCookieWarning else skyBlockButton.itemWithoutCookieWarning - if (skyBlockButton.requiresBoosterCookie && !CookieWarning.hasActiveBoosterCookie()) { - event.replaceWith(skyBlockButton.itemWithCookieWarning) + if (skyBlockButton == SkyBlockButton.ACCESSORY) { + val magicalPower = NotEnoughUpdates.INSTANCE.config.profileSpecific?.magicalPower ?: 0 + + val lore = ItemUtils.getLore(item) + lore.add(4, "") + val format = decimalFormat.format(magicalPower) + lore.add(5, "§7Magical Power: §6$format") + + val newItem = ItemStack.copyItemStack(item) + ItemUtils.setLore(newItem, lore) + event.replaceWith(newItem) } else { - event.replaceWith(skyBlockButton.itemWithoutCookieWarning) + event.replaceWith(item) } } -- cgit From 5dd063fbba6bde64806a7620541dc2d9bdf42871 Mon Sep 17 00:00:00 2001 From: Roman / Linnea Gräf Date: Sat, 4 Mar 2023 02:54:50 +0100 Subject: Replace all commands in NEU with a brigadier implementation (#599) --- build.gradle.kts | 9 +- .../notenoughupdates/NotEnoughUpdates.java | 5 +- .../commands/ClientCommandBase.java | 46 --- .../notenoughupdates/commands/Commands.java | 107 ------- .../commands/EntityViewerCommand.java | 100 ------ .../notenoughupdates/commands/ScreenCommand.java | 45 --- .../commands/dev/DevTestCommand.java | 292 ------------------ .../notenoughupdates/commands/dev/DiagCommand.java | 134 -------- .../commands/dev/DungeonWinTestCommand.java | 42 --- .../commands/dev/EnableStorageCommand.java | 39 --- .../commands/dev/NullzeeSphereCommand.java | 61 ---- .../commands/dev/PackDevCommand.java | 304 ------------------ .../commands/dev/ReloadRepoCommand.java | 39 --- .../commands/dev/ResetRepoCommand.java | 42 --- .../commands/dev/StatsCommand.java | 200 ------------ .../commands/dungeon/DhCommand.java | 37 --- .../commands/dungeon/DnCommand.java | 40 --- .../commands/dungeon/JoinDungeonCommand.java | 57 ---- .../commands/dungeon/MapCommand.java | 131 -------- .../commands/help/FeaturesCommand.java | 60 ---- .../commands/help/HelpCommand.java | 94 ------ .../commands/help/LinksCommand.java | 52 ---- .../commands/help/SettingsCommand.java | 53 ---- .../commands/help/StorageViewerWhyCommand.java | 45 --- .../notenoughupdates/commands/misc/AhCommand.java | 60 ---- .../commands/misc/CalculatorCommand.java | 75 ----- .../commands/misc/CalendarCommand.java | 41 --- .../commands/misc/CosmeticsCommand.java | 47 --- .../commands/misc/CustomizeCommand.java | 63 ---- .../commands/misc/PronounsCommand.java | 94 ------ .../commands/misc/UpdateCommand.java | 76 ----- .../commands/profile/CataCommand.java | 36 --- .../commands/profile/PeekCommand.java | 343 --------------------- .../commands/profile/PvCommand.java | 41 --- .../commands/profile/ViewProfileCommand.java | 102 ------ .../notenoughupdates/listener/RenderListener.java | 10 +- .../notenoughupdates/miscfeatures/FairySouls.java | 80 +---- .../mixins/AccessorCommandHandler.java | 33 ++ .../util/brigadier/NEUBrigadierHook.kt | 109 +++++++ .../commands/dev/DevTestCommand.kt | 256 +++++++++++++++ .../notenoughupdates/commands/dev/DiagCommand.kt | 78 +++++ .../commands/dev/NEUStatsCommand.kt | 209 +++++++++++++ .../commands/dev/PackDevCommand.kt | 165 ++++++++++ .../commands/dev/SimpleDevCommands.kt | 110 +++++++ .../commands/help/FeaturesCommand.kt | 65 ++++ .../notenoughupdates/commands/help/HelpCommand.kt | 95 ++++++ .../notenoughupdates/commands/help/LinksCommand.kt | 52 ++++ .../commands/help/SettingsCommand.kt | 53 ++++ .../commands/help/StorageViewerWhyCommand.kt | 48 +++ .../notenoughupdates/commands/misc/AhCommand.kt | 67 ++++ .../commands/misc/DungeonCommands.kt | 144 +++++++++ .../commands/misc/FairySoulsCommand.kt | 62 ++++ .../notenoughupdates/commands/misc/MiscCommands.kt | 169 ++++++++++ .../notenoughupdates/commands/misc/PeekCommand.kt | 318 +++++++++++++++++++ .../commands/misc/ProfileViewerCommands.kt | 87 ++++++ .../commands/misc/ScreenOpenCommands.kt | 52 ++++ .../events/RegisterBrigadierCommandEvent.kt | 52 ++++ .../util/brigadier/BrigadierRoot.kt | 103 +++++++ .../util/brigadier/EnumArgumentType.kt | 64 ++++ .../util/brigadier/RestArgumentType.kt | 31 ++ .../notenoughupdates/util/brigadier/dsl.kt | 179 +++++++++++ .../moulberry/notenoughupdates/util/iterate.kt | 28 ++ src/main/resources/mixins.notenoughupdates.json | 1 + 63 files changed, 2654 insertions(+), 3078 deletions(-) delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/commands/ClientCommandBase.java delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/commands/Commands.java delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/commands/EntityViewerCommand.java delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/commands/ScreenCommand.java delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.java delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/commands/dev/DiagCommand.java delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/commands/dev/DungeonWinTestCommand.java delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/commands/dev/EnableStorageCommand.java delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/commands/dev/NullzeeSphereCommand.java delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/commands/dev/PackDevCommand.java delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/commands/dev/ReloadRepoCommand.java delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/commands/dev/ResetRepoCommand.java delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/commands/dev/StatsCommand.java delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/commands/dungeon/DhCommand.java delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/commands/dungeon/DnCommand.java delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/commands/dungeon/JoinDungeonCommand.java delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/commands/dungeon/MapCommand.java delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/commands/help/FeaturesCommand.java delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/commands/help/HelpCommand.java delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/commands/help/LinksCommand.java delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/commands/help/SettingsCommand.java delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/commands/help/StorageViewerWhyCommand.java delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/commands/misc/AhCommand.java delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/commands/misc/CalculatorCommand.java delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/commands/misc/CalendarCommand.java delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/commands/misc/CosmeticsCommand.java delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/commands/misc/CustomizeCommand.java delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/commands/misc/PronounsCommand.java delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/commands/misc/UpdateCommand.java delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/commands/profile/CataCommand.java delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/commands/profile/PeekCommand.java delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/commands/profile/PvCommand.java delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/commands/profile/ViewProfileCommand.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/mixins/AccessorCommandHandler.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/util/brigadier/NEUBrigadierHook.kt create mode 100644 src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.kt create mode 100644 src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/DiagCommand.kt create mode 100644 src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/NEUStatsCommand.kt create mode 100644 src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/PackDevCommand.kt create mode 100644 src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/SimpleDevCommands.kt create mode 100644 src/main/kotlin/io/github/moulberry/notenoughupdates/commands/help/FeaturesCommand.kt create mode 100644 src/main/kotlin/io/github/moulberry/notenoughupdates/commands/help/HelpCommand.kt create mode 100644 src/main/kotlin/io/github/moulberry/notenoughupdates/commands/help/LinksCommand.kt create mode 100644 src/main/kotlin/io/github/moulberry/notenoughupdates/commands/help/SettingsCommand.kt create mode 100644 src/main/kotlin/io/github/moulberry/notenoughupdates/commands/help/StorageViewerWhyCommand.kt create mode 100644 src/main/kotlin/io/github/moulberry/notenoughupdates/commands/misc/AhCommand.kt create mode 100644 src/main/kotlin/io/github/moulberry/notenoughupdates/commands/misc/DungeonCommands.kt create mode 100644 src/main/kotlin/io/github/moulberry/notenoughupdates/commands/misc/FairySoulsCommand.kt create mode 100644 src/main/kotlin/io/github/moulberry/notenoughupdates/commands/misc/MiscCommands.kt create mode 100644 src/main/kotlin/io/github/moulberry/notenoughupdates/commands/misc/PeekCommand.kt create mode 100644 src/main/kotlin/io/github/moulberry/notenoughupdates/commands/misc/ProfileViewerCommands.kt create mode 100644 src/main/kotlin/io/github/moulberry/notenoughupdates/commands/misc/ScreenOpenCommands.kt create mode 100644 src/main/kotlin/io/github/moulberry/notenoughupdates/events/RegisterBrigadierCommandEvent.kt create mode 100644 src/main/kotlin/io/github/moulberry/notenoughupdates/util/brigadier/BrigadierRoot.kt create mode 100644 src/main/kotlin/io/github/moulberry/notenoughupdates/util/brigadier/EnumArgumentType.kt create mode 100644 src/main/kotlin/io/github/moulberry/notenoughupdates/util/brigadier/RestArgumentType.kt create mode 100644 src/main/kotlin/io/github/moulberry/notenoughupdates/util/brigadier/dsl.kt create mode 100644 src/main/kotlin/io/github/moulberry/notenoughupdates/util/iterate.kt (limited to 'src/main/kotlin') diff --git a/build.gradle.kts b/build.gradle.kts index e41aa513..aec078d3 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -135,19 +135,21 @@ dependencies { kotlinDependencies(kotlin("stdlib")) compileOnly(ksp(project(":annotations"))!!) - compileOnly("org.projectlombok:lombok:1.18.24") + compileOnly("org.projectlombok:lombok:1.18.24") annotationProcessor("org.projectlombok:lombok:1.18.24") "oneconfigAnnotationProcessor"("org.projectlombok:lombok:1.18.24") + shadowImplementation("com.mojang:brigadier:1.0.18") + shadowImplementation("org.spongepowered:mixin:0.7.11-SNAPSHOT") { isTransitive = false // Dependencies of mixin are already bundled by minecraft } - annotationProcessor("org.spongepowered:mixin:0.8.4-SNAPSHOT") + annotationProcessor("net.fabricmc:sponge-mixin:0.11.4+mixin.0.8.5") @Suppress("VulnerableLibrariesLocal") shadowApi("info.bliki.wiki:bliki-core:3.1.0") testImplementation("org.junit.jupiter:junit-jupiter:5.9.2") - testAnnotationProcessor("org.spongepowered:mixin:0.8.4-SNAPSHOT") + testAnnotationProcessor("net.fabricmc:sponge-mixin:0.11.4+mixin.0.8.5") // modImplementation("io.github.notenoughupdates:MoulConfig:0.0.1") devEnv("me.djtheredstoner:DevAuth-forge-legacy:1.1.0") @@ -233,6 +235,7 @@ tasks.shadowJar { from(kotlinDependencyCollectionJar) dependsOn(kotlinDependencyCollectionJar) fun relocate(name: String) = relocate(name, "io.github.moulberry.notenoughupdates.deps.$name") + relocate("com.mojang.brigadier") } tasks.assemble.get().dependsOn(remapJar) diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java index 25d1002a..7f0136ee 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java @@ -25,7 +25,6 @@ import com.google.gson.GsonBuilder; import com.google.gson.JsonObject; import io.github.moulberry.notenoughupdates.autosubscribe.AutoLoad; import io.github.moulberry.notenoughupdates.autosubscribe.NEUAutoSubscribe; -import io.github.moulberry.notenoughupdates.commands.Commands; import io.github.moulberry.notenoughupdates.core.BackgroundBlur; import io.github.moulberry.notenoughupdates.cosmetics.ShaderManager; import io.github.moulberry.notenoughupdates.listener.ChatListener; @@ -52,6 +51,7 @@ import io.github.moulberry.notenoughupdates.overlays.OverlayManager; import io.github.moulberry.notenoughupdates.profileviewer.ProfileViewer; import io.github.moulberry.notenoughupdates.recipes.RecipeGenerator; import io.github.moulberry.notenoughupdates.util.Utils; +import io.github.moulberry.notenoughupdates.util.brigadier.BrigadierRoot; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.GuiScreen; @@ -158,7 +158,6 @@ public class NotEnoughUpdates { public Navigation navigation = new Navigation(this); public GuiScreen openGui = null; public long lastOpenedGui = 0; - public Commands commands; public boolean packDevEnabled = false; public Color[][] colourMap = null; public AutoUpdater autoUpdater = new AutoUpdater(this); @@ -281,7 +280,7 @@ public class NotEnoughUpdates { manager.registerReloadListener(new CustomBlockSounds.ReloaderListener()); } - this.commands = new Commands(); + BrigadierRoot.INSTANCE.updateHooks(); BackgroundBlur.registerListener(); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/ClientCommandBase.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/ClientCommandBase.java deleted file mode 100644 index e0ae7a1a..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/commands/ClientCommandBase.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (C) 2022 NotEnoughUpdates contributors - * - * This file is part of NotEnoughUpdates. - * - * NotEnoughUpdates is free software: you can redistribute it - * and/or modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation, either - * version 3 of the License, or (at your option) any later version. - * - * NotEnoughUpdates is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with NotEnoughUpdates. If not, see . - */ - -package io.github.moulberry.notenoughupdates.commands; - -import net.minecraft.command.CommandBase; -import net.minecraft.command.ICommandSender; - -public abstract class ClientCommandBase extends CommandBase { - private final String name; - - protected ClientCommandBase(String name) { - this.name = name; - } - - @Override - public String getCommandName() { - return name; - } - - @Override - public String getCommandUsage(ICommandSender sender) { - return "/" + name; - } - - @Override - public boolean canCommandSenderUseCommand(ICommandSender sender) { - return true; - } -} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/Commands.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/Commands.java deleted file mode 100644 index 91365cd1..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/commands/Commands.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright (C) 2022 NotEnoughUpdates contributors - * - * This file is part of NotEnoughUpdates. - * - * NotEnoughUpdates is free software: you can redistribute it - * and/or modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation, either - * version 3 of the License, or (at your option) any later version. - * - * NotEnoughUpdates is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with NotEnoughUpdates. If not, see . - */ - -package io.github.moulberry.notenoughupdates.commands; - -import io.github.moulberry.notenoughupdates.NotEnoughUpdates; -import io.github.moulberry.notenoughupdates.commands.dev.DevTestCommand; -import io.github.moulberry.notenoughupdates.commands.dev.DiagCommand; -import io.github.moulberry.notenoughupdates.commands.dev.DungeonWinTestCommand; -import io.github.moulberry.notenoughupdates.commands.dev.EnableStorageCommand; -import io.github.moulberry.notenoughupdates.commands.dev.NullzeeSphereCommand; -import io.github.moulberry.notenoughupdates.commands.dev.PackDevCommand; -import io.github.moulberry.notenoughupdates.commands.dev.ReloadRepoCommand; -import io.github.moulberry.notenoughupdates.commands.dev.ResetRepoCommand; -import io.github.moulberry.notenoughupdates.commands.dev.StatsCommand; -import io.github.moulberry.notenoughupdates.commands.dungeon.DhCommand; -import io.github.moulberry.notenoughupdates.commands.dungeon.DnCommand; -import io.github.moulberry.notenoughupdates.commands.dungeon.JoinDungeonCommand; -import io.github.moulberry.notenoughupdates.commands.dungeon.MapCommand; -import io.github.moulberry.notenoughupdates.commands.help.FeaturesCommand; -import io.github.moulberry.notenoughupdates.commands.help.HelpCommand; -import io.github.moulberry.notenoughupdates.commands.help.LinksCommand; -import io.github.moulberry.notenoughupdates.commands.help.SettingsCommand; -import io.github.moulberry.notenoughupdates.commands.help.StorageViewerWhyCommand; -import io.github.moulberry.notenoughupdates.commands.misc.AhCommand; -import io.github.moulberry.notenoughupdates.commands.misc.CalculatorCommand; -import io.github.moulberry.notenoughupdates.commands.misc.CalendarCommand; -import io.github.moulberry.notenoughupdates.commands.misc.CosmeticsCommand; -import io.github.moulberry.notenoughupdates.commands.misc.CustomizeCommand; -import io.github.moulberry.notenoughupdates.commands.misc.PronounsCommand; -import io.github.moulberry.notenoughupdates.commands.misc.UpdateCommand; -import io.github.moulberry.notenoughupdates.commands.profile.CataCommand; -import io.github.moulberry.notenoughupdates.commands.profile.PeekCommand; -import io.github.moulberry.notenoughupdates.commands.profile.PvCommand; -import io.github.moulberry.notenoughupdates.commands.profile.ViewProfileCommand; -import io.github.moulberry.notenoughupdates.miscfeatures.FairySouls; -import io.github.moulberry.notenoughupdates.miscgui.GuiEnchantColour; -import io.github.moulberry.notenoughupdates.miscgui.GuiInvButtonEditor; -import io.github.moulberry.notenoughupdates.miscgui.NEUOverlayPlacements; -import net.minecraftforge.client.ClientCommandHandler; -import net.minecraftforge.fml.common.Loader; - -public class Commands { - public Commands() { - - // Help Commands - ClientCommandHandler.instance.registerCommand(new LinksCommand()); - ClientCommandHandler.instance.registerCommand(new HelpCommand()); - ClientCommandHandler.instance.registerCommand(new StorageViewerWhyCommand()); - ClientCommandHandler.instance.registerCommand(new FeaturesCommand()); - ClientCommandHandler.instance.registerCommand(new SettingsCommand()); - - // Dev Commands - ClientCommandHandler.instance.registerCommand(new PackDevCommand()); - ClientCommandHandler.instance.registerCommand(new DungeonWinTestCommand()); - ClientCommandHandler.instance.registerCommand(new StatsCommand()); - ClientCommandHandler.instance.registerCommand(new DevTestCommand()); - ClientCommandHandler.instance.registerCommand(new NullzeeSphereCommand()); - ClientCommandHandler.instance.registerCommand(new DiagCommand()); - ClientCommandHandler.instance.registerCommand(new ReloadRepoCommand()); - ClientCommandHandler.instance.registerCommand(new ResetRepoCommand()); - ClientCommandHandler.instance.registerCommand(new EnableStorageCommand()); - - // Profile Commands - ClientCommandHandler.instance.registerCommand(new PeekCommand()); - ClientCommandHandler.instance.registerCommand(new ViewProfileCommand()); - ClientCommandHandler.instance.registerCommand(new PvCommand()); - if (!Loader.isModLoaded("skyblockextras")) ClientCommandHandler.instance.registerCommand(new CataCommand()); - - // Dungeon Commands - ClientCommandHandler.instance.registerCommand(new MapCommand()); - ClientCommandHandler.instance.registerCommand(new JoinDungeonCommand()); - ClientCommandHandler.instance.registerCommand(new DnCommand()); - ClientCommandHandler.instance.registerCommand(new DhCommand()); - - // Misc Commands - ClientCommandHandler.instance.registerCommand(new CosmeticsCommand()); - ClientCommandHandler.instance.registerCommand(new CustomizeCommand()); - ClientCommandHandler.instance.registerCommand(new ScreenCommand("neubuttons", GuiInvButtonEditor::new)); - ClientCommandHandler.instance.registerCommand(new ScreenCommand("neuec", GuiEnchantColour::new)); - ClientCommandHandler.instance.registerCommand(new ScreenCommand("neuoverlay", NEUOverlayPlacements::new)); - ClientCommandHandler.instance.registerCommand(new AhCommand()); - ClientCommandHandler.instance.registerCommand(new CalculatorCommand()); - ClientCommandHandler.instance.registerCommand(new CalendarCommand()); - ClientCommandHandler.instance.registerCommand(new UpdateCommand(NotEnoughUpdates.INSTANCE)); - ClientCommandHandler.instance.registerCommand(new PronounsCommand()); - - // Fairy Soul Commands - ClientCommandHandler.instance.registerCommand(new FairySouls.FairySoulsCommand()); - } -} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/EntityViewerCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/EntityViewerCommand.java deleted file mode 100644 index e3738661..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/commands/EntityViewerCommand.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright (C) 2022 NotEnoughUpdates contributors - * - * This file is part of NotEnoughUpdates. - * - * NotEnoughUpdates is free software: you can redistribute it - * and/or modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation, either - * version 3 of the License, or (at your option) any later version. - * - * NotEnoughUpdates is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with NotEnoughUpdates. If not, see . - */ - -package io.github.moulberry.notenoughupdates.commands; - -import com.google.common.collect.Lists; -import io.github.moulberry.notenoughupdates.miscfeatures.entityviewer.EntityViewer; -import net.minecraft.client.Minecraft; -import net.minecraft.command.CommandException; -import net.minecraft.command.ICommandSender; -import net.minecraft.entity.EntityLivingBase; -import net.minecraft.event.ClickEvent; -import net.minecraft.util.ChatComponentText; -import net.minecraft.util.ChatStyle; -import net.minecraft.util.EnumChatFormatting; -import net.minecraft.util.ResourceLocation; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; -import net.minecraftforge.fml.common.gameevent.TickEvent; - -import java.util.Arrays; -import java.util.List; -import java.util.Queue; -import java.util.concurrent.ConcurrentLinkedDeque; - -public class EntityViewerCommand extends ClientCommandBase { - public EntityViewerCommand() { - super("neushowentity"); - MinecraftForge.EVENT_BUS.register(this); - } - - @Override - public List getCommandAliases() { - return Lists.newArrayList("neuentityviewer"); - } - - @Override - public String getCommandUsage(ICommandSender sender) { - return EnumChatFormatting.RED + "Use /neushowentity list"; - } - - public void showUsage(ICommandSender sender) { - sender.addChatMessage(new ChatComponentText(getCommandUsage(sender))); - } - - private final Queue queuedGUIS = new ConcurrentLinkedDeque<>(); - - @SubscribeEvent - public void onTick(TickEvent event) { - if (Minecraft.getMinecraft().currentScreen == null) { - EntityViewer poll = queuedGUIS.poll(); - if (poll == null) return; - Minecraft.getMinecraft().displayGuiScreen(poll); - } - } - - @Override - public void processCommand(ICommandSender sender, String[] strings) throws CommandException { - if (strings.length == 0) { - showUsage(sender); - return; - } - if (strings[0].equals("list")) { - for (String label : EntityViewer.validEntities.keySet()) { - sender.addChatMessage(new ChatComponentText(EnumChatFormatting.BLUE + " " + label) - .setChatStyle(new ChatStyle().setChatClickEvent( - new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/neuentityviewer " + label)))); - } - return; - } - EntityLivingBase entityLivingBase; - if (strings[0].startsWith("@")) { - ResourceLocation resourceLocation = new ResourceLocation(strings[0].substring(1)); - entityLivingBase = EntityViewer.constructEntity(resourceLocation); - } else { - entityLivingBase = EntityViewer.constructEntity(strings[0], Arrays.copyOfRange(strings, 1, strings.length)); - } - if (entityLivingBase == null) { - sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "Could not create that entity")); - return; - } - queuedGUIS.add(new EntityViewer(strings[0], entityLivingBase)); - } -} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/ScreenCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/ScreenCommand.java deleted file mode 100644 index 1b90e5df..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/commands/ScreenCommand.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (C) 2022 NotEnoughUpdates contributors - * - * This file is part of NotEnoughUpdates. - * - * NotEnoughUpdates is free software: you can redistribute it - * and/or modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation, either - * version 3 of the License, or (at your option) any later version. - * - * NotEnoughUpdates is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with NotEnoughUpdates. If not, see . - */ - -package io.github.moulberry.notenoughupdates.commands; - -import io.github.moulberry.notenoughupdates.NotEnoughUpdates; -import net.minecraft.client.gui.GuiScreen; -import net.minecraft.command.CommandException; -import net.minecraft.command.ICommandSender; - -public class ScreenCommand extends ClientCommandBase { - - private final ScreenOpener opener; - - protected ScreenCommand(String name, ScreenOpener opener) { - super(name); - this.opener = opener; - } - - @Override - public void processCommand(ICommandSender sender, String[] args) throws CommandException { - NotEnoughUpdates.INSTANCE.openGui = opener.open(); - } - - @FunctionalInterface - public interface ScreenOpener { - GuiScreen open(); - } -} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.java deleted file mode 100644 index 1a1400ab..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.java +++ /dev/null @@ -1,292 +0,0 @@ -/* - * Copyright (C) 2022 NotEnoughUpdates contributors - * - * This file is part of NotEnoughUpdates. - * - * NotEnoughUpdates is free software: you can redistribute it - * and/or modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation, either - * version 3 of the License, or (at your option) any later version. - * - * NotEnoughUpdates is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with NotEnoughUpdates. If not, see . - */ - -package io.github.moulberry.notenoughupdates.commands.dev; - -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import io.github.moulberry.notenoughupdates.BuildFlags; -import io.github.moulberry.notenoughupdates.NotEnoughUpdates; -import io.github.moulberry.notenoughupdates.commands.ClientCommandBase; -import io.github.moulberry.notenoughupdates.core.config.GuiPositionEditor; -import io.github.moulberry.notenoughupdates.core.util.MiscUtils; -import io.github.moulberry.notenoughupdates.miscfeatures.FishingHelper; -import io.github.moulberry.notenoughupdates.miscfeatures.customblockzones.CustomBiomes; -import io.github.moulberry.notenoughupdates.miscfeatures.customblockzones.LocationChangeEvent; -import io.github.moulberry.notenoughupdates.miscfeatures.customblockzones.SpecialBlockZone; -import io.github.moulberry.notenoughupdates.miscgui.GuiPriceGraph; -import io.github.moulberry.notenoughupdates.miscgui.minionhelper.MinionHelperManager; -import io.github.moulberry.notenoughupdates.util.ApiCache; -import io.github.moulberry.notenoughupdates.util.PronounDB; -import io.github.moulberry.notenoughupdates.util.SBInfo; -import io.github.moulberry.notenoughupdates.util.TabListUtils; -import io.github.moulberry.notenoughupdates.util.Utils; -import io.github.moulberry.notenoughupdates.util.hypixelapi.ProfileCollectionInfo; -import lombok.var; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.GuiScreen; -import net.minecraft.command.CommandException; -import net.minecraft.command.ICommandSender; -import net.minecraft.launchwrapper.Launch; -import net.minecraft.util.BlockPos; -import net.minecraft.util.ChatComponentText; -import net.minecraft.util.EnumChatFormatting; -import net.minecraft.util.EnumParticleTypes; -import net.minecraftforge.common.MinecraftForge; - -import java.util.Arrays; -import java.util.List; -import java.util.stream.Collectors; - -public class DevTestCommand extends ClientCommandBase { - - private static final List DEV_TESTERS = - Arrays.asList( - "d0e05de7-6067-454d-beae-c6d19d886191", // moulberry - "66502b40-6ac1-4d33-950d-3df110297aab", // lucycoconut - "a5761ff3-c710-4cab-b4f4-3e7f017a8dbf", // ironm00n - "5d5c548a-790c-4fc8-bd8f-d25b04857f44", // ariyio - "53924f1a-87e6-4709-8e53-f1c7d13dc239", // throwpo - "d3cb85e2-3075-48a1-b213-a9bfb62360c1", // lrg89 - "0b4d470f-f2fb-4874-9334-1eaef8ba4804", // dediamondpro - "ebb28704-ed85-43a6-9e24-2fe9883df9c2", // lulonaut - "698e199d-6bd1-4b10-ab0c-52fedd1460dc", // craftyoldminer - "8a9f1841-48e9-48ed-b14f-76a124e6c9df", // eisengolem - "a7d6b3f1-8425-48e5-8acc-9a38ab9b86f7", // whalker - "0ce87d5a-fa5f-4619-ae78-872d9c5e07fe", // ascynx - "a049a538-4dd8-43f8-87d5-03f09d48b4dc", // egirlefe - "7a9dc802-d401-4d7d-93c0-8dd1bc98c70d", // efefury - "bb855349-dfd8-4125-a750-5fc2cf543ad5" // hannibal2 - ); - - private static final String[] DEV_FAIL_STRINGS = { - "No.", - "I said no.", - "You aren't allowed to use this.", - "Are you sure you want to use this? Type 'Yes' in chat.", - "Are you sure you want to use this? Type 'Yes' in chat.", - "Lmao you thought", - "Ok please stop", - "What do you want from me?", - "This command almost certainly does nothing useful for you", - "Ok, this is the last message, after this it will repeat", - "No.", - "I said no.", - "Dammit. I thought that would work. Uhh...", - "\u00a7dFrom \u00a7c[ADMIN] Minikloon\u00a77: If you use that command again, I'll have to ban you", - "", - "Ok, this is actually the last message, use the command again and you'll crash I promise" - }; - private int devFailIndex = 0; - - public static int testValue = 0; - - public DevTestCommand() { - super("neudevtest"); - } - - @Override - public void processCommand(ICommandSender sender, String[] args) throws CommandException { - if (!DEV_TESTERS.contains(Minecraft.getMinecraft().thePlayer.getUniqueID().toString()) - && !(boolean) Launch.blackboard.get("fml.deobfuscatedEnvironment")) { - if (devFailIndex >= DEV_FAIL_STRINGS.length) { - throw new Error("L") { - @Override - public void printStackTrace() { - throw new Error("L"); - } - }; - } - if (devFailIndex == DEV_FAIL_STRINGS.length - 2) { - devFailIndex++; - - ChatComponentText component = new ChatComponentText("\u00a7cYou are permanently banned from this server!"); - component.appendText("\n"); - component.appendText("\n\u00a77Reason: \u00a7rI told you not to run the command - Moulberry"); - component.appendText("\n\u00a77Find out more: \u00a7b\u00a7nhttps://www.hypixel.net/appeal"); - component.appendText("\n"); - component.appendText("\n\u00a77Ban ID: \u00a7r#49871982"); - component.appendText("\n\u00a77Sharing your Ban ID may affect the processing of your appeal!"); - Minecraft.getMinecraft().getNetHandler().getNetworkManager().closeChannel(component); - return; - } - Utils.addChatMessage(EnumChatFormatting.RED + DEV_FAIL_STRINGS[devFailIndex++]); - return; - } - if (args.length == 1 && args[0].equalsIgnoreCase("dumpapihistogram")) { - synchronized (ApiCache.INSTANCE) { - Utils.addChatMessage("§e[NEU] API Request Histogram"); - Utils.addChatMessage("§e[NEU] §bClass Name§e: §aCached§e/§cNonCached§e/§dTotal"); - ApiCache.INSTANCE.getHistogramTotalRequests().forEach((className, totalRequests) -> { - var nonCachedRequests = ApiCache.INSTANCE.getHistogramNonCachedRequests().getOrDefault(className, 0); - var cachedRequests = totalRequests - nonCachedRequests; - Utils.addChatMessage( - String.format( - "§e[NEU] §b%s §a%d§e/§c%d§e/§d%d", - className, - cachedRequests, - nonCachedRequests, - totalRequests - )); - }); - } - } - if (args.length == 1 && args[0].equalsIgnoreCase("testprofile")) { - NotEnoughUpdates.INSTANCE.manager.apiUtils.newHypixelApiRequest("skyblock/profiles") - .queryArgument( - "uuid", - "" + Minecraft.getMinecraft().thePlayer.getUniqueID() - ) - .requestJson() - .thenApply(jsonObject -> { - JsonArray profiles = jsonObject.get("profiles").getAsJsonArray(); - JsonObject cp = null; - for (JsonElement profile : profiles) { - JsonObject asJsonObject = profile.getAsJsonObject(); - if ((asJsonObject.has("selected") && - asJsonObject.get("selected").getAsBoolean()) || cp == null) { - cp = asJsonObject; - } - } - return cp; - }) - .thenCompose(obj -> ProfileCollectionInfo.getCollectionData( - obj, - Minecraft.getMinecraft().thePlayer.getUniqueID().toString() - )) - .thenAccept(it -> - Utils.addChatMessage("Response: " + it)); - } - if (args.length >= 1 && args[0].equalsIgnoreCase("profileinfo")) { - String currentProfile = SBInfo.getInstance().currentProfile; - SBInfo.Gamemode gamemode = SBInfo.getInstance().getGamemodeForProfile(currentProfile); - sender.addChatMessage(new ChatComponentText(EnumChatFormatting.GOLD + - "You are on Profile " + - currentProfile + - " with the mode " + - gamemode)); - } - if (args.length >= 1 && args[0].equalsIgnoreCase("buildflags")) { - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText( - "BuildFlags: \n" + - BuildFlags.getAllFlags().entrySet().stream() - .map(it -> " + " + it.getKey() + " - " + it.getValue()) - .collect(Collectors.joining("\n")))); - return; - } - if (args.length >= 1 && args[0].equalsIgnoreCase("exteditor")) { - if (args.length > 1) { - NotEnoughUpdates.INSTANCE.config.hidden.externalEditor = String.join( - " ", - Arrays.copyOfRange(args, 1, args.length) - ); - } - Utils.addChatMessage( - "§e[NEU] §fYour external editor is: §Z" + NotEnoughUpdates.INSTANCE.config.hidden.externalEditor); - return; - } - if (args.length >= 1 && args[0].equalsIgnoreCase("pricetest")) { - if (args.length == 1) { - NotEnoughUpdates.INSTANCE.manager.auctionManager.updateBazaar(); - } else { - NotEnoughUpdates.INSTANCE.openGui = new GuiPriceGraph(args[1]); - } - } - if (args.length == 1 && args[0].equalsIgnoreCase("zone")) { - BlockPos target = Minecraft.getMinecraft().objectMouseOver.getBlockPos(); - if (target == null) target = Minecraft.getMinecraft().thePlayer.getPosition(); - SpecialBlockZone zone = CustomBiomes.INSTANCE.getSpecialZone(target); - Arrays.asList( - new ChatComponentText("Showing Zone Info for: " + target), - new ChatComponentText("Zone: " + (zone != null ? zone.name() : "null")), - new ChatComponentText("Location: " + SBInfo.getInstance().getLocation()), - new ChatComponentText("Biome: " + CustomBiomes.INSTANCE.getCustomBiome(target)) - ).forEach(Minecraft.getMinecraft().thePlayer::addChatMessage); - MinecraftForge.EVENT_BUS.post(new LocationChangeEvent(SBInfo.getInstance().getLocation(), SBInfo - .getInstance() - .getLocation())); - } - if (args.length == 1 && args[0].equalsIgnoreCase("positiontest")) { - NotEnoughUpdates.INSTANCE.openGui = new GuiPositionEditor(); - return; - } - - if (args.length == 2 && args[0].equalsIgnoreCase("pt")) { - FishingHelper.type = EnumParticleTypes.valueOf(args[1]); - return; - } - if (args.length == 1 && args[0].equalsIgnoreCase("dev")) { - NotEnoughUpdates.INSTANCE.config.hidden.dev = !NotEnoughUpdates.INSTANCE.config.hidden.dev; - Utils.addChatMessage( - "§e[NEU] Dev mode " + (NotEnoughUpdates.INSTANCE.config.hidden.dev ? "§aenabled" : "§cdisabled")); - return; - } - if (args.length == 1 && args[0].equalsIgnoreCase("saveconfig")) { - NotEnoughUpdates.INSTANCE.saveConfig(); - return; - } - if (args.length == 1 && args[0].equalsIgnoreCase("searchmode")) { - NotEnoughUpdates.INSTANCE.config.hidden.firstTimeSearchFocus = true; - Utils.addChatMessage(EnumChatFormatting.AQUA + "I would never search"); - return; - } - if (args.length == 1 && args[0].equalsIgnoreCase("bluehair")) { - PronounDB.test(); - return; - } - if (args.length == 2 && args[0].equalsIgnoreCase("openGui")) { - try { - NotEnoughUpdates.INSTANCE.openGui = (GuiScreen) Class.forName(args[1]).newInstance(); - Utils.addChatMessage("Opening gui: " + NotEnoughUpdates.INSTANCE.openGui); - } catch (InstantiationException | IllegalAccessException | ClassNotFoundException | ClassCastException e) { - e.printStackTrace(); - Utils.addChatMessage("Failed to open this GUI."); - } - } - if (args.length == 1 && args[0].equalsIgnoreCase("center")) { - double x = Math.floor(Minecraft.getMinecraft().thePlayer.posX) + 0.5f; - double z = Math.floor(Minecraft.getMinecraft().thePlayer.posZ) + 0.5f; - Minecraft.getMinecraft().thePlayer.setPosition(x, Minecraft.getMinecraft().thePlayer.posY, z); - } - if (args.length >= 1 && args[0].equalsIgnoreCase("minion")) { - MinionHelperManager.getInstance().handleCommand(args); - } - if (args.length == 1 && args[0].equalsIgnoreCase("copytablist")) { - StringBuilder builder = new StringBuilder(); - for (String name : TabListUtils.getTabList()) { - builder.append(name).append("\n"); - } - MiscUtils.copyToClipboard(builder.toString()); - Utils.addChatMessage("§e[NEU] Copied tablist to clipboard!"); - } - if (args.length >= 1 && args[0].equalsIgnoreCase("useragent")) { - String newUserAgent = args.length == 1 ? null : String.join(" ", Arrays.copyOfRange(args, 1, args.length)); - Utils.addChatMessage("§e[NEU] Changed user agent override to: " + newUserAgent); - NotEnoughUpdates.INSTANCE.config.hidden.customUserAgent = newUserAgent; - } - if (args.length == 2 && args[0].equalsIgnoreCase("value")) { - try { - testValue = Integer.parseInt(args[1]); - } catch (NumberFormatException e) { - Utils.addChatMessage("NumberFormatException!"); - } - } - } -} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/DiagCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/DiagCommand.java deleted file mode 100644 index fb546efb..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/DiagCommand.java +++ /dev/null @@ -1,134 +0,0 @@ -/* - * Copyright (C) 2022 NotEnoughUpdates contributors - * - * This file is part of NotEnoughUpdates. - * - * NotEnoughUpdates is free software: you can redistribute it - * and/or modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation, either - * version 3 of the License, or (at your option) any later version. - * - * NotEnoughUpdates is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with NotEnoughUpdates. If not, see . - */ - -package io.github.moulberry.notenoughupdates.commands.dev; - -import io.github.moulberry.notenoughupdates.NotEnoughUpdates; -import io.github.moulberry.notenoughupdates.commands.ClientCommandBase; -import io.github.moulberry.notenoughupdates.miscfeatures.CrystalMetalDetectorSolver; -import io.github.moulberry.notenoughupdates.miscfeatures.CrystalWishingCompassSolver; -import io.github.moulberry.notenoughupdates.options.customtypes.NEUDebugFlag; -import net.minecraft.command.CommandException; -import net.minecraft.command.ICommandSender; -import net.minecraft.util.ChatComponentText; -import net.minecraft.util.EnumChatFormatting; - -public class DiagCommand extends ClientCommandBase { - public DiagCommand() { - super("neudiag"); - } - - private static final String USAGE_TEXT = EnumChatFormatting.WHITE + - "Usage: /neudiag \n\n" + - "/neudiag metal Metal Detector Solver diagnostics\n" + - " Show current solution diags\n" + - " center= Disable / enable using center\n" + - "/neudiag wishing Wishing Compass Solver diagnostics\n" + - "/neudiag debug\n" + - " Show all enabled flags\n" + - " Show all flags\n"+ - " Enable/disable flag\n"; - - private void showUsage(ICommandSender sender) { - sender.addChatMessage(new ChatComponentText(USAGE_TEXT)); - } - - @Override - public void processCommand(ICommandSender sender, String[] args) throws CommandException { - if (args.length == 0) { - showUsage(sender); - return; - } - - String command = args[0].toLowerCase(); - switch (command) { - case "metal": - if (args.length == 1) { - CrystalMetalDetectorSolver.logDiagnosticData(true); - return; - } - - String subCommand = args[1].toLowerCase(); - if (subCommand.equals("center=off")) { - CrystalMetalDetectorSolver.setDebugDoNotUseCenter(true); - sender.addChatMessage(new ChatComponentText(EnumChatFormatting.YELLOW + - "Center coordinates-based solutions disabled")); - } else if (subCommand.equals("center=on")) { - CrystalMetalDetectorSolver.setDebugDoNotUseCenter(false); - sender.addChatMessage(new ChatComponentText(EnumChatFormatting.YELLOW + - "Center coordinates-based solutions enabled")); - } else { - showUsage(sender); - return; - } - - break; - case "wishing": - CrystalWishingCompassSolver.getInstance().logDiagnosticData(true); - break; - case "debug": - if (args.length > 1) { - boolean enablingFlag = true; - String action = args[1]; - switch (action) { - case "list": - sender.addChatMessage(new ChatComponentText( - EnumChatFormatting.YELLOW + "Here are all flags:\n" + NEUDebugFlag.getFlagList())); - return; - case "disable": - enablingFlag = false; - // falls through - case "enable": - if (args.length != 3) { - sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + - "You must specify a flag:\n" + - NEUDebugFlag.getFlagList())); - return; - } - - String flagName = args[2].toUpperCase(); - try { - NEUDebugFlag debugFlag = NEUDebugFlag.valueOf(flagName); - if (enablingFlag) { - NotEnoughUpdates.INSTANCE.config.hidden.debugFlags.add(debugFlag); - } else { - NotEnoughUpdates.INSTANCE.config.hidden.debugFlags.remove(debugFlag); - } - } catch (IllegalArgumentException e) { - sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + - flagName + " is invalid. Valid flags are:\n" + - NEUDebugFlag.getFlagList())); - return; - } - break; - default: - showUsage(sender); - return; - } - } - - sender.addChatMessage(new ChatComponentText(EnumChatFormatting.YELLOW + "Effective debug flags: \n" + - NEUDebugFlag.getEnabledFlags())); - break; - default: - showUsage(sender); - return; - } - } -} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/DungeonWinTestCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/DungeonWinTestCommand.java deleted file mode 100644 index be25e697..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/DungeonWinTestCommand.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (C) 2022 NotEnoughUpdates contributors - * - * This file is part of NotEnoughUpdates. - * - * NotEnoughUpdates is free software: you can redistribute it - * and/or modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation, either - * version 3 of the License, or (at your option) any later version. - * - * NotEnoughUpdates is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with NotEnoughUpdates. If not, see . - */ - -package io.github.moulberry.notenoughupdates.commands.dev; - -import io.github.moulberry.notenoughupdates.commands.ClientCommandBase; -import io.github.moulberry.notenoughupdates.dungeons.DungeonWin; -import net.minecraft.command.CommandException; -import net.minecraft.command.ICommandSender; -import net.minecraft.util.ResourceLocation; - -public class DungeonWinTestCommand extends ClientCommandBase { - - public DungeonWinTestCommand() { - super("neudungeonwintest"); - } - - @Override - public void processCommand(ICommandSender sender, String[] args) throws CommandException { - if (args.length > 0) { - DungeonWin.TEAM_SCORE = new ResourceLocation("notenoughupdates:dungeon_win/" + args[0].toLowerCase() + ".png"); - } - - DungeonWin.displayWin(); - } -} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/EnableStorageCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/EnableStorageCommand.java deleted file mode 100644 index 3415b030..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/EnableStorageCommand.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (C) 2022 NotEnoughUpdates contributors - * - * This file is part of NotEnoughUpdates. - * - * NotEnoughUpdates is free software: you can redistribute it - * and/or modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation, either - * version 3 of the License, or (at your option) any later version. - * - * NotEnoughUpdates is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with NotEnoughUpdates. If not, see . - */ - -package io.github.moulberry.notenoughupdates.commands.dev; - -import io.github.moulberry.notenoughupdates.NotEnoughUpdates; -import io.github.moulberry.notenoughupdates.commands.ClientCommandBase; -import net.minecraft.command.CommandException; -import net.minecraft.command.ICommandSender; - -public class EnableStorageCommand extends ClientCommandBase { - - public EnableStorageCommand() { - super("neuenablestorage"); - } - - @Override - public void processCommand(ICommandSender sender, String[] args) throws CommandException { - NotEnoughUpdates.INSTANCE.config.storageGUI.enableStorageGUI3 = true; - NotEnoughUpdates.INSTANCE.saveConfig(); - } - -} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/NullzeeSphereCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/NullzeeSphereCommand.java deleted file mode 100644 index 3a9ce90f..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/NullzeeSphereCommand.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (C) 2022 NotEnoughUpdates contributors - * - * This file is part of NotEnoughUpdates. - * - * NotEnoughUpdates is free software: you can redistribute it - * and/or modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation, either - * version 3 of the License, or (at your option) any later version. - * - * NotEnoughUpdates is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with NotEnoughUpdates. If not, see . - */ - -package io.github.moulberry.notenoughupdates.commands.dev; - -import io.github.moulberry.notenoughupdates.commands.ClientCommandBase; -import io.github.moulberry.notenoughupdates.miscfeatures.NullzeeSphere; -import net.minecraft.client.entity.EntityPlayerSP; -import net.minecraft.command.CommandException; -import net.minecraft.command.ICommandSender; -import net.minecraft.util.BlockPos; -import net.minecraft.util.ChatComponentText; -import net.minecraft.util.EnumChatFormatting; - -public class NullzeeSphereCommand extends ClientCommandBase { - - public NullzeeSphereCommand() { - super("neuzeesphere"); - } - - @Override - public void processCommand(ICommandSender sender, String[] args) throws CommandException { - if (args.length != 1) { - sender.addChatMessage(new ChatComponentText( - EnumChatFormatting.RED + "Usage: /neuzeesphere [on/off] or /neuzeesphere (radius) or /neuzeesphere setCenter")); - return; - } - if (args[0].equalsIgnoreCase("on")) { - NullzeeSphere.enabled = true; - } else if (args[0].equalsIgnoreCase("off")) { - NullzeeSphere.enabled = false; - } else if (args[0].equalsIgnoreCase("setCenter")) { - EntityPlayerSP p = ((EntityPlayerSP) sender); - NullzeeSphere.centerPos = new BlockPos(p.posX, p.posY, p.posZ); - NullzeeSphere.overlayVBO = null; - } else { - try { - NullzeeSphere.size = Float.parseFloat(args[0]); - NullzeeSphere.overlayVBO = null; - } catch (Exception e) { - sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "Can't parse radius: " + args[0])); - } - } - } -} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/PackDevCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/PackDevCommand.java deleted file mode 100644 index 1d30a15f..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/PackDevCommand.java +++ /dev/null @@ -1,304 +0,0 @@ -/* - * Copyright (C) 2022 NotEnoughUpdates contributors - * - * This file is part of NotEnoughUpdates. - * - * NotEnoughUpdates is free software: you can redistribute it - * and/or modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation, either - * version 3 of the License, or (at your option) any later version. - * - * NotEnoughUpdates is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with NotEnoughUpdates. If not, see . - */ - -package io.github.moulberry.notenoughupdates.commands.dev; - -import io.github.moulberry.notenoughupdates.NotEnoughUpdates; -import io.github.moulberry.notenoughupdates.commands.ClientCommandBase; -import io.github.moulberry.notenoughupdates.core.util.MiscUtils; -import io.github.moulberry.notenoughupdates.util.Utils; -import net.minecraft.client.Minecraft; -import net.minecraft.client.entity.AbstractClientPlayer; -import net.minecraft.command.CommandException; -import net.minecraft.command.ICommandSender; -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityLiving; -import net.minecraft.entity.EntityLivingBase; -import net.minecraft.entity.item.EntityArmorStand; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTBase; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.BlockPos; -import net.minecraft.util.ChatComponentText; -import net.minecraft.util.EnumChatFormatting; - -import java.util.HashMap; -import java.util.List; -import java.util.function.Supplier; - -public class PackDevCommand extends ClientCommandBase { - static Minecraft mc = Minecraft.getMinecraft(); - - public PackDevCommand() { - super("neupackdev"); - } - - private static final HashMap> commands = new HashMap>() {{ - put( - "getnpc", - new Command<>( - "NPC", - () -> mc.theWorld.playerEntities, - true, - AbstractClientPlayer.class - ) - ); - put( - "getnpcs", - new Command<>( - "NPC", - () -> mc.theWorld.playerEntities, - false, - AbstractClientPlayer.class - ) - ); - put( - "getmob", - new Command<>( - "mob", - () -> mc.theWorld.loadedEntityList, - true, - EntityLiving.class - ) - ); - put( - "getmobs", - new Command<>( - "mob", - () -> mc.theWorld.loadedEntityList, - false, - EntityLiving.class - ) - ); - put( - "getarmorstand", - new Command<>( - "armor stand", - () -> mc.theWorld.loadedEntityList, - true, - EntityArmorStand.class - ) - ); - put( - "getarmorstands", - new Command<>( - "armor stand", - () -> mc.theWorld.loadedEntityList, - false, - EntityArmorStand.class - ) - ); - }}; - - @Override - public List addTabCompletionOptions(ICommandSender sender, String[] args, BlockPos pos) { - return args.length == 1 ? getListOfStringsMatchingLastWord(args, commands.keySet()) : null; - } - - public static void togglePackDeveloperMode(ICommandSender sender) { - NotEnoughUpdates.INSTANCE.packDevEnabled = !NotEnoughUpdates.INSTANCE.packDevEnabled; - if (NotEnoughUpdates.INSTANCE.packDevEnabled) { - sender.addChatMessage(new ChatComponentText( - EnumChatFormatting.GREEN + "Enabled pack developer mode.")); - } else { - sender.addChatMessage(new ChatComponentText( - EnumChatFormatting.RED + "Disabled pack developer mode.")); - } - } - - @Override - public void processCommand(ICommandSender sender, String[] args) throws CommandException { - if (args.length == 0) { - togglePackDeveloperMode(sender); - return; - } - - double dist = 5.0; - if (args.length >= 2) { - try { - dist = Double.parseDouble(args[1]); - } catch (NumberFormatException e) { - sender.addChatMessage(new ChatComponentText( - EnumChatFormatting.RED + "Invalid distance! Must be a number, defaulting to a radius of 5.")); - } - } - - StringBuilder output; - String subCommand = args[0].toLowerCase(); - if (commands.containsKey(subCommand)) { - Command command = commands.get(subCommand); - output = command.getData(dist); - } else if (subCommand.equals("getall")) { - output = getAll(dist); - } else if (subCommand.equals("getallclose")) { - output = getAllClose(dist); - } else { - sender.addChatMessage(new ChatComponentText( - EnumChatFormatting.RED + "Invalid sub-command.")); - return; - } - - if (output.length() != 0) { - MiscUtils.copyToClipboard(output.toString()); - } - } - - private static StringBuilder getAllClose(Double dist) { - StringBuilder sb = new StringBuilder(); - sb.append(commands.get("getmob").getData(dist)); - sb.append(commands.get("getarmorstand").getData(dist)); - sb.append(commands.get("getnpc").getData(dist)); - return sb; - } - - private static StringBuilder getAll(Double dist) { - StringBuilder sb = new StringBuilder(); - sb.append(commands.get("getmobs").getData(dist)); - sb.append(commands.get("getarmorstands").getData(dist)); - sb.append(commands.get("getnpcs").getData(dist)); - return sb; - } - - public static StringBuilder livingBaseDataBuilder(T entity, Class clazz) { - StringBuilder entityData = new StringBuilder(); - if (EntityPlayer.class.isAssignableFrom(entity.getClass())) { - EntityPlayer entityPlayer = (EntityPlayer) entity; - - // NPC Information - String skinResourcePath = ((AbstractClientPlayer) entityPlayer).getLocationSkin().getResourcePath(); - entityData - .append("Player Id: ") - .append(entityPlayer.getUniqueID() != null ? entityPlayer.getUniqueID().toString() : "null") - .append(entityPlayer.getCustomNameTag() != null ? entityPlayer.getCustomNameTag() : "null") - .append("\nEntity Texture Id: ") - .append(skinResourcePath != null ? skinResourcePath.replace("skins/", "") : "null"); - } - - if (!clazz.isAssignableFrom(entity.getClass())) { - return entityData; - } - - //Entity Information - entityData - .append("Entity Id: ") - .append(entity.getEntityId()) - .append("\nMob: ") - .append(entity.getName() != null ? entity.getName() : "null") - .append("\nCustom Name: ") - .append(entity.getCustomNameTag() != null ? entity.getCustomNameTag() : "null"); - - //Held Item - if (entity.getHeldItem() != null) { - entityData - .append("\nItem: ") - .append(entity.getHeldItem()) - .append("\nItem Display Name: ") - .append(entity.getHeldItem().getDisplayName() != null - ? entity.getHeldItem().getDisplayName() - : "null") - .append("\nItem Tag Compound: "); - NBTTagCompound heldItemTagCompound = entity.getHeldItem().getTagCompound(); - if (heldItemTagCompound != null) { - String heldItemString = heldItemTagCompound.toString(); - NBTBase extraAttrTag = heldItemTagCompound.getTag("ExtraAttributes"); - entityData - .append(heldItemString != null ? heldItemString : "null") - .append("\nItem Tag Compound Extra Attributes: ") - .append(extraAttrTag != null ? extraAttrTag : "null"); - } else { - entityData.append("null"); - } - - } else { - entityData.append("\nItem: null"); - } - - entityData.append(armorDataBuilder(entity)).append("\n\n"); - - return entityData; - } - - private static final String[] armorPieceTypes = {"Boots", "Leggings", "Chestplate", "Helmet"}; - - public static StringBuilder armorDataBuilder(T entity) { - StringBuilder armorData = new StringBuilder(); - for (int i = 0; i < 4; i++) { - ItemStack currentArmor = entity.getCurrentArmor(0); - armorData.append(String.format("\n%s: ", armorPieceTypes[i])); - if (currentArmor == null) { - armorData.append("null"); - } else { - armorData.append(currentArmor.getTagCompound() != null ? currentArmor.getTagCompound().toString() : "null"); - } - } - return armorData; - } - - static class Command { - String typeFriendlyName; - Supplier> entitySupplier; - Class clazz; - boolean single; - - Command( - String typeFriendlyName, - Supplier> entitySupplier, - boolean single, - Class clazz - ) { - this.typeFriendlyName = typeFriendlyName; - this.entitySupplier = entitySupplier; - this.single = single; - this.clazz = clazz; - } - - @SuppressWarnings("unchecked") - public StringBuilder getData(double dist) { - StringBuilder result = new StringBuilder(); - double distSq = dist * dist; - T closest = null; - for (Entity entity : entitySupplier.get()) { - if (!clazz.isAssignableFrom(entity.getClass()) || entity == mc.thePlayer) { - continue; - } - T entityT = (T) entity; - double entityDistanceSq = entity.getDistanceSq(mc.thePlayer.posX, mc.thePlayer.posY, mc.thePlayer.posZ); - if (entityDistanceSq < distSq) { - if (single) { - distSq = entityDistanceSq; - closest = entityT; - } else { - result.append(livingBaseDataBuilder(entityT, clazz)); - } - } - } - - if ((single && closest == null) || (!single && result.length() == 0)) { - Utils.addChatMessage(EnumChatFormatting.RED + "No " + typeFriendlyName + "s found within " + dist + " blocks."); - } else { - Utils.addChatMessage( - EnumChatFormatting.GREEN + "Copied " + typeFriendlyName + " data to clipboard"); - return single ? livingBaseDataBuilder(closest, clazz) : result; - } - - return result; - } - } -} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/ReloadRepoCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/ReloadRepoCommand.java deleted file mode 100644 index 0bf57594..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/ReloadRepoCommand.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (C) 2022 NotEnoughUpdates contributors - * - * This file is part of NotEnoughUpdates. - * - * NotEnoughUpdates is free software: you can redistribute it - * and/or modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation, either - * version 3 of the License, or (at your option) any later version. - * - * NotEnoughUpdates is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with NotEnoughUpdates. If not, see . - */ - -package io.github.moulberry.notenoughupdates.commands.dev; - -import io.github.moulberry.notenoughupdates.NotEnoughUpdates; -import io.github.moulberry.notenoughupdates.commands.ClientCommandBase; -import net.minecraft.command.CommandException; -import net.minecraft.command.ICommandSender; -import net.minecraft.util.ChatComponentText; - -public class ReloadRepoCommand extends ClientCommandBase { - - public ReloadRepoCommand() { - super("neureloadrepo"); - } - - @Override - public void processCommand(ICommandSender sender, String[] args) throws CommandException { - NotEnoughUpdates.INSTANCE.manager.reloadRepository(); - sender.addChatMessage(new ChatComponentText("§e[NEU] Reloaded repository.")); - } -} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/ResetRepoCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/ResetRepoCommand.java deleted file mode 100644 index 3f693898..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/ResetRepoCommand.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (C) 2022 NotEnoughUpdates contributors - * - * This file is part of NotEnoughUpdates. - * - * NotEnoughUpdates is free software: you can redistribute it - * and/or modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation, either - * version 3 of the License, or (at your option) any later version. - * - * NotEnoughUpdates is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with NotEnoughUpdates. If not, see . - */ - -package io.github.moulberry.notenoughupdates.commands.dev; - -import io.github.moulberry.notenoughupdates.NotEnoughUpdates; -import io.github.moulberry.notenoughupdates.commands.ClientCommandBase; -import net.minecraft.command.CommandException; -import net.minecraft.command.ICommandSender; -import net.minecraft.util.ChatComponentText; - -public class ResetRepoCommand extends ClientCommandBase { - - public ResetRepoCommand() { - super("neuresetrepo"); - } - - @Override - public void processCommand(ICommandSender sender, String[] args) throws CommandException { - NotEnoughUpdates.INSTANCE.manager - .userFacingRepositoryReload() - .thenAccept(strings -> - strings.forEach(line -> - sender.addChatMessage(new ChatComponentText("§e[NEU] " + line)))); - } -} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/StatsCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/StatsCommand.java deleted file mode 100644 index ea417977..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/StatsCommand.java +++ /dev/null @@ -1,200 +0,0 @@ -/* - * Copyright (C) 2022 NotEnoughUpdates contributors - * - * This file is part of NotEnoughUpdates. - * - * NotEnoughUpdates is free software: you can redistribute it - * and/or modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation, either - * version 3 of the License, or (at your option) any later version. - * - * NotEnoughUpdates is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with NotEnoughUpdates. If not, see . - */ - -package io.github.moulberry.notenoughupdates.commands.dev; - -import io.github.moulberry.notenoughupdates.NotEnoughUpdates; -import io.github.moulberry.notenoughupdates.commands.ClientCommandBase; -import io.github.moulberry.notenoughupdates.util.DiscordMarkdownBuilder; -import io.github.moulberry.notenoughupdates.util.HastebinUploader; -import io.github.moulberry.notenoughupdates.util.SBInfo; -import io.github.moulberry.notenoughupdates.util.Utils; -import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.OpenGlHelper; -import net.minecraft.command.ICommandSender; -import net.minecraft.util.BlockPos; -import net.minecraft.util.EnumChatFormatting; -import net.minecraftforge.common.ForgeVersion; -import net.minecraftforge.fml.client.FMLClientHandler; -import net.minecraftforge.fml.common.Loader; -import org.lwjgl.opengl.Display; -import org.lwjgl.opengl.GL11; - -import javax.management.JMX; -import javax.management.MBeanServer; -import javax.management.ObjectName; -import java.awt.*; -import java.awt.datatransfer.StringSelection; -import java.lang.management.ManagementFactory; -import java.util.List; -import java.util.Locale; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; - -public class StatsCommand extends ClientCommandBase { - private final ExecutorService threadPool = Executors.newFixedThreadPool(1); - - public StatsCommand() { - super("neustats"); - } - - private static final int activeModCount = Loader.instance().getActiveModList().size(); - - @Override - public void processCommand(ICommandSender sender, String[] args) { - if (args.length > 0) { - switch (args[0].toLowerCase(Locale.ROOT)) { - case "modlist": - if (activeModCount > 15) { - clipboardAndSendMessage(createModList(new DiscordMarkdownBuilder()).toString()); - } else { - clipboardAndSendMessage(createStats()); - } - break; - case "dump": - modPrefixedMessage(EnumChatFormatting.GREEN + - "This will upload a dump of the java classes your game has loaded how big they are and how many there are. This can take a few seconds as it is uploading to HasteBin."); - threadPool.submit(() -> { - try { - final MBeanServer server = ManagementFactory.getPlatformMBeanServer(); - final ObjectName objectName = ObjectName.getInstance("com.sun.management:type=DiagnosticCommand"); - final DiagnosticCommandMXBean proxy = JMX.newMXBeanProxy( - server, - objectName, - DiagnosticCommandMXBean.class - ); - clipboardAndSendMessage(HastebinUploader.upload( - proxy.gcClassHistogram(new String[0]).replace("[", "[]"), - HastebinUploader.Mode.NORMAL - )); - } catch (Exception e) { - clipboardAndSendMessage(null); - } - }); - break; - } - } else { - clipboardAndSendMessage(createStats()); - } - - } - - @Override - public List addTabCompletionOptions(ICommandSender sender, String[] args, BlockPos pos) { - return args.length == 1 ? getListOfStringsMatchingLastWord(args, "modlist", "dump") : null; - } - - public interface DiagnosticCommandMXBean { - String gcClassHistogram(String[] array); - } - - private static void clipboardAndSendMessage(String data) { - if (data == null) { - modPrefixedMessage(EnumChatFormatting.DARK_RED + "Error occurred trying to perform command."); - return; - } - try { - StringSelection clipboard = new StringSelection(data); - Toolkit.getDefaultToolkit().getSystemClipboard().setContents(clipboard, clipboard); - modPrefixedMessage(EnumChatFormatting.GREEN + "Dev info copied to clipboard."); - } catch (Exception ignored) { - modPrefixedMessage(EnumChatFormatting.DARK_RED + "Could not copy to clipboard."); - } - } - - private static void modPrefixedMessage(String message) { - Utils.addChatMessage( - EnumChatFormatting.GOLD + "[" + EnumChatFormatting.RED + "NotEnoughUpdates" + EnumChatFormatting.GOLD + "]: " + message); - } - - private static String createStats() { - DiscordMarkdownBuilder builder = new DiscordMarkdownBuilder(); - long maxMemory = Runtime.getRuntime().maxMemory(); - long totalMemory = Runtime.getRuntime().totalMemory(); - long freeMemory = Runtime.getRuntime().freeMemory(); - long currentMemory = totalMemory - freeMemory; - - builder.category("System Stats"); - builder.append("OS", System.getProperty("os.name")); - builder.append("CPU", OpenGlHelper.getCpu()); - builder.append( - "Display", - String.format("%dx%d (%s)", Display.getWidth(), Display.getHeight(), GL11.glGetString(GL11.GL_VENDOR)) - ); - builder.append("GPU", GL11.glGetString(GL11.GL_RENDERER)); - builder.append("GPU Driver", GL11.glGetString(GL11.GL_VERSION)); - if (getMemorySize() > 0) builder.append("Maximum Memory", (getMemorySize() / 1024L / 1024L) + "MB"); - builder.append("Shaders", ("" + OpenGlHelper.isFramebufferEnabled()).toUpperCase()); - builder.category("Java Stats"); - builder.append( - "Java", - String.format("%s %dbit", System.getProperty("java.version"), Minecraft.getMinecraft().isJava64bit() ? 64 : 32) - ); - builder.append( - "Memory", - String.format( - "% 2d%% %03d/%03dMB", - currentMemory * 100L / maxMemory, - currentMemory / 1024L / 1024L, - maxMemory / 1024L / 1024L - ) - ); - builder.append( - "Memory Allocated", - String.format("% 2d%% %03dMB", totalMemory * 100L / maxMemory, totalMemory / 1024L / 1024L) - ); - builder.category("Game Stats"); - builder.append("FPS", String.valueOf(Minecraft.getDebugFPS())); - builder.append("Loaded Mods", String.valueOf(activeModCount)); - builder.append("Forge", ForgeVersion.getVersion()); - builder.append("Optifine", FMLClientHandler.instance().hasOptifine() ? "TRUE" : "FALSE"); - builder.category("Neu Settings"); - builder.append("API Key", NotEnoughUpdates.INSTANCE.config.apiData.apiKey.isEmpty() ? "FALSE" : "TRUE"); - builder.append("On SkyBlock", NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard() ? "TRUE" : "FALSE"); - builder.append( - "Mod Version", - Loader.instance().getIndexedModList().get(NotEnoughUpdates.MODID).getDisplayVersion() - ); - builder.append("SB Profile", SBInfo.getInstance().currentProfile); - builder.append("Has Advanced Tab", SBInfo.getInstance().hasNewTab ? "TRUE" : "FALSE"); - builder.category("Repo Stats"); - builder.append("Last Commit", NotEnoughUpdates.INSTANCE.manager.latestRepoCommit); - builder.append("Loaded Items", String.valueOf(NotEnoughUpdates.INSTANCE.manager.getItemInformation().size())); - if (activeModCount <= 15) createModList(builder); - - return builder.toString(); - } - - private static DiscordMarkdownBuilder createModList(DiscordMarkdownBuilder builder) { - builder.category("Mods Loaded"); - Loader.instance().getActiveModList().forEach(mod -> builder.append(mod.getName(), mod.getSource().getName())); - return builder; - } - - private static long getMemorySize() { - try { - return ((com.sun.management.OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean()).getTotalPhysicalMemorySize(); - } catch (Exception e) { - try { - return ((com.sun.management.UnixOperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean()).getTotalPhysicalMemorySize(); - } catch (Exception ignored) {/*IGNORE*/} - } - return -1; - } -} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/dungeon/DhCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/dungeon/DhCommand.java deleted file mode 100644 index 222862f9..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/commands/dungeon/DhCommand.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (C) 2022 NotEnoughUpdates contributors - * - * This file is part of NotEnoughUpdates. - * - * NotEnoughUpdates is free software: you can redistribute it - * and/or modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation, either - * version 3 of the License, or (at your option) any later version. - * - * NotEnoughUpdates is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with NotEnoughUpdates. If not, see . - */ - -package io.github.moulberry.notenoughupdates.commands.dungeon; - -import io.github.moulberry.notenoughupdates.commands.ClientCommandBase; -import net.minecraft.client.Minecraft; -import net.minecraft.command.CommandException; -import net.minecraft.command.ICommandSender; - -public class DhCommand extends ClientCommandBase { - - public DhCommand() { - super("dh"); - } - - @Override - public void processCommand(ICommandSender sender, String[] args) throws CommandException { - Minecraft.getMinecraft().thePlayer.sendChatMessage("/warp dungeon_hub"); - } -} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/dungeon/DnCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/dungeon/DnCommand.java deleted file mode 100644 index 3b697905..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/commands/dungeon/DnCommand.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (C) 2022 NotEnoughUpdates contributors - * - * This file is part of NotEnoughUpdates. - * - * NotEnoughUpdates is free software: you can redistribute it - * and/or modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation, either - * version 3 of the License, or (at your option) any later version. - * - * NotEnoughUpdates is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with NotEnoughUpdates. If not, see . - */ - -package io.github.moulberry.notenoughupdates.commands.dungeon; - -import io.github.moulberry.notenoughupdates.commands.ClientCommandBase; -import io.github.moulberry.notenoughupdates.util.Utils; -import net.minecraft.client.Minecraft; -import net.minecraft.command.CommandException; -import net.minecraft.command.ICommandSender; -import net.minecraft.util.EnumChatFormatting; - -public class DnCommand extends ClientCommandBase { - - public DnCommand() { - super("dn"); - } - - @Override - public void processCommand(ICommandSender sender, String[] args) throws CommandException { - Minecraft.getMinecraft().thePlayer.sendChatMessage("/warp dungeon_hub"); - Utils.addChatMessage(EnumChatFormatting.AQUA + "Warping to:" + EnumChatFormatting.YELLOW + " Deez Nuts lmao"); - } -} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/dungeon/JoinDungeonCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/dungeon/JoinDungeonCommand.java deleted file mode 100644 index 58bfbef2..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/commands/dungeon/JoinDungeonCommand.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (C) 2022 NotEnoughUpdates contributors - * - * This file is part of NotEnoughUpdates. - * - * NotEnoughUpdates is free software: you can redistribute it - * and/or modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation, either - * version 3 of the License, or (at your option) any later version. - * - * NotEnoughUpdates is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with NotEnoughUpdates. If not, see . - */ - -package io.github.moulberry.notenoughupdates.commands.dungeon; - -import io.github.moulberry.notenoughupdates.NotEnoughUpdates; -import io.github.moulberry.notenoughupdates.commands.ClientCommandBase; -import io.github.moulberry.notenoughupdates.util.Utils; -import net.minecraft.client.Minecraft; -import net.minecraft.command.CommandException; -import net.minecraft.command.ICommandSender; -import net.minecraft.util.EnumChatFormatting; -import org.apache.commons.lang3.StringUtils; - -public class JoinDungeonCommand extends ClientCommandBase { - - public JoinDungeonCommand() { - super("join"); - } - - @Override - public void processCommand(ICommandSender sender, String[] args) throws CommandException { - if (!NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard()) { - Minecraft.getMinecraft().thePlayer.sendChatMessage("/join " + StringUtils.join(args, " ")); - } else { - if (args.length != 1) { - Utils.addChatMessage(EnumChatFormatting.RED + "Example Usage: /join f7, /join m6 or /join 7"); - } else { - String cataPrefix = "catacombs"; - if (args[0].toLowerCase().startsWith("m")) { - cataPrefix = "master_catacombs"; - } - String cmd = "/joindungeon " + cataPrefix + " " + args[0].charAt(args[0].length() - 1); - Utils.addChatMessage(EnumChatFormatting.YELLOW + "Running command: " + cmd); - Utils.addChatMessage(EnumChatFormatting.YELLOW + - "The dungeon should start soon. If it doesn't, make sure you have a party of 5 people"); - Minecraft.getMinecraft().thePlayer.sendChatMessage(cmd); - } - } - } -} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/dungeon/MapCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/dungeon/MapCommand.java deleted file mode 100644 index d52ed196..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/commands/dungeon/MapCommand.java +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Copyright (C) 2022 NotEnoughUpdates contributors - * - * This file is part of NotEnoughUpdates. - * - * NotEnoughUpdates is free software: you can redistribute it - * and/or modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation, either - * version 3 of the License, or (at your option) any later version. - * - * NotEnoughUpdates is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with NotEnoughUpdates. If not, see . - */ - -package io.github.moulberry.notenoughupdates.commands.dungeon; - -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import io.github.moulberry.notenoughupdates.NotEnoughUpdates; -import io.github.moulberry.notenoughupdates.commands.ClientCommandBase; -import io.github.moulberry.notenoughupdates.dungeons.GuiDungeonMapEditor; -import io.github.moulberry.notenoughupdates.util.Utils; -import net.minecraft.block.material.MapColor; -import net.minecraft.client.Minecraft; -import net.minecraft.command.CommandException; -import net.minecraft.command.ICommandSender; -import net.minecraft.item.ItemMap; -import net.minecraft.item.ItemStack; -import net.minecraft.util.ChatComponentText; -import net.minecraft.util.EnumChatFormatting; -import net.minecraft.world.storage.MapData; - -import java.awt.*; -import java.io.File; -import java.util.Map; - -public class MapCommand extends ClientCommandBase { - - public MapCommand() { - super("neumap"); - } - - @Override - public void processCommand(ICommandSender sender, String[] args) throws CommandException { - - if (!NotEnoughUpdates.INSTANCE.config.hidden.dev) { - NotEnoughUpdates.INSTANCE.openGui = new GuiDungeonMapEditor(null); - return; - } - - if (args.length == 1 && args[0].equals("reset")) { - NotEnoughUpdates.INSTANCE.colourMap = null; - return; - } - - if (args.length != 2) { - NotEnoughUpdates.INSTANCE.openGui = new GuiDungeonMapEditor(null); - return; - } - - if (args[0].equals("save")) { - ItemStack stack = Minecraft.getMinecraft().thePlayer.getHeldItem(); - if (stack != null && stack.getItem() instanceof ItemMap) { - ItemMap map = (ItemMap) stack.getItem(); - MapData mapData = map.getMapData(stack, Minecraft.getMinecraft().theWorld); - - if (mapData == null) return; - - JsonObject json = new JsonObject(); - for (int i = 0; i < 16384; ++i) { - int x = i % 128; - int y = i / 128; - - int j = mapData.colors[i] & 255; - - Color c; - if (j / 4 == 0) { - c = new Color((i + i / 128 & 1) * 8 + 16 << 24, true); - } else { - c = new Color(MapColor.mapColorArray[j / 4].getMapColor(j & 3), true); - } - - json.addProperty(x + ":" + y, c.getRGB()); - } - - try { - new File(NotEnoughUpdates.INSTANCE.manager.configLocation, "maps").mkdirs(); - NotEnoughUpdates.INSTANCE.manager.writeJson( - json, - new File(NotEnoughUpdates.INSTANCE.manager.configLocation, "maps/" + args[1] + ".json") - ); - } catch (Exception e) { - e.printStackTrace(); - } - - Utils.addChatMessage(EnumChatFormatting.GREEN + "Saved to file."); - } - - return; - } - - if (args[0].equals("load")) { - JsonObject json = NotEnoughUpdates.INSTANCE.manager.getJsonFromFile(new File( - NotEnoughUpdates.INSTANCE.manager.configLocation, - "maps/" + args[1] + ".json" - )); - - NotEnoughUpdates.INSTANCE.colourMap = new Color[128][128]; - for (int x = 0; x < 128; x++) { - for (int y = 0; y < 128; y++) { - NotEnoughUpdates.INSTANCE.colourMap[x][y] = new Color(0, 0, 0, 0); - } - } - for (Map.Entry entry : json.entrySet()) { - int x = Integer.parseInt(entry.getKey().split(":")[0]); - int y = Integer.parseInt(entry.getKey().split(":")[1]); - - NotEnoughUpdates.INSTANCE.colourMap[x][y] = new Color(entry.getValue().getAsInt(), true); - } - - return; - } - - NotEnoughUpdates.INSTANCE.openGui = new GuiDungeonMapEditor(null); - } -} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/help/FeaturesCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/help/FeaturesCommand.java deleted file mode 100644 index bbabc172..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/commands/help/FeaturesCommand.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (C) 2022 NotEnoughUpdates contributors - * - * This file is part of NotEnoughUpdates. - * - * NotEnoughUpdates is free software: you can redistribute it - * and/or modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation, either - * version 3 of the License, or (at your option) any later version. - * - * NotEnoughUpdates is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with NotEnoughUpdates. If not, see . - */ - -package io.github.moulberry.notenoughupdates.commands.help; - -import io.github.moulberry.notenoughupdates.commands.ClientCommandBase; -import io.github.moulberry.notenoughupdates.util.Constants; -import io.github.moulberry.notenoughupdates.util.Utils; -import net.minecraft.client.Minecraft; -import net.minecraft.command.CommandException; -import net.minecraft.command.ICommandSender; -import net.minecraft.event.ClickEvent; -import net.minecraft.util.ChatComponentText; -import net.minecraft.util.EnumChatFormatting; - -public class FeaturesCommand extends ClientCommandBase { - public FeaturesCommand() { - super("neufeatures"); - } - - @Override - public void processCommand(ICommandSender sender, String[] args) throws CommandException { - Utils.addChatMessage(""); - if (Constants.MISC == null || !Constants.MISC.has("featureslist")) { - Utils.showOutdatedRepoNotification(); - return; - } - String url = Constants.MISC.get("featureslist").getAsString(); - - if (Utils.openUrl(url)) { - Utils.addChatMessage( - EnumChatFormatting.DARK_PURPLE + "" + EnumChatFormatting.BOLD + "NEU" + EnumChatFormatting.RESET + - EnumChatFormatting.GOLD + "> Opening Feature List in browser."); - } else { - ChatComponentText clickTextFeatures = new ChatComponentText( - EnumChatFormatting.DARK_PURPLE + "" + EnumChatFormatting.BOLD + "NEU" + EnumChatFormatting.RESET + - EnumChatFormatting.GOLD + "> Click here to open the Feature List in your browser."); - clickTextFeatures.setChatStyle(Utils.createClickStyle(ClickEvent.Action.OPEN_URL, url)); - Minecraft.getMinecraft().thePlayer.addChatMessage(clickTextFeatures); - - } - Utils.addChatMessage(""); - } -} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/help/HelpCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/help/HelpCommand.java deleted file mode 100644 index 3a47509d..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/commands/help/HelpCommand.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (C) 2022 NotEnoughUpdates contributors - * - * This file is part of NotEnoughUpdates. - * - * NotEnoughUpdates is free software: you can redistribute it - * and/or modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation, either - * version 3 of the License, or (at your option) any later version. - * - * NotEnoughUpdates is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with NotEnoughUpdates. If not, see . - */ - -package io.github.moulberry.notenoughupdates.commands.help; - -import com.google.common.collect.Lists; -import io.github.moulberry.notenoughupdates.NotEnoughUpdates; -import io.github.moulberry.notenoughupdates.commands.ClientCommandBase; -import io.github.moulberry.notenoughupdates.util.Utils; -import net.minecraft.command.ICommandSender; - -import java.util.ArrayList; - -public class HelpCommand extends ClientCommandBase { - - public HelpCommand() { - super("neuhelp"); - } - - @Override - public void processCommand(ICommandSender sender, String[] args) { - ArrayList neuHelpMessages = Lists.newArrayList( - "\u00a75\u00a7lNotEnoughUpdates commands", - "\u00a76/neu \u00a77- Opens the main NEU GUI.", - "\u00a76/pv \u00a7b?{name} \u00a72\u2D35 \u00a7r\u00a77- Opens the profile viewer", - "\u00a76/neusouls {on/off/clear/unclear} \u00a7r\u00a77- Shows waypoints to fairy souls.", - "\u00a76/neubuttons \u00a7r\u00a77- Opens a GUI which allows you to customize inventory buttons.", - "\u00a76/neuec \u00a7r\u00a77- Opens the enchant colour GUI.", - "\u00a76/join {floor} \u00a7r\u00a77- Short Command to join a Dungeon. \u00a7lNeed a Party of 5 People\u00a7r\u00a77 {4/f7/m5}.", - "\u00a76/neucosmetics \u00a7r\u00a77- Opens the cosmetic GUI.", - "\u00a76/neurename \u00a7r\u00a77- Opens the NEU Item Customizer.", - "\u00a76/cata \u00a7b?{name} \u00a72\u2D35 \u00a7r\u00a77- Opens the profile viewer's Catacombs page.", - "\u00a76/neulinks \u00a7r\u00a77- Shows links to NEU/Moulberry.", - "\u00a76/neuoverlay \u00a7r\u00a77- Opens GUI Editor for quickcommands and searchbar.", - "\u00a76/neuah \u00a7r\u00a77- Opens NEU's custom auction house GUI.", - "\u00a76/neucalendar \u00a7r\u00a77- Opens NEU's custom calendar GUI.", - "\u00a76/neucalc \u00a7r\u00a77- Run calculations.", - "", - "\u00a76\u00a7lOld commands:", - "\u00a76/peek \u00a7b?{user} \u00a72\u2D35 \u00a7r\u00a77- Shows quick stats for a user.", - "", - "\u00a76\u00a7lDebug commands:", - "\u00a76/neustats \u00a7r\u00a77- Copies helpful info to the clipboard.", - "\u00a76/neustats modlist \u00a7r\u00a77- Copies mod list info to clipboard.", - "\u00a76/neuresetrepo \u00a7r\u00a77- Deletes all repo files.", - "\u00a76/neureloadrepo \u00a7r\u00a77- Debug command with repo.", - "", - "\u00a76\u00a7lDev commands:", - "\u00a76/neupackdev \u00a7r\u00a77- pack creator command - getnpc, getmob(s), getarmorstand(s), getall. Optional radius argument for all." - ); - for (String neuHelpMessage : neuHelpMessages) { - Utils.addChatMessage(neuHelpMessage); - } - if (NotEnoughUpdates.INSTANCE.config.hidden.dev) { - ArrayList neuDevHelpMessages = Lists.newArrayList( - "\u00a76/neudevtest \u00a7r\u00a77- dev test command", - "\u00a76/neuzeephere \u00a7r\u00a77- sphere", - "\u00a76/neudungeonwintest \u00a7r\u00a77- displays the dungeon win screen" - ); - - for (String neuDevHelpMessage : neuDevHelpMessages) { - Utils.addChatMessage(neuDevHelpMessage); - } - } - String[] helpInfo = { - "", - "\u00a77Commands marked with a \u00a72\"\u2D35\"\u00a77 require an api key. You can set your api key via \"/api new\" or by manually putting it in the api field in \"/neu\"", - "", - "\u00a77Arguments marked with a \u00a7b\"?\"\u00a77 are optional.", - "", - "\u00a76\u00a7lScroll up to see everything" - }; - - for (String message : helpInfo) { - Utils.addChatMessage(message); - } - } -} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/help/LinksCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/help/LinksCommand.java deleted file mode 100644 index 793e652e..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/commands/help/LinksCommand.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (C) 2022 NotEnoughUpdates contributors - * - * This file is part of NotEnoughUpdates. - * - * NotEnoughUpdates is free software: you can redistribute it - * and/or modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation, either - * version 3 of the License, or (at your option) any later version. - * - * NotEnoughUpdates is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with NotEnoughUpdates. If not, see . - */ - -package io.github.moulberry.notenoughupdates.commands.help; - -import com.google.gson.JsonObject; -import io.github.moulberry.notenoughupdates.NotEnoughUpdates; -import io.github.moulberry.notenoughupdates.commands.ClientCommandBase; -import io.github.moulberry.notenoughupdates.util.Utils; -import net.minecraft.command.CommandException; -import net.minecraft.command.ICommandSender; - -import java.io.File; - -public class LinksCommand extends ClientCommandBase { - - public LinksCommand() { - super("neulinks"); - } - - @Override - public void processCommand(ICommandSender sender, String[] args) throws CommandException { - File repo = NotEnoughUpdates.INSTANCE.manager.repoLocation; - if (repo.exists()) { - File updateJson = new File(repo, "update.json"); - try { - JsonObject update = NotEnoughUpdates.INSTANCE.manager.getJsonFromFile(updateJson); - - Utils.addChatMessage(""); - NotEnoughUpdates.INSTANCE.displayLinks(update,0 ); - Utils.addChatMessage(""); - } catch (Exception ignored) { - } - } - } -} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/help/SettingsCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/help/SettingsCommand.java deleted file mode 100644 index 1855a2b5..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/commands/help/SettingsCommand.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (C) 2022 NotEnoughUpdates contributors - * - * This file is part of NotEnoughUpdates. - * - * NotEnoughUpdates is free software: you can redistribute it - * and/or modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation, either - * version 3 of the License, or (at your option) any later version. - * - * NotEnoughUpdates is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with NotEnoughUpdates. If not, see . - */ - -package io.github.moulberry.notenoughupdates.commands.help; - -import io.github.moulberry.notenoughupdates.NotEnoughUpdates; -import io.github.moulberry.notenoughupdates.commands.ClientCommandBase; -import io.github.moulberry.notenoughupdates.core.GuiScreenElementWrapper; -import io.github.moulberry.notenoughupdates.options.NEUConfigEditor; -import net.minecraft.command.CommandException; -import net.minecraft.command.ICommandSender; -import org.apache.commons.lang3.StringUtils; - -import java.util.Arrays; -import java.util.List; - -public class SettingsCommand extends ClientCommandBase { - - public SettingsCommand() { - super("neu"); - } - - @Override - public List getCommandAliases() { - return Arrays.asList("neusettings", "neuconfig"); - } - - @Override - public void processCommand(ICommandSender sender, String[] args) throws CommandException { - if (args.length > 0) { - NotEnoughUpdates.INSTANCE.openGui = - new GuiScreenElementWrapper(new NEUConfigEditor(NotEnoughUpdates.INSTANCE.config, StringUtils.join(args, " "))); - } else { - NotEnoughUpdates.INSTANCE.openGui = new GuiScreenElementWrapper(new NEUConfigEditor(NotEnoughUpdates.INSTANCE.config)); - } - } -} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/help/StorageViewerWhyCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/help/StorageViewerWhyCommand.java deleted file mode 100644 index 820c6f2a..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/commands/help/StorageViewerWhyCommand.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (C) 2022 NotEnoughUpdates contributors - * - * This file is part of NotEnoughUpdates. - * - * NotEnoughUpdates is free software: you can redistribute it - * and/or modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation, either - * version 3 of the License, or (at your option) any later version. - * - * NotEnoughUpdates is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with NotEnoughUpdates. If not, see . - */ - -package io.github.moulberry.notenoughupdates.commands.help; - -import com.google.common.collect.Lists; -import io.github.moulberry.notenoughupdates.commands.ClientCommandBase; -import io.github.moulberry.notenoughupdates.util.NotificationHandler; -import net.minecraft.command.ICommandSender; - -public class StorageViewerWhyCommand extends ClientCommandBase { - - public StorageViewerWhyCommand() { - super("neustwhy"); - } - - @Override - public void processCommand(ICommandSender sender, String[] args) { - NotificationHandler.displayNotification(Lists.newArrayList( - "\u00a7eStorage Viewer", - "\u00a77Currently, the storage viewer requires you to click twice", - "\u00a77in order to switch between pages. This is because Hypixel", - "\u00a77has not yet added a shortcut command to go to any enderchest/", - "\u00a77storage page.", - "\u00a77While it is possible to send the second click", - "\u00a77automatically, doing so violates Hypixel's new mod rules." - ), true); - } -} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/misc/AhCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/misc/AhCommand.java deleted file mode 100644 index 1ca398ef..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/commands/misc/AhCommand.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (C) 2022 NotEnoughUpdates contributors - * - * This file is part of NotEnoughUpdates. - * - * NotEnoughUpdates is free software: you can redistribute it - * and/or modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation, either - * version 3 of the License, or (at your option) any later version. - * - * NotEnoughUpdates is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with NotEnoughUpdates. If not, see . - */ - -package io.github.moulberry.notenoughupdates.commands.misc; - -import io.github.moulberry.notenoughupdates.NotEnoughUpdates; -import io.github.moulberry.notenoughupdates.auction.CustomAHGui; -import io.github.moulberry.notenoughupdates.commands.ClientCommandBase; -import io.github.moulberry.notenoughupdates.util.Utils; -import net.minecraft.command.CommandException; -import net.minecraft.command.ICommandSender; -import net.minecraft.util.EnumChatFormatting; -import org.apache.commons.lang3.StringUtils; - -public class AhCommand extends ClientCommandBase { - - public AhCommand() { - super("neuah"); - } - - @Override - public void processCommand(ICommandSender sender, String[] args) throws CommandException { - if (!NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard()) { - Utils.addChatMessage(EnumChatFormatting.RED + "You must be on SkyBlock to use this feature."); - } else if (NotEnoughUpdates.INSTANCE.config.apiData.apiKey == null || - NotEnoughUpdates.INSTANCE.config.apiData.apiKey.trim().isEmpty()) { - Utils.addChatMessage( - EnumChatFormatting.RED + "Can't open NEU AH: an api key is not set. Run /api new and put the result in settings."); - } else { - NotEnoughUpdates.INSTANCE.openGui = new CustomAHGui(); - NotEnoughUpdates.INSTANCE.manager.auctionManager.customAH.lastOpen = System.currentTimeMillis(); - NotEnoughUpdates.INSTANCE.manager.auctionManager.customAH.clearSearch(); - NotEnoughUpdates.INSTANCE.manager.auctionManager.customAH.updateSearch(); - - if (args.length > 0) { - NotEnoughUpdates.INSTANCE.manager.auctionManager.customAH.setSearch(StringUtils.join(args, " ")); - } else { - if (NotEnoughUpdates.INSTANCE.config.neuAuctionHouse.saveLastSearch) { - NotEnoughUpdates.INSTANCE.manager.auctionManager.customAH.setSearch(null); - } - } - } - } -} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/misc/CalculatorCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/misc/CalculatorCommand.java deleted file mode 100644 index b01f106b..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/commands/misc/CalculatorCommand.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (C) 2022 NotEnoughUpdates contributors - * - * This file is part of NotEnoughUpdates. - * - * NotEnoughUpdates is free software: you can redistribute it - * and/or modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation, either - * version 3 of the License, or (at your option) any later version. - * - * NotEnoughUpdates is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with NotEnoughUpdates. If not, see . - */ - -package io.github.moulberry.notenoughupdates.commands.misc; - -import io.github.moulberry.notenoughupdates.commands.ClientCommandBase; -import io.github.moulberry.notenoughupdates.util.Calculator; -import net.minecraft.command.CommandException; -import net.minecraft.command.ICommandSender; -import net.minecraft.util.ChatComponentText; -import net.minecraft.util.EnumChatFormatting; - -import java.math.BigDecimal; -import java.text.DecimalFormat; -import java.util.Arrays; -import java.util.List; -import java.util.Objects; - -public class CalculatorCommand extends ClientCommandBase { - public CalculatorCommand() { - super("neucalc"); - } - - @Override - public List getCommandAliases() { - return Arrays.asList("neucalculator"); - } - - @Override - public void processCommand(ICommandSender sender, String[] args) throws CommandException { - if ((args.length == 1 && Objects.equals(args[0], "help")) || args.length == 0) { - sender.addChatMessage(new ChatComponentText( - "\n§e[NEU] §5It's a calculator.\n" + - "§eFor Example §b/neucalc 3m*7k§e.\n" + - "§eYou can also use suffixes (k, m, b, t, s)§e.\n" + - "§eThe \"s\" suffix acts as 64.\n" + - "§eTurn on Sign Calculator in /neu misc to also support this in sign popups and the neu search bar.\n")); - return; - } - String source = String.join(" ", args); - try { - BigDecimal calculate = Calculator.calculate(source); - DecimalFormat formatter = new DecimalFormat("#,##0.##"); - String format = formatter.format(calculate); - sender.addChatMessage(new ChatComponentText( - EnumChatFormatting.YELLOW + "[NEU] " + EnumChatFormatting.WHITE + source + " " + EnumChatFormatting.YELLOW + - "= " + EnumChatFormatting.GREEN + format - )); - } catch (Calculator.CalculatorException e) { - sender.addChatMessage(new ChatComponentText( - EnumChatFormatting.YELLOW + "[NEU] " + EnumChatFormatting.RED + "Error during calculation: " + - e.getMessage() + "\n" + - EnumChatFormatting.WHITE + source.substring(0, e.getOffset()) + EnumChatFormatting.DARK_RED + - source.substring(e.getOffset(), e.getLength() + e.getOffset()) + EnumChatFormatting.GRAY + - source.substring(e.getLength() + e.getOffset()) - )); - } - } -} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/misc/CalendarCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/misc/CalendarCommand.java deleted file mode 100644 index 58c13474..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/commands/misc/CalendarCommand.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (C) 2022 NotEnoughUpdates contributors - * - * This file is part of NotEnoughUpdates. - * - * NotEnoughUpdates is free software: you can redistribute it - * and/or modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation, either - * version 3 of the License, or (at your option) any later version. - * - * NotEnoughUpdates is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with NotEnoughUpdates. If not, see . - */ - -package io.github.moulberry.notenoughupdates.commands.misc; - -import io.github.moulberry.notenoughupdates.NotEnoughUpdates; -import io.github.moulberry.notenoughupdates.commands.ClientCommandBase; -import io.github.moulberry.notenoughupdates.miscgui.CalendarOverlay; -import net.minecraft.client.Minecraft; -import net.minecraft.command.CommandException; -import net.minecraft.command.ICommandSender; - -public class CalendarCommand extends ClientCommandBase { - - public CalendarCommand() { - super("neucalendar"); - } - - @Override - public void processCommand(ICommandSender sender, String[] args) throws CommandException { - Minecraft.getMinecraft().thePlayer.closeScreen(); - CalendarOverlay.setEnabled(true); - NotEnoughUpdates.INSTANCE.sendChatMessage("/calendar"); - } -} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/misc/CosmeticsCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/misc/CosmeticsCommand.java deleted file mode 100644 index bbab316e..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/commands/misc/CosmeticsCommand.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (C) 2022 NotEnoughUpdates contributors - * - * This file is part of NotEnoughUpdates. - * - * NotEnoughUpdates is free software: you can redistribute it - * and/or modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation, either - * version 3 of the License, or (at your option) any later version. - * - * NotEnoughUpdates is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with NotEnoughUpdates. If not, see . - */ - -package io.github.moulberry.notenoughupdates.commands.misc; - -import io.github.moulberry.notenoughupdates.NotEnoughUpdates; -import io.github.moulberry.notenoughupdates.commands.ClientCommandBase; -import io.github.moulberry.notenoughupdates.cosmetics.GuiCosmetics; -import io.github.moulberry.notenoughupdates.util.Utils; -import net.minecraft.client.renderer.OpenGlHelper; -import net.minecraft.command.CommandException; -import net.minecraft.command.ICommandSender; -import net.minecraft.util.EnumChatFormatting; - -public class CosmeticsCommand extends ClientCommandBase { - - public CosmeticsCommand() { - super("neucosmetics"); - } - - @Override - public void processCommand(ICommandSender sender, String[] args) throws CommandException { - if (!OpenGlHelper.isFramebufferEnabled() && NotEnoughUpdates.INSTANCE.config.notifications.doFastRenderNotif) { - Utils.addChatMessage(EnumChatFormatting.RED + - "NEU Cosmetics do not work with OptiFine Fast Render. Go to ESC > Options > Video Settings > Performance > Fast Render to disable it."); - - } - - NotEnoughUpdates.INSTANCE.openGui = new GuiCosmetics(); - } -} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/misc/CustomizeCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/misc/CustomizeCommand.java deleted file mode 100644 index 28c2893d..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/commands/misc/CustomizeCommand.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (C) 2022 NotEnoughUpdates contributors - * - * This file is part of NotEnoughUpdates. - * - * NotEnoughUpdates is free software: you can redistribute it - * and/or modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation, either - * version 3 of the License, or (at your option) any later version. - * - * NotEnoughUpdates is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with NotEnoughUpdates. If not, see . - */ - -package io.github.moulberry.notenoughupdates.commands.misc; - -import io.github.moulberry.notenoughupdates.NotEnoughUpdates; -import io.github.moulberry.notenoughupdates.commands.ClientCommandBase; -import io.github.moulberry.notenoughupdates.miscgui.GuiItemCustomize; -import net.minecraft.client.Minecraft; -import net.minecraft.command.CommandException; -import net.minecraft.command.ICommandSender; -import net.minecraft.item.ItemStack; -import net.minecraft.util.ChatComponentText; - -import java.util.Collections; -import java.util.List; - -public class CustomizeCommand extends ClientCommandBase { - - public CustomizeCommand() { - super("neucustomize"); - } - - @Override - public List getCommandAliases() { - return Collections.singletonList("neurename"); - } - - @Override - public void processCommand(ICommandSender sender, String[] args) throws CommandException { - ItemStack held = Minecraft.getMinecraft().thePlayer.getHeldItem(); - - if (held == null) { - sender.addChatMessage(new ChatComponentText("\u00a7cYou can't customize your hand...")); - return; - } - - String heldUUID = NotEnoughUpdates.INSTANCE.manager.getUUIDForItem(held); - - if (heldUUID == null) { - sender.addChatMessage(new ChatComponentText("\u00a7cHeld item does not have a UUID, so it cannot be customized")); - return; - } - - NotEnoughUpdates.INSTANCE.openGui = new GuiItemCustomize(held, heldUUID); - } -} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/misc/PronounsCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/misc/PronounsCommand.java deleted file mode 100644 index cf0d0c56..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/commands/misc/PronounsCommand.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (C) 2022 NotEnoughUpdates contributors - * - * This file is part of NotEnoughUpdates. - * - * NotEnoughUpdates is free software: you can redistribute it - * and/or modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation, either - * version 3 of the License, or (at your option) any later version. - * - * NotEnoughUpdates is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with NotEnoughUpdates. If not, see . - */ - -package io.github.moulberry.notenoughupdates.commands.misc; - -import io.github.moulberry.notenoughupdates.NotEnoughUpdates; -import io.github.moulberry.notenoughupdates.commands.ClientCommandBase; -import io.github.moulberry.notenoughupdates.util.MinecraftExecutor; -import io.github.moulberry.notenoughupdates.util.PronounDB; -import io.github.moulberry.notenoughupdates.util.Utils; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.GuiNewChat; -import net.minecraft.command.CommandException; -import net.minecraft.command.ICommandSender; -import net.minecraft.util.ChatComponentText; - -import java.util.Optional; -import java.util.Random; -import java.util.UUID; -import java.util.concurrent.CompletableFuture; - -public class PronounsCommand extends ClientCommandBase { - public PronounsCommand() { - super("neupronouns"); - } - - @Override - public String getCommandUsage(ICommandSender sender) { - return "/neupronouns [platform]"; - } - - @Override - public void processCommand(ICommandSender sender, String[] args) throws CommandException { - switch (args.length) { - case 1: - fetchPronouns("minecraft", args[0]); - break; - case 2: - fetchPronouns(args[1], args[0]); - break; - default: - sender.addChatMessage(new ChatComponentText("§4" + getCommandUsage(sender))); - } - } - - private void fetchPronouns(String platform, String user) { - GuiNewChat nc = Minecraft.getMinecraft().ingameGUI.getChatGUI(); - int id = new Random().nextInt(); - nc.printChatMessageWithOptionalDeletion(new ChatComponentText("§e[NEU] Fetching Pronouns..."), id); - - CompletableFuture> pronouns; - if ("minecraft".equals(platform)) { - CompletableFuture c = new CompletableFuture<>(); - NotEnoughUpdates.profileViewer.getPlayerUUID(user, uuidString -> { - if (uuidString == null) { - c.completeExceptionally(new NullPointerException()); - } else { - c.complete(Utils.parseDashlessUUID(uuidString)); - } - }); - pronouns = c.thenCompose(PronounDB::getPronounsFor); - } else { - pronouns = PronounDB.getPronounsFor(platform, user); - } - pronouns.handleAsync((pronounChoice, throwable) -> { - if (throwable != null || !pronounChoice.isPresent()) { - nc.printChatMessageWithOptionalDeletion(new ChatComponentText("§e[NEU] §4Failed to fetch pronouns."), id); - return null; - } - PronounDB.PronounChoice betterPronounChoice = pronounChoice.get(); - nc.printChatMessageWithOptionalDeletion(new ChatComponentText( - "§e[NEU] Pronouns for §b" + user + " §eon §b" + platform + "§e:"), id); - betterPronounChoice.render().forEach(it -> nc.printChatMessage(new ChatComponentText("§e[NEU] §a" + it))); - return null; - }, MinecraftExecutor.OnThread); - - } -} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/misc/UpdateCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/misc/UpdateCommand.java deleted file mode 100644 index 1aeebda5..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/commands/misc/UpdateCommand.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (C) 2022 NotEnoughUpdates contributors - * - * This file is part of NotEnoughUpdates. - * - * NotEnoughUpdates is free software: you can redistribute it - * and/or modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation, either - * version 3 of the License, or (at your option) any later version. - * - * NotEnoughUpdates is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with NotEnoughUpdates. If not, see . - */ - -package io.github.moulberry.notenoughupdates.commands.misc; - -import io.github.moulberry.notenoughupdates.NotEnoughUpdates; -import io.github.moulberry.notenoughupdates.commands.ClientCommandBase; -import net.minecraft.command.CommandException; -import net.minecraft.command.ICommandSender; -import net.minecraft.util.ChatComponentText; - -import java.util.Arrays; -import java.util.List; -import java.util.Objects; - -public class UpdateCommand extends ClientCommandBase { - NotEnoughUpdates neu; - - public UpdateCommand(NotEnoughUpdates neu) { - super("neuupdate"); - this.neu = neu; - } - - @Override - public List getCommandAliases() { - return Arrays.asList("neuupdates", "enoughupdates"); - } - - public void displayHelp(ICommandSender sender) { - sender.addChatMessage(new ChatComponentText( - "" + - "§e[NEU] §b/neuupdate help - View help.\n" + - "§e[NEU] §b/neuupdate check - Check for updates.\n" + - "" - )); - - } - - @Override - public void processCommand(ICommandSender sender, String[] args) throws CommandException { - if ((args.length == 1 && Objects.equals(args[0], "help")) || args.length == 0) { - displayHelp(sender); - return; - } - switch (args[0].toLowerCase().intern()) { - case "check": - neu.autoUpdater.displayUpdateMessageIfOutOfDate(); - break; - case "scheduledownload": - neu.autoUpdater.scheduleDownload(); - break; - case "updatemodes": - sender.addChatMessage(new ChatComponentText("§e[NEU] §bTo ensure we do not accidentally corrupt your mod folder, we can only offer support for auto-updates on system with certain capabilities for file deletions (specifically unix systems). You can still manually update your files")); - break; - default: - displayHelp(sender); - - } - } -} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/profile/CataCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/profile/CataCommand.java deleted file mode 100644 index afc47418..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/commands/profile/CataCommand.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (C) 2022 NotEnoughUpdates contributors - * - * This file is part of NotEnoughUpdates. - * - * NotEnoughUpdates is free software: you can redistribute it - * and/or modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation, either - * version 3 of the License, or (at your option) any later version. - * - * NotEnoughUpdates is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with NotEnoughUpdates. If not, see . - */ - -package io.github.moulberry.notenoughupdates.commands.profile; - -import io.github.moulberry.notenoughupdates.profileviewer.GuiProfileViewer; -import net.minecraft.command.ICommandSender; - -public class CataCommand extends ViewProfileCommand { - - public CataCommand() { - super("cata"); - } - - @Override - public void processCommand(ICommandSender sender, String[] args) { - GuiProfileViewer.currentPage = GuiProfileViewer.ProfileViewerPage.DUNGEON; - super.processCommand(sender, args); - } -} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/profile/PeekCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/profile/PeekCommand.java deleted file mode 100644 index 23852ab6..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/commands/profile/PeekCommand.java +++ /dev/null @@ -1,343 +0,0 @@ -/* - * Copyright (C) 2022 NotEnoughUpdates contributors - * - * This file is part of NotEnoughUpdates. - * - * NotEnoughUpdates is free software: you can redistribute it - * and/or modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation, either - * version 3 of the License, or (at your option) any later version. - * - * NotEnoughUpdates is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with NotEnoughUpdates. If not, see . - */ - -package io.github.moulberry.notenoughupdates.commands.profile; - -import com.google.gson.JsonObject; -import io.github.moulberry.notenoughupdates.NotEnoughUpdates; -import io.github.moulberry.notenoughupdates.commands.ClientCommandBase; -import io.github.moulberry.notenoughupdates.profileviewer.PlayerStats; -import io.github.moulberry.notenoughupdates.profileviewer.ProfileViewer; -import io.github.moulberry.notenoughupdates.util.Utils; -import net.minecraft.client.Minecraft; -import net.minecraft.command.CommandException; -import net.minecraft.command.ICommandSender; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.util.BlockPos; -import net.minecraft.util.ChatComponentText; -import net.minecraft.util.EnumChatFormatting; -import org.apache.commons.lang3.text.WordUtils; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Map; -import java.util.Random; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.ScheduledFuture; -import java.util.concurrent.TimeUnit; - -public class PeekCommand extends ClientCommandBase { - - private ScheduledExecutorService peekCommandExecutorService = null; - private ScheduledFuture peekScheduledFuture = null; - - public PeekCommand() { - super("peek"); - } - - @Override - public void processCommand(ICommandSender sender, String[] args) throws CommandException { - String name; - if (args.length == 0) { - name = Minecraft.getMinecraft().thePlayer.getName(); - } else { - name = args[0]; - } - int id = new Random().nextInt(Integer.MAX_VALUE / 2) + Integer.MAX_VALUE / 2; - - Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessageWithOptionalDeletion(new ChatComponentText( - EnumChatFormatting.YELLOW + "[PEEK] Getting player information..."), id); - NotEnoughUpdates.profileViewer.getProfileByName(name, profile -> { - if (profile == null) { - Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessageWithOptionalDeletion(new ChatComponentText( - EnumChatFormatting.RED + "[PEEK] Unknown player or the Hypixel API is down."), id); - } else { - profile.resetCache(); - - if (peekCommandExecutorService == null || peekCommandExecutorService.isTerminated()) { - peekCommandExecutorService = Executors.newSingleThreadScheduledExecutor(); - } - - if (peekScheduledFuture != null && !peekScheduledFuture.isDone()) { - Utils.addChatMessage( - EnumChatFormatting.RED + "[PEEK] New peek command was run, cancelling old one."); - peekScheduledFuture.cancel(true); - } - - Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessageWithOptionalDeletion(new ChatComponentText( - EnumChatFormatting.YELLOW + "[PEEK] Getting the player's SkyBlock profile(s)..."), id); - - long startTime = System.currentTimeMillis(); - peekScheduledFuture = peekCommandExecutorService.schedule(new Runnable() { - public void run() { - if (System.currentTimeMillis() - startTime > 10 * 1000) { - Minecraft.getMinecraft().ingameGUI - .getChatGUI() - .printChatMessageWithOptionalDeletion(new ChatComponentText( - EnumChatFormatting.RED + "[PEEK] Getting profile info took too long, aborting."), id); - return; - } - - String g = EnumChatFormatting.GRAY.toString(); - - JsonObject profileInfo = profile.getProfileInformation(null); - if (profileInfo != null) { - float overallScore = 0; - - boolean isMe = name.equalsIgnoreCase("moulberry"); - - PlayerStats.Stats stats = profile.getStats(null); - if (stats == null) { - peekScheduledFuture = peekCommandExecutorService.schedule(this, 200, TimeUnit.MILLISECONDS); - return; - } - Map skyblockInfo = profile.getSkyblockInfo(null); - - if (NotEnoughUpdates.INSTANCE.config.profileViewer.useSoopyNetworth) { - Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessageWithOptionalDeletion(new ChatComponentText( - EnumChatFormatting.YELLOW + "[PEEK] Getting the player's Skyblock networth..."), id); - - CountDownLatch countDownLatch = new CountDownLatch(1); - - profile.getSoopyNetworth(null, () -> countDownLatch.countDown()); - - try { //Wait for async network request - countDownLatch.await(10, TimeUnit.SECONDS); - } catch (InterruptedException e) {} - - //Now it's waited for network request the data should be cached (accessed in nw section) - } - - Minecraft.getMinecraft().ingameGUI - .getChatGUI() - .printChatMessageWithOptionalDeletion(new ChatComponentText(EnumChatFormatting.GREEN + " " + - EnumChatFormatting.STRIKETHROUGH + "-=-" + EnumChatFormatting.RESET + EnumChatFormatting.GREEN + - " " + - Utils.getElementAsString(profile.getHypixelProfile().get("displayname"), name) + "'s Info " + - EnumChatFormatting.STRIKETHROUGH + "-=-"), id); - - if (skyblockInfo == null) { - Utils.addChatMessage(EnumChatFormatting.YELLOW + "Skills API disabled!"); - } else { - float totalSkillLVL = 0; - float totalSkillCount = 0; - - List skills = Arrays.asList("taming", "mining", "foraging", "enchanting", "farming", "combat", "fishing", "alchemy", "carpentry"); - for (String skillName : skills) { - totalSkillLVL += skyblockInfo.get(skillName).level; - totalSkillCount++; - } - - float combat = skyblockInfo.get("combat").level; - float zombie = skyblockInfo.get("zombie").level; - float spider = skyblockInfo.get("spider").level; - float wolf = skyblockInfo.get("wolf").level; - float enderman = skyblockInfo.get("enderman").level; - float blaze = skyblockInfo.get("blaze").level; - - float avgSkillLVL = totalSkillLVL / totalSkillCount; - - if (isMe) { - avgSkillLVL = 6; - combat = 4; - zombie = 2; - spider = 1; - wolf = 2; - enderman = 0; - blaze = 0; - } - - EnumChatFormatting combatPrefix = combat > 20 - ? (combat > 35 ? EnumChatFormatting.GREEN : EnumChatFormatting.YELLOW) - : EnumChatFormatting.RED; - EnumChatFormatting zombiePrefix = zombie > 3 - ? (zombie > 6 ? EnumChatFormatting.GREEN : EnumChatFormatting.YELLOW) - : EnumChatFormatting.RED; - EnumChatFormatting spiderPrefix = spider > 3 - ? (spider > 6 ? EnumChatFormatting.GREEN : EnumChatFormatting.YELLOW) - : EnumChatFormatting.RED; - EnumChatFormatting wolfPrefix = - wolf > 3 ? (wolf > 6 ? EnumChatFormatting.GREEN : EnumChatFormatting.YELLOW) : EnumChatFormatting.RED; - EnumChatFormatting endermanPrefix = enderman > 3 - ? (enderman > 6 - ? EnumChatFormatting.GREEN - : EnumChatFormatting.YELLOW) - : EnumChatFormatting.RED; - EnumChatFormatting blazePrefix = blaze > 3 - ? (blaze > 6 - ? EnumChatFormatting.GREEN - : EnumChatFormatting.YELLOW) - : EnumChatFormatting.RED; - EnumChatFormatting avgPrefix = avgSkillLVL > 20 - ? (avgSkillLVL > 35 - ? EnumChatFormatting.GREEN - : EnumChatFormatting.YELLOW) - : EnumChatFormatting.RED; - - overallScore += zombie * zombie / 81f; - overallScore += spider * spider / 81f; - overallScore += wolf * wolf / 81f; - overallScore += enderman * enderman / 81f; - overallScore += blaze * blaze / 81f; - overallScore += avgSkillLVL / 20f; - - int cata = (int) skyblockInfo.get("catacombs").level; - EnumChatFormatting cataPrefix = cata > 15 - ? (cata > 25 ? EnumChatFormatting.GREEN : EnumChatFormatting.YELLOW) - : EnumChatFormatting.RED; - - overallScore += cata * cata / 2000f; - - Utils.addChatMessage(g + "Combat: " + combatPrefix + (int) Math.floor(combat) + - (cata > 0 ? g + " - Cata: " + cataPrefix + cata : "") + - g + " - AVG: " + avgPrefix + (int) Math.floor(avgSkillLVL)); - Utils.addChatMessage(g + "Slayer: " + zombiePrefix + (int) Math.floor(zombie) + g + "-" + - spiderPrefix + (int) Math.floor(spider) + g + "-" + - wolfPrefix + (int) Math.floor(wolf) + g + "-" + - endermanPrefix + (int) Math.floor(enderman) + g + "-" + - blazePrefix + (int) Math.floor(blaze)); - } - if (stats == null) { - Utils.addChatMessage(EnumChatFormatting.YELLOW + "Skills, collection and/or inventory apis disabled!"); - } else { - int health = (int) stats.get("health"); - int defence = (int) stats.get("defence"); - int strength = (int) stats.get("strength"); - int intelligence = (int) stats.get("intelligence"); - - EnumChatFormatting healthPrefix = health > 800 - ? (health > 1600 - ? EnumChatFormatting.GREEN - : EnumChatFormatting.YELLOW) - : EnumChatFormatting.RED; - EnumChatFormatting defencePrefix = defence > 200 - ? (defence > 600 - ? EnumChatFormatting.GREEN - : EnumChatFormatting.YELLOW) - : EnumChatFormatting.RED; - EnumChatFormatting strengthPrefix = strength > 100 - ? (strength > 300 - ? EnumChatFormatting.GREEN - : EnumChatFormatting.YELLOW) - : EnumChatFormatting.RED; - EnumChatFormatting intelligencePrefix = intelligence > 300 - ? (intelligence > 900 - ? EnumChatFormatting.GREEN - : EnumChatFormatting.YELLOW) - : EnumChatFormatting.RED; - - Utils.addChatMessage( g + "Stats : " + healthPrefix + health + EnumChatFormatting.RED + "\u2764 " + - defencePrefix + defence + EnumChatFormatting.GREEN + "\u2748 " + - strengthPrefix + strength + EnumChatFormatting.RED + "\u2741 " + - intelligencePrefix + intelligence + EnumChatFormatting.AQUA + "\u270e "); - } - float bankBalance = Utils.getElementAsFloat(Utils.getElement(profileInfo, "banking.balance"), -1); - float purseBalance = Utils.getElementAsFloat(Utils.getElement(profileInfo, "coin_purse"), 0); - - long networth; - if (NotEnoughUpdates.INSTANCE.config.profileViewer.useSoopyNetworth) { - ProfileViewer.Profile.SoopyNetworthData nwData = profile.getSoopyNetworth(null, () -> {}); - if (nwData == null) { - networth = -2l; - } else { - networth = nwData.getTotal(); - } - } else { - networth = profile.getNetWorth(null); - } - - float money = Math.max(bankBalance + purseBalance, networth); - EnumChatFormatting moneyPrefix = money > 50 * 1000 * 1000 ? - (money > 200 * 1000 * 1000 - ? EnumChatFormatting.GREEN - : EnumChatFormatting.YELLOW) : EnumChatFormatting.RED; - Utils.addChatMessage( g + "Purse: " + moneyPrefix + Utils.shortNumberFormat(purseBalance, 0) + g + " - Bank: " + - (bankBalance == -1 ? EnumChatFormatting.YELLOW + "N/A" : moneyPrefix + - (isMe ? "4.8b" : Utils.shortNumberFormat(bankBalance, 0))) + - (networth > 0 ? g + " - Net: " + moneyPrefix + Utils.shortNumberFormat(networth, 0) : "")); - - overallScore += Math.min(2, money / (100f * 1000 * 1000)); - - String activePet = Utils.getElementAsString( - Utils.getElement(profile.getPetsInfo(null), "active_pet.type"), - "None Active" - ); - String activePetTier = Utils.getElementAsString(Utils.getElement( - profile.getPetsInfo(null), - "active_pet.tier" - ), "UNKNOWN"); - - String col = NotEnoughUpdates.petRarityToColourMap.get(activePetTier); - if (col == null) col = EnumChatFormatting.LIGHT_PURPLE.toString(); - - Utils.addChatMessage(g + "Pet : " + col + WordUtils.capitalizeFully(activePet.replace("_", " "))); - - String overall = "Skywars Main"; - if (isMe) { - overall = Utils.chromaString("Literally the best player to exist"); // ego much - } else if (overallScore < 5 && (bankBalance + purseBalance) > 500 * 1000 * 1000) { - overall = EnumChatFormatting.GOLD + "Bill Gates"; - } else if (overallScore > 9) { - overall = Utils.chromaString("Didn't even think this score was possible"); - } else if (overallScore > 8) { - overall = Utils.chromaString("Mentally unstable"); - } else if (overallScore > 7) { - overall = EnumChatFormatting.GOLD + "Why though 0.0"; - } else if (overallScore > 5.5) { - overall = EnumChatFormatting.GOLD + "Bro stop playing"; - } else if (overallScore > 4) { - overall = EnumChatFormatting.GREEN + "Kinda sweaty"; - } else if (overallScore > 3) { - overall = EnumChatFormatting.YELLOW + "Alright I guess"; - } else if (overallScore > 2) { - overall = EnumChatFormatting.YELLOW + "Ender Non"; - } else if (overallScore > 1) { - overall = EnumChatFormatting.RED + "Played SkyBlock"; - } - - Utils.addChatMessage(g + "Overall score: " + overall + g + " (" + Math.round(overallScore * 10) / 10f + ")"); - - peekCommandExecutorService.shutdownNow(); - } else { - peekScheduledFuture = peekCommandExecutorService.schedule(this, 200, TimeUnit.MILLISECONDS); - } - } - }, 200, TimeUnit.MILLISECONDS); - } - }); - } - - @Override - public List addTabCompletionOptions(ICommandSender sender, String[] args, BlockPos pos) { - if (args.length != 1) return null; - - String lastArg = args[args.length - 1]; - List playerMatches = new ArrayList<>(); - for (EntityPlayer player : Minecraft.getMinecraft().theWorld.playerEntities) { - String playerName = player.getName(); - if (playerName.toLowerCase().startsWith(lastArg.toLowerCase())) { - playerMatches.add(playerName); - } - } - return playerMatches; - } -} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/profile/PvCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/profile/PvCommand.java deleted file mode 100644 index 2d5c05f4..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/commands/profile/PvCommand.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (C) 2022 NotEnoughUpdates contributors - * - * This file is part of NotEnoughUpdates. - * - * NotEnoughUpdates is free software: you can redistribute it - * and/or modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation, either - * version 3 of the License, or (at your option) any later version. - * - * NotEnoughUpdates is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with NotEnoughUpdates. If not, see . - */ - -package io.github.moulberry.notenoughupdates.commands.profile; - -import io.github.moulberry.notenoughupdates.NotEnoughUpdates; -import net.minecraft.client.Minecraft; -import net.minecraft.command.ICommandSender; -import org.apache.commons.lang3.StringUtils; - -public class PvCommand extends ViewProfileCommand { - - public PvCommand() { - super("pv"); - } - - @Override - public void processCommand(ICommandSender sender, String[] args) { - if (!NotEnoughUpdates.INSTANCE.isOnSkyblock()) { - Minecraft.getMinecraft().thePlayer.sendChatMessage("/pv " + StringUtils.join(args, " ")); - } else { - super.processCommand(sender, args); - } - } -} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/profile/ViewProfileCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/profile/ViewProfileCommand.java deleted file mode 100644 index 26468e39..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/commands/profile/ViewProfileCommand.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright (C) 2022 NotEnoughUpdates contributors - * - * This file is part of NotEnoughUpdates. - * - * NotEnoughUpdates is free software: you can redistribute it - * and/or modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation, either - * version 3 of the License, or (at your option) any later version. - * - * NotEnoughUpdates is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with NotEnoughUpdates. If not, see . - */ - -package io.github.moulberry.notenoughupdates.commands.profile; - -import io.github.moulberry.notenoughupdates.NotEnoughUpdates; -import io.github.moulberry.notenoughupdates.commands.ClientCommandBase; -import io.github.moulberry.notenoughupdates.profileviewer.GuiProfileViewer; -import io.github.moulberry.notenoughupdates.util.Utils; -import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.OpenGlHelper; -import net.minecraft.command.ICommandSender; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.util.BlockPos; -import net.minecraft.util.ChatComponentText; -import net.minecraft.util.EnumChatFormatting; - -import java.util.ArrayList; -import java.util.List; -import java.util.function.Consumer; - -public class ViewProfileCommand extends ClientCommandBase { - - public static final Consumer RUNNABLE = (args) -> { - if (!OpenGlHelper.isFramebufferEnabled()) { - Utils.addChatMessage(EnumChatFormatting.RED + - "Some parts of the profile viewer do not work with OptiFine Fast Render. Go to ESC > Options > Video Settings > Performance > Fast Render to disable it."); - - } - if (NotEnoughUpdates.INSTANCE.config.apiData.apiKey == null || - NotEnoughUpdates.INSTANCE.config.apiData.apiKey.trim().isEmpty()) { - Utils.addChatMessage(EnumChatFormatting.RED + - "Can't view profile, an API key is not set. Run /api new and put the result in settings."); - } else if (args.length == 0) { - NotEnoughUpdates.profileViewer.getProfileByName(Minecraft.getMinecraft().thePlayer.getName(), profile -> { - if (profile == null) { - Utils.addChatMessage(EnumChatFormatting.RED + - "Invalid player name/API key. Maybe the API is down? Try /api new."); - } else { - profile.resetCache(); - NotEnoughUpdates.INSTANCE.openGui = new GuiProfileViewer(profile); - } - }); - } else if (args.length > 1) { - Utils.addChatMessage(EnumChatFormatting.RED + - "Too many arguments. Usage: /neuprofile [name]"); - } else { - NotEnoughUpdates.profileViewer.getProfileByName(args[0], profile -> { - if (profile == null) { - Utils.addChatMessage(EnumChatFormatting.RED + "Invalid player name/api key. Maybe the API is down? Try /api new."); - } else { - profile.resetCache(); - NotEnoughUpdates.INSTANCE.openGui = new GuiProfileViewer(profile); - } - }); - } - }; - - public ViewProfileCommand() { - this("neuprofile"); - } - - public ViewProfileCommand(String name) { - super(name); - } - - @Override - public void processCommand(ICommandSender sender, String[] args) { - RUNNABLE.accept(args); - } - - @Override - public List addTabCompletionOptions(ICommandSender sender, String[] args, BlockPos pos) { - if (args.length != 1) return null; - - String lastArg = args[args.length - 1]; - List playerMatches = new ArrayList<>(); - for (EntityPlayer player : Minecraft.getMinecraft().theWorld.playerEntities) { - String playerName = player.getName(); - if (playerName.toLowerCase().startsWith(lastArg.toLowerCase())) { - playerMatches.add(playerName); - } - } - return playerMatches; - } -} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java b/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java index 5ccd6767..65724c65 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java @@ -26,7 +26,6 @@ import io.github.moulberry.notenoughupdates.NEUApi; import io.github.moulberry.notenoughupdates.NEUOverlay; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.auction.CustomAHGui; -import io.github.moulberry.notenoughupdates.commands.profile.ViewProfileCommand; import io.github.moulberry.notenoughupdates.core.GuiScreenElementWrapper; import io.github.moulberry.notenoughupdates.dungeons.DungeonWin; import io.github.moulberry.notenoughupdates.miscfeatures.AbiphoneWarning; @@ -1062,7 +1061,14 @@ public class RenderListener { if (tag.hasKey("SkullOwner") && tag.getCompoundTag("SkullOwner").hasKey("Name")) { String username = tag.getCompoundTag("SkullOwner").getString("Name"); Utils.playPressSound(); - ViewProfileCommand.RUNNABLE.accept(new String[]{username}); + NotEnoughUpdates.profileViewer.getProfileByName(username, profile -> { + if (profile == null) { + Utils.addChatMessage("${RED}Invalid player name/API key. Maybe the API is down? Try /api new."); + } else { + profile.resetCache(); + NotEnoughUpdates.INSTANCE.openGui = new GuiProfileViewer(profile); + } + }); } } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/FairySouls.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/FairySouls.java index 5a611178..97aa25d4 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/FairySouls.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/FairySouls.java @@ -26,7 +26,6 @@ import com.google.gson.JsonObject; import com.google.gson.JsonSyntaxException; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.autosubscribe.NEUAutoSubscribe; -import io.github.moulberry.notenoughupdates.commands.ClientCommandBase; import io.github.moulberry.notenoughupdates.core.util.StringUtils; import io.github.moulberry.notenoughupdates.core.util.render.RenderUtils; import io.github.moulberry.notenoughupdates.util.Constants; @@ -34,8 +33,6 @@ import io.github.moulberry.notenoughupdates.util.SBInfo; import io.github.moulberry.notenoughupdates.util.Utils; import lombok.var; import net.minecraft.client.Minecraft; -import net.minecraft.command.CommandException; -import net.minecraft.command.ICommandSender; import net.minecraft.util.BlockPos; import net.minecraft.util.EnumChatFormatting; import net.minecraftforge.client.event.ClientChatReceivedEvent; @@ -56,7 +53,6 @@ import java.io.OutputStreamWriter; import java.lang.reflect.Type; import java.nio.charset.StandardCharsets; import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -87,6 +83,14 @@ public class FairySouls { return instance; } + public boolean isTrackSouls() { + return trackSouls; + } + + public boolean isShowSouls() { + return showSouls; + } + @SubscribeEvent public void onWorldLoad(WorldEvent.Load event) { currentLocation = null; @@ -379,25 +383,6 @@ public class FairySouls { Utils.addChatMessage(s); } - private static void printHelp() { - print(""); - print(EnumChatFormatting.DARK_PURPLE.toString() + EnumChatFormatting.BOLD + " NEU Fairy Soul Waypoint Guide"); - print(EnumChatFormatting.LIGHT_PURPLE + "Shows waypoints for every fairy soul in your world"); - print(EnumChatFormatting.LIGHT_PURPLE + "Clicking a fairy soul automatically removes it from the list"); - if (!NotEnoughUpdates.INSTANCE.config.hidden.dev) { - print(EnumChatFormatting.DARK_RED + "" + EnumChatFormatting.OBFUSCATED + "Ab" + EnumChatFormatting.RESET + - EnumChatFormatting.DARK_RED + "!" + EnumChatFormatting.RESET + EnumChatFormatting.RED + - " This feature cannot and will not work in Dungeons. " + EnumChatFormatting.DARK_RED + "!" + - EnumChatFormatting.OBFUSCATED + "Ab"); - } - print(EnumChatFormatting.GOLD.toString() + EnumChatFormatting.BOLD + " Commands:"); - print(EnumChatFormatting.YELLOW + "/neusouls help - Display this message"); - print(EnumChatFormatting.YELLOW + "/neusouls on/off - Enable/disable showing waypoint markers"); - print(EnumChatFormatting.YELLOW + - "/neusouls clear/unclear - Marks every waypoint in your current world as completed/uncompleted"); - print(""); - } - @SubscribeEvent(priority = EventPriority.HIGHEST, receiveCanceled = true) public void onChatReceived(ClientChatReceivedEvent event) { if (!trackSouls || event.type == 2) return; @@ -407,53 +392,4 @@ public class FairySouls { markClosestSoulFound(); } } - - public static class FairySoulsCommand extends ClientCommandBase { - public FairySoulsCommand() { - super("neusouls"); - } - - @Override - public List getCommandAliases() { - return Collections.singletonList("fairysouls"); - } - - @Override - public void processCommand(ICommandSender sender, String[] args) throws CommandException { - if (args.length != 1) { - printHelp(); - return; - } - - String subcommand = args[0].toLowerCase(); - switch (subcommand) { - case "help": - printHelp(); - break; - case "on": - case "enable": - if (!FairySouls.instance.trackSouls) { - print( - EnumChatFormatting.RED + "Fairy soul tracking is off, enable it using /neu before using this command"); - return; - } - print(EnumChatFormatting.DARK_PURPLE + "Enabled fairy soul waypoints"); - FairySouls.getInstance().setShowFairySouls(true); - break; - case "off": - case "disable": - FairySouls.getInstance().setShowFairySouls(false); - print(EnumChatFormatting.DARK_PURPLE + "Disabled fairy soul waypoints"); - break; - case "clear": - FairySouls.getInstance().markAllAsFound(); - break; - case "unclear": - FairySouls.getInstance().markAllAsMissing(); - break; - default: - print(EnumChatFormatting.RED + "Unknown subcommand: " + subcommand); - } - } - } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/mixins/AccessorCommandHandler.java b/src/main/java/io/github/moulberry/notenoughupdates/mixins/AccessorCommandHandler.java new file mode 100644 index 00000000..73d31196 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/mixins/AccessorCommandHandler.java @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2023 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see . + */ + +package io.github.moulberry.notenoughupdates.mixins; + +import net.minecraft.command.CommandHandler; +import net.minecraft.command.ICommand; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +import java.util.Set; + +@Mixin(CommandHandler.class) +public interface AccessorCommandHandler { + @Accessor("commandSet") + Set neuGetClientCommands(); +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/brigadier/NEUBrigadierHook.kt b/src/main/java/io/github/moulberry/notenoughupdates/util/brigadier/NEUBrigadierHook.kt new file mode 100644 index 00000000..668c412a --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/util/brigadier/NEUBrigadierHook.kt @@ -0,0 +1,109 @@ +/* + * Copyright (C) 2023 Linnea Gräf + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see . + */ + +package io.github.moulberry.notenoughupdates.util.brigadier + +import com.mojang.brigadier.ParseResults +import com.mojang.brigadier.exceptions.CommandSyntaxException +import com.mojang.brigadier.suggestion.Suggestions +import com.mojang.brigadier.tree.CommandNode +import net.minecraft.command.CommandBase +import net.minecraft.command.ICommandSender +import net.minecraft.util.BlockPos +import net.minecraft.util.ChatComponentText +import net.minecraft.util.EnumChatFormatting.RED +import net.minecraft.util.EnumChatFormatting.YELLOW +import java.util.concurrent.CompletableFuture +import java.util.function.Predicate + +/** + * Hook for converting brigadier commands to normal legacy Minecraft commands (string array style). + */ +class NEUBrigadierHook( + val brigadierRoot: BrigadierRoot, + val commandNode: CommandNode, + val aliases: List +) : CommandBase() { + /** + * Runs before the command gets executed. Return false to prevent execution. + */ + var beforeCommand: Predicate>? = null + + override fun getCommandName(): String { + return commandNode.name + } + + override fun getCommandAliases(): List { + return aliases + } + + data class Usage( + val path: String, + val help: String?, + ) + + + override fun getCommandUsage(sender: ICommandSender): String { + return brigadierRoot.getAllUsages("/$commandName", commandNode, mutableSetOf()).joinToString("\n") { "${it.path} - ${it.help ?: "Missing help"}"} + } + + private fun getText(args: Array) = "${commandNode.name} ${args.joinToString(" ")}" + + override fun processCommand(sender: ICommandSender, args: Array) { + val results = brigadierRoot.parseText.apply(sender to getText(args).trim()) + if (beforeCommand?.test(results) == false) + return + try { + brigadierRoot.dispatcher.execute(results) + } catch (syntax: CommandSyntaxException) { + brigadierRoot.getAllUsages("/$commandName", commandNode, mutableSetOf()).forEach { + sender.addChatMessage(ChatComponentText("${YELLOW}[NEU] ${it.path} - ${it.help}")) + } + } + } + + // We love async tab completion (may end up requiring pressing tab multiple times, but uhhhhh .get() bad) + private var lastCompletionText: String? = null + private var lastCompletion: CompletableFuture? = null + override fun addTabCompletionOptions( + sender: ICommandSender, + args: Array, + pos: BlockPos + ): List { + val originalText = getText(args) + var lc: CompletableFuture? = null + if (lastCompletionText == originalText) { + lc = lastCompletion + } + if (lc == null) { + lastCompletion?.cancel(true) + val results = brigadierRoot.parseText.apply(sender to originalText) + lc = brigadierRoot.dispatcher.getCompletionSuggestions(results) + } + lastCompletion = lc + lastCompletionText = originalText + val suggestions = lastCompletion?.getNow(null) ?: return emptyList() + return suggestions.list.map { it.text } + } + + override fun canCommandSenderUseCommand(sender: ICommandSender): Boolean { + return true // Permissions are checked by brigadier instead (or by the beforeCommand hook) + } + +} diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.kt new file mode 100644 index 00000000..805ff114 --- /dev/null +++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.kt @@ -0,0 +1,256 @@ +/* + * Copyright (C) 2023 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see . + */ + +package io.github.moulberry.notenoughupdates.commands.dev + +import com.mojang.brigadier.arguments.StringArgumentType +import io.github.moulberry.notenoughupdates.BuildFlags +import io.github.moulberry.notenoughupdates.NotEnoughUpdates +import io.github.moulberry.notenoughupdates.autosubscribe.NEUAutoSubscribe +import io.github.moulberry.notenoughupdates.core.config.GuiPositionEditor +import io.github.moulberry.notenoughupdates.core.util.MiscUtils +import io.github.moulberry.notenoughupdates.events.RegisterBrigadierCommandEvent +import io.github.moulberry.notenoughupdates.miscfeatures.FishingHelper +import io.github.moulberry.notenoughupdates.miscfeatures.customblockzones.CustomBiomes +import io.github.moulberry.notenoughupdates.miscfeatures.customblockzones.LocationChangeEvent +import io.github.moulberry.notenoughupdates.miscgui.GuiPriceGraph +import io.github.moulberry.notenoughupdates.miscgui.minionhelper.MinionHelperManager +import io.github.moulberry.notenoughupdates.util.PronounDB +import io.github.moulberry.notenoughupdates.util.SBInfo +import io.github.moulberry.notenoughupdates.util.TabListUtils +import io.github.moulberry.notenoughupdates.util.brigadier.* +import net.minecraft.client.Minecraft +import net.minecraft.client.gui.GuiScreen +import net.minecraft.command.ICommandSender +import net.minecraft.entity.player.EntityPlayer +import net.minecraft.launchwrapper.Launch +import net.minecraft.util.ChatComponentText +import net.minecraft.util.EnumChatFormatting.* +import net.minecraft.util.EnumParticleTypes +import net.minecraftforge.common.MinecraftForge +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import java.util.function.Predicate +import kotlin.math.floor + +@NEUAutoSubscribe +class DevTestCommand { + companion object { + val DEV_TESTERS: List = mutableListOf( + "d0e05de7-6067-454d-beae-c6d19d886191", // moulberry + "66502b40-6ac1-4d33-950d-3df110297aab", // lucycoconut + "a5761ff3-c710-4cab-b4f4-3e7f017a8dbf", // ironm00n + "5d5c548a-790c-4fc8-bd8f-d25b04857f44", // ariyio + "53924f1a-87e6-4709-8e53-f1c7d13dc239", // throwpo + "d3cb85e2-3075-48a1-b213-a9bfb62360c1", // lrg89 + "0b4d470f-f2fb-4874-9334-1eaef8ba4804", // dediamondpro + "ebb28704-ed85-43a6-9e24-2fe9883df9c2", // lulonaut + "698e199d-6bd1-4b10-ab0c-52fedd1460dc", // craftyoldminer + "8a9f1841-48e9-48ed-b14f-76a124e6c9df", // eisengolem + "a7d6b3f1-8425-48e5-8acc-9a38ab9b86f7", // whalker + "0ce87d5a-fa5f-4619-ae78-872d9c5e07fe", // ascynx + "a049a538-4dd8-43f8-87d5-03f09d48b4dc", // egirlefe + "7a9dc802-d401-4d7d-93c0-8dd1bc98c70d", // efefury + "bb855349-dfd8-4125-a750-5fc2cf543ad5" // hannibal2 + ) + val SPECIAL_KICK = "SPECIAL_KICK" + + val DEV_FAIL_STRINGS = arrayOf( + "No.", + "I said no.", + "You aren't allowed to use this.", + "Are you sure you want to use this? Type 'Yes' in chat.", + "Are you sure you want to use this? Type 'Yes' in chat.", + "Lmao you thought", + "Ok please stop", + "What do you want from me?", + "This command almost certainly does nothing useful for you", + "Ok, this is the last message, after this it will repeat", + "No.", + "I said no.", + "Dammit. I thought that would work. Uhh...", + "\u00a7dFrom \u00a7c[ADMIN] Minikloon\u00a77: If you use that command again, I'll have to ban you", + SPECIAL_KICK, + "Ok, this is actually the last message, use the command again and you'll crash I promise" + ) + + fun isDeveloper(commandSender: ICommandSender): Boolean { + return DEV_TESTERS.contains((commandSender as? EntityPlayer)?.uniqueID?.toString()) + || Launch.blackboard.get("fml.deobfuscatedEnvironment") as Boolean + + } + } + + var devFailIndex = 0 + fun canPlayerExecute(commandSender: ICommandSender): Boolean { + return isDeveloper(commandSender) + } + + @SubscribeEvent + fun onCommands(event: RegisterBrigadierCommandEvent) { + val hook = event.command("neudevtest") { + requires { + canPlayerExecute(it) + } + thenLiteralExecute("profileinfo") { + val currentProfile = SBInfo.getInstance().currentProfile + val gamemode = SBInfo.getInstance().getGamemodeForProfile(currentProfile) + reply("${GOLD}You are on Profile $currentProfile with the mode $gamemode") + }.withHelp("Display information about your current profile") + thenLiteralExecute("buildflags") { + reply("BuildFlags: \n" + + BuildFlags.getAllFlags().entries + .joinToString(("\n")) { (key, value) -> " + $key - $value" }) + }.withHelp("List the flags with which NEU was built") + thenLiteral("exteditor") { + thenArgument("editor", StringArgumentType.string()) { newEditor -> + thenExecute { + NotEnoughUpdates.INSTANCE.config.hidden.externalEditor = this[newEditor] + reply("You changed your external editor to: §Z${this[newEditor]}") + } + }.withHelp("Change the editor used to edit repo files") + thenExecute { + reply("Your external editor is: §Z${NotEnoughUpdates.INSTANCE.config.hidden.externalEditor}") + } + }.withHelp("See your current external editor for repo files") + thenLiteral("pricetest") { + thenArgument("item", StringArgumentType.string()) { item -> + thenExecute { + NotEnoughUpdates.INSTANCE.openGui = GuiPriceGraph(this[item]) + } + }.withHelp("Display the price graph for an item by id") + thenExecute { + NotEnoughUpdates.INSTANCE.manager.auctionManager.updateBazaar() + } + }.withHelp("Update the price data from the bazaar") + thenLiteralExecute("zone") { + val target = Minecraft.getMinecraft().objectMouseOver.blockPos + ?: Minecraft.getMinecraft().thePlayer.position + val zone = CustomBiomes.INSTANCE.getSpecialZone(target) + listOf( + ChatComponentText("Showing Zone Info for: $target"), + ChatComponentText("Zone: " + (zone?.name ?: "null")), + ChatComponentText("Location: " + SBInfo.getInstance().getLocation()), + ChatComponentText("Biome: " + CustomBiomes.INSTANCE.getCustomBiome(target)) + ).forEach { component -> + reply(component) + } + MinecraftForge.EVENT_BUS.post( + LocationChangeEvent( + SBInfo.getInstance().getLocation(), SBInfo + .getInstance() + .getLocation() + ) + ) + }.withHelp("Display information about the special block zone at your cursor (Custom Texture Regions)") + thenLiteralExecute("positiontest") { + NotEnoughUpdates.INSTANCE.openGui = GuiPositionEditor() + }.withHelp("Open the gui position editor") + thenLiteral("pt") { + thenArgument("particle", EnumArgumentType.enum()) { particle -> + thenExecute { + FishingHelper.type = this[particle] + reply("Fishing particles set to ${FishingHelper.type}") + } + } + } + thenLiteralExecute("dev") { + NotEnoughUpdates.INSTANCE.config.hidden.dev = !NotEnoughUpdates.INSTANCE.config.hidden.dev + reply("§e[NEU] Dev mode " + if (NotEnoughUpdates.INSTANCE.config.hidden.dev) "§aenabled" else "§cdisabled") + }.withHelp("Toggle developer mode") + thenLiteralExecute("saveconfig") { + NotEnoughUpdates.INSTANCE.saveConfig() + reply("Config saved") + }.withHelp("Force sync the config to disk") + thenLiteralExecute("searchmode") { + NotEnoughUpdates.INSTANCE.config.hidden.firstTimeSearchFocus = true + reply(AQUA.toString() + "I would never search") + }.withHelp("Reset your search data to redisplay the search tutorial") + thenLiteralExecute("bluehair") { + PronounDB.test() + }.withHelp("Test the pronoundb integration") + thenLiteral("opengui") { + thenArgumentExecute("class", StringArgumentType.string()) { className -> + try { + NotEnoughUpdates.INSTANCE.openGui = + Class.forName(this[className]).newInstance() as GuiScreen + reply("Opening gui: " + NotEnoughUpdates.INSTANCE.openGui) + } catch (e: Exception) { + e.printStackTrace() + reply("Failed to open this GUI.") + } + }.withHelp("Open a gui by class name") + } + thenLiteralExecute("center") { + val x = floor(Minecraft.getMinecraft().thePlayer.posX) + 0.5f + val z = floor(Minecraft.getMinecraft().thePlayer.posZ) + 0.5f + Minecraft.getMinecraft().thePlayer.setPosition(x, Minecraft.getMinecraft().thePlayer.posY, z) + reply("Literal hacks") + }.withHelp("Center yourself on the block you are currently standing (like using AOTE)") + thenLiteral("minion") { + thenArgumentExecute("args", RestArgumentType) { arg -> + MinionHelperManager.getInstance().handleCommand(arrayOf("minion") + this[arg].split(" ")) + }.withHelp("Minion related commands. Not yet integrated in brigadier") + } + thenLiteralExecute("copytablist") { + val tabList = TabListUtils.getTabList().joinToString("\n", postfix = "\n") + MiscUtils.copyToClipboard(tabList) + reply("Copied tablist to clipboard!") + }.withHelp("Copy the tab list") + thenLiteralExecute("useragent") { + thenArgumentExecute("newuseragent", RestArgumentType) { userAgent -> + reply("Setting your user agent to ${this[userAgent]}") + NotEnoughUpdates.INSTANCE.config.hidden.customUserAgent = this[userAgent] + }.withHelp("Set a custom user agent for all HTTP requests") + thenExecute { + reply("Resetting your user agent.") + NotEnoughUpdates.INSTANCE.config.hidden.customUserAgent = null + } + }.withHelp("Reset the custom user agent") + } + hook.beforeCommand = Predicate { + if (!canPlayerExecute(it.context.source)) { + if (devFailIndex !in DEV_FAIL_STRINGS.indices) { + throw object : Error("L") { + @Override + fun printStackTrace() { + throw Error("L") + } + } + } + val text = DEV_FAIL_STRINGS[devFailIndex++] + if (text == SPECIAL_KICK) { + val component = ChatComponentText("\u00a7cYou are permanently banned from this server!") + component.appendText("\n") + component.appendText("\n\u00a77Reason: \u00a7rI told you not to run the command - Moulberry") + component.appendText("\n\u00a77Find out more: \u00a7b\u00a7nhttps://www.hypixel.net/appeal") + component.appendText("\n") + component.appendText("\n\u00a77Ban ID: \u00a7r#49871982") + component.appendText("\n\u00a77Sharing your Ban ID may affect the processing of your appeal!") + Minecraft.getMinecraft().netHandler.networkManager.closeChannel(component) + } else { + it.context.source.addChatMessage(ChatComponentText("$RED$text")) + } + false + } else { + true + } + } + } + +} diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/DiagCommand.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/DiagCommand.kt new file mode 100644 index 00000000..3e5e7b9b --- /dev/null +++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/DiagCommand.kt @@ -0,0 +1,78 @@ +/* + * Copyright (C) 2023 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see . + */ + +package io.github.moulberry.notenoughupdates.commands.dev + +import com.mojang.brigadier.arguments.BoolArgumentType.bool +import io.github.moulberry.notenoughupdates.NotEnoughUpdates +import io.github.moulberry.notenoughupdates.autosubscribe.NEUAutoSubscribe +import io.github.moulberry.notenoughupdates.events.RegisterBrigadierCommandEvent +import io.github.moulberry.notenoughupdates.miscfeatures.CrystalMetalDetectorSolver +import io.github.moulberry.notenoughupdates.miscfeatures.CrystalWishingCompassSolver +import io.github.moulberry.notenoughupdates.options.customtypes.NEUDebugFlag +import io.github.moulberry.notenoughupdates.util.brigadier.* +import io.github.moulberry.notenoughupdates.util.brigadier.EnumArgumentType.Companion.enum +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +// Why is this not merged into /neudevtest +@NEUAutoSubscribe +class DiagCommand { + @SubscribeEvent + fun onCommands(event: RegisterBrigadierCommandEvent) { + event.command("neudiag") { + thenLiteral("metal") { + thenLiteral("center") { + thenArgumentExecute("usecenter", bool()) { useCenter -> + CrystalMetalDetectorSolver.setDebugDoNotUseCenter(this[useCenter]) + reply("Center coordinates-based solutions ${if (this[useCenter]) "enabled" else "disabled"}") + }.withHelp("Toggle coordinate based solutions") + } + thenExecute { + CrystalMetalDetectorSolver.logDiagnosticData(true) + reply("Enabled metal detector diagnostic logging.") + } + }.withHelp("Enable metal detector diagnostics") + thenLiteralExecute("wishing") { + CrystalWishingCompassSolver.getInstance().logDiagnosticData(true) + reply("Enabled wishing compass diagnostic logging") + }.withHelp("Enable wishing compass diagnostic logging") + thenLiteral("debug") { + thenLiteralExecute("list") { + reply("Here are all flags:\n${NEUDebugFlag.getFlagList()}") + }.withHelp("List all debug diagnostic logging flags") + thenLiteral("setflag") { + thenArgument("flag", enum()) { flag -> + thenArgumentExecute("enable", bool()) { enable -> + val debugFlags = NotEnoughUpdates.INSTANCE.config.hidden.debugFlags + if (this[enable]) { + debugFlags.add(this[flag]) + } else { + debugFlags.remove(this[flag]) + } + reply("${if(this[enable]) "Enabled" else "Disabled"} the flag ${this[flag]}.") + }.withHelp("Enable or disable a diagnostic logging stream") + } + } + thenExecute { + reply("Effective debug flags: \n${NEUDebugFlag.getEnabledFlags()}") + } + }.withHelp("Log diagnostic data.") + } + } +} diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/NEUStatsCommand.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/NEUStatsCommand.kt new file mode 100644 index 00000000..7035aaa3 --- /dev/null +++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/NEUStatsCommand.kt @@ -0,0 +1,209 @@ +/* + * Copyright (C) 2023 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see . + */ + +package io.github.moulberry.notenoughupdates.commands.dev + +import com.mojang.brigadier.context.CommandContext +import com.sun.management.OperatingSystemMXBean +import com.sun.management.UnixOperatingSystemMXBean +import io.github.moulberry.notenoughupdates.NotEnoughUpdates +import io.github.moulberry.notenoughupdates.autosubscribe.NEUAutoSubscribe +import io.github.moulberry.notenoughupdates.events.RegisterBrigadierCommandEvent +import io.github.moulberry.notenoughupdates.util.DiscordMarkdownBuilder +import io.github.moulberry.notenoughupdates.util.HastebinUploader +import io.github.moulberry.notenoughupdates.util.SBInfo +import io.github.moulberry.notenoughupdates.util.brigadier.reply +import io.github.moulberry.notenoughupdates.util.brigadier.thenExecute +import io.github.moulberry.notenoughupdates.util.brigadier.thenLiteralExecute +import io.github.moulberry.notenoughupdates.util.brigadier.withHelp +import net.minecraft.client.Minecraft +import net.minecraft.client.renderer.OpenGlHelper +import net.minecraft.command.ICommandSender +import net.minecraft.util.EnumChatFormatting.DARK_RED +import net.minecraft.util.EnumChatFormatting.GREEN +import net.minecraftforge.common.ForgeVersion +import net.minecraftforge.fml.client.FMLClientHandler +import net.minecraftforge.fml.common.Loader +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import org.lwjgl.opengl.Display +import org.lwjgl.opengl.GL11 +import java.awt.Toolkit +import java.awt.datatransfer.StringSelection +import java.lang.management.ManagementFactory +import java.util.concurrent.CompletableFuture +import javax.management.JMX +import javax.management.ObjectName + +@NEUAutoSubscribe +class NEUStatsCommand { + @SubscribeEvent + fun onCommands(event: RegisterBrigadierCommandEvent) { + event.command("stats", "neustats") { + thenLiteralExecute("modlist") { + clipboardAndSendMessage( + DiscordMarkdownBuilder() + .also(::appendModList) + .toString() + ) + }.withHelp("Copy the mod list to your clipboard") + thenLiteralExecute("full") { + clipboardAndSendMessage( + DiscordMarkdownBuilder() + .also(::appendStats) + .also(::appendModList) + .toString() + ) + }.withHelp("Copy the full list of all NEU stats and your mod list to your clipboard") + thenLiteralExecute("dump") { + reply("${GREEN}This will upload a dump of the java classes your game has loaded how big they are and how many there are. This can take a few seconds as it is uploading to HasteBin.") + uploadDataUsageDump().thenAccept { + clipboardAndSendMessage(it) + } + }.withHelp("Dump all loaded classes and their memory usage and copy that to your clipboard.") + thenExecute { + clipboardAndSendMessage( + DiscordMarkdownBuilder() + .also(::appendStats) + .also { + if (Loader.instance().activeModList.size <= 15) appendModList(it) + } + .toString() + ) + } + }.withHelp("Copy a list of NEU relevant stats to your clipboard for debugging purposes") + } + interface DiagnosticCommandMXBean { + fun gcClassHistogram(array: Array): String + } + + private fun uploadDataUsageDump(): CompletableFuture { + return CompletableFuture.supplyAsync { + try { + val server = + ManagementFactory.getPlatformMBeanServer() + val objectName = + ObjectName.getInstance("com.sun.management:type=DiagnosticCommand") + val proxy = JMX.newMXBeanProxy( + server, + objectName, + DiagnosticCommandMXBean::class.java + ) + HastebinUploader.upload( + proxy.gcClassHistogram(emptyArray()).replace("[", "[]"), + HastebinUploader.Mode.NORMAL + ) + } catch (e: Exception) { + null + } + } + + } + + + private fun getMemorySize(): Long { + try { + return (ManagementFactory.getOperatingSystemMXBean() as OperatingSystemMXBean).totalPhysicalMemorySize + } catch (e: java.lang.Exception) { + try { + return (ManagementFactory.getOperatingSystemMXBean() as UnixOperatingSystemMXBean).totalPhysicalMemorySize + } catch (ignored: java.lang.Exception) { /*IGNORE*/ + } + } + return -1 + } + + val ONE_MB = 1024L * 1024L + private fun appendStats(builder: DiscordMarkdownBuilder) { + val maxMemory = Runtime.getRuntime().maxMemory() + val totalMemory = Runtime.getRuntime().totalMemory() + val freeMemory = Runtime.getRuntime().freeMemory() + val currentMemory = totalMemory - freeMemory + builder.category("System Stats") + builder.append("OS", System.getProperty("os.name")) + builder.append("CPU", OpenGlHelper.getCpu()) + builder.append( + "Display", + String.format("%dx%d (%s)", Display.getWidth(), Display.getHeight(), GL11.glGetString(GL11.GL_VENDOR)) + ) + builder.append("GPU", GL11.glGetString(GL11.GL_RENDERER)) + builder.append("GPU Driver", GL11.glGetString(GL11.GL_VERSION)) + if (getMemorySize() > 0) + builder.append( + "Maximum Memory", + "${getMemorySize() / ONE_MB}MB" + ) + builder.append("Shaders", ("" + OpenGlHelper.isFramebufferEnabled()).uppercase()) + builder.category("Java Stats") + builder.append( + "Java", + "${System.getProperty("java.version")} ${if (Minecraft.getMinecraft().isJava64bit) 64 else 32}bit", + ) + builder.append( + "Memory", String.format( + "% 2d%% %03d/%03dMB", + currentMemory * 100L / maxMemory, + currentMemory / ONE_MB, + maxMemory / ONE_MB + ) + ) + builder.append( + "Memory Allocated", + String.format("% 2d%% %03dMB", totalMemory * 100L / maxMemory, totalMemory / ONE_MB) + ) + builder.category("Game Stats") + builder.append("FPS", Minecraft.getDebugFPS().toString()) + builder.append("Loaded Mods", Loader.instance().activeModList.size) + builder.append("Forge", ForgeVersion.getVersion()) + builder.append("Optifine", if (FMLClientHandler.instance().hasOptifine()) "TRUE" else "FALSE") + builder.category("Neu Settings") + builder.append("API Key", if (NotEnoughUpdates.INSTANCE.config.apiData.apiKey.isEmpty()) "FALSE" else "TRUE") + builder.append("On SkyBlock", if (NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard()) "TRUE" else "FALSE") + builder.append( + "Mod Version", + Loader.instance().indexedModList[NotEnoughUpdates.MODID]!!.displayVersion + ) + builder.append("SB Profile", SBInfo.getInstance().currentProfile) + builder.append("Has Advanced Tab", if (SBInfo.getInstance().hasNewTab) "TRUE" else "FALSE") + builder.category("Repo Stats") + builder.append("Last Commit", NotEnoughUpdates.INSTANCE.manager.latestRepoCommit) + builder.append("Loaded Items", NotEnoughUpdates.INSTANCE.manager.itemInformation.size.toString()) + } + + private fun appendModList(builder: DiscordMarkdownBuilder): DiscordMarkdownBuilder { + builder.category("Mods Loaded") + Loader.instance().activeModList.forEach { + builder.append(it.name, "${it.source} (${it.displayVersion})") + } + return builder + } + + fun CommandContext.clipboardAndSendMessage(data: String?) { + if (data == null) { + reply("${DARK_RED}Error occurred trying to perform command.") + return + } + try { + val clipboard = StringSelection(data) + Toolkit.getDefaultToolkit().systemClipboard.setContents(clipboard, null) + reply("${GREEN}Dev info copied to clipboard.") + } catch (ignored: Exception) { + reply("${DARK_RED}Could not copy to clipboard.") + } + } +} diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/PackDevCommand.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/PackDevCommand.kt new file mode 100644 index 00000000..fceacfab --- /dev/null +++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/PackDevCommand.kt @@ -0,0 +1,165 @@ +/* + * Copyright (C) 2023 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see . + */ + +package io.github.moulberry.notenoughupdates.commands.dev + +import com.mojang.brigadier.arguments.DoubleArgumentType.doubleArg +import com.mojang.brigadier.builder.ArgumentBuilder +import io.github.moulberry.notenoughupdates.NotEnoughUpdates +import io.github.moulberry.notenoughupdates.autosubscribe.NEUAutoSubscribe +import io.github.moulberry.notenoughupdates.core.util.MiscUtils +import io.github.moulberry.notenoughupdates.events.RegisterBrigadierCommandEvent +import io.github.moulberry.notenoughupdates.util.brigadier.* +import net.minecraft.client.Minecraft +import net.minecraft.client.entity.AbstractClientPlayer +import net.minecraft.command.ICommandSender +import net.minecraft.entity.Entity +import net.minecraft.entity.EntityLiving +import net.minecraft.entity.EntityLivingBase +import net.minecraft.entity.item.EntityArmorStand +import net.minecraft.entity.player.EntityPlayer +import net.minecraft.item.ItemStack +import net.minecraft.util.EnumChatFormatting +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +@NEUAutoSubscribe +class PackDevCommand { + + fun > U.npcListCommand( + name: String, + singleCommand: String, + multipleCommand: String, + clazz: Class, + provider: () -> List + ) { + fun getEntities(distance: Double): List { + val distanceSquared = distance * distance + val thePlayer = Minecraft.getMinecraft().thePlayer + return provider() + .asSequence() + .filterIsInstance(clazz) + .filter { it != thePlayer } + .filter { it.getDistanceSqToEntity(thePlayer) < distanceSquared } + .toList() + } + + thenLiteral(singleCommand) { + thenArgumentExecute("distance", doubleArg(0.0)) { dist -> + val dist = this[dist] + val entity = getEntities(dist).minByOrNull { it.getDistanceSqToEntity(Minecraft.getMinecraft().thePlayer) } + if (entity == null) { + reply("No $name found within $dist blocks") + return@thenArgumentExecute + } + MiscUtils.copyToClipboard(StringBuilder().appendEntityData(entity).toString().trim()) + reply("Copied data to clipboard") + }.withHelp("Find the nearest $name and copy data about them to your clipboard") + } + thenLiteral(multipleCommand) { + thenArgumentExecute("distance", doubleArg(0.0)) { dist -> + val dist = this[dist] + val entity = getEntities(dist) + val sb = StringBuilder() + reply("Found ${entity.size} ${name}s") + if (entity.isNotEmpty()) { + entity.forEach { + sb.appendEntityData(it) + } + MiscUtils.copyToClipboard(sb.toString().trim()) + + reply("Copied data to clipboard") + } + }.withHelp("Find all $name within range and copy data about them to your clipboard") + } + } + + fun StringBuilder.appendEntityData(entity: EntityLivingBase) { + if (entity is EntityPlayer) { + append("Player UUID: ") + appendLine(entity.uniqueID) + if (entity is AbstractClientPlayer) { + append("Entity Texture Id: ") + appendLine(entity.locationSkin.resourcePath?.replace("skins/", "")) + } + } + append("Custom Name Tag: ") + appendLine(entity.customNameTag ?: "null") + append("Mob: ") + appendLine(entity.name) + append("Entity Id: ") + appendLine(entity.entityId) + + appendItemData("Item", entity.heldItem) + + for ((slot, name) in listOf("Boots", "Leggings", "Chestplate", "Helmet").withIndex()) { + val armorPiece = entity.getCurrentArmor(slot) + appendItemData(name, armorPiece) + } + appendLine() + appendLine() + } + + fun StringBuilder.appendItemData(name: String, item: ItemStack?) { + append("$name: ") + if (item != null) { + appendLine(item) + append("$name Display Name") + appendLine(item.displayName) + append("$name Tag Compound: ") + val compound = item.tagCompound + if (compound == null) { + appendLine("null") + } else { + appendLine(compound) + append("$name Tag Compound Extra Attributes") + appendLine(compound.getTag("ExtraAttributes")) + } + } else { + appendLine("null") + } + + } + + + @SubscribeEvent + fun onCommands(event: RegisterBrigadierCommandEvent) { + event.command("neupackdev") { + npcListCommand("Player", "getplayer", "getplayers", AbstractClientPlayer::class.java) { + Minecraft.getMinecraft().theWorld.playerEntities + } + npcListCommand("NPC", "getnpc", "getnpcs", AbstractClientPlayer::class.java) { + Minecraft.getMinecraft().theWorld.playerEntities.filter { it.uniqueID?.version() != 4 } + } + npcListCommand("mob", "getmob", "getmobs", EntityLiving::class.java) { + Minecraft.getMinecraft().theWorld.loadedEntityList + } + npcListCommand("armor stand", "getarmorstand", "getarmorstands", EntityArmorStand::class.java) { + Minecraft.getMinecraft().theWorld.loadedEntityList + } + thenExecute { + NotEnoughUpdates.INSTANCE.packDevEnabled = !NotEnoughUpdates.INSTANCE.packDevEnabled + if (NotEnoughUpdates.INSTANCE.packDevEnabled) { + reply("${EnumChatFormatting.GREEN}Enabled pack developer mode.") + } else { + reply("${EnumChatFormatting.RED}Disabled pack developer mode.") + } + } + }.withHelp("Toggle pack developer mode") + } +} diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/SimpleDevCommands.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/SimpleDevCommands.kt new file mode 100644 index 00000000..95a6500e --- /dev/null +++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/SimpleDevCommands.kt @@ -0,0 +1,110 @@ +/* + * Copyright (C) 2023 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see . + */ + +package io.github.moulberry.notenoughupdates.commands.dev + +import com.mojang.brigadier.arguments.FloatArgumentType.floatArg +import com.mojang.brigadier.arguments.StringArgumentType.string +import io.github.moulberry.notenoughupdates.NotEnoughUpdates +import io.github.moulberry.notenoughupdates.autosubscribe.NEUAutoSubscribe +import io.github.moulberry.notenoughupdates.dungeons.DungeonWin +import io.github.moulberry.notenoughupdates.events.RegisterBrigadierCommandEvent +import io.github.moulberry.notenoughupdates.miscfeatures.NullzeeSphere +import io.github.moulberry.notenoughupdates.util.brigadier.* +import net.minecraft.client.entity.EntityPlayerSP +import net.minecraft.event.ClickEvent +import net.minecraft.util.BlockPos +import net.minecraft.util.ChatComponentText +import net.minecraft.util.ResourceLocation +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import java.util.function.Consumer + +@NEUAutoSubscribe +class SimpleDevCommands { + @SubscribeEvent + fun onCommands(event: RegisterBrigadierCommandEvent) { + event.command("neureloadrepo") { + thenExecute { + NotEnoughUpdates.INSTANCE.manager.reloadRepository() + reply("Reloaded repository.") + } + }.withHelp("Reload the NEU data repository from disk (not from network)") + event.command("neudungeonwintest") { + thenArgumentExecute("file", string()) { file -> + DungeonWin.TEAM_SCORE = ResourceLocation("notenoughupdates:dungeon_win/${this[file].lowercase()}.png") + reply("Changed the dungeon win display") + }.withHelp("Change the dungeon win test to load from a file") + thenExecute { + DungeonWin.displayWin() + } + }.withHelp("Display the dungeon win pop up") + event.command("neuenablestorage") { + thenLiteralExecute("disable") { + NotEnoughUpdates.INSTANCE.config.storageGUI.enableStorageGUI3 = true + NotEnoughUpdates.INSTANCE.saveConfig() + reply("Disabled the NEU storage overlay. Click here to enable again") { + chatStyle.chatClickEvent = ClickEvent( + ClickEvent.Action.SUGGEST_COMMAND, + "/neuenablestorage" + ) + } + }.withHelp("Disable the neu storage overlay") + thenExecute { + NotEnoughUpdates.INSTANCE.config.storageGUI.enableStorageGUI3 = true + NotEnoughUpdates.INSTANCE.saveConfig() + reply("Enabled the NEU storage overlay. Click here to disable again") { + chatStyle.chatClickEvent = ClickEvent( + ClickEvent.Action.SUGGEST_COMMAND, + "/neuenablestorage disable" + ) + } + } + }.withHelp("Enable the neu storage overlay") + event.command("neuzeesphere") { + thenLiteralExecute("on") { + NullzeeSphere.enabled = true + reply("Enabled nullzee sphere") + }.withHelp("Enable nullzee sphere") + thenLiteralExecute("off") { + NullzeeSphere.enabled = false + reply("Disabled nullzee sphere") + }.withHelp("Disable nullzee sphere") + thenLiteralExecute("setcenter") { + val p = source as EntityPlayerSP + NullzeeSphere.centerPos = BlockPos(p.posX, p.posY, p.posZ) + NullzeeSphere.overlayVBO = null + reply("Set center to ${NullzeeSphere.centerPos}") + }.withHelp("Set the center of the nullzee sphere") + thenArgumentExecute("radius", floatArg(0F)) { size -> + NullzeeSphere.size = this[size] + NullzeeSphere.overlayVBO = null + reply("Set size to ${this[size]}") + }.withHelp("Set the radius of the nullzee sphere") + } + event.command("neuresetrepo") { + thenExecute { + NotEnoughUpdates.INSTANCE.manager + .userFacingRepositoryReload() + .thenAccept { it + it.forEach(::reply) + } + } + }.withHelp("Reload the NEU data repository from network") + } +} diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/help/FeaturesCommand.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/help/FeaturesCommand.kt new file mode 100644 index 00000000..6cc4e255 --- /dev/null +++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/help/FeaturesCommand.kt @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2023 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see . + */ + +package io.github.moulberry.notenoughupdates.commands.help + +import io.github.moulberry.notenoughupdates.autosubscribe.NEUAutoSubscribe +import io.github.moulberry.notenoughupdates.events.RegisterBrigadierCommandEvent +import io.github.moulberry.notenoughupdates.util.Constants +import io.github.moulberry.notenoughupdates.util.Utils +import io.github.moulberry.notenoughupdates.util.brigadier.reply +import io.github.moulberry.notenoughupdates.util.brigadier.thenExecute +import io.github.moulberry.notenoughupdates.util.brigadier.withHelp +import net.minecraft.event.ClickEvent +import net.minecraft.util.ChatComponentText +import net.minecraft.util.EnumChatFormatting +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +@NEUAutoSubscribe +class FeaturesCommand { + @SubscribeEvent + fun onCommands(event: RegisterBrigadierCommandEvent) { + event.command("neufeatures") { + thenExecute { + reply("") + val url = Constants.MISC?.get("featureslist")?.asString + if (url == null) { + Utils.showOutdatedRepoNotification() + return@thenExecute + } + + if (Utils.openUrl(url)) { + reply( + EnumChatFormatting.DARK_PURPLE.toString() + "" + EnumChatFormatting.BOLD + "NEU" + EnumChatFormatting.RESET + + EnumChatFormatting.GOLD + "> Opening Feature List in browser." + ) + } else { + val clickTextFeatures = ChatComponentText( + (EnumChatFormatting.DARK_PURPLE.toString() + "" + EnumChatFormatting.BOLD + "NEU" + EnumChatFormatting.RESET + + EnumChatFormatting.GOLD + "> Click here to open the Feature List in your browser.") + ) + clickTextFeatures.chatStyle = + Utils.createClickStyle(ClickEvent.Action.OPEN_URL, url) + reply(clickTextFeatures) + } + reply("") + } + }.withHelp("List all of NEUs features") + } +} diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/help/HelpCommand.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/help/HelpCommand.kt new file mode 100644 index 00000000..1b4f817e --- /dev/null +++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/help/HelpCommand.kt @@ -0,0 +1,95 @@ +/* + * Copyright (C) 2023 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see . + */ + +package io.github.moulberry.notenoughupdates.commands.help + +import com.mojang.brigadier.arguments.StringArgumentType.string +import io.github.moulberry.notenoughupdates.NotEnoughUpdates +import io.github.moulberry.notenoughupdates.autosubscribe.NEUAutoSubscribe +import io.github.moulberry.notenoughupdates.events.RegisterBrigadierCommandEvent +import io.github.moulberry.notenoughupdates.util.brigadier.* +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +@NEUAutoSubscribe +class HelpCommand { + val neuHelpMessages = listOf( + "§5§lNotEnoughUpdates commands", + "§6/neu §7- Opens the main NEU GUI.", + "§6/pv §b?{name} §2ⴵ §r§7- Opens the profile viewer", + "§6/neusouls {on/off/clear/unclear} §r§7- Shows waypoints to fairy souls.", + "§6/neubuttons §r§7- Opens a GUI which allows you to customize inventory buttons.", + "§6/neuec §r§7- Opens the enchant colour GUI.", + "§6/join {floor} §r§7- Short Command to join a Dungeon. §lNeed a Party of 5 People§r§7 {4/f7/m5}.", + "§6/neucosmetics §r§7- Opens the cosmetic GUI.", + "§6/neurename §r§7- Opens the NEU Item Customizer.", + "§6/cata §b?{name} §2ⴵ §r§7- Opens the profile viewer's Catacombs page.", + "§6/neulinks §r§7- Shows links to NEU/Moulberry.", + "§6/neuoverlay §r§7- Opens GUI Editor for quickcommands and searchbar.", + "§6/neuah §r§7- Opens NEU's custom auction house GUI.", + "§6/neucalendar §r§7- Opens NEU's custom calendar GUI.", + "§6/neucalc §r§7- Run calculations.", + "", + "§6§lOld commands:", + "§6/peek §b?{user} §2ⴵ §r§7- Shows quick stats for a user.", + "", + "§6§lDebug commands:", + "§6/neustats §r§7- Copies helpful info to the clipboard.", + "§6/neustats modlist §r§7- Copies mod list info to clipboard.", + "§6/neuresetrepo §r§7- Deletes all repo files.", + "§6/neureloadrepo §r§7- Debug command with repo.", + "", + "§6§lDev commands:", + "§6/neupackdev §r§7- pack creator command - getnpc, getmob(s), getarmorstand(s), getall. Optional radius argument for all." + ) + val neuDevHelpMessages = listOf( + "§6/neudevtest §r§7- dev test command", + "§6/neuzeephere §r§7- sphere", + "§6/neudungeonwintest §r§7- displays the dungeon win screen" + ) + val helpInfo = listOf( + "", + "§7Commands marked with a §2\"ⴵ\"§7 require an api key. You can set your api key via \"/api new\" or by manually putting it in the api field in \"/neu\"", + "", + "§7Arguments marked with a §b\"?\"§7 are optional.", + "", + "§6§lScroll up to see everything" + ) + + @SubscribeEvent + fun onCommands(event: RegisterBrigadierCommandEvent) { + event.command("neuhelp") { + thenArgumentExecute("command", string()) { commandName -> + val commandNode = event.dispatcher.root.getChild(this[commandName]) + if (commandNode == null) { + reply("Could not find NEU command with name ${this[commandName]}") + return@thenArgumentExecute + } + reply(event.brigadierRoot.getAllUsages("/${this[commandName]}", commandNode).joinToString("\n"){ + "${it.path} - ${it.help}" + }) + }.withHelp("Display help for a specific NEU command") + thenExecute { + neuHelpMessages.forEach(::reply) + if (NotEnoughUpdates.INSTANCE.config.hidden.dev) + neuDevHelpMessages.forEach(::reply) + helpInfo.forEach(::reply) + } + }.withHelp("Display a list of all NEU commands") + } +} diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/help/LinksCommand.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/help/LinksCommand.kt new file mode 100644 index 00000000..957948ae --- /dev/null +++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/help/LinksCommand.kt @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2023 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see . + */ + +package io.github.moulberry.notenoughupdates.commands.help + +import io.github.moulberry.notenoughupdates.NotEnoughUpdates +import io.github.moulberry.notenoughupdates.autosubscribe.NEUAutoSubscribe +import io.github.moulberry.notenoughupdates.events.RegisterBrigadierCommandEvent +import io.github.moulberry.notenoughupdates.util.Utils +import io.github.moulberry.notenoughupdates.util.brigadier.reply +import io.github.moulberry.notenoughupdates.util.brigadier.thenExecute +import io.github.moulberry.notenoughupdates.util.brigadier.withHelp +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +@NEUAutoSubscribe +class LinksCommand { + @SubscribeEvent + fun onCommands(event: RegisterBrigadierCommandEvent) { + event.command("neulinks") { + thenExecute { + val manager = NotEnoughUpdates.INSTANCE.manager + val updateJsonFile = manager.repoLocation.resolve("update.json") + if (!updateJsonFile.exists()) { + Utils.showOutdatedRepoNotification() + return@thenExecute + } + try { + val updateJson = manager.getJsonFromFile(updateJsonFile) + NotEnoughUpdates.INSTANCE.displayLinks(updateJson, 0) + } catch (_: Exception) { + Utils.showOutdatedRepoNotification() + } + } + }.withHelp("Display links for Moulberry and NEU") + } +} diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/help/SettingsCommand.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/help/SettingsCommand.kt new file mode 100644 index 00000000..fe58c807 --- /dev/null +++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/help/SettingsCommand.kt @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2023 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see . + */ + +package io.github.moulberry.notenoughupdates.commands.help + +import io.github.moulberry.notenoughupdates.NotEnoughUpdates +import io.github.moulberry.notenoughupdates.autosubscribe.NEUAutoSubscribe +import io.github.moulberry.notenoughupdates.core.GuiScreenElementWrapper +import io.github.moulberry.notenoughupdates.core.config.struct.ConfigProcessor +import io.github.moulberry.notenoughupdates.events.RegisterBrigadierCommandEvent +import io.github.moulberry.notenoughupdates.options.NEUConfigEditor +import io.github.moulberry.notenoughupdates.util.brigadier.* +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +@NEUAutoSubscribe +class SettingsCommand { + @SubscribeEvent + fun onCommands(event: RegisterBrigadierCommandEvent) { + event.command("neu", "neusettings") { + thenArgument("search", RestArgumentType) { search -> + suggestsList(ConfigProcessor.create(NotEnoughUpdates.INSTANCE.config).keys.toList()) + thenExecute { + NotEnoughUpdates.INSTANCE.openGui = GuiScreenElementWrapper( + NEUConfigEditor( + NotEnoughUpdates.INSTANCE.config, + this[search] + ) + ) + } + }.withHelp("Search the NEU settings") + thenExecute { + NotEnoughUpdates.INSTANCE.openGui = + GuiScreenElementWrapper(NEUConfigEditor(NotEnoughUpdates.INSTANCE.config)) + } + }.withHelp("Open the NEU settings") + } +} diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/help/StorageViewerWhyCommand.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/help/StorageViewerWhyCommand.kt new file mode 100644 index 00000000..782eaf3d --- /dev/null +++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/help/StorageViewerWhyCommand.kt @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2023 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see . + */ +package io.github.moulberry.notenoughupdates.commands.help + +import io.github.moulberry.notenoughupdates.autosubscribe.NEUAutoSubscribe +import io.github.moulberry.notenoughupdates.events.RegisterBrigadierCommandEvent +import io.github.moulberry.notenoughupdates.util.NotificationHandler +import io.github.moulberry.notenoughupdates.util.brigadier.thenExecute +import io.github.moulberry.notenoughupdates.util.brigadier.withHelp +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +@NEUAutoSubscribe +class StorageViewerWhyCommand { + @SubscribeEvent + fun onCommands(event: RegisterBrigadierCommandEvent) { + event.command("neustwhy") { + thenExecute { + NotificationHandler.displayNotification( + listOf( + "§eStorage Viewer", + "§7Currently, the storage viewer requires you to click twice", + "§7in order to switch between pages. This is because Hypixel", + "§7has not yet added a shortcut command to go to any enderchest/", + "§7storage page.", + "§7While it is possible to send the second click", + "§7automatically, doing so violates Hypixel's new mod rules." + ), true + ) + } + }.withHelp("Display information about why you have to click twice in the NEU storage overlay") + } +} diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/misc/AhCommand.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/misc/AhCommand.kt new file mode 100644 index 00000000..c7d80487 --- /dev/null +++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/misc/AhCommand.kt @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2023 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see . + */ + +package io.github.moulberry.notenoughupdates.commands.misc + +import io.github.moulberry.notenoughupdates.NotEnoughUpdates +import io.github.moulberry.notenoughupdates.auction.CustomAHGui +import io.github.moulberry.notenoughupdates.autosubscribe.NEUAutoSubscribe +import io.github.moulberry.notenoughupdates.events.RegisterBrigadierCommandEvent +import io.github.moulberry.notenoughupdates.util.Utils +import io.github.moulberry.notenoughupdates.util.brigadier.RestArgumentType +import io.github.moulberry.notenoughupdates.util.brigadier.get +import io.github.moulberry.notenoughupdates.util.brigadier.reply +import io.github.moulberry.notenoughupdates.util.brigadier.thenArgumentExecute +import net.minecraft.util.EnumChatFormatting.RED +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import java.util.function.Predicate + +@NEUAutoSubscribe +class AhCommand { + @SubscribeEvent + fun onCommands(event: RegisterBrigadierCommandEvent) { + val hook = event.command("neuah") { + + thenArgumentExecute("search", RestArgumentType) { search -> + if (NotEnoughUpdates.INSTANCE.config.apiData.apiKey == null || + NotEnoughUpdates.INSTANCE.config.apiData.apiKey.isBlank() + ) { + reply("${RED}Can't open NEU AH: an api key is not set. Run /api new and put the result in settings.") + return@thenArgumentExecute + } + NotEnoughUpdates.INSTANCE.openGui = CustomAHGui() + NotEnoughUpdates.INSTANCE.manager.auctionManager.customAH.lastOpen = System.currentTimeMillis() + NotEnoughUpdates.INSTANCE.manager.auctionManager.customAH.clearSearch() + NotEnoughUpdates.INSTANCE.manager.auctionManager.customAH.updateSearch() + + val search = this[search] + + NotEnoughUpdates.INSTANCE.manager.auctionManager.customAH.setSearch( + if (search.isBlank() && NotEnoughUpdates.INSTANCE.config.neuAuctionHouse.saveLastSearch) + null else search + ) + } + } + hook.beforeCommand = Predicate { + if (!NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard()) + Utils.addChatMessage("${RED}You must be on SkyBlock to use this feature.") + NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard() + } + } +} diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/misc/DungeonCommands.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/misc/DungeonCommands.kt new file mode 100644 index 00000000..3b721df5 --- /dev/null +++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/misc/DungeonCommands.kt @@ -0,0 +1,144 @@ +/* + * Copyright (C) 2023 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see . + */ + +package io.github.moulberry.notenoughupdates.commands.misc + +import com.google.gson.JsonObject +import com.mojang.brigadier.arguments.StringArgumentType.string +import io.github.moulberry.notenoughupdates.NotEnoughUpdates +import io.github.moulberry.notenoughupdates.autosubscribe.NEUAutoSubscribe +import io.github.moulberry.notenoughupdates.dungeons.GuiDungeonMapEditor +import io.github.moulberry.notenoughupdates.events.RegisterBrigadierCommandEvent +import io.github.moulberry.notenoughupdates.util.brigadier.* +import net.minecraft.block.material.MapColor +import net.minecraft.client.Minecraft +import net.minecraft.item.ItemMap +import net.minecraft.util.EnumChatFormatting.GREEN +import net.minecraft.util.EnumChatFormatting.RED +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import java.awt.Color + +@NEUAutoSubscribe +class DungeonCommands { + @SubscribeEvent + fun onCommands(event: RegisterBrigadierCommandEvent) { + event.command("dh") { + thenExecute { + Minecraft.getMinecraft().thePlayer.sendChatMessage("/warp dungeon_hub") + } + }.withHelp("Warps to the dungeon hub") + event.command("dn") { + thenExecute { + Minecraft.getMinecraft().thePlayer.sendChatMessage("/warp dungeon_hub") + reply("Warping to...") + reply("Deez nuts lmao") + } + }.withHelp("Warps to the dungeon nuts") + event.command("join") { + thenArgument("floor", string()) { floor -> + suggestsList((1..7).flatMap { listOf("f$it", "m$it") }) + thenExecute { + val floor = this[floor] + val prefix = if (floor.startsWith("m")) "master_catacombs" else "catacombs" + val level = floor.lastOrNull()?.digitToIntOrNull() + val cmd = "/joindungeon $prefix ${floor.lastOrNull()}" + reply("Running command: $cmd") + Minecraft.getMinecraft().thePlayer.sendChatMessage(cmd) + } + }.withHelp("Join a dungeon floor with a party of 5") + } + event.command("neumap") { + thenLiteral("reset") { + thenExecute { + NotEnoughUpdates.INSTANCE.colourMap = null + reply("Reset color map") + } + requiresDev() + }.withHelp("Reset the colour map") + thenLiteral("save") { + thenArgument("filename", string()) { fileName -> + requiresDev() + thenExecute { + val stack = Minecraft.getMinecraft().thePlayer.heldItem + if (stack == null || stack.item !is ItemMap) { + reply("Please hold a map item") + return@thenExecute + } + val map = stack.item as ItemMap + val mapData = map.getMapData(stack, Minecraft.getMinecraft().theWorld) + if (mapData == null) { + reply("Could not grab map data (empty map)") + return@thenExecute + } + val json = JsonObject() + for (i in 0 until (128 * 128)) { + val x = i % 128 + val y = i / 128 + val j = mapData.colors[i].toInt() and 255 + val c = if (j / 4 == 0) { + Color((i + i / 128 and 1) * 8 + 16 shl 24, true) + } else { + Color(MapColor.mapColorArray[j / 4].getMapColor(j and 3), true) + } + json.addProperty("$x:$y", c.rgb) + } + try { + NotEnoughUpdates.INSTANCE.manager.configLocation.resolve("maps").mkdirs() + NotEnoughUpdates.INSTANCE.manager.writeJson( + json, + NotEnoughUpdates.INSTANCE.manager.configLocation.resolve("maps/${this[fileName]}.json") + ) + reply("${GREEN}Saved to file.") + } catch (e: Exception) { + e.printStackTrace() + reply("${RED}Failed to save.") + } + } + }.withHelp("Save a colour map from an item") + } + thenLiteral("load") { + thenArgument("filename", string()) { fileName -> + requiresDev() + thenExecute { + val json = NotEnoughUpdates.INSTANCE.manager.getJsonFromFile( + NotEnoughUpdates.INSTANCE.manager.configLocation.resolve( + "maps/${this[fileName]}.json" + ) + ) + NotEnoughUpdates.INSTANCE.colourMap = (0 until 128).map { x -> + (0 until 128).map { y -> + val key = "$x:$y" + json[key]?.asInt?.let { Color(it, true) } ?: Color(0, 0, 0, 0) + }.toTypedArray() + }.toTypedArray() + for (x in 0..127) { + for (y in 0..127) { + NotEnoughUpdates.INSTANCE.colourMap[x][y] = Color(0, 0, 0, 0) + } + } + reply("Loaded colour map from file") + } + }.withHelp("Load a colour map from a file") + } + thenExecute { + NotEnoughUpdates.INSTANCE.openGui = GuiDungeonMapEditor(null) + } + }.withHelp("Open the dungeon map editor") + } +} diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/misc/FairySoulsCommand.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/misc/FairySoulsCommand.kt new file mode 100644 index 00000000..1d766646 --- /dev/null +++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/misc/FairySoulsCommand.kt @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2023 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see . + */ + +package io.github.moulberry.notenoughupdates.commands.misc + +import io.github.moulberry.notenoughupdates.autosubscribe.NEUAutoSubscribe +import io.github.moulberry.notenoughupdates.events.RegisterBrigadierCommandEvent +import io.github.moulberry.notenoughupdates.miscfeatures.FairySouls +import io.github.moulberry.notenoughupdates.util.brigadier.* +import net.minecraft.util.EnumChatFormatting.DARK_PURPLE +import net.minecraft.util.EnumChatFormatting.RED +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +@NEUAutoSubscribe +class FairySoulsCommand { + + @SubscribeEvent + fun onCommands(event: RegisterBrigadierCommandEvent) { + event.command("neusouls", "fairysouls") { + val enable = thenLiteralExecute("enable") { + if (!FairySouls.getInstance().isTrackSouls) { + reply("${RED}Fairy soul tracking is off, enable it using /neu before using this command") + return@thenLiteralExecute + } + reply("${DARK_PURPLE}Enabled fairy soul waypoints") + FairySouls.getInstance().setShowFairySouls(true) + }.withHelp("Show fairy soul waypoints") + thenLiteral("on") { redirect(enable) } + val disable = thenLiteralExecute("disable") { + FairySouls.getInstance().setShowFairySouls(false) + reply("${DARK_PURPLE}Disabled fairy soul waypoints") + }.withHelp("Hide fairy soul waypoints") + thenLiteral("off") { redirect(disable) } + val clear = thenLiteralExecute("clear") { + FairySouls.getInstance().markAllAsFound() + // Reply handled by mark all as found + }.withHelp("Mark all fairy souls in your current world as found") + thenLiteral("markfound") { redirect(clear) } + val unclear = thenLiteralExecute("unclear") { + FairySouls.getInstance().markAllAsMissing() + // Reply handled by mark all as missing + }.withHelp("Mark all fairy souls in your current world as not found") + thenLiteral("marknotfound") { redirect(unclear) } + } + } +} diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/misc/MiscCommands.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/misc/MiscCommands.kt new file mode 100644 index 00000000..c86eb4fe --- /dev/null +++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/misc/MiscCommands.kt @@ -0,0 +1,169 @@ +/* + * Copyright (C) 2023 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see . + */ + +package io.github.moulberry.notenoughupdates.commands.misc + +import com.mojang.brigadier.arguments.StringArgumentType.string +import io.github.moulberry.notenoughupdates.NEUManager +import io.github.moulberry.notenoughupdates.NotEnoughUpdates +import io.github.moulberry.notenoughupdates.autosubscribe.NEUAutoSubscribe +import io.github.moulberry.notenoughupdates.cosmetics.GuiCosmetics +import io.github.moulberry.notenoughupdates.events.RegisterBrigadierCommandEvent +import io.github.moulberry.notenoughupdates.miscgui.CalendarOverlay +import io.github.moulberry.notenoughupdates.miscgui.GuiItemCustomize +import io.github.moulberry.notenoughupdates.util.Calculator +import io.github.moulberry.notenoughupdates.util.Calculator.CalculatorException +import io.github.moulberry.notenoughupdates.util.MinecraftExecutor +import io.github.moulberry.notenoughupdates.util.PronounDB +import io.github.moulberry.notenoughupdates.util.Utils +import io.github.moulberry.notenoughupdates.util.brigadier.* +import net.minecraft.client.Minecraft +import net.minecraft.client.renderer.OpenGlHelper +import net.minecraft.util.ChatComponentText +import net.minecraft.util.EnumChatFormatting.* +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import java.text.DecimalFormat +import java.util.* +import java.util.concurrent.CompletableFuture + +@NEUAutoSubscribe +class MiscCommands { + @SubscribeEvent + fun onCommands(event: RegisterBrigadierCommandEvent) { + event.command("neucalc", "neucalculator") { + thenArgumentExecute("calculation", RestArgumentType) { calculation -> + val calculation = this[calculation] + try { + val calculate = Calculator.calculate(calculation) + val formatter = DecimalFormat("#,##0.##") + val formatted = formatter.format(calculate) + reply("$WHITE$calculation $YELLOW= $GREEN$formatted") + } catch (e: CalculatorException) { + reply( + "${RED}Error during calculation: ${e.message}\n${WHITE}${calculation.substring(0, e.offset)}" + + "${DARK_RED}${calculation.substring(e.offset, e.length + e.offset)}${GRAY}" + + calculation.substring(e.length + e.offset) + ) + } + }.withHelp("Calculate an expression") + thenExecute { + reply( + "§5It's a calculator.\n" + + "§eFor Example §b/neucalc 3m*7k§e.\n" + + "§eYou can also use suffixes (k, m, b, t, s)§e.\n" + + "§eThe \"s\" suffix acts as 64.\n" + + "§eTurn on Sign Calculator in /neu misc to also support this in sign popups and the neu search bar." + ) + } + }.withHelp("Display help for NEUs calculator") + event.command("neucalendar") { + thenExecute { + Minecraft.getMinecraft().thePlayer.closeScreen() + CalendarOverlay.setEnabled(true) + NotEnoughUpdates.INSTANCE.sendChatMessage("/calendar") + } + }.withHelp("Display NEUs custom calendar overlay") + event.command("neucosmetics") { + thenExecute { + if (!OpenGlHelper.isFramebufferEnabled() && NotEnoughUpdates.INSTANCE.config.notifications.doFastRenderNotif) { + reply( + "${RED}NEU Cosmetics do not work with OptiFine Fast Render. Go to ESC > Options > Video Settings > Performance > Fast Render to disable it." + ) + } + NotEnoughUpdates.INSTANCE.openGui = GuiCosmetics() + } + }.withHelp("Equip NEU cosmetics") + event.command("neucustomize", "neurename") { + thenExecute { + val held = Minecraft.getMinecraft().thePlayer.heldItem + if (held == null) { + reply("${RED}You can't customize your hand...") + return@thenExecute + } + val heldUUID = NEUManager.getUUIDForItem(held) + if (heldUUID == null) { + reply("${RED}This item does not have an UUID, so it cannot be customized.") + return@thenExecute + } + + NotEnoughUpdates.INSTANCE.openGui = GuiItemCustomize(held, heldUUID) + } + }.withHelp("Customize your items") + event.command("neupronouns", "neuliberals") { + thenArgument("user", string()) {user-> + suggestsList { Minecraft.getMinecraft().theWorld.playerEntities.map { it.name } } + thenArgumentExecute("platform", string()) { platform -> + fetchPronouns(this[platform], this[user]) + }.withHelp("Look up someones pronouns using their username on a platform") + thenExecute { + fetchPronouns("minecraft", this[user]) + } + }.withHelp("Look up someones pronouns using their minecraft username") + } + event.command("neuupdate", "neuupdates", "enoughupdates") { + thenLiteralExecute("check") { + NotEnoughUpdates.INSTANCE.autoUpdater.displayUpdateMessageIfOutOfDate() + }.withHelp("Check for updates") + thenLiteralExecute("scheduledownload") { + NotEnoughUpdates.INSTANCE.autoUpdater.scheduleDownload() + }.withHelp("Queue a new version of NEU to be downloaded") + thenLiteralExecute("updatemodes") { + reply("§bTo ensure we do not accidentally corrupt your mod folder, we can only offer support for auto-updates on system with certain capabilities for file deletions (specifically unix systems). You can still manually update your files") + }.withHelp("Display an explanation why you cannot auto update") + } + } + + fun fetchPronouns(platform: String, user: String) { + val nc = Minecraft.getMinecraft().ingameGUI.chatGUI + val id = Random().nextInt() + nc.printChatMessageWithOptionalDeletion(ChatComponentText("§e[NEU] Fetching Pronouns..."), id) + + val pronouns = if ("minecraft" == platform) { + val c = CompletableFuture() + NotEnoughUpdates.profileViewer.getPlayerUUID(user) { uuidString -> + if (uuidString == null) { + c.completeExceptionally(NullPointerException()) + } else { + c.complete(Utils.parseDashlessUUID(uuidString)) + } + } + c.thenCompose { minecraftPlayer -> + PronounDB.getPronounsFor(minecraftPlayer) + } + } else { + PronounDB.getPronounsFor(platform, user) + } + pronouns.handleAsync({ pronounChoice, throwable -> + if (throwable != null || !pronounChoice.isPresent) { + nc.printChatMessageWithOptionalDeletion(ChatComponentText("§e[NEU] §4Failed to fetch pronouns."), id) + return@handleAsync null + } + val betterPronounChoice = pronounChoice.get() + nc.printChatMessageWithOptionalDeletion( + ChatComponentText("§e[NEU] Pronouns for §b$user §eon §b$platform§e:"), id + ) + betterPronounChoice.render().forEach { + nc.printChatMessage(ChatComponentText("§e[NEU] §a$it")) + } + null + }, MinecraftExecutor.OffThread) + + } + +} diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/misc/PeekCommand.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/misc/PeekCommand.kt new file mode 100644 index 00000000..61fa6029 --- /dev/null +++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/misc/PeekCommand.kt @@ -0,0 +1,318 @@ +/* + * Copyright (C) 2023 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see . + */ + +package io.github.moulberry.notenoughupdates.commands.misc + +import com.mojang.brigadier.arguments.StringArgumentType.string +import io.github.moulberry.notenoughupdates.NotEnoughUpdates +import io.github.moulberry.notenoughupdates.autosubscribe.NEUAutoSubscribe +import io.github.moulberry.notenoughupdates.events.RegisterBrigadierCommandEvent +import io.github.moulberry.notenoughupdates.profileviewer.ProfileViewer +import io.github.moulberry.notenoughupdates.util.Utils +import io.github.moulberry.notenoughupdates.util.brigadier.* +import net.minecraft.client.Minecraft +import net.minecraft.util.ChatComponentText +import net.minecraft.util.EnumChatFormatting.* +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import org.apache.commons.lang3.text.WordUtils +import java.util.* +import java.util.concurrent.* + +@NEUAutoSubscribe +class PeekCommand { + + var future: Future<*>? = null + val executor = Executors.newScheduledThreadPool(1) + + fun executePeek(name: String) { + val chatGui = Minecraft.getMinecraft().ingameGUI.chatGUI + val id = Random().nextInt(Int.MAX_VALUE / 2) + Int.MAX_VALUE / 2 + fun deleteReply(text: String) { + chatGui.printChatMessageWithOptionalDeletion(ChatComponentText(text), id) + } + + deleteReply("$YELLOW[PEEK] Getting player information...") + + + NotEnoughUpdates.profileViewer.getProfileByName( + name + ) { profile: ProfileViewer.Profile? -> + if (profile == null) { + deleteReply("$RED[PEEK] Unknown player or the Hypixel API is down.") + } else { + profile.resetCache() + if (future?.isDone != true) { + Utils.addChatMessage( + "$RED[PEEK] New peek command was run, cancelling old one." + ) + future?.cancel(true) + } + deleteReply("$YELLOW[PEEK] Getting the player's SkyBlock profile(s)...") + val startTime = System.currentTimeMillis() + future = ForkJoinPool.commonPool().submit(object : Runnable { + override fun run() { + if (System.currentTimeMillis() - startTime > 10 * 1000) { + deleteReply("$RED[PEEK] Getting profile info took too long, aborting.") + return + } + val g = GRAY.toString() + val profileInfo = profile.getProfileInformation(null) + if (profileInfo == null) { + future = executor.schedule(this, 200, TimeUnit.MILLISECONDS) + return + } + var overallScore = 0f + val isMe = name.equals("moulberry", ignoreCase = true) + val stats = profile.getStats(null) + if (stats == null) { + future = executor.schedule(this, 200, TimeUnit.MILLISECONDS) + return + } + val skyblockInfo = profile.getSkyblockInfo(null) + if (NotEnoughUpdates.INSTANCE.config.profileViewer.useSoopyNetworth) { + deleteReply("$YELLOW[PEEK] Getting the player's Skyblock networth...") + val countDownLatch = CountDownLatch(1) + profile.getSoopyNetworth(null, Runnable { countDownLatch.countDown() }) + try { //Wait for async network request + countDownLatch.await(10, TimeUnit.SECONDS) + } catch (e: InterruptedException) { + } + + //Now it's waited for network request the data should be cached (accessed in nw section) + } + deleteReply( + "$GREEN $STRIKETHROUGH-=-$RESET$GREEN ${ + Utils.getElementAsString( + profile.hypixelProfile!!["displayname"], + name + ) + }'s Info $STRIKETHROUGH-=-" + ) + if (skyblockInfo == null) { + Utils.addChatMessage(YELLOW.toString() + "Skills API disabled!") + } else { + var totalSkillLVL = 0f + var totalSkillCount = 0f + val skills: List = + mutableListOf( + "taming", + "mining", + "foraging", + "enchanting", + "farming", + "combat", + "fishing", + "alchemy", + "carpentry" + ) + for (skillName in skills) { + totalSkillLVL += skyblockInfo[skillName]!!.level + totalSkillCount++ + } + var combat = skyblockInfo["combat"]!!.level + var zombie = skyblockInfo["zombie"]!!.level + var spider = skyblockInfo["spider"]!!.level + var wolf = skyblockInfo["wolf"]!!.level + var enderman = skyblockInfo["enderman"]!!.level + var blaze = skyblockInfo["blaze"]!!.level + var avgSkillLVL = totalSkillLVL / totalSkillCount + if (isMe) { + avgSkillLVL = 6f + combat = 4f + zombie = 2f + spider = 1f + wolf = 2f + enderman = 0f + blaze = 0f + } + val combatPrefix = + if (combat > 20) (if (combat > 35) GREEN else YELLOW) else RED + val zombiePrefix = + if (zombie > 3) (if (zombie > 6) GREEN else YELLOW) else RED + val spiderPrefix = + if (spider > 3) (if (spider > 6) GREEN else YELLOW) else RED + val wolfPrefix = + if (wolf > 3) (if (wolf > 6) GREEN else YELLOW) else RED + val endermanPrefix = + if (enderman > 3) (if (enderman > 6) GREEN else YELLOW) else RED + val blazePrefix = + if (blaze > 3) (if (blaze > 6) GREEN else YELLOW) else RED + val avgPrefix = + if (avgSkillLVL > 20) (if (avgSkillLVL > 35) GREEN else YELLOW) else RED + overallScore += zombie * zombie / 81f + overallScore += spider * spider / 81f + overallScore += wolf * wolf / 81f + overallScore += enderman * enderman / 81f + overallScore += blaze * blaze / 81f + overallScore += avgSkillLVL / 20f + val cata = skyblockInfo["catacombs"]!!.level.toInt() + val cataPrefix = + if (cata > 15) (if (cata > 25) GREEN else YELLOW) else RED + overallScore += cata * cata / 2000f + Utils.addChatMessage( + g + "Combat: " + combatPrefix + Math.floor(combat.toDouble()) + .toInt() + + (if (cata > 0) "$g - Cata: $cataPrefix$cata" else "") + + g + " - AVG: " + avgPrefix + Math.floor(avgSkillLVL.toDouble()) + .toInt() + ) + Utils.addChatMessage( + g + "Slayer: " + zombiePrefix + Math.floor(zombie.toDouble()) + .toInt() + g + "-" + + spiderPrefix + Math.floor(spider.toDouble()) + .toInt() + g + "-" + + wolfPrefix + Math.floor(wolf.toDouble()).toInt() + g + "-" + + endermanPrefix + Math.floor(enderman.toDouble()) + .toInt() + g + "-" + + blazePrefix + Math.floor(blaze.toDouble()).toInt() + ) + } + val health = stats["health"].toInt() + val defence = stats["defence"].toInt() + val strength = stats["strength"].toInt() + val intelligence = stats["intelligence"].toInt() + val healthPrefix = + if (health > 800) (if (health > 1600) GREEN else YELLOW) else RED + val defencePrefix = + if (defence > 200) (if (defence > 600) GREEN else YELLOW) else RED + val strengthPrefix = + if (strength > 100) (if (strength > 300) GREEN else YELLOW) else RED + val intelligencePrefix = + if (intelligence > 300) (if (intelligence > 900) GREEN else YELLOW) else RED + Utils.addChatMessage( + g + "Stats : " + healthPrefix + health + RED + "\u2764 " + + defencePrefix + defence + GREEN + "\u2748 " + + strengthPrefix + strength + RED + "\u2741 " + + intelligencePrefix + intelligence + AQUA + "\u270e " + ) + val bankBalance = + Utils.getElementAsFloat( + Utils.getElement( + profileInfo, + "banking.balance" + ), -1f + ) + val purseBalance = + Utils.getElementAsFloat( + Utils.getElement( + profileInfo, + "coin_purse" + ), 0f + ) + val networth = if (NotEnoughUpdates.INSTANCE.config.profileViewer.useSoopyNetworth) { + val nwData = + profile.getSoopyNetworth(null, Runnable {}) + nwData?.total ?: -2L + } else { + profile.getNetWorth(null) + } + val money = + Math.max(bankBalance + purseBalance, networth.toFloat()) + val moneyPrefix = + if (money > 50 * 1000 * 1000) (if (money > 200 * 1000 * 1000) GREEN else YELLOW) else RED + Utils.addChatMessage( + g + "Purse: " + moneyPrefix + Utils.shortNumberFormat( + purseBalance.toDouble(), + 0 + ) + g + " - Bank: " + + (if (bankBalance == -1f) YELLOW.toString() + "N/A" else moneyPrefix.toString() + + if (isMe) "4.8b" else Utils.shortNumberFormat( + bankBalance.toDouble(), + 0 + )) + + if (networth > 0) "$g - Net: $moneyPrefix" + Utils.shortNumberFormat( + networth.toDouble(), + 0 + ) else "" + ) + overallScore += Math.min(2f, money / (100f * 1000 * 1000)) + val activePet = + Utils.getElementAsString( + Utils.getElement( + profile.getPetsInfo( + null + ), "active_pet.type" + ), + "None Active" + ) + val activePetTier = + Utils.getElementAsString( + Utils.getElement( + profile.getPetsInfo(null), + "active_pet.tier" + ), "UNKNOWN" + ) + var col = NotEnoughUpdates.petRarityToColourMap[activePetTier] + if (col == null) col = LIGHT_PURPLE.toString() + Utils.addChatMessage( + g + "Pet : " + col + WordUtils.capitalizeFully( + activePet.replace("_", " ") + ) + ) + var overall = "Skywars Main" + if (isMe) { + overall = + Utils.chromaString("Literally the best player to exist") // ego much + } else if (overallScore < 5 && bankBalance + purseBalance > 500 * 1000 * 1000) { + overall = GOLD.toString() + "Bill Gates" + } else if (overallScore > 9) { + overall = + Utils.chromaString("Didn't even think this score was possible") + } else if (overallScore > 8) { + overall = + Utils.chromaString("Mentally unstable") + } else if (overallScore > 7) { + overall = GOLD.toString() + "Why though 0.0" + } else if (overallScore > 5.5) { + overall = GOLD.toString() + "Bro stop playing" + } else if (overallScore > 4) { + overall = GREEN.toString() + "Kinda sweaty" + } else if (overallScore > 3) { + overall = YELLOW.toString() + "Alright I guess" + } else if (overallScore > 2) { + overall = YELLOW.toString() + "Ender Non" + } else if (overallScore > 1) { + overall = RED.toString() + "Played SkyBlock" + } + Utils.addChatMessage( + g + "Overall score: " + overall + g + " (" + Math.round( + overallScore * 10 + ) / 10f + ")" + ) + } + }) + } + } + } + + @SubscribeEvent + fun onCommand(event: RegisterBrigadierCommandEvent) { + event.command("peek") { + thenArgument("player", string()) { player -> + suggestsList { Minecraft.getMinecraft().theWorld.playerEntities.map { it.name } } + thenExecute { + executePeek(this[player]) + } + }.withHelp("Quickly glance at other peoples stats") + thenExecute { + executePeek(Minecraft.getMinecraft().thePlayer.name) + } + }.withHelp("Quickly glance at your own stats") + } +} diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/misc/ProfileViewerCommands.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/misc/ProfileViewerCommands.kt new file mode 100644 index 00000000..8a2763f7 --- /dev/null +++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/misc/ProfileViewerCommands.kt @@ -0,0 +1,87 @@ +/* + * Copyright (C) 2023 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see . + */ + +package io.github.moulberry.notenoughupdates.commands.misc + +import com.mojang.brigadier.arguments.StringArgumentType.string +import com.mojang.brigadier.context.CommandContext +import io.github.moulberry.notenoughupdates.NotEnoughUpdates +import io.github.moulberry.notenoughupdates.autosubscribe.NEUAutoSubscribe +import io.github.moulberry.notenoughupdates.events.RegisterBrigadierCommandEvent +import io.github.moulberry.notenoughupdates.profileviewer.GuiProfileViewer +import io.github.moulberry.notenoughupdates.util.brigadier.* +import net.minecraft.client.Minecraft +import net.minecraft.client.renderer.OpenGlHelper +import net.minecraft.command.ICommandSender +import net.minecraft.util.EnumChatFormatting.RED +import net.minecraftforge.fml.common.Loader +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +@NEUAutoSubscribe +class ProfileViewerCommands { + companion object { + fun CommandContext.openPv(name: String) { + if (!OpenGlHelper.isFramebufferEnabled()) { + reply("${RED}Some parts of the profile viewer do not work with OptiFine Fast Render. Go to ESC > Options > Video Settings > Performance > Fast Render to disable it.") + } + + if (NotEnoughUpdates.INSTANCE.config.apiData.apiKey.isNullOrBlank()) { + reply("${RED}Can't view profile, an API key is not set. Run /api new and put the result in settings.") + return + } + + NotEnoughUpdates.profileViewer.getProfileByName(name) { profile -> + if (profile == null) { + reply("${RED}Invalid player name/API key. Maybe the API is down? Try /api new.") + } else { + profile.resetCache() + NotEnoughUpdates.INSTANCE.openGui = GuiProfileViewer(profile) + } + } + } + } + + + @SubscribeEvent + fun onCommand(event: RegisterBrigadierCommandEvent) { + fun pvCommand(name: String, before: () -> Unit) { + event.command(name) { + thenExecute { + before() + openPv(Minecraft.getMinecraft().thePlayer.name) + } + thenArgument("player", string()) { player -> + suggestsList { Minecraft.getMinecraft().theWorld.playerEntities.map { it.name } } + thenExecute { + before() + openPv(this[player]) + } + }.withHelp("Open the profile viewer for a player") + }.withHelp("Open the profile viewer for yourself") + } + pvCommand("pv") {} + pvCommand("neuprofile") {} + if (!Loader.isModLoaded("skyblockextras")) + pvCommand("cata") { + GuiProfileViewer.currentPage = GuiProfileViewer.ProfileViewerPage.DUNGEON + } + + + } +} diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/misc/ScreenOpenCommands.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/misc/ScreenOpenCommands.kt new file mode 100644 index 00000000..7a9b8d0e --- /dev/null +++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/misc/ScreenOpenCommands.kt @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2023 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see . + */ + +package io.github.moulberry.notenoughupdates.commands.misc + +import io.github.moulberry.notenoughupdates.NotEnoughUpdates +import io.github.moulberry.notenoughupdates.autosubscribe.NEUAutoSubscribe +import io.github.moulberry.notenoughupdates.events.RegisterBrigadierCommandEvent +import io.github.moulberry.notenoughupdates.miscgui.GuiEnchantColour +import io.github.moulberry.notenoughupdates.miscgui.GuiInvButtonEditor +import io.github.moulberry.notenoughupdates.miscgui.NEUOverlayPlacements +import io.github.moulberry.notenoughupdates.util.brigadier.thenExecute +import io.github.moulberry.notenoughupdates.util.brigadier.withHelp +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +@NEUAutoSubscribe +class ScreenOpenCommands { + @SubscribeEvent + fun onCommands(event: RegisterBrigadierCommandEvent) { + event.command("neubuttons") { + thenExecute { + NotEnoughUpdates.INSTANCE.openGui = GuiInvButtonEditor() + } + }.withHelp("Open the NEU inventory button editor") + event.command("neuec") { + thenExecute { + NotEnoughUpdates.INSTANCE.openGui = GuiEnchantColour() + } + }.withHelp("Open the NEU custom enchant colour editor") + event.command("neuoverlay") { + thenExecute { + NotEnoughUpdates.INSTANCE.openGui = NEUOverlayPlacements() + } + }.withHelp("Open the NEU gui overlay editor") + } +} diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/events/RegisterBrigadierCommandEvent.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/events/RegisterBrigadierCommandEvent.kt new file mode 100644 index 00000000..d3e0b69a --- /dev/null +++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/events/RegisterBrigadierCommandEvent.kt @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2023 Linnea Gräf + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see . + */ + +package io.github.moulberry.notenoughupdates.events + +import com.mojang.brigadier.builder.LiteralArgumentBuilder +import io.github.moulberry.notenoughupdates.util.brigadier.BrigadierRoot +import io.github.moulberry.notenoughupdates.util.brigadier.NEUBrigadierHook +import io.github.moulberry.notenoughupdates.util.brigadier.literal +import net.minecraft.command.ICommandSender +import java.util.function.Consumer + +data class RegisterBrigadierCommandEvent(val brigadierRoot: BrigadierRoot) : NEUEvent() { + val dispatcher = brigadierRoot.dispatcher + val hooks = mutableListOf() + fun command(name: String, block: Consumer>): NEUBrigadierHook { + return command(name) { + block.accept(this) + } + } + + fun command( + name: String, + vararg aliases: String, + block: LiteralArgumentBuilder.() -> Unit + ): NEUBrigadierHook { + val node = dispatcher.register(literal(name, block)) + for (alias in aliases) { + dispatcher.register(literal(alias) { redirect(node) }) + } + val hook = NEUBrigadierHook(brigadierRoot, node, aliases.toList()) + hooks.add(hook) + return hook + } + +} diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/util/brigadier/BrigadierRoot.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/util/brigadier/BrigadierRoot.kt new file mode 100644 index 00000000..66008044 --- /dev/null +++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/util/brigadier/BrigadierRoot.kt @@ -0,0 +1,103 @@ +/* + * Copyright (C) 2023 Linnea Gräf + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see . + */ + +package io.github.moulberry.notenoughupdates.util.brigadier + +import com.mojang.brigadier.CommandDispatcher +import com.mojang.brigadier.ParseResults +import com.mojang.brigadier.tree.ArgumentCommandNode +import com.mojang.brigadier.tree.CommandNode +import io.github.moulberry.notenoughupdates.autosubscribe.NEUAutoSubscribe +import io.github.moulberry.notenoughupdates.events.RegisterBrigadierCommandEvent +import io.github.moulberry.notenoughupdates.util.LRUCache +import net.minecraft.command.ICommandSender +import net.minecraftforge.client.ClientCommandHandler +import java.lang.RuntimeException +import java.util.* + +@NEUAutoSubscribe +object BrigadierRoot { + private val help: MutableMap, String> = IdentityHashMap() + var dispatcher = CommandDispatcher() + private set + val parseText = + LRUCache.memoize, ParseResults>({ (sender, text) -> + dispatcher.parse(text, sender) + }, 1) + + fun getHelpForNode(node: CommandNode): String? { + return help[node] + } + + fun setHelpForNode(node: CommandNode, helpText: String) { + if (node.command == null) { + RuntimeException("Warning: Setting help on node that cannot be executed. Will be ignored").printStackTrace() + } + help[node] = helpText + } + + + fun getAllUsages( + path: String, + node: CommandNode, + visited: MutableSet> = mutableSetOf() + ): Sequence = sequence { + if (node in visited) return@sequence + visited.add(node) + val redirect = node.redirect + if (redirect != null) { + yieldAll(getAllUsages(path, node.redirect, visited)) + visited.remove(node) + return@sequence + } + if (node.command != null) + yield(NEUBrigadierHook.Usage(path, getHelpForNode(node))) + node.children.forEach { + val nodeName = when (it) { + is ArgumentCommandNode<*, *> -> "<${it.name}>" + else -> it.name + } + yieldAll(getAllUsages("$path $nodeName", it, visited)) + } + visited.remove(node) + } + + + fun updateHooks() = registerHooks(ClientCommandHandler.instance) + + fun registerHooks(handler: ClientCommandHandler) { + val iterator = handler.commands.entries.iterator() + while (iterator.hasNext()) { + if (iterator.next().value is NEUBrigadierHook) + iterator.remove() + } + dispatcher = CommandDispatcher() + help.clear() + parseText.clearCache() + val event = RegisterBrigadierCommandEvent(this) + event.post() + event.hooks.forEach { + if (handler.commands.containsKey(it.commandName)) { + println("Could not register command ${it.commandName}") + } else { + handler.registerCommand(it) + } + } + } +} diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/util/brigadier/EnumArgumentType.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/util/brigadier/EnumArgumentType.kt new file mode 100644 index 00000000..14b6ed6e --- /dev/null +++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/util/brigadier/EnumArgumentType.kt @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2023 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see . + */ + +package io.github.moulberry.notenoughupdates.util.brigadier + +import com.mojang.brigadier.LiteralMessage +import com.mojang.brigadier.StringReader +import com.mojang.brigadier.arguments.ArgumentType +import com.mojang.brigadier.context.CommandContext +import com.mojang.brigadier.exceptions.SimpleCommandExceptionType +import com.mojang.brigadier.suggestion.Suggestions +import com.mojang.brigadier.suggestion.SuggestionsBuilder +import java.util.concurrent.CompletableFuture + +class EnumArgumentType>( + val values: List +) : ArgumentType { + companion object { + @JvmStatic + fun > enum(values: Array) = EnumArgumentType(values.toList()) + + inline fun > enum() = enum(enumValues()) + } + + override fun getExamples(): Collection { + return values.map { it.name } + } + + override fun listSuggestions( + context: CommandContext, + builder: SuggestionsBuilder + ): CompletableFuture { + + examples + .filter {builder.remaining.isBlank() || it.startsWith(builder.remaining, ignoreCase = true) } + .forEach { builder.suggest(it) } + return builder.buildFuture() + } + + private val invalidEnum = + SimpleCommandExceptionType(LiteralMessage("Expected one of: ${values.joinToString(", ")}")) + + override fun parse(reader: StringReader): T { + val enumName = reader.readString() + return values.find { enumName == it.name } + ?: throw invalidEnum.createWithContext(reader) + } +} diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/util/brigadier/RestArgumentType.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/util/brigadier/RestArgumentType.kt new file mode 100644 index 00000000..adfdae6a --- /dev/null +++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/util/brigadier/RestArgumentType.kt @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2023 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see . + */ + +package io.github.moulberry.notenoughupdates.util.brigadier + +import com.mojang.brigadier.StringReader +import com.mojang.brigadier.arguments.ArgumentType + +object RestArgumentType : ArgumentType { + override fun parse(reader: StringReader): String { + val remaining = reader.remaining + reader.cursor += remaining.length + return remaining + } +} diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/util/brigadier/dsl.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/util/brigadier/dsl.kt new file mode 100644 index 00000000..17203a4b --- /dev/null +++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/util/brigadier/dsl.kt @@ -0,0 +1,179 @@ +/* + * Copyright (C) 2023 Linnea Gräf + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see . + */ + +package io.github.moulberry.notenoughupdates.util.brigadier + +import com.mojang.brigadier.arguments.ArgumentType +import com.mojang.brigadier.builder.ArgumentBuilder +import com.mojang.brigadier.builder.LiteralArgumentBuilder +import com.mojang.brigadier.builder.RequiredArgumentBuilder +import com.mojang.brigadier.context.CommandContext +import com.mojang.brigadier.tree.ArgumentCommandNode +import com.mojang.brigadier.tree.CommandNode +import com.mojang.brigadier.tree.LiteralCommandNode +import io.github.moulberry.notenoughupdates.commands.dev.DevTestCommand +import io.github.moulberry.notenoughupdates.util.iterate +import net.minecraft.command.ICommandSender +import net.minecraft.util.ChatComponentText +import net.minecraft.util.IChatComponent +import java.lang.reflect.ParameterizedType +import java.lang.reflect.Type +import java.lang.reflect.TypeVariable + + +typealias DefaultSource = ICommandSender + + + +private fun normalizeGeneric(argument: Type): Class<*> { + return if (argument is Class<*>) { + argument + } else if (argument is TypeVariable<*>) { + normalizeGeneric(argument.bounds[0]) + } else if (argument is ParameterizedType) { + normalizeGeneric(argument.rawType) + } else { + Any::class.java + } +} + +data class TypeSafeArg(val name: String, val argument: ArgumentType) { + val argClass by lazy { + argument.javaClass + .iterate>> { + it.superclass + } + .flatMap { + it.genericInterfaces.toList() + } + .filterIsInstance() + .find { it.rawType == ArgumentType::class.java }!! + .let { + normalizeGeneric(it.actualTypeArguments[0]) + } + } + + @JvmName("getWithThis") + fun CommandContext.get(): T = + get(this) + + + fun get(ctx: CommandContext): T { + return ctx.getArgument(name, argClass) as T + } +} + +fun > C.reply(component: IChatComponent) { + source.addChatMessage(ChatComponentText("§e[NEU] ").appendSibling(component)) +} + +fun > C.reply(text: String, block: ChatComponentText.() -> Unit = {}) { + source.addChatMessage(ChatComponentText(text.split("\n").joinToString("\n") { "§e[NEU] $it" }).also(block)) +} + +operator fun > C.get(arg: TypeSafeArg): T { + return arg.get(this) +} + + +fun argument( + name: String, + argument: ArgumentType, + block: RequiredArgumentBuilder.(TypeSafeArg) -> Unit +): RequiredArgumentBuilder = + RequiredArgumentBuilder.argument(name, argument).also { block(it, TypeSafeArg(name, argument)) } + +fun , AT : Any> T.thenArgument( + name: String, + argument: ArgumentType, + block: RequiredArgumentBuilder.(TypeSafeArg) -> Unit +): ArgumentCommandNode = argument(name, argument, block).build().also(::then) + +fun , AT : Any> T.thenArgumentExecute( + name: String, + argument: ArgumentType, + block: CommandContext.(TypeSafeArg) -> Unit +): ArgumentCommandNode = thenArgument(name, argument) { + thenExecute { + block(it) + } +} + +fun literal( + name: String, + block: LiteralArgumentBuilder.() -> Unit = {} +): LiteralArgumentBuilder = + LiteralArgumentBuilder.literal(name).also(block) + +fun > T.thenLiteral( + name: String, + block: LiteralArgumentBuilder.() -> Unit +): LiteralCommandNode = + then(literal(name), block) as LiteralCommandNode + + +fun > T.thenLiteralExecute( + name: String, + block: CommandContext.() -> Unit +): LiteralCommandNode = + thenLiteral(name) { + thenExecute(block) + } + +fun , U : ArgumentBuilder> T.then( + node: U, + block: U.() -> Unit +): CommandNode = + node.also(block).build().also(::then) + +fun > T.thenExecute(block: CommandContext.() -> Unit): T = + executes { + block(it) + 1 + } + +fun > T.requiresDev(): T { + requires { DevTestCommand.isDeveloper(it) } + return this +} + +fun NEUBrigadierHook.withHelp(helpText: String): NEUBrigadierHook { + commandNode.withHelp(helpText) + return this +} + +fun > T.withHelp(helpText: String): T { + BrigadierRoot.setHelpForNode(this, helpText) + return this +} + +fun > T.suggestsList(list: List) { + suggestsList { list } +} + +fun > T.suggestsList(list: () -> List) { + suggests { context, builder -> + list().filter { it.startsWith(builder.remaining, ignoreCase = true) } + .forEach { builder.suggest(it) } + builder.buildFuture() + } +} + + + diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/util/iterate.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/util/iterate.kt new file mode 100644 index 00000000..bcfe11aa --- /dev/null +++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/util/iterate.kt @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2023 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see . + */ + +package io.github.moulberry.notenoughupdates.util + +fun T.iterate(evolve: (T) -> T?): Sequence = sequence { + var pointer: T? = this@iterate + while (pointer != null) { + yield(pointer) + pointer = evolve(pointer) + } +} diff --git a/src/main/resources/mixins.notenoughupdates.json b/src/main/resources/mixins.notenoughupdates.json index 8877aed8..8a8b10bc 100644 --- a/src/main/resources/mixins.notenoughupdates.json +++ b/src/main/resources/mixins.notenoughupdates.json @@ -5,6 +5,7 @@ "plugin": "io.github.moulberry.notenoughupdates.envcheck.NEUMixinConfigPlugin", "compatibilityLevel": "JAVA_8", "mixins": [ + "AccessorCommandHandler", "AccessorEntityAgeable", "AccessorEntityArmorStand", "AccessorGuiPlayerTabOverlay", -- cgit From 5a79ff410eb64e906c555751b32bef87cc7caee9 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal002@users.noreply.github.com> Date: Sat, 4 Mar 2023 03:03:33 +0100 Subject: I hate FontRenderer. (#612) Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> --- .../moulberry/notenoughupdates/NEUOverlay.java | 10 +- .../notenoughupdates/auction/CustomAH.java | 75 +- .../notenoughupdates/core/GuiElementColour.java | 3 - .../notenoughupdates/core/GuiElementTextField.java | 5 +- .../core/config/gui/GuiOptionEditor.java | 5 +- .../core/config/gui/GuiOptionEditorAccordion.java | 5 +- .../core/config/gui/GuiOptionEditorButton.java | 6 +- .../config/gui/GuiOptionEditorDraggableList.java | 13 +- .../core/config/gui/GuiOptionEditorDropdown.java | 33 +- .../core/config/gui/GuiOptionEditorFSR.java | 6 +- .../core/config/gui/GuiOptionEditorKeybind.java | 6 +- .../core/config/gui/GuiPositionEditor.java | 7 +- .../gui/GuiPositionEditorButForTheDungeonMap.java | 10 +- .../core/config/struct/GuiOptionEditorBlocked.java | 1 - .../core/util/ArrowPagesUtils.java | 6 +- .../core/util/render/TextRenderUtils.java | 42 +- .../notenoughupdates/cosmetics/GuiCosmetics.java | 19 +- .../notenoughupdates/dungeons/DungeonWin.java | 5 +- .../dungeons/GuiDungeonMapEditor.java | 76 +- .../infopanes/FlipperInfoPane.java | 3 +- .../notenoughupdates/infopanes/TextInfoPane.java | 2 +- .../itemeditor/GuiElementTextField.java | 35 +- .../notenoughupdates/itemeditor/NEUItemEditor.java | 4 +- .../notenoughupdates/listener/RenderListener.java | 4 +- .../miscfeatures/AbiphoneWarning.java | 31 +- .../miscfeatures/AuctionBINWarning.java | 49 +- .../miscfeatures/AuctionSortModeWarning.java | 4 +- .../miscfeatures/DungeonNpcProfitOverlay.java | 10 +- .../miscfeatures/EnchantingSolvers.java | 2 +- .../miscfeatures/FishingHelper.java | 6 +- .../notenoughupdates/miscfeatures/MiningStuff.java | 7 +- .../notenoughupdates/miscfeatures/SunTzu.java | 1 - .../miscfeatures/entityviewer/EntityViewer.java | 4 +- .../miscgui/AccessoryBagOverlay.java | 264 ++----- .../notenoughupdates/miscgui/CalendarOverlay.java | 16 +- .../notenoughupdates/miscgui/GuiCustomEnchant.java | 325 ++------ .../notenoughupdates/miscgui/GuiEnchantColour.java | 16 +- .../miscgui/GuiInvButtonEditor.java | 6 - .../notenoughupdates/miscgui/GuiItemCustomize.java | 2 +- .../notenoughupdates/miscgui/GuiItemRecipe.java | 12 +- .../notenoughupdates/miscgui/GuiNavigation.java | 1 - .../notenoughupdates/miscgui/GuiPriceGraph.java | 19 +- .../miscgui/InventoryStorageSelector.java | 25 +- .../notenoughupdates/miscgui/KatSitterOverlay.java | 3 +- .../miscgui/NEUOverlayPlacements.java | 12 +- .../notenoughupdates/miscgui/SignCalculator.java | 11 +- .../notenoughupdates/miscgui/StorageOverlay.java | 46 +- .../notenoughupdates/miscgui/TradeWindow.java | 65 +- .../notenoughupdates/miscgui/hex/GuiCustomHex.java | 878 +++++---------------- .../render/MinionHelperOverlayHover.java | 13 +- .../notenoughupdates/options/NEUConfigEditor.java | 26 +- .../overlays/AuctionSearchOverlay.java | 10 +- .../overlays/BazaarSearchOverlay.java | 10 +- .../overlays/EquipmentOverlay.java | 35 +- .../overlays/RancherBootOverlay.java | 9 +- .../notenoughupdates/profileviewer/BasicPage.java | 41 +- .../notenoughupdates/profileviewer/BingoPage.java | 30 +- .../profileviewer/CollectionsPage.java | 58 +- .../profileviewer/CrimsonIslePage.java | 36 +- .../profileviewer/GuiProfileViewer.java | 96 +-- .../profileviewer/InventoriesPage.java | 15 +- .../notenoughupdates/profileviewer/MiningPage.java | 20 +- .../notenoughupdates/profileviewer/PetsPage.java | 9 +- .../profileviewer/bestiary/BestiaryPage.java | 10 +- .../profileviewer/trophy/TrophyFishPage.java | 55 +- .../notenoughupdates/recipes/CraftingOverlay.java | 3 +- .../notenoughupdates/recipes/CraftingRecipe.java | 6 +- .../notenoughupdates/recipes/EssenceUpgrades.java | 9 +- .../notenoughupdates/recipes/ForgeRecipe.java | 9 +- .../notenoughupdates/recipes/MobLootRecipe.java | 11 +- .../recipes/VillagerTradeRecipe.java | 6 +- .../notenoughupdates/util/NotificationHandler.java | 23 +- .../moulberry/notenoughupdates/util/Utils.java | 179 ++++- .../notenoughupdates/recipes/KatRecipe.kt | 1 - 74 files changed, 756 insertions(+), 2160 deletions(-) (limited to 'src/main/kotlin') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java index 927b5e76..ce7b21b2 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java @@ -1665,7 +1665,7 @@ public class NEUOverlay extends Gui { buttonXSize, ySize, 1 - leftPressed, leftPressed, 1 - leftPressed, leftPressed ); GlStateManager.bindTexture(0); - Utils.drawStringCenteredScaled(EnumChatFormatting.BOLD + "Prev", fr, + Utils.drawStringCenteredScaled(EnumChatFormatting.BOLD + "Prev", leftSide - 1 + buttonXSize * 300 / 480f + leftPressed, top + ySize / 2f + leftPressed, false, (int) (buttonXSize * 240 / 480f), Color.BLACK.getRGB() @@ -1684,7 +1684,7 @@ public class NEUOverlay extends Gui { buttonXSize, ySize, 1 - rightPressed, rightPressed, 1 - rightPressed, rightPressed ); GlStateManager.bindTexture(0); - Utils.drawStringCenteredScaled(EnumChatFormatting.BOLD + "Next", fr, + Utils.drawStringCenteredScaled(EnumChatFormatting.BOLD + "Next", rightSide + 1 - buttonXSize * 300 / 480f + rightPressed, top + ySize / 2f + rightPressed, false, (int) (buttonXSize * 240 / 480f), Color.BLACK.getRGB() @@ -1699,7 +1699,7 @@ public class NEUOverlay extends Gui { new Color(50, 50, 50).getRGB() ); drawRect(leftSide + buttonXSize + 3, top + 1, rightSide - buttonXSize - 3, top + ySize - 1, fg.getRGB()); - Utils.drawStringCenteredScaledMaxWidth(pageText, fr, (leftSide + rightSide) / 2, + Utils.drawStringCenteredScaledMaxWidth(pageText, (leftSide + rightSide) / 2, top + ySize / 2f, false, strMaxLen, Color.BLACK.getRGB() ); } @@ -1845,8 +1845,6 @@ public class NEUOverlay extends Gui { } GlStateManager.enableDepth(); - FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; - Utils.resetGuiScale(); Utils.pushGuiScale(NotEnoughUpdates.INSTANCE.config.itemlist.paneGuiScale); @@ -2238,7 +2236,7 @@ public class NEUOverlay extends Gui { textToDisplay = text; } if (textToDisplay != null) { - Utils.drawHoveringText(textToDisplay, mouseX, mouseY, width, height, -1, fr); + Utils.drawHoveringText(textToDisplay, mouseX, mouseY, width, height, -1); textToDisplay = null; } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/auction/CustomAH.java b/src/main/java/io/github/moulberry/notenoughupdates/auction/CustomAH.java index 07ec4a59..e1ccdef7 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/auction/CustomAH.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/auction/CustomAH.java @@ -580,6 +580,7 @@ public class CustomAH extends Gui { } List tooltipToRender = null; + int black = Color.BLACK.getRGB(); if (Minecraft.getMinecraft().currentScreen instanceof GuiChest) { resetCurrAucIdTimer = System.currentTimeMillis(); GuiChest auctionView = (GuiChest) Minecraft.getMinecraft().currentScreen; @@ -620,9 +621,7 @@ public class CustomAH extends Gui { endsInStr = EnumChatFormatting.DARK_PURPLE + prettyTime( auctionViewEndsIn + lastGuiScreenSwitch - System.currentTimeMillis()); } - Utils.drawStringCenteredScaledMaxWidth(endsInStr, Minecraft.getMinecraft().fontRendererObj, - auctionViewLeft + 39, guiTop + 20, false, 70, 4210752 - ); + Utils.drawStringCenteredScaledMaxWidth(endsInStr, auctionViewLeft + 39, guiTop + 20, false, 70, 4210752); } Utils.drawItemStack(leftStack, auctionViewLeft + 31, guiTop + 100); @@ -790,9 +789,7 @@ public class CustomAH extends Gui { } } - Utils.drawStringCenteredScaledMaxWidth(containerName, Minecraft.getMinecraft().fontRendererObj, - auctionViewLeft + 39, guiTop + 10, false, 70, 4210752 - ); + Utils.drawStringCenteredScaledMaxWidth(containerName, auctionViewLeft + 39, guiTop + 10, false, 70, 4210752); } else if (isEditingPrice()) { hasPopup = true; resetCurrAucIdTimer = System.currentTimeMillis(); @@ -810,9 +807,7 @@ public class CustomAH extends Gui { this.drawTexturedModalRect(auctionViewLeft, guiTop, 0, 0, 96, 99); priceField.drawTextBox(); - Utils.drawStringCenteredScaledMaxWidth("Bid Amount", Minecraft.getMinecraft().fontRendererObj, - auctionViewLeft + 39, guiTop + 10, false, 70, 4210752 - ); + Utils.drawStringCenteredScaledMaxWidth("Bid Amount", auctionViewLeft + 39, guiTop + 10, false, 70, 4210752); GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); Minecraft.getMinecraft().getTextureManager().bindTexture(auction_view_buttons); @@ -822,22 +817,11 @@ public class CustomAH extends Gui { this.drawTexturedModalRect(auctionViewLeft + 16 + 34, guiTop + 50, 0, 16, 30, 16); this.drawTexturedModalRect(auctionViewLeft + 16, guiTop + 68, 0, 32, 64, 16); - FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; - Utils.drawStringCentered("x2", fr, auctionViewLeft + 16 + 15, guiTop + 32 + 8, false, - Color.BLACK.getRGB() - ); - Utils.drawStringCentered("+50%", fr, auctionViewLeft + 16 + 34 + 15, guiTop + 32 + 8, false, - Color.BLACK.getRGB() - ); - Utils.drawStringCentered("+25%", fr, auctionViewLeft + 16 + 15, guiTop + 50 + 8, false, - Color.BLACK.getRGB() - ); - Utils.drawStringCentered("+10%", fr, auctionViewLeft + 16 + 34 + 15, guiTop + 50 + 8, false, - Color.BLACK.getRGB() - ); - Utils.drawStringCentered("Set Amount", fr, auctionViewLeft + 16 + 32, guiTop + 68 + 8, false, - Color.BLACK.getRGB() - ); + Utils.drawStringCentered("x2", auctionViewLeft + 16 + 15, guiTop + 32 + 8, false, black); + Utils.drawStringCentered("+50%", auctionViewLeft + 16 + 34 + 15, guiTop + 32 + 8, false, black); + Utils.drawStringCentered("+25%", auctionViewLeft + 16 + 15, guiTop + 50 + 8, false, black); + Utils.drawStringCentered("+10%", auctionViewLeft + 16 + 34 + 15, guiTop + 50 + 8, false, black); + Utils.drawStringCentered("Set Amount", auctionViewLeft + 16 + 32, guiTop + 68 + 8, false, black); GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); GuiEditSign editSign = (GuiEditSign) Minecraft.getMinecraft().currentScreen; @@ -907,7 +891,7 @@ public class CustomAH extends Gui { this.drawTexturedModalRect(guiLeft, y, 0, ySplit, getXSize(), 136 - ySplit); //GUI Name - Utils.drawStringCenteredScaledMaxWidth("Auction House", Minecraft.getMinecraft().fontRendererObj, guiLeft + 42, + Utils.drawStringCenteredScaledMaxWidth("Auction House", guiLeft + 42, guiTop + 10, false, 68, 4210752 ); GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); @@ -1000,7 +984,7 @@ public class CustomAH extends Gui { if (!NotEnoughUpdates.INSTANCE.config.neuAuctionHouse.enableNeuAuctionHouse) { Utils.drawStringCentered(EnumChatFormatting.RED + "NEUAH is DISABLED! Enable in /neu.", - Minecraft.getMinecraft().fontRendererObj, guiLeft + getXSize() / 2, guiTop + getYSize() / 2 - 5, true, 0 + guiLeft + getXSize() / 2, guiTop + getYSize() / 2 - 5, true, 0 ); } @@ -1009,9 +993,7 @@ public class CustomAH extends Gui { for (String line : tooltipToRender) { tooltipGray.add(EnumChatFormatting.GRAY + line); } - Utils.drawHoveringText(tooltipGray, mouseX, mouseY, width, - height, -1, Minecraft.getMinecraft().fontRendererObj - ); + Utils.drawHoveringText(tooltipGray, mouseX, mouseY, width, height, -1); } float slideAmount = 1 - Math.max(0, Math.min(1, (System.currentTimeMillis() - lastGuiScreenSwitch) / 200f)); int auctionViewLeft = guiLeft + getXSize() + 4 - (int) (slideAmount * (78 + 4)); @@ -1032,9 +1014,7 @@ public class CustomAH extends Gui { } priceFilterField.drawTextBox(); - Utils.drawStringCenteredScaledMaxWidth("Price Filter", Minecraft.getMinecraft().fontRendererObj, - auctionViewLeft + 39, guiTop + 10, false, 70, 4210752 - ); + Utils.drawStringCenteredScaledMaxWidth("Price Filter", auctionViewLeft + 39, guiTop + 10, false, 70, 421052); GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); Minecraft.getMinecraft().getTextureManager().bindTexture(auction_view_buttons); @@ -1054,16 +1034,9 @@ public class CustomAH extends Gui { this.drawTexturedModalRect(auctionViewLeft + 16, guiTop + 50, 0, 32, 64, 16); } - FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; - Utils.drawStringCentered("<=", fr, auctionViewLeft + 16 + 15, guiTop + 32 + 8, false, - Color.BLACK.getRGB() - ); - Utils.drawStringCentered(">=", fr, auctionViewLeft + 16 + 34 + 15, guiTop + 32 + 8, false, - Color.BLACK.getRGB() - ); - Utils.drawStringCentered("==", fr, auctionViewLeft + 16 + 32, guiTop + 50 + 8, false, - Color.BLACK.getRGB() - ); + Utils.drawStringCentered("<=", auctionViewLeft + 16 + 15, guiTop + 32 + 8, false, black); + Utils.drawStringCentered(">=", auctionViewLeft + 16 + 34 + 15, guiTop + 32 + 8, false, black); + Utils.drawStringCentered("==", auctionViewLeft + 16 + 32, guiTop + 50 + 8, false, black); GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); // Bin average price filter @@ -1079,9 +1052,7 @@ public class CustomAH extends Gui { } binPriceFilterField.drawTextBox(); - Utils.drawStringCenteredScaledMaxWidth("BIN Average Filter", Minecraft.getMinecraft().fontRendererObj, - auctionViewLeft + 39, guiTop + 10 + binPriceFilterYOffset, false, 70, 4210752 - ); + Utils.drawStringCenteredScaledMaxWidth("BIN Average Filter", auctionViewLeft + 39, guiTop + 10 + binPriceFilterYOffset, false, 70, 4210752); GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); Minecraft.getMinecraft().getTextureManager().bindTexture(auction_view_buttons); @@ -1101,15 +1072,9 @@ public class CustomAH extends Gui { this.drawTexturedModalRect(auctionViewLeft + 16, guiTop + 50 + binPriceFilterYOffset, 0, 32, 64, 16); } - Utils.drawStringCentered("<=", fr, auctionViewLeft + 16 + 15, guiTop + 32 + 8 + binPriceFilterYOffset, false, - Color.BLACK.getRGB() - ); - Utils.drawStringCentered(">=", fr, auctionViewLeft + 16 + 34 + 15, guiTop + 32 + 8 + binPriceFilterYOffset, false, - Color.BLACK.getRGB() - ); - Utils.drawStringCentered("==", fr, auctionViewLeft + 16 + 32, guiTop + 50 + 8 + binPriceFilterYOffset, false, - Color.BLACK.getRGB() - ); + Utils.drawStringCentered("<=", auctionViewLeft + 16 + 15, guiTop + 32 + 8 + binPriceFilterYOffset, false, black); + Utils.drawStringCentered(">=", auctionViewLeft + 16 + 34 + 15, guiTop + 32 + 8 + binPriceFilterYOffset, false, black); + Utils.drawStringCentered("==", auctionViewLeft + 16 + 32, guiTop + 50 + 8 + binPriceFilterYOffset, false, black); GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/GuiElementColour.java b/src/main/java/io/github/moulberry/notenoughupdates/core/GuiElementColour.java index 1802a1a4..405b18fc 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/core/GuiElementColour.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/GuiElementColour.java @@ -254,13 +254,11 @@ public class GuiElementColour extends GuiElement { RenderUtils.drawTexturedRect(x + 5 + 32 + selx - 4, y + 5 + 32 + sely - 4, 8, 8, GL11.GL_NEAREST); TextRenderUtils.drawStringCenteredScaledMaxWidth(EnumChatFormatting.GRAY.toString() + Math.round(hsv[2] * 100) + "", - Minecraft.getMinecraft().fontRendererObj, x + 5 + 64 + 5 + 5 - (Math.round(hsv[2] * 100) == 100 ? 1 : 0), y + 5 + 64 + 5 + 5, true, 13, -1 ); if (opacitySlider) { TextRenderUtils.drawStringCenteredScaledMaxWidth( EnumChatFormatting.GRAY.toString() + Math.round(c.getAlpha() / 255f * 100) + "", - Minecraft.getMinecraft().fontRendererObj, x + 5 + 64 + 5 + valueOffset + 5, y + 5 + 64 + 5 + 5, true, @@ -271,7 +269,6 @@ public class GuiElementColour extends GuiElement { if (chromaSpeed > 0) { TextRenderUtils.drawStringCenteredScaledMaxWidth(EnumChatFormatting.GRAY.toString() + (int) ChromaColour.getSecondsForSpeed(chromaSpeed) + "s", - Minecraft.getMinecraft().fontRendererObj, x + 5 + 64 + 5 + valueOffset + opacityOffset + 6, y + 5 + 64 + 5 + 5, true, 13, -1 ); } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/GuiElementTextField.java b/src/main/java/io/github/moulberry/notenoughupdates/core/GuiElementTextField.java index 45dc58cc..5ab62d2a 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/core/GuiElementTextField.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/GuiElementTextField.java @@ -550,7 +550,6 @@ public class GuiElementTextField { TextRenderUtils.drawStringCenteredScaledMaxWidth( Utils.chromaStringByColourCode(texts[yOffI]), - Minecraft.getMinecraft().fontRendererObj, x + searchBarXSize / 2f, y + searchBarYSize / 2f + yOff, false, @@ -665,12 +664,12 @@ public class GuiElementTextField { y + (searchBarYSize - 8) / 2 + 9 + texY, Color.LIGHT_GRAY.getRGB() ); - TextRenderUtils.drawStringScaled(String.valueOf(c), Minecraft.getMinecraft().fontRendererObj, + TextRenderUtils.drawStringScaled(String.valueOf(c), x + xStartOffset + texX, y + searchBarYSize / 2f - scale * 8 / 2f + texY, false, Color.BLACK.getRGB(), scale ); if (bold) { - TextRenderUtils.drawStringScaled(String.valueOf(c), Minecraft.getMinecraft().fontRendererObj, + TextRenderUtils.drawStringScaled(String.valueOf(c), x + xStartOffset + texX + 1, y + searchBarYSize / 2f - scale * 8 / 2f + texY, false, Color.BLACK.getRGB(), scale ); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditor.java b/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditor.java index 9edad918..fd0946c9 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditor.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditor.java @@ -39,8 +39,9 @@ public abstract class GuiOptionEditor { FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; RenderUtils.drawFloatingRectDark(x, y, width, height, true); - TextRenderUtils.drawStringCenteredScaledMaxWidth(option.name, - fr, x + width / 6, y + 13, true, width / 3 - 10, 0xc0c0c0 + TextRenderUtils.drawStringCenteredScaledMaxWidth( + option.name, + x + width / 6, y + 13, true, width / 3 - 10, 0xc0c0c0 ); int maxLines = 5; diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorAccordion.java b/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorAccordion.java index 91515259..a422a8ec 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorAccordion.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorAccordion.java @@ -22,7 +22,6 @@ package io.github.moulberry.notenoughupdates.core.config.gui; import io.github.moulberry.notenoughupdates.core.config.struct.ConfigProcessor; import io.github.moulberry.notenoughupdates.core.util.render.RenderUtils; import io.github.moulberry.notenoughupdates.core.util.render.TextRenderUtils; -import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.WorldRenderer; @@ -76,9 +75,7 @@ public class GuiOptionEditorAccordion extends GuiOptionEditor { GlStateManager.enableTexture2D(); GlStateManager.disableBlend(); - TextRenderUtils.drawStringScaledMaxWidth(option.name, Minecraft.getMinecraft().fontRendererObj, - x + 18, y + 6, false, width - 10, 0xc0c0c0 - ); + TextRenderUtils.drawStringScaledMaxWidth(option.name, x + 18, y + 6, false, width - 10, 0xc0c0c0); } @Override diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorButton.java b/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorButton.java index aef6318c..fb5b58f3 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorButton.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorButton.java @@ -59,9 +59,9 @@ public class GuiOptionEditorButton extends GuiOptionEditor { RenderUtils.drawTexturedRect(x + width / 6 - 24, y + height - 7 - 14, 48, 16); if (buttonText != null) { - TextRenderUtils.drawStringCenteredScaledMaxWidth(buttonText, Minecraft.getMinecraft().fontRendererObj, - x + width / 6, y + height - 7 - 6, - false, 44, 0xFF303030 + TextRenderUtils.drawStringCenteredScaledMaxWidth( + buttonText, + x + width / 6, y + height - 7 - 6, false, 44, 0xFF303030 ); } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorDraggableList.java b/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorDraggableList.java index ef2a52bb..e080bb28 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorDraggableList.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorDraggableList.java @@ -25,7 +25,6 @@ import io.github.moulberry.notenoughupdates.core.util.render.RenderUtils; import io.github.moulberry.notenoughupdates.core.util.render.TextRenderUtils; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.Gui; import net.minecraft.client.gui.ScaledResolution; import net.minecraft.client.renderer.GlStateManager; @@ -93,10 +92,7 @@ public class GuiOptionEditorDraggableList extends GuiOptionEditor { Minecraft.getMinecraft().getTextureManager().bindTexture(button_tex); RenderUtils.drawTexturedRect(x + width / 6 - 24, y + 45 - 7 - 14, 48, 16); - TextRenderUtils.drawStringCenteredScaledMaxWidth("Add", Minecraft.getMinecraft().fontRendererObj, - x + width / 6, y + 45 - 7 - 6, - false, 44, 0xFF303030 - ); + TextRenderUtils.drawStringCenteredScaledMaxWidth("Add", x + width / 6, y + 45 - 7 - 6, false, 44, 0xFF303030); long currentTime = System.currentTimeMillis(); if (trashHoverTime < 0) { @@ -128,7 +124,8 @@ public class GuiOptionEditorDraggableList extends GuiOptionEditor { if (i++ != dragStartIndex) { for (int multilineIndex = 0; multilineIndex < multilines.length; multilineIndex++) { String line = multilines[multilineIndex]; - Utils.drawStringScaledMaxWidth(line + EnumChatFormatting.RESET, Minecraft.getMinecraft().fontRendererObj, + Utils.drawStringScaledMaxWidth( + line + EnumChatFormatting.RESET, x + 20, y + 50 + yOff + multilineIndex * 10, true, width - 20, 0xffffffff ); } @@ -156,7 +153,6 @@ public class GuiOptionEditorDraggableList extends GuiOptionEditor { } remaining.removeAll(activeText); - FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; int dropdownWidth = Math.min(width / 2 - 10, 150); int left = dragOffsetX; int top = dragOffsetY; @@ -184,7 +180,7 @@ public class GuiOptionEditorDraggableList extends GuiOptionEditor { str = ""; } TextRenderUtils.drawStringScaledMaxWidth(str.replaceAll("(\n.*)+", " ..."), - fr, left + 3, top + 3 + dropdownY, false, dropdownWidth - 6, 0xffa0a0a0 + left + 3, top + 3 + dropdownY, false, dropdownWidth - 6, 0xffa0a0a0 ); dropdownY += 12; } @@ -215,7 +211,6 @@ public class GuiOptionEditorDraggableList extends GuiOptionEditor { String line = multilines[multilineIndex]; Utils.drawStringScaledMaxWidth( line + EnumChatFormatting.RESET, - Minecraft.getMinecraft().fontRendererObj, dragOffsetX + mouseX + 10, dragOffsetY + mouseY + multilineIndex * 10, true, diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorDropdown.java b/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorDropdown.java index af6af277..115b502e 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorDropdown.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorDropdown.java @@ -22,8 +22,6 @@ package io.github.moulberry.notenoughupdates.core.config.gui; import io.github.moulberry.notenoughupdates.core.config.struct.ConfigProcessor; import io.github.moulberry.notenoughupdates.core.util.render.RenderUtils; import io.github.moulberry.notenoughupdates.core.util.render.TextRenderUtils; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.Gui; import net.minecraft.client.renderer.GlStateManager; import org.lwjgl.input.Mouse; @@ -54,7 +52,6 @@ public class GuiOptionEditorDropdown extends GuiOptionEditor { if (!open) { int height = getHeight(); - FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; int dropdownWidth = Math.min(width / 3 - 10, 80); int left = x + width / 6 - dropdownWidth / 2; int top = y + height - 7 - 14; @@ -67,7 +64,6 @@ public class GuiOptionEditorDropdown extends GuiOptionEditor { RenderUtils.drawFloatingRectDark(left, top, dropdownWidth, 14, false); TextRenderUtils.drawStringScaled( "\u25BC", - fr, left + dropdownWidth - 10, y + height - 7 - 15, false, @@ -75,9 +71,9 @@ public class GuiOptionEditorDropdown extends GuiOptionEditor { 2 ); - TextRenderUtils.drawStringScaledMaxWidth(selectedString, fr, left + 3, top + 3, false, - dropdownWidth - 16, 0xffa0a0a0 - ); + TextRenderUtils.drawStringScaledMaxWidth( + selectedString, + left + 3, top + 3, false, dropdownWidth - 16, 0xffa0a0a0); } } @@ -91,7 +87,6 @@ public class GuiOptionEditorDropdown extends GuiOptionEditor { int height = getHeight(); - FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; int dropdownWidth = Math.min(width / 3 - 10, 80); int left = x + width / 6 - dropdownWidth / 2; int top = y + height - 7 - 14; @@ -117,28 +112,16 @@ public class GuiOptionEditorDropdown extends GuiOptionEditor { } TextRenderUtils.drawStringScaledMaxWidth( option, - fr, - left + 3, - top + 3 + dropdownY, - false, - dropdownWidth - 6, - 0xffa0a0a0 + left + 3, top + 3 + dropdownY, false, dropdownWidth - 6, 0xffa0a0a0 ); dropdownY += 12; } - TextRenderUtils.drawStringScaled( - "\u25B2", - fr, - left + dropdownWidth - 10, - y + height - 7 - 15, - false, - 0xffa0a0a0, - 2 - ); + TextRenderUtils.drawStringScaled("\u25B2", left + dropdownWidth - 10, y + height - 7 - 15, false, 0xffa0a0a0, 2); - TextRenderUtils.drawStringScaledMaxWidth(selectedString, fr, left + 3, top + 3, false, - dropdownWidth - 16, 0xffa0a0a0 + TextRenderUtils.drawStringScaledMaxWidth( + selectedString, + left + 3, top + 3, false, dropdownWidth - 16, 0xffa0a0a0 ); GlStateManager.popMatrix(); } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorFSR.java b/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorFSR.java index 048e261e..db788b95 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorFSR.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorFSR.java @@ -54,9 +54,9 @@ public class GuiOptionEditorFSR extends GuiOptionEditor { RenderUtils.drawTexturedRect(x + width / 6 - 24, y + height - 7 - 14, 48, 16); if (buttonText != null) { - TextRenderUtils.drawStringCenteredScaledMaxWidth(buttonText, Minecraft.getMinecraft().fontRendererObj, - x + width / 6, y + height - 7 - 6, - false, 44, 0xFF303030 + TextRenderUtils.drawStringCenteredScaledMaxWidth( + buttonText, + x + width / 6, y + height - 7 - 6, false, 44, 0xFF303030 ); } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorKeybind.java b/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorKeybind.java index b7d70db8..ffad3bc0 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorKeybind.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorKeybind.java @@ -59,11 +59,7 @@ public class GuiOptionEditorKeybind extends GuiOptionEditor { String keyName = KeybindHelper.getKeyName(getKeyCode()); String text = editingKeycode ? "> " + keyName + " <" : keyName; - TextRenderUtils.drawStringCenteredScaledMaxWidth(text, - Minecraft.getMinecraft().fontRendererObj, - x + width / 6, y + height - 7 - 6, - false, 40, 0xFF303030 - ); + TextRenderUtils.drawStringCenteredScaledMaxWidth(text, x + width / 6, y + height - 7 - 6, false, 40, 0xFF303030); Minecraft.getMinecraft().getTextureManager().bindTexture(RESET); GlStateManager.color(1, 1, 1, 1); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiPositionEditor.java b/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiPositionEditor.java index 1b71e3ce..c7dced22 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiPositionEditor.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiPositionEditor.java @@ -135,10 +135,9 @@ public class GuiPositionEditor extends GuiScreen { if (position.isCenterY()) y -= elementHeight / 2; Gui.drawRect(x, y, x + elementWidth, y + elementHeight, 0x80404040); - Utils.drawStringCentered("Position Editor", Minecraft.getMinecraft().fontRendererObj, - scaledResolution.getScaledWidth() / 2, 8, true, 0xffffff - ); - Utils.drawStringCentered("R to Reset - Arrow keys/mouse to move", Minecraft.getMinecraft().fontRendererObj, + Utils.drawStringCentered("Position Editor", scaledResolution.getScaledWidth() / 2, 8, true, 0xffffff); + Utils.drawStringCentered( + "R to Reset - Arrow keys/mouse to move", scaledResolution.getScaledWidth() / 2, 18, true, 0xffffff ); } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiPositionEditorButForTheDungeonMap.java b/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiPositionEditorButForTheDungeonMap.java index b334418c..9f2088ed 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiPositionEditorButForTheDungeonMap.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiPositionEditorButForTheDungeonMap.java @@ -106,12 +106,10 @@ public class GuiPositionEditorButForTheDungeonMap extends GuiScreen { // nea is } scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); - Utils.drawStringCentered("Position Editor", Minecraft.getMinecraft().fontRendererObj, - scaledResolution.getScaledWidth() / 2, 8, true, 0xffffff - ); - Utils.drawStringCentered("R to Reset - Arrow keys/mouse to move", Minecraft.getMinecraft().fontRendererObj, - scaledResolution.getScaledWidth() / 2, 18, true, 0xffffff - ); + Utils.drawStringCentered("Position Editor", scaledResolution.getScaledWidth() / 2, 8, true, 0xffffff); + Utils.drawStringCentered( + "R to Reset - Arrow keys/mouse to move", + scaledResolution.getScaledWidth() / 2, 18, true, 0xffffff); } @Override diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/config/struct/GuiOptionEditorBlocked.java b/src/main/java/io/github/moulberry/notenoughupdates/core/config/struct/GuiOptionEditorBlocked.java index 8415cf72..11112782 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/core/config/struct/GuiOptionEditorBlocked.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/config/struct/GuiOptionEditorBlocked.java @@ -56,7 +56,6 @@ public class GuiOptionEditorBlocked extends GuiOptionEditor { TextRenderUtils.drawStringScaledMaxWidth( "This option is currently not available.", - mc.fontRendererObj, x + iconWidth,y + getHeight() / 2F - mc.fontRendererObj.FONT_HEIGHT / 2F, true, (int) (width - iconWidth), 0xFFFF4444 ); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/util/ArrowPagesUtils.java b/src/main/java/io/github/moulberry/notenoughupdates/core/util/ArrowPagesUtils.java index 1e70db7f..e9bff8f6 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/core/util/ArrowPagesUtils.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/util/ArrowPagesUtils.java @@ -21,7 +21,6 @@ package io.github.moulberry.notenoughupdates.core.util; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.ScaledResolution; import net.minecraft.util.MathHelper; import net.minecraft.util.ResourceLocation; @@ -92,9 +91,8 @@ public class ArrowPagesUtils { String selectedPage = (currentPage + 1) + "/" + totalPages; - FontRenderer fontRendererObj = Minecraft.getMinecraft().fontRendererObj; - Utils.drawStringCenteredScaledMaxWidth(selectedPage, fontRendererObj, - guiLeft + pageStringX, guiTop + pageStringY, false, 28, Color.BLACK.getRGB() + Utils.drawStringCenteredScaledMaxWidth( + selectedPage, guiLeft + pageStringX, guiTop + pageStringY, false, 28, Color.BLACK.getRGB() ); } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/util/render/TextRenderUtils.java b/src/main/java/io/github/moulberry/notenoughupdates/core/util/render/TextRenderUtils.java index cee38cea..336dcb67 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/core/util/render/TextRenderUtils.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/util/render/TextRenderUtils.java @@ -65,6 +65,18 @@ public class TextRenderUtils { } } + public static void drawStringScaledMaxWidth( + String str, + float x, + float y, + boolean shadow, + int len, + int colour + ) { + drawStringScaledMaxWidth(str, Minecraft.getMinecraft().fontRendererObj, x, y, shadow, len, colour); + } + + @Deprecated public static void drawStringScaledMaxWidth( String str, FontRenderer fr, @@ -78,7 +90,7 @@ public class TextRenderUtils { float factor = len / (float) strLen; factor = Math.min(1, factor); - drawStringScaled(str, fr, x, y, shadow, colour, factor); + drawStringScaled(str, x, y, shadow, colour, factor); } public static void drawStringCentered(String str, FontRenderer fr, float x, float y, boolean shadow, int colour) { @@ -94,7 +106,19 @@ public class TextRenderUtils { public static void drawStringScaled( String str, - FontRenderer fr, + float x, + float y, + boolean shadow, + int colour, + float factor + ) { + drawStringScaled(str, Minecraft.getMinecraft().fontRendererObj, x, y, shadow, colour, factor); + } + + @Deprecated + public static void drawStringScaled( + String str, + FontRenderer fr, float x, float y, boolean shadow, @@ -106,6 +130,18 @@ public class TextRenderUtils { GlStateManager.scale(1 / factor, 1 / factor, 1); } + public static void drawStringCenteredScaledMaxWidth( + String str, + float x, + float y, + boolean shadow, + int len, + int colour + ) { + drawStringCenteredScaledMaxWidth(str, Minecraft.getMinecraft().fontRendererObj, x, y, shadow, len, colour); + } + + @Deprecated public static void drawStringCenteredScaledMaxWidth( String str, FontRenderer fr, @@ -122,7 +158,7 @@ public class TextRenderUtils { float fontHeight = 8 * factor; - drawStringScaled(str, fr, x - newLen / 2, y - fontHeight / 2, shadow, colour, factor); + drawStringScaled(str, x - newLen / 2, y - fontHeight / 2, shadow, colour, factor); } public static void renderToolTip( diff --git a/src/main/java/io/github/moulberry/notenoughupdates/cosmetics/GuiCosmetics.java b/src/main/java/io/github/moulberry/notenoughupdates/cosmetics/GuiCosmetics.java index 12d8c92d..cacae83b 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/cosmetics/GuiCosmetics.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/cosmetics/GuiCosmetics.java @@ -134,17 +134,7 @@ public class GuiCosmetics extends GuiScreen { for (String line : cosmeticsInfoTooltip) { grayTooltip.add(EnumChatFormatting.GRAY + line); } - Utils.drawHoveringText( - grayTooltip, - mouseX, - mouseY, - width, - height, - -1, - Minecraft.getMinecraft().fontRendererObj - ); - - } + Utils.drawHoveringText(grayTooltip, mouseX, mouseY, width, height, -1);} } StringBuilder statusMsg = new StringBuilder("Last Sync: "); @@ -193,9 +183,7 @@ public class GuiCosmetics extends GuiScreen { equipMsg += " - " + (20 - (System.currentTimeMillis() - lastCapeEquip) / 1000) + "s"; } - Utils.drawStringCenteredScaledMaxWidth(equipMsg, Minecraft.getMinecraft().fontRendererObj, - guiLeft + sizeX / 2f, guiTop + sizeY + 5 + 10, false, 90, 0 - ); + Utils.drawStringCenteredScaledMaxWidth(equipMsg, guiLeft + sizeX / 2f, guiTop + sizeY + 5 + 10, false, 90, 0); } if (unlockTextField.getFocus() || !unlockTextField.getText().isEmpty()) { @@ -529,7 +517,6 @@ public class GuiCosmetics extends GuiScreen { Utils.drawStringCenteredScaledMaxWidth( "Try it out", - Minecraft.getMinecraft().fontRendererObj, guiLeft + 20 + 91 * displayIndex + 81 / 2f - xOffset, guiTop + 123 + 10, false, @@ -539,7 +526,6 @@ public class GuiCosmetics extends GuiScreen { if (equipable) { Utils.drawStringCenteredScaledMaxWidth( "Equip", - Minecraft.getMinecraft().fontRendererObj, guiLeft + 20 + 91 * displayIndex + 81 / 2f - xOffset, guiTop + 149 + 10, false, @@ -549,7 +535,6 @@ public class GuiCosmetics extends GuiScreen { } else { Utils.drawStringCenteredScaledMaxWidth( "Not Unlocked", - Minecraft.getMinecraft().fontRendererObj, guiLeft + 20 + 91 * displayIndex + 81 / 2f - xOffset, guiTop + 149 + 10, false, diff --git a/src/main/java/io/github/moulberry/notenoughupdates/dungeons/DungeonWin.java b/src/main/java/io/github/moulberry/notenoughupdates/dungeons/DungeonWin.java index 8f44242a..5b476c93 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/dungeons/DungeonWin.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/dungeons/DungeonWin.java @@ -284,7 +284,6 @@ public class DungeonWin { if (Math.abs(xOff) != Math.abs(yOff)) { Utils.drawStringCentered( Utils.cleanColourNotModifiers(line), - Minecraft.getMinecraft().fontRendererObj, sr.getScaledWidth() / 2 + xOff / 2f, textCenterY + yOff / 2f, false, @@ -295,9 +294,7 @@ public class DungeonWin { } } - Utils.drawStringCentered(line, Minecraft.getMinecraft().fontRendererObj, - sr.getScaledWidth() / 2, textCenterY, false, (textAlpha << 24) | 0x00FFFFFF - ); + Utils.drawStringCentered(line, sr.getScaledWidth() / 2, textCenterY, false, (textAlpha << 24) | 0x00FFFFFF); } } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/dungeons/GuiDungeonMapEditor.java b/src/main/java/io/github/moulberry/notenoughupdates/dungeons/GuiDungeonMapEditor.java index 025e11b2..dfd0405b 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/dungeons/GuiDungeonMapEditor.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/dungeons/GuiDungeonMapEditor.java @@ -145,7 +145,6 @@ public class GuiDungeonMapEditor extends GuiScreen { if (text.length() > 0) { Utils.drawStringCenteredScaledMaxWidth( text, - Minecraft.getMinecraft().fontRendererObj, guiLeft + x + 24, guiTop + y + 8, false, @@ -379,64 +378,30 @@ public class GuiDungeonMapEditor extends GuiScreen { Minecraft.getMinecraft().fontRendererObj.drawString("NEU Dungeon Map Editor", guiLeft + 8, guiTop + 6, 0xFFB4B4B4); - Utils.drawStringCenteredScaledMaxWidth("Border Size", Minecraft.getMinecraft().fontRendererObj, - guiLeft + 76, guiTop + 30, false, 137, 0xFFB4B4B4 - ); - Utils.drawStringCenteredScaledMaxWidth("Rooms Size", Minecraft.getMinecraft().fontRendererObj, - guiLeft + 76, guiTop + 60, false, 137, 0xFFB4B4B4 - ); - Utils.drawStringCenteredScaledMaxWidth("Icon Scale", Minecraft.getMinecraft().fontRendererObj, - guiLeft + 76, guiTop + 90, false, 137, 0xFFB4B4B4 - ); - Utils.drawStringCenteredScaledMaxWidth("Border Style", Minecraft.getMinecraft().fontRendererObj, - guiLeft + 76, guiTop + 120, false, 137, 0xFFB4B4B4 - ); + Utils.drawStringCenteredScaledMaxWidth("Border Size", guiLeft + 76, guiTop + 30, false, 137, 0xFFB4B4B4); + Utils.drawStringCenteredScaledMaxWidth("Rooms Size", guiLeft + 76, guiTop + 60, false, 137, 0xFFB4B4B4); + Utils.drawStringCenteredScaledMaxWidth("Icon Scale", guiLeft + 76, guiTop + 90, false, 137, 0xFFB4B4B4); + Utils.drawStringCenteredScaledMaxWidth("Border Style", guiLeft + 76, guiTop + 120, false, 137, 0xFFB4B4B4); - Utils.drawStringCenteredScaledMaxWidth("Dungeon Map", Minecraft.getMinecraft().fontRendererObj, - guiLeft + 44 + 139, guiTop + 30, false, 60, 0xFFB4B4B4 - ); - Utils.drawStringCenteredScaledMaxWidth("Center", Minecraft.getMinecraft().fontRendererObj, - guiLeft + 108 + 139, guiTop + 30, false, 60, 0xFFB4B4B4 - ); + Utils.drawStringCenteredScaledMaxWidth("Dungeon Map", guiLeft + 44 + 139, guiTop + 30, false, 60, 0xFFB4B4B4); + Utils.drawStringCenteredScaledMaxWidth("Center", guiLeft + 108 + 139, guiTop + 30, false, 60, 0xFFB4B4B4); - Utils.drawStringCenteredScaledMaxWidth("Rotate", Minecraft.getMinecraft().fontRendererObj, - guiLeft + 44 + 139, guiTop + 59, false, 60, 0xFFB4B4B4 - ); - Utils.drawStringCenteredScaledMaxWidth("Icon Style", Minecraft.getMinecraft().fontRendererObj, - guiLeft + 108 + 139, guiTop + 59, false, 60, 0xFFB4B4B4 - ); + Utils.drawStringCenteredScaledMaxWidth("Rotate", guiLeft + 44 + 139, guiTop + 59, false, 60, 0xFFB4B4B4); + Utils.drawStringCenteredScaledMaxWidth("Icon Style", guiLeft + 108 + 139, guiTop + 59, false, 60, 0xFFB4B4B4); - Utils.drawStringCenteredScaledMaxWidth("Check Orient", Minecraft.getMinecraft().fontRendererObj, - guiLeft + 44 + 139, guiTop + 88, false, 60, 0xFFB4B4B4 - ); - Utils.drawStringCenteredScaledMaxWidth("Check Center", Minecraft.getMinecraft().fontRendererObj, - guiLeft + 108 + 139, guiTop + 88, false, 60, 0xFFB4B4B4 - ); + Utils.drawStringCenteredScaledMaxWidth("Check Orient", guiLeft + 44 + 139, guiTop + 88, false, 60, 0xFFB4B4B4); + Utils.drawStringCenteredScaledMaxWidth("Check Center", guiLeft + 108 + 139, guiTop + 88, false, 60, 0xFFB4B4B4); - Utils.drawStringCenteredScaledMaxWidth("Interpolation", Minecraft.getMinecraft().fontRendererObj, - guiLeft + 44 + 139, guiTop + 117, false, 60, 0xFFB4B4B4 - ); - Utils.drawStringCenteredScaledMaxWidth("Compatibility", Minecraft.getMinecraft().fontRendererObj, - guiLeft + 108 + 139, guiTop + 117, false, 60, 0xFFB4B4B4 - ); + Utils.drawStringCenteredScaledMaxWidth("Interpolation", guiLeft + 44 + 139, guiTop + 117, false, 60, 0xFFB4B4B4); + Utils.drawStringCenteredScaledMaxWidth("Compatibility", guiLeft + 108 + 139, guiTop + 117, false, 60, 0xFFB4B4B4); - Utils.drawStringCenteredScaledMaxWidth("Background", Minecraft.getMinecraft().fontRendererObj, - guiLeft + 44 + 139, guiTop + 146, false, 60, 0xFFB4B4B4 - ); - Utils.drawStringCenteredScaledMaxWidth("Border", Minecraft.getMinecraft().fontRendererObj, - guiLeft + 108 + 139, guiTop + 146, false, 60, 0xFFB4B4B4 - ); + Utils.drawStringCenteredScaledMaxWidth("Background", guiLeft + 44 + 139, guiTop + 146, false, 60, 0xFFB4B4B4); + Utils.drawStringCenteredScaledMaxWidth("Border", guiLeft + 108 + 139, guiTop + 146, false, 60, 0xFFB4B4B4); - Utils.drawStringCenteredScaledMaxWidth("BG Blur", Minecraft.getMinecraft().fontRendererObj, - guiLeft + 44 + 139, guiTop + 175, false, 60, 0xFFB4B4B4 - ); - Utils.drawStringCenteredScaledMaxWidth("Chroma Type", Minecraft.getMinecraft().fontRendererObj, - guiLeft + 108 + 139, guiTop + 175, false, 60, 0xFFB4B4B4 - ); + Utils.drawStringCenteredScaledMaxWidth("BG Blur", guiLeft + 44 + 139, guiTop + 175, false, 60, 0xFFB4B4B4); + Utils.drawStringCenteredScaledMaxWidth("Chroma Type", guiLeft + 108 + 139, guiTop + 175, false, 60, 0xFFB4B4B4); - Utils.drawStringCenteredScaledMaxWidth("Edit Map Position", Minecraft.getMinecraft().fontRendererObj, - guiLeft + 76, guiTop + 209, false, 200, 0xFFB4B4B4 - ); + Utils.drawStringCenteredScaledMaxWidth("Edit Map Position", guiLeft + 76, guiTop + 209, false, 200, 0xFFB4B4B4); try { drawSlider(DungeonMapConfig.class.getDeclaredField("dmBorderSize"), guiLeft + 76, guiTop + 45); @@ -468,9 +433,7 @@ public class GuiDungeonMapEditor extends GuiScreen { GlStateManager.color(1, 1, 1, 1); Minecraft.getMinecraft().getTextureManager().bindTexture(button_tex); RenderUtils.drawTexturedRect(guiLeft + 52, guiTop + 215, 48, 16); - TextRenderUtils.drawStringCenteredScaledMaxWidth("Edit", fontRendererObj, guiLeft + 76, guiTop + 223, - false, 48, 0xFF303030 - ); + TextRenderUtils.drawStringCenteredScaledMaxWidth("Edit", guiLeft + 76, guiTop + 223, false, 48, 0xFF303030); Map decorations = new HashMap<>(); Vec4b vec4b = new Vec4b((byte) 3, (byte) (((50) - 64) * 2), (byte) (((40) - 64) * 2), (byte) ((60) * 16 / 360)); @@ -495,8 +458,7 @@ public class GuiDungeonMapEditor extends GuiScreen { mouseY, width, height, - 200, - Minecraft.getMinecraft().fontRendererObj + 200 ); } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/infopanes/FlipperInfoPane.java b/src/main/java/io/github/moulberry/notenoughupdates/infopanes/FlipperInfoPane.java index 4b6c73f4..a8df8d1f 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/infopanes/FlipperInfoPane.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/infopanes/FlipperInfoPane.java @@ -121,7 +121,6 @@ public class FlipperInfoPane extends InfoPane { } private int renderParagraph(int width, int height, int startY, String text, Color bg) { - FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; int paneWidth = (int) (width / 3 * overlay.getWidthMult()); int rightSide = (int) (width * overlay.getInfoPaneOffsetFactor()); @@ -129,7 +128,7 @@ public class FlipperInfoPane extends InfoPane { int yOff = 0; for (String line : text.split("\n")) { - yOff += Utils.renderStringTrimWidth(line, fr, false, leftSide + overlay.getBoxPadding() + 5, + yOff += Utils.renderStringTrimWidth(line, false, leftSide + overlay.getBoxPadding() + 5, startY + overlay.getBoxPadding() + 10 + yOff, width * 1 / 3 - overlay.getBoxPadding() * 2 - 10, Color.WHITE.getRGB(), -1 ); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/infopanes/TextInfoPane.java b/src/main/java/io/github/moulberry/notenoughupdates/infopanes/TextInfoPane.java index 90bed1fa..37e9e4d7 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/infopanes/TextInfoPane.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/infopanes/TextInfoPane.java @@ -61,7 +61,7 @@ public class TextInfoPane extends ScrollableInfoPane { int yOff = 20; for (String line : text.split("\n")) { - yOff += Utils.renderStringTrimWidth(line, fr, false, leftSide + overlay.getBoxPadding() + 5, + yOff += Utils.renderStringTrimWidth(line, false, leftSide + overlay.getBoxPadding() + 5, yScroll + overlay.getBoxPadding() + 10 + yOff, width * 1 / 3 - overlay.getBoxPadding() * 2 - 10, Color.WHITE.getRGB(), -1 ); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/itemeditor/GuiElementTextField.java b/src/main/java/io/github/moulberry/notenoughupdates/itemeditor/GuiElementTextField.java index 7cc96d42..cf4edb76 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/itemeditor/GuiElementTextField.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/itemeditor/GuiElementTextField.java @@ -123,7 +123,7 @@ public class GuiElementTextField extends GuiElement { } private float getScaleFactor(String str) { - return Math.min(1, (searchBarXSize - 2) / (float) Minecraft.getMinecraft().fontRendererObj.getStringWidth(str)); + return Math.min(1, (searchBarXSize - 2) / (float) getStringWidth0(str)); } private boolean isScaling() { @@ -132,12 +132,16 @@ public class GuiElementTextField extends GuiElement { private float getStringWidth(String str) { if (isScaling()) { - return Minecraft.getMinecraft().fontRendererObj.getStringWidth(str) * getScaleFactor(str); + return getStringWidth0(str) * getScaleFactor(str); } else { - return Minecraft.getMinecraft().fontRendererObj.getStringWidth(str); + return getStringWidth0(str); } } + private static int getStringWidth0(String str) { + return Minecraft.getMinecraft().fontRendererObj.getStringWidth(str); + } + public int getCursorPos(int mouseX, int mouseY) { int xComp = mouseX - x; int yComp = mouseY - y; @@ -188,7 +192,7 @@ public class GuiElementTextField extends GuiElement { int linePos = strLenNoColor(trimmed); if (linePos != strLenNoColor(line)) { char after = line.charAt(linePos); - int trimmedWidth = Minecraft.getMinecraft().fontRendererObj.getStringWidth(trimmed); + int trimmedWidth = getStringWidth0(trimmed); int charWidth = Minecraft.getMinecraft().fontRendererObj.getCharWidth(after); if (trimmedWidth + charWidth / 2 < xComp - padding) { linePos++; @@ -304,7 +308,7 @@ public class GuiElementTextField extends GuiElement { } else if (split.length > 1) { thisLineBeforeCursor = split[split.length - 1]; lineBefore = split[split.length - 2]; - textBeforeCursorWidth = Minecraft.getMinecraft().fontRendererObj.getStringWidth(thisLineBeforeCursor); + textBeforeCursorWidth = getStringWidth0(thisLineBeforeCursor); } else { return; } @@ -313,7 +317,7 @@ public class GuiElementTextField extends GuiElement { int linePos = strLenNoColor(trimmed); if (linePos != strLenNoColor(lineBefore)) { char after = lineBefore.charAt(linePos); - int trimmedWidth = Minecraft.getMinecraft().fontRendererObj.getStringWidth(trimmed); + int trimmedWidth = getStringWidth0(trimmed); int charWidth = Minecraft.getMinecraft().fontRendererObj.getCharWidth(after); if (trimmedWidth + charWidth / 2 < textBeforeCursorWidth) { linePos++; @@ -342,7 +346,7 @@ public class GuiElementTextField extends GuiElement { textBeforeCursorWidth = 0; } else if (split.length > 0) { thisLineBeforeCursor = split[split.length - 1]; - textBeforeCursorWidth = Minecraft.getMinecraft().fontRendererObj.getStringWidth(thisLineBeforeCursor); + textBeforeCursorWidth = getStringWidth0(thisLineBeforeCursor); } else { return; } @@ -355,7 +359,7 @@ public class GuiElementTextField extends GuiElement { int linePos = strLenNoColor(trimmed); if (linePos != strLenNoColor(lineAfter)) { char after = lineAfter.charAt(linePos); - int trimmedWidth = Minecraft.getMinecraft().fontRendererObj.getStringWidth(trimmed); + int trimmedWidth = getStringWidth0(trimmed); int charWidth = Minecraft.getMinecraft().fontRendererObj.getCharWidth(after); if (trimmedWidth + charWidth / 2 < textBeforeCursorWidth) { linePos++; @@ -468,15 +472,14 @@ public class GuiElementTextField extends GuiElement { for (int yOffI = 0; yOffI < texts.length; yOffI++) { int yOff = yOffI * extraSize; - if (isScaling() && Minecraft.getMinecraft().fontRendererObj.getStringWidth(texts[yOffI]) > searchBarXSize - 10) { - scale = (searchBarXSize - 2) / (float) Minecraft.getMinecraft().fontRendererObj.getStringWidth(texts[yOffI]); + if (isScaling() && getStringWidth0(texts[yOffI]) > searchBarXSize - 10) { + scale = (searchBarXSize - 2) / (float) getStringWidth0(texts[yOffI]); if (scale > 1) scale = 1; - float newLen = Minecraft.getMinecraft().fontRendererObj.getStringWidth(texts[yOffI]) * scale; + float newLen = getStringWidth0(texts[yOffI]) * scale; xStartOffset = (int) ((searchBarXSize - newLen) / 2f); Utils.drawStringCenteredScaledMaxWidth( texts[yOffI], - Minecraft.getMinecraft().fontRendererObj, x + searchBarXSize / 2f, y + searchBarYSize / 2f + yOff, false, @@ -506,7 +509,7 @@ public class GuiElementTextField extends GuiElement { if (split.length <= numLinesBeforeCursor || split.length == 0) { textBeforeCursorWidth = 0; } else { - textBeforeCursorWidth = (int) (Minecraft.getMinecraft().fontRendererObj.getStringWidth(split[split.length - + textBeforeCursorWidth = (int) (getStringWidth0(split[split.length - 1]) * scale); } drawRect(x + xStartOffset + textBeforeCursorWidth, @@ -557,7 +560,7 @@ public class GuiElementTextField extends GuiElement { continue; } - int len = Minecraft.getMinecraft().fontRendererObj.getStringWidth(String.valueOf(c)); + int len = getStringWidth0(String.valueOf(c)); if (bold) len++; if (i >= leftIndex && i < rightIndex) { drawRect(x + xStartOffset + (int) texX, @@ -566,12 +569,12 @@ public class GuiElementTextField extends GuiElement { y + (searchBarYSize - 8) / 2 + 9 + texY, Color.LIGHT_GRAY.getRGB() ); - Utils.drawStringScaled(String.valueOf(c), Minecraft.getMinecraft().fontRendererObj, + Utils.drawStringScaled(String.valueOf(c), x + xStartOffset + texX, y + searchBarYSize / 2f - scale * 8 / 2f + texY, false, Color.BLACK.getRGB(), scale ); if (bold) { - Utils.drawStringScaled(String.valueOf(c), Minecraft.getMinecraft().fontRendererObj, + Utils.drawStringScaled(String.valueOf(c), x + xStartOffset + texX + 1, y + searchBarYSize / 2f - scale * 8 / 2f + texY, false, Color.BLACK.getRGB(), scale ); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/itemeditor/NEUItemEditor.java b/src/main/java/io/github/moulberry/notenoughupdates/itemeditor/NEUItemEditor.java index e08e5369..041843ae 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/itemeditor/NEUItemEditor.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/itemeditor/NEUItemEditor.java @@ -370,9 +370,7 @@ public class NEUItemEditor extends GuiScreen { text.add(displayName.get()); text.addAll(Arrays.asList(lore.get().split("\n"))); - Utils.drawHoveringText(text, itemX - 20, itemY + itemSize + 28, width, height, -1, - Minecraft.getMinecraft().fontRendererObj - ); + Utils.drawHoveringText(text, itemX - 20, itemY + itemSize + 28, width, height, -1); GlStateManager.disableLighting(); } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java b/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java index 65724c65..03f3a449 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java @@ -709,8 +709,7 @@ public class RenderListener { event.mouseY, event.gui.width, event.gui.height, - -1, - Minecraft.getMinecraft().fontRendererObj + -1 ); } } @@ -970,7 +969,6 @@ public class RenderListener { && NotEnoughUpdates.INSTANCE.config.dungeons.shouldWarningDerpy) { Utils.drawStringScaled( EnumChatFormatting.RED + EnumChatFormatting.BOLD.toString() + "Mayor Derpy active!", - Minecraft.getMinecraft().fontRendererObj, guiLeft + xSize + 4 + 10, guiTop + 85, true, diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AbiphoneWarning.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AbiphoneWarning.java index 2c28bcd1..69b0a1b6 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AbiphoneWarning.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AbiphoneWarning.java @@ -120,29 +120,24 @@ public class AbiphoneWarning extends GuiElement { int neuLength = Minecraft.getMinecraft().fontRendererObj.getStringWidth("\u00a7lNEU"); Minecraft.getMinecraft().fontRendererObj.drawString( "\u00a7lNEU", - width / 2 + 90 - neuLength - 3, - height / 2 - 45 + 4, - 0xff000000 + width / 2 + 90 - neuLength - 3, height / 2 - 45 + 4, 0xff000000 ); - TextRenderUtils.drawStringCenteredScaledMaxWidth("Are you SURE?", Minecraft.getMinecraft().fontRendererObj, + TextRenderUtils.drawStringCenteredScaledMaxWidth( + "Are you SURE?", width / 2, height / 2 - 45 + 10, false, 170, 0xffff4040 ); String sellLine = "\u00a77[ \u00a7r" + contactName + "\u00a77 ]"; - TextRenderUtils.drawStringCenteredScaledMaxWidth(sellLine, Minecraft.getMinecraft().fontRendererObj, + TextRenderUtils.drawStringCenteredScaledMaxWidth( + sellLine, width / 2, height / 2 - 45 + 25, false, 170, 0xffffffff ); TextRenderUtils.drawStringCenteredScaledMaxWidth( "Continue removing this contact?", - Minecraft.getMinecraft().fontRendererObj, - width / 2, - height / 2 - 45 + 50, - false, - 170, - 0xffa0a0a0 + width / 2, height / 2 - 45 + 50, false, 170, 0xffa0a0a0 ); RenderUtils.drawFloatingRectDark(width / 2 - 43, height / 2 + 23, 40, 16, false); @@ -150,21 +145,11 @@ public class AbiphoneWarning extends GuiElement { TextRenderUtils.drawStringCenteredScaledMaxWidth( EnumChatFormatting.GREEN + "[Y]es", - Minecraft.getMinecraft().fontRendererObj, - width / 2 - 23, - height / 2 + 31, - true, - 36, - 0xff00ff00 + width / 2 - 23, height / 2 + 31, true, 36, 0xff00ff00 ); TextRenderUtils.drawStringCenteredScaledMaxWidth( EnumChatFormatting.RED + "[N]o", - Minecraft.getMinecraft().fontRendererObj, - width / 2 + 23, - height / 2 + 31, - true, - 36, - 0xffff0000 + width / 2 + 23, height / 2 + 31, true, 36, 0xffff0000 ); GlStateManager.popMatrix(); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AuctionBINWarning.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AuctionBINWarning.java index 7282aad7..2b292aec 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AuctionBINWarning.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AuctionBINWarning.java @@ -183,7 +183,7 @@ public class AuctionBINWarning extends GuiElement { 0xff000000 ); - TextRenderUtils.drawStringCenteredScaledMaxWidth("Are you SURE?", Minecraft.getMinecraft().fontRendererObj, + TextRenderUtils.drawStringCenteredScaledMaxWidth("Are you SURE?", width / 2, height / 2 - 45 + 10, false, 170, 0xffff4040 ); @@ -203,19 +203,14 @@ public class AuctionBINWarning extends GuiElement { String sellLine = "\u00a77[ \u00a7r" + sellingName + "\u00a77 ]"; - TextRenderUtils.drawStringCenteredScaledMaxWidth(sellLine, Minecraft.getMinecraft().fontRendererObj, + TextRenderUtils.drawStringCenteredScaledMaxWidth(sellLine, width / 2, height / 2 - 45 + 25, false, 170, 0xffffffff ); TextRenderUtils.drawStringCenteredScaledMaxWidth( (lowestPrice > 0 ? "has a lowest BIN of \u00a76" + lowestPriceStr + "\u00a7r coins" : "\u00a7cWarning: No lowest BIN found!"), - Minecraft.getMinecraft().fontRendererObj, - width / 2, - height / 2 - 45 + 34, - false, - 170, - 0xffa0a0a0 + width / 2, height / 2 - 45 + 34, false, 170, 0xffa0a0a0 ); if (sellingPrice > lowestPrice * sellStackAmount) { @@ -229,22 +224,12 @@ public class AuctionBINWarning extends GuiElement { TextRenderUtils.drawStringCenteredScaledMaxWidth( "Continue selling it for", - Minecraft.getMinecraft().fontRendererObj, - width / 2, - height / 2 - 45 + 50, - false, - 170, - 0xffa0a0a0 + width / 2, height / 2 - 45 + 50, false, 170, 0xffa0a0a0 ); TextRenderUtils.drawStringCenteredScaledMaxWidth( "\u00a76" + sellingPriceStr + "\u00a7r coins?" + (lowestPrice > 0 ? "(\u00a7" + (isALoss ? "c-" : "a+") + (buyPercentage >= 100 ? buyPercentage - 100 : buyPercentage) + "%\u00a7r)" : ""), - Minecraft.getMinecraft().fontRendererObj, - width / 2, - height / 2 - 45 + 59, - false, - 170, - 0xffa0a0a0 + width / 2, height / 2 - 45 + 59, false, 170, 0xffa0a0a0 ); RenderUtils.drawFloatingRectDark(width / 2 - 43, height / 2 + 23, 40, 16, false); @@ -252,21 +237,11 @@ public class AuctionBINWarning extends GuiElement { TextRenderUtils.drawStringCenteredScaledMaxWidth( EnumChatFormatting.GREEN + "[Y]es", - Minecraft.getMinecraft().fontRendererObj, - width / 2 - 23, - height / 2 + 31, - true, - 36, - 0xff00ff00 + width / 2 - 23, height / 2 + 31, true, 36, 0xff00ff00 ); TextRenderUtils.drawStringCenteredScaledMaxWidth( EnumChatFormatting.RED + "[N]o", - Minecraft.getMinecraft().fontRendererObj, - width / 2 + 23, - height / 2 + 31, - true, - 36, - 0xffff0000 + width / 2 + 23, height / 2 + 31, true, 36, 0xffff0000 ); if (sellingTooltip != null) { @@ -277,15 +252,7 @@ public class AuctionBINWarning extends GuiElement { if (mouseX >= width / 2 - sellLineLength / 2 && mouseX <= width / 2 + sellLineLength / 2 && mouseY >= height / 2 - 45 + 20 && mouseY <= height / 2 - 45 + 30) { - Utils.drawHoveringText( - sellingTooltip, - mouseX, - mouseY, - width, - height, - -1, - Minecraft.getMinecraft().fontRendererObj - ); + Utils.drawHoveringText(sellingTooltip, mouseX, mouseY, width, height, -1); } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AuctionSortModeWarning.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AuctionSortModeWarning.java index ed05ee79..e840acdf 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AuctionSortModeWarning.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AuctionSortModeWarning.java @@ -82,9 +82,7 @@ public class AuctionSortModeWarning { RenderUtils.drawFloatingRectDark(centerX - warningLength / 2 - 4, centerY - 6, warningLength + 8, 12, false ); - TextRenderUtils.drawStringCenteredScaledMaxWidth(warningText, Minecraft.getMinecraft().fontRendererObj, - centerX, centerY, true, chest.width / 2, 0xffffffff - ); + TextRenderUtils.drawStringCenteredScaledMaxWidth(warningText, centerX, centerY, true, chest.width / 2, 0xffffffff); GlStateManager.popMatrix(); } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/DungeonNpcProfitOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/DungeonNpcProfitOverlay.java index 711d5235..c4b03b84 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/DungeonNpcProfitOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/DungeonNpcProfitOverlay.java @@ -221,15 +221,7 @@ public class DungeonNpcProfitOverlay { int mouseY = Utils.getMouseY(); if (Utils.isWithinRect(mouseX, mouseY, x, y, 160, 10)) - Utils.drawHoveringText( - chestProfit.lore, - mouseX, - mouseY, - width, - height, - -1, - Minecraft.getMinecraft().fontRendererObj - ); + Utils.drawHoveringText(chestProfit.lore, mouseX, mouseY, width, height, -1); } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/EnchantingSolvers.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/EnchantingSolvers.java index 695c9851..a5c96e4a 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/EnchantingSolvers.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/EnchantingSolvers.java @@ -277,7 +277,7 @@ public class EnchantingSolvers { GlStateManager.disableDepth(); GlStateManager.enableBlend(); GlStateManager.disableLighting(); - Utils.drawStringScaled((solveIndex + 1) + "", Minecraft.getMinecraft().fontRendererObj, + Utils.drawStringScaled((solveIndex + 1) + "", x + 8.5f - w / 2f, y + 8.5f - 4, true, 0xffc0c0c0, 1f ); return true; diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/FishingHelper.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/FishingHelper.java index 800e25b1..b43b0e78 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/FishingHelper.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/FishingHelper.java @@ -174,11 +174,7 @@ public class FishingHelper { Utils.drawStringCentered( String.format("%.02fs", seconds), - Minecraft.getMinecraft().fontRendererObj, - 0, - -baseHeight - Minecraft.getMinecraft().fontRendererObj.FONT_HEIGHT, - false, - color + 0, -baseHeight - Minecraft.getMinecraft().fontRendererObj.FONT_HEIGHT, false, color ); } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/MiningStuff.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/MiningStuff.java index 2cbd3125..9217dcae 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/MiningStuff.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/MiningStuff.java @@ -152,12 +152,7 @@ public class MiningStuff { if (alpha > 10) { TextRenderUtils.drawStringCenteredScaledMaxWidth( "Titanium has spawned nearby!", - Minecraft.getMinecraft().fontRendererObj, - 0, - 0, - true, - width / 4 - 20, - colour | (colour << 8) | (colour << 16) | (alpha << 24) + 0, 0, true, width / 4 - 20, colour | (colour << 8) | (colour << 16) | (alpha << 24) ); } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/SunTzu.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/SunTzu.java index 736d5058..8d1c06f3 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/SunTzu.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/SunTzu.java @@ -96,7 +96,6 @@ public class SunTzu { int height = Utils.renderStringTrimWidth( EnumChatFormatting.YELLOW + getQuote(), - Minecraft.getMinecraft().fontRendererObj, true, sr.getScaledWidth() / 2 - 100, 5, diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/entityviewer/EntityViewer.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/entityviewer/EntityViewer.java index 2f091304..1e7dc319 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/entityviewer/EntityViewer.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/entityviewer/EntityViewer.java @@ -25,7 +25,6 @@ import com.google.gson.JsonObject; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; 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.renderer.GlStateManager; import net.minecraft.client.renderer.OpenGlHelper; @@ -208,7 +207,6 @@ public class EntityViewer extends GuiScreen { @Override public void drawScreen(int mouseX, int mouseY, float partialTicks) { drawDefaultBackground(); - FontRenderer fontRenderer = Minecraft.getMinecraft().fontRendererObj; this.guiLeft = (width - this.xSize) / 2; this.guiTop = (height - this.ySize) / 2; @@ -216,7 +214,7 @@ public class EntityViewer extends GuiScreen { Minecraft.getMinecraft().getTextureManager().bindTexture(BACKGROUND); drawTexturedModalRect(guiLeft, guiTop, 0, 0, this.xSize, this.ySize); - Utils.drawStringScaledMaxWidth(label, fontRenderer, guiLeft + 10, guiTop + 10, false, 100, 0xFF00FF); + Utils.drawStringScaledMaxWidth(label, guiLeft + 10, guiTop + 10, false, 100, 0xFF00FF); renderEntity(entity, guiLeft + 90, guiTop + 75, mouseX, mouseY); } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/AccessoryBagOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/AccessoryBagOverlay.java index 530dcfd1..562eb1e0 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/AccessoryBagOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/AccessoryBagOverlay.java @@ -204,24 +204,8 @@ public class AccessoryBagOverlay { private static Set pagesVisited = new HashSet<>(); public static void renderVisitOverlay(int x, int y) { - Utils.drawStringCenteredScaledMaxWidth( - "Please visit all", - Minecraft.getMinecraft().fontRendererObj, - x + 40, - y + 78, - true, - 70, - -1 - ); - Utils.drawStringCenteredScaledMaxWidth( - "pages of the bag", - Minecraft.getMinecraft().fontRendererObj, - x + 40, - y + 86, - true, - 70, - -1 - ); + Utils.drawStringCenteredScaledMaxWidth("Please visit all", x + 40, y + 78, true, 70, -1); + Utils.drawStringCenteredScaledMaxWidth("pages of the bag", x + 40, y + 86, true, 70, -1); } private static TreeMap talismanCountRarity = null; @@ -237,15 +221,7 @@ public class AccessoryBagOverlay { } } - Utils.drawStringCenteredScaledMaxWidth( - "# By Rarity", - Minecraft.getMinecraft().fontRendererObj, - x + 40, - y + 12, - false, - 70, - new Color(80, 80, 80).getRGB() - ); + drawString(x, y, "# By Rarity"); int yIndex = 0; for (Map.Entry entry : talismanCountRarity.descendingMap().entrySet()) { @@ -271,15 +247,7 @@ public class AccessoryBagOverlay { } } - Utils.drawStringCenteredScaledMaxWidth( - "Total Stats", - Minecraft.getMinecraft().fontRendererObj, - x + 40, - y + 12, - false, - 70, - new Color(80, 80, 80).getRGB() - ); + drawString(x, y, "Total Stats"); int yIndex = 0; for (int i = 0; i < PlayerStats.defaultStatNames.length; i++) { String statName = PlayerStats.defaultStatNames[i]; @@ -319,15 +287,7 @@ public class AccessoryBagOverlay { } } - Utils.drawStringCenteredScaledMaxWidth( - "Reforge Stats", - Minecraft.getMinecraft().fontRendererObj, - x + 40, - y + 12, - false, - 70, - new Color(80, 80, 80).getRGB() - ); + drawString(x, y, "Reforge Stats"); int yIndex = 0; for (int i = 0; i < PlayerStats.defaultStatNames.length; i++) { String statName = PlayerStats.defaultStatNames[i]; @@ -363,28 +323,12 @@ public class AccessoryBagOverlay { if (duplicates == null) { JsonObject misc = Constants.MISC; if (misc == null) { - Utils.drawStringCenteredScaledMaxWidth( - "Duplicates: ERROR", - Minecraft.getMinecraft().fontRendererObj, - x + 40, - y + 12, - false, - 70, - new Color(80, 80, 80).getRGB() - ); + drawString(x, y, "Duplicates: ERROR"); return; } JsonElement talisman_upgrades_element = misc.get("talisman_upgrades"); if (talisman_upgrades_element == null) { - Utils.drawStringCenteredScaledMaxWidth( - "Duplicates: ERROR", - Minecraft.getMinecraft().fontRendererObj, - x + 40, - y + 12, - false, - 70, - new Color(80, 80, 80).getRGB() - ); + drawString(x, y, "Duplicates: ERROR"); return; } JsonObject talisman_upgrades = talisman_upgrades_element.getAsJsonObject(); @@ -419,25 +363,9 @@ public class AccessoryBagOverlay { } } if (duplicates.isEmpty()) { - Utils.drawStringCenteredScaledMaxWidth( - "No Duplicates", - Minecraft.getMinecraft().fontRendererObj, - x + 40, - y + 12, - false, - 70, - new Color(80, 80, 80).getRGB() - ); + drawString(x, y, "No Duplicates"); } else { - Utils.drawStringCenteredScaledMaxWidth( - "Duplicates: " + duplicates.size(), - Minecraft.getMinecraft().fontRendererObj, - x + 40, - y + 12, - false, - 70, - new Color(80, 80, 80).getRGB() - ); + drawString(x, y, "Duplicates: " + duplicates.size()); int yIndex = 0; for (ItemStack duplicate : duplicates) { @@ -451,9 +379,12 @@ public class AccessoryBagOverlay { } if (duplicates.size() > 11) { - Utils.drawStringCenteredScaledMaxWidth("+" + (duplicates.size() - 10) + " More", - Minecraft.getMinecraft().fontRendererObj, x + 40, y + 16 + 121, false, 70, - new Color(80, 80, 80).getRGB() + Utils.drawStringCenteredScaledMaxWidth( + "+" + (duplicates.size() - 10) + " More", + x + 40, y + 16 + 121, + false, + 70, + gray() ); } } @@ -465,28 +396,12 @@ public class AccessoryBagOverlay { if (missing == null) { JsonObject misc = Constants.MISC; if (misc == null) { - Utils.drawStringCenteredScaledMaxWidth( - "Duplicates: ERROR", - Minecraft.getMinecraft().fontRendererObj, - x + 40, - y + 12, - false, - 70, - new Color(80, 80, 80).getRGB() - ); + drawString(x, y, "Duplicates: ERROR"); return; } JsonElement talisman_upgrades_element = misc.get("talisman_upgrades"); if (talisman_upgrades_element == null) { - Utils.drawStringCenteredScaledMaxWidth( - "Duplicates: ERROR", - Minecraft.getMinecraft().fontRendererObj, - x + 40, - y + 12, - false, - 70, - new Color(80, 80, 80).getRGB() - ); + drawString(x, y, "Duplicates: ERROR"); return; } JsonObject talisman_upgrades = talisman_upgrades_element.getAsJsonObject(); @@ -554,25 +469,9 @@ public class AccessoryBagOverlay { } } if (missing.isEmpty()) { - Utils.drawStringCenteredScaledMaxWidth( - "No Missing", - Minecraft.getMinecraft().fontRendererObj, - x + 40, - y + 12, - false, - 70, - new Color(80, 80, 80).getRGB() - ); + drawString(x, y, "No Missing"); } else { - Utils.drawStringCenteredScaledMaxWidth( - "Missing: " + missing.size(), - Minecraft.getMinecraft().fontRendererObj, - x + 40, - y + 12, - false, - 70, - new Color(80, 80, 80).getRGB() - ); + drawString(x, y, "Missing: " + missing.size()); int yIndex = 0; long currentTime = System.currentTimeMillis(); @@ -610,10 +509,7 @@ public class AccessoryBagOverlay { } if (missing.size() > 11) { - Utils.drawStringCenteredScaledMaxWidth("Show All", - Minecraft.getMinecraft().fontRendererObj, x + 40, y + 16 + 121, false, 70, - new Color(80, 80, 80).getRGB() - ); + Utils.drawStringCenteredScaledMaxWidth("Show All", x + 40, y + 16 + 121, false, 70, gray()); final ScaledResolution scaledresolution = new ScaledResolution(Minecraft.getMinecraft()); final int scaledWidth = scaledresolution.getScaledWidth(); @@ -675,7 +571,7 @@ public class AccessoryBagOverlay { mouseX * scaledresolution.getScaleFactor() / 2, mouseY * scaledresolution.getScaleFactor() / 2, scaledWidth * scaledresolution.getScaleFactor() / 2, - scaledHeight * scaledresolution.getScaleFactor() / 2, -1, Minecraft.getMinecraft().fontRendererObj + scaledHeight * scaledresolution.getScaleFactor() / 2, -1 ); GlStateManager.popMatrix(); } @@ -683,6 +579,10 @@ public class AccessoryBagOverlay { } } + private static void drawString(int x, int y, String abc) { + Utils.drawStringCenteredScaledMaxWidth(abc, x + 40, y + 12, false, 70, gray()); + } + private static boolean forceCC = false; private static boolean forceAS = false; private static boolean useGodPot = true; @@ -690,15 +590,7 @@ public class AccessoryBagOverlay { private static int mainWeapon = 1; public static void renderOptimizerOverlay(int x, int y) { - Utils.drawStringCenteredScaledMaxWidth( - "Optimizer", - Minecraft.getMinecraft().fontRendererObj, - x + 40, - y + 12, - false, - 70, - new Color(80, 80, 80).getRGB() - ); + Utils.drawStringCenteredScaledMaxWidth("Optimizer", x + 40, y + 12, false, 70, gray()); int light = new Color(220, 220, 220).getRGB(); int dark = new Color(170, 170, 170).getRGB(); @@ -724,116 +616,50 @@ public class AccessoryBagOverlay { dark ); + Utils.drawStringCenteredScaledMaxWidth("Force 100% CC", x + 40, y + 27, false, 70, gray()); Utils.drawStringCenteredScaledMaxWidth( - "Force 100% CC", - Minecraft.getMinecraft().fontRendererObj, - x + 40, - y + 27, - false, - 70, - new Color(80, 80, 80).getRGB() - ); - Utils.drawStringCenteredScaledMaxWidth((forceCC ? EnumChatFormatting.GREEN : EnumChatFormatting.GRAY) + "YES", - Minecraft.getMinecraft().fontRendererObj, x + 20, y + 37, - true, 30, new Color(80, 80, 80).getRGB() + (forceCC ? EnumChatFormatting.GREEN : EnumChatFormatting.GRAY) + "YES", x + 20, y + 37, true, 30, gray() ); Utils.drawStringCenteredScaledMaxWidth( (forceCC ? EnumChatFormatting.GRAY : EnumChatFormatting.RED) + "NO", - Minecraft.getMinecraft().fontRendererObj, - x + 60, - y + 37, - true, - 30, - new Color(80, 80, 80).getRGB() + x + 60, y + 37, true, 30, gray() ); - Utils.drawStringCenteredScaledMaxWidth( - "Force 100% ATKSPEED", - Minecraft.getMinecraft().fontRendererObj, - x + 40, - y + 47, - false, - 70, - new Color(80, 80, 80).getRGB() - ); + Utils.drawStringCenteredScaledMaxWidth("Force 100% ATKSPEED", x + 40, y + 47, false, 70, gray()); Utils.drawStringCenteredScaledMaxWidth( (forceAS ? EnumChatFormatting.GREEN : EnumChatFormatting.GRAY) + "YES", - Minecraft.getMinecraft().fontRendererObj, - x + 20, - y + 57, - true, - 30, - new Color(80, 80, 80).getRGB() + x + 20, y + 57, true, 30, gray() ); Utils.drawStringCenteredScaledMaxWidth( (forceAS ? EnumChatFormatting.GRAY : EnumChatFormatting.RED) + "NO", - Minecraft.getMinecraft().fontRendererObj, - x + 60, - y + 57, - true, - 30, - new Color(80, 80, 80).getRGB() + x + 60, y + 57, true, 30, gray() ); - Utils.drawStringCenteredScaledMaxWidth( - "Use God Potion", - Minecraft.getMinecraft().fontRendererObj, - x + 40, - y + 67, - false, - 70, - new Color(80, 80, 80).getRGB() - ); + Utils.drawStringCenteredScaledMaxWidth("Use God Potion", x + 40, y + 67, false, 70, gray()); Utils.drawStringCenteredScaledMaxWidth( (useGodPot ? EnumChatFormatting.GREEN : EnumChatFormatting.GRAY) + "YES", - Minecraft.getMinecraft().fontRendererObj, - x + 20, - y + 77, - true, - 30, - new Color(80, 80, 80).getRGB() + x + 20, y + 77, true, 30, gray() ); Utils.drawStringCenteredScaledMaxWidth( (useGodPot ? EnumChatFormatting.GRAY : EnumChatFormatting.RED) + "NO", - Minecraft.getMinecraft().fontRendererObj, - x + 60, - y + 77, - true, - 30, - new Color(80, 80, 80).getRGB() + x + 60, y + 77, true, 30, gray() ); - Utils.drawStringCenteredScaledMaxWidth( - "Use God Potion", - Minecraft.getMinecraft().fontRendererObj, - x + 40, - y + 87, - false, - 70, - new Color(80, 80, 80).getRGB() - ); + Utils.drawStringCenteredScaledMaxWidth("Use God Potion", x + 40, y + 87, false, 70, gray()); Utils.drawStringCenteredScaledMaxWidth((allowShaded ? EnumChatFormatting.GREEN : EnumChatFormatting.GRAY) + "YES", - Minecraft.getMinecraft().fontRendererObj, x + 20, y + 97, - true, 30, new Color(80, 80, 80).getRGB() + x + 20, y + 97, true, 30, gray() ); Utils.drawStringCenteredScaledMaxWidth((allowShaded ? EnumChatFormatting.GRAY : EnumChatFormatting.RED) + "NO", - Minecraft.getMinecraft().fontRendererObj, x + 60, y + 97, - true, 30, new Color(80, 80, 80).getRGB() + x + 60, y + 97, + true, 30, gray() ); - Utils.drawStringCenteredScaledMaxWidth( - "Main Weapon", - Minecraft.getMinecraft().fontRendererObj, - x + 40, - y + 107, - false, - 70, - new Color(80, 80, 80).getRGB() - ); - Utils.drawStringCenteredScaled("1 2 3 4 5 6 7 8 9", - Minecraft.getMinecraft().fontRendererObj, x + 40, y + 117, - true, 70, new Color(80, 80, 80).getRGB() - ); + Utils.drawStringCenteredScaledMaxWidth("Main Weapon", x + 40, y + 107, false, 70, gray()); + Utils.drawStringCenteredScaled("1 2 3 4 5 6 7 8 9", x + 40, y + 117, true, 70, gray()); + } + + private static int gray() { + return new Color(80, 80, 80).getRGB(); } private static Comparator getItemComparator() { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/CalendarOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/CalendarOverlay.java index baea367c..3bd90db8 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/CalendarOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/CalendarOverlay.java @@ -822,7 +822,7 @@ public class CalendarOverlay { int startingWidth = fr.getStringWidth(starting); fr.drawString(starting, Math.max(guiLeft + 23, width / 2f - startingWidth / 2f), y + 7, -1, false); } else { - Utils.drawStringCentered(EnumChatFormatting.YELLOW + "Event Starting Now!", fr, width / 2, y + 11, false, -1); + Utils.drawStringCentered(EnumChatFormatting.YELLOW + "Event Starting Now!", width / 2, y + 11, false, -1); } int displayWidth = fr.getStringWidth(event.display); @@ -981,7 +981,7 @@ public class CalendarOverlay { GL11.glDisable(GL11.GL_SCISSOR_TEST); } else { if (guiLeft + xSize - 8 - untilLen > (width + displayWidth) / 2) { - Utils.drawStringCentered(nextEvent.display, fr, width / 2f, guiTop + 10, false, -1); + Utils.drawStringCentered(nextEvent.display, width / 2f, guiTop + 10, false, -1); } else { fr.drawString(nextEvent.display, guiLeft + 8 + nextSLen, guiTop + 6, -1, false); } @@ -1026,7 +1026,7 @@ public class CalendarOverlay { if (tooltipToDisplay != null) { drawTimerForeground = true; GlStateManager.translate(0, 0, 100); - Utils.drawHoveringText(tooltipToDisplay, mouseX, Math.max(17, mouseY), width, height, -1, fr); + Utils.drawHoveringText(tooltipToDisplay, mouseX, Math.max(17, mouseY), width, height, -1); GlStateManager.translate(0, 0, -100); } } @@ -1121,20 +1121,20 @@ public class CalendarOverlay { if (mayorStack != null) { String mayor = mayorStack.getDisplayName(); float verticalHeight = Utils.getVerticalHeight(mayor); - Utils.drawStringVertical(mayor, fr, guiLeft + 8, guiTop + 96 - verticalHeight / 2, + Utils.drawStringVertical(mayor, guiLeft + 8, guiTop + 96 - verticalHeight / 2, false, -1 ); } String calendar = EnumChatFormatting.GREEN + "Calendar"; float calendarHeight = Utils.getVerticalHeight(calendar); - Utils.drawStringVertical(calendar, fr, guiLeft + xSize - 12, guiTop + 60 - calendarHeight / 2, + Utils.drawStringVertical(calendar, guiLeft + xSize - 12, guiTop + 60 - calendarHeight / 2, false, -1 ); String rewards = EnumChatFormatting.GOLD + "Rewards"; float rewardsHeight = Utils.getVerticalHeight(rewards); - Utils.drawStringVertical(rewards, fr, guiLeft + xSize - 12, guiTop + 132 - rewardsHeight / 2, + Utils.drawStringVertical(rewards, guiLeft + xSize - 12, guiTop + 132 - rewardsHeight / 2, false, -1 ); @@ -1349,7 +1349,7 @@ public class CalendarOverlay { tooltipToDisplay.add(EnumChatFormatting.DARK_GRAY + "In order to show crop types for Jacob's Farming"); tooltipToDisplay.add(EnumChatFormatting.DARK_GRAY + "contest, visit the full SkyBlock calendar and go all"); tooltipToDisplay.add(EnumChatFormatting.DARK_GRAY + "the way to the end of the SkyBlock year"); - Utils.drawHoveringText(tooltipToDisplay, mouseX, mouseY, width, height, -1, fr); + Utils.drawHoveringText(tooltipToDisplay, mouseX, mouseY, width, height, -1); tooltipToDisplay = null; } } @@ -1415,7 +1415,7 @@ public class CalendarOverlay { } GlStateManager.translate(0, 0, -20); } else if (tooltipToDisplay != null) { - Utils.drawHoveringText(tooltipToDisplay, mouseX, mouseY, width, height, -1, fr); + Utils.drawHoveringText(tooltipToDisplay, mouseX, mouseY, width, height, -1); } GlStateManager.translate(0, 0, -10); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiCustomEnchant.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiCustomEnchant.java index 6f190ada..6d219999 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiCustomEnchant.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiCustomEnchant.java @@ -36,6 +36,7 @@ import io.github.moulberry.notenoughupdates.util.ItemUtils; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.EntityPlayerSP; +import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.Gui; import net.minecraft.client.gui.ScaledResolution; import net.minecraft.client.gui.inventory.GuiContainer; @@ -146,7 +147,8 @@ public class GuiCustomEnchant extends Gui { if (costs.size() >= 1) { if (useMaxLevelForCost) { - int cost = (maxLevel != null && maxLevel.has(this.enchId) ? maxLevel.get(this.enchId).getAsInt() : costs.size()); + int cost = + (maxLevel != null && maxLevel.has(this.enchId) ? maxLevel.get(this.enchId).getAsInt() : costs.size()); this.xpCost = costs.get(cost - 1).getAsInt(); } else if (level - 1 < costs.size()) { this.xpCost = costs.get(level - 1).getAsInt(); @@ -600,16 +602,15 @@ public class GuiCustomEnchant extends Gui { 0, X_SIZE / 512f, 0, Y_SIZE / 512f, GL11.GL_NEAREST ); - Minecraft.getMinecraft().fontRendererObj.drawString("Applicable", guiLeft + 7, guiTop + 7, 0x404040, false); - Minecraft.getMinecraft().fontRendererObj.drawString("Removable", guiLeft + 247, guiTop + 7, 0x404040, false); + FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; + fr.drawString("Applicable", guiLeft + 7, guiTop + 7, 0x404040, false); + fr.drawString("Removable", guiLeft + 247, guiTop + 7, 0x404040, false); //Page Text if (currentState == EnchantState.HAS_ITEM || currentState == EnchantState.ADDING_ENCHANT) { String pageStr = "Page: " + currentPage + "/" + expectedMaxPage; - int pageStrLen = Minecraft.getMinecraft().fontRendererObj.getStringWidth(pageStr); - Utils.drawStringCentered(pageStr, Minecraft.getMinecraft().fontRendererObj, - guiLeft + X_SIZE / 2, guiTop + 14, false, 0x404040 - ); + int pageStrLen = fr.getStringWidth(pageStr); + Utils.drawStringCentered(pageStr, guiLeft + X_SIZE / 2, guiTop + 14, false, 0x404040); //Page Arrows Minecraft.getMinecraft().getTextureManager().bindTexture(TEXTURE); @@ -727,12 +728,8 @@ public class GuiCustomEnchant extends Gui { //Can't be enchanted text if (currentState == EnchantState.INVALID_ITEM) { GlStateManager.disableDepth(); - Utils.drawStringCentered("This item can't", Minecraft.getMinecraft().fontRendererObj, - guiLeft + X_SIZE / 2, guiTop + 88, true, 0xffff5555 - ); - Utils.drawStringCentered("be enchanted", Minecraft.getMinecraft().fontRendererObj, - guiLeft + X_SIZE / 2, guiTop + 98, true, 0xffff5555 - ); + Utils.drawStringCentered("This item can't", guiLeft + X_SIZE / 2, guiTop + 88, true, 0xffff5555); + Utils.drawStringCentered("be enchanted", guiLeft + X_SIZE / 2, guiTop + 98, true, 0xffff5555); GlStateManager.enableDepth(); } @@ -755,52 +752,24 @@ public class GuiCustomEnchant extends Gui { //Text if no enchants appear if (currentState == EnchantState.HAS_ITEM || currentState == EnchantState.ADDING_ENCHANT) { if (applicable.isEmpty() && removable.isEmpty() && searchRemovedFromApplicable) { - Utils.drawStringCentered("Can't find that", Minecraft.getMinecraft().fontRendererObj, - guiLeft + 8 + 48, guiTop + 28, true, 0xffff5555 - ); - Utils.drawStringCentered("enchant, perhaps", Minecraft.getMinecraft().fontRendererObj, - guiLeft + 8 + 48, guiTop + 38, true, 0xffff5555 - ); - Utils.drawStringCentered("it is on", Minecraft.getMinecraft().fontRendererObj, - guiLeft + 8 + 48, guiTop + 48, true, 0xffff5555 - ); - Utils.drawStringCentered("another page?", Minecraft.getMinecraft().fontRendererObj, - guiLeft + 8 + 48, guiTop + 58, true, 0xffff5555 - ); + Utils.drawStringCentered("Can't find that", guiLeft + 8 + 48, guiTop + 28, true, 0xffff5555); + Utils.drawStringCentered("enchant, perhaps", guiLeft + 8 + 48, guiTop + 38, true, 0xffff5555); + Utils.drawStringCentered("it is on", guiLeft + 8 + 48, guiTop + 48, true, 0xffff5555); + Utils.drawStringCentered("another page?", guiLeft + 8 + 48, guiTop + 58, true, 0xffff5555); } else if (applicable.isEmpty() && !searchRemovedFromApplicable) { - Utils.drawStringCentered("No applicable", Minecraft.getMinecraft().fontRendererObj, - guiLeft + 8 + 48, guiTop + 28, true, 0xffff5555 - ); - Utils.drawStringCentered("enchants on", Minecraft.getMinecraft().fontRendererObj, - guiLeft + 8 + 48, guiTop + 38, true, 0xffff5555 - ); - Utils.drawStringCentered("this page...", Minecraft.getMinecraft().fontRendererObj, - guiLeft + 8 + 48, guiTop + 48, true, 0xffff5555 - ); + Utils.drawStringCentered("No applicable", guiLeft + 8 + 48, guiTop + 28, true, 0xffff5555); + Utils.drawStringCentered("enchants on", guiLeft + 8 + 48, guiTop + 38, true, 0xffff5555); + Utils.drawStringCentered("this page...", guiLeft + 8 + 48, guiTop + 48, true, 0xffff5555); } if (applicable.isEmpty() && removable.isEmpty() && searchRemovedFromRemovable) { - Utils.drawStringCentered("Can't find that", Minecraft.getMinecraft().fontRendererObj, - guiLeft + 248 + 48, guiTop + 28, true, 0xffff5555 - ); - Utils.drawStringCentered("enchant, perhaps", Minecraft.getMinecraft().fontRendererObj, - guiLeft + 248 + 48, guiTop + 38, true, 0xffff5555 - ); - Utils.drawStringCentered("it is on", Minecraft.getMinecraft().fontRendererObj, - guiLeft + 248 + 48, guiTop + 48, true, 0xffff5555 - ); - Utils.drawStringCentered("another page?", Minecraft.getMinecraft().fontRendererObj, - guiLeft + 248 + 48, guiTop + 58, true, 0xffff5555 - ); + Utils.drawStringCentered("Can't find that", guiLeft + 248 + 48, guiTop + 28, true, 0xffff5555); + Utils.drawStringCentered("enchant, perhaps", guiLeft + 248 + 48, guiTop + 38, true, 0xffff5555); + Utils.drawStringCentered("it is on", guiLeft + 248 + 48, guiTop + 48, true, 0xffff5555); + Utils.drawStringCentered("another page?", guiLeft + 248 + 48, guiTop + 58, true, 0xffff5555); } else if (removable.isEmpty() && !searchRemovedFromRemovable) { - Utils.drawStringCentered("No removable", Minecraft.getMinecraft().fontRendererObj, - guiLeft + 248 + 48, guiTop + 28, true, 0xffff5555 - ); - Utils.drawStringCentered("enchants on", Minecraft.getMinecraft().fontRendererObj, - guiLeft + 248 + 48, guiTop + 38, true, 0xffff5555 - ); - Utils.drawStringCentered("this page...", Minecraft.getMinecraft().fontRendererObj, - guiLeft + 248 + 48, guiTop + 48, true, 0xffff5555 - ); + Utils.drawStringCentered("No removable", guiLeft + 248 + 48, guiTop + 28, true, 0xffff5555); + Utils.drawStringCentered("enchants on", guiLeft + 248 + 48, guiTop + 38, true, 0xffff5555); + Utils.drawStringCentered("this page...", guiLeft + 248 + 48, guiTop + 48, true, 0xffff5555); } } //Available enchants (left) @@ -836,50 +805,14 @@ public class GuiCustomEnchant extends Gui { colour = 0xff5555; } - int levelWidth = Minecraft.getMinecraft().fontRendererObj.getStringWidth(levelStr); - Minecraft.getMinecraft().fontRendererObj.drawString( - levelStr, - guiLeft + 16 - levelWidth / 2 - 1, - top + 4, - 0x2d2102, - false - ); - Minecraft.getMinecraft().fontRendererObj.drawString( - levelStr, - guiLeft + 16 - levelWidth / 2 + 1, - top + 4, - 0x2d2102, - false - ); - Minecraft.getMinecraft().fontRendererObj.drawString( - levelStr, - guiLeft + 16 - levelWidth / 2, - top + 4 - 1, - 0x2d2102, - false - ); - Minecraft.getMinecraft().fontRendererObj.drawString( - levelStr, - guiLeft + 16 - levelWidth / 2, - top + 4 + 1, - 0x2d2102, - false - ); - Minecraft.getMinecraft().fontRendererObj.drawString( - levelStr, - guiLeft + 16 - levelWidth / 2, - top + 4, - colour, - false - ); + int levelWidth = fr.getStringWidth(levelStr); + fr.drawString(levelStr, guiLeft + 16 - levelWidth / 2 - 1, top + 4, 0x2d2102, false); + fr.drawString(levelStr, guiLeft + 16 - levelWidth / 2 + 1, top + 4, 0x2d2102, false); + fr.drawString(levelStr, guiLeft + 16 - levelWidth / 2, top + 4 - 1, 0x2d2102, false); + fr.drawString(levelStr, guiLeft + 16 - levelWidth / 2, top + 4 + 1, 0x2d2102, false); + fr.drawString(levelStr, guiLeft + 16 - levelWidth / 2, top + 4, colour, false); - Minecraft.getMinecraft().fontRendererObj.drawString( - ench.enchantName, - guiLeft + 8 + 16 + 2 + textOffset, - top + 4 + textOffset, - 0xffffffdd, - true - ); + fr.drawString(ench.enchantName, guiLeft + 8 + 16 + 2 + textOffset, top + 4 + textOffset, 0xffffffdd, true); } GlScissorStack.pop(scaledResolution); @@ -916,53 +849,26 @@ public class GuiCustomEnchant extends Gui { colour = 0xff5555; } - int levelWidth = Minecraft.getMinecraft().fontRendererObj.getStringWidth(levelStr); - Minecraft.getMinecraft().fontRendererObj.drawString( - levelStr, - guiLeft + 256 - levelWidth / 2 - 1, - top + 4, - 0x2d2102, - false - ); - Minecraft.getMinecraft().fontRendererObj.drawString( + int levelWidth = fr.getStringWidth(levelStr); + fr.drawString(levelStr, guiLeft + 256 - levelWidth / 2 - 1, top + 4, 0x2d2102, false); + fr.drawString( levelStr, guiLeft + 256 - levelWidth / 2 + 1, top + 4, 0x2d2102, false ); - Minecraft.getMinecraft().fontRendererObj.drawString( - levelStr, - guiLeft + 256 - levelWidth / 2, - top + 4 - 1, - 0x2d2102, - false - ); - Minecraft.getMinecraft().fontRendererObj.drawString( - levelStr, - guiLeft + 256 - levelWidth / 2, - top + 4 + 1, - 0x2d2102, - false - ); - Minecraft.getMinecraft().fontRendererObj.drawString( - levelStr, - guiLeft + 256 - levelWidth / 2, - top + 4, - colour, - false - ); + fr.drawString(levelStr, guiLeft + 256 - levelWidth / 2, top + 4 - 1, 0x2d2102, false); + fr.drawString(levelStr, guiLeft + 256 - levelWidth / 2, top + 4 + 1, 0x2d2102, false); + fr.drawString(levelStr, guiLeft + 256 - levelWidth / 2, top + 4, colour, false); - Minecraft.getMinecraft().fontRendererObj.drawString(ench.enchantName, - guiLeft + 248 + 16 + 2 + textOffset, top + 4 + textOffset, 0xffffffdd, true - ); + fr.drawString(ench.enchantName, guiLeft + 248 + 16 + 2 + textOffset, top + 4 + textOffset, 0xffffffdd, true); } GlScissorStack.pop(scaledResolution); //Player Inventory Items - Minecraft.getMinecraft().fontRendererObj.drawString(Minecraft.getMinecraft().thePlayer.inventory - .getDisplayName() - .getUnformattedText(), + fr.drawString( + Minecraft.getMinecraft().thePlayer.inventory.getDisplayName().getUnformattedText(), guiLeft + 102, guiTop + Y_SIZE - 96 + 2, 0x404040 ); int inventoryStartIndex = cc.getLowerChestInventory().getSizeInventory(); @@ -1003,7 +909,7 @@ public class GuiCustomEnchant extends Gui { searchField.setPrependText("\u00a77Search..."); } else { if (searchField.getFocus()) { - int len = Minecraft.getMinecraft().fontRendererObj.getStringWidth(searchField.getTextDisplay()) + 10; + int len = fr.getStringWidth(searchField.getTextDisplay()) + 10; searchField.setSize(Math.max(90, len), 14); } else { searchField.setSize(90, 14); @@ -1041,36 +947,12 @@ public class GuiCustomEnchant extends Gui { colour = 0xff5555; } - int levelWidth = Minecraft.getMinecraft().fontRendererObj.getStringWidth(levelStr); - Minecraft.getMinecraft().fontRendererObj.drawString( - levelStr, - left + 8 - levelWidth / 2 - 1, - top + 4, - 0x2d2102, - false - ); - Minecraft.getMinecraft().fontRendererObj.drawString( - levelStr, - left + 8 - levelWidth / 2 + 1, - top + 4, - 0x2d2102, - false - ); - Minecraft.getMinecraft().fontRendererObj.drawString( - levelStr, - left + 8 - levelWidth / 2, - top + 4 - 1, - 0x2d2102, - false - ); - Minecraft.getMinecraft().fontRendererObj.drawString( - levelStr, - left + 8 - levelWidth / 2, - top + 4 + 1, - 0x2d2102, - false - ); - Minecraft.getMinecraft().fontRendererObj.drawString(levelStr, left + 8 - levelWidth / 2, top + 4, colour, false); + int levelWidth = fr.getStringWidth(levelStr); + fr.drawString(levelStr, left + 8 - levelWidth / 2 - 1, top + 4, 0x2d2102, false); + fr.drawString(levelStr, left + 8 - levelWidth / 2 + 1, top + 4, 0x2d2102, false); + fr.drawString(levelStr, left + 8 - levelWidth / 2, top + 4 - 1, 0x2d2102, false); + fr.drawString(levelStr, left + 8 - levelWidth / 2, top + 4 + 1, 0x2d2102, false); + fr.drawString(levelStr, left + 8 - levelWidth / 2, top + 4, colour, false); //Enchant name String name = WordUtils.capitalizeFully(ItemUtils @@ -1085,14 +967,7 @@ public class GuiCustomEnchant extends Gui { } else if (name.equalsIgnoreCase("Luck of the Sea")) { name = "Luck of Sea"; } - Utils.drawStringCentered( - name, - Minecraft.getMinecraft().fontRendererObj, - guiLeft + X_SIZE / 2, - top + 8, - true, - 0xffffffdd - ); + Utils.drawStringCentered(name, guiLeft + X_SIZE / 2, top + 8, true, 0xffffffdd); if (isChangingEnchLevel) { Minecraft.getMinecraft().getTextureManager().bindTexture(TEXTURE); @@ -1105,42 +980,12 @@ public class GuiCustomEnchant extends Gui { //Enchant level levelStr = "" + enchanterCurrentEnch.level; if (enchanterCurrentEnch.xpCost < 0) levelStr = "?"; - levelWidth = Minecraft.getMinecraft().fontRendererObj.getStringWidth(levelStr); - Minecraft.getMinecraft().fontRendererObj.drawString( - levelStr, - left + 96 + 8 - levelWidth / 2 - 1, - top + 4, - 0x2d2102, - false - ); - Minecraft.getMinecraft().fontRendererObj.drawString( - levelStr, - left + 96 + 8 - levelWidth / 2 + 1, - top + 4, - 0x2d2102, - false - ); - Minecraft.getMinecraft().fontRendererObj.drawString( - levelStr, - left + 96 + 8 - levelWidth / 2, - top + 4 - 1, - 0x2d2102, - false - ); - Minecraft.getMinecraft().fontRendererObj.drawString( - levelStr, - left + 96 + 8 - levelWidth / 2, - top + 4 + 1, - 0x2d2102, - false - ); - Minecraft.getMinecraft().fontRendererObj.drawString( - levelStr, - left + 96 + 8 - levelWidth / 2, - top + 4, - 0xea82ff, - false - ); + levelWidth = fr.getStringWidth(levelStr); + fr.drawString(levelStr, left + 96 + 8 - levelWidth / 2 - 1, top + 4, 0x2d2102, false); + fr.drawString(levelStr, left + 96 + 8 - levelWidth / 2 + 1, top + 4, 0x2d2102, false); + fr.drawString(levelStr, left + 96 + 8 - levelWidth / 2, top + 4 - 1, 0x2d2102, false); + fr.drawString(levelStr, left + 96 + 8 - levelWidth / 2, top + 4 + 1, 0x2d2102, false); + fr.drawString(levelStr, left + 96 + 8 - levelWidth / 2, top + 4, 0xea82ff, false); //Confirm button @@ -1160,18 +1005,14 @@ public class GuiCustomEnchant extends Gui { Utils.drawTexturedRect(guiLeft + X_SIZE / 2 - 1 - 48, top + 18, 48, 14, 0, 48 / 512f, 342 / 512f, (342 + 14) / 512f, GL11.GL_NEAREST ); - Utils.drawStringCentered(confirmText, Minecraft.getMinecraft().fontRendererObj, - guiLeft + X_SIZE / 2 - 1 - 23, top + 18 + 9, false, 0x408040 - ); + Utils.drawStringCentered(confirmText, guiLeft + X_SIZE / 2 - 1 - 23, top + 18 + 9, false, 0x408040); } else { Minecraft.getMinecraft().getTextureManager().bindTexture(TEXTURE); GlStateManager.color(1, 1, 1, 1); Utils.drawTexturedRect(guiLeft + X_SIZE / 2 - 1 - 48, top + 18, 48, 14, 0, 48 / 512f, 328 / 512f, (328 + 14) / 512f, GL11.GL_NEAREST ); - Utils.drawStringCentered(confirmText, Minecraft.getMinecraft().fontRendererObj, - guiLeft + X_SIZE / 2 - 1 - 24, top + 18 + 8, false, 0x408040 - ); + Utils.drawStringCentered(confirmText, guiLeft + X_SIZE / 2 - 1 - 24, top + 18 + 8, false, 0x408040); if (playerXpLevel < enchanterCurrentEnch.xpCost) { Gui.drawRect(guiLeft + X_SIZE / 2 - 1 - 48, top + 18, guiLeft + X_SIZE / 2 - 1, top + 18 + 14, 0x80000000); @@ -1185,18 +1026,14 @@ public class GuiCustomEnchant extends Gui { Utils.drawTexturedRect(guiLeft + X_SIZE / 2 + 1, top + 18, 48, 14, 0, 48 / 512f, 342 / 512f, (342 + 14) / 512f, GL11.GL_NEAREST ); - Utils.drawStringCentered("Cancel", Minecraft.getMinecraft().fontRendererObj, - guiLeft + X_SIZE / 2 + 1 + 25, top + 18 + 9, false, 0xa04040 - ); + Utils.drawStringCentered("Cancel", guiLeft + X_SIZE / 2 + 1 + 25, top + 18 + 9, false, 0xa04040); } else { Minecraft.getMinecraft().getTextureManager().bindTexture(TEXTURE); GlStateManager.color(1, 1, 1, 1); Utils.drawTexturedRect(guiLeft + X_SIZE / 2 + 1, top + 18, 48, 14, 0, 48 / 512f, 328 / 512f, (328 + 14) / 512f, GL11.GL_NEAREST ); - Utils.drawStringCentered("Cancel", Minecraft.getMinecraft().fontRendererObj, - guiLeft + X_SIZE / 2 + 1 + 24, top + 18 + 8, false, 0xa04040 - ); + Utils.drawStringCentered("Cancel", guiLeft + X_SIZE / 2 + 1 + 24, top + 18 + 8, false, 0xa04040); } if (mouseY > top + 18 && mouseY <= top + 18 + 16) { @@ -1269,42 +1106,12 @@ public class GuiCustomEnchant extends Gui { ); levelStr = "" + ench.level; - levelWidth = Minecraft.getMinecraft().fontRendererObj.getStringWidth(levelStr); - Minecraft.getMinecraft().fontRendererObj.drawString( - levelStr, - left + 96 + 8 - levelWidth / 2 - 1, - top + 16 * yIndex + 4, - 0x2d2102, - false - ); - Minecraft.getMinecraft().fontRendererObj.drawString( - levelStr, - left + 96 + 8 - levelWidth / 2 + 1, - top + 16 * yIndex + 4, - 0x2d2102, - false - ); - Minecraft.getMinecraft().fontRendererObj.drawString( - levelStr, - left + 96 + 8 - levelWidth / 2, - top + 16 * yIndex + 4 - 1, - 0x2d2102, - false - ); - Minecraft.getMinecraft().fontRendererObj.drawString( - levelStr, - left + 96 + 8 - levelWidth / 2, - top + 16 * yIndex + 4 + 1, - 0x2d2102, - false - ); - Minecraft.getMinecraft().fontRendererObj.drawString( - levelStr, - left + 96 + 8 - levelWidth / 2, - top + 16 * yIndex + 4, - 0xea82ff, - false - ); + levelWidth = fr.getStringWidth(levelStr); + fr.drawString(levelStr, left + 96 + 8 - levelWidth / 2 - 1, top + 16 * yIndex + 4, 0x2d2102, false); + fr.drawString(levelStr, left + 96 + 8 - levelWidth / 2 + 1, top + 16 * yIndex + 4, 0x2d2102, false); + fr.drawString(levelStr, left + 96 + 8 - levelWidth / 2, top + 16 * yIndex + 4 - 1, 0x2d2102, false); + fr.drawString(levelStr, left + 96 + 8 - levelWidth / 2, top + 16 * yIndex + 4 + 1, 0x2d2102, false); + fr.drawString(levelStr, left + 96 + 8 - levelWidth / 2, top + 16 * yIndex + 4, 0xea82ff, false); } GlStateManager.enableDepth(); } @@ -1380,9 +1187,7 @@ public class GuiCustomEnchant extends Gui { Utils.drawItemStack(stackOnMouse, mouseX - 8, mouseY - 8); } } else if (tooltipToDisplay != null) { - Utils.drawHoveringText(tooltipToDisplay, mouseX, mouseY, width, height, -1, - Minecraft.getMinecraft().fontRendererObj - ); + Utils.drawHoveringText(tooltipToDisplay, mouseX, mouseY, width, height, -1); } GlStateManager.translate(0, 0, -300); } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiEnchantColour.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiEnchantColour.java index 5053ae70..41208681 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiEnchantColour.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiEnchantColour.java @@ -31,7 +31,6 @@ import io.github.moulberry.notenoughupdates.itemeditor.GuiElementTextField; import io.github.moulberry.notenoughupdates.options.NEUConfig; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.Gui; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.renderer.GlStateManager; @@ -132,7 +131,6 @@ public class GuiEnchantColour extends GuiScreen { Utils.drawStringCentered( "Add Ench Colour", - fontRendererObj, guiLeft + xSize / 2 + 1, guiTop + ySize - 20, false, @@ -156,7 +154,7 @@ public class GuiEnchantColour extends GuiScreen { if (colourCode.length() > 1) colourCode = String.valueOf(colourCode.toLowerCase().charAt(0)); if (comparator.length() > 1) comparator = String.valueOf(comparator.toLowerCase().charAt(0)); - Utils.drawStringCentered(comparator, fontRendererObj, guiLeft + 96, guiTop + 33 + 25 * yIndex, false, 4210752); + Utils.drawStringCentered(comparator, guiLeft + 96, guiTop + 33 + 25 * yIndex, false, 4210752); if (guiElementTextFields.size() <= yIndex) { guiElementTextFields.add(new GuiElementTextField[3]); @@ -226,7 +224,6 @@ public class GuiEnchantColour extends GuiScreen { yIndex++; } renderSideBar(mouseX, mouseY, partialTicks); - FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; List tooltipToDisplay = null; GlStateManager.color(1, 1, 1, 1); Minecraft.getMinecraft().getTextureManager().bindTexture(help); @@ -275,13 +272,13 @@ public class GuiEnchantColour extends GuiScreen { if (mouseY >= guiTopSidebar - 34 && mouseY <= guiTopSidebar - 18 && maxedBookFound == 1) { tooltipToDisplay = maxedBook.getTooltip(Minecraft.getMinecraft().thePlayer, false); - Utils.drawHoveringText(tooltipToDisplay, mouseX, mouseY, width, height, -1, fr); + Utils.drawHoveringText(tooltipToDisplay, mouseX, mouseY, width, height, -1); tooltipToDisplay = null; renderingTooltip = true; } if (mouseY >= guiTopSidebar - 52 && mouseY <= guiTopSidebar - 34 && maxedAttBookFound == 1 && !renderingTooltip) { tooltipToDisplay = maxedAttBook.getTooltip(Minecraft.getMinecraft().thePlayer, false); - Utils.drawHoveringText(tooltipToDisplay, mouseX, mouseY, width, height, -1, fr); + Utils.drawHoveringText(tooltipToDisplay, mouseX, mouseY, width, height, -1); tooltipToDisplay = null; renderingTooltip = true; } @@ -326,7 +323,7 @@ public class GuiEnchantColour extends GuiScreen { EnumChatFormatting.GRAY + "" + EnumChatFormatting.ITALIC + "I" + EnumChatFormatting.RESET + EnumChatFormatting.GRAY + " = " + EnumChatFormatting.ITALIC + "Italic" ); - Utils.drawHoveringText(tooltipToDisplay, mouseX, mouseY, width, height, -1, fr); + Utils.drawHoveringText(tooltipToDisplay, mouseX, mouseY, width, height, -1); tooltipToDisplay = null; } } @@ -390,7 +387,6 @@ public class GuiEnchantColour extends GuiScreen { ); Utils.drawStringCenteredScaledMaxWidth( "Load preset", - fontRendererObj, guiLeft + xSize + 4 + 44, guiTopSidebar + 8, false, @@ -399,7 +395,6 @@ public class GuiEnchantColour extends GuiScreen { ); Utils.drawStringCenteredScaledMaxWidth( "from Clipboard", - fontRendererObj, guiLeft + xSize + 4 + 44, guiTopSidebar + 16, false, @@ -408,7 +403,6 @@ public class GuiEnchantColour extends GuiScreen { ); Utils.drawStringCenteredScaledMaxWidth( "Save preset", - fontRendererObj, guiLeft + xSize + 4 + 44, guiTopSidebar + 8 + 24, false, @@ -417,7 +411,6 @@ public class GuiEnchantColour extends GuiScreen { ); Utils.drawStringCenteredScaledMaxWidth( "to Clipboard", - fontRendererObj, guiLeft + xSize + 4 + 44, guiTopSidebar + 16 + 24, false, @@ -426,7 +419,6 @@ public class GuiEnchantColour extends GuiScreen { ); Utils.drawStringCenteredScaledMaxWidth( "Reset Config", - fontRendererObj, guiLeft + xSize + 4 + 44, guiTopSidebar + 12 + 24 * 2, false, diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiInvButtonEditor.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiInvButtonEditor.java index d97227cf..147bf567 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiInvButtonEditor.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiInvButtonEditor.java @@ -411,7 +411,6 @@ public class GuiInvButtonEditor extends GuiScreen { ); Utils.drawStringCenteredScaledMaxWidth( "Load preset", - fontRendererObj, guiLeft - 44 - 2 - 22 - (NotEnoughUpdates.INSTANCE.config.customArmour.enableArmourHud ? 25 : 0), guiTop + 8, false, @@ -420,7 +419,6 @@ public class GuiInvButtonEditor extends GuiScreen { ); Utils.drawStringCenteredScaledMaxWidth( "from Clipboard", - fontRendererObj, guiLeft - 44 - 2 - 22 - (NotEnoughUpdates.INSTANCE.config.customArmour.enableArmourHud ? 25 : 0), guiTop + 16, false, @@ -429,7 +427,6 @@ public class GuiInvButtonEditor extends GuiScreen { ); Utils.drawStringCenteredScaledMaxWidth( "Save preset", - fontRendererObj, guiLeft - 44 - 2 - 22 - (NotEnoughUpdates.INSTANCE.config.customArmour.enableArmourHud ? 25 : 0), guiTop + 8 + 24, false, @@ -438,7 +435,6 @@ public class GuiInvButtonEditor extends GuiScreen { ); Utils.drawStringCenteredScaledMaxWidth( "to Clipboard", - fontRendererObj, guiLeft - 44 - 2 - 22 - (NotEnoughUpdates.INSTANCE.config.customArmour.enableArmourHud ? 25 : 0), guiTop + 16 + 24, false, @@ -459,7 +455,6 @@ public class GuiInvButtonEditor extends GuiScreen { ); Utils.drawStringCenteredScaledMaxWidth( "\u00a7nPresets", - fontRendererObj, guiLeft + xSize + 22 + 40, guiTop + 10, false, @@ -471,7 +466,6 @@ public class GuiInvButtonEditor extends GuiScreen { for (String presetName : presets.keySet()) { Utils.drawStringCenteredScaledMaxWidth( presetName, - fontRendererObj, guiLeft + xSize + 22 + 40, guiTop + 25 + 10 * (index++), false, diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiItemCustomize.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiItemCustomize.java index 129699da..eac58a1a 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiItemCustomize.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiItemCustomize.java @@ -355,7 +355,7 @@ public class GuiItemCustomize extends GuiScreen { } if (tooltipToDisplay != null) { - Utils.drawHoveringText(tooltipToDisplay, mouseX, mouseY, width, height, -1, fontRendererObj); + Utils.drawHoveringText(tooltipToDisplay, mouseX, mouseY, width, height, -1); } super.drawScreen(mouseX, mouseY, partialTicks); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiItemRecipe.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiItemRecipe.java index e81834d3..3627a94e 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiItemRecipe.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiItemRecipe.java @@ -29,7 +29,6 @@ import io.github.moulberry.notenoughupdates.recipes.RecipeSlot; import io.github.moulberry.notenoughupdates.recipes.RecipeType; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.ScaledResolution; @@ -127,7 +126,6 @@ public class GuiItemRecipe extends GuiScreen { @Override public void drawScreen(int mouseX, int mouseY, float partialTicks) { drawDefaultBackground(); - FontRenderer fontRendererObj = Minecraft.getMinecraft().fontRendererObj; GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); @@ -150,7 +148,6 @@ public class GuiItemRecipe extends GuiScreen { Utils.drawStringScaledMaxWidth( currentRecipe.getTitle(), - fontRendererObj, guiLeft + TITLE_X, guiTop + TITLE_Y, false, @@ -165,12 +162,7 @@ public class GuiItemRecipe extends GuiScreen { if (slot.getItemStack() == null) continue; Utils.drawHoveringText( slot.getItemStack().getTooltip(Minecraft.getMinecraft().thePlayer, false), - mouseX, - mouseY, - width, - height, - -1, - fontRendererObj + mouseX, mouseY, width, height, -1 ); } } @@ -195,7 +187,7 @@ public class GuiItemRecipe extends GuiScreen { "" + EnumChatFormatting.RESET + EnumChatFormatting.GREEN + type.getLabel(), "" + EnumChatFormatting.RESET + EnumChatFormatting.GRAY + craftingRecipes.get(type).size() + " Recipes" ), - mouseX, mouseY, width, height, -1, Minecraft.getMinecraft().fontRendererObj + mouseX, mouseY, width, height, -1 ); return; } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiNavigation.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiNavigation.java index 35c80579..ba3f95df 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiNavigation.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiNavigation.java @@ -104,7 +104,6 @@ public class GuiNavigation extends GuiScreen { ); Utils.drawStringF( json.get("displayname").getAsString(), - Minecraft.getMinecraft().fontRendererObj, baseX + TEXT_OFFSET_X, baseY + LIST_OFFSET_Y / 2F - Minecraft.getMinecraft().fontRendererObj.FONT_HEIGHT / 2F, false, diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiPriceGraph.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiPriceGraph.java index eb6aa956..c03a72a6 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiPriceGraph.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiPriceGraph.java @@ -139,20 +139,16 @@ public class GuiPriceGraph extends GuiScreen { if (itemName != null && itemStack != null) { Utils.drawItemStack(itemStack, guiLeft + 16, guiTop + 11); - Utils.drawStringScaledMax(itemName, Minecraft.getMinecraft().fontRendererObj, guiLeft + 35, guiTop + 13, false, + Utils.drawStringScaledMax(itemName, guiLeft + 35, guiTop + 13, false, 0xffffff, 1.77f, 208 ); } if (!loaded) - Utils.drawStringCentered("Loading...", Minecraft.getMinecraft().fontRendererObj, - guiLeft + 166, guiTop + 116, false, 0xffffff00 - ); + Utils.drawStringCentered("Loading...", guiLeft + 166, guiTop + 116, false, 0xffffff00); else if ( itemData == null || itemData.get() == null || itemData.get().size() <= 1) - Utils.drawStringCentered("No data found.", Minecraft.getMinecraft().fontRendererObj, - guiLeft + 166, guiTop + 116, false, 0xffff0000 - ); + Utils.drawStringCentered("No data found.", guiLeft + 166, guiTop + 116, false, 0xffff0000); else { int graphColor = SpecialColour.specialToChromaRGB(NotEnoughUpdates.INSTANCE.config.ahGraph.graphColor); int graphColor2 = SpecialColour.specialToChromaRGB(NotEnoughUpdates.INSTANCE.config.ahGraph.graphColor2); @@ -226,9 +222,7 @@ public class GuiPriceGraph extends GuiScreen { if (num != prevNum) { int xPos = (int) map(time, firstTime, lastTime, guiLeft + 17, guiLeft + 315); if (Math.abs(prevXPos - xPos) > 30) { - Utils.drawStringCentered(String.valueOf(num), Minecraft.getMinecraft().fontRendererObj, - xPos, guiTop + 206, false, 0x8b8b8b - ); + Utils.drawStringCentered(String.valueOf(num), xPos, guiTop + 206, false, 0x8b8b8b); prevXPos = xPos; } prevNum = num; @@ -237,10 +231,9 @@ public class GuiPriceGraph extends GuiScreen { for (int i = 0; i <= 6; i++) { long price = (long) map(i, 0, 6, highestValue, lowestValue); String formattedPrice = formatPrice(price); - Utils.drawStringF(formattedPrice, Minecraft.getMinecraft().fontRendererObj, guiLeft + 320, + Utils.drawStringF(formattedPrice, guiLeft + 320, (float) map(i, 0, 6, guiTop + 35, guiTop + 198) - - Minecraft.getMinecraft().fontRendererObj.FONT_HEIGHT / 2f, - false, 0x8b8b8b + - Minecraft.getMinecraft().fontRendererObj.FONT_HEIGHT / 2f, false, 0x8b8b8b ); } if (customSelecting) { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/InventoryStorageSelector.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/InventoryStorageSelector.java index 8ee68457..648345bf 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/InventoryStorageSelector.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/InventoryStorageSelector.java @@ -25,7 +25,6 @@ import io.github.moulberry.notenoughupdates.core.config.KeybindHelper; import io.github.moulberry.notenoughupdates.miscfeatures.StorageManager; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.Gui; import net.minecraft.client.gui.ScaledResolution; import net.minecraft.client.renderer.GlStateManager; @@ -40,6 +39,7 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.gameevent.InputEvent; import org.lwjgl.input.Mouse; import org.lwjgl.opengl.GL11; + @NEUAutoSubscribe public class InventoryStorageSelector { private static final InventoryStorageSelector INSTANCE = new InventoryStorageSelector(); @@ -266,7 +266,6 @@ public class InventoryStorageSelector { int width = scaledResolution.getScaledWidth(); int height = scaledResolution.getScaledHeight(); - FontRenderer fontRendererObj = Minecraft.getMinecraft().fontRendererObj; int centerX = width / 2; int offset = 91 + 10 + 12; @@ -439,32 +438,18 @@ public class InventoryStorageSelector { Utils.drawItemStack(held, centerX - 8, startY - 8); GlStateManager.translate(0, 0, 100); - Utils.drawStringCentered(pageTitle, fontRendererObj, centerX, height - 76, true, 0xffff0000); + Utils.drawStringCentered(pageTitle, centerX, height - 76, true, 0xffff0000); int keyCode = NotEnoughUpdates.INSTANCE.config.storageGUI.backpackScrollKey; if (KeybindHelper.isKeyValid(keyCode) && !KeybindHelper.isKeyDown(keyCode)) { String keyName = KeybindHelper.getKeyName(keyCode); - Utils.drawStringCentered( - "[" + keyName + "] Scroll Backpacks", - fontRendererObj, - centerX, - startY - 10, - true, - 0xff32CD32 - ); + Utils.drawStringCentered("[" + keyName + "] Scroll Backpacks", centerX, startY - 10, true, 0xff32CD32); } GlStateManager.translate(0, 0, -200); } else if (page == null) { - Utils.drawStringCentered( - "Run /storage to enable this feature!", - fontRendererObj, - centerX, - height - 80, - true, - 0xffff0000 - ); + Utils.drawStringCentered("Run /storage to enable this feature!", centerX, height - 80, true, 0xffff0000); } else { - Utils.drawStringCentered("Right-click to load items", fontRendererObj, centerX, height - 80, true, 0xffff0000); + Utils.drawStringCentered("Right-click to load items", centerX, height - 80, true, 0xffff0000); } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/KatSitterOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/KatSitterOverlay.java index 288c3926..c2908807 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/KatSitterOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/KatSitterOverlay.java @@ -95,11 +95,10 @@ public class KatSitterOverlay { ) : currentWidth); GlStateManager.disableLighting(); GlStateManager.color(1F, 1F, 1F, 1F); - Utils.drawStringScaled(currentText, font, left, ((AccessorGuiContainer) gui).getGuiTop() + 25, false, 0xFFD700, 1F); + Utils.drawStringScaled(currentText, left, ((AccessorGuiContainer) gui).getGuiTop() + 25, false, 0xFFD700, 1F); if (upgradedLevel != null) Utils.drawStringScaled( upgradedText, - font, left, ((AccessorGuiContainer) gui).getGuiTop() + 45, false, diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/NEUOverlayPlacements.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/NEUOverlayPlacements.java index ac96f527..30907836 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/NEUOverlayPlacements.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/NEUOverlayPlacements.java @@ -74,14 +74,7 @@ public class NEUOverlayPlacements extends GuiScreen { drawRect((width - 176) / 2, (height - 166) / 2, (width + 176) / 2, (height + 166) / 2, new Color(100, 100, 100, 200).getRGB() ); - Utils.drawStringCentered( - GOLD + "Inventory", - Minecraft.getMinecraft().fontRendererObj, - width / 2f, - height / 2f, - false, - 0 - ); + Utils.drawStringCentered(GOLD + "Inventory", width / 2f, height / 2f, false, 0); MBGuiGroupFloating mainGroup = NotEnoughUpdates.INSTANCE.overlay.guiGroup; mainGroup.render(0, 0); @@ -145,7 +138,8 @@ public class NEUOverlayPlacements extends GuiScreen { } if (anchorPoint.inventoryRelative) { - Utils.drawStringCentered(GOLD + "Inv-Relative", Minecraft.getMinecraft().fontRendererObj, + Utils.drawStringCentered( + GOLD + "Inv-Relative", position.x + element.getWidth() * 0.5f, position.y + element.getHeight() * 0.5f, false, 0 ); } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/SignCalculator.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/SignCalculator.java index 4f01e551..31331ab3 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/SignCalculator.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/SignCalculator.java @@ -32,8 +32,8 @@ import net.minecraft.util.EnumChatFormatting; import net.minecraftforge.client.event.GuiScreenEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; -import java.text.DecimalFormat; import java.math.BigDecimal; +import java.text.DecimalFormat; import java.util.Objects; @NEUAutoSubscribe @@ -62,14 +62,7 @@ public class SignCalculator { int calculationMode = NotEnoughUpdates.INSTANCE.config.misc.calculationMode; if ((calculationMode == 1 && !source.startsWith("!"))) return; - Utils.drawStringCentered( - getRenderedString(), - Minecraft.getMinecraft().fontRendererObj, - guiEditSign.width / 2F, - 58, - false, - 0x808080FF - ); + Utils.drawStringCentered(getRenderedString(), guiEditSign.width / 2F, 58, false, 0x808080FF); } @SubscribeEvent diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/StorageOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/StorageOverlay.java index 5dd8bd9c..ff1d8687 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/StorageOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/StorageOverlay.java @@ -862,11 +862,11 @@ public class StorageOverlay extends GuiElement { Gui.drawRect(storageX, storageY, storageX + 162, storageY + h, 0x80000000); if (storageId < 9) { - Utils.drawStringCenteredScaledMaxWidth("Locked Page", fontRendererObj, + Utils.drawStringCenteredScaledMaxWidth("Locked Page", storageX + 81, storageY + h / 2, true, 150, 0xd94c00 ); } else { - Utils.drawStringCenteredScaledMaxWidth("Empty Backpack Slot", fontRendererObj, + Utils.drawStringCenteredScaledMaxWidth("Empty Backpack Slot", storageX + 81, storageY + h / 2, true, 150, 0xd94c00 ); } @@ -889,7 +889,7 @@ public class StorageOverlay extends GuiElement { Gui.drawRect(storageX, storageY, storageX + 162, storageY + h, 0x80000000); - Utils.drawStringCenteredScaledMaxWidth("Click to load items", fontRendererObj, + Utils.drawStringCenteredScaledMaxWidth("Click to load items", storageX + 81, storageY + h / 2, true, 150, 0xffdf00 ); } else { @@ -1233,35 +1233,35 @@ public class StorageOverlay extends GuiElement { if (StorageManager.getInstance().desiredStoragePage == storageId && StorageManager.getInstance().onStorageMenu) { - Utils.drawStringCenteredScaledMaxWidth("Please click again to load...", fontRendererObj, + Utils.drawStringCenteredScaledMaxWidth("Please click again to load...", storageX + 81 - 1, storageY + storageH / 2 - 5, false, 150, 0x111111 ); - Utils.drawStringCenteredScaledMaxWidth("Please click again to load...", fontRendererObj, + Utils.drawStringCenteredScaledMaxWidth("Please click again to load...", storageX + 81 + 1, storageY + storageH / 2 - 5, false, 150, 0x111111 ); - Utils.drawStringCenteredScaledMaxWidth("Please click again to load...", fontRendererObj, + Utils.drawStringCenteredScaledMaxWidth("Please click again to load...", storageX + 81, storageY + storageH / 2 - 5 - 1, false, 150, 0x111111 ); - Utils.drawStringCenteredScaledMaxWidth("Please click again to load...", fontRendererObj, + Utils.drawStringCenteredScaledMaxWidth("Please click again to load...", storageX + 81, storageY + storageH / 2 - 5 + 1, false, 150, 0x111111 ); - Utils.drawStringCenteredScaledMaxWidth("Please click again to load...", fontRendererObj, + Utils.drawStringCenteredScaledMaxWidth("Please click again to load...", storageX + 81, storageY + storageH / 2 - 5, false, 150, 0xffdf00 ); - Utils.drawStringCenteredScaledMaxWidth("Use /neustwhy for more info", fontRendererObj, + Utils.drawStringCenteredScaledMaxWidth("Use /neustwhy for more info", storageX + 81 - 1, storageY + storageH / 2 + 5, false, 150, 0x111111 ); - Utils.drawStringCenteredScaledMaxWidth("Use /neustwhy for more info", fontRendererObj, + Utils.drawStringCenteredScaledMaxWidth("Use /neustwhy for more info", storageX + 81 + 1, storageY + storageH / 2 + 5, false, 150, 0x111111 ); - Utils.drawStringCenteredScaledMaxWidth("Use /neustwhy for more info", fontRendererObj, + Utils.drawStringCenteredScaledMaxWidth("Use /neustwhy for more info", storageX + 81, storageY + storageH / 2 + 5 - 1, false, 150, 0x111111 ); - Utils.drawStringCenteredScaledMaxWidth("Use /neustwhy for more info", fontRendererObj, + Utils.drawStringCenteredScaledMaxWidth("Use /neustwhy for more info", storageX + 81, storageY + storageH / 2 + 5 + 1, false, 150, 0x111111 ); - Utils.drawStringCenteredScaledMaxWidth("Use /neustwhy for more info", fontRendererObj, + Utils.drawStringCenteredScaledMaxWidth("Use /neustwhy for more info", storageX + 81, storageY + storageH / 2 + 5, false, 150, 0xffdf00 ); } @@ -1685,26 +1685,10 @@ public class StorageOverlay extends GuiElement { } GlStateManager.translate(0, 0, -100); } else { - Utils.drawHoveringText( - tooltipToDisplay, - mouseX, - mouseY, - width, - height, - -1, - Minecraft.getMinecraft().fontRendererObj - ); + Utils.drawHoveringText(tooltipToDisplay, mouseX, mouseY, width, height, -1); } } else if (tooltipToDisplay != null) { - Utils.drawHoveringText( - tooltipToDisplay, - mouseX, - mouseY, - width, - height, - -1, - Minecraft.getMinecraft().fontRendererObj - ); + Utils.drawHoveringText(tooltipToDisplay, mouseX, mouseY, width, height, -1); } else { allowTypingInSearchBar = true; } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/TradeWindow.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/TradeWindow.java index 16b5015b..6d565bb3 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/TradeWindow.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/TradeWindow.java @@ -107,7 +107,6 @@ public class TradeWindow { for (int yOff = -2; yOff <= 2; yOff++) { if (Math.abs(xOff) != Math.abs(yOff)) { Utils.drawStringCenteredScaledMaxWidth(Utils.cleanColourNotModifiers(str), - Minecraft.getMinecraft().fontRendererObj, x + xOff / 2f, y + yOff / 2f, false, len, new Color(20, 20, 20, 100 / Math.max(Math.abs(xOff), Math.abs(yOff))).getRGB() ); @@ -115,11 +114,7 @@ public class TradeWindow { } } - Utils.drawStringCenteredScaledMaxWidth(str, - Minecraft.getMinecraft().fontRendererObj, - x, y, false, len, - new Color(64, 64, 64, 255).getRGB() - ); + Utils.drawStringCenteredScaledMaxWidth(str, x, y, false, len, new Color(64, 64, 64, 255).getRGB()); } private static long getPrice(String internalName) { @@ -567,14 +562,12 @@ public class TradeWindow { Utils.drawTexturedRect(guiLeft, guiTop, xSize, ySize, 0, 176 / 256f, 0, 204 / 256f, GL11.GL_NEAREST); Utils.drawStringF(new ChatComponentTranslation("container.inventory").getUnformattedText(), - Minecraft.getMinecraft().fontRendererObj, guiLeft + 8, guiTop + 111, false, 4210752 - ); - Utils.drawStringF("You", Minecraft.getMinecraft().fontRendererObj, guiLeft + 8, - guiTop + 5, false, 4210752 + guiLeft + 8, guiTop + 111, false, 4210752 ); + Utils.drawStringF("You", guiLeft + 8, guiTop + 5, false, 421752); String[] split = containerName.split(" "); if (split.length >= 1) { - Utils.drawStringF(split[split.length - 1], Minecraft.getMinecraft().fontRendererObj, + Utils.drawStringF(split[split.length - 1], guiLeft + 167 - Minecraft.getMinecraft().fontRendererObj.getStringWidth(split[split.length - 1]), guiTop + 5, false, 4210752 ); @@ -692,31 +685,19 @@ public class TradeWindow { Utils.drawStringCentered( EnumChatFormatting.DARK_RED + "Check " + EnumChatFormatting.BOLD + (char) (9311 + num), - Minecraft.getMinecraft().fontRendererObj, - guiLeft + 56, - guiTop + 99, + guiLeft + 56, guiTop + 99, false, 4210752 ); } else if (confirmDisplay.equals(EnumChatFormatting.AQUA + "Gift!")) { - Utils.drawStringCentered( - EnumChatFormatting.GREEN + "Accept", - Minecraft.getMinecraft().fontRendererObj, - guiLeft + 56, - guiTop + 99, - true, - 4210752 - ); + Utils.drawStringCentered(EnumChatFormatting.GREEN + "Accept", guiLeft + 56, guiTop + 99, true, 4210752); } else if (confirmDisplay.equals(EnumChatFormatting.GREEN + "Deal accepted!")) { - Utils.drawStringCentered(EnumChatFormatting.GREEN + "Accepted", Minecraft.getMinecraft().fontRendererObj, - guiLeft + 56, guiTop + 99, true, 4210752 - ); + Utils.drawStringCentered(EnumChatFormatting.GREEN + "Accepted", guiLeft + 56, guiTop + 99, true, 4210752); } else if (lastTradeMillis > 0) { long delta = System.currentTimeMillis() - lastTradeMillis; if (delta > 2000) { Utils.drawStringCentered( EnumChatFormatting.GREEN + "Accept", - Minecraft.getMinecraft().fontRendererObj, guiLeft + 56, guiTop + 99, true, @@ -725,7 +706,6 @@ public class TradeWindow { } else { Utils.drawStringCentered( EnumChatFormatting.YELLOW + "Trade " + EnumChatFormatting.BOLD + (char) (9312 + (2000 - delta) / 1000), - Minecraft.getMinecraft().fontRendererObj, guiLeft + 56, guiTop + 99, true, @@ -735,7 +715,6 @@ public class TradeWindow { } else { Utils.drawStringCentered( EnumChatFormatting.YELLOW + "Trade " + EnumChatFormatting.BOLD + (char) (9314), - Minecraft.getMinecraft().fontRendererObj, guiLeft + 56, guiTop + 99, true, @@ -764,32 +743,11 @@ public class TradeWindow { ); if (confirmDisplay.equals(EnumChatFormatting.YELLOW + "Pending their confirm")) { - Utils.drawStringCentered( - EnumChatFormatting.YELLOW + "Pending", - Minecraft.getMinecraft().fontRendererObj, - guiLeft + 120, - guiTop + 99, - true, - 4210752 - ); + Utils.drawStringCentered(EnumChatFormatting.YELLOW + "Pending", guiLeft + 120, guiTop + 99, true, 4210752); } else if (confirmDisplay.equals(EnumChatFormatting.YELLOW + "Deal timer...")) { - Utils.drawStringCentered( - EnumChatFormatting.YELLOW + "Pending", - Minecraft.getMinecraft().fontRendererObj, - guiLeft + 120, - guiTop + 99, - true, - 4210752 - ); + Utils.drawStringCentered(EnumChatFormatting.YELLOW + "Pending", guiLeft + 120, guiTop + 99, true, 4210752); } else if (confirmDisplay.equals(EnumChatFormatting.GREEN + "Other player confirmed!")) { - Utils.drawStringCentered( - EnumChatFormatting.GREEN + "Accepted", - Minecraft.getMinecraft().fontRendererObj, - guiLeft + 120, - guiTop + 99, - true, - 4210752 - ); + Utils.drawStringCentered(EnumChatFormatting.GREEN + "Accepted", guiLeft + 120, guiTop + 99, true, 4210752); } } @@ -1041,8 +999,7 @@ public class TradeWindow { mouseY, scaledResolution.getScaledWidth(), scaledResolution.getScaledHeight(), - tooltipLen, - Minecraft.getMinecraft().fontRendererObj + tooltipLen ); } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/hex/GuiCustomHex.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/hex/GuiCustomHex.java index 4dbe7f94..deef7bdc 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/hex/GuiCustomHex.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/hex/GuiCustomHex.java @@ -37,6 +37,7 @@ import io.github.moulberry.notenoughupdates.util.ItemUtils; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.EntityPlayerSP; +import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.Gui; import net.minecraft.client.gui.ScaledResolution; import net.minecraft.client.gui.inventory.GuiContainer; @@ -539,7 +540,8 @@ public class GuiCustomHex extends Gui { if (enchanterCurrentEnch == null) { enchanterCurrentEnch = enchantment; } else if (updateLevel) { - if (removingEnchantPlayerLevel < 0 && enchantment.level > enchanterCurrentEnch.level && !aboveMaxLevelFromEt) { + if (removingEnchantPlayerLevel < 0 && enchantment.level > enchanterCurrentEnch.level && + !aboveMaxLevelFromEt) { enchanterCurrentEnch = enchantment; } else if (removingEnchantPlayerLevel >= 0 && enchantment.level < enchanterCurrentEnch.level) { enchanterCurrentEnch = enchantment; @@ -1286,14 +1288,15 @@ public class GuiCustomHex extends Gui { renderBaseTexture(); - Minecraft.getMinecraft().fontRendererObj.drawString("Applicable", guiLeft + 7, guiTop + 7, 0x404040, false); - Minecraft.getMinecraft().fontRendererObj.drawString("Removable", guiLeft + 247, guiTop + 7, 0x404040, false); + FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; + fr.drawString("Applicable", guiLeft + 7, guiTop + 7, 0x404040, false); + fr.drawString("Removable", guiLeft + 247, guiTop + 7, 0x404040, false); //Page Text if (currentState == EnchantState.HAS_ITEM || currentState == EnchantState.ADDING_ENCHANT) { String pageStr = "Page: " + currentPage + "/" + expectedMaxPage; - int pageStrLen = Minecraft.getMinecraft().fontRendererObj.getStringWidth(pageStr); - Utils.drawStringCentered(pageStr, Minecraft.getMinecraft().fontRendererObj, + int pageStrLen = fr.getStringWidth(pageStr); + Utils.drawStringCentered(pageStr, guiLeft + X_SIZE / 2, guiTop + 14, false, 0x404040 ); @@ -1318,10 +1321,10 @@ public class GuiCustomHex extends Gui { //Can't be enchanted text if (currentState == EnchantState.INVALID_ITEM) { GlStateManager.disableDepth(); - Utils.drawStringCentered("This item can't", Minecraft.getMinecraft().fontRendererObj, + Utils.drawStringCentered("This item can't", guiLeft + X_SIZE / 2, guiTop + 88, true, 0xffff5555 ); - Utils.drawStringCentered("be enchanted", Minecraft.getMinecraft().fontRendererObj, + Utils.drawStringCentered("be enchanted", guiLeft + X_SIZE / 2, guiTop + 98, true, 0xffff5555 ); GlStateManager.enableDepth(); @@ -1332,52 +1335,24 @@ public class GuiCustomHex extends Gui { //Text if no enchants appear if (currentState == EnchantState.HAS_ITEM || currentState == EnchantState.ADDING_ENCHANT) { if (applicable.isEmpty() && removable.isEmpty() && searchRemovedFromApplicable) { - Utils.drawStringCentered("Can't find that", Minecraft.getMinecraft().fontRendererObj, - guiLeft + 8 + 48, guiTop + 28, true, 0xffff5555 - ); - Utils.drawStringCentered("enchant, perhaps", Minecraft.getMinecraft().fontRendererObj, - guiLeft + 8 + 48, guiTop + 38, true, 0xffff5555 - ); - Utils.drawStringCentered("it is on", Minecraft.getMinecraft().fontRendererObj, - guiLeft + 8 + 48, guiTop + 48, true, 0xffff5555 - ); - Utils.drawStringCentered("another page?", Minecraft.getMinecraft().fontRendererObj, - guiLeft + 8 + 48, guiTop + 58, true, 0xffff5555 - ); + Utils.drawStringCentered("Can't find that", guiLeft + 8 + 48, guiTop + 28, true, 0xffff5555); + Utils.drawStringCentered("enchant, perhaps", guiLeft + 8 + 48, guiTop + 38, true, 0xffff5555); + Utils.drawStringCentered("it is on", guiLeft + 8 + 48, guiTop + 48, true, 0xffff5555); + Utils.drawStringCentered("another page?", guiLeft + 8 + 48, guiTop + 58, true, 0xffff5555); } else if (applicable.isEmpty() && !searchRemovedFromApplicable) { - Utils.drawStringCentered("No applicable", Minecraft.getMinecraft().fontRendererObj, - guiLeft + 8 + 48, guiTop + 28, true, 0xffff5555 - ); - Utils.drawStringCentered("enchants on", Minecraft.getMinecraft().fontRendererObj, - guiLeft + 8 + 48, guiTop + 38, true, 0xffff5555 - ); - Utils.drawStringCentered("this page...", Minecraft.getMinecraft().fontRendererObj, - guiLeft + 8 + 48, guiTop + 48, true, 0xffff5555 - ); + Utils.drawStringCentered("No applicable", guiLeft + 8 + 48, guiTop + 28, true, 0xffff5555); + Utils.drawStringCentered("enchants on", guiLeft + 8 + 48, guiTop + 38, true, 0xffff5555); + Utils.drawStringCentered("this page...", guiLeft + 8 + 48, guiTop + 48, true, 0xffff5555); } if (applicable.isEmpty() && removable.isEmpty() && searchRemovedFromRemovable) { - Utils.drawStringCentered("Can't find that", Minecraft.getMinecraft().fontRendererObj, - guiLeft + 248 + 48, guiTop + 28, true, 0xffff5555 - ); - Utils.drawStringCentered("enchant, perhaps", Minecraft.getMinecraft().fontRendererObj, - guiLeft + 248 + 48, guiTop + 38, true, 0xffff5555 - ); - Utils.drawStringCentered("it is on", Minecraft.getMinecraft().fontRendererObj, - guiLeft + 248 + 48, guiTop + 48, true, 0xffff5555 - ); - Utils.drawStringCentered("another page?", Minecraft.getMinecraft().fontRendererObj, - guiLeft + 248 + 48, guiTop + 58, true, 0xffff5555 - ); + Utils.drawStringCentered("Can't find that", guiLeft + 248 + 48, guiTop + 28, true, 0xffff5555); + Utils.drawStringCentered("enchant, perhaps", guiLeft + 248 + 48, guiTop + 38, true, 0xffff5555); + Utils.drawStringCentered("it is on", guiLeft + 248 + 48, guiTop + 48, true, 0xffff5555); + Utils.drawStringCentered("another page?", guiLeft + 248 + 48, guiTop + 58, true, 0xffff5555); } else if (removable.isEmpty() && !searchRemovedFromRemovable) { - Utils.drawStringCentered("No removable", Minecraft.getMinecraft().fontRendererObj, - guiLeft + 248 + 48, guiTop + 28, true, 0xffff5555 - ); - Utils.drawStringCentered("enchants on", Minecraft.getMinecraft().fontRendererObj, - guiLeft + 248 + 48, guiTop + 38, true, 0xffff5555 - ); - Utils.drawStringCentered("this page...", Minecraft.getMinecraft().fontRendererObj, - guiLeft + 248 + 48, guiTop + 48, true, 0xffff5555 - ); + Utils.drawStringCentered("No removable", guiLeft + 248 + 48, guiTop + 28, true, 0xffff5555); + Utils.drawStringCentered("enchants on", guiLeft + 248 + 48, guiTop + 38, true, 0xffff5555); + Utils.drawStringCentered("this page...", guiLeft + 248 + 48, guiTop + 48, true, 0xffff5555); } } //Available enchants (left) @@ -1413,50 +1388,14 @@ public class GuiCustomHex extends Gui { colour = 0xff5555; } - int levelWidth = Minecraft.getMinecraft().fontRendererObj.getStringWidth(levelStr); - Minecraft.getMinecraft().fontRendererObj.drawString( - levelStr, - guiLeft + 16 - levelWidth / 2 - 1, - top + 4, - 0x2d2102, - false - ); - Minecraft.getMinecraft().fontRendererObj.drawString( - levelStr, - guiLeft + 16 - levelWidth / 2 + 1, - top + 4, - 0x2d2102, - false - ); - Minecraft.getMinecraft().fontRendererObj.drawString( - levelStr, - guiLeft + 16 - levelWidth / 2, - top + 4 - 1, - 0x2d2102, - false - ); - Minecraft.getMinecraft().fontRendererObj.drawString( - levelStr, - guiLeft + 16 - levelWidth / 2, - top + 4 + 1, - 0x2d2102, - false - ); - Minecraft.getMinecraft().fontRendererObj.drawString( - levelStr, - guiLeft + 16 - levelWidth / 2, - top + 4, - colour, - false - ); + int levelWidth = fr.getStringWidth(levelStr); + fr.drawString(levelStr, guiLeft + 16 - levelWidth / 2 - 1, top + 4, 0x2d2102, false); + fr.drawString(levelStr, guiLeft + 16 - levelWidth / 2 + 1, top + 4, 0x2d2102, false); + fr.drawString(levelStr, guiLeft + 16 - levelWidth / 2, top + 4 - 1, 0x2d2102, false); + fr.drawString(levelStr, guiLeft + 16 - levelWidth / 2, top + 4 + 1, 0x2d2102, false); + fr.drawString(levelStr, guiLeft + 16 - levelWidth / 2, top + 4, colour, false); - Minecraft.getMinecraft().fontRendererObj.drawString( - ench.enchantName, - guiLeft + 8 + 16 + 2 + textOffset, - top + 4 + textOffset, - 0xffffffdd, - true - ); + fr.drawString(ench.enchantName, guiLeft + 8 + 16 + 2 + textOffset, top + 4 + textOffset, 0xffffffdd, true); } GlScissorStack.pop(scaledResolution); @@ -1493,51 +1432,19 @@ public class GuiCustomHex extends Gui { colour = 0xff5555; } - int levelWidth = Minecraft.getMinecraft().fontRendererObj.getStringWidth(levelStr); - Minecraft.getMinecraft().fontRendererObj.drawString( - levelStr, - guiLeft + 256 - levelWidth / 2 - 1, - top + 4, - 0x2d2102, - false - ); - Minecraft.getMinecraft().fontRendererObj.drawString( - levelStr, - guiLeft + 256 - levelWidth / 2 + 1, - top + 4, - 0x2d2102, - false - ); - Minecraft.getMinecraft().fontRendererObj.drawString( - levelStr, - guiLeft + 256 - levelWidth / 2, - top + 4 - 1, - 0x2d2102, - false - ); - Minecraft.getMinecraft().fontRendererObj.drawString( - levelStr, - guiLeft + 256 - levelWidth / 2, - top + 4 + 1, - 0x2d2102, - false - ); - Minecraft.getMinecraft().fontRendererObj.drawString( - levelStr, - guiLeft + 256 - levelWidth / 2, - top + 4, - colour, - false - ); + int levelWidth = fr.getStringWidth(levelStr); + fr.drawString(levelStr, guiLeft + 256 - levelWidth / 2 - 1, top + 4, 0x2d2102, false); + fr.drawString(levelStr, guiLeft + 256 - levelWidth / 2 + 1, top + 4, 0x2d2102, false); + fr.drawString(levelStr, guiLeft + 256 - levelWidth / 2, top + 4 - 1, 0x2d2102, false); + fr.drawString(levelStr, guiLeft + 256 - levelWidth / 2, top + 4 + 1, 0x2d2102, false); + fr.drawString(levelStr, guiLeft + 256 - levelWidth / 2, top + 4, colour, false); - Minecraft.getMinecraft().fontRendererObj.drawString(ench.enchantName, - guiLeft + 248 + 16 + 2 + textOffset, top + 4 + textOffset, 0xffffffdd, true - ); + fr.drawString(ench.enchantName, guiLeft + 248 + 16 + 2 + textOffset, top + 4 + textOffset, 0xffffffdd, true); } GlScissorStack.pop(scaledResolution); //Player Inventory Items - Minecraft.getMinecraft().fontRendererObj.drawString(Minecraft.getMinecraft().thePlayer.inventory + fr.drawString(Minecraft.getMinecraft().thePlayer.inventory .getDisplayName() .getUnformattedText(), guiLeft + 102, guiTop + Y_SIZE - 96 + 2, 0x404040 @@ -1580,7 +1487,7 @@ public class GuiCustomHex extends Gui { searchField.setPrependText("\u00a77Search..."); } else { if (searchField.getFocus()) { - int len = Minecraft.getMinecraft().fontRendererObj.getStringWidth(searchField.getTextDisplay()) + 10; + int len = fr.getStringWidth(searchField.getTextDisplay()) + 10; searchField.setSize(Math.max(90, len), 14); } else { searchField.setSize(90, 14); @@ -1618,78 +1525,24 @@ public class GuiCustomHex extends Gui { colour = 0xff5555; } - int levelWidth = Minecraft.getMinecraft().fontRendererObj.getStringWidth(levelStr); - Minecraft.getMinecraft().fontRendererObj.drawString( - levelStr, - left + 8 - levelWidth / 2 - 1, - top + 4, - 0x2d2102, - false - ); - Minecraft.getMinecraft().fontRendererObj.drawString( - levelStr, - left + 8 - levelWidth / 2 + 1, - top + 4, - 0x2d2102, - false - ); - Minecraft.getMinecraft().fontRendererObj.drawString( - levelStr, - left + 8 - levelWidth / 2, - top + 4 - 1, - 0x2d2102, - false - ); - Minecraft.getMinecraft().fontRendererObj.drawString( - levelStr, - left + 8 - levelWidth / 2, - top + 4 + 1, - 0x2d2102, - false - ); - Minecraft.getMinecraft().fontRendererObj.drawString(levelStr, left + 8 - levelWidth / 2, top + 4, colour, false); + int levelWidth = fr.getStringWidth(levelStr); + fr.drawString(levelStr, left + 8 - levelWidth / 2 - 1, top + 4, 0x2d2102, false); + fr.drawString(levelStr, left + 8 - levelWidth / 2 + 1, top + 4, 0x2d2102, false); + fr.drawString(levelStr, left + 8 - levelWidth / 2, top + 4 - 1, 0x2d2102, false); + fr.drawString(levelStr, left + 8 - levelWidth / 2, top + 4 + 1, 0x2d2102, false); + fr.drawString(levelStr, left + 8 - levelWidth / 2, top + 4, colour, false); String priceStr = "" + numberFormat.format(enchanterCurrentEnch.price) + " Coins"; if (enchanterCurrentEnch.price < 0) priceStr = ""; - int priceWidth = Minecraft.getMinecraft().fontRendererObj.getStringWidth(priceStr); + int priceWidth = fr.getStringWidth(priceStr); int priceTop = guiTop + 16; int x = 180; int color = 0x2d2102; - Minecraft.getMinecraft().fontRendererObj.drawString( - priceStr, - guiLeft + x - priceWidth / 2 - 1, - priceTop + 4, - color, - false - ); - Minecraft.getMinecraft().fontRendererObj.drawString( - priceStr, - guiLeft + x - priceWidth / 2 + 1, - priceTop + 4, - color, - false - ); - Minecraft.getMinecraft().fontRendererObj.drawString( - priceStr, - guiLeft + x - priceWidth / 2, - priceTop + 4 - 1, - color, - false - ); - Minecraft.getMinecraft().fontRendererObj.drawString( - priceStr, - guiLeft + x - priceWidth / 2, - priceTop + 4 + 1, - color, - false - ); - Minecraft.getMinecraft().fontRendererObj.drawString( - priceStr, - guiLeft + x - priceWidth / 2, - priceTop + 4, - 0xfcba03, - false - ); + fr.drawString(priceStr, guiLeft + x - priceWidth / 2 - 1, priceTop + 4, color, false); + fr.drawString(priceStr, guiLeft + x - priceWidth / 2 + 1, priceTop + 4, color, false); + fr.drawString(priceStr, guiLeft + x - priceWidth / 2, priceTop + 4 - 1, color, false); + fr.drawString(priceStr, guiLeft + x - priceWidth / 2, priceTop + 4 + 1, color, false); + fr.drawString(priceStr, guiLeft + x - priceWidth / 2, priceTop + 4, 0xfcba03, false); //Enchant name String name = WordUtils.capitalizeFully(ItemUtils @@ -1706,14 +1559,7 @@ public class GuiCustomHex extends Gui { } else if (name.equalsIgnoreCase("Turbo Mushrooms")) { name = "Turbo-Mush"; } - Utils.drawStringCentered( - name, - Minecraft.getMinecraft().fontRendererObj, - guiLeft + X_SIZE / 2, - top + 8, - true, - 0xffffffdd - ); + Utils.drawStringCentered(name, guiLeft + X_SIZE / 2, top + 8, true, 0xffffffdd); if (isChangingEnchLevel) { Minecraft.getMinecraft().getTextureManager().bindTexture(TEXTURE); @@ -1726,42 +1572,12 @@ public class GuiCustomHex extends Gui { //Enchant level levelStr = "" + enchanterCurrentEnch.level; if (enchanterCurrentEnch.xpCost < 0) levelStr = "?"; - levelWidth = Minecraft.getMinecraft().fontRendererObj.getStringWidth(levelStr); - Minecraft.getMinecraft().fontRendererObj.drawString( - levelStr, - left + 96 + 8 - levelWidth / 2 - 1, - top + 4, - 0x2d2102, - false - ); - Minecraft.getMinecraft().fontRendererObj.drawString( - levelStr, - left + 96 + 8 - levelWidth / 2 + 1, - top + 4, - 0x2d2102, - false - ); - Minecraft.getMinecraft().fontRendererObj.drawString( - levelStr, - left + 96 + 8 - levelWidth / 2, - top + 4 - 1, - 0x2d2102, - false - ); - Minecraft.getMinecraft().fontRendererObj.drawString( - levelStr, - left + 96 + 8 - levelWidth / 2, - top + 4 + 1, - 0x2d2102, - false - ); - Minecraft.getMinecraft().fontRendererObj.drawString( - levelStr, - left + 96 + 8 - levelWidth / 2, - top + 4, - 0xea82ff, - false - ); + levelWidth = fr.getStringWidth(levelStr); + fr.drawString(levelStr, left + 96 + 8 - levelWidth / 2 - 1, top + 4, 0x2d2102, false); + fr.drawString(levelStr, left + 96 + 8 - levelWidth / 2 + 1, top + 4, 0x2d2102, false); + fr.drawString(levelStr, left + 96 + 8 - levelWidth / 2, top + 4 - 1, 0x2d2102, false); + fr.drawString(levelStr, left + 96 + 8 - levelWidth / 2, top + 4 + 1, 0x2d2102, false); + fr.drawString(levelStr, left + 96 + 8 - levelWidth / 2, top + 4, 0xea82ff, false); //Confirm button @@ -1781,7 +1597,7 @@ public class GuiCustomHex extends Gui { Utils.drawTexturedRect(guiLeft + X_SIZE / 2 - 1 - 48, top + 18, 48, 14, 0, 48 / 512f, 342 / 512f, (342 + 14) / 512f, GL11.GL_NEAREST ); - Utils.drawStringCentered(confirmText, Minecraft.getMinecraft().fontRendererObj, + Utils.drawStringCentered(confirmText, guiLeft + X_SIZE / 2 - 1 - 23, top + 18 + 9, false, 0x408040 ); } else { @@ -1790,7 +1606,7 @@ public class GuiCustomHex extends Gui { Utils.drawTexturedRect(guiLeft + X_SIZE / 2 - 1 - 48, top + 18, 48, 14, 0, 48 / 512f, 328 / 512f, (328 + 14) / 512f, GL11.GL_NEAREST ); - Utils.drawStringCentered(confirmText, Minecraft.getMinecraft().fontRendererObj, + Utils.drawStringCentered(confirmText, guiLeft + X_SIZE / 2 - 1 - 24, top + 18 + 8, false, 0x408040 ); @@ -1806,7 +1622,7 @@ public class GuiCustomHex extends Gui { Utils.drawTexturedRect(guiLeft + X_SIZE / 2 + 1, top + 18, 48, 14, 0, 48 / 512f, 342 / 512f, (342 + 14) / 512f, GL11.GL_NEAREST ); - Utils.drawStringCentered("Cancel", Minecraft.getMinecraft().fontRendererObj, + Utils.drawStringCentered("Cancel", guiLeft + X_SIZE / 2 + 1 + 25, top + 18 + 9, false, 0xa04040 ); } else { @@ -1815,7 +1631,7 @@ public class GuiCustomHex extends Gui { Utils.drawTexturedRect(guiLeft + X_SIZE / 2 + 1, top + 18, 48, 14, 0, 48 / 512f, 328 / 512f, (328 + 14) / 512f, GL11.GL_NEAREST ); - Utils.drawStringCentered("Cancel", Minecraft.getMinecraft().fontRendererObj, + Utils.drawStringCentered("Cancel", guiLeft + X_SIZE / 2 + 1 + 24, top + 18 + 8, false, 0xa04040 ); } @@ -1890,42 +1706,12 @@ public class GuiCustomHex extends Gui { ); levelStr = "" + ench.level; - levelWidth = Minecraft.getMinecraft().fontRendererObj.getStringWidth(levelStr); - Minecraft.getMinecraft().fontRendererObj.drawString( - levelStr, - left + 96 + 8 - levelWidth / 2 - 1, - top + 16 * yIndex + 4, - 0x2d2102, - false - ); - Minecraft.getMinecraft().fontRendererObj.drawString( - levelStr, - left + 96 + 8 - levelWidth / 2 + 1, - top + 16 * yIndex + 4, - 0x2d2102, - false - ); - Minecraft.getMinecraft().fontRendererObj.drawString( - levelStr, - left + 96 + 8 - levelWidth / 2, - top + 16 * yIndex + 4 - 1, - 0x2d2102, - false - ); - Minecraft.getMinecraft().fontRendererObj.drawString( - levelStr, - left + 96 + 8 - levelWidth / 2, - top + 16 * yIndex + 4 + 1, - 0x2d2102, - false - ); - Minecraft.getMinecraft().fontRendererObj.drawString( - levelStr, - left + 96 + 8 - levelWidth / 2, - top + 16 * yIndex + 4, - 0xea82ff, - false - ); + levelWidth = fr.getStringWidth(levelStr); + fr.drawString(levelStr, left + 96 + 8 - levelWidth / 2 - 1, top + 16 * yIndex + 4, 0x2d2102, false); + fr.drawString(levelStr, left + 96 + 8 - levelWidth / 2 + 1, top + 16 * yIndex + 4, 0x2d2102, false); + fr.drawString(levelStr, left + 96 + 8 - levelWidth / 2, top + 16 * yIndex + 4 - 1, 0x2d2102, false); + fr.drawString(levelStr, left + 96 + 8 - levelWidth / 2, top + 16 * yIndex + 4 + 1, 0x2d2102, false); + fr.drawString(levelStr, left + 96 + 8 - levelWidth / 2, top + 16 * yIndex + 4, 0xea82ff, false); } GlStateManager.enableDepth(); } @@ -2034,14 +1820,15 @@ public class GuiCustomHex extends Gui { renderBaseTexture(); - Minecraft.getMinecraft().fontRendererObj.drawString("Applicable", guiLeft + 7, guiTop + 7, 0x404040, false); - Minecraft.getMinecraft().fontRendererObj.drawString("Applied", guiLeft + 247, guiTop + 7, 0x404040, false); + FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; + fr.drawString("Applicable", guiLeft + 7, guiTop + 7, 0x404040, false); + fr.drawString("Applied", guiLeft + 247, guiTop + 7, 0x404040, false); //Page Text /*if (currentState == EnchantState.HAS_ITEM || currentState == EnchantState.ADDING_ENCHANT) { String pageStr = "Page: " + currentPage + "/" + expectedMaxPage; int pageStrLen = Minecraft.getMinecraft().fontRendererObj.getStringWidth(pageStr); - Utils.drawStringCentered(pageStr, Minecraft.getMinecraft().fontRendererObj, + Utils.drawStringCentered(pageStr, guiLeft + X_SIZE / 2, guiTop + 14, false, 0x404040 ); @@ -2066,10 +1853,10 @@ public class GuiCustomHex extends Gui { //Can't be enchanted text /*if (currentState == EnchantState.INVALID_ITEM) { GlStateManager.disableDepth(); - Utils.drawStringCentered("This item can't", Minecraft.getMinecraft().fontRendererObj, + Utils.drawStringCentered("This item can't", guiLeft + X_SIZE / 2, guiTop + 88, true, 0xffff5555 ); - Utils.drawStringCentered("be enchanted", Minecraft.getMinecraft().fontRendererObj, + Utils.drawStringCentered("be enchanted", guiLeft + X_SIZE / 2, guiTop + 98, true, 0xffff5555 ); GlStateManager.enableDepth(); @@ -2081,50 +1868,50 @@ public class GuiCustomHex extends Gui { if (currentState == EnchantState.HAS_ITEM || currentState == EnchantState.ADDING_ENCHANT || currentState == EnchantState.HAS_ITEM_IN_BOOKS || currentState == EnchantState.ADDING_BOOK) { if (applicableItem.isEmpty() && removableItem.isEmpty() && searchRemovedFromApplicable) { - Utils.drawStringCentered("Can't find that", Minecraft.getMinecraft().fontRendererObj, + Utils.drawStringCentered("Can't find that", guiLeft + 8 + 48, guiTop + 28, true, 0xffff5555 ); - Utils.drawStringCentered("enchant, perhaps", Minecraft.getMinecraft().fontRendererObj, + Utils.drawStringCentered("enchant, perhaps", guiLeft + 8 + 48, guiTop + 38, true, 0xffff5555 ); - Utils.drawStringCentered("it is on", Minecraft.getMinecraft().fontRendererObj, + Utils.drawStringCentered("it is on", guiLeft + 8 + 48, guiTop + 48, true, 0xffff5555 ); - Utils.drawStringCentered("another page?", Minecraft.getMinecraft().fontRendererObj, + Utils.drawStringCentered("another page?", guiLeft + 8 + 48, guiTop + 58, true, 0xffff5555 ); } else if (applicableItem.isEmpty() && !searchRemovedFromApplicable) { - Utils.drawStringCentered("No applicable", Minecraft.getMinecraft().fontRendererObj, + Utils.drawStringCentered("No applicable", guiLeft + 8 + 48, guiTop + 28, true, 0xffff5555 ); - Utils.drawStringCentered("enchants on", Minecraft.getMinecraft().fontRendererObj, + Utils.drawStringCentered("enchants on", guiLeft + 8 + 48, guiTop + 38, true, 0xffff5555 ); - Utils.drawStringCentered("this page...", Minecraft.getMinecraft().fontRendererObj, + Utils.drawStringCentered("this page...", guiLeft + 8 + 48, guiTop + 48, true, 0xffff5555 ); } if (applicableItem.isEmpty() && removableItem.isEmpty() && searchRemovedFromRemovable) { - Utils.drawStringCentered("Can't find that", Minecraft.getMinecraft().fontRendererObj, + Utils.drawStringCentered("Can't find that", guiLeft + 248 + 48, guiTop + 28, true, 0xffff5555 ); - Utils.drawStringCentered("enchant, perhaps", Minecraft.getMinecraft().fontRendererObj, + Utils.drawStringCentered("enchant, perhaps", guiLeft + 248 + 48, guiTop + 38, true, 0xffff5555 ); - Utils.drawStringCentered("it is on", Minecraft.getMinecraft().fontRendererObj, + Utils.drawStringCentered("it is on", guiLeft + 248 + 48, guiTop + 48, true, 0xffff5555 ); - Utils.drawStringCentered("another page?", Minecraft.getMinecraft().fontRendererObj, + Utils.drawStringCentered("another page?", guiLeft + 248 + 48, guiTop + 58, true, 0xffff5555 ); } else if (removableItem.isEmpty() && !searchRemovedFromRemovable) { - Utils.drawStringCentered("No removable", Minecraft.getMinecraft().fontRendererObj, + Utils.drawStringCentered("No removable", guiLeft + 248 + 48, guiTop + 28, true, 0xffff5555 ); - Utils.drawStringCentered("enchants on", Minecraft.getMinecraft().fontRendererObj, + Utils.drawStringCentered("enchants on", guiLeft + 248 + 48, guiTop + 38, true, 0xffff5555 ); - Utils.drawStringCentered("this page...", Minecraft.getMinecraft().fontRendererObj, + Utils.drawStringCentered("this page...", guiLeft + 248 + 48, guiTop + 48, true, 0xffff5555 ); } @@ -2162,50 +1949,14 @@ public class GuiCustomHex extends Gui { colour = 0xff5555; } - int levelWidth = Minecraft.getMinecraft().fontRendererObj.getStringWidth(levelStr); - Minecraft.getMinecraft().fontRendererObj.drawString( - levelStr, - guiLeft + 16 - levelWidth / 2 - 1, - top + 4, - 0x2d2102, - false - ); - Minecraft.getMinecraft().fontRendererObj.drawString( - levelStr, - guiLeft + 16 - levelWidth / 2 + 1, - top + 4, - 0x2d2102, - false - ); - Minecraft.getMinecraft().fontRendererObj.drawString( - levelStr, - guiLeft + 16 - levelWidth / 2, - top + 4 - 1, - 0x2d2102, - false - ); - Minecraft.getMinecraft().fontRendererObj.drawString( - levelStr, - guiLeft + 16 - levelWidth / 2, - top + 4 + 1, - 0x2d2102, - false - ); - Minecraft.getMinecraft().fontRendererObj.drawString( - levelStr, - guiLeft + 16 - levelWidth / 2, - top + 4, - colour, - false - ); + int levelWidth = fr.getStringWidth(levelStr); + fr.drawString(levelStr, guiLeft + 16 - levelWidth / 2 - 1, top + 4, 0x2d2102, false); + fr.drawString(levelStr, guiLeft + 16 - levelWidth / 2 + 1, top + 4, 0x2d2102, false); + fr.drawString(levelStr, guiLeft + 16 - levelWidth / 2, top + 4 - 1, 0x2d2102, false); + fr.drawString(levelStr, guiLeft + 16 - levelWidth / 2, top + 4 + 1, 0x2d2102, false); + fr.drawString(levelStr, guiLeft + 16 - levelWidth / 2, top + 4, colour, false); - Minecraft.getMinecraft().fontRendererObj.drawString( - item.itemName, - guiLeft + 8 + 16 + 2 + textOffset, - top + 4 + textOffset, - 0xffffffdd, - true - ); + fr.drawString(item.itemName, guiLeft + 8 + 16 + 2 + textOffset, top + 4 + textOffset, 0xffffffdd, true); } GlScissorStack.pop(scaledResolution); @@ -2241,51 +1992,19 @@ public class GuiCustomHex extends Gui { colour = 0xff5555; }*/ - int levelWidth = Minecraft.getMinecraft().fontRendererObj.getStringWidth(levelStr); - Minecraft.getMinecraft().fontRendererObj.drawString( - levelStr, - guiLeft + 256 - levelWidth / 2 - 1, - top + 4, - 0x2d2102, - false - ); - Minecraft.getMinecraft().fontRendererObj.drawString( - levelStr, - guiLeft + 256 - levelWidth / 2 + 1, - top + 4, - 0x2d2102, - false - ); - Minecraft.getMinecraft().fontRendererObj.drawString( - levelStr, - guiLeft + 256 - levelWidth / 2, - top + 4 - 1, - 0x2d2102, - false - ); - Minecraft.getMinecraft().fontRendererObj.drawString( - levelStr, - guiLeft + 256 - levelWidth / 2, - top + 4 + 1, - 0x2d2102, - false - ); - Minecraft.getMinecraft().fontRendererObj.drawString( - levelStr, - guiLeft + 256 - levelWidth / 2, - top + 4, - colour, - false - ); + int levelWidth = fr.getStringWidth(levelStr); + fr.drawString(levelStr, guiLeft + 256 - levelWidth / 2 - 1, top + 4, 0x2d2102, false); + fr.drawString(levelStr, guiLeft + 256 - levelWidth / 2 + 1, top + 4, 0x2d2102, false); + fr.drawString(levelStr, guiLeft + 256 - levelWidth / 2, top + 4 - 1, 0x2d2102, false); + fr.drawString(levelStr, guiLeft + 256 - levelWidth / 2, top + 4 + 1, 0x2d2102, false); + fr.drawString(levelStr, guiLeft + 256 - levelWidth / 2, top + 4, colour, false); - Minecraft.getMinecraft().fontRendererObj.drawString(item.itemName, - guiLeft + 248 + 16 + 2 + textOffset, top + 4 + textOffset, 0xffffffdd, true - ); + fr.drawString(item.itemName, guiLeft + 248 + 16 + 2 + textOffset, top + 4 + textOffset, 0xffffffdd, true); } GlScissorStack.pop(scaledResolution); //Player Inventory Items - Minecraft.getMinecraft().fontRendererObj.drawString(Minecraft.getMinecraft().thePlayer.inventory + fr.drawString(Minecraft.getMinecraft().thePlayer.inventory .getDisplayName() .getUnformattedText(), guiLeft + 102, guiTop + Y_SIZE - 96 + 2, 0x404040 @@ -2328,7 +2047,7 @@ public class GuiCustomHex extends Gui { searchField.setPrependText("\u00a77Search..."); } else { if (searchField.getFocus()) { - int len = Minecraft.getMinecraft().fontRendererObj.getStringWidth(searchField.getTextDisplay()) + 10; + int len = fr.getStringWidth(searchField.getTextDisplay()) + 10; searchField.setSize(Math.max(90, len), 14); } else { searchField.setSize(90, 14); @@ -2359,57 +2078,20 @@ public class GuiCustomHex extends Gui { String priceStr = "" + numberFormat.format(enchanterCurrentItem.getPrice()) + " Coins"; if (enchanterCurrentItem.price < 0) priceStr = ""; - int priceWidth = Minecraft.getMinecraft().fontRendererObj.getStringWidth(priceStr); + int priceWidth = fr.getStringWidth(priceStr); int priceTop = guiTop + 10; int x = 180; int color = 0x2d2102; - Minecraft.getMinecraft().fontRendererObj.drawString( - priceStr, - guiLeft + x - priceWidth / 2 - 1, - priceTop + 4, - color, - false - ); - Minecraft.getMinecraft().fontRendererObj.drawString( - priceStr, - guiLeft + x - priceWidth / 2 + 1, - priceTop + 4, - color, - false - ); - Minecraft.getMinecraft().fontRendererObj.drawString( - priceStr, - guiLeft + x - priceWidth / 2, - priceTop + 4 - 1, - color, - false - ); - Minecraft.getMinecraft().fontRendererObj.drawString( - priceStr, - guiLeft + x - priceWidth / 2, - priceTop + 4 + 1, - color, - false - ); - Minecraft.getMinecraft().fontRendererObj.drawString( - priceStr, - guiLeft + x - priceWidth / 2, - priceTop + 4, - 0xfcba03, - false - ); + fr.drawString(priceStr, guiLeft + x - priceWidth / 2 - 1, priceTop + 4, color, false); + fr.drawString(priceStr, guiLeft + x - priceWidth / 2 + 1, priceTop + 4, color, false); + fr.drawString(priceStr, guiLeft + x - priceWidth / 2, priceTop + 4 - 1, color, false); + fr.drawString(priceStr, guiLeft + x - priceWidth / 2, priceTop + 4 + 1, color, false); + fr.drawString(priceStr, guiLeft + x - priceWidth / 2, priceTop + 4, 0xfcba03, false); //Enchant name String name = WordUtils.capitalizeFully(enchanterCurrentItem.itemId.replace("_", " ")); name = fixName(name); - Utils.drawStringCentered( - name, - Minecraft.getMinecraft().fontRendererObj, - guiLeft + X_SIZE / 2, - top + 8, - true, - 0xffffffdd - ); + Utils.drawStringCentered(name, guiLeft + X_SIZE / 2, top + 8, true, 0xffffffdd); //Confirm button String confirmText = "Apply"; @@ -2428,7 +2110,7 @@ public class GuiCustomHex extends Gui { Utils.drawTexturedRect(guiLeft + X_SIZE / 2 - 1 - 48, top + 18, 48, 14, 0, 48 / 512f, 342 / 512f, (342 + 14) / 512f, GL11.GL_NEAREST ); - Utils.drawStringCentered(confirmText, Minecraft.getMinecraft().fontRendererObj, + Utils.drawStringCentered(confirmText, guiLeft + X_SIZE / 2 - 1 - 23, top + 18 + 9, false, 0x408040 ); } else { @@ -2437,7 +2119,7 @@ public class GuiCustomHex extends Gui { Utils.drawTexturedRect(guiLeft + X_SIZE / 2 - 1 - 48, top + 18, 48, 14, 0, 48 / 512f, 328 / 512f, (328 + 14) / 512f, GL11.GL_NEAREST ); - Utils.drawStringCentered(confirmText, Minecraft.getMinecraft().fontRendererObj, + Utils.drawStringCentered(confirmText, guiLeft + X_SIZE / 2 - 1 - 24, top + 18 + 8, false, 0x408040 ); @@ -2453,7 +2135,7 @@ public class GuiCustomHex extends Gui { Utils.drawTexturedRect(guiLeft + X_SIZE / 2 + 1, top + 18, 48, 14, 0, 48 / 512f, 342 / 512f, (342 + 14) / 512f, GL11.GL_NEAREST ); - Utils.drawStringCentered("Cancel", Minecraft.getMinecraft().fontRendererObj, + Utils.drawStringCentered("Cancel", guiLeft + X_SIZE / 2 + 1 + 25, top + 18 + 9, false, 0xa04040 ); } else { @@ -2462,7 +2144,7 @@ public class GuiCustomHex extends Gui { Utils.drawTexturedRect(guiLeft + X_SIZE / 2 + 1, top + 18, 48, 14, 0, 48 / 512f, 328 / 512f, (328 + 14) / 512f, GL11.GL_NEAREST ); - Utils.drawStringCentered("Cancel", Minecraft.getMinecraft().fontRendererObj, + Utils.drawStringCentered("Cancel", guiLeft + X_SIZE / 2 + 1 + 24, top + 18 + 8, false, 0xa04040 ); } @@ -2574,7 +2256,8 @@ public class GuiCustomHex extends Gui { renderBaseTexture(); - Minecraft.getMinecraft().fontRendererObj.drawString("The Hex", guiLeft + 7, guiTop + 7, 0x404040, false); + FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; + fr.drawString("The Hex", guiLeft + 7, guiTop + 7, 0x404040, false); //Minecraft.getMinecraft().fontRendererObj.drawString("Applied", guiLeft + 247, guiTop + 7, 0x404040, false); tooltipToDisplay = renderSettings(mouseX, mouseY, tooltipToDisplay); @@ -2587,10 +2270,10 @@ public class GuiCustomHex extends Gui { //Can't be enchanted text if (currentState == EnchantState.INVALID_ITEM_HEX) { GlStateManager.disableDepth(); - Utils.drawStringCentered("This item can't", Minecraft.getMinecraft().fontRendererObj, + Utils.drawStringCentered("This item can't", guiLeft + X_SIZE / 2, guiTop + 88, true, 0xffff5555 ); - Utils.drawStringCentered("be enchanted", Minecraft.getMinecraft().fontRendererObj, + Utils.drawStringCentered("be enchanted", guiLeft + X_SIZE / 2, guiTop + 98, true, 0xffff5555 ); GlStateManager.enableDepth(); @@ -2631,50 +2314,14 @@ public class GuiCustomHex extends Gui { colour = 0xff5555; } - int levelWidth = Minecraft.getMinecraft().fontRendererObj.getStringWidth(levelStr); - Minecraft.getMinecraft().fontRendererObj.drawString( - levelStr, - guiLeft + 16 - levelWidth / 2 - 1, - top + 4, - 0x2d2102, - false - ); - Minecraft.getMinecraft().fontRendererObj.drawString( - levelStr, - guiLeft + 16 - levelWidth / 2 + 1, - top + 4, - 0x2d2102, - false - ); - Minecraft.getMinecraft().fontRendererObj.drawString( - levelStr, - guiLeft + 16 - levelWidth / 2, - top + 4 - 1, - 0x2d2102, - false - ); - Minecraft.getMinecraft().fontRendererObj.drawString( - levelStr, - guiLeft + 16 - levelWidth / 2, - top + 4 + 1, - 0x2d2102, - false - ); - Minecraft.getMinecraft().fontRendererObj.drawString( - levelStr, - guiLeft + 16 - levelWidth / 2, - top + 4, - colour, - false - ); + int levelWidth = fr.getStringWidth(levelStr); + fr.drawString(levelStr, guiLeft + 16 - levelWidth / 2 - 1, top + 4, 0x2d2102, false); + fr.drawString(levelStr, guiLeft + 16 - levelWidth / 2 + 1, top + 4, 0x2d2102, false); + fr.drawString(levelStr, guiLeft + 16 - levelWidth / 2, top + 4 - 1, 0x2d2102, false); + fr.drawString(levelStr, guiLeft + 16 - levelWidth / 2, top + 4 + 1, 0x2d2102, false); + fr.drawString(levelStr, guiLeft + 16 - levelWidth / 2, top + 4, colour, false); - Minecraft.getMinecraft().fontRendererObj.drawString( - item.itemName, - guiLeft + 8 + 16 + 2 + textOffset, - top + 4 + textOffset, - 0xffffffdd, - true - ); + fr.drawString(item.itemName, guiLeft + 8 + 16 + 2 + textOffset, top + 4 + textOffset, 0xffffffdd, true); } GlScissorStack.pop(scaledResolution); @@ -2710,53 +2357,20 @@ public class GuiCustomHex extends Gui { colour = 0xff5555; } - int levelWidth = Minecraft.getMinecraft().fontRendererObj.getStringWidth(levelStr); - Minecraft.getMinecraft().fontRendererObj.drawString( - levelStr, - guiLeft + 256 - levelWidth / 2 - 1, - top + 4, - 0x2d2102, - false - ); - Minecraft.getMinecraft().fontRendererObj.drawString( - levelStr, - guiLeft + 256 - levelWidth / 2 + 1, - top + 4, - 0x2d2102, - false - ); - Minecraft.getMinecraft().fontRendererObj.drawString( - levelStr, - guiLeft + 256 - levelWidth / 2, - top + 4 - 1, - 0x2d2102, - false - ); - Minecraft.getMinecraft().fontRendererObj.drawString( - levelStr, - guiLeft + 256 - levelWidth / 2, - top + 4 + 1, - 0x2d2102, - false - ); - Minecraft.getMinecraft().fontRendererObj.drawString( - levelStr, - guiLeft + 256 - levelWidth / 2, - top + 4, - colour, - false - ); + int levelWidth = fr.getStringWidth(levelStr); + fr.drawString(levelStr, guiLeft + 256 - levelWidth / 2 - 1, top + 4, 0x2d2102, false); + fr.drawString(levelStr, guiLeft + 256 - levelWidth / 2 + 1, top + 4, 0x2d2102, false); + fr.drawString(levelStr, guiLeft + 256 - levelWidth / 2, top + 4 - 1, 0x2d2102, false); + fr.drawString(levelStr, guiLeft + 256 - levelWidth / 2, top + 4 + 1, 0x2d2102, false); + fr.drawString(levelStr, guiLeft + 256 - levelWidth / 2, top + 4, colour, false); - Minecraft.getMinecraft().fontRendererObj.drawString(item.itemName, - guiLeft + 248 + 16 + 2 + textOffset, top + 4 + textOffset, 0xffffffdd, true - ); + fr.drawString(item.itemName, guiLeft + 248 + 16 + 2 + textOffset, top + 4 + textOffset, 0xffffffdd, true); } GlScissorStack.pop(scaledResolution); //Player Inventory Items - Minecraft.getMinecraft().fontRendererObj.drawString(Minecraft.getMinecraft().thePlayer.inventory - .getDisplayName() - .getUnformattedText(), + fr.drawString( + Minecraft.getMinecraft().thePlayer.inventory.getDisplayName().getUnformattedText(), guiLeft + 102, guiTop + Y_SIZE - 96 + 2, 0x404040 ); int inventoryStartIndex = cc.getLowerChestInventory().getSizeInventory(); @@ -2918,14 +2532,15 @@ public class GuiCustomHex extends Gui { renderBaseTexture(); - Minecraft.getMinecraft().fontRendererObj.drawString("Applicable", guiLeft + 7, guiTop + 7, 0x404040, false); - Minecraft.getMinecraft().fontRendererObj.drawString("Applied", guiLeft + 247, guiTop + 7, 0x404040, false); + FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; + fr.drawString("Applicable", guiLeft + 7, guiTop + 7, 0x404040, false); + fr.drawString("Applied", guiLeft + 247, guiTop + 7, 0x404040, false); //Page Text if (currentState == EnchantState.ADDING_GEMSTONE || currentState == EnchantState.APPLYING_GEMSTONE) { String pageStr = "Page: " + currentPage + "/" + expectedMaxPage; - int pageStrLen = Minecraft.getMinecraft().fontRendererObj.getStringWidth(pageStr); - Utils.drawStringCentered(pageStr, Minecraft.getMinecraft().fontRendererObj, + int pageStrLen = fr.getStringWidth(pageStr); + Utils.drawStringCentered(pageStr, guiLeft + X_SIZE / 2, guiTop + 14, false, 0x404040 ); @@ -2960,7 +2575,7 @@ public class GuiCustomHex extends Gui { Utils.drawTexturedRect(guiLeft + X_SIZE / 2 - 1 - 48, top + 18, 48, 14, 0, 48 / 512f, 342 / 512f, (342 + 14) / 512f, GL11.GL_NEAREST ); - Utils.drawStringCentered(confirmText, Minecraft.getMinecraft().fontRendererObj, + Utils.drawStringCentered(confirmText, guiLeft + X_SIZE / 2 - 1 - 23, top + 18 + 9, false, 0x408040 ); } else { @@ -2969,7 +2584,7 @@ public class GuiCustomHex extends Gui { Utils.drawTexturedRect(guiLeft + X_SIZE / 2 - 1 - 48, top + 18, 48, 14, 0, 48 / 512f, 328 / 512f, (328 + 14) / 512f, GL11.GL_NEAREST ); - Utils.drawStringCentered(confirmText, Minecraft.getMinecraft().fontRendererObj, + Utils.drawStringCentered(confirmText, guiLeft + X_SIZE / 2 - 1 - 24, top + 18 + 8, false, 0x408040 ); } @@ -2983,7 +2598,7 @@ public class GuiCustomHex extends Gui { Utils.drawTexturedRect(guiLeft + X_SIZE / 2 + 1, top + 18, 48, 14, 0, 48 / 512f, 342 / 512f, (342 + 14) / 512f, GL11.GL_NEAREST ); - Utils.drawStringCentered("Cancel", Minecraft.getMinecraft().fontRendererObj, + Utils.drawStringCentered("Cancel", guiLeft + X_SIZE / 2 + 1 + 25, top + 18 + 9, false, 0xa04040 ); } else { @@ -2992,7 +2607,7 @@ public class GuiCustomHex extends Gui { Utils.drawTexturedRect(guiLeft + X_SIZE / 2 + 1, top + 18, 48, 14, 0, 48 / 512f, 328 / 512f, (328 + 14) / 512f, GL11.GL_NEAREST ); - Utils.drawStringCentered("Cancel", Minecraft.getMinecraft().fontRendererObj, + Utils.drawStringCentered("Cancel", guiLeft + X_SIZE / 2 + 1 + 24, top + 18 + 8, false, 0xa04040 ); } @@ -3040,50 +2655,14 @@ public class GuiCustomHex extends Gui { colour = 0xff5555; } - int levelWidth = Minecraft.getMinecraft().fontRendererObj.getStringWidth(levelStr); - Minecraft.getMinecraft().fontRendererObj.drawString( - levelStr, - guiLeft + 16 - levelWidth / 2 - 1, - top + 4, - 0x2d2102, - false - ); - Minecraft.getMinecraft().fontRendererObj.drawString( - levelStr, - guiLeft + 16 - levelWidth / 2 + 1, - top + 4, - 0x2d2102, - false - ); - Minecraft.getMinecraft().fontRendererObj.drawString( - levelStr, - guiLeft + 16 - levelWidth / 2, - top + 4 - 1, - 0x2d2102, - false - ); - Minecraft.getMinecraft().fontRendererObj.drawString( - levelStr, - guiLeft + 16 - levelWidth / 2, - top + 4 + 1, - 0x2d2102, - false - ); - Minecraft.getMinecraft().fontRendererObj.drawString( - levelStr, - guiLeft + 16 - levelWidth / 2, - top + 4, - colour, - false - ); + int levelWidth = fr.getStringWidth(levelStr); + fr.drawString(levelStr, guiLeft + 16 - levelWidth / 2 - 1, top + 4, 0x2d2102, false); + fr.drawString(levelStr, guiLeft + 16 - levelWidth / 2 + 1, top + 4, 0x2d2102, false); + fr.drawString(levelStr, guiLeft + 16 - levelWidth / 2, top + 4 - 1, 0x2d2102, false); + fr.drawString(levelStr, guiLeft + 16 - levelWidth / 2, top + 4 + 1, 0x2d2102, false); + fr.drawString(levelStr, guiLeft + 16 - levelWidth / 2, top + 4, colour, false); - Minecraft.getMinecraft().fontRendererObj.drawString( - item.itemName, - guiLeft + 8 + 16 + 2 + textOffset, - top + 4 + textOffset, - 0xffffffdd, - true - ); + fr.drawString(item.itemName, guiLeft + 8 + 16 + 2 + textOffset, top + 4 + textOffset, 0xffffffdd, true); } GlScissorStack.pop(scaledResolution); @@ -3119,51 +2698,19 @@ public class GuiCustomHex extends Gui { colour = 0xff5555; } - int levelWidth = Minecraft.getMinecraft().fontRendererObj.getStringWidth(levelStr); - Minecraft.getMinecraft().fontRendererObj.drawString( - levelStr, - guiLeft + 256 - levelWidth / 2 - 1, - top + 4, - 0x2d2102, - false - ); - Minecraft.getMinecraft().fontRendererObj.drawString( - levelStr, - guiLeft + 256 - levelWidth / 2 + 1, - top + 4, - 0x2d2102, - false - ); - Minecraft.getMinecraft().fontRendererObj.drawString( - levelStr, - guiLeft + 256 - levelWidth / 2, - top + 4 - 1, - 0x2d2102, - false - ); - Minecraft.getMinecraft().fontRendererObj.drawString( - levelStr, - guiLeft + 256 - levelWidth / 2, - top + 4 + 1, - 0x2d2102, - false - ); - Minecraft.getMinecraft().fontRendererObj.drawString( - levelStr, - guiLeft + 256 - levelWidth / 2, - top + 4, - colour, - false - ); + int levelWidth = fr.getStringWidth(levelStr); + fr.drawString(levelStr, guiLeft + 256 - levelWidth / 2 - 1, top + 4, 0x2d2102, false); + fr.drawString(levelStr, guiLeft + 256 - levelWidth / 2 + 1, top + 4, 0x2d2102, false); + fr.drawString(levelStr, guiLeft + 256 - levelWidth / 2, top + 4 - 1, 0x2d2102, false); + fr.drawString(levelStr, guiLeft + 256 - levelWidth / 2, top + 4 + 1, 0x2d2102, false); + fr.drawString(levelStr, guiLeft + 256 - levelWidth / 2, top + 4, colour, false); - Minecraft.getMinecraft().fontRendererObj.drawString(item.itemName, - guiLeft + 248 + 16 + 2 + textOffset, top + 4 + textOffset, 0xffffffdd, true - ); + fr.drawString(item.itemName, guiLeft + 248 + 16 + 2 + textOffset, top + 4 + textOffset, 0xffffffdd, true); } GlScissorStack.pop(scaledResolution); //Player Inventory Items - Minecraft.getMinecraft().fontRendererObj.drawString(Minecraft.getMinecraft().thePlayer.inventory + fr.drawString(Minecraft.getMinecraft().thePlayer.inventory .getDisplayName() .getUnformattedText(), guiLeft + 102, guiTop + Y_SIZE - 96 + 2, 0x404040 @@ -3286,36 +2833,12 @@ public class GuiCustomHex extends Gui { colour = 0xff5555; } - int levelWidth = Minecraft.getMinecraft().fontRendererObj.getStringWidth(levelStr); - Minecraft.getMinecraft().fontRendererObj.drawString( - levelStr, - left + 8 - levelWidth / 2 - 1, - top + 4, - 0x2d2102, - false - ); - Minecraft.getMinecraft().fontRendererObj.drawString( - levelStr, - left + 8 - levelWidth / 2 + 1, - top + 4, - 0x2d2102, - false - ); - Minecraft.getMinecraft().fontRendererObj.drawString( - levelStr, - left + 8 - levelWidth / 2, - top + 4 - 1, - 0x2d2102, - false - ); - Minecraft.getMinecraft().fontRendererObj.drawString( - levelStr, - left + 8 - levelWidth / 2, - top + 4 + 1, - 0x2d2102, - false - ); - Minecraft.getMinecraft().fontRendererObj.drawString(levelStr, left + 8 - levelWidth / 2, top + 4, colour, false); + int levelWidth = fr.getStringWidth(levelStr); + fr.drawString(levelStr, left + 8 - levelWidth / 2 - 1, top + 4, 0x2d2102, false); + fr.drawString(levelStr, left + 8 - levelWidth / 2 + 1, top + 4, 0x2d2102, false); + fr.drawString(levelStr, left + 8 - levelWidth / 2, top + 4 - 1, 0x2d2102, false); + fr.drawString(levelStr, left + 8 - levelWidth / 2, top + 4 + 1, 0x2d2102, false); + fr.drawString(levelStr, left + 8 - levelWidth / 2, top + 4, colour, false); //Enchant name String name = WordUtils.capitalizeFully(enchanterCurrentItem.itemName); @@ -3330,14 +2853,7 @@ public class GuiCustomHex extends Gui { } else if (name.equalsIgnoreCase("Turbo Mushrooms")) { name = "Turbo-Mush"; } - Utils.drawStringCentered( - name, - Minecraft.getMinecraft().fontRendererObj, - guiLeft + X_SIZE / 2, - top + 8, - true, - 0xffffffdd - ); + Utils.drawStringCentered(name, guiLeft + X_SIZE / 2, top + 8, true, 0xffffffdd); if (isChangingEnchLevel) { Minecraft.getMinecraft().getTextureManager().bindTexture(TEXTURE); @@ -3349,42 +2865,12 @@ public class GuiCustomHex extends Gui { //Enchant level levelStr = ""; - levelWidth = Minecraft.getMinecraft().fontRendererObj.getStringWidth(levelStr); - Minecraft.getMinecraft().fontRendererObj.drawString( - levelStr, - left + 96 + 8 - levelWidth / 2 - 1, - top + 4, - 0x2d2102, - false - ); - Minecraft.getMinecraft().fontRendererObj.drawString( - levelStr, - left + 96 + 8 - levelWidth / 2 + 1, - top + 4, - 0x2d2102, - false - ); - Minecraft.getMinecraft().fontRendererObj.drawString( - levelStr, - left + 96 + 8 - levelWidth / 2, - top + 4 - 1, - 0x2d2102, - false - ); - Minecraft.getMinecraft().fontRendererObj.drawString( - levelStr, - left + 96 + 8 - levelWidth / 2, - top + 4 + 1, - 0x2d2102, - false - ); - Minecraft.getMinecraft().fontRendererObj.drawString( - levelStr, - left + 96 + 8 - levelWidth / 2, - top + 4, - 0xea82ff, - false - ); + levelWidth = fr.getStringWidth(levelStr); + fr.drawString(levelStr, left + 96 + 8 - levelWidth / 2 - 1, top + 4, 0x2d2102, false); + fr.drawString(levelStr, left + 96 + 8 - levelWidth / 2 + 1, top + 4, 0x2d2102, false); + fr.drawString(levelStr, left + 96 + 8 - levelWidth / 2, top + 4 - 1, 0x2d2102, false); + fr.drawString(levelStr, left + 96 + 8 - levelWidth / 2, top + 4 + 1, 0x2d2102, false); + fr.drawString(levelStr, left + 96 + 8 - levelWidth / 2, top + 4, 0xea82ff, false); } if (!isChangingEnchLevel && itemHoverX >= 0 && itemHoverY >= 0) { @@ -3604,7 +3090,8 @@ public class GuiCustomHex extends Gui { Gui.drawRect(guiLeft + 295 + 18, guiTop + 147, guiLeft + 295 + 16 + 18, guiTop + 147 + 16, 0x80ffffff); tooltipToDisplay = createTooltip("Max Level", (NotEnoughUpdates.INSTANCE.config.enchantingSolvers.maxEnchLevel ? 0 : 1), - "Enabled", "Disabled"); + "Enabled", "Disabled" + ); tooltipToDisplay.add(1, EnumChatFormatting.GRAY + "Show max level of enchant"); tooltipToDisplay.add(2, EnumChatFormatting.GRAY + "from either hex or enchantment table"); tooltipToDisplay.add(3, EnumChatFormatting.GRAY + "max level"); @@ -3700,18 +3187,14 @@ public class GuiCustomHex extends Gui { Utils.drawTexturedRect(guiLeft + X_SIZE / 2 + 1, top + 18, 48, 14, 0, 48 / 512f, 342 / 512f, (342 + 14) / 512f, GL11.GL_NEAREST ); - Utils.drawStringCentered("Cancel", Minecraft.getMinecraft().fontRendererObj, - guiLeft + X_SIZE / 2 + 1 + 25, top + 18 + 9, false, 0xa04040 - ); + Utils.drawStringCentered("Cancel", guiLeft + X_SIZE / 2 + 1 + 25, top + 18 + 9, false, 0xa04040); } else { Minecraft.getMinecraft().getTextureManager().bindTexture(TEXTURE); GlStateManager.color(1, 1, 1, 1); Utils.drawTexturedRect(guiLeft + X_SIZE / 2 + 1, top + 18, 48, 14, 0, 48 / 512f, 328 / 512f, (328 + 14) / 512f, GL11.GL_NEAREST ); - Utils.drawStringCentered("Cancel", Minecraft.getMinecraft().fontRendererObj, - guiLeft + X_SIZE / 2 + 1 + 24, top + 18 + 8, false, 0xa04040 - ); + Utils.drawStringCentered("Cancel", guiLeft + X_SIZE / 2 + 1 + 24, top + 18 + 8, false, 0xa04040); } } @@ -3735,9 +3218,7 @@ public class GuiCustomHex extends Gui { Utils.drawItemStack(stackOnMouse, mouseX - 8, mouseY - 8); } } else if (tooltipToDisplay != null) { - Utils.drawHoveringText(tooltipToDisplay, mouseX, mouseY, width, height, -1, - Minecraft.getMinecraft().fontRendererObj - ); + Utils.drawHoveringText(tooltipToDisplay, mouseX, mouseY, width, height, -1); } } @@ -4380,7 +3861,8 @@ public class GuiCustomHex extends Gui { break; } case 1: { - NotEnoughUpdates.INSTANCE.config.enchantingSolvers.maxEnchLevel = !NotEnoughUpdates.INSTANCE.config.enchantingSolvers.maxEnchLevel; + NotEnoughUpdates.INSTANCE.config.enchantingSolvers.maxEnchLevel = + !NotEnoughUpdates.INSTANCE.config.enchantingSolvers.maxEnchLevel; break; } case 2: { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/render/MinionHelperOverlayHover.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/render/MinionHelperOverlayHover.java index 84678c0c..a3549d51 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/render/MinionHelperOverlayHover.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/render/MinionHelperOverlayHover.java @@ -68,9 +68,7 @@ public class MinionHelperOverlayHover { OverviewLine mouseObject = overlay.getObjectOverMouse(renderMap); if (mouseObject != null) { - Utils.drawHoveringText(getTooltip(mouseObject), mouseX, mouseY, - scaledWidth, scaledHeight, -1, Minecraft.getMinecraft().fontRendererObj - ); + Utils.drawHoveringText(getTooltip(mouseObject), mouseX, mouseY, scaledWidth, scaledHeight, -1); } renderButtons(); @@ -90,7 +88,6 @@ public class MinionHelperOverlayHover { int mouseX = Mouse.getX() * scaledWidth / Minecraft.getMinecraft().displayWidth; int mouseY = scaledHeight - Mouse.getY() * scaledHeight / Minecraft.getMinecraft().displayHeight - 1; - int x = guiLeft + xSize + 4 + 149 - 3; int y = guiTop + 109 - 3; if (mouseX > x && mouseX < x + 16 && @@ -122,9 +119,7 @@ public class MinionHelperOverlayHover { list.add(""); list.add("§eClick to toggle!"); - Utils.drawHoveringText(list, mouseX, mouseY, scaledWidth, scaledHeight, -1, - Minecraft.getMinecraft().fontRendererObj - ); + Utils.drawHoveringText(list, mouseX, mouseY, scaledWidth, scaledHeight, -1); } private void renderBuyPriceButton(int scaledWidth, int scaledHeight, int mouseX, int mouseY) { @@ -145,9 +140,7 @@ public class MinionHelperOverlayHover { list.add(""); list.add("§eClick to toggle!"); - Utils.drawHoveringText(list, mouseX, mouseY, scaledWidth, scaledHeight, -1, - Minecraft.getMinecraft().fontRendererObj - ); + Utils.drawHoveringText(list, mouseX, mouseY, scaledWidth, scaledHeight, -1); } private List getTooltip(OverviewLine overviewLine) { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfigEditor.java b/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfigEditor.java index fe1f0af4..677e5822 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfigEditor.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfigEditor.java @@ -34,7 +34,6 @@ import io.github.moulberry.notenoughupdates.core.util.render.RenderUtils; import io.github.moulberry.notenoughupdates.core.util.render.TextRenderUtils; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.Gui; import net.minecraft.client.gui.ScaledResolution; import net.minecraft.client.renderer.GlStateManager; @@ -289,15 +288,9 @@ public class NEUConfigEditor extends GuiElement { RenderUtils.drawFloatingRectDark(x + 5, y + 5, xSize - 10, 20, false); - FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; TextRenderUtils.drawStringCenteredScaledMaxWidth( "NotEnoughUpdates by " + EnumChatFormatting.DARK_PURPLE + "Moulberry", - fr, - x + xSize / 2, - y + 15, - false, - 200, - 0xa0a0a0 + x + xSize / 2, y + 15, false, 200, 0xa0a0a0 ); RenderUtils.drawFloatingRectDark(x + 4, y + 49 - 20, @@ -334,9 +327,7 @@ public class NEUConfigEditor extends GuiElement { } else { catName = EnumChatFormatting.GRAY + catName; } - TextRenderUtils.drawStringCenteredScaledMaxWidth(catName, - fr, x + 75, y + 70 + catY, false, 100, -1 - ); + TextRenderUtils.drawStringCenteredScaledMaxWidth(catName, x + 75, y + 70 + catY, false, 100, -1); catY += 15; if (catY > 0) { catBarSize = @@ -366,9 +357,7 @@ public class NEUConfigEditor extends GuiElement { GlScissorStack.pop(scaledResolution); - TextRenderUtils.drawStringCenteredScaledMaxWidth("Categories", - fr, x + 75, y + 44, false, 120, 0xa368ef - ); + TextRenderUtils.drawStringCenteredScaledMaxWidth("Categories", x + 75, y + 44, false, 120, 0xa368ef); RenderUtils.drawFloatingRectDark(x + 149, y + 29, xSize - 154, ySize - 34, false); @@ -405,8 +394,9 @@ public class NEUConfigEditor extends GuiElement { if (getSelectedCategory() != null && currentConfigEditing.containsKey(getSelectedCategory())) { ConfigProcessor.ProcessedCategory cat = currentConfigEditing.get(getSelectedCategory()); - TextRenderUtils.drawStringScaledMaxWidth(cat.desc, - fr, innerLeft + 5, y + 40, true, innerRight - innerLeft - rightStuffLen - 10, 0xb0b0b0 + TextRenderUtils.drawStringScaledMaxWidth( + cat.desc, + innerLeft + 5, y + 40, true, innerRight - innerLeft - rightStuffLen - 10, 0xb0b0b0 ); } @@ -552,7 +542,9 @@ public class NEUConfigEditor extends GuiElement { GlScissorStack.clear(); if (tooltipToDisplay != null) { - TextRenderUtils.drawHoveringText(tooltipToDisplay, mouseX, mouseY, width, height, -1, fr); + TextRenderUtils.drawHoveringText(tooltipToDisplay, mouseX, mouseY, width, height, -1, + Minecraft.getMinecraft().fontRendererObj + ); } GlStateManager.translate(0, 0, -2); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/overlays/AuctionSearchOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/overlays/AuctionSearchOverlay.java index fcea79dd..942eee8b 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/overlays/AuctionSearchOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/overlays/AuctionSearchOverlay.java @@ -274,15 +274,7 @@ public class AuctionSearchOverlay { } if (tooltipToDisplay != null) { - Utils.drawHoveringText( - tooltipToDisplay, - mouseX, - mouseY, - width, - height, - -1, - Minecraft.getMinecraft().fontRendererObj - ); + Utils.drawHoveringText(tooltipToDisplay, mouseX, mouseY, width, height, -1); } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/overlays/BazaarSearchOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/overlays/BazaarSearchOverlay.java index 66dacda3..dab9156e 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/overlays/BazaarSearchOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/overlays/BazaarSearchOverlay.java @@ -225,15 +225,7 @@ public class BazaarSearchOverlay { } if (tooltipToDisplay != null) { - Utils.drawHoveringText( - tooltipToDisplay, - mouseX, - mouseY, - width, - height, - -1, - Minecraft.getMinecraft().fontRendererObj - ); + Utils.drawHoveringText(tooltipToDisplay, mouseX, mouseY, width, height, -1); } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/overlays/EquipmentOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/overlays/EquipmentOverlay.java index db81bfa4..a812ff52 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/overlays/EquipmentOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/overlays/EquipmentOverlay.java @@ -34,7 +34,6 @@ import io.github.moulberry.notenoughupdates.util.ItemUtils; import io.github.moulberry.notenoughupdates.util.SBInfo; 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.inventory.GuiChest; import net.minecraft.client.gui.inventory.GuiInventory; @@ -108,7 +107,9 @@ public class EquipmentOverlay { case 2: return ARMOR_DISPLAY_DARK; case 3: - return NotEnoughUpdates.INSTANCE.config.petOverlay.colourStyle == 3 && isPetRendering ? ARMOR_DISPLAY_TRANSPARENT_PET : ARMOR_DISPLAY_TRANSPARENT; + return NotEnoughUpdates.INSTANCE.config.petOverlay.colourStyle == 3 && isPetRendering + ? ARMOR_DISPLAY_TRANSPARENT_PET + : ARMOR_DISPLAY_TRANSPARENT; case 4: return ARMOR_DISPLAY_FSR; } @@ -142,7 +143,6 @@ public class EquipmentOverlay { public static final int PET_OVERLAY_OFFSET_Y = ARMOR_OVERLAY_HEIGHT - 14 /* overlaying pixels */; // - public boolean shouldRenderPets; public boolean shouldRenderArmorHud; @@ -229,12 +229,7 @@ public class EquipmentOverlay { )) { Utils.drawHoveringText( tooltipToDisplay, - mouseX - calculateTooltipXOffset(tooltipToDisplay, Minecraft.getMinecraft().fontRendererObj), - mouseY, - width, - height, - -1, - Minecraft.getMinecraft().fontRendererObj + mouseX - calculateTooltipXOffset(tooltipToDisplay), mouseY, width, height, -1 ); } @@ -263,7 +258,8 @@ public class EquipmentOverlay { slot4 = getWardrobeSlot(37); } - if ((screen instanceof GuiChest || screen instanceof GuiInventory) && NotEnoughUpdates.INSTANCE.config.petOverlay.petInvDisplay){ + if ((screen instanceof GuiChest || screen instanceof GuiInventory) && + NotEnoughUpdates.INSTANCE.config.petOverlay.petInvDisplay) { petStack = getRepoPetStack(); } if ((!(screen instanceof GuiInventory) && !(screen instanceof GuiInvButtonEditor)) @@ -321,12 +317,8 @@ public class EquipmentOverlay { tooltipToDisplay = petInfo.getTooltip(Minecraft.getMinecraft().thePlayer, false); Utils.drawHoveringText( tooltipToDisplay, - mouseX - calculateTooltipXOffset(tooltipToDisplay, Minecraft.getMinecraft().fontRendererObj), - mouseY, - width, - height, - -1, - Minecraft.getMinecraft().fontRendererObj + mouseX - calculateTooltipXOffset(tooltipToDisplay), + mouseY, width, height, -1 ); } } @@ -413,14 +405,13 @@ public class EquipmentOverlay { * Calculates the width of the longest String in the tooltip, which can be used to offset the entire tooltip to the left more precisely * * @param tooltipToDisplay tooltip - * @param fr FontRenderer object * @return offset to apply */ - private int calculateTooltipXOffset(List tooltipToDisplay, FontRenderer fr) { + private int calculateTooltipXOffset(List tooltipToDisplay) { int offset = 0; if (tooltipToDisplay != null) { for (String line : tooltipToDisplay) { - int lineWidth = fr.getStringWidth(line); + int lineWidth = Minecraft.getMinecraft().fontRendererObj.getStringWidth(line); if (lineWidth > offset) { offset = lineWidth; } @@ -430,7 +421,8 @@ public class EquipmentOverlay { } public void renderPreviewArmorHud() { - if (!NotEnoughUpdates.INSTANCE.config.customArmour.enableArmourHud || !(Minecraft.getMinecraft().currentScreen instanceof GuiInvButtonEditor)) return; + if (!NotEnoughUpdates.INSTANCE.config.customArmour.enableArmourHud || + !(Minecraft.getMinecraft().currentScreen instanceof GuiInvButtonEditor)) return; GuiInvButtonEditor container = (GuiInvButtonEditor) Minecraft.getMinecraft().currentScreen; int overlayLeft = container.getGuiLeft() - ARMOR_OVERLAY_OVERHAND_WIDTH; @@ -443,7 +435,8 @@ public class EquipmentOverlay { } public void renderPreviewPetInvHud() { - if (!NotEnoughUpdates.INSTANCE.config.petOverlay.petInvDisplay || !(Minecraft.getMinecraft().currentScreen instanceof GuiInvButtonEditor)) return; + if (!NotEnoughUpdates.INSTANCE.config.petOverlay.petInvDisplay || + !(Minecraft.getMinecraft().currentScreen instanceof GuiInvButtonEditor)) return; GuiInvButtonEditor container = (GuiInvButtonEditor) Minecraft.getMinecraft().currentScreen; int overlayLeft = container.getGuiLeft() - ARMOR_OVERLAY_OVERHAND_WIDTH; int overlayTop = container.getGuiTop() + PET_OVERLAY_OFFSET_Y; diff --git a/src/main/java/io/github/moulberry/notenoughupdates/overlays/RancherBootOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/overlays/RancherBootOverlay.java index 2a30f6f1..22f6eb96 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/overlays/RancherBootOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/overlays/RancherBootOverlay.java @@ -92,14 +92,7 @@ public class RancherBootOverlay { selectedIndex == i ? 0xff0000ff : 0xff808080 ); Utils.drawItemStack(new ItemStack(Items.carrot), iconsLeft + i * 25 + 2, topY + 25 + 2); - Utils.drawStringCentered( - "" + currentSpeeds.get(i), - Minecraft.getMinecraft().fontRendererObj, - iconsLeft + i * 25 + 10, - topY + 52, - true, - 0xffffffff - ); + Utils.drawStringCentered("" + currentSpeeds.get(i), iconsLeft + i * 25 + 10, topY + 52, true, 0xffffffff); //Minecraft.getMinecraft().fontRendererObj.drawString("\u2710", iconsLeft+i*25+15, topY+40, 0xffffff, false); } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/BasicPage.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/BasicPage.java index 5939e122..266722e5 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/BasicPage.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/BasicPage.java @@ -317,19 +317,13 @@ public class BasicPage extends GuiProfileViewerPage { int offset = (fontWidth >= 117 ? 63 + (fontWidth - 117) : 63); if (networth > 0) { if (fontWidth >= 117) { - fr.drawString(EnumChatFormatting.GREEN + "Net Worth: " + EnumChatFormatting.GOLD + GuiProfileViewer.numberFormat.format(networth), guiLeft + 8, guiTop + 38 - fr.FONT_HEIGHT / 2f, 0, true); - } else { Utils.drawStringCentered( EnumChatFormatting.GREEN + "Net Worth: " + EnumChatFormatting.GOLD + GuiProfileViewer.numberFormat.format(networth), - fr, - guiLeft + 68, - guiTop + 38, - true, - 0 + guiLeft + 68, guiTop + 38, true, 0 ); } if (NotEnoughUpdates.INSTANCE.manager.auctionManager.getBazaarInfo("BOOSTER_COOKIE") != null && @@ -400,11 +394,7 @@ public class BasicPage extends GuiProfileViewerPage { } else { Utils.drawStringCentered( EnumChatFormatting.GREEN + "Net Worth: " + stateStr, - fr, - guiLeft + 63, - guiTop + 38, - true, - 0 + guiLeft + 63, guiTop + 38, true, 0 ); } } @@ -440,7 +430,7 @@ public class BasicPage extends GuiProfileViewerPage { statusStr += EnumChatFormatting.GRAY + " - " + EnumChatFormatting.GREEN + locationStr; } - Utils.drawStringCentered(statusStr, fr, guiLeft + 63, guiTop + 160, true, 0); + Utils.drawStringCentered(statusStr, guiLeft + 63, guiTop + 160, true, 0); } if (entityPlayer == null) { @@ -600,14 +590,14 @@ public class BasicPage extends GuiProfileViewerPage { GlStateManager.scale(1.5f, 1.5f, 1); Utils.drawItemStack(skull, 0, 0); GlStateManager.popMatrix(); - Utils.drawStringCenteredScaled(skyblockLevelColour.toString() + (int) skyblockLevel, fr, + Utils.drawStringCenteredScaled(skyblockLevelColour.toString() + (int) skyblockLevel, sbLevelX + 9, sbLevelY - 12, true, 1.5f ); float progress = (float) (skyblockLevel - (long) skyblockLevel); getInstance().renderBar(sbLevelX - 30, sbLevelY + 30, 80, progress); - Utils.drawStringScaled(EnumChatFormatting.YELLOW.toString() + (int) (progress * 100) + "/100", fr, + Utils.drawStringScaled(EnumChatFormatting.YELLOW.toString() + (int) (progress * 100) + "/100", sbLevelX - 30, sbLevelY + 20, true, 0, 0.9f ); @@ -723,11 +713,7 @@ public class BasicPage extends GuiProfileViewerPage { } else { Utils.drawStringCentered( EnumChatFormatting.RED + "Skills API not enabled!", - Minecraft.getMinecraft().fontRendererObj, - guiLeft + 322, - guiTop + 101, - true, - 0 + guiLeft + 322, guiTop + 101, true, 0 ); } @@ -808,11 +794,7 @@ public class BasicPage extends GuiProfileViewerPage { "Senither Weight: " + EnumChatFormatting.GOLD + GuiProfileViewer.numberFormat.format(roundToNearestInt(senitherWeight.getTotalWeight().getRaw())), - fr, - guiLeft + 63, - guiTop + 18, - true, - 0 + guiLeft + 63, guiTop + 18, true, 0 ); int textWidth = fr.getStringWidth( @@ -873,14 +855,9 @@ public class BasicPage extends GuiProfileViewerPage { Utils.drawStringCentered( EnumChatFormatting.GREEN + - "Lily Weight: " + - EnumChatFormatting.GOLD + + "Lily Weight: " + EnumChatFormatting.GOLD + GuiProfileViewer.numberFormat.format(roundToNearestInt(lilyWeight.getTotalWeight().getRaw())), - fr, - guiLeft + 63, - guiTop + 28, - true, - 0 + guiLeft + 63, guiTop + 28, true, 0 ); int fontWidth = fr.getStringWidth( diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/BingoPage.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/BingoPage.java index ab80afab..cc5fc92f 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/BingoPage.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/BingoPage.java @@ -126,15 +126,7 @@ public class BingoPage extends GuiProfileViewerPage { y = communityGoal ? y - 1 : y; if (mouseX >= x && mouseX < x + 24) { if (mouseY >= y && mouseY <= y + 24) { - Utils.drawHoveringText( - getTooltip(bingoGoal, completed, communityGoal), - mouseX, - mouseY, - width, - height, - -1, - Minecraft.getMinecraft().fontRendererObj - ); + Utils.drawHoveringText(getTooltip(bingoGoal, completed, communityGoal), mouseX, mouseY, width, height, -1); } } col++; @@ -161,15 +153,8 @@ public class BingoPage extends GuiProfileViewerPage { EnumChatFormatting.WHITE + 20; } - Utils.drawStringF(totalPointsString, Minecraft.getMinecraft().fontRendererObj, guiLeft + 22, guiTop + 19, true, 0); - Utils.drawStringF( - personalGoalsString, - Minecraft.getMinecraft().fontRendererObj, - guiLeft + 22, - guiTop + 31, - true, - 0 - ); + Utils.drawStringF(totalPointsString, guiLeft + 22, guiTop + 19, true, 0); + Utils.drawStringF(personalGoalsString, guiLeft + 22, guiTop + 31, true, 0); GlStateManager.enableLighting(); } @@ -299,14 +284,7 @@ public class BingoPage extends GuiProfileViewerPage { private void showMissingDataMessage(int guiLeft, int guiTop) { String message = EnumChatFormatting.RED + "No Bingo data for current event!"; - Utils.drawStringCentered( - message, - Minecraft.getMinecraft().fontRendererObj, - guiLeft + 431 / 2f, - guiTop + 101, - true, - 0 - ); + Utils.drawStringCentered(message, guiLeft + 431 / 2f, guiTop + 101, true, 0); } private List jsonArrayToStringList(JsonArray completedGoals) { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/CollectionsPage.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/CollectionsPage.java index 45d9370b..03be7cf1 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/CollectionsPage.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/CollectionsPage.java @@ -36,9 +36,7 @@ import org.lwjgl.opengl.GL11; import java.awt.*; import java.io.IOException; -import java.math.BigDecimal; import java.math.BigInteger; -import java.math.RoundingMode; import java.text.NumberFormat; import java.util.ArrayList; import java.util.Iterator; @@ -96,11 +94,7 @@ public class CollectionsPage extends GuiProfileViewerPage { if (collectionInfo == null) { Utils.drawStringCentered( EnumChatFormatting.RED + "Collection API not enabled!", - Minecraft.getMinecraft().fontRendererObj, - guiLeft + 134, - guiTop + 101, - true, - 0 + guiLeft + 134, guiTop + 101, true, 0 ); return; } @@ -195,11 +189,7 @@ public class CollectionsPage extends GuiProfileViewerPage { Utils.drawStringCentered( selectedCollectionCategory.getDisplayName() + " Collections", - Minecraft.getMinecraft().fontRendererObj, - guiLeft + 134, - guiTop + 14, - true, - 4210752 + guiLeft + 134, guiTop + 14, true, 4210752 ); if (collections != null) { @@ -292,35 +282,16 @@ public class CollectionsPage extends GuiProfileViewerPage { GlStateManager.color(1, 1, 1, 1); if (tier >= 0) { - Utils.drawStringCentered( - tierString, - Minecraft.getMinecraft().fontRendererObj, - guiLeft + x + 10, - guiTop + y - 4, - true, - tierStringColour - ); + Utils.drawStringCentered(tierString, guiLeft + x + 10, guiTop + y - 4, true, tierStringColour); } Utils.drawStringCentered( - StringUtils.shortNumberFormat(amount) + "", - Minecraft.getMinecraft().fontRendererObj, - guiLeft + x + 10, - guiTop + y + 26, - true, - color.getRGB() - ); + StringUtils.shortNumberFormat(amount) + "", guiLeft + x + 10, guiTop + y + 26, true, color.getRGB()); } } Utils.drawStringCentered( - selectedCollectionCategory.getDisplayName() + " Minions", - Minecraft.getMinecraft().fontRendererObj, - guiLeft + 326, - guiTop + 14, - true, - 4210752 - ); + selectedCollectionCategory.getDisplayName() + " Minions", guiLeft + 326, guiTop + 14, true, 4210752); if (minions != null) { for (int i = page * 20, j = 0; i < Math.min((page + 1) * 20, minions.size()); i++, j++) { @@ -409,14 +380,7 @@ public class CollectionsPage extends GuiProfileViewerPage { GlStateManager.color(1, 1, 1, 1); if (tier >= 0) { - Utils.drawStringCentered( - tierString, - Minecraft.getMinecraft().fontRendererObj, - guiLeft + x + 10, - guiTop + y - 4, - true, - tierStringColour - ); + Utils.drawStringCentered(tierString, guiLeft + x + 10, guiTop + y - 4, true, tierStringColour); } } } @@ -426,15 +390,7 @@ public class CollectionsPage extends GuiProfileViewerPage { for (String line : tooltipToDisplay) { grayTooltip.add(EnumChatFormatting.GRAY + line); } - Utils.drawHoveringText( - grayTooltip, - mouseX, - mouseY, - getInstance().width, - getInstance().height, - -1, - Minecraft.getMinecraft().fontRendererObj - ); + Utils.drawHoveringText(grayTooltip, mouseX, mouseY, getInstance().width, getInstance().height, -1); tooltipToDisplay = null; } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/CrimsonIslePage.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/CrimsonIslePage.java index 6460003a..454ad989 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/CrimsonIslePage.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/CrimsonIslePage.java @@ -109,11 +109,7 @@ public class CrimsonIslePage extends GuiProfileViewerPage { if (profileInfo == null || !profileInfo.has("nether_island_player_data")) { Utils.drawStringCentered( EnumChatFormatting.RED + "No data found for the Crimson Isles", - Minecraft.getMinecraft().fontRendererObj, - guiLeft + 431 / 2f, - guiTop + 101, - true, - 0 + guiLeft + 431 / 2f, guiTop + 101, true, 0 ); return; } @@ -137,14 +133,7 @@ public class CrimsonIslePage extends GuiProfileViewerPage { } public void drawKuudraStats(JsonObject data, int guiLeft, int guiTop, int mouseX, int mouseY) { - Utils.drawStringCentered( - EnumChatFormatting.RED + "Kuudra Stats", - Minecraft.getMinecraft().fontRendererObj, - guiLeft + (431 * 0.18f), - guiTop + 14, - true, - 0 - ); + Utils.drawStringCentered(EnumChatFormatting.RED + "Kuudra Stats", guiLeft + (431 * 0.18f), guiTop + 14, true, 0); JsonObject kuudraCompletedTiers = data.getAsJsonObject("kuudra_completed_tiers"); @@ -213,14 +202,7 @@ public class CrimsonIslePage extends GuiProfileViewerPage { } public void drawDojoStats(JsonObject data, int guiLeft, int guiTop) { - Utils.drawStringCentered( - EnumChatFormatting.YELLOW + "Dojo Stats", - Minecraft.getMinecraft().fontRendererObj, - guiLeft + (431 * 0.49f), - guiTop + 14, - true, - 0 - ); + Utils.drawStringCentered(EnumChatFormatting.YELLOW + "Dojo Stats", guiLeft + (431 * 0.49f), guiTop + 14, true, 0); JsonObject dojoStats = data.getAsJsonObject("dojo"); int[] dojoScores = {0, 0, 0, 0, 0, 0, 0}; @@ -298,11 +280,7 @@ public class CrimsonIslePage extends GuiProfileViewerPage { public void drawLastMatriarchAttempt(JsonObject data, int guiLeft, int guiTop) { Utils.drawStringCentered( EnumChatFormatting.GOLD + "Last Matriarch Attempt", - Minecraft.getMinecraft().fontRendererObj, - guiLeft + (431 * 0.82f), - guiTop + 104, - true, - 0 + guiLeft + (431 * 0.82f), guiTop + 104, true, 0 ); JsonObject lastMatriarchAttempt = data.getAsJsonObject("matriarch"); @@ -351,11 +329,7 @@ public class CrimsonIslePage extends GuiProfileViewerPage { public void drawFactionReputation(JsonObject data, int guiLeft, int guiTop) { Utils.drawStringCentered( EnumChatFormatting.DARK_PURPLE + "Faction Reputation", - Minecraft.getMinecraft().fontRendererObj, - guiLeft + (431 * 0.82f), - guiTop + 14, - true, - 0 + guiLeft + (431 * 0.82f), guiTop + 14, true, 0 ); String selectedFaction = data.has("selected_faction") ? data.get("selected_faction").getAsString() : "N/A"; diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/GuiProfileViewer.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/GuiProfileViewer.java index c379c7eb..a5229acb 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/GuiProfileViewer.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/GuiProfileViewer.java @@ -329,7 +329,6 @@ public class GuiProfileViewer extends GuiScreen { Utils.drawTexturedRect(guiLeft, guiTop + sizeY + 3, 100, 20, 0, 100 / 200f, 0, 20 / 185f, GL11.GL_NEAREST); Utils.drawStringCenteredScaledMaxWidth( profileId, - Minecraft.getMinecraft().fontRendererObj, guiLeft + 50, guiTop + sizeY + 3 + 10, true, @@ -394,7 +393,6 @@ public class GuiProfileViewer extends GuiScreen { ); Utils.drawStringCenteredScaledMaxWidth( "Open in SkyCrypt", - Minecraft.getMinecraft().fontRendererObj, guiLeft + 50 + 100 + 6, guiTop + sizeY + 3 + 10, true, @@ -437,7 +435,6 @@ public class GuiProfileViewer extends GuiScreen { String otherProfileId = profile.getProfileNames().get(yIndex); Utils.drawStringCenteredScaledMaxWidth( otherProfileId, - Minecraft.getMinecraft().fontRendererObj, guiLeft + 50, guiTop + sizeY + 23 + dropdownOptionSize / 2f + dropdownOptionSize * yIndex, true, @@ -529,14 +526,7 @@ public class GuiProfileViewer extends GuiScreen { } } - Utils.drawStringCentered( - str, - Minecraft.getMinecraft().fontRendererObj, - guiLeft + sizeX / 2f, - guiTop + 101, - true, - 0 - ); + Utils.drawStringCentered(str, guiLeft + sizeX / 2f, guiTop + 101, true, 0); //This is just here to inform the player what to do //like typing /api new or telling them to go find a psychotherapist @@ -545,37 +535,21 @@ public class GuiProfileViewer extends GuiScreen { if (timeDiff > 20000) { Utils.drawStringCentered( EnumChatFormatting.YELLOW + "Its taking a while...", - Minecraft.getMinecraft().fontRendererObj, - guiLeft + sizeX / 2f, - guiTop + 111, - true, - 0 + guiLeft + sizeX / 2f, guiTop + 111, true, 0 ); Utils.drawStringCentered( EnumChatFormatting.YELLOW + "Try \"/api new\".", - Minecraft.getMinecraft().fontRendererObj, - guiLeft + sizeX / 2f, - guiTop + 121, - true, - 0 + guiLeft + sizeX / 2f, guiTop + 121, true, 0 ); if (timeDiff > 60000) { Utils.drawStringCentered( EnumChatFormatting.YELLOW + "Might be hypixel's fault.", - Minecraft.getMinecraft().fontRendererObj, - guiLeft + sizeX / 2f, - guiTop + 131, - true, - 0 + guiLeft + sizeX / 2f, guiTop + 131, true, 0 ); if (timeDiff > 180000) { Utils.drawStringCentered( EnumChatFormatting.YELLOW + "Wow you're still here?", - Minecraft.getMinecraft().fontRendererObj, - guiLeft + sizeX / 2f, - guiTop + 141, - true, - 0 + guiLeft + sizeX / 2f, guiTop + 141, true, 0 ); if (timeDiff > 360000) { long second = (timeDiff / 1000) % 60; @@ -585,58 +559,32 @@ public class GuiProfileViewer extends GuiScreen { String time = String.format("%02d:%02d:%02d", hour, minute, second); Utils.drawStringCentered( EnumChatFormatting.YELLOW + "You've wasted your time here for: " + time, - Minecraft.getMinecraft().fontRendererObj, - guiLeft + sizeX / 2f, - guiTop + 151, - true, - 0 + guiLeft + sizeX / 2f, guiTop + 151, true, 0 ); Utils.drawStringCentered( EnumChatFormatting.YELLOW + "" + EnumChatFormatting.BOLD + "What are you doing with your life?", - Minecraft.getMinecraft().fontRendererObj, - guiLeft + sizeX / 2f, - guiTop + 161, - true, - 0 + guiLeft + sizeX / 2f, guiTop + 161, true, 0 ); if (timeDiff > 600000) { Utils.drawStringCentered( EnumChatFormatting.RED + "" + EnumChatFormatting.BOLD + "Maniac", - Minecraft.getMinecraft().fontRendererObj, - guiLeft + sizeX / 2f, - guiTop + 171, - true, - 0 + guiLeft + sizeX / 2f, guiTop + 171, true, 0 ); if (timeDiff > 1200000) { Utils.drawStringCentered( EnumChatFormatting.RED + "" + EnumChatFormatting.BOLD + "You're a menace to society", - Minecraft.getMinecraft().fontRendererObj, - guiLeft + sizeX / 2f, - guiTop + 181, - true, - 0 + guiLeft + sizeX / 2f, guiTop + 181, true, 0 ); if (timeDiff > 1800000) { Utils.drawStringCentered( - EnumChatFormatting.RED + - "" + - EnumChatFormatting.BOLD + + EnumChatFormatting.RED + "" + EnumChatFormatting.BOLD + "You don't know what's gonna happen to you", - Minecraft.getMinecraft().fontRendererObj, - guiLeft + sizeX / 2f, - guiTop + 191, - true, - 0 + guiLeft + sizeX / 2f, guiTop + 191, true, 0 ); if (timeDiff > 3000000) { Utils.drawStringCentered( EnumChatFormatting.RED + "" + EnumChatFormatting.BOLD + "You really want this?", - Minecraft.getMinecraft().fontRendererObj, - guiLeft + sizeX / 2f, - guiTop + 91, - true, - 0 + guiLeft + sizeX / 2f, guiTop + 91, true, 0 ); if (timeDiff > 3300000) { Utils.drawStringCentered( @@ -644,11 +592,7 @@ public class GuiProfileViewer extends GuiScreen { "" + EnumChatFormatting.BOLD + "OW LORD FORGIVE ME FOR THIS", - Minecraft.getMinecraft().fontRendererObj, - guiLeft + sizeX / 2f, - guiTop + 71, - true, - 0 + guiLeft + sizeX / 2f, guiTop + 71, true, 0 ); if (timeDiff > 3600000) { throw new Error("Go do something productive") { @@ -672,21 +616,13 @@ public class GuiProfileViewer extends GuiScreen { case INVALID_NAME: Utils.drawStringCentered( EnumChatFormatting.RED + "Invalid name or API is down!", - Minecraft.getMinecraft().fontRendererObj, - guiLeft + sizeX / 2f, - guiTop + 101, - true, - 0 + guiLeft + sizeX / 2f, guiTop + 101, true, 0 ); break; case NO_SKYBLOCK: Utils.drawStringCentered( EnumChatFormatting.RED + "No SkyBlock data found!", - Minecraft.getMinecraft().fontRendererObj, - guiLeft + sizeX / 2f, - guiTop + 101, - true, - 0 + guiLeft + sizeX / 2f, guiTop + 101, true, 0 ); break; } @@ -727,7 +663,7 @@ public class GuiProfileViewer extends GuiScreen { for (String line : tooltipToDisplay) { grayTooltip.add(EnumChatFormatting.GRAY + line); } - Utils.drawHoveringText(grayTooltip, mouseX, mouseY, width, height, -1, Minecraft.getMinecraft().fontRendererObj); + Utils.drawHoveringText(grayTooltip, mouseX, mouseY, width, height, -1); tooltipToDisplay = null; } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/InventoriesPage.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/InventoriesPage.java index 164f5d78..29f84a5b 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/InventoriesPage.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/InventoriesPage.java @@ -350,21 +350,10 @@ public class InventoriesPage extends GuiProfileViewerPage { strToRender = "Inventory API not enabled"; Utils.drawStringCentered( EnumChatFormatting.RED + "Or has no backpacks!", - Minecraft.getMinecraft().fontRendererObj, - guiLeft + 317, - guiTop + 112, - true, - 0 + guiLeft + 317, guiTop + 112, true, 0 ); } - Utils.drawStringCentered( - EnumChatFormatting.RED + strToRender, - Minecraft.getMinecraft().fontRendererObj, - guiLeft + 317, - guiTop + 101, - true, - 0 - ); + Utils.drawStringCentered(EnumChatFormatting.RED + strToRender, guiLeft + 317, guiTop + 101, true, 0); return; } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/MiningPage.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/MiningPage.java index c8ec09d3..a9dade6a 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/MiningPage.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/MiningPage.java @@ -1453,15 +1453,7 @@ public class MiningPage extends GuiProfileViewerPage { GlStateManager.enableLighting(); if (mouseX >= xPosition && mouseX < xPosition + 16) { if (mouseY >= yPosition && mouseY <= yPosition + 16) { - Utils.drawHoveringText( - tooltip, - mouseX, - mouseY, - getInstance().width, - getInstance().height, - -1, - Minecraft.getMinecraft().fontRendererObj - ); + Utils.drawHoveringText(tooltip, mouseX, mouseY, getInstance().width, getInstance().height, -1); } } } @@ -1519,15 +1511,7 @@ public class MiningPage extends GuiProfileViewerPage { GlStateManager.enableLighting(); if (mouseX >= xPosition && mouseX < xPosition + 16) { if (mouseY >= yPosition && mouseY <= yPosition + 16) { - Utils.drawHoveringText( - tooltip, - mouseX, - mouseY, - getInstance().width, - getInstance().height, - -1, - Minecraft.getMinecraft().fontRendererObj - ); + Utils.drawHoveringText(tooltip, mouseX,mouseY, getInstance().width, getInstance().height, -1); } } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/PetsPage.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/PetsPage.java index 098c252e..a56662e7 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/PetsPage.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/PetsPage.java @@ -148,14 +148,7 @@ public class PetsPage extends GuiProfileViewerPage { Minecraft.getMinecraft().getTextureManager().bindTexture(pv_pets); Utils.drawTexturedRect(guiLeft, guiTop, getInstance().sizeX, getInstance().sizeY, GL11.GL_NEAREST); - Utils.drawStringCentered( - EnumChatFormatting.DARK_PURPLE + "Pets", - Minecraft.getMinecraft().fontRendererObj, - guiLeft + 100, - guiTop + 14, - true, - 4210752 - ); + Utils.drawStringCentered(EnumChatFormatting.DARK_PURPLE + "Pets", guiLeft + 100, guiTop + 14, true, 4210752); GlStateManager.color(1, 1, 1, 1); JsonElement activePetElement = petsInfo.get("active_pet"); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/bestiary/BestiaryPage.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/bestiary/BestiaryPage.java index 7da6c627..81b99948 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/bestiary/BestiaryPage.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/bestiary/BestiaryPage.java @@ -219,18 +219,14 @@ public class BestiaryPage extends GuiProfileViewerPage { GlStateManager.color(1, 1, 1, 1); // if (tier >= 0) { - // Utils.drawStringCentered(tierString, Minecraft.getMinecraft().fontRendererObj, + // Utils.drawStringCentered(tierString, // guiLeft + x + 10, guiTop + y - 4, true, // tierStringColour // ); // } Utils.drawStringCentered( (int) Math.floor(levelNum) + "", - Minecraft.getMinecraft().fontRendererObj, - guiLeft + x + 10, - guiTop + y + 26, - true, - color.getRGB() + guiLeft + x + 10, guiTop + y + 26, true, color.getRGB() ); } } @@ -241,7 +237,7 @@ public class BestiaryPage extends GuiProfileViewerPage { for (String line : tooltipToDisplay) { grayTooltip.add(EnumChatFormatting.GRAY + line); } - Utils.drawHoveringText(grayTooltip, mouseX, mouseY, width, height, -1, Minecraft.getMinecraft().fontRendererObj); + Utils.drawHoveringText(grayTooltip, mouseX, mouseY, width, height, -1); tooltipToDisplay = null; } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/trophy/TrophyFishPage.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/trophy/TrophyFishPage.java index 1db53267..d6746e1d 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/trophy/TrophyFishPage.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/trophy/TrophyFishPage.java @@ -142,14 +142,7 @@ public class TrophyFishPage extends GuiProfileViewerPage { JsonObject profileInformation = GuiProfileViewer.getProfile().getProfileInformation(GuiProfileViewer.getProfileId()); if (profileInformation == null || !profileInformation.has("trophy_fish")) { - Utils.drawStringCentered( - EnumChatFormatting.RED + "No data found", - Minecraft.getMinecraft().fontRendererObj, - guiLeft + 431 / 2f, - guiTop + 101, - true, - 0 - ); + Utils.drawStringCentered(EnumChatFormatting.RED + "No data found", guiLeft + 431 / 2f, guiTop + 101, true, 0); return; } JsonObject trophyObject = profileInformation.get("trophy_fish").getAsJsonObject(); @@ -180,11 +173,7 @@ public class TrophyFishPage extends GuiProfileViewerPage { Utils.drawStringF( EnumChatFormatting.AQUA + "Thunder Kills: §f" + thunderKills, - Minecraft.getMinecraft().fontRendererObj, - guiLeft + 36, - guiTop + 112, - true, - 0 + guiLeft + 36, guiTop + 112, true, 0 ); ItemStack lord_jawbus_sc = NotEnoughUpdates.INSTANCE.manager.jsonToStack( @@ -198,11 +187,7 @@ public class TrophyFishPage extends GuiProfileViewerPage { Utils.drawStringF( EnumChatFormatting.AQUA + "Lord Jawbus Kills: §f" + jawbusKills, - Minecraft.getMinecraft().fontRendererObj, - guiLeft + 36, - guiTop + 124, - true, - 0 + guiLeft + 36, guiTop + 124, true, 0 ); ItemStack fishing_rod = NotEnoughUpdates.INSTANCE.manager.jsonToStack( @@ -210,14 +195,7 @@ public class TrophyFishPage extends GuiProfileViewerPage { ); Minecraft.getMinecraft().getRenderItem().renderItemIntoGUI(fishing_rod, guiLeft + 20, guiTop + 21); - Utils.drawStringF( - EnumChatFormatting.AQUA + "Total Caught: §f" + totalCount, - Minecraft.getMinecraft().fontRendererObj, - guiLeft + 38, - guiTop + 25, - true, - 0 - ); + Utils.drawStringF(EnumChatFormatting.AQUA + "Total Caught: §f" + totalCount, guiLeft + 38, guiTop + 25, true, 0); ArrayList arrayList = new ArrayList<>(trophyFishList.values()); arrayList.sort((c1, c2) -> Integer.compare(c2.getTotal(), c1.getTotal())); @@ -250,12 +228,7 @@ public class TrophyFishPage extends GuiProfileViewerPage { if (mouseY >= y && mouseY <= y + 24) { Utils.drawHoveringText( getTooltip(value.getName(), value.getTrophyFishRarityIntegerMap()), - mouseX, - mouseY, - width, - height, - -1, - Minecraft.getMinecraft().fontRendererObj + mouseX, mouseY, width, height, -1 ); } } @@ -273,15 +246,7 @@ public class TrophyFishPage extends GuiProfileViewerPage { Minecraft.getMinecraft().getRenderItem().renderItemIntoGUI(itemStack, x, y); if (mouseX >= x && mouseX < x + 24) { if (mouseY >= y && mouseY <= y + 24) { - Utils.drawHoveringText( - getTooltip(difference, null), - mouseX, - mouseY, - width, - height, - -1, - Minecraft.getMinecraft().fontRendererObj - ); + Utils.drawHoveringText(getTooltip(difference, null), mouseX, mouseY, width, height, -1); GlStateManager.color(1, 1, 1, 1); } } @@ -302,7 +267,7 @@ public class TrophyFishPage extends GuiProfileViewerPage { y = guiTop + 50 + i; Minecraft.getMinecraft().getRenderItem().renderItemIntoGUI(itemStack, x, y); - Utils.drawStringF(armorHelmets.get(itemStack).getLeft(), Minecraft.getMinecraft().fontRendererObj, x + 20, y + 4, true, 0); + Utils.drawStringF(armorHelmets.get(itemStack).getLeft(), x + 20, y + 4, true, 0); int hasValue = trophiesPerTier[integer - 1]; int neededValue = integer == 1 ? 15 : 18; @@ -311,12 +276,12 @@ public class TrophyFishPage extends GuiProfileViewerPage { try { JsonElement jsonElement = rewards.get(integer - 1); if (!jsonElement.isJsonNull()) { - Utils.drawStringF(check, Minecraft.getMinecraft().fontRendererObj, x + 100, y + 2, true, 0); + Utils.drawStringF(check, x + 100, y + 2, true, 0); } else { - Utils.drawStringF(neededText, Minecraft.getMinecraft().fontRendererObj, x + 100, y + 4, true, 0); + Utils.drawStringF(neededText, x + 100, y + 4, true, 0); } } catch (IndexOutOfBoundsException exception) { - Utils.drawStringF(neededText, Minecraft.getMinecraft().fontRendererObj, x + 100, y + 4, true, 0); + Utils.drawStringF(neededText, x + 100, y + 4, true, 0); } i += 10; } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/recipes/CraftingOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/recipes/CraftingOverlay.java index bd45f3e1..4be3b051 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/recipes/CraftingOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/recipes/CraftingOverlay.java @@ -141,8 +141,7 @@ public class CraftingOverlay { Utils.drawHoveringText( recipeIngredient.getItemStack().getTooltip(Minecraft.getMinecraft().thePlayer, false), mouseX, mouseY, - Utils.peekGuiScale().getScaledWidth(), Utils.peekGuiScale().getScaledHeight(), -1, - Minecraft.getMinecraft().fontRendererObj + Utils.peekGuiScale().getScaledWidth(), Utils.peekGuiScale().getScaledHeight(), -1 ); } }); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/recipes/CraftingRecipe.java b/src/main/java/io/github/moulberry/notenoughupdates/recipes/CraftingRecipe.java index a642187b..8e4623e3 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/recipes/CraftingRecipe.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/recipes/CraftingRecipe.java @@ -24,8 +24,6 @@ import com.google.gson.JsonObject; import io.github.moulberry.notenoughupdates.NEUManager; import io.github.moulberry.notenoughupdates.miscgui.GuiItemRecipe; import io.github.moulberry.notenoughupdates.util.Utils; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.FontRenderer; import net.minecraft.item.ItemStack; import net.minecraft.util.ResourceLocation; @@ -115,11 +113,9 @@ public class CraftingRecipe implements NeuRecipe { @Override public void drawExtraInfo(GuiItemRecipe gui, int mouseX, int mouseY) { - FontRenderer fontRenderer = Minecraft.getMinecraft().fontRendererObj; - String craftingText = getCraftText(); if (craftingText != null) - Utils.drawStringCenteredScaledMaxWidth(craftingText, fontRenderer, + Utils.drawStringCenteredScaledMaxWidth(craftingText, gui.guiLeft + EXTRA_STRING_X, gui.guiTop + EXTRA_STRING_Y, false, 75, 0x404040 ); } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/recipes/EssenceUpgrades.java b/src/main/java/io/github/moulberry/notenoughupdates/recipes/EssenceUpgrades.java index 439ac56b..15b3c832 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/recipes/EssenceUpgrades.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/recipes/EssenceUpgrades.java @@ -350,14 +350,7 @@ public class EssenceUpgrades implements NeuRecipe { Minecraft.getMinecraft().getTextureManager().bindTexture(BACKGROUND); GlStateManager.color(1, 1, 1, 1); drawButton(x, y, i + 1 == selectedTier); - Utils.drawStringCentered( - String.valueOf(i + 1), - Minecraft.getMinecraft().fontRendererObj, - x + 8, - y + 9, - false, - 0x2d4ffc - ); + Utils.drawStringCentered(String.valueOf(i + 1), x + 8, y + 9, false, 0x2d4ffc); } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/recipes/ForgeRecipe.java b/src/main/java/io/github/moulberry/notenoughupdates/recipes/ForgeRecipe.java index 73b4f32d..ff6a175d 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/recipes/ForgeRecipe.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/recipes/ForgeRecipe.java @@ -31,7 +31,6 @@ import io.github.moulberry.notenoughupdates.options.NEUConfig; import io.github.moulberry.notenoughupdates.util.HotmInformation; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.FontRenderer; import net.minecraft.item.ItemStack; import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.ResourceLocation; @@ -148,11 +147,9 @@ public class ForgeRecipe implements NeuRecipe { @Override public void drawExtraInfo(GuiItemRecipe gui, int mouseX, int mouseY) { - FontRenderer fontRenderer = Minecraft.getMinecraft().fontRendererObj; if (timeInSeconds > 0) Utils.drawStringCenteredScaledMaxWidth( formatDuration(timeInSeconds), - fontRenderer, gui.guiLeft + EXTRA_INFO_X, gui.guiTop + EXTRA_INFO_Y, false, @@ -180,11 +177,7 @@ public class ForgeRecipe implements NeuRecipe { Utils.drawHoveringText( Collections.singletonList( EnumChatFormatting.YELLOW + formatDuration(reducedTime) + " with Quick Forge (Level " + level + ")"), - mouseX, mouseY, - gui.width, gui.height, - 500, - Minecraft.getMinecraft().fontRendererObj - ); + mouseX, mouseY, gui.width, gui.height, 500); } public int getReducedTime(int quickForgeUpgradeLevel) { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/recipes/MobLootRecipe.java b/src/main/java/io/github/moulberry/notenoughupdates/recipes/MobLootRecipe.java index 61749593..0e580cb8 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/recipes/MobLootRecipe.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/recipes/MobLootRecipe.java @@ -31,7 +31,6 @@ import io.github.moulberry.notenoughupdates.profileviewer.Panorama; import io.github.moulberry.notenoughupdates.util.ItemUtils; import io.github.moulberry.notenoughupdates.util.JsonUtils; import io.github.moulberry.notenoughupdates.util.Utils; -import net.minecraft.client.Minecraft; import net.minecraft.entity.EntityLivingBase; import net.minecraft.item.ItemStack; import net.minecraft.util.ResourceLocation; @@ -276,15 +275,7 @@ public class MobLootRecipe implements NeuRecipe { if (combatXp > 0) stuff.add("§r§bCombat Experience: " + combatXp); stuff.addAll(extra); - Utils.drawHoveringText( - stuff, - mouseX, - mouseY, - gui.width, - gui.height, - -1, - Minecraft.getMinecraft().fontRendererObj - ); + Utils.drawHoveringText(stuff, mouseX, mouseY, gui.width, gui.height, -1); } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/recipes/VillagerTradeRecipe.java b/src/main/java/io/github/moulberry/notenoughupdates/recipes/VillagerTradeRecipe.java index 9bb79604..4938c383 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/recipes/VillagerTradeRecipe.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/recipes/VillagerTradeRecipe.java @@ -27,9 +27,7 @@ import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.miscgui.GuiItemRecipe; import io.github.moulberry.notenoughupdates.util.SBInfo; import io.github.moulberry.notenoughupdates.util.Utils; -import net.minecraft.client.Minecraft; import net.minecraft.client.entity.AbstractClientPlayer; -import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.inventory.GuiInventory; import net.minecraft.client.network.NetworkPlayerInfo; import net.minecraft.entity.EntityLivingBase; @@ -135,10 +133,8 @@ public class VillagerTradeRecipe implements NeuRecipe { @Override public void drawExtraInfo(GuiItemRecipe gui, int mouseX, int mouseY) { if (hasVariableCost()) { - FontRenderer fontRenderer = Minecraft.getMinecraft().fontRendererObj; Utils.drawStringCenteredScaledMaxWidth( - minCost + " - " + maxCost, fontRenderer, - gui.guiLeft + 50, gui.guiTop + 90, false, 75, 0xff00ff + minCost + " - " + maxCost, gui.guiLeft + 50, gui.guiTop + 90, false, 75, 0xff00ff ); } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/NotificationHandler.java b/src/main/java/io/github/moulberry/notenoughupdates/util/NotificationHandler.java index d373ef2c..99a39d0a 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/util/NotificationHandler.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/util/NotificationHandler.java @@ -83,10 +83,7 @@ public class NotificationHandler { int xLen = Minecraft.getMinecraft().fontRendererObj.getStringWidth("[X] Close"); Minecraft.getMinecraft().fontRendererObj.drawString( "[X] Close", - midX + width / 2f - 3 - xLen, - topY + 3, - 0xFFFF5555, - false + midX + width / 2f - 3 - xLen, topY + 3, 0xFFFF5555, false ); if (notificationDisplayMillis > 0) { @@ -99,24 +96,10 @@ public class NotificationHandler { ); } - Utils.drawStringCentered( - notificationLines.get(0), - Minecraft.getMinecraft().fontRendererObj, - midX, - topY + 4 + 5, - false, - -1 - ); + Utils.drawStringCentered(notificationLines.get(0), midX, topY + 4 + 5, false, -1); for (int i = 1; i < notificationLines.size(); i++) { String line = notificationLines.get(i); - Utils.drawStringCentered( - line, - Minecraft.getMinecraft().fontRendererObj, - midX, - topY + 4 + 5 + 2 + i * 10, - false, - -1 - ); + Utils.drawStringCentered(line, midX, topY + 4 + 5 + 2 + i * 10, false, -1); } Utils.pushGuiScale(-1); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java b/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java index 38debbbc..49caa2b6 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java @@ -293,9 +293,9 @@ public class Utils { while (matcher.find()) { matcher.appendReplacement( sb, - Utils.chromaString(matcher.group(1)) - .replace("\\", "\\\\") - .replace("$", "\\$") + chromaString(matcher.group(1)) + .replace("\\", "\\\\") + .replace("$", "\\$") ); } matcher.appendTail(sb); @@ -628,10 +628,10 @@ public class Utils { Minecraft.getMinecraft().getTextureManager().bindTexture(GuiProfileViewer.pv_elements); - Utils.drawTexturedRect(x, y, pressed ? 32 : 28, 28, uMin, uMax, vMin, vMax, GL11.GL_NEAREST); + drawTexturedRect(x, y, pressed ? 32 : 28, 28, uMin, uMax, vMin, vMax, GL11.GL_NEAREST); GlStateManager.enableDepth(); - Utils.drawItemStack(itemStack, x + 8, y + 7); + drawItemStack(itemStack, x + 8, y + 7); } public static void drawTexturedRect(float x, float y, float width, float height, int filter) { @@ -676,7 +676,7 @@ public class Utils { public static int checkItemTypePet(List lore) { for (int i = lore.size() - 1; i >= 0; i--) { - String line = Utils.cleanColour(lore.get(i)); + String line = cleanColour(lore.get(i)); for (int i1 = 0; i1 < rarityArr.length; i1++) { if (line.equals(rarityArr[i1])) { return i1; @@ -1016,6 +1016,11 @@ public class Utils { return render; } + public static void drawStringF(String str, float x, float y, boolean shadow, int colour) { + drawStringF(str, Minecraft.getMinecraft().fontRendererObj, x, y, shadow, colour); + } + + @Deprecated public static void drawStringF(String str, FontRenderer fr, float x, float y, boolean shadow, int colour) { fr.drawString(str, x, y, colour, shadow); } @@ -1039,6 +1044,11 @@ public class Utils { return height; } + public static void drawStringVertical(String str, float x, float y, boolean shadow, int colour) { + drawStringVertical(str, Minecraft.getMinecraft().fontRendererObj, x, y, shadow, colour); + } + + @Deprecated public static void drawStringVertical(String str, FontRenderer fr, float x, float y, boolean shadow, int colour) { String format = FontRenderer.getFormatFromString(str); str = cleanColour(str); @@ -1066,9 +1076,8 @@ public class Utils { for (int xOff = -2; xOff <= 2; xOff++) { for (int yOff = -2; yOff <= 2; yOff++) { if (Math.abs(xOff) != Math.abs(yOff)) { - Utils.drawStringCenteredScaledMaxWidth( - Utils.cleanColourNotModifiers(str), - Minecraft.getMinecraft().fontRendererObj, + drawStringCenteredScaledMaxWidth( + cleanColourNotModifiers(str), x + xOff / 2f * factor, y + 4 + yOff / 2f * factor, false, @@ -1080,9 +1089,7 @@ public class Utils { } GlStateManager.color(1, 1, 1, 1); - Utils.drawStringCenteredScaledMaxWidth(str, Minecraft.getMinecraft().fontRendererObj, - x, y + 4, false, maxLength, 4210752 - ); + drawStringCenteredScaledMaxWidth(str, x, y + 4, false, maxLength, 421075); } public static void renderAlignedString(String first, String second, float x, float y, int length) { @@ -1093,7 +1100,7 @@ public class Utils { for (int xOff = -2; xOff <= 2; xOff++) { for (int yOff = -2; yOff <= 2; yOff++) { if (Math.abs(xOff) != Math.abs(yOff)) { - fontRendererObj.drawString(Utils.cleanColourNotModifiers(first), + fontRendererObj.drawString(cleanColourNotModifiers(first), x + xOff / 2f, y + yOff / 2f, new Color(0, 0, 0, 200 / Math.max(Math.abs(xOff), Math.abs(yOff))).getRGB(), false ); @@ -1107,7 +1114,7 @@ public class Utils { for (int xOff = -2; xOff <= 2; xOff++) { for (int yOff = -2; yOff <= 2; yOff++) { if (Math.abs(xOff) != Math.abs(yOff)) { - fontRendererObj.drawString(Utils.cleanColourNotModifiers(second), + fontRendererObj.drawString(cleanColourNotModifiers(second), x + length - secondLen + xOff / 2f, y + yOff / 2f, new Color(0, 0, 0, 200 / Math.max(Math.abs(xOff), Math.abs(yOff))).getRGB(), false ); @@ -1120,6 +1127,18 @@ public class Utils { } } + public static void drawStringScaledMaxWidth( + String str, + float x, + float y, + boolean shadow, + int len, + int colour + ) { + drawStringScaledMaxWidth(str, Minecraft.getMinecraft().fontRendererObj, x, y, shadow, len, colour); + } + + @Deprecated public static void drawStringScaledMaxWidth( String str, FontRenderer fr, @@ -1133,9 +1152,14 @@ public class Utils { float factor = len / (float) strLen; factor = Math.min(1, factor); - drawStringScaled(str, fr, x, y, shadow, colour, factor); + drawStringScaled(str, x, y, shadow, colour, factor); + } + + public static void drawStringCentered(String str, float x, float y, boolean shadow, int colour) { + drawStringCentered(str, Minecraft.getMinecraft().fontRendererObj, x, y, shadow, colour); } + @Deprecated public static void drawStringCentered(String str, FontRenderer fr, float x, float y, boolean shadow, int colour) { int strLen = fr.getStringWidth(str); @@ -1147,6 +1171,18 @@ public class Utils { GL11.glTranslatef(-x2, -y2, 0); } + public static void drawStringScaled( + String str, + float x, + float y, + boolean shadow, + int colour, + float factor + ) { + drawStringScaled(str, Minecraft.getMinecraft().fontRendererObj, x, y, shadow, colour, factor); + } + + @Deprecated public static void drawStringScaled( String str, FontRenderer fr, @@ -1170,9 +1206,22 @@ public class Utils { int colour, float factor ) { - drawStringScaled(str, fr, x - fr.getStringWidth(str) * factor, y, shadow, colour, factor); + drawStringScaled(str, x - fr.getStringWidth(str) * factor, y, shadow, colour, factor); } + public static void drawStringScaledMax( + String str, + float x, + float y, + boolean shadow, + int colour, + float factor, + int len + ) { + drawStringScaledMax(str, Minecraft.getMinecraft().fontRendererObj, x, y, shadow, colour, factor, len); + } + + @Deprecated public static void drawStringScaledMax( String str, FontRenderer fr, @@ -1192,6 +1241,18 @@ public class Utils { GlStateManager.scale(1 / factor, 1 / factor, 1); } + public static void drawStringCenteredScaledMaxWidth( + String str, + float x, + float y, + boolean shadow, + int len, + int colour + ) { + drawStringCenteredScaledMaxWidth(str, Minecraft.getMinecraft().fontRendererObj, x, y, shadow, len, colour); + } + + @Deprecated public static void drawStringCenteredScaledMaxWidth( String str, FontRenderer fr, @@ -1208,7 +1269,7 @@ public class Utils { float fontHeight = 8 * factor; - drawStringScaled(str, fr, x - newLen / 2, y - fontHeight / 2, shadow, colour, factor); + drawStringScaled(str, x - newLen / 2, y - fontHeight / 2, shadow, colour, factor); } public static Matrix4f createProjectionMatrix(int width, int height) { @@ -1226,20 +1287,34 @@ public class Utils { public static void drawStringCenteredScaled( String str, - FontRenderer fr, - float x, - float y, + float x, float y, boolean shadow, int len, int colour ) { - int strLen = fr.getStringWidth(str); + int strLen = Minecraft.getMinecraft().fontRendererObj.getStringWidth(str); float factor = len / (float) strLen; float fontHeight = 8 * factor; - drawStringScaled(str, fr, x - len / 2, y - fontHeight / 2, shadow, colour, factor); + drawStringScaled( + str, + x - len / 2, y - fontHeight / 2, + shadow, + colour, + factor + ); } + public static void drawStringCenteredScaled( + String str, + float x, float y, + boolean shadow, + float factor + ) { + drawStringCenteredScaled(str, Minecraft.getMinecraft().fontRendererObj, x, y, shadow, factor); + } + + @Deprecated public static void drawStringCenteredScaled( String str, FontRenderer fr, @@ -1253,7 +1328,7 @@ public class Utils { float x2 = x - strLen / 2f; float y2 = y - fr.FONT_HEIGHT / 2f; - drawStringScaled(str, fr, x2, y2, shadow, 0, factor); + drawStringScaled(str, x2, y2, shadow, 0, factor); } public static void drawStringCenteredYScaled( @@ -1269,7 +1344,7 @@ public class Utils { float factor = len / (float) strLen; float fontHeight = 8 * factor; - drawStringScaled(str, fr, x, y - fontHeight / 2, shadow, colour, factor); + drawStringScaled(str, x, y - fontHeight / 2, shadow, colour, factor); } public static void drawStringCenteredYScaledMaxWidth( @@ -1286,12 +1361,11 @@ public class Utils { factor = Math.min(1, factor); float fontHeight = 8 * factor; - drawStringScaled(str, fr, x, y - fontHeight / 2, shadow, colour, factor); + drawStringScaled(str, x, y - fontHeight / 2, shadow, colour, factor); } public static int renderStringTrimWidth( String str, - FontRenderer fr, boolean shadow, int x, int y, @@ -1299,12 +1373,11 @@ public class Utils { int colour, int maxLines ) { - return renderStringTrimWidth(str, fr, shadow, x, y, len, colour, maxLines, 1); + return renderStringTrimWidth(str, shadow, x, y, len, colour, maxLines, 1); } public static int renderStringTrimWidth( String str, - FontRenderer fr, boolean shadow, int x, int y, @@ -1331,20 +1404,20 @@ public class Utils { int lines = 0; while ((lines++ < maxLines) || maxLines < 0) { if (trimmed.length() == str.length()) { - drawStringScaled(trimmed, fr, x, y + yOff, shadow, colour, scale); + drawStringScaled(trimmed, x, y + yOff, shadow, colour, scale); break; } else if (trimmed.isEmpty()) { yOff -= 12 * scale; break; } else { if (firstLine) { - drawStringScaled(trimmed, fr, x, y + yOff, shadow, colour, scale); + drawStringScaled(trimmed, x, y + yOff, shadow, colour, scale); firstLine = false; } else { if (trimmed.startsWith(" ")) { trimmed = trimmed.substring(1); } - drawStringScaled(colourCodes + trimmed, fr, x, y + yOff, shadow, colour, scale); + drawStringScaled(colourCodes + trimmed, x, y + yOff, shadow, colour, scale); } excess = str.substring(trimmedCharacters); @@ -1430,6 +1503,26 @@ public class Utils { GlStateManager.enableTexture2D(); } + public static void drawHoveringText( + List textLines, + final int mouseX, + final int mouseY, + final int screenWidth, + final int screenHeight, + final int maxTextWidth + ) { + drawHoveringText( + textLines, + mouseX, + mouseY, + screenWidth, + screenHeight, + maxTextWidth, + Minecraft.getMinecraft().fontRendererObj + ); + } + + @Deprecated public static void drawHoveringText( List textLines, final int mouseX, @@ -1575,6 +1668,28 @@ public class Utils { scrollY.resetTimer(); } + public static void drawHoveringText( + List textLines, + final int mouseX, + final int mouseY, + final int screenWidth, + final int screenHeight, + final int maxTextWidth, + boolean coloured + ) { + drawHoveringText( + textLines, + mouseX, + mouseY, + screenWidth, + screenHeight, + maxTextWidth, + Minecraft.getMinecraft().fontRendererObj, + coloured + ); + } + + @Deprecated public static void drawHoveringText( List textLines, final int mouseX, @@ -2144,7 +2259,7 @@ public class Utils { runtime.exec("xdg-open " + url); return true; } catch (IOException e) { - Utils.playSound(new ResourceLocation("game.player.hurt"), true); + playSound(new ResourceLocation("game.player.hurt"), true); return false; } } diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/recipes/KatRecipe.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/recipes/KatRecipe.kt index e6dc0abc..acb379de 100644 --- a/src/main/kotlin/io/github/moulberry/notenoughupdates/recipes/KatRecipe.kt +++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/recipes/KatRecipe.kt @@ -98,7 +98,6 @@ data class KatRecipe( ) Utils.drawStringCentered( Utils.prettyTime(time), - Minecraft.getMinecraft().fontRendererObj, gui.guiLeft + textPosition.first.toFloat(), gui.guiTop + textPosition.second.toFloat(), false, 0xff00ff ) -- cgit From 1869ce4d63f4ef9b16bc3140f4bb5a53d8bfe646 Mon Sep 17 00:00:00 2001 From: Roman / Linnea Gräf Date: Sun, 5 Mar 2023 21:20:52 +0100 Subject: Fix /neudevtest useragent command (#648) --- .../github/moulberry/notenoughupdates/commands/dev/DevTestCommand.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/main/kotlin') diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.kt index 805ff114..a5ff48d2 100644 --- a/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.kt +++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.kt @@ -171,7 +171,7 @@ class DevTestCommand { } thenLiteralExecute("dev") { NotEnoughUpdates.INSTANCE.config.hidden.dev = !NotEnoughUpdates.INSTANCE.config.hidden.dev - reply("§e[NEU] Dev mode " + if (NotEnoughUpdates.INSTANCE.config.hidden.dev) "§aenabled" else "§cdisabled") + reply("Dev mode " + if (NotEnoughUpdates.INSTANCE.config.hidden.dev) "§aenabled" else "§cdisabled") }.withHelp("Toggle developer mode") thenLiteralExecute("saveconfig") { NotEnoughUpdates.INSTANCE.saveConfig() @@ -212,7 +212,7 @@ class DevTestCommand { MiscUtils.copyToClipboard(tabList) reply("Copied tablist to clipboard!") }.withHelp("Copy the tab list") - thenLiteralExecute("useragent") { + thenLiteral("useragent") { thenArgumentExecute("newuseragent", RestArgumentType) { userAgent -> reply("Setting your user agent to ${this[userAgent]}") NotEnoughUpdates.INSTANCE.config.hidden.customUserAgent = this[userAgent] -- cgit From 5f147d6adbe9898239a0cb86e4daaa74c9e4c08a Mon Sep 17 00:00:00 2001 From: Vixid <52578495+VixidDev@users.noreply.github.com> Date: Sat, 11 Mar 2023 23:51:41 +0000 Subject: Dynamic Light Items (#646) Co-authored-by: Vixid <52578495+Vixid1@users.noreply.github.com> --- .../envcheck/NEUMixinConfigPlugin.java | 4 + .../mixins/MixinOFDynamicLights.java | 40 ++++ .../notenoughupdates/options/NEUConfig.java | 4 + .../notenoughupdates/commands/misc/MiscCommands.kt | 6 + .../miscgui/DynamicLightItemsEditor.kt | 255 +++++++++++++++++++++ .../assets/notenoughupdates/disabled_button.png | Bin 0 -> 161 bytes .../dynamic_light_items_editor.png | Bin 0 -> 439 bytes .../assets/notenoughupdates/enabled_button.png | Bin 0 -> 158 bytes src/main/resources/mixins.notenoughupdates.json | 1 + 9 files changed, 310 insertions(+) create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinOFDynamicLights.java create mode 100644 src/main/kotlin/io/github/moulberry/notenoughupdates/miscgui/DynamicLightItemsEditor.kt create mode 100644 src/main/resources/assets/notenoughupdates/disabled_button.png create mode 100644 src/main/resources/assets/notenoughupdates/dynamic_light_items_editor.png create mode 100644 src/main/resources/assets/notenoughupdates/enabled_button.png (limited to 'src/main/kotlin') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/envcheck/NEUMixinConfigPlugin.java b/src/main/java/io/github/moulberry/notenoughupdates/envcheck/NEUMixinConfigPlugin.java index 44e24ff4..1d12813c 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/envcheck/NEUMixinConfigPlugin.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/envcheck/NEUMixinConfigPlugin.java @@ -1,5 +1,6 @@ package io.github.moulberry.notenoughupdates.envcheck; +import io.github.moulberry.notenoughupdates.miscgui.DynamicLightItemsEditor; import org.spongepowered.asm.lib.tree.ClassNode; import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; import org.spongepowered.asm.mixin.extensibility.IMixinInfo; @@ -42,5 +43,8 @@ public class NEUMixinConfigPlugin implements IMixinConfigPlugin { @Override public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { + if ("io.github.moulberry.notenoughupdates.mixins.MixinOFDynamicLights".equals(mixinClassName)) { + DynamicLightItemsEditor.setDidApplyMixin(true); + } } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinOFDynamicLights.java b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinOFDynamicLights.java new file mode 100644 index 00000000..68f75d49 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinOFDynamicLights.java @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2023 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see . + */ + +package io.github.moulberry.notenoughupdates.mixins; + +import io.github.moulberry.notenoughupdates.miscgui.DynamicLightItemsEditor; +import net.minecraft.item.ItemStack; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Pseudo; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Pseudo +@Mixin(targets = "net.optifine.DynamicLights", remap = false) +public class MixinOFDynamicLights { + + @Inject(method = "getLightLevel(Lnet/minecraft/item/ItemStack;)I", at = @At("TAIL"), cancellable = true) + private static void getLightLevel(ItemStack itemStack, CallbackInfoReturnable cir) { + int lightLevel = DynamicLightItemsEditor.findDynamicLightItems(itemStack); + if (lightLevel != 0) cir.setReturnValue(lightLevel); + } + +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java b/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java index e2a483f7..498b3b0d 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java @@ -82,9 +82,11 @@ import net.minecraftforge.client.ClientCommandHandler; import java.util.ArrayList; import java.util.EnumSet; import java.util.HashMap; +import java.util.HashSet; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Set; public class NEUConfig extends Config { public void editOverlay() { @@ -471,6 +473,8 @@ public class NEUConfig extends Config { public ArrayList quickCommands = createDefaultQuickCommands(); @Expose public ArrayList enchantColours = createDefaultEnchantColours(); + @Expose + public Set dynamicLightItems = new HashSet<>(); @Expose public boolean firstTimeSearchFocus = true; diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/misc/MiscCommands.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/misc/MiscCommands.kt index c86eb4fe..caa57909 100644 --- a/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/misc/MiscCommands.kt +++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/misc/MiscCommands.kt @@ -26,6 +26,7 @@ import io.github.moulberry.notenoughupdates.autosubscribe.NEUAutoSubscribe import io.github.moulberry.notenoughupdates.cosmetics.GuiCosmetics import io.github.moulberry.notenoughupdates.events.RegisterBrigadierCommandEvent import io.github.moulberry.notenoughupdates.miscgui.CalendarOverlay +import io.github.moulberry.notenoughupdates.miscgui.DynamicLightItemsEditor import io.github.moulberry.notenoughupdates.miscgui.GuiItemCustomize import io.github.moulberry.notenoughupdates.util.Calculator import io.github.moulberry.notenoughupdates.util.Calculator.CalculatorException @@ -127,6 +128,11 @@ class MiscCommands { reply("§bTo ensure we do not accidentally corrupt your mod folder, we can only offer support for auto-updates on system with certain capabilities for file deletions (specifically unix systems). You can still manually update your files") }.withHelp("Display an explanation why you cannot auto update") } + event.command("neudynamiclights", "neudli", "neudynlights", "neudynamicitems") { + thenExecute { + NotEnoughUpdates.INSTANCE.openGui = DynamicLightItemsEditor() + } + }.withHelp("Add items to dynamically emit light") } fun fetchPronouns(platform: String, user: String) { diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/miscgui/DynamicLightItemsEditor.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/miscgui/DynamicLightItemsEditor.kt new file mode 100644 index 00000000..7cebadcb --- /dev/null +++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/miscgui/DynamicLightItemsEditor.kt @@ -0,0 +1,255 @@ +/* + * Copyright (C) 2023 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see . + */ + +package io.github.moulberry.notenoughupdates.miscgui + +import io.github.moulberry.notenoughupdates.NotEnoughUpdates +import io.github.moulberry.notenoughupdates.util.Utils +import net.minecraft.client.Minecraft +import net.minecraft.client.gui.GuiScreen +import net.minecraft.client.renderer.GlStateManager +import net.minecraft.item.ItemStack +import net.minecraft.util.ResourceLocation +import net.minecraftforge.fml.common.registry.GameRegistry +import org.lwjgl.opengl.GL11 +import java.awt.Color +import kotlin.math.ceil + +class DynamicLightItemsEditor() : GuiScreen() { + + val background = ResourceLocation("notenoughupdates:dynamic_light_items_editor.png") + val enabledButton = ResourceLocation("notenoughupdates:enabled_button.png") + val disabledButton = ResourceLocation("notenoughupdates:disabled_button.png") + val chestGui = ResourceLocation("textures/gui/container/generic_54.png") + val widgets = ResourceLocation("textures/gui/widgets.png") + val help = ResourceLocation("notenoughupdates:help.png") + + var xSize = 217 + var ySize = 88 + var guiLeft = 0 + var guiTop = 0 + + var stackToRender: String? = null + var itemSelected: String? = null + + override fun drawScreen(mouseX: Int, mouseY: Int, partialTicks: Float) { + drawDefaultBackground() + + val numOfItems = NotEnoughUpdates.INSTANCE.config.hidden.dynamicLightItems.size + val numOfRows = if (didApplyMixin) ceil(numOfItems / 9f).toInt() else 0 + ySize = 70 + 18 * numOfRows + guiLeft = (width - xSize) / 2 + guiTop = (height - ySize) / 2 + + // Top and bottom half of gui + Minecraft.getMinecraft().textureManager.bindTexture(background) + Utils.drawTexturedRect(guiLeft.toFloat(), guiTop.toFloat(), xSize.toFloat(), 24F, + 0F, 1F, 0F, 24 / 88f, GL11.GL_NEAREST) + Utils.drawTexturedRect(guiLeft.toFloat(), (guiTop + ySize - 46).toFloat(), xSize.toFloat(), 46F, + 0F, 1F, 42 / 88f, 1F, GL11.GL_NEAREST) + + fontRendererObj.drawString("Dynamic Light Items Editor", guiLeft + 10, guiTop + 7, 4210752) + + GlStateManager.color(1f, 1f, 1f, 1f) + Minecraft.getMinecraft().textureManager.bindTexture(help) + Utils.drawTexturedRect((guiLeft + xSize + 3).toFloat(), guiTop.toFloat(), 16F, 16F, GL11.GL_NEAREST) + if (mouseX >= guiLeft + xSize + 3 && + mouseX <= guiLeft + xSize + 19 && + mouseY >= guiTop && + mouseY <= guiTop + 16) { + val tooltip = listOf( + "§bDynamic Light Item Editor", + "§eWhat is this?", + "§eNEU makes use of OptiFine's feature of certain items", + "§eemitting dynamic light. By default OptiFine only implements", + "§ethis feature for a select few minecraft items.", + "", + "§eThis editor however, allows you to add specific skyblock", + "§eitems that will emit dynamic light when held. Simply hold the", + "§eitem you wish to add, then open this menu again and click", + "§e'Add Held Item', now if you have OptiFine installed and the", + "§edynamic lights option enabled, the added items will emit light!", + "", + "§eTo remove an item, click the item in this menu and click", + "§ethe 'Remove Item' button in the bottom right.", + ) + Utils.drawHoveringText(tooltip, mouseX, mouseY, width, height, -1) + } + + if (!didApplyMixin) { + fontRendererObj.drawString("Could not find OptiFine!", guiLeft + 50, guiTop + 22, Color.RED.rgb) + fontRendererObj.drawString("Go to #neu-support in", guiLeft + 50, guiTop + 32, Color.RED.rgb) + fontRendererObj.drawString("the discord for help", guiLeft + 52, guiTop + 42, Color.RED.rgb) + return + } + + // Buttons + GlStateManager.color(1f, 1f, 1f, 1f) + Minecraft.getMinecraft().textureManager.bindTexture(enabledButton) + Utils.drawTexturedRect(guiLeft.toFloat() + 15, (guiTop + ySize - 32).toFloat(), 88F, 20F, + 0F, 1F, 0F, 1F, GL11.GL_NEAREST) + + if (itemSelected != null) { + Minecraft.getMinecraft().textureManager.bindTexture(enabledButton) + } else { + Minecraft.getMinecraft().textureManager.bindTexture(disabledButton) + } + Utils.drawTexturedRect(guiLeft.toFloat() + 114, (guiTop + ySize - 32).toFloat(), 88F, 20F, + 0F, 1F, 0F, 1F, GL11.GL_NEAREST) + + fontRendererObj.drawString("Add Held Item", guiLeft + 27, guiTop + ySize - 26, 4210752) + fontRendererObj.drawString("Remove Item", guiLeft + 130, guiTop + ySize - 26, 4210752) + + GlStateManager.color(1f, 1f, 1f, 1f) + + // Add in some part of the gui for every row + Minecraft.getMinecraft().textureManager.bindTexture(background) + for (i in 0 until numOfRows) { + Utils.drawTexturedRect(guiLeft.toFloat(), ((guiTop + 24) + (i * 18)).toFloat(), xSize.toFloat(), 18f, + 0f, 1f, 24 / 88f, 42 / 88f, GL11.GL_NEAREST) + } + + var hoveredItem: String? = null + var selectedPosition: Pair = Pair(-999, -999) + + // Draw a slot for each item and the ItemStack + for ((index, item) in NotEnoughUpdates.INSTANCE.config.hidden.dynamicLightItems.withIndex()) { + val i = index % 9 + val j = index / 9 + GlStateManager.color(1f, 1f, 1f, 1f) + + Minecraft.getMinecraft().textureManager.bindTexture(chestGui) + drawTexturedModalRect(guiLeft + 27 + i % 9 * 18, guiTop + 24 + j * 18, 7, 17, 18, 18) + + val itemStack = resolveItemStack(item) ?: return + Utils.drawItemStack(itemStack, guiLeft + 28 + i % 9 * 18, guiTop + 25 + j * 18) + + if (mouseX >= guiLeft + 27 + i % 9 * 18 && mouseX <= guiLeft + 45 + i % 9 * 18) { + if (mouseY >= guiTop + 24 + j * 18 && mouseY <= guiTop + 42 + j * 18) { + hoveredItem = item + val tooltip = itemStack.getTooltip(Minecraft.getMinecraft().thePlayer, false) + Utils.drawHoveringText(tooltip, mouseX, mouseY, width, height, -1) + } + } + + if (itemSelected != null && itemSelected.equals(item)) { + // Save the position, so when we render the selected box its renders on top of everything + selectedPosition = Pair(guiLeft + 24 + i % 9 * 18, guiTop + 21 + j * 18) + } + } + + stackToRender = hoveredItem + + GlStateManager.color(1f, 1f, 1f, 1f) + Minecraft.getMinecraft().textureManager.bindTexture(widgets) + drawTexturedModalRect(selectedPosition.first, selectedPosition.second, 0, 22, 24, 24) + + super.drawScreen(mouseX, mouseY, partialTicks) + } + + override fun mouseClicked(mouseX: Int, mouseY: Int, mouseButton: Int) { + if (didApplyMixin) { + // Add Held Item button + if (mouseX >= guiLeft + 15 && + mouseX <= guiLeft + 103 && + mouseY >= (guiTop + ySize - 32) && + mouseY <= (guiTop + ySize - 12)) { + + val heldItem = Minecraft.getMinecraft().thePlayer.heldItem + + if (heldItem == null) { + Utils.addChatMessage("§c[NEU] You can't add your hand to the list of dynamic light items.") + return + } + + val internalName = resolveInternalName(heldItem) + if (internalName == null) { + Utils.addChatMessage("§c[NEU] Couldn't resolve an internal name for this item!") + return + } + NotEnoughUpdates.INSTANCE.config.hidden.dynamicLightItems.add(internalName) + } + + // Remove Item button + if (mouseX >= guiLeft + 114 && + mouseX <= guiLeft + 202 && + mouseY >= guiTop + ySize - 32 && + mouseY <= guiTop + ySize - 12 && + itemSelected != null) { + NotEnoughUpdates.INSTANCE.config.hidden.dynamicLightItems.remove(itemSelected) + itemSelected = null + } + + if (stackToRender != null) { + itemSelected = stackToRender + } + } + + super.mouseClicked(mouseX, mouseY, mouseButton) + } + + companion object { + @JvmStatic + var didApplyMixin = false + + fun resolveItemStack(internalName: String): ItemStack? { + var itemStack = NotEnoughUpdates.INSTANCE.manager + .createItemResolutionQuery() + .withKnownInternalName(internalName) + .resolveToItemStack() + if (itemStack == null) { + // Try resolve the item stack through forge + itemStack = GameRegistry.makeItemStack(internalName, 0, 1, null) + if (itemStack == null) { + Utils.addChatMessage("§c[NEU] Couldn't resolve the ItemStack for $internalName") + return null + } + } + + return itemStack + } + + @JvmStatic + fun resolveInternalName(itemStack: ItemStack): String? { + var internalName = + NotEnoughUpdates.INSTANCE.manager.createItemResolutionQuery().withItemStack(itemStack).resolveInternalName() + if (internalName == null) { + // If resolving internal name failed, the item may be a minecraft item + internalName = itemStack.item.registryName + if (internalName == null) { + // Check if minecraft searching also fails + // Leave error handling for caller since this method is also called in MixinOFDynamicLights which + // is run every tick, and we don't want to flood the chat + return null + } + } + + return internalName + } + + @JvmStatic + fun findDynamicLightItems(itemStack: ItemStack): Int { + val internalName: String = resolveInternalName(itemStack) ?: return 0 + if (NotEnoughUpdates.INSTANCE.config.hidden.dynamicLightItems.contains(internalName)) { + return 15 + } + return 0 + } + } +} diff --git a/src/main/resources/assets/notenoughupdates/disabled_button.png b/src/main/resources/assets/notenoughupdates/disabled_button.png new file mode 100644 index 00000000..4283fbf3 Binary files /dev/null and b/src/main/resources/assets/notenoughupdates/disabled_button.png differ diff --git a/src/main/resources/assets/notenoughupdates/dynamic_light_items_editor.png b/src/main/resources/assets/notenoughupdates/dynamic_light_items_editor.png new file mode 100644 index 00000000..399924c1 Binary files /dev/null and b/src/main/resources/assets/notenoughupdates/dynamic_light_items_editor.png differ diff --git a/src/main/resources/assets/notenoughupdates/enabled_button.png b/src/main/resources/assets/notenoughupdates/enabled_button.png new file mode 100644 index 00000000..a0f8d7fc Binary files /dev/null and b/src/main/resources/assets/notenoughupdates/enabled_button.png differ diff --git a/src/main/resources/mixins.notenoughupdates.json b/src/main/resources/mixins.notenoughupdates.json index eb04957b..279d5cef 100644 --- a/src/main/resources/mixins.notenoughupdates.json +++ b/src/main/resources/mixins.notenoughupdates.json @@ -37,6 +37,7 @@ "MixinMinecraft", "MixinMouseHelper", "MixinNetHandlerPlayClient", + "MixinOFDynamicLights", "MixinPlayerControllerMP", "MixinRender", "MixinRendererLivingEntity", -- cgit From 193ba468e43bd4db5b5534d17472078708783349 Mon Sep 17 00:00:00 2001 From: Lulonaut Date: Sun, 12 Mar 2023 00:54:04 +0100 Subject: cheapest museum item to donate (#522) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: nea Co-authored-by: nea Co-authored-by: Roman / Linnea Gräf Co-authored-by: nopo Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> --- .../notenoughupdates/NotEnoughUpdates.java | 18 +- .../notenoughupdates/listener/RenderListener.java | 365 ++++--------- .../miscfeatures/AbiphoneFavourites.java | 6 +- .../miscfeatures/AuctionProfit.java | 16 + .../miscfeatures/DungeonNpcProfitOverlay.java | 15 + .../miscgui/AccessoryBagOverlay.java | 72 +-- .../miscgui/TrophyRewardOverlay.java | 17 + .../minionhelper/render/MinionHelperOverlay.java | 16 + .../notenoughupdates/mixins/MixinRenderItem.java | 47 +- .../notenoughupdates/options/NEUConfig.java | 4 +- .../options/seperateSections/Misc.java | 1 - .../options/seperateSections/Museum.java | 19 + .../overlays/EquipmentOverlay.java | 25 + .../events/ButtonExclusionZoneEvent.kt | 69 +++ .../inventory/MuseumCheapestItemOverlay.kt | 574 +++++++++++++++++++++ .../moulberry/notenoughupdates/util/Rectangle.kt | 75 +++ .../notenoughupdates/util/RectangleTest.kt | 49 ++ 17 files changed, 1026 insertions(+), 362 deletions(-) create mode 100644 src/main/kotlin/io/github/moulberry/notenoughupdates/events/ButtonExclusionZoneEvent.kt create mode 100644 src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/inventory/MuseumCheapestItemOverlay.kt create mode 100644 src/main/kotlin/io/github/moulberry/notenoughupdates/util/Rectangle.kt create mode 100644 src/test/kotlin/io/github/moulberry/notenoughupdates/util/RectangleTest.kt (limited to 'src/main/kotlin') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java index 7f0136ee..8b6c2255 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java @@ -43,6 +43,8 @@ import io.github.moulberry.notenoughupdates.miscfeatures.PetInfoOverlay; import io.github.moulberry.notenoughupdates.miscfeatures.SlotLocking; import io.github.moulberry.notenoughupdates.miscfeatures.StorageManager; import io.github.moulberry.notenoughupdates.miscfeatures.customblockzones.CustomBlockSounds; +import io.github.moulberry.notenoughupdates.miscfeatures.inventory.MuseumCheapestItemOverlay; +import io.github.moulberry.notenoughupdates.miscfeatures.inventory.MuseumItemHighlighter; import io.github.moulberry.notenoughupdates.miscfeatures.updater.AutoUpdater; import io.github.moulberry.notenoughupdates.mixins.AccessorMinecraft; import io.github.moulberry.notenoughupdates.oneconfig.IOneConfigCompat; @@ -168,6 +170,13 @@ public class NotEnoughUpdates { private File neuDir; private boolean hasSkyblockScoreboard; + public NotEnoughUpdates() { + // Budget Construction Event + ((AccessorMinecraft) FMLClientHandler.instance().getClient()) + .onGetDefaultResourcePacks() + .add(new NEURepoResourcePack(null, "neurepo")); + } + public File getConfigFile() { return this.configFile; } @@ -180,13 +189,6 @@ public class NotEnoughUpdates { return this.neuDir; } - public NotEnoughUpdates() { - // Budget Construction Event - ((AccessorMinecraft) FMLClientHandler.instance().getClient()) - .onGetDefaultResourcePacks() - .add(new NEURepoResourcePack(null, "neurepo")); - } - /** * Instantiates NEUIo, NEUManager and NEUOverlay instances. Registers keybinds and adds a shutdown hook to clear tmp folder. */ @@ -270,6 +272,8 @@ public class NotEnoughUpdates { MinecraftForge.EVENT_BUS.register(navigation); MinecraftForge.EVENT_BUS.register(new WorldListener(this)); AutoLoad.INSTANCE.provide(supplier -> MinecraftForge.EVENT_BUS.register(supplier.get())); + MinecraftForge.EVENT_BUS.register(MuseumItemHighlighter.INSTANCE); + MinecraftForge.EVENT_BUS.register(MuseumCheapestItemOverlay.INSTANCE); if (Minecraft.getMinecraft().getResourceManager() instanceof IReloadableResourceManager) { IReloadableResourceManager manager = (IReloadableResourceManager) Minecraft.getMinecraft().getResourceManager(); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java b/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java index 03f3a449..5e39aa45 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java @@ -28,12 +28,11 @@ import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.auction.CustomAHGui; import io.github.moulberry.notenoughupdates.core.GuiScreenElementWrapper; import io.github.moulberry.notenoughupdates.dungeons.DungeonWin; +import io.github.moulberry.notenoughupdates.events.ButtonExclusionZoneEvent; import io.github.moulberry.notenoughupdates.miscfeatures.AbiphoneWarning; import io.github.moulberry.notenoughupdates.miscfeatures.AuctionBINWarning; -import io.github.moulberry.notenoughupdates.miscfeatures.AuctionProfit; import io.github.moulberry.notenoughupdates.miscfeatures.BetterContainers; import io.github.moulberry.notenoughupdates.miscfeatures.CrystalMetalDetectorSolver; -import io.github.moulberry.notenoughupdates.miscfeatures.DungeonNpcProfitOverlay; import io.github.moulberry.notenoughupdates.miscfeatures.EnchantingSolvers; import io.github.moulberry.notenoughupdates.miscfeatures.PresetWarning; import io.github.moulberry.notenoughupdates.miscfeatures.StorageManager; @@ -45,20 +44,18 @@ import io.github.moulberry.notenoughupdates.miscgui.GuiInvButtonEditor; import io.github.moulberry.notenoughupdates.miscgui.GuiItemRecipe; import io.github.moulberry.notenoughupdates.miscgui.StorageOverlay; import io.github.moulberry.notenoughupdates.miscgui.TradeWindow; -import io.github.moulberry.notenoughupdates.miscgui.TrophyRewardOverlay; import io.github.moulberry.notenoughupdates.miscgui.hex.GuiCustomHex; -import io.github.moulberry.notenoughupdates.miscgui.minionhelper.MinionHelperManager; import io.github.moulberry.notenoughupdates.mixins.AccessorGuiContainer; import io.github.moulberry.notenoughupdates.options.NEUConfig; import io.github.moulberry.notenoughupdates.overlays.AuctionSearchOverlay; import io.github.moulberry.notenoughupdates.overlays.BazaarSearchOverlay; -import io.github.moulberry.notenoughupdates.overlays.EquipmentOverlay; import io.github.moulberry.notenoughupdates.overlays.OverlayManager; import io.github.moulberry.notenoughupdates.overlays.RancherBootOverlay; import io.github.moulberry.notenoughupdates.overlays.TextOverlay; import io.github.moulberry.notenoughupdates.profileviewer.GuiProfileViewer; import io.github.moulberry.notenoughupdates.util.ItemUtils; import io.github.moulberry.notenoughupdates.util.NotificationHandler; +import io.github.moulberry.notenoughupdates.util.Rectangle; import io.github.moulberry.notenoughupdates.util.SBInfo; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; @@ -105,6 +102,7 @@ import java.util.Map; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; +import java.util.function.BiConsumer; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -484,96 +482,68 @@ public class RenderListener { if (CalendarOverlay.isEnabled() || event.isCanceled()) return; if (NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard() && NotificationHandler.shouldRenderOverlay(event.gui) && event.gui instanceof GuiContainer) { - doInventoryButtons = true; - - int zOffset = 50; - - GlStateManager.translate(0, 0, zOffset); - - int xSize = ((AccessorGuiContainer) event.gui).getXSize(); - int ySize = ((AccessorGuiContainer) event.gui).getYSize(); - int guiLeft = ((AccessorGuiContainer) event.gui).getGuiLeft(); - int guiTop = ((AccessorGuiContainer) event.gui).getGuiTop(); + renderButtons((GuiContainer) event.gui); + } + } - if (!NEUApi.disableInventoryButtons) { - if (!EnchantingSolvers.disableButtons()) { - for (NEUConfig.InventoryButton button : NotEnoughUpdates.INSTANCE.config.hidden.inventoryButtons) { - if (!button.isActive()) continue; - if (button.playerInvOnly && !(event.gui instanceof GuiInventory)) continue; + public void iterateButtons(GuiContainer gui, BiConsumer acceptButton) { + if (NEUApi.disableInventoryButtons || EnchantingSolvers.disableButtons()) { + return; + } - int x = guiLeft + button.x; - int y = guiTop + button.y; - if (button.anchorRight) { - x += xSize; - } - if (button.anchorBottom) { - y += ySize; - } - if (AccessoryBagOverlay.isInAccessoryBag()) { - if (x > guiLeft + xSize && x < guiLeft + xSize + 80 + 28 + 5 && y > guiTop - 18 && y < guiTop + 150) { - x += 80 + 28; - } - } - if (TrophyRewardOverlay.inTrophyFishingInventory()) { - int diffX = 162; - if (x > guiLeft + xSize && x < guiLeft + xSize + diffX + 5 && y > guiTop - 18 && y < guiTop + 120) { - x += diffX; - } - } - if (MinionHelperManager.getInstance().inCraftedMinionsInventory()) { - int diffX = 172; - if (x > guiLeft + xSize && x < guiLeft + xSize + diffX + 5 && y > guiTop - 18 && y < guiTop + 128) { - x += diffX; - } - } - if (AuctionProfit.inAuctionPage()) { - if (x + 18 > guiLeft + xSize && x + 18 < guiLeft + xSize + 4 + 28 + 20 && y > guiTop - 180 && - y < guiTop + 56) { - x -= 68 - 200; - } - } - if (EquipmentOverlay.isRenderingArmorHud()) { - if (x < guiLeft + xSize - 150 && x > guiLeft + xSize - 200 && y > guiTop && y < guiTop + 84) { - x -= 25; - } - } - if (EquipmentOverlay.isRenderingPetHud()) { - if (x < guiLeft + xSize - 150 && x > guiLeft + xSize - 200 && y > guiTop + 60 && y < guiTop + 120) { - x -= 25; - } - } - if (inDungeonPage || DungeonNpcProfitOverlay.isRendering()) { - if (x + 10 > guiLeft + xSize && x + 18 < guiLeft + xSize + 4 + 28 + 20 && y > guiTop - 180 && - y < guiTop + 100) { - x += 185; - } - } + AccessorGuiContainer accessor = (AccessorGuiContainer) gui; + Rectangle guiRectangle = new Rectangle( + accessor.getGuiLeft(), + accessor.getGuiTop(), + accessor.getXSize(), + accessor.getYSize() + ); + + ButtonExclusionZoneEvent buttonExclusionZoneEvent = new ButtonExclusionZoneEvent(gui, guiRectangle); + buttonExclusionZoneEvent.post(); + for (NEUConfig.InventoryButton button : NotEnoughUpdates.INSTANCE.config.hidden.inventoryButtons) { + if (!button.isActive()) continue; + if (button.playerInvOnly && !(gui instanceof GuiInventory)) continue; + + Rectangle buttonPosition = buttonExclusionZoneEvent.findButtonPosition(new Rectangle( + accessor.getGuiLeft() + button.x + (button.anchorRight ? accessor.getXSize() : 0), + accessor.getGuiTop() + button.y + (button.anchorBottom ? accessor.getYSize() : 0), + 18, 18 + ) + ); + acceptButton.accept(button, buttonPosition); + } + } - GlStateManager.color(1, 1, 1, 1f); - - GlStateManager.enableDepth(); - GlStateManager.enableAlpha(); - Minecraft.getMinecraft().getTextureManager().bindTexture(EDITOR); - Utils.drawTexturedRect( - x, - y, - 18, - 18, - button.backgroundIndex * 18 / 256f, - (button.backgroundIndex * 18 + 18) / 256f, - 18 / 256f, - 36 / 256f, - GL11.GL_NEAREST - ); + public void renderButtons(GuiContainer gui) { + doInventoryButtons = true; - if (button.icon != null && !button.icon.trim().isEmpty()) { - GuiInvButtonEditor.renderIcon(button.icon, x + 1, y + 1); - } - } - } + int zOffset = 50; + GlStateManager.pushMatrix(); + GlStateManager.translate(0, 0, zOffset); + iterateButtons(gui, (button, buttonPosition) -> { + GlStateManager.color(1, 1, 1, 1f); + GlStateManager.enableDepth(); + GlStateManager.enableAlpha(); + + Minecraft.getMinecraft().getTextureManager().bindTexture(EDITOR); + Utils.drawTexturedRect( + buttonPosition.getX(), + buttonPosition.getY(), + 18, + 18, + button.backgroundIndex * 18 / 256f, + (button.backgroundIndex * 18 + 18) / 256f, + 18 / 256f, + 36 / 256f, + GL11.GL_NEAREST + ); + + if (button.icon != null && !button.icon.trim().isEmpty()) { + GuiInvButtonEditor.renderIcon(button.icon, buttonPosition.getX() + 1, buttonPosition.getY() + 1); } - GlStateManager.translate(0, 0, -zOffset); - } + }); + GlStateManager.popMatrix(); } /** @@ -620,104 +590,50 @@ public class RenderListener { } } - boolean hoveringButton = false; + final boolean[] hoveringButton = {false}; if (!doInventoryButtons) return; if (NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard() && NotificationHandler.shouldRenderOverlay(event.gui) && event.gui instanceof GuiContainer) { - int xSize = ((AccessorGuiContainer) event.gui).getXSize(); - int ySize = ((AccessorGuiContainer) event.gui).getYSize(); - int guiLeft = ((AccessorGuiContainer) event.gui).getGuiLeft(); - int guiTop = ((AccessorGuiContainer) event.gui).getGuiTop(); - - if (!NEUApi.disableInventoryButtons) { - if (!EnchantingSolvers.disableButtons()) { - for (NEUConfig.InventoryButton button : NotEnoughUpdates.INSTANCE.config.hidden.inventoryButtons) { - if (!button.isActive()) continue; - if (button.playerInvOnly && !(event.gui instanceof GuiInventory)) continue; - - int x = guiLeft + button.x; - int y = guiTop + button.y; - if (button.anchorRight) { - x += xSize; - } - if (button.anchorBottom) { - y += ySize; - } - if (AccessoryBagOverlay.isInAccessoryBag()) { - if (x > guiLeft + xSize && x < guiLeft + xSize + 80 + 28 + 5 && y > guiTop - 18 && y < guiTop + 150) { - x += 80 + 28; - } - } - if (TrophyRewardOverlay.inTrophyFishingInventory()) { - int diffX = 162; - if (x > guiLeft + xSize && x < guiLeft + xSize + diffX + 5 && y > guiTop - 18 && y < guiTop + 120) { - x += diffX; - } - } - if (MinionHelperManager.getInstance().inCraftedMinionsInventory()) { - int diffX = 172; - if (x > guiLeft + xSize && x < guiLeft + xSize + diffX + 5 && y > guiTop - 18 && y < guiTop + 128) { - x += diffX; - } - } - if (AuctionProfit.inAuctionPage()) { - if (x + 18 > guiLeft + xSize && x + 18 < guiLeft + xSize + 4 + 28 + 20 && y > guiTop - 180 && - y < guiTop + 56) { - x -= 68 - 200; - } - } - if (EquipmentOverlay.isRenderingArmorHud()) { - if (x < guiLeft + xSize - 150 && x > guiLeft + xSize - 200 && y > guiTop && y < guiTop + 84) { - x -= 25; - } - } - if (EquipmentOverlay.isRenderingPetHud()) { - if (x < guiLeft + xSize - 150 && x > guiLeft + xSize - 200 && y > guiTop + 60 && y < guiTop + 120) { - x -= 25; - } - } + AccessorGuiContainer acc = (AccessorGuiContainer) event.gui; + Rectangle mousePosition = new Rectangle(event.mouseX, event.mouseY, 0, 0); + Rectangle craftingTextRectangle = new Rectangle(acc.getGuiLeft() + 85, acc.getGuiTop() + 4, 30, 21); + iterateButtons((GuiContainer) guiScreen, (button, buttonPosition) -> { - if (inDungeonPage || DungeonNpcProfitOverlay.isRendering()) { - if (x + 10 > guiLeft + xSize && x + 18 < guiLeft + xSize + 4 + 28 + 20 && y > guiTop - 180 && - y < guiTop + 100) { - x += 185; - } - } + if (buttonPosition.intersects(craftingTextRectangle)) { + disableCraftingText = true; + } - if (x - guiLeft >= 85 && x - guiLeft <= 115 && y - guiTop >= 4 && y - guiTop <= 25) { - disableCraftingText = true; - } + if (!buttonPosition.intersects(mousePosition)) { + return; + } + hoveringButton[0] = true; + long currentTime = System.currentTimeMillis(); - if (event.mouseX >= x && event.mouseX <= x + 18 && event.mouseY >= y && event.mouseY <= y + 18) { - hoveringButton = true; - long currentTime = System.currentTimeMillis(); + if (buttonHovered != button) { + buttonHoveredMillis = currentTime; + buttonHovered = button; + } - if (buttonHovered != button) { - buttonHoveredMillis = currentTime; - buttonHovered = button; - } + if (currentTime - buttonHoveredMillis <= NotEnoughUpdates.INSTANCE.config.inventoryButtons.tooltipDelay) { + return; + } + String command = button.command.trim(); + if (!command.startsWith("/")) { + command = "/" + command; + } - if (currentTime - buttonHoveredMillis > NotEnoughUpdates.INSTANCE.config.inventoryButtons.tooltipDelay) { - String command = button.command.trim(); - if (!command.startsWith("/")) { - command = "/" + command; - } + Utils.drawHoveringText( + Lists.newArrayList("\u00a77" + command), + event.mouseX, + event.mouseY, + event.gui.width, + event.gui.height, + -1 + ); - Utils.drawHoveringText( - Lists.newArrayList("\u00a77" + command), - event.mouseX, - event.mouseY, - event.gui.width, - event.gui.height, - -1 - ); - } - } - } - } - } + }); } - if (!hoveringButton) buttonHovered = null; + if (!hoveringButton[0]) buttonHovered = null; if (AuctionBINWarning.getInstance().shouldShow()) { AuctionBINWarning.getInstance().render(); @@ -1121,85 +1037,28 @@ public class RenderListener { if (!doInventoryButtons) return; if (NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard() && NotificationHandler.shouldRenderOverlay(event.gui) && Mouse.getEventButton() >= 0 && event.gui instanceof GuiContainer) { - int xSize = ((AccessorGuiContainer) event.gui).getXSize(); - int ySize = ((AccessorGuiContainer) event.gui).getYSize(); - int guiLeft = ((AccessorGuiContainer) event.gui).getGuiLeft(); - int guiTop = ((AccessorGuiContainer) event.gui).getGuiTop(); - if (!NEUApi.disableInventoryButtons) { - if (!EnchantingSolvers.disableButtons()) { - for (NEUConfig.InventoryButton button : NotEnoughUpdates.INSTANCE.config.hidden.inventoryButtons) { - if (!button.isActive()) continue; - if (button.playerInvOnly && !(event.gui instanceof GuiInventory)) continue; - - int x = guiLeft + button.x; - int y = guiTop + button.y; - if (button.anchorRight) { - x += xSize; - } - if (button.anchorBottom) { - y += ySize; - } - if (AccessoryBagOverlay.isInAccessoryBag()) { - if (x > guiLeft + xSize && x < guiLeft + xSize + 80 + 28 + 5 && y > guiTop - 18 && y < guiTop + 150) { - x += 80 + 28; - } - } - if (TrophyRewardOverlay.inTrophyFishingInventory()) { - int diffX = 162; - if (x > guiLeft + xSize && x < guiLeft + xSize + diffX + 5 && y > guiTop - 18 && y < guiTop + 120) { - x += diffX; - } - } - if (MinionHelperManager.getInstance().inCraftedMinionsInventory()) { - int diffX = 172; - if (x > guiLeft + xSize && x < guiLeft + xSize + diffX + 5 && y > guiTop - 18 && y < guiTop + 128) { - x += diffX; - } - } - if (AuctionProfit.inAuctionPage()) { - if (x + 18 > guiLeft + xSize && x + 18 < guiLeft + xSize + 4 + 28 + 20 && y > guiTop - 180 && - y < guiTop + 56) { - x -= 68 - 200; - } - } - if (EquipmentOverlay.isRenderingArmorHud()) { - if (x < guiLeft + xSize - 150 && x > guiLeft + xSize - 200 && y > guiTop && y < guiTop + 84) { - x -= 25; - } + Rectangle mouseRect = new Rectangle(mouseX, mouseY, 0, 0); + iterateButtons((GuiContainer) event.gui, (button, buttonPositon) -> { + if (!buttonPositon.intersects(mouseRect)) { + return; + } + if (Minecraft.getMinecraft().thePlayer.inventory.getItemStack() == null) { + int clickType = NotEnoughUpdates.INSTANCE.config.inventoryButtons.clickType; + if ((clickType == 0 && Mouse.getEventButtonState()) || + (clickType == 1 && !Mouse.getEventButtonState())) { + String command = button.command.trim(); + if (!command.startsWith("/")) { + command = "/" + command; } - if (EquipmentOverlay.isRenderingPetHud()) { - if (x < guiLeft + xSize - 150 && x > guiLeft + xSize - 200 && y > guiTop + 60 && y < guiTop + 120) { - x -= 25; - } - } - if (inDungeonPage || DungeonNpcProfitOverlay.isRendering()) { - if (x + 10 > guiLeft + xSize && x + 18 < guiLeft + xSize + 4 + 28 + 20 && y > guiTop - 180 && - y < guiTop + 100) { - x += 185; - } - } - - if (mouseX >= x && mouseX <= x + 18 && mouseY >= y && mouseY <= y + 18) { - if (Minecraft.getMinecraft().thePlayer.inventory.getItemStack() == null) { - int clickType = NotEnoughUpdates.INSTANCE.config.inventoryButtons.clickType; - if ((clickType == 0 && Mouse.getEventButtonState()) || - (clickType == 1 && !Mouse.getEventButtonState())) { - String command = button.command.trim(); - if (!command.startsWith("/")) { - command = "/" + command; - } - if (ClientCommandHandler.instance.executeCommand(Minecraft.getMinecraft().thePlayer, command) == 0) { - NotEnoughUpdates.INSTANCE.sendChatMessage(command); - } - } - } else { - event.setCanceled(true); - } - return; + if (ClientCommandHandler.instance.executeCommand(Minecraft.getMinecraft().thePlayer, command) == 0) { + NotEnoughUpdates.INSTANCE.sendChatMessage(command); } } + } else { + event.setCanceled(true); } - } + + }); } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AbiphoneFavourites.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AbiphoneFavourites.java index 3366fd1e..750e674d 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AbiphoneFavourites.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AbiphoneFavourites.java @@ -24,6 +24,7 @@ import io.github.moulberry.notenoughupdates.autosubscribe.NEUAutoSubscribe; import io.github.moulberry.notenoughupdates.core.config.KeybindHelper; import io.github.moulberry.notenoughupdates.core.util.StringUtils; import io.github.moulberry.notenoughupdates.core.util.render.RenderUtils; +import io.github.moulberry.notenoughupdates.events.GuiContainerBackgroundDrawnEvent; import io.github.moulberry.notenoughupdates.events.ReplaceItemEvent; import io.github.moulberry.notenoughupdates.events.SlotClickEvent; import io.github.moulberry.notenoughupdates.options.NEUConfig; @@ -202,10 +203,11 @@ public class AbiphoneFavourites { return isAbiphoneShowOnlyFavourites() && !getFavouriteContacts().contains(name); } - public void onDrawBackground(GuiScreen screen) { + @SubscribeEvent + public void onDrawBackground(GuiContainerBackgroundDrawnEvent event) { if (isWrongInventory()) return; - GuiContainer container = (GuiContainer) screen; + GuiContainer container = event.getContainer(); for (Slot slot : container.inventorySlots.inventorySlots) { if (slot == null) continue; diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AuctionProfit.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AuctionProfit.java index c0e40ec9..c761f847 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AuctionProfit.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AuctionProfit.java @@ -22,7 +22,9 @@ package io.github.moulberry.notenoughupdates.miscfeatures; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.autosubscribe.NEUAutoSubscribe; import io.github.moulberry.notenoughupdates.core.util.StringUtils; +import io.github.moulberry.notenoughupdates.events.ButtonExclusionZoneEvent; import io.github.moulberry.notenoughupdates.mixins.AccessorGuiContainer; +import io.github.moulberry.notenoughupdates.util.Rectangle; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; @@ -46,6 +48,20 @@ public class AuctionProfit { public static final ResourceLocation auctionProfitImage = new ResourceLocation("notenoughupdates:auction_profit.png"); + @SubscribeEvent + public void onButtonExclusionZones(ButtonExclusionZoneEvent event) { + if (inAuctionPage()) { + event.blockArea( + new Rectangle( + event.getGuiBaseRect().getRight(), + event.getGuiBaseRect().getTop(), + 128 /*width*/ + 4 /*space*/, 56 + ), + ButtonExclusionZoneEvent.PushDirection.TOWARDS_RIGHT + ); + } + } + @SubscribeEvent public void onDrawBackground(GuiScreenEvent.BackgroundDrawnEvent event) { if (!inAuctionPage()) return; diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/DungeonNpcProfitOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/DungeonNpcProfitOverlay.java index c4b03b84..c06563c2 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/DungeonNpcProfitOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/DungeonNpcProfitOverlay.java @@ -24,8 +24,10 @@ import com.google.gson.JsonObject; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.autosubscribe.NEUAutoSubscribe; import io.github.moulberry.notenoughupdates.core.util.StringUtils; +import io.github.moulberry.notenoughupdates.events.ButtonExclusionZoneEvent; import io.github.moulberry.notenoughupdates.mixins.AccessorGuiContainer; import io.github.moulberry.notenoughupdates.util.ItemUtils; +import io.github.moulberry.notenoughupdates.util.Rectangle; import io.github.moulberry.notenoughupdates.util.SBInfo; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; @@ -99,6 +101,19 @@ public class DungeonNpcProfitOverlay { } } + @SubscribeEvent + public void onButtonExclusionZones(ButtonExclusionZoneEvent event) { + if (isRendering()) + event.blockArea( + new Rectangle( + event.getGuiBaseRect().getRight(), + event.getGuiBaseRect().getTop(), + 180 /*width*/ + 4 /*space*/, 101 + ), + ButtonExclusionZoneEvent.PushDirection.TOWARDS_RIGHT + ); + } + @SubscribeEvent public void onDrawBackground(GuiScreenEvent.BackgroundDrawnEvent event) { if (!NotEnoughUpdates.INSTANCE.config.dungeons.croesusProfitOverlay || !(event.gui instanceof GuiChest)) { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/AccessoryBagOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/AccessoryBagOverlay.java index 562eb1e0..908ae307 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/AccessoryBagOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/AccessoryBagOverlay.java @@ -25,9 +25,11 @@ import com.google.gson.JsonObject; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.auction.APIManager; import io.github.moulberry.notenoughupdates.core.util.StringUtils; +import io.github.moulberry.notenoughupdates.events.ButtonExclusionZoneEvent; import io.github.moulberry.notenoughupdates.listener.RenderListener; import io.github.moulberry.notenoughupdates.profileviewer.PlayerStats; import io.github.moulberry.notenoughupdates.util.Constants; +import io.github.moulberry.notenoughupdates.util.Rectangle; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Gui; @@ -45,6 +47,7 @@ import net.minecraft.nbt.CompressedStreamTools; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.util.EnumChatFormatting; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import org.lwjgl.input.Mouse; import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL14; @@ -73,6 +76,22 @@ public class AccessoryBagOverlay { private static final int TAB_MISSING = 4; private static final int TAB_OPTIMIZER = 5; + public static final AccessoryBagOverlay INSTANCE = new AccessoryBagOverlay(); + + @SubscribeEvent + public void onButtonExclusionZones(ButtonExclusionZoneEvent event) { + if (isInAccessoryBag()) { + event.blockArea( + new Rectangle( + event.getGuiBaseRect().getRight(), + event.getGuiBaseRect().getTop(), + 80 /*pane*/ + 24 /*tabs*/ + 4 /*space*/, 150 + ), + ButtonExclusionZoneEvent.PushDirection.TOWARDS_RIGHT + ); + } + } + private static final ItemStack[] TAB_STACKS = new ItemStack[]{ Utils.createItemStack(Items.dye, EnumChatFormatting.DARK_AQUA + "Basic Information", 10, EnumChatFormatting.GREEN + "- Talis count by rarity" @@ -475,15 +494,9 @@ public class AccessoryBagOverlay { int yIndex = 0; long currentTime = System.currentTimeMillis(); - int marqueeOffset = (int) (currentTime / 500 % 100); for (ItemStack missingStack : missing) { String s = missingStack.getDisplayName(); - //int marueeOffset - //if(s.length()) { - - //} - s = Minecraft.getMinecraft().fontRendererObj.trimStringToWidth(s, 70); String clean = StringUtils.cleanColourNotModifiers(s); @@ -844,51 +857,8 @@ public class AccessoryBagOverlay { } } - /*private static void renderAlignedString(String first, String second, float x, float y, int length) { - FontRenderer fontRendererObj = Minecraft.getMinecraft().fontRendererObj; - - if(fontRendererObj.getStringWidth(first + " " + second) >= length) { - for(int xOff=-2; xOff<=2; xOff++) { - for(int yOff=-2; yOff<=2; yOff++) { - if(Math.abs(xOff) != Math.abs(yOff)) { - Utils.drawStringCenteredScaledMaxWidth(Utils.cleanColourNotModifiers(first + " " + second), Minecraft.getMinecraft().fontRendererObj, - x+length/2f+xOff/2f, y+4+yOff/2f, false, length, - new Color(0, 0, 0, 200/Math.max(Math.abs(xOff), Math.abs(yOff))).getRGB()); - } - } - } - - GlStateManager.color(1, 1, 1, 1); - Utils.drawStringCenteredScaledMaxWidth(first + " " + second, Minecraft.getMinecraft().fontRendererObj, - x+length/2f, y+4, false, length, 4210752); - } else { - for(int xOff=-2; xOff<=2; xOff++) { - for(int yOff=-2; yOff<=2; yOff++) { - if(Math.abs(xOff) != Math.abs(yOff)) { - fontRendererObj.drawString(Utils.cleanColourNotModifiers(first), - x+xOff/2f, y+yOff/2f, - new Color(0, 0, 0, 200/Math.max(Math.abs(xOff), Math.abs(yOff))).getRGB(), false); - } - } - } - - int secondLen = fontRendererObj.getStringWidth(second); - GlStateManager.color(1, 1, 1, 1); - fontRendererObj.drawString(first, x, y, 4210752, false); - for(int xOff=-2; xOff<=2; xOff++) { - for(int yOff=-2; yOff<=2; yOff++) { - if(Math.abs(xOff) != Math.abs(yOff)) { - fontRendererObj.drawString(Utils.cleanColourNotModifiers(second), - x+length-secondLen+xOff/2f, y+yOff/2f, - new Color(0, 0, 0, 200/Math.max(Math.abs(xOff), Math.abs(yOff))).getRGB(), false); - } - } - } - - GlStateManager.color(1, 1, 1, 1); - fontRendererObj.drawString(second, x+length-secondLen, y, 4210752, false); - } - }*/ + + private static final HashMap STAT_PATTERN_MAP_BONUS = new HashMap() {{ String STAT_PATTERN_BONUS_END = ": (?:\\+|-)[0-9]+(?:\\.[0-9]+)?\\%? \\(((?:\\+|-)[0-9]+)%?"; diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/TrophyRewardOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/TrophyRewardOverlay.java index e13934e1..e8653d53 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/TrophyRewardOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/TrophyRewardOverlay.java @@ -23,9 +23,11 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.autosubscribe.NEUAutoSubscribe; +import io.github.moulberry.notenoughupdates.events.ButtonExclusionZoneEvent; import io.github.moulberry.notenoughupdates.events.RepositoryReloadEvent; import io.github.moulberry.notenoughupdates.mixins.AccessorGuiContainer; import io.github.moulberry.notenoughupdates.util.Constants; +import io.github.moulberry.notenoughupdates.util.Rectangle; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; @@ -97,6 +99,21 @@ public class TrophyRewardOverlay { return line.get(1); } + @SubscribeEvent + public void onButtonExclusionZones(ButtonExclusionZoneEvent event) { + if (inTrophyFishingInventory()) { + event.blockArea( + new Rectangle( + event.getGuiBaseRect().getRight(), + event.getGuiBaseRect().getTop(), + 168 /*width*/ + 4 /*space*/, + 128 + ), + ButtonExclusionZoneEvent.PushDirection.TOWARDS_RIGHT + ); + } + } + @SubscribeEvent(priority = EventPriority.LOWEST) public void onDrawBackground(GuiScreenEvent.BackgroundDrawnEvent event) { if (!inTrophyFishingInventory()) return; diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/render/MinionHelperOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/render/MinionHelperOverlay.java index 1a625794..93a39ec0 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/render/MinionHelperOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/render/MinionHelperOverlay.java @@ -24,6 +24,7 @@ import com.google.common.collect.Lists; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.core.util.ArrowPagesUtils; import io.github.moulberry.notenoughupdates.core.util.StringUtils; +import io.github.moulberry.notenoughupdates.events.ButtonExclusionZoneEvent; import io.github.moulberry.notenoughupdates.miscgui.TrophyRewardOverlay; import io.github.moulberry.notenoughupdates.miscgui.minionhelper.Minion; import io.github.moulberry.notenoughupdates.miscgui.minionhelper.MinionHelperManager; @@ -34,6 +35,7 @@ import io.github.moulberry.notenoughupdates.miscgui.minionhelper.sources.NpcSour import io.github.moulberry.notenoughupdates.mixins.AccessorGuiContainer; import io.github.moulberry.notenoughupdates.util.ItemUtils; import io.github.moulberry.notenoughupdates.util.NotificationHandler; +import io.github.moulberry.notenoughupdates.util.Rectangle; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; @@ -93,6 +95,20 @@ public class MinionHelperOverlay { cacheTotalPages = -1; } + @SubscribeEvent + public void onButtonExclusionZones(ButtonExclusionZoneEvent event) { + if (manager.inCraftedMinionsInventory() && NotEnoughUpdates.INSTANCE.config.minionHelper.gui) { + event.blockArea( + new Rectangle( + event.getGuiBaseRect().getRight(), + event.getGuiBaseRect().getTop(), + 168 /*width*/ + 4 /*space*/, 128 + ), + ButtonExclusionZoneEvent.PushDirection.TOWARDS_RIGHT + ); + } + } + @SubscribeEvent public void onDrawBackground(GuiScreenEvent.BackgroundDrawnEvent event) { if (!manager.inCraftedMinionsInventory()) return; diff --git a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinRenderItem.java b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinRenderItem.java index 2173a3c8..633a82a2 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinRenderItem.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinRenderItem.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 NotEnoughUpdates contributors + * Copyright (C) 2022-2023 NotEnoughUpdates contributors * * This file is part of NotEnoughUpdates. * @@ -148,51 +148,6 @@ public abstract class MixinRenderItem { @Shadow abstract void renderModel(IBakedModel model, int color); - /*@Redirect(method="renderEffect", - at=@At( - value = "INVOKE", - target = "Lnet/minecraft/client/renderer/entity/RenderItem;renderModel(Lnet/minecraft/client/resources/model/IBakedModel;I)V" - ) - ) - public void renderEffect_renderModel(RenderItem renderItem, IBakedModel model, int colour) { - if(customEnchGlint != null) { - renderModel(model, ChromaColour.specialToChromaRGB(customEnchGlint)); - } else { - renderModel(model, colour); - } - } - - @Redirect(method="renderEffect", - at=@At( - value = "INVOKE", - target = "Lnet/minecraft/client/renderer/texture/TextureManager;bindTexture(Lnet/minecraft/util/ResourceLocation;)V" - ) - ) - public void renderEffect_bindTexture(TextureManager textureManager, ResourceLocation location) { - if(customEnchGlint != null) { - textureManager.bindTexture(GlintManager.getCustomGlintTexture()); - GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); - GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); - } else { - textureManager.bindTexture(location); - } - } - - @Redirect(method="renderEffect", - at=@At( - value = "INVOKE", - target = "Lnet/minecraft/client/renderer/GlStateManager;blendFunc(II)V" - ) - ) - public void renderEffect_blendFunc(int src, int dst) { - if(dst != 1) { - GlStateManager.blendFunc(src, dst); - } else if(customEnchGlint != null) { - GlintManager.setCustomBlendFunc(customEnchGlint); - } else { - GlStateManager.blendFunc(GL11.GL_SRC_COLOR, 1); - } - }*/ @Inject(method = "renderItemIntoGUI", at = @At("HEAD")) public void renderItemHead(ItemStack stack, int x, int y, CallbackInfo ci) { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java b/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java index 498b3b0d..53906cd8 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java @@ -250,8 +250,8 @@ public class NEUConfig extends Config { @Expose @Category( - name = "Todo Overlay", - desc = "Todo Overlay" + name = "Todo Overlays", + desc = "Todo Overlays" ) public MiscOverlays miscOverlays = new MiscOverlays(); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Misc.java b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Misc.java index affaa68a..02630df9 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Misc.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Misc.java @@ -319,5 +319,4 @@ public class Misc { ) @ConfigEditorBoolean public boolean oldSkyBlockMenu = false; - } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Museum.java b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Museum.java index c476fc3b..6f03c2bb 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Museum.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Museum.java @@ -22,6 +22,7 @@ package io.github.moulberry.notenoughupdates.options.seperateSections; import com.google.gson.annotations.Expose; import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigEditorBoolean; import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigEditorColour; +import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigEditorDropdown; import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigOption; public class Museum { @@ -42,4 +43,22 @@ public class Museum { @ConfigEditorColour public String museumItemColor = "0:255:0:255:0"; + @Expose + @ConfigOption( + name = "Show Items to donate", + desc = "Show the cheapest items you have not yet donated to the Museum" + ) + @ConfigEditorBoolean + public boolean museumCheapestItemOverlay = true; + + @Expose + @ConfigOption( + name = "Value calculation", + desc = "Choose the source for the value calculation" + ) + @ConfigEditorDropdown( + values = {"Lowest BIN", "Craft cost"} + ) + public int museumCheapestItemOverlayValueSource = 0; + } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/overlays/EquipmentOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/overlays/EquipmentOverlay.java index a812ff52..4d14e47f 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/overlays/EquipmentOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/overlays/EquipmentOverlay.java @@ -25,12 +25,14 @@ import com.google.gson.JsonPrimitive; import io.github.moulberry.notenoughupdates.NEUManager; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.autosubscribe.NEUAutoSubscribe; +import io.github.moulberry.notenoughupdates.events.ButtonExclusionZoneEvent; import io.github.moulberry.notenoughupdates.events.GuiInventoryBackgroundDrawnEvent; import io.github.moulberry.notenoughupdates.miscfeatures.PetInfoOverlay; import io.github.moulberry.notenoughupdates.miscgui.GuiInvButtonEditor; import io.github.moulberry.notenoughupdates.mixins.AccessorGuiContainer; import io.github.moulberry.notenoughupdates.options.NEUConfig; import io.github.moulberry.notenoughupdates.util.ItemUtils; +import io.github.moulberry.notenoughupdates.util.Rectangle; import io.github.moulberry.notenoughupdates.util.SBInfo; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; @@ -149,6 +151,29 @@ public class EquipmentOverlay { public ItemStack petStack; // + @SubscribeEvent + public void onButtonExclusionZones(ButtonExclusionZoneEvent event) { + if (isRenderingArmorHud()) { + event.blockArea( + new Rectangle( + event.getGuiBaseRect().getRight() - 200, + event.getGuiBaseRect().getTop(), + 50, 84 + ), + ButtonExclusionZoneEvent.PushDirection.TOWARDS_LEFT + ); + } + if (isRenderingPetHud()) { + event.blockArea( + new Rectangle( + event.getGuiBaseRect().getRight() - 200, + event.getGuiBaseRect().getTop() + 60, + 50, 60 + ), + ButtonExclusionZoneEvent.PushDirection.TOWARDS_LEFT + ); + } + } @SubscribeEvent public void onGuiTick(TickEvent.ClientTickEvent event) { diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/events/ButtonExclusionZoneEvent.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/events/ButtonExclusionZoneEvent.kt new file mode 100644 index 00000000..3c8ce418 --- /dev/null +++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/events/ButtonExclusionZoneEvent.kt @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2023 Linnea Gräf + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see . + */ + +package io.github.moulberry.notenoughupdates.events + +import io.github.moulberry.notenoughupdates.events.ButtonExclusionZoneEvent.PushDirection.* +import io.github.moulberry.notenoughupdates.util.Rectangle +import net.minecraft.client.gui.GuiScreen +import java.util.* + +class ButtonExclusionZoneEvent( + val gui: GuiScreen, + val guiBaseRect: Rectangle, +) : NEUEvent() { + enum class PushDirection { + TOWARDS_RIGHT, + TOWARDS_LEFT, + TOWARDS_TOP, + TOWARDS_BOTTOM, + } + + data class ExclusionZone( + val area: Rectangle, + val pushDirection: PushDirection, + ) + + val occupiedRects = mutableListOf() + fun blockArea(area: Rectangle, direction: PushDirection) { + occupiedRects.add(ExclusionZone(area, direction)) + } + + @JvmOverloads + fun findButtonPosition(button: Rectangle, margin: Int = 0): Rectangle { + val processedAreas = IdentityHashMap() + + var buttonPosition = button + while (true) { + val overlappingExclusionZone = + occupiedRects.find { it !in processedAreas && it.area.intersects(buttonPosition) } ?: break + buttonPosition = when (overlappingExclusionZone.pushDirection) { + TOWARDS_RIGHT -> buttonPosition.copy(x = overlappingExclusionZone.area.right + margin) + TOWARDS_LEFT -> buttonPosition.copy(x = overlappingExclusionZone.area.left - buttonPosition.width - margin) + TOWARDS_TOP -> buttonPosition.copy(y = overlappingExclusionZone.area.top - buttonPosition.height - margin) + TOWARDS_BOTTOM -> buttonPosition.copy(y = overlappingExclusionZone.area.bottom + margin) + } + processedAreas[overlappingExclusionZone] = Unit + } + + return buttonPosition + } + + +} diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/inventory/MuseumCheapestItemOverlay.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/inventory/MuseumCheapestItemOverlay.kt new file mode 100644 index 00000000..8a711230 --- /dev/null +++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/inventory/MuseumCheapestItemOverlay.kt @@ -0,0 +1,574 @@ +/* + * Copyright (C) 2023 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see . + */ + +package io.github.moulberry.notenoughupdates.miscfeatures.inventory + +import io.github.moulberry.notenoughupdates.NotEnoughUpdates +import io.github.moulberry.notenoughupdates.core.util.ArrowPagesUtils +import io.github.moulberry.notenoughupdates.core.util.render.TextRenderUtils +import io.github.moulberry.notenoughupdates.events.ButtonExclusionZoneEvent +import io.github.moulberry.notenoughupdates.mixins.AccessorGuiContainer +import io.github.moulberry.notenoughupdates.options.seperateSections.Museum +import io.github.moulberry.notenoughupdates.util.* +import io.github.moulberry.notenoughupdates.util.MuseumUtil.DonationState.MISSING +import net.minecraft.client.Minecraft +import net.minecraft.client.gui.GuiScreen +import net.minecraft.client.gui.ScaledResolution +import net.minecraft.client.gui.inventory.GuiChest +import net.minecraft.client.renderer.GlStateManager +import net.minecraft.client.renderer.RenderHelper +import net.minecraft.init.Blocks +import net.minecraft.init.Items +import net.minecraft.inventory.Slot +import net.minecraft.item.ItemStack +import net.minecraft.util.EnumChatFormatting +import net.minecraft.util.ResourceLocation +import net.minecraftforge.client.event.GuiScreenEvent +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import org.lwjgl.input.Mouse +import org.lwjgl.opengl.GL11 +import kotlin.math.ceil + + +object MuseumCheapestItemOverlay { + + enum class Category { + WEAPONS, + ARMOUR_SETS, + RARITIES, + NOT_APPLICABLE; // Either not a valid category or inside the "Special Items" category, which is not useful; + + /** + * Convert to readable String to be displayed to the user + */ + override fun toString(): String { + return when (this) { + WEAPONS -> "Weapons" + ARMOUR_SETS -> "Armour Sets" + RARITIES -> "Rarities" + NOT_APPLICABLE -> "Everything" + } + } + } + + data class MuseumItem( + var name: String, + var internalNames: List, + var value: Double, + var priceRefreshedAt: Long, + var category: Category + ) + + private const val ITEMS_PER_PAGE = 10 + + private val backgroundResource: ResourceLocation = ResourceLocation("notenoughupdates:minion_overlay.png") + + val config: Museum get() = NotEnoughUpdates.INSTANCE.config.museum + + /** + * The top left position of the arrows to be drawn, used by [ArrowPagesUtils] + */ + private var topLeft = intArrayOf(237, 110) + private var currentPage: Int = 0 + private var previousSlots: List = emptyList() + private var itemsToDonate: MutableList = emptyList().toMutableList() + private var leftButtonRect = Rectangle(0, 0, 0, 0) + private var rightButtonRect = Rectangle(0, 0, 0, 0) + private var selectedCategory = Category.NOT_APPLICABLE + private var totalPages = 0 + + /** + *category -> was the highest page visited? + */ + private var checkedPages: HashMap = hashMapOf( + //this page only shows items when you have already donated them -> there is no useful information to gather + Category.WEAPONS to false, + Category.ARMOUR_SETS to false, + Category.RARITIES to false + ) + + /** + * Draw the overlay and parse items, if applicable + */ + @SubscribeEvent + fun onDrawBackground(event: GuiScreenEvent.BackgroundDrawnEvent) { + if (!shouldRender(event.gui)) return + val chest = event.gui as GuiChest + + val slots = chest.inventorySlots.inventorySlots + //check if there is any info to gather only when a category is currently open + if (!slots.equals(previousSlots) && Utils.getOpenChestName().startsWith("Museum ➜")) { + checkIfHighestPageWasVisited(slots) + parseItems(slots) + updateOutdatedValues() + } + previousSlots = slots + + val xSize = (event.gui as AccessorGuiContainer).xSize + val guiLeft = (event.gui as AccessorGuiContainer).guiLeft + val guiTop = (event.gui as AccessorGuiContainer).guiTop + + drawBackground(guiLeft, xSize, guiTop) + drawLines(guiLeft, guiTop) + drawButtons(guiLeft, xSize, guiTop) + } + + /** + * Pass on mouse clicks to [ArrowPagesUtils], if applicable + */ + @SubscribeEvent + fun onMouseClick(event: GuiScreenEvent.MouseInputEvent.Pre) { + if (!shouldRender(event.gui)) return + if (!Mouse.getEventButtonState()) return + val guiLeft = (event.gui as AccessorGuiContainer).guiLeft + val guiTop = (event.gui as AccessorGuiContainer).guiTop + ArrowPagesUtils.onPageSwitchMouse( + guiLeft, guiTop, topLeft, currentPage, totalPages + ) { pageChange: Int -> currentPage = pageChange } + } + + @SubscribeEvent + fun onButtonExclusionZones(event: ButtonExclusionZoneEvent) { + if (shouldRender(event.gui)) { + event.blockArea( + Rectangle( + event.guiBaseRect.right, + event.guiBaseRect.top, + 175, 130 + ), ButtonExclusionZoneEvent.PushDirection.TOWARDS_RIGHT + ) + } + } + + @SubscribeEvent + fun onMouseInput(event: GuiScreenEvent.MouseInputEvent.Pre) { + if (!shouldRender(event.gui)) return + val mouseX = Utils.getMouseX() + val mouseY = Utils.getMouseY() + if (Mouse.getEventButtonState() && leftButtonRect.contains(mouseX, mouseY)) { + config.museumCheapestItemOverlayValueSource = 1 - config.museumCheapestItemOverlayValueSource + updateAllValues() + } else if (Mouse.getEventButtonState() && rightButtonRect.contains(mouseX, mouseY)) { + advanceSelectedCategory() + } + } + + /** + * Move the selected category one index forward, or back to the start when already at the end + */ + private fun advanceSelectedCategory() { + val nextValueIndex = (selectedCategory.ordinal + 1) % 4 + selectedCategory = enumValues()[nextValueIndex] + } + + /** + * Draw the two clickable buttons on the bottom right and display a tooltip if needed + */ + private fun drawButtons(guiLeft: Int, xSize: Int, guiTop: Int) { + RenderHelper.enableGUIStandardItemLighting() + val useBIN = config.museumCheapestItemOverlayValueSource == 0 + val mouseX = Utils.getMouseX() + val mouseY = Utils.getMouseY() + val scaledResolution = ScaledResolution(Minecraft.getMinecraft()) + val width = scaledResolution.scaledWidth + val height = scaledResolution.scaledHeight + + // Left button + val leftItemStack = if (useBIN) { + ItemUtils.getCoinItemStack(100000.0) + } else { + ItemStack(Blocks.crafting_table) + } + leftButtonRect = Rectangle( + guiLeft + xSize + 131, + guiTop + 106, + 16, + 16 + ) + Minecraft.getMinecraft().renderItem.renderItemIntoGUI( + leftItemStack, + leftButtonRect.x, + leftButtonRect.y + ) + + if (leftButtonRect.contains(mouseX, mouseY)) { + val tooltip = if (useBIN) { + listOf( + "${EnumChatFormatting.GREEN}Using ${EnumChatFormatting.BLUE}lowest BIN ${EnumChatFormatting.GREEN}as price source!", + "", + "${EnumChatFormatting.YELLOW}Click to switch to craft cost!" + ) + } else { + listOf( + "${EnumChatFormatting.GREEN}Using ${EnumChatFormatting.AQUA}craft cost ${EnumChatFormatting.GREEN}as price source!", + "", + "${EnumChatFormatting.YELLOW}Click to switch to lowest BIN!" + ) + } + Utils.drawHoveringText( + tooltip, + mouseX, + mouseY, + width, + height, + -1, + Minecraft.getMinecraft().fontRendererObj + ) + } + + // Right button + val rightItemStack = when (selectedCategory) { + Category.WEAPONS -> ItemStack(Items.diamond_sword) + Category.ARMOUR_SETS -> ItemStack(Items.diamond_chestplate) + Category.RARITIES -> ItemStack(Items.emerald) + Category.NOT_APPLICABLE -> ItemStack(Items.filled_map) + } + rightButtonRect = Rectangle( + guiLeft + xSize + 150, + guiTop + 106, + 16, + 16 + ) + Minecraft.getMinecraft().renderItem.renderItemIntoGUI( + rightItemStack, + rightButtonRect.x, + rightButtonRect.y + ) + if (rightButtonRect.contains(mouseX, mouseY)) { + val tooltip = mutableListOf( + "${EnumChatFormatting.GREEN}Category Filter", + "", + ) + for (category in Category.values()) { + tooltip.add( + if (category == selectedCategory) { + "${EnumChatFormatting.BLUE}>$category" + } else { + category.toString() + } + ) + } + + tooltip.add("") + tooltip.add("${EnumChatFormatting.YELLOW}Click to advance!") + Utils.drawHoveringText( + tooltip, + mouseX, + mouseY, + width, + height, + -1, + Minecraft.getMinecraft().fontRendererObj + ) + } + RenderHelper.disableStandardItemLighting() + } + + /** + * Sort the collected items by their calculated value + */ + private fun sortByValue() { + itemsToDonate.sortBy { it.value } + } + + /** + * Update all values that have not been updated for the last minute + */ + private fun updateOutdatedValues() { + val time = System.currentTimeMillis() + itemsToDonate.filter { time - it.priceRefreshedAt >= 60000 } + .forEach { + it.value = calculateValue(it.internalNames) + it.priceRefreshedAt = time + } + } + + /** + * Update all values regardless of the time of the last update + */ + private fun updateAllValues() { + val time = System.currentTimeMillis() + itemsToDonate.forEach { + it.value = calculateValue(it.internalNames) + it.priceRefreshedAt = time + } + sortByValue() + } + + /** + * Calculate the value of an item as displayed in the museum, which may consist of multiple pieces + */ + private fun calculateValue(internalNames: List): Double { + var totalValue = 0.0 + internalNames.forEach { + val itemValue: Double = + when (config.museumCheapestItemOverlayValueSource) { + 0 -> NotEnoughUpdates.INSTANCE.manager.auctionManager.getBazaarOrBin(it, false) + 1 -> NotEnoughUpdates.INSTANCE.manager.auctionManager.getCraftCost(it)?.craftCost ?: return@forEach + else -> -1.0 //unreachable + } + if (itemValue == -1.0 || itemValue == 0.0) { + totalValue = Double.MAX_VALUE + return@forEach + } else { + totalValue += itemValue + } + } + if (totalValue == 0.0) { + totalValue = Double.MAX_VALUE + } + + return totalValue + } + + /** + * Draw the lines containing the displayname and value over the background + */ + private fun drawLines(guiLeft: Int, guiTop: Int) { + val mouseX = Utils.getMouseX() + val mouseY = Utils.getMouseY() + val scaledResolution = ScaledResolution(Minecraft.getMinecraft()) + val width = scaledResolution.scaledWidth + val height = scaledResolution.scaledHeight + + val applicableItems = if (selectedCategory == Category.NOT_APPLICABLE) { + itemsToDonate + } else { + itemsToDonate.toList().filter { it.category == selectedCategory } + } + val lines = buildLines(applicableItems) + totalPages = ceil(applicableItems.size.toFloat() / ITEMS_PER_PAGE.toFloat()).toInt() + + lines.forEachIndexed { index, line -> + if (!visitedAllPages() && (index == ITEMS_PER_PAGE || index == lines.size - 1)) { + TextRenderUtils.drawStringScaledMaxWidth( + "${EnumChatFormatting.RED}Visit all pages for accurate info!", + Minecraft.getMinecraft().fontRendererObj, + (guiLeft + 185).toFloat(), + (guiTop + 95).toFloat(), + true, + 155, + 0 + ) + return@forEachIndexed + } else { + val x = (guiLeft + 187).toFloat() + val y = (guiTop + 5 + (index * 10)).toFloat() + Utils.renderAlignedString( + line.name, + if (line.value == Double.MAX_VALUE) "${EnumChatFormatting.RED}Unknown ${if (config.museumCheapestItemOverlayValueSource == 0) "BIN" else "Craft Cost"}" else "${EnumChatFormatting.AQUA}${ + Utils.shortNumberFormat( + line.value, + 0 + ) + }", + x, + y, + 156 + ) + + if (Utils.isWithinRect(mouseX, mouseY, x.toInt(), y.toInt(), 170, 10)) { + val tooltip = mutableListOf(line.name, "") + //armor set + if (line.internalNames.size > 1) { + tooltip.add("${EnumChatFormatting.AQUA}Consists of:") + line.internalNames.forEach { + val displayname = + NotEnoughUpdates.INSTANCE.manager.createItemResolutionQuery().withKnownInternalName(it) + .resolveToItemListJson() + ?.get("displayname")?.asString ?: "ERROR" + val value = calculateValue(listOf(it)) + + // Creates:" - displayname (price)" OR " - displayname (No BIN found!)" + tooltip.add( + " ${EnumChatFormatting.DARK_GRAY}-${EnumChatFormatting.RESET} $displayname${EnumChatFormatting.DARK_GRAY} (${EnumChatFormatting.GOLD}${ + if (value == Double.MAX_VALUE) { + "${EnumChatFormatting.RED}No BIN found!" + } else { + Utils.shortNumberFormat( + value, + 0 + ) + } + }${EnumChatFormatting.DARK_GRAY})" + ) + } + tooltip.add("") + } + + if (NotEnoughUpdates.INSTANCE.manager.getRecipesFor(line.internalNames[0]).isNotEmpty()) { + tooltip.add("${EnumChatFormatting.YELLOW}${EnumChatFormatting.BOLD}Click to open recipe!") + } else { + tooltip.add("${EnumChatFormatting.RED}${EnumChatFormatting.BOLD}No recipe available!") + } + + if (Mouse.getEventButtonState()) { + //TODO? this only opens the recipe for one of the armor pieces + NotEnoughUpdates.INSTANCE.manager.showRecipe(line.internalNames[0]) + } + + Utils.drawHoveringText( + tooltip, + mouseX, + mouseY, + width, + height, + -1, + Minecraft.getMinecraft().fontRendererObj + ) + } + } + } + + //no page has been visited yet + if (lines.isEmpty()) { + TextRenderUtils.drawStringScaledMaxWidth( + "${EnumChatFormatting.RED}No items matching filter!", + Minecraft.getMinecraft().fontRendererObj, + (guiLeft + 200).toFloat(), + (guiTop + 128 / 2).toFloat(), + true, + 155, + 0 + ) + } + + ArrowPagesUtils.onDraw(guiLeft, guiTop, topLeft, currentPage, totalPages) + return + } + + /** + * Create the list of [MuseumItem]s that should be displayed on the current page + */ + private fun buildLines(applicableItems: List): List { + val list = emptyList().toMutableList() + + for (i in (ITEMS_PER_PAGE * currentPage) until ((ITEMS_PER_PAGE * currentPage) + ITEMS_PER_PAGE)) { + if (i >= applicableItems.size) { + break + } + + list.add(applicableItems[i]) + } + return list + } + + /** + * Parse the not already donated items present in the currently open Museum page + */ + private fun parseItems(slots: List) { + Thread { + val time = System.currentTimeMillis() + val category = getCategory() + if (category == Category.NOT_APPLICABLE) { + return@Thread + } + val armor = category == Category.ARMOUR_SETS + for (i in 0..53) { + val stack = slots[i].stack ?: continue + val parsedItems = MuseumUtil.findMuseumItem(stack, armor) ?: continue + when (parsedItems.state) { + MISSING -> { + val displayName = if (armor) { + // Use the provided displayname for armor sets but change the color to blue (from red) + "${EnumChatFormatting.BLUE}${stack.displayName.stripControlCodes()}" + } else { + // Find out the real displayname and use it for normal items, if possible + NotEnoughUpdates.INSTANCE.manager.createItemResolutionQuery() + .withKnownInternalName(parsedItems.skyblockItemIds.first()) + .resolveToItemListJson() + ?.get("displayname")?.asString ?: "${EnumChatFormatting.RED}ERROR" + } + + //if the list does not already contain it, insert this MuseumItem + if (itemsToDonate.none { it.internalNames == parsedItems.skyblockItemIds }) { + itemsToDonate.add( + MuseumItem( + displayName, + parsedItems.skyblockItemIds, + calculateValue(parsedItems.skyblockItemIds), + time, + category + ) + ) + } + } + + else -> itemsToDonate.retainAll { it.internalNames != parsedItems.skyblockItemIds } + } + } + sortByValue() + }.start() + } + + /** + * Check if the highest page for the current category is currently open and update [checkedPages] accordingly + */ + private fun checkIfHighestPageWasVisited(slots: List) { + val category = getCategory() + val nextPageSlot = slots[53] + // If the "Next Page" arrow is missing, we are at the highest page + if ((nextPageSlot.stack ?: return).item != Items.arrow) { + checkedPages[category] = true + } + } + + /** + * Draw the background texture to the right side of the open Museum Page + */ + private fun drawBackground(guiLeft: Int, xSize: Int, guiTop: Int) { + Minecraft.getMinecraft().textureManager.bindTexture(backgroundResource) + GL11.glColor4f(1F, 1F, 1F, 1F) + GlStateManager.disableLighting() + Utils.drawTexturedRect( + (guiLeft + xSize + 4).toFloat(), + guiTop.toFloat(), + 168f, + 128f, + 0f, + 1f, + 0f, + 1f, + GL11.GL_NEAREST + ) + } + + /** + * Determine if the overlay should be active based on the config option and the currently open GuiChest, if applicable + */ + private fun shouldRender(gui: GuiScreen): Boolean = + config.museumCheapestItemOverlay && NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard() && (gui is GuiChest && Utils.getOpenChestName() + .startsWith("Museum ➜") || Utils.getOpenChestName() == "Your Museum") + + /** + * Determine the currently open Museum Category + */ + private fun getCategory(): Category = + when (Utils.getOpenChestName().substring(9, Utils.getOpenChestName().length)) { + "Weapons" -> Category.WEAPONS + "Armor Sets" -> Category.ARMOUR_SETS + "Rarities" -> Category.RARITIES + else -> Category.NOT_APPLICABLE + } + + /** + * Determine if all useful pages have been visited + */ + private fun visitedAllPages(): Boolean = !checkedPages.containsValue(false) +} diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/util/Rectangle.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/util/Rectangle.kt new file mode 100644 index 00000000..d44b7721 --- /dev/null +++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/util/Rectangle.kt @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2023 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see . + */ + +package io.github.moulberry.notenoughupdates.util + +/** + * An axis aligned rectangle in the following coordinate space: + * + * * The top direction is towards y=-INF + * * The bottom direction is towards y=+INF + * * The right direction is towards x=+INF + * * The left direction is towards x=-INF + */ +data class Rectangle( + val x: Int, val y: Int, + val width: Int, val height: Int, +) { + /** + * The left edge of this rectangle (Low X) + */ + val left get() = x + + /** + * The right edge of this rectangle (High X) + */ + val right get() = x + width + + /** + * The top edge of this rectangle (Low X) + */ + val top get() = y + + /** + * The bottom edge of this rectangle (High X) + */ + val bottom get() = y + height + + init { + require(width >= 0) + require(height >= 0) + } + + /** + * Check for intersections between two rectangles. Two rectangles with perfectly aligned edges do *not* count as + * intersecting. + */ + fun intersects(other: Rectangle): Boolean { + val intersectsX = !(right <= other.left || left >= other.right) + val intersectsY = !(top >= other.bottom || bottom <= other.top) + return intersectsX && intersectsY + } + + /** + * Check if this rectangle contains the given coordinate + */ + fun contains(x1: Int, y1: Int) :Boolean{ + return left <= x1 && x1 < left + width && top <= y1 && y1 < top + height + } +} diff --git a/src/test/kotlin/io/github/moulberry/notenoughupdates/util/RectangleTest.kt b/src/test/kotlin/io/github/moulberry/notenoughupdates/util/RectangleTest.kt new file mode 100644 index 00000000..6d4270dd --- /dev/null +++ b/src/test/kotlin/io/github/moulberry/notenoughupdates/util/RectangleTest.kt @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2023 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see . + */ + +package io.github.moulberry.notenoughupdates.util + +import org.junit.jupiter.api.Assertions.assertFalse +import org.junit.jupiter.api.Assertions.assertTrue +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertThrows + +class RectangleTest { + + @Test + fun testNoNegativeSizes() { + assertThrows { + Rectangle(0, 0, -1, 0) + } + assertThrows { + Rectangle(0, 0, 0, -1) + } + } + + @Test + fun testOverlaps() { + val topLeft = Rectangle(0, 0, 10, 10) + assertTrue(topLeft.intersects(topLeft)) + assertTrue(topLeft.intersects(Rectangle(9, 2, 1, 1))) + assertTrue(topLeft.intersects(Rectangle(-2, -2, 4, 4))) + assertTrue(topLeft.intersects(Rectangle(4, 4, 1, 1))) + assertFalse(topLeft.intersects(Rectangle(-2,-2, 1,1))) + assertFalse(topLeft.intersects(Rectangle(-2,-2, 2,2))) + } +} -- cgit