aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/utils
diff options
context:
space:
mode:
authorCalMWolfs <94038482+CalMWolfs@users.noreply.github.com>2023-06-17 22:38:50 +1000
committerGitHub <noreply@github.com>2023-06-17 14:38:50 +0200
commit1e38bdc596e99830c1f04a5aef75db2b7e6a8caa (patch)
tree3ada783d3c0d7ca985db95458d8caa28a86df337 /src/main/java/at/hannibal2/skyhanni/utils
parentdf6acc5bd8bfdf70180cf746a6649fd349374916 (diff)
downloadskyhanni-1e38bdc596e99830c1f04a5aef75db2b7e6a8caa.tar.gz
skyhanni-1e38bdc596e99830c1f04a5aef75db2b7e6a8caa.tar.bz2
skyhanni-1e38bdc596e99830c1f04a5aef75db2b7e6a8caa.zip
v2 for fortune guide (#188)
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/utils')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/GuiRenderUtils.kt47
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt16
2 files changed, 57 insertions, 6 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/GuiRenderUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/GuiRenderUtils.kt
index a4dbede9d..6d9a4f94f 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/GuiRenderUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/GuiRenderUtils.kt
@@ -1,7 +1,6 @@
package at.hannibal2.skyhanni.utils
import at.hannibal2.skyhanni.features.garden.fortuneguide.FFGuideGUI
-import at.hannibal2.skyhanni.utils.LorenzUtils.round
import net.minecraft.client.Minecraft
import net.minecraft.client.gui.FontRenderer
import net.minecraft.client.gui.GuiScreen
@@ -31,6 +30,39 @@ object GuiRenderUtils {
Minecraft.getMinecraft().fontRendererObj.drawString(str, x, y, 0xffffff, true)
}
+ fun drawString(str: String, x: Int, y: Int) {
+ Minecraft.getMinecraft().fontRendererObj.drawString(str, x.toFloat(), y.toFloat(), 0xffffff, true)
+ }
+
+ fun drawTwoLineString(str: String, x: Float, y: Float) {
+ val desiredSplitIndex = str.length / 2
+ var splitIndex = -1
+ var lastColorCode = ""
+
+ for (i in desiredSplitIndex downTo 0) {
+ if (str[i] == ' ') {
+ splitIndex = i
+ break
+ }
+ }
+
+ if (splitIndex == -1) {
+ splitIndex = desiredSplitIndex
+ }
+ for (i in 0 until desiredSplitIndex) {
+ if (str[i] == '§' && i + 1 < str.length) {
+ lastColorCode = str.substring(i, i + 2)
+ }
+ }
+
+ val firstString = str.substring(0, splitIndex).trim()
+ val secondString = lastColorCode + str.substring(splitIndex).trim()
+
+ Minecraft.getMinecraft().fontRendererObj.drawString(firstString, x, y - 5, 0xffffff, true)
+ Minecraft.getMinecraft().fontRendererObj.drawString(secondString, x, y + 5, 0xffffff, true)
+
+ }
+
fun drawStringCentered(str: String?, x: Int, y: Int) {
drawStringCentered(
str,
@@ -141,6 +173,10 @@ object GuiRenderUtils {
}
}
+ fun renderItemAndTip(item: ItemStack?, x: Float, y: Float, mouseX: Float, mouseY: Float, color: Int = 0xFF43464B.toInt()) {
+ renderItemAndTip(item, x.toInt(), y.toInt(), mouseX.toInt(), mouseY.toInt(), color)
+ }
+
// assuming 70% font size
fun drawFarmingBar(
label: String,
@@ -167,17 +203,17 @@ object GuiRenderUtils {
}
val filledWidth = (width * barProgress).toInt()
- val current = DecimalFormat("0.##").format(currentVal.round(2))
+ val current = DecimalFormat("0.##").format(currentVal)
val progressPercentage = (barProgress * 10000).roundToInt() / 100
val inverseScale = 1 / textScale
val textWidth: Int = Minecraft.getMinecraft().fontRendererObj.getStringWidth("$progressPercentage%")
val barColor = barColorGradient(barProgress)
- GlStateManager.scale(textScale, textScale, textScale)
+ GlStateManager.scale(textScale, textScale, 1f)
drawString(label, xPos * inverseScale, yPos * inverseScale)
- drawString("§2$current / $maxValue☘", xPos * inverseScale, (yPos + 8) * inverseScale)
+ drawString("§2$current / ${DecimalFormat("0.#").format(maxValue)}☘", xPos * inverseScale, (yPos + 8) * inverseScale)
drawString("§2$progressPercentage%", (xPos + width - textWidth * textScale) * inverseScale, (yPos + 8) * inverseScale)
- GlStateManager.scale(inverseScale, inverseScale, inverseScale)
+ GlStateManager.scale(inverseScale, inverseScale, 1f)
GuiScreen.drawRect(xPos, yPos + 16, xPos + width, yPos + 20, 0xFF43464B.toInt())
GuiScreen.drawRect(xPos + 1, yPos + 17, xPos + width - 1, yPos + 19, barColor.darkenColor())
@@ -204,5 +240,4 @@ object GuiRenderUtils {
val color = Color(this)
return Color(color.red / 5, color.green / 5, color.blue / 5).rgb
}
-
} \ No newline at end of file
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt
index f36f9a60c..e9adfe055 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt
@@ -135,6 +135,22 @@ object ItemUtils {
.getTagList("textures", Constants.NBT.TAG_COMPOUND).getCompoundTagAt(0).getString("Value")
}
+ fun ItemStack.getItemRarity(): Int {
+ //todo make into an enum in future
+ return when (this.getLore().lastOrNull()?.take(4)) {
+ "§f§l" -> 0 // common
+ "§a§l" -> 1 // uncommon
+ "§9§l" -> 2 // rare
+ "§5§l" -> 3 // epic
+ "§6§l" -> 4 // legendary
+ "§d§l" -> 5 // mythic
+ "§b§l" -> 6 // divine
+ "§4§l" -> 7 // supreme
+ "§c§l" -> 8 // special/very special
+ else -> -1 // unknown
+ }
+ }
+
//extra method for shorter name and kotlin nullability logic
var ItemStack.name: String?
get() = this.displayName