aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/utils
diff options
context:
space:
mode:
authorCalMWolfs <94038482+CalMWolfs@users.noreply.github.com>2023-10-14 21:45:26 +1100
committerGitHub <noreply@github.com>2023-10-14 12:45:26 +0200
commit7a634386ec4dd842e946bd3ba331c0d565faf173 (patch)
tree558cc86b80b6e1af0d2a8ba857324b1d72ed774b /src/main/java/at/hannibal2/skyhanni/utils
parent16ef943b3c2ce8db2331332261143a12bdba61cf (diff)
downloadskyhanni-7a634386ec4dd842e946bd3ba331c0d565faf173.tar.gz
skyhanni-7a634386ec4dd842e946bd3ba331c0d565faf173.tar.bz2
skyhanni-7a634386ec4dd842e946bd3ba331c0d565faf173.zip
Feature: Modify Visual Words (#492)
Added /shwords. #492
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/utils')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/GuiRenderUtils.kt25
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt46
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt4
3 files changed, 69 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 e250511a5..1269ec005 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/GuiRenderUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/GuiRenderUtils.kt
@@ -1,6 +1,5 @@
package at.hannibal2.skyhanni.utils
-import at.hannibal2.skyhanni.features.garden.fortuneguide.FFGuideGUI
import net.minecraft.client.Minecraft
import net.minecraft.client.gui.FontRenderer
import net.minecraft.client.gui.GuiScreen
@@ -13,7 +12,7 @@ import java.text.DecimalFormat
import kotlin.math.roundToInt
/**
- * Taken from NotEnoughUpdates
+ * Some functions taken from NotEnoughUpdates
*/
object GuiRenderUtils {
@@ -60,7 +59,6 @@ object GuiRenderUtils {
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) {
@@ -74,6 +72,10 @@ object GuiRenderUtils {
)
}
+ fun drawStringCentered(str: String?, x: Float, y: Float) {
+ drawStringCentered(str, x.toInt(), y.toInt())
+ }
+
fun renderItemStack(item: ItemStack, x: Int, y: Int) {
val itemRender = Minecraft.getMinecraft().renderItem
RenderHelper.enableGUIStandardItemLighting()
@@ -179,18 +181,19 @@ object GuiRenderUtils {
)
}
- fun renderItemAndTip(item: ItemStack?, x: Int, y: Int, mouseX: Int, mouseY: Int, color: Int = 0xFF43464B.toInt()) {
+ fun renderItemAndTip(list: MutableList<String>, item: ItemStack?, x: Int, y: Int, mouseX: Int, mouseY: Int, color: Int = 0xFF43464B.toInt()) {
GuiScreen.drawRect(x, y, x + 16, y + 16, color)
if (item != null) {
renderItemStack(item, x, y)
if (isPointInRect(mouseX, mouseY, x, y, 16, 16)) {
val tt: List<String> = item.getTooltip(Minecraft.getMinecraft().thePlayer, false)
- FFGuideGUI.tooltipToDisplay.addAll(tt)
+ list.addAll(tt)
}
}
}
fun renderItemAndTip(
+ list: MutableList<String>,
item: ItemStack?,
x: Float,
y: Float,
@@ -198,7 +201,7 @@ object GuiRenderUtils {
mouseY: Float,
color: Int = 0xFF43464B.toInt()
) {
- renderItemAndTip(item, x.toInt(), y.toInt(), mouseX.toInt(), mouseY.toInt(), color)
+ renderItemAndTip(list, item, x.toInt(), y.toInt(), mouseX.toInt(), mouseY.toInt(), color)
}
// assuming 70% font size
@@ -272,4 +275,14 @@ object GuiRenderUtils {
val color = Color(this)
return Color(color.red / 5, color.green / 5, color.blue / 5).rgb
}
+
+ fun drawScaledRec(left: Int, top: Int, right: Int, bottom: Int, colour: Int, inverseScale: Float) {
+ GuiScreen.drawRect((left * inverseScale).toInt(), (top * inverseScale).toInt(),
+ (right * inverseScale).toInt(), (bottom * inverseScale).toInt(), colour)
+ }
+
+ fun renderItemAndBackground(item: ItemStack, x: Int, y: Int, colour: Int) {
+ renderItemStack(item, x, y)
+ GuiScreen.drawRect(x, y, x + 16, y + 16, colour)
+ }
} \ 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 e00aadf42..06e7108d9 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt
@@ -13,6 +13,9 @@ import com.google.gson.JsonObject
import net.minecraft.client.Minecraft
import net.minecraft.init.Items
import net.minecraft.item.ItemStack
+import net.minecraft.nbt.NBTTagCompound
+import net.minecraft.nbt.NBTTagList
+import net.minecraft.nbt.NBTTagString
import net.minecraftforge.common.util.Constants
import java.util.LinkedList
import kotlin.time.Duration.Companion.seconds
@@ -146,6 +149,49 @@ object ItemUtils {
return nbt.getCompoundTag("SkullOwner").getString("Id")
}
+ // Taken from NEU
+ fun createSkull(displayName: String, uuid: String, value: String): ItemStack {
+ return createSkull(displayName, uuid, value, null)
+ }
+
+ // Taken from NEU
+ fun createSkull(displayName: String, uuid: String, value: String, lore: Array<String>?): ItemStack {
+ val render = ItemStack(Items.skull, 1, 3)
+ val tag = NBTTagCompound()
+ val skullOwner = NBTTagCompound()
+ val properties = NBTTagCompound()
+ val textures = NBTTagList()
+ val textures0 = NBTTagCompound()
+
+ skullOwner.setString("Id", uuid)
+ skullOwner.setString("Name", uuid)
+ textures0.setString("Value", value)
+
+ textures.appendTag(textures0)
+
+ addNameAndLore(tag, displayName, lore)
+
+ properties.setTag("textures", textures)
+ skullOwner.setTag("Properties", properties)
+ tag.setTag("SkullOwner", skullOwner)
+ render.tagCompound = tag
+ return render
+ }
+
+ // Taken from NEU
+ private fun addNameAndLore(tag: NBTTagCompound, displayName: String, lore: Array<String>?) {
+ val display = NBTTagCompound()
+ display.setString("Name", displayName)
+ if (lore != null) {
+ val tagLore = NBTTagList()
+ for (line in lore) {
+ tagLore.appendTag(NBTTagString(line))
+ }
+ display.setTag("Lore", tagLore)
+ }
+ tag.setTag("display", display)
+ }
+
fun ItemStack.getItemRarityOrCommon() = getItemRarityOrNull() ?: LorenzRarity.COMMON
fun ItemStack.getItemRarityOrNull(logError: Boolean = true): LorenzRarity? {
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt
index 58659daeb..2e0a57c53 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt
@@ -220,4 +220,8 @@ object StringUtils {
if (!matcher.matches()) return null
return matcher.group("username")
}
+
+ fun String.convertToFormatted(): String {
+ return this.replace("&&", "ยง")
+ }
} \ No newline at end of file