aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorLulonaut <lulonaut@tutanota.de>2022-12-28 16:33:37 +0100
committerLulonaut <lulonaut@tutanota.de>2022-12-28 16:33:37 +0100
commit33bef42b9159f865acb0a34886195334ed922634 (patch)
treeb25dc0425c0f8ee55e437eda59e8c2937422a891 /src/main
parentd17ec9b2b2d1ad8dae4633b08e740bf878301189 (diff)
downloadNotEnoughUpdates-33bef42b9159f865acb0a34886195334ed922634.tar.gz
NotEnoughUpdates-33bef42b9159f865acb0a34886195334ed922634.tar.bz2
NotEnoughUpdates-33bef42b9159f865acb0a34886195334ed922634.zip
add option for craft cost
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java4
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Misc.java36
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/MiscOverlays.java41
-rw-r--r--src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/MuseumCheapestItemOverlay.kt79
-rw-r--r--src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/inventory/MuseumItemHighlighter.kt4
5 files changed, 99 insertions, 65 deletions
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 f936ceb1..63a58fb1 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java
@@ -241,8 +241,8 @@ public class NEUConfig extends Config {
@Expose
@Category(
- name = "Todo Overlay",
- desc = "Todo Overlay"
+ name = "Misc Overlays",
+ desc = "Miscellaneous 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 29edb314..3a7d0b81 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
@@ -24,7 +24,6 @@ import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigAccord
import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigEditorAccordion;
import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigEditorBoolean;
import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigEditorButton;
-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.ConfigEditorKeybind;
import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigEditorSlider;
@@ -295,39 +294,4 @@ public class Misc {
)
@ConfigEditorBoolean
public boolean abiphoneFavourites = true;
-
- @ConfigOption(
- name = "Museum Overlay",
- desc = ""
- )
- @ConfigEditorAccordion(id = 2)
- public boolean museumAccordion = false;
-
- @ConfigOption(
- name = "Show Museum Items",
- desc = "Show real items instead of green dye in the museum"
- )
- @ConfigAccordionId(id = 2)
- @ConfigEditorBoolean
- @Expose
- public boolean museumItemShow = true;
-
- @ConfigOption(
- name = "Highlight the virtual museum items",
- desc = "Highlight virtual museum items"
- )
- @ConfigAccordionId(id = 2)
- @ConfigEditorColour
- @Expose
- public String museumItemColor = "0:255:0:255:0";
-
- @Expose
- @ConfigOption(
- name = "Enable Overlay",
- desc = "Show the cheapest items you have not yet donated to the Museum"
- )
- @ConfigEditorBoolean
- @ConfigAccordionId(id = 2)
- public boolean museumCheapestItemOverlay = true;
-
}
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/MiscOverlays.java b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/MiscOverlays.java
index bb713041..f6710514 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/MiscOverlays.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/MiscOverlays.java
@@ -24,6 +24,7 @@ import io.github.moulberry.notenoughupdates.core.config.Position;
import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigAccordionId;
import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigEditorAccordion;
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.ConfigEditorDraggableList;
import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigEditorDropdown;
import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigOption;
@@ -436,5 +437,43 @@ public class MiscOverlays {
desc = ""
)
@ConfigEditorAccordion(id = 1)
- public boolean museumOverlay = true;
+ public boolean museumAccordion = true;
+
+ @Expose
+ @ConfigOption(
+ name = "Show Museum Items",
+ desc = "Show real items instead of green dye in the museum"
+ )
+ @ConfigAccordionId(id = 1)
+ @ConfigEditorBoolean
+ public boolean museumItemShow = true;
+
+ @Expose
+ @ConfigOption(
+ name = "Highlight virtual museum items",
+ desc = "Highlight virtual museum items with a background color"
+ )
+ @ConfigAccordionId(id = 1)
+ @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
+ @ConfigAccordionId(id = 1)
+ public boolean museumCheapestItemOverlay = true;
+
+ @Expose
+ @ConfigOption(
+ name = "Value calculation",
+ desc = "Choose the source for the value calculation"
+ )
+ @ConfigEditorDropdown(
+ values = {"Lowest BIN", "Craft cost"}
+ )
+ @ConfigAccordionId(id = 1)
+ public int museumCheapestItemOverlayValueSource = 0;
}
diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/MuseumCheapestItemOverlay.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/MuseumCheapestItemOverlay.kt
index 6cd102c9..aebdf602 100644
--- a/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/MuseumCheapestItemOverlay.kt
+++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/MuseumCheapestItemOverlay.kt
@@ -37,14 +37,18 @@ 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.client.event.GuiScreenEvent.KeyboardInputEvent
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 value: Double, var priceRefreshedAt: Long)
+ data class MuseumItem(
+ var name: String,
+ var internalNames: List<String>,
+ var value: Double,
+ var priceRefreshedAt: Long
+ )
private val backgroundResource: ResourceLocation by lazy {
ResourceLocation("notenoughupdates:dungeon_chest_worth.png")
@@ -72,9 +76,10 @@ object MuseumCheapestItemOverlay {
val slots = chest.inventorySlots.inventorySlots
if (!slots.equals(previousSlots)) {
- parseItems(slots)
checkIfHighestPageWasVisited(slots)
- sortByPrice()
+ parseItems(slots)
+ updateOutdatedValues()
+ sortByValue()
}
previousSlots = slots
@@ -98,10 +103,42 @@ object MuseumCheapestItemOverlay {
}
- private fun sortByPrice() {
+ 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<String>): 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
@@ -116,7 +153,7 @@ object MuseumCheapestItemOverlay {
)
} else {
Utils.renderAlignedString(
- "${EnumChatFormatting.RESET}${EnumChatFormatting.BLUE}${line.name}",
+ "${EnumChatFormatting.RESET}${line.name}",
if (line.value == Double.MAX_VALUE) "${EnumChatFormatting.RED}Unknown" else "${EnumChatFormatting.AQUA}${
Utils.shortNumberFormat(
line.value,
@@ -136,7 +173,7 @@ object MuseumCheapestItemOverlay {
private fun buildLines(): List<MuseumItem> {
val list = emptyList<MuseumItem>().toMutableList()
- for (i in ITEMS_PER_PAGE * currentPage..ITEMS_PER_PAGE * currentPage + ITEMS_PER_PAGE) {
+ 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
}
@@ -154,25 +191,19 @@ object MuseumCheapestItemOverlay {
//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 internalNames = guessInternalNames(name, Utils.getOpenChestName().endsWith("Armor Sets"))
-// println("$name resolves to ${internalNames.toString()}")
- var totalValue = 0.0
- internalNames.forEach {
- val itemValue = NotEnoughUpdates.INSTANCE.manager.auctionManager.getBazaarOrBin(it, false)
- if (itemValue == -1.0 || itemValue == 0.0) {
- totalValue = Double.MAX_VALUE
- return@forEach
- } else {
- totalValue += itemValue
- }
- }
- if (totalValue == 0.0) {
- totalValue = Double.MAX_VALUE
+ 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.name == name }) {
- itemsToDonate.add(MuseumItem(name, totalValue, time))
+ if (itemsToDonate.none { it.internalNames == internalNames }) {
+ itemsToDonate.add(MuseumItem(displayName, internalNames, value, time))
}
}
}
@@ -239,7 +270,7 @@ object MuseumCheapestItemOverlay {
}
private fun shouldRender(gui: GuiScreen): Boolean =
- NotEnoughUpdates.INSTANCE.config.misc.museumCheapestItemOverlay && gui is GuiChest && Utils.getOpenChestName()
+ NotEnoughUpdates.INSTANCE.config.miscOverlays.museumCheapestItemOverlay && gui is GuiChest && Utils.getOpenChestName()
.startsWith("Museum ➜")
private fun getCategory(): String = Utils.getOpenChestName().substring(9, Utils.getOpenChestName().length)
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
index 68810db1..63b88094 100644
--- a/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/inventory/MuseumItemHighlighter.kt
+++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/inventory/MuseumItemHighlighter.kt
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2022 Linnea Gräf
+ * Copyright (C) 2022 NotEnoughUpdates contributors
*
* This file is part of NotEnoughUpdates.
*
@@ -40,7 +40,7 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
object MuseumItemHighlighter {
val manager get() = NotEnoughUpdates.INSTANCE.manager
- val config get() = NotEnoughUpdates.INSTANCE.config.misc
+ val config get() = NotEnoughUpdates.INSTANCE.config.miscOverlays
fun getHighlightColor() = ChromaColour.specialToChromaRGB(config.museumItemColor)