aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/utils
diff options
context:
space:
mode:
authorCalMWolfs <94038482+CalMWolfs@users.noreply.github.com>2024-09-23 23:54:16 +1000
committerGitHub <noreply@github.com>2024-09-23 15:54:16 +0200
commitd39f595b150aaa0eee32c7ebacb961ef48095924 (patch)
tree03725f81d7090e880df9ae7038e6e40307a2e341 /src/main/java/at/hannibal2/skyhanni/utils
parent74490dcdb619e6eadf1be7665871cdaba4d58ee8 (diff)
downloadskyhanni-d39f595b150aaa0eee32c7ebacb961ef48095924.tar.gz
skyhanni-d39f595b150aaa0eee32c7ebacb961ef48095924.tar.bz2
skyhanni-d39f595b150aaa0eee32c7ebacb961ef48095924.zip
Backend: Remove more neu code from SkyHanni (#2419)
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/utils')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/GuiRenderUtils.kt132
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt56
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt3
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt28
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/SkyBlockItemModifierUtils.kt3
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/json/JsonUtils.kt18
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/json/Shimmy.kt64
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt27
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/renderables/RenderableTooltips.kt5
9 files changed, 255 insertions, 81 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/GuiRenderUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/GuiRenderUtils.kt
index 75eb5087e..ba1081a5f 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/GuiRenderUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/GuiRenderUtils.kt
@@ -7,16 +7,17 @@ import at.hannibal2.skyhanni.utils.LorenzUtils.round
import at.hannibal2.skyhanni.utils.NumberUtil.fractionOf
import at.hannibal2.skyhanni.utils.RenderUtils.HorizontalAlignment
import at.hannibal2.skyhanni.utils.renderables.Renderable
-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.ScaledResolution
import net.minecraft.client.renderer.GlStateManager
import net.minecraft.client.renderer.RenderHelper
import net.minecraft.client.renderer.Tessellator
import net.minecraft.client.renderer.vertex.DefaultVertexFormats
import net.minecraft.item.ItemStack
import org.lwjgl.opengl.GL11
+import org.lwjgl.opengl.GL14
import java.awt.Color
import java.text.DecimalFormat
import kotlin.math.ceil
@@ -75,7 +76,7 @@ object GuiRenderUtils {
fun drawStringCentered(str: String?, x: Int, y: Int) {
drawStringCentered(
- str, Minecraft.getMinecraft().fontRendererObj, x.toFloat(), y.toFloat(), true, 0xffffff
+ str, Minecraft.getMinecraft().fontRendererObj, x.toFloat(), y.toFloat(), true, 0xffffff,
)
}
@@ -125,25 +126,25 @@ object GuiRenderUtils {
if (tooltipY + tooltipHeight + 6 > screenHeight) tooltipY = screenHeight - tooltipHeight - 6
// main background
GuiScreen.drawRect(
- tooltipX - 3, tooltipY - 3, tooltipX + tooltipTextWidth + 3, tooltipY + tooltipHeight + 3, -0xfeffff0
+ tooltipX - 3, tooltipY - 3, tooltipX + tooltipTextWidth + 3, tooltipY + tooltipHeight + 3, -0xfeffff0,
)
// borders
GuiScreen.drawRect(
- tooltipX - 3, tooltipY - 3 + 1, tooltipX - 3 + 1, tooltipY + tooltipHeight + 3 - 1, borderColor
+ tooltipX - 3, tooltipY - 3 + 1, tooltipX - 3 + 1, tooltipY + tooltipHeight + 3 - 1, borderColor,
- )
+ )
GuiScreen.drawRect(
tooltipX + tooltipTextWidth + 2,
tooltipY - 3 + 1,
tooltipX + tooltipTextWidth + 3,
tooltipY + tooltipHeight + 3 - 1,
- borderColor
+ borderColor,
)
GuiScreen.drawRect(
- tooltipX - 3, tooltipY - 3, tooltipX + tooltipTextWidth + 3, tooltipY - 3 + 1, borderColor
+ tooltipX - 3, tooltipY - 3, tooltipX + tooltipTextWidth + 3, tooltipY - 3 + 1, borderColor,
)
GuiScreen.drawRect(
@@ -151,7 +152,7 @@ object GuiRenderUtils {
tooltipY + tooltipHeight + 2,
tooltipX + tooltipTextWidth + 3,
tooltipY + tooltipHeight + 3,
- borderColor
+ borderColor,
)
GlStateManager.translate(0f, 0f, -100f)
GlStateManager.disableDepth()
@@ -188,27 +189,33 @@ object GuiRenderUtils {
val current = currentValue.toDouble().coerceAtLeast(0.0)
val percent = current.fractionOf(maxValue)
val scale = textScale.toDouble()
- return Renderable.hoverTips(Renderable.verticalContainer(
- listOf(
- Renderable.string(label, scale = scale),
- Renderable.fixedSizeLine(
- listOf(
- Renderable.string(
- "§2${DecimalFormat("0.##").format(current)} / ${
- DecimalFormat(
- "0.##"
- ).format(maxValue)
- }☘", scale = scale, horizontalAlign = HorizontalAlignment.LEFT
+ return Renderable.hoverTips(
+ Renderable.verticalContainer(
+ listOf(
+ Renderable.string(label, scale = scale),
+ Renderable.fixedSizeLine(
+ listOf(
+ Renderable.string(
+ "§2${DecimalFormat("0.##").format(current)} / ${
+ DecimalFormat(
+ "0.##",
+ ).format(maxValue)
+ }☘",
+ scale = scale, horizontalAlign = HorizontalAlignment.LEFT,
+ ),
+ Renderable.string(
+ "§2${(percent * 100).round(1)}%",
+ scale = scale,
+ horizontalAlign = HorizontalAlignment.RIGHT,
+ ),
),
- Renderable.string(
- "§2${(percent * 100).round(1)}%",
- scale = scale,
- horizontalAlign = HorizontalAlignment.RIGHT
- ),
- ), width
- ), Renderable.progressBar(percent, width = width)
- )
- ), tooltip.split('\n').map { Renderable.string(it) })
+ width,
+ ),
+ Renderable.progressBar(percent, width = width),
+ ),
+ ),
+ tooltip.split('\n').map { Renderable.string(it) },
+ )
}
private fun barColorGradient(double: Double): Int {
@@ -265,16 +272,14 @@ object GuiRenderUtils {
Color.LIGHT_GRAY.darker().red / 255f,
Color.LIGHT_GRAY.darker().green / 255f,
Color.LIGHT_GRAY.darker().blue / 255f,
- 1f
+ 1f,
)
} else {
GlStateManager.color(color.darker().red / 255f, color.darker().green / 255f, color.darker().blue / 255f, 1f)
}
- Utils.drawTexturedRect(x, y, w_2.toFloat(), height, 0f, w_2 / xSize, vMinEmpty, vMaxEmpty, GL11.GL_NEAREST)
- Utils.drawTexturedRect(
- x + w_2, y, w_2.toFloat(), height, 1 - w_2 / xSize, 1f, vMinEmpty, vMaxEmpty, GL11.GL_NEAREST
- )
+ drawTexturedRect(x, y, w_2.toFloat(), height, 0f, w_2 / xSize, vMinEmpty, vMaxEmpty, GL11.GL_NEAREST)
+ drawTexturedRect(x + w_2, y, w_2.toFloat(), height, 1 - w_2 / xSize, 1f, vMinEmpty, vMaxEmpty, GL11.GL_NEAREST)
if (useChroma) {
GlStateManager.color(Color.WHITE.red / 255f, Color.WHITE.green / 255f, Color.WHITE.blue / 255f, 1f)
@@ -285,9 +290,9 @@ object GuiRenderUtils {
if (k > 0) {
val uMax = w_2.toDouble().coerceAtMost(k.toDouble() / xSize).toFloat()
val width = w_2.coerceAtMost(k).toFloat()
- Utils.drawTexturedRect(x, y, width, height, 0f, uMax, vMinFilled, vMaxFilled, GL11.GL_NEAREST)
+ drawTexturedRect(x, y, width, height, 0f, uMax, vMinFilled, vMaxFilled, GL11.GL_NEAREST)
if (completed > 0.5f) {
- Utils.drawTexturedRect(
+ drawTexturedRect(
x + w_2,
y,
(k - w_2).toFloat(),
@@ -296,7 +301,7 @@ object GuiRenderUtils {
1 + (k - w) / xSize,
vMinFilled,
vMaxFilled,
- GL11.GL_NEAREST
+ GL11.GL_NEAREST,
)
}
}
@@ -342,4 +347,59 @@ object GuiRenderUtils {
GlStateManager.enableAlpha()
GlStateManager.enableTexture2D()
}
+
+ fun drawTexturedRect(x: Float, y: Float) {
+ with(ScaledResolution(Minecraft.getMinecraft())) {
+ drawTexturedRect(x, y, scaledWidth.toFloat(), scaledHeight.toFloat(), filter = GL11.GL_NEAREST)
+ }
+ }
+
+ fun drawTexturedRect(
+ x: Int,
+ y: Int,
+ width: Int,
+ height: Int,
+ uMin: Float = 0f,
+ uMax: Float = 1f,
+ vMin: Float = 0f,
+ vMax: Float = 1f,
+ filter: Int = GL11.GL_NEAREST,
+ ) {
+ drawTexturedRect(x.toFloat(), y.toFloat(), width.toFloat(), height.toFloat(), uMin, uMax, vMin, vMax, filter)
+ }
+
+ // Taken from NEU
+ fun drawTexturedRect(
+ x: Float,
+ y: Float,
+ width: Float,
+ height: Float,
+ uMin: Float = 0f,
+ uMax: Float = 1f,
+ vMin: Float = 0f,
+ vMax: Float = 1f,
+ filter: Int = GL11.GL_NEAREST,
+ ) {
+ GlStateManager.enableTexture2D()
+ GlStateManager.enableBlend()
+ GlStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA)
+ GL14.glBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA)
+
+ GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, filter)
+ GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, filter)
+
+ val tessellator = Tessellator.getInstance()
+ val worldRenderer = tessellator.worldRenderer
+ worldRenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX)
+ worldRenderer.pos(x.toDouble(), (y + height).toDouble(), 0.0).tex(uMin.toDouble(), vMax.toDouble()).endVertex()
+ worldRenderer.pos((x + width).toDouble(), (y + height).toDouble(), 0.0).tex(uMax.toDouble(), vMax.toDouble()).endVertex()
+ worldRenderer.pos((x + width).toDouble(), y.toDouble(), 0.0).tex(uMax.toDouble(), vMin.toDouble()).endVertex()
+ worldRenderer.pos(x.toDouble(), y.toDouble(), 0.0).tex(uMin.toDouble(), vMin.toDouble()).endVertex()
+ tessellator.draw()
+
+ GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST)
+ GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST)
+
+ GlStateManager.disableBlend()
+ }
}
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt
index ac35c0741..add66cc0a 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt
@@ -22,6 +22,7 @@ import com.google.common.collect.Lists
import io.github.moulberry.notenoughupdates.util.NotificationHandler
import net.minecraft.client.Minecraft
import net.minecraft.init.Items
+import net.minecraft.item.Item
import net.minecraft.item.ItemStack
import net.minecraft.nbt.NBTTagCompound
import net.minecraft.nbt.NBTTagList
@@ -43,9 +44,11 @@ object ItemUtils {
fun isSack(stack: ItemStack) = stack.getInternalName().endsWith("_SACK") && stack.cleanName().endsWith(" Sack")
- fun ItemStack.getLore(): List<String> {
- val tagCompound = this.tagCompound ?: return emptyList()
- val tagList = tagCompound.getCompoundTag("display").getTagList("Lore", 8)
+ fun ItemStack.getLore(): List<String> = this.tagCompound.getLore()
+
+ fun NBTTagCompound?.getLore(): List<String> {
+ this ?: return emptyList()
+ val tagList = this.getCompoundTag("display").getTagList("Lore", 8)
val list: MutableList<String> = ArrayList()
for (i in 0 until tagList.tagCount()) {
list.add(tagList.getStringTagAt(i))
@@ -53,6 +56,13 @@ object ItemUtils {
return list
}
+ fun getDisplayName(compound: NBTTagCompound?): String? {
+ compound ?: return null
+ val name = compound.getCompoundTag("display").getString("Name")
+ if (name == null || name.isEmpty()) return null
+ return name
+ }
+
fun ItemStack.setLore(lore: List<String>): ItemStack {
val tagCompound = this.tagCompound ?: NBTTagCompound()
val display = tagCompound.getCompoundTag("display")
@@ -67,12 +77,14 @@ object ItemUtils {
}
var ItemStack.extraAttributes: NBTTagCompound
- get() = this.tagCompound?.getCompoundTag("ExtraAttributes") ?: NBTTagCompound()
+ get() = this.tagCompound?.extraAttributes ?: NBTTagCompound()
set(value) {
val tag = this.tagCompound ?: NBTTagCompound().also { tagCompound = it }
tag.setTag("ExtraAttributes", value)
}
+ val NBTTagCompound.extraAttributes: NBTTagCompound get() = this.getCompoundTag("ExtraAttributes")
+
fun ItemStack.overrideId(id: String): ItemStack {
extraAttributes = extraAttributes.apply { setString("id", id) }
return this
@@ -183,6 +195,20 @@ object ItemUtils {
return render
}
+ fun createItemStack(item: Item, displayName: String, vararg lore: String): ItemStack {
+ return createItemStack(item, displayName, lore.toList())
+ }
+
+ // Taken from NEU
+ fun createItemStack(item: Item, displayName: String, lore: List<String>, amount: Int = 1, damage: Int = 0): ItemStack {
+ val stack = ItemStack(item, amount, damage)
+ val tag = NBTTagCompound()
+ addNameAndLore(tag, displayName, *lore.toTypedArray())
+ tag.setInteger("HideFlags", 254)
+ stack.tagCompound = tag
+ return stack
+ }
+
// Taken from NEU
private fun addNameAndLore(tag: NBTTagCompound, displayName: String, vararg lore: String) {
val display = NBTTagCompound()
@@ -315,6 +341,28 @@ object ItemUtils {
setStackDisplayName(value)
}
+ // Taken from NEU
+ fun ItemStack.editItemInfo(displayName: String, disableNeuTooltips: Boolean, lore: List<String>): ItemStack {
+ val tag = this.tagCompound ?: NBTTagCompound()
+ val display = tag.getCompoundTag("display")
+ val loreList = NBTTagList()
+ for (line in lore) {
+ loreList.appendTag(NBTTagString(line))
+ }
+
+ display.setString("Name", displayName)
+ display.setTag("Lore", loreList)
+
+ tag.setTag("display", display)
+ tag.setInteger("HideFlags", 254)
+ if (disableNeuTooltips) {
+ tag.setBoolean("disableNeuTooltip", true)
+ }
+
+ this.tagCompound = tag
+ return this
+ }
+
fun isSkyBlockMenuItem(stack: ItemStack?): Boolean = stack?.getInternalName()?.equals("SKYBLOCK_MENU") ?: false
private val itemAmountCache = mutableMapOf<String, Pair<String, Int>>()
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt b/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt
index 34d491cee..198b43a85 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt
@@ -31,7 +31,6 @@ import io.github.moulberry.notenoughupdates.events.ProfileDataLoadedEvent
import io.github.moulberry.notenoughupdates.overlays.AuctionSearchOverlay
import io.github.moulberry.notenoughupdates.overlays.BazaarSearchOverlay
import io.github.moulberry.notenoughupdates.util.ItemResolutionQuery
-import io.github.moulberry.notenoughupdates.util.Utils
import net.minecraft.client.Minecraft
import net.minecraft.client.renderer.GLAllocation
import net.minecraft.client.renderer.GlStateManager
@@ -97,7 +96,7 @@ object NEUItems {
val ignoreItemsFilter = MultiFilter()
private val fallbackItem by lazy {
- Utils.createItemStack(
+ ItemUtils.createItemStack(
ItemStack(Blocks.barrier).item,
"§cMissing Repo Item",
"§cYour NEU repo seems to be out of date",
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt
index 08532e0c4..609ccebae 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt
@@ -19,11 +19,11 @@ import at.hannibal2.skyhanni.utils.CollectionUtils.zipWithNext3
import at.hannibal2.skyhanni.utils.ColorUtils.getFirstColorCode
import at.hannibal2.skyhanni.utils.LorenzColor.Companion.toLorenzColor
import at.hannibal2.skyhanni.utils.LorenzUtils.getCorners
+import at.hannibal2.skyhanni.utils.compat.GuiScreenUtils
import at.hannibal2.skyhanni.utils.renderables.Renderable
import at.hannibal2.skyhanni.utils.renderables.RenderableUtils.renderXAligned
import at.hannibal2.skyhanni.utils.renderables.RenderableUtils.renderYAligned
import at.hannibal2.skyhanni.utils.shader.ShaderManager
-import io.github.moulberry.notenoughupdates.util.Utils
import io.github.notenoughupdates.moulconfig.internal.TextRenderUtils
import net.minecraft.client.Minecraft
import net.minecraft.client.gui.FontRenderer
@@ -41,6 +41,7 @@ import net.minecraft.item.ItemStack
import net.minecraft.util.AxisAlignedBB
import net.minecraft.util.MathHelper
import net.minecraft.util.ResourceLocation
+import org.lwjgl.input.Mouse
import org.lwjgl.opengl.GL11
import java.awt.Color
import java.nio.FloatBuffer
@@ -95,6 +96,15 @@ object RenderUtils {
highlight(color, x, y)
}
+ fun getMouseX(): Int {
+ return Mouse.getX() * GuiScreenUtils.scaledWindowWidth / Minecraft.getMinecraft().displayWidth
+ }
+
+ fun getMouseY(): Int {
+ val height = GuiScreenUtils.scaledWindowHeight
+ return height - Mouse.getY() * height / Minecraft.getMinecraft().displayHeight - 1
+ }
+
fun highlight(color: Color, x: Int, y: Int) {
GlStateManager.disableLighting()
GlStateManager.disableDepth()
@@ -504,8 +514,8 @@ object RenderUtils {
fun Position.transform(): Pair<Int, Int> {
GlStateManager.translate(getAbsX().toFloat(), getAbsY().toFloat(), 0F)
GlStateManager.scale(effectiveScale, effectiveScale, 1F)
- val x = ((Utils.getMouseX() - getAbsX()) / effectiveScale).toInt()
- val y = ((Utils.getMouseY() - getAbsY()) / effectiveScale).toInt()
+ val x = ((getMouseX() - getAbsX()) / effectiveScale).toInt()
+ val y = ((getMouseY() - getAbsY()) / effectiveScale).toInt()
return x to y
}
@@ -1712,7 +1722,7 @@ object RenderUtils {
fun drawRoundTexturedRect(x: Int, y: Int, width: Int, height: Int, filter: Int, radius: Int = 10, smoothness: Int = 1) {
// if radius is 0 then just draw a normal textured rect
if (radius <= 0) {
- Utils.drawTexturedRect(x.toFloat(), y.toFloat(), width.toFloat(), height.toFloat(), filter)
+ GuiRenderUtils.drawTexturedRect(x, y, width, height, filter = filter)
return
}
@@ -1731,7 +1741,7 @@ object RenderUtils {
GlStateManager.pushMatrix()
ShaderManager.enableShader(ShaderManager.Shaders.ROUNDED_TEXTURE)
- Utils.drawTexturedRect(x.toFloat(), y.toFloat(), width.toFloat(), height.toFloat(), filter)
+ GuiRenderUtils.drawTexturedRect(x, y, width, height, filter = filter)
ShaderManager.disableShader()
GlStateManager.popMatrix()
@@ -1832,6 +1842,7 @@ object RenderUtils {
GlStateManager.popMatrix()
}
+ // todo merge with the one in GuiRenderUtils
fun drawGradientRect(
left: Int,
top: Int,
@@ -1871,13 +1882,6 @@ object RenderUtils {
GlStateManager.enableTexture2D()
}
- // TODO move off of neu function
- fun drawTexturedRect(x: Float, y: Float) {
- with(ScaledResolution(Minecraft.getMinecraft())) {
- Utils.drawTexturedRect(x, y, scaledWidth.toFloat(), scaledHeight.toFloat(), GL11.GL_NEAREST)
- }
- }
-
fun getAlpha(): Float {
colorBuffer.clear()
GlStateManager.getFloat(GL11.GL_CURRENT_COLOR, colorBuffer)
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/SkyBlockItemModifierUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/SkyBlockItemModifierUtils.kt
index 4d0cf4468..128b5d11e 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/SkyBlockItemModifierUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/SkyBlockItemModifierUtils.kt
@@ -3,6 +3,7 @@ package at.hannibal2.skyhanni.utils
import at.hannibal2.skyhanni.config.ConfigManager
import at.hannibal2.skyhanni.data.PetAPI
import at.hannibal2.skyhanni.mixins.hooks.ItemStackCachedData
+import at.hannibal2.skyhanni.utils.ItemUtils.extraAttributes
import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName
import at.hannibal2.skyhanni.utils.ItemUtils.getLore
import at.hannibal2.skyhanni.utils.ItemUtils.name
@@ -272,7 +273,7 @@ object SkyBlockItemModifierUtils {
private fun ItemStack.getAttributeByte(label: String) =
getExtraAttributes()?.getByte(label) ?: 0
- fun ItemStack.getExtraAttributes() = tagCompound?.getCompoundTag("ExtraAttributes")
+ fun ItemStack.getExtraAttributes() = tagCompound?.extraAttributes
class GemstoneSlot(val type: GemstoneType, val quality: GemstoneQuality) {
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/json/JsonUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/json/JsonUtils.kt
index 750bd96aa..ed4a5fbe6 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/json/JsonUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/json/JsonUtils.kt
@@ -1,9 +1,11 @@
package at.hannibal2.skyhanni.utils.json
+import at.hannibal2.skyhanni.config.ConfigManager
import com.google.gson.Gson
import com.google.gson.JsonArray
import com.google.gson.JsonElement
import com.google.gson.JsonObject
+import java.io.File
import java.io.Reader
import kotlin.reflect.jvm.javaType
import kotlin.reflect.typeOf
@@ -15,6 +17,16 @@ inline fun <reified T : Any> Gson.fromJson(jsonElement: JsonElement): T =
inline fun <reified T : Any> Gson.fromJson(reader: Reader): T = this.fromJson(reader, typeOf<T>().javaType)
+fun File.getJson(): JsonObject? {
+ return try {
+ this.inputStream().use {
+ ConfigManager.gson.fromJson(it.reader(), JsonObject::class.java)
+ }
+ } catch (e: Exception) {
+ null
+ }
+}
+
/**
* Straight forward deep copy. This is included in gson as well, but different versions have it exposed privately instead of publicly,
* so this reimplementation is here as an always public alternative.
@@ -35,3 +47,9 @@ fun JsonElement.shDeepCopy(): JsonElement {
else -> this
}
}
+
+fun Iterable<JsonElement>.toJsonArray(): JsonArray = JsonArray().also {
+ for (jsonElement in this) {
+ it.add(jsonElement)
+ }
+}
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/json/Shimmy.kt b/src/main/java/at/hannibal2/skyhanni/utils/json/Shimmy.kt
new file mode 100644
index 000000000..31022da58
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/utils/json/Shimmy.kt
@@ -0,0 +1,64 @@
+package at.hannibal2.skyhanni.utils.json
+
+import at.hannibal2.skyhanni.config.ConfigManager
+import com.google.gson.JsonElement
+import java.lang.reflect.Field
+
+// Copied from NEU
+class Shimmy private constructor(
+ val source: Any,
+ val field: Field,
+) {
+ companion object {
+ private fun shimmy(source: Any?, fieldName: String): Any? {
+ if (source == null) return null
+ return try {
+ val declaredField = source.javaClass.getDeclaredField(fieldName)
+ declaredField.isAccessible = true
+ declaredField.get(source)
+ } catch (e: NoSuchFieldException) {
+ null
+ }
+ }
+
+ @JvmStatic
+ fun makeShimmy(source: Any?, path: List<String>): Shimmy? {
+ if (path.isEmpty())
+ return null
+ var source = source
+ for (part in path.dropLast(1)) {
+ source = shimmy(source, part)
+ }
+ if (source == null) return null
+ val lastName = path.last()
+ return try {
+ val field = source.javaClass.getDeclaredField(lastName)
+ field.isAccessible = true
+ Shimmy(
+ source,
+ field,
+ )
+ } catch (e: NoSuchFieldException) {
+ null
+ }
+ }
+
+ }
+
+ val clazz: Class<*> = field.type
+ fun get(): Any? {
+ return field.get(source)
+ }
+
+ fun set(value: Any?) {
+ field.set(source, value)
+ }
+
+ fun getJson(): JsonElement {
+ return ConfigManager.gson.toJsonTree(get())
+ }
+
+ fun setJson(element: JsonElement) {
+ set(ConfigManager.gson.fromJson(element, clazz))
+ }
+}
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt b/src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt
index d161cf2b0..f3f704f37 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt
@@ -14,6 +14,7 @@ import at.hannibal2.skyhanni.utils.CollectionUtils.contains
import at.hannibal2.skyhanni.utils.ColorUtils
import at.hannibal2.skyhanni.utils.ColorUtils.addAlpha
import at.hannibal2.skyhanni.utils.ColorUtils.darker
+import at.hannibal2.skyhanni.utils.GuiRenderUtils
import at.hannibal2.skyhanni.utils.KeyboardManager.isKeyClicked
import at.hannibal2.skyhanni.utils.LorenzColor
import at.hannibal2.skyhanni.utils.LorenzLogger
@@ -29,7 +30,6 @@ import at.hannibal2.skyhanni.utils.renderables.RenderableUtils.renderXAligned
import at.hannibal2.skyhanni.utils.renderables.RenderableUtils.renderXYAligned
import at.hannibal2.skyhanni.utils.renderables.RenderableUtils.renderYAligned
import at.hannibal2.skyhanni.utils.shader.ShaderManager
-import io.github.moulberry.notenoughupdates.util.Utils
import io.github.notenoughupdates.moulconfig.gui.GuiScreenElementWrapper
import net.minecraft.client.Minecraft
import net.minecraft.client.gui.Gui
@@ -1272,18 +1272,9 @@ interface Renderable {
override fun render(posX: Int, posY: Int) {
Minecraft.getMinecraft().textureManager.bindTexture(texture)
+
GlStateManager.color(1f, 1f, 1f, alpha / 255f)
- Utils.drawTexturedRect(
- 0f,
- 0f,
- width.toFloat(),
- height.toFloat(),
- uMin,
- uMax,
- vMin,
- vMax,
- GL11.GL_NEAREST,
- )
+ GuiRenderUtils.drawTexturedRect(0, 0, width, height, uMin, uMax, vMin, vMax)
GlStateManager.color(1f, 1f, 1f, 1f)
GlStateManager.translate(padding.toFloat(), padding.toFloat(), 0f)
@@ -1312,17 +1303,7 @@ interface Renderable {
override fun render(posX: Int, posY: Int) {
Minecraft.getMinecraft().textureManager.bindTexture(texture)
GlStateManager.color(1f, 1f, 1f, alpha / 255f)
- Utils.drawTexturedRect(
- 0f,
- 0f,
- width.toFloat(),
- height.toFloat(),
- uMin,
- uMax,
- vMin,
- vMax,
- GL11.GL_NEAREST,
- )
+ GuiRenderUtils.drawTexturedRect(0, 0, width, height, uMin, uMax, vMin, vMax)
GlStateManager.color(1f, 1f, 1f, 1f)
}
}
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/renderables/RenderableTooltips.kt b/src/main/java/at/hannibal2/skyhanni/utils/renderables/RenderableTooltips.kt
index b37c89bb5..b6c4225ba 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/renderables/RenderableTooltips.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/renderables/RenderableTooltips.kt
@@ -5,7 +5,6 @@ import at.hannibal2.skyhanni.utils.ItemUtils.getLore
import at.hannibal2.skyhanni.utils.LorenzColor
import at.hannibal2.skyhanni.utils.RenderUtils
import at.hannibal2.skyhanni.utils.renderables.RenderableUtils.renderXAligned
-import io.github.moulberry.notenoughupdates.util.Utils
import net.minecraft.client.Minecraft
import net.minecraft.client.gui.ScaledResolution
import net.minecraft.client.renderer.GlStateManager
@@ -44,8 +43,8 @@ object RenderableTooltips {
val tips = tooltip.tips
if (tips.isEmpty()) return
- val x = Utils.getMouseX() + 12
- val y = Utils.getMouseY() - if (tips.size > 1) 1 else -7
+ val x = RenderUtils.getMouseX() + 12
+ val y = RenderUtils.getMouseY() - if (tips.size > 1) 1 else -7
val borderColorStart = tooltip.getBorderColor()
val scaled = ScaledResolution(Minecraft.getMinecraft())
val isSpacedTitle = tooltip.isSpacedTitle()