aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal002@users.noreply.github.com>2024-04-07 14:23:06 +0200
committerGitHub <noreply@github.com>2024-04-07 14:23:06 +0200
commitd3cd3c4ff4c51a8f047d396fb5edbb7cf523ca84 (patch)
tree2fec2b35a50cea15ea7da188549cc3fd21b8ee82 /src/main
parentfcd404d862b4b051474898076fcc06b406d1ea91 (diff)
downloadskyhanni-d3cd3c4ff4c51a8f047d396fb5edbb7cf523ca84.tar.gz
skyhanni-d3cd3c4ff4c51a8f047d396fb5edbb7cf523ca84.tar.bz2
skyhanni-d3cd3c4ff4c51a8f047d396fb5edbb7cf523ca84.zip
Improvement: fillTable now uses Renderable.table (#1376)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/AnitaMedalProfit.kt28
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/inventory/SkyMartCopperPrice.kt17
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt23
3 files changed, 36 insertions, 32 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/AnitaMedalProfit.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/AnitaMedalProfit.kt
index 84ca5b235..497932ae4 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/AnitaMedalProfit.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/AnitaMedalProfit.kt
@@ -6,7 +6,6 @@ import at.hannibal2.skyhanni.events.InventoryCloseEvent
import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent
import at.hannibal2.skyhanni.features.garden.visitor.VisitorAPI
import at.hannibal2.skyhanni.test.command.ErrorManager
-import at.hannibal2.skyhanni.utils.CollectionUtils.addAsSingletonList
import at.hannibal2.skyhanni.utils.DisplayTableEntry
import at.hannibal2.skyhanni.utils.InventoryUtils
import at.hannibal2.skyhanni.utils.ItemUtils
@@ -14,20 +13,21 @@ import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName
import at.hannibal2.skyhanni.utils.ItemUtils.getLore
import at.hannibal2.skyhanni.utils.ItemUtils.itemName
import at.hannibal2.skyhanni.utils.ItemUtils.name
-import at.hannibal2.skyhanni.utils.LorenzUtils.fillTable
+import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.NEUInternalName
import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName
import at.hannibal2.skyhanni.utils.NEUItems.getPrice
import at.hannibal2.skyhanni.utils.NumberUtil
-import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems
+import at.hannibal2.skyhanni.utils.RenderUtils.renderRenderables
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
+import at.hannibal2.skyhanni.utils.renderables.Renderable
import net.minecraft.item.ItemStack
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
class AnitaMedalProfit {
private val config get() = GardenAPI.config.anitaShop
- private var display = emptyList<List<Any>>()
+ private var display = emptyList<Renderable>()
companion object {
@@ -70,9 +70,9 @@ class AnitaMedalProfit {
}
}
- val newList = mutableListOf<List<Any>>()
- newList.addAsSingletonList("§eMedal Profit")
- newList.fillTable(table)
+ val newList = mutableListOf<Renderable>()
+ newList.add(Renderable.string("§eMedal Profit"))
+ newList.add(LorenzUtils.fillTable(table, padding = 5, itemScale = 1.7))
display = newList
}
@@ -108,7 +108,16 @@ class AnitaMedalProfit {
"§7Material cost: §6${NumberUtil.format(fullCost)} ",
"§7Final profit: §6${profitFormat} ",
)
- table.add(DisplayTableEntry(itemName, "$color$profitFormat", profit, internalName, hover, highlightsOnHoverSlots = listOf(slot)))
+ table.add(
+ DisplayTableEntry(
+ itemName,
+ "$color$profitFormat",
+ profit,
+ internalName,
+ hover,
+ highlightsOnHoverSlots = listOf(slot)
+ )
+ )
}
private fun getItemName(item: ItemStack): String? {
@@ -167,10 +176,9 @@ class AnitaMedalProfit {
@SubscribeEvent
fun onBackgroundDraw(event: GuiRenderEvent.ChestGuiOverlayRenderEvent) {
if (inInventory) {
- config.medalProfitPos.renderStringsAndItems(
+ config.medalProfitPos.renderRenderables(
display,
extraSpace = 5,
- itemScale = 1.7,
posLabel = "Anita Medal Profit"
)
}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/SkyMartCopperPrice.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/SkyMartCopperPrice.kt
index 9e5ec780c..29623653b 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/SkyMartCopperPrice.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/SkyMartCopperPrice.kt
@@ -5,20 +5,20 @@ import at.hannibal2.skyhanni.events.GuiRenderEvent
import at.hannibal2.skyhanni.events.InventoryCloseEvent
import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent
import at.hannibal2.skyhanni.features.garden.GardenAPI
-import at.hannibal2.skyhanni.utils.CollectionUtils.addAsSingletonList
import at.hannibal2.skyhanni.utils.DisplayTableEntry
import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName
import at.hannibal2.skyhanni.utils.ItemUtils.getLore
import at.hannibal2.skyhanni.utils.ItemUtils.itemName
-import at.hannibal2.skyhanni.utils.LorenzUtils.fillTable
+import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.NEUInternalName
import at.hannibal2.skyhanni.utils.NEUItems.getPrice
import at.hannibal2.skyhanni.utils.NEUItems.getPriceOrNull
import at.hannibal2.skyhanni.utils.NumberUtil
import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators
import at.hannibal2.skyhanni.utils.NumberUtil.formatInt
-import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems
+import at.hannibal2.skyhanni.utils.RenderUtils.renderRenderables
import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
+import at.hannibal2.skyhanni.utils.renderables.Renderable
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
import net.minecraft.item.ItemStack
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
@@ -30,7 +30,7 @@ class SkyMartCopperPrice {
"§c(?<amount>.*) Copper"
)
- private var display = emptyList<List<Any>>()
+ private var display = emptyList<Renderable>()
private val config get() = GardenAPI.config.skyMart
companion object {
@@ -97,9 +97,9 @@ class SkyMartCopperPrice {
}
}
- val newList = mutableListOf<List<Any>>()
- newList.addAsSingletonList("§eCoins per Copper§f:")
- newList.fillTable(table)
+ val newList = mutableListOf<Renderable>()
+ newList.add(Renderable.string("§eCoins per Copper§f:"))
+ newList.add(LorenzUtils.fillTable(table, padding = 5, itemScale = config.itemScale))
display = newList
}
@@ -111,10 +111,9 @@ class SkyMartCopperPrice {
@SubscribeEvent
fun onBackgroundDraw(event: GuiRenderEvent.ChestGuiOverlayRenderEvent) {
if (inInventory) {
- config.copperPricePos.renderStringsAndItems(
+ config.copperPricePos.renderRenderables(
display,
extraSpace = 5,
- itemScale = config.itemScale,
posLabel = "SkyMart Copper Price"
)
}
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt
index ef98c1264..77c776043 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt
@@ -170,26 +170,23 @@ object LorenzUtils {
fun getPlayerName(): String = Minecraft.getMinecraft().thePlayer.name
- fun MutableList<List<Any>>.fillTable(data: List<DisplayTableEntry>) {
+ fun fillTable(data: List<DisplayTableEntry>, padding: Int = 1, itemScale: Double = 1.0): Renderable {
val sorted = data.sortedByDescending { it.sort }
- val renderer = Minecraft.getMinecraft().fontRendererObj
- val longest = sorted.maxOfOrNull { renderer.getStringWidth(it.left.removeColor()) } ?: 0
+ val outerList = mutableListOf<List<Renderable>>()
for (entry in sorted) {
- var displayName = entry.left
- while (renderer.getStringWidth(displayName.removeColor()) < longest) {
- displayName += " "
- }
-
- val renderable = Renderable.hoverTips(
- "$displayName ${entry.right}",
+ val item = entry.item.getItemStackOrNull()?.let {
+ Renderable.itemStack(it, scale = itemScale)
+ } ?: continue
+ val left = Renderable.hoverTips(
+ entry.left,
tips = entry.hover,
highlightsOnHoverSlots = entry.highlightsOnHoverSlots
)
- entry.item.getItemStackOrNull()?.let {
- add(listOf(it, renderable))
- }
+ val right = Renderable.string(entry.right)
+ outerList.add(listOf(item, left, right))
}
+ return Renderable.table(outerList, xPadding = 5, yPadding = padding)
}
fun setTextIntoSign(text: String, line: Int = 0) {