From 3de3b26e839a2bfc2794d5dd1c17bf12e7a517c8 Mon Sep 17 00:00:00 2001 From: Lulonaut Date: Wed, 28 Dec 2022 16:42:30 +0100 Subject: move file for consistency --- .../notenoughupdates/NotEnoughUpdates.java | 16 +- .../miscfeatures/MuseumCheapestItemOverlay.kt | 284 --------------------- .../inventory/MuseumCheapestItemOverlay.kt | 284 +++++++++++++++++++++ 3 files changed, 292 insertions(+), 292 deletions(-) delete mode 100644 src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/MuseumCheapestItemOverlay.kt create mode 100644 src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/inventory/MuseumCheapestItemOverlay.kt diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java index c24d69f9..21dc32c6 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java @@ -55,7 +55,6 @@ import io.github.moulberry.notenoughupdates.miscfeatures.FishingHelper; import io.github.moulberry.notenoughupdates.miscfeatures.ItemCooldowns; import io.github.moulberry.notenoughupdates.miscfeatures.ItemCustomizeManager; import io.github.moulberry.notenoughupdates.miscfeatures.MiningStuff; -import io.github.moulberry.notenoughupdates.miscfeatures.MuseumCheapestItemOverlay; import io.github.moulberry.notenoughupdates.miscfeatures.NPCRetexturing; import io.github.moulberry.notenoughupdates.miscfeatures.Navigation; import io.github.moulberry.notenoughupdates.miscfeatures.NullzeeSphere; @@ -68,6 +67,7 @@ import io.github.moulberry.notenoughupdates.miscfeatures.WitherCloakChanger; import io.github.moulberry.notenoughupdates.miscfeatures.customblockzones.CustomBiomes; import io.github.moulberry.notenoughupdates.miscfeatures.customblockzones.CustomBlockSounds; import io.github.moulberry.notenoughupdates.miscfeatures.customblockzones.DwarvenMinesTextures; +import io.github.moulberry.notenoughupdates.miscfeatures.inventory.MuseumCheapestItemOverlay; import io.github.moulberry.notenoughupdates.miscfeatures.inventory.MuseumItemHighlighter; import io.github.moulberry.notenoughupdates.miscfeatures.item.enchants.EnchantStyleCustomizer; import io.github.moulberry.notenoughupdates.miscfeatures.updater.AutoUpdater; @@ -207,6 +207,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; } @@ -219,13 +226,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. */ diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/MuseumCheapestItemOverlay.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/MuseumCheapestItemOverlay.kt deleted file mode 100644 index aebdf602..00000000 --- a/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/MuseumCheapestItemOverlay.kt +++ /dev/null @@ -1,284 +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.miscfeatures - -import io.github.moulberry.notenoughupdates.NEUManager -import io.github.moulberry.notenoughupdates.NotEnoughUpdates -import io.github.moulberry.notenoughupdates.core.util.ArrowPagesUtils -import io.github.moulberry.notenoughupdates.mixins.AccessorGuiContainer -import io.github.moulberry.notenoughupdates.util.ItemResolutionQuery -import io.github.moulberry.notenoughupdates.util.Utils -import io.github.moulberry.notenoughupdates.util.stripControlCodes -import net.minecraft.client.Minecraft -import net.minecraft.client.gui.GuiScreen -import net.minecraft.client.gui.inventory.GuiChest -import net.minecraft.client.renderer.GlStateManager -import net.minecraft.init.Items -import net.minecraft.inventory.Slot -import net.minecraft.item.ItemDye -import net.minecraft.util.EnumChatFormatting -import net.minecraft.util.ResourceLocation -import net.minecraftforge.client.event.GuiScreenEvent -import net.minecraftforge.client.event.GuiScreenEvent.BackgroundDrawnEvent -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent -import org.lwjgl.input.Mouse -import org.lwjgl.opengl.GL11 - - -object MuseumCheapestItemOverlay { - data class MuseumItem( - var name: String, - var internalNames: List, - var value: Double, - var priceRefreshedAt: Long - ) - - private val backgroundResource: ResourceLocation by lazy { - ResourceLocation("notenoughupdates:dungeon_chest_worth.png") - } - - private const val ITEMS_PER_PAGE = 8 - private var topLeft = intArrayOf(237, 110) - private var currentPage: Int = 0 - private var previousSlots: List = emptyList() - private var itemsToDonate: MutableList = emptyList().toMutableList() - - //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 - "Special Items" to true, - "Weapons" to false, - "Armor Sets" to false, - "Rarities" to false - ) - - @SubscribeEvent - fun onDrawBackground(event: BackgroundDrawnEvent) { - if (!shouldRender(event.gui)) return - val chest = event.gui as GuiChest - - val slots = chest.inventorySlots.inventorySlots - if (!slots.equals(previousSlots)) { - checkIfHighestPageWasVisited(slots) - parseItems(slots) - updateOutdatedValues() - sortByValue() - } - 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) - } - - @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 } - } - - - private fun sortByValue() { - itemsToDonate.sortBy { it.value } - } - - private fun updateOutdatedValues() { - val time = System.currentTimeMillis() - itemsToDonate.filter { time - it.priceRefreshedAt >= 60000 } - .forEach { - it.value = calculateValue(it.internalNames) - it.priceRefreshedAt = time - } - } - - private fun calculateValue(internalNames: List): Double { - var totalValue = 0.0 - internalNames.forEach { - val itemValue: Double = - when (NotEnoughUpdates.INSTANCE.config.miscOverlays.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 - } - - - private fun drawLines(guiLeft: Int, guiTop: Int) { - //render - val lines = buildLines() - lines.forEachIndexed { index, line -> - if (index == ITEMS_PER_PAGE && !visitedAllPages()) { - Minecraft.getMinecraft().fontRendererObj.drawStringWithShadow( - "${EnumChatFormatting.RED}Visit all pages for accurate info!", - (guiLeft + 185).toFloat(), - (guiTop + 85).toFloat(), - 0 - ) - } else { - Utils.renderAlignedString( - "${EnumChatFormatting.RESET}${line.name}", - if (line.value == Double.MAX_VALUE) "${EnumChatFormatting.RED}Unknown" else "${EnumChatFormatting.AQUA}${ - Utils.shortNumberFormat( - line.value, - 0 - ) - }", - (guiLeft + 187).toFloat(), - (guiTop + 5 + (index * 10)).toFloat(), - 160 - ) - } - } - - ArrowPagesUtils.onDraw(guiLeft, guiTop, topLeft, currentPage, totalPages()) - return - } - - private fun buildLines(): List { - val list = emptyList().toMutableList() - for (i in (if (currentPage == 0) ITEMS_PER_PAGE else ITEMS_PER_PAGE + 1) * (currentPage)..(if (currentPage == 0) ITEMS_PER_PAGE else ITEMS_PER_PAGE + 1) * currentPage + ITEMS_PER_PAGE) { - if (i >= itemsToDonate.size) { - break - } - list.add(itemsToDonate[i]) - } - return list - } - - - private fun parseItems(slots: List) { - //iterate upper chest with 56 slots - val time = System.currentTimeMillis() - for (i in 0..53) { - val stack = slots[i].stack ?: continue - //check for gray dye which indicates that the item has not been donated - if (stack.item is ItemDye && stack.itemDamage == 8) { - val name = stack.displayName.stripControlCodes() - val armor = Utils.getOpenChestName().endsWith("Armor Sets") - val internalNames = guessInternalNames(name, armor) - val value = calculateValue(internalNames) - - val displayName = if (armor) { - "${EnumChatFormatting.BLUE}$name" - } else { - NotEnoughUpdates.INSTANCE.manager.getDisplayName(internalNames[0]) ?: "ERROR" - } - - //make sure this item does not already exist - if (itemsToDonate.none { it.internalNames == internalNames }) { - itemsToDonate.add(MuseumItem(displayName, internalNames, value, time)) - } - } - } - } - - 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 - } - } - - - private fun guessInternalNames(itemName: String, armor: Boolean): List { - return if (armor) { - val mustHaves = arrayOf( - "HELMET", - "LEGGINGS", - "CHESTPLATE", - "BOOTS" - ) - val monochromeName = NEUManager.cleanForTitleMapSearch(itemName) - val candidates = monochromeName.split(" ") - .asSequence() - .mapNotNull { NotEnoughUpdates.INSTANCE.manager.titleWordMap[it]?.keys } - .flatten() - .filter { - val item = NotEnoughUpdates.INSTANCE.manager.createItem(it) - val name = NEUManager.cleanForTitleMapSearch(item.displayName) - monochromeName.replace("armor", "") in name - }.filter { item -> - mustHaves.any { - item.contains(it) - } - } - //filter out duplicates - .toSet() - .toList() - - return candidates - } else { - listOf(ItemResolutionQuery.getInternalNameByDisplayName(itemName)) - } - } - - - 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.toFloat() + xSize + 4, - guiTop.toFloat(), - 180F, - 101F, - 0F, - 180 / 256F, - 0F, - 101 / 256F, - GL11.GL_NEAREST - ) - } - - private fun shouldRender(gui: GuiScreen): Boolean = - NotEnoughUpdates.INSTANCE.config.miscOverlays.museumCheapestItemOverlay && gui is GuiChest && Utils.getOpenChestName() - .startsWith("Museum ➜") - - private fun getCategory(): String = Utils.getOpenChestName().substring(9, Utils.getOpenChestName().length) - - private fun visitedAllPages(): Boolean = !checkedPages.containsValue(false) - - private fun totalPages(): Int = when (itemsToDonate.size % ITEMS_PER_PAGE) { - 0 -> itemsToDonate.size / ITEMS_PER_PAGE - else -> (itemsToDonate.size / ITEMS_PER_PAGE) + 1 - } -} 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..140c9d1f --- /dev/null +++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/inventory/MuseumCheapestItemOverlay.kt @@ -0,0 +1,284 @@ +/* + * 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.miscfeatures.inventory + +import io.github.moulberry.notenoughupdates.NEUManager +import io.github.moulberry.notenoughupdates.NotEnoughUpdates +import io.github.moulberry.notenoughupdates.core.util.ArrowPagesUtils +import io.github.moulberry.notenoughupdates.mixins.AccessorGuiContainer +import io.github.moulberry.notenoughupdates.util.ItemResolutionQuery +import io.github.moulberry.notenoughupdates.util.Utils +import io.github.moulberry.notenoughupdates.util.stripControlCodes +import net.minecraft.client.Minecraft +import net.minecraft.client.gui.GuiScreen +import net.minecraft.client.gui.inventory.GuiChest +import net.minecraft.client.renderer.GlStateManager +import net.minecraft.init.Items +import net.minecraft.inventory.Slot +import net.minecraft.item.ItemDye +import net.minecraft.util.EnumChatFormatting +import net.minecraft.util.ResourceLocation +import net.minecraftforge.client.event.GuiScreenEvent +import net.minecraftforge.client.event.GuiScreenEvent.BackgroundDrawnEvent +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import org.lwjgl.input.Mouse +import org.lwjgl.opengl.GL11 + + +object MuseumCheapestItemOverlay { + data class MuseumItem( + var name: String, + var internalNames: List, + var value: Double, + var priceRefreshedAt: Long + ) + + private val backgroundResource: ResourceLocation by lazy { + ResourceLocation("notenoughupdates:dungeon_chest_worth.png") + } + + private const val ITEMS_PER_PAGE = 8 + private var topLeft = intArrayOf(237, 110) + private var currentPage: Int = 0 + private var previousSlots: List = emptyList() + private var itemsToDonate: MutableList = emptyList().toMutableList() + + //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 + "Special Items" to true, + "Weapons" to false, + "Armor Sets" to false, + "Rarities" to false + ) + + @SubscribeEvent + fun onDrawBackground(event: BackgroundDrawnEvent) { + if (!shouldRender(event.gui)) return + val chest = event.gui as GuiChest + + val slots = chest.inventorySlots.inventorySlots + if (!slots.equals(previousSlots)) { + checkIfHighestPageWasVisited(slots) + parseItems(slots) + updateOutdatedValues() + sortByValue() + } + 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) + } + + @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 } + } + + + private fun sortByValue() { + itemsToDonate.sortBy { it.value } + } + + private fun updateOutdatedValues() { + val time = System.currentTimeMillis() + itemsToDonate.filter { time - it.priceRefreshedAt >= 60000 } + .forEach { + it.value = calculateValue(it.internalNames) + it.priceRefreshedAt = time + } + } + + private fun calculateValue(internalNames: List): Double { + var totalValue = 0.0 + internalNames.forEach { + val itemValue: Double = + when (NotEnoughUpdates.INSTANCE.config.miscOverlays.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 + } + + + private fun drawLines(guiLeft: Int, guiTop: Int) { + //render + val lines = buildLines() + lines.forEachIndexed { index, line -> + if (index == ITEMS_PER_PAGE && !visitedAllPages()) { + Minecraft.getMinecraft().fontRendererObj.drawStringWithShadow( + "${EnumChatFormatting.RED}Visit all pages for accurate info!", + (guiLeft + 185).toFloat(), + (guiTop + 85).toFloat(), + 0 + ) + } else { + Utils.renderAlignedString( + "${EnumChatFormatting.RESET}${line.name}", + if (line.value == Double.MAX_VALUE) "${EnumChatFormatting.RED}Unknown" else "${EnumChatFormatting.AQUA}${ + Utils.shortNumberFormat( + line.value, + 0 + ) + }", + (guiLeft + 187).toFloat(), + (guiTop + 5 + (index * 10)).toFloat(), + 160 + ) + } + } + + ArrowPagesUtils.onDraw(guiLeft, guiTop, topLeft, currentPage, totalPages()) + return + } + + private fun buildLines(): List { + val list = emptyList().toMutableList() + for (i in (if (currentPage == 0) ITEMS_PER_PAGE else ITEMS_PER_PAGE + 1) * (currentPage)..(if (currentPage == 0) ITEMS_PER_PAGE else ITEMS_PER_PAGE + 1) * currentPage + ITEMS_PER_PAGE) { + if (i >= itemsToDonate.size) { + break + } + list.add(itemsToDonate[i]) + } + return list + } + + + private fun parseItems(slots: List) { + //iterate upper chest with 56 slots + val time = System.currentTimeMillis() + for (i in 0..53) { + val stack = slots[i].stack ?: continue + //check for gray dye which indicates that the item has not been donated + if (stack.item is ItemDye && stack.itemDamage == 8) { + val name = stack.displayName.stripControlCodes() + val armor = Utils.getOpenChestName().endsWith("Armor Sets") + val internalNames = guessInternalNames(name, armor) + val value = calculateValue(internalNames) + + val displayName = if (armor) { + "${EnumChatFormatting.BLUE}$name" + } else { + NotEnoughUpdates.INSTANCE.manager.getDisplayName(internalNames[0]) ?: "ERROR" + } + + //make sure this item does not already exist + if (itemsToDonate.none { it.internalNames == internalNames }) { + itemsToDonate.add(MuseumItem(displayName, internalNames, value, time)) + } + } + } + } + + 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 + } + } + + + private fun guessInternalNames(itemName: String, armor: Boolean): List { + return if (armor) { + val mustHaves = arrayOf( + "HELMET", + "LEGGINGS", + "CHESTPLATE", + "BOOTS" + ) + val monochromeName = NEUManager.cleanForTitleMapSearch(itemName) + val candidates = monochromeName.split(" ") + .asSequence() + .mapNotNull { NotEnoughUpdates.INSTANCE.manager.titleWordMap[it]?.keys } + .flatten() + .filter { + val item = NotEnoughUpdates.INSTANCE.manager.createItem(it) + val name = NEUManager.cleanForTitleMapSearch(item.displayName) + monochromeName.replace("armor", "") in name + }.filter { item -> + mustHaves.any { + item.contains(it) + } + } + //filter out duplicates + .toSet() + .toList() + + return candidates + } else { + listOf(ItemResolutionQuery.getInternalNameByDisplayName(itemName)) + } + } + + + 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.toFloat() + xSize + 4, + guiTop.toFloat(), + 180F, + 101F, + 0F, + 180 / 256F, + 0F, + 101 / 256F, + GL11.GL_NEAREST + ) + } + + private fun shouldRender(gui: GuiScreen): Boolean = + NotEnoughUpdates.INSTANCE.config.miscOverlays.museumCheapestItemOverlay && gui is GuiChest && Utils.getOpenChestName() + .startsWith("Museum ➜") + + private fun getCategory(): String = Utils.getOpenChestName().substring(9, Utils.getOpenChestName().length) + + private fun visitedAllPages(): Boolean = !checkedPages.containsValue(false) + + private fun totalPages(): Int = when (itemsToDonate.size % ITEMS_PER_PAGE) { + 0 -> itemsToDonate.size / ITEMS_PER_PAGE + else -> (itemsToDonate.size / ITEMS_PER_PAGE) + 1 + } +} -- cgit