aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/lorenz/mod/utils
diff options
context:
space:
mode:
authorLorenz <ESs95s3P5z8Pheb>2022-07-11 23:30:46 +0200
committerLorenz <ESs95s3P5z8Pheb>2022-07-11 23:30:46 +0200
commitddf652388cce1d14dc1a9dc7c44c5b6ccbb9c367 (patch)
treea1df487f4393f3ef8c4356ea1047f19757706e53 /src/main/java/at/lorenz/mod/utils
parentcbd64656802075dd31964853723ad8dac8555062 (diff)
downloadskyhanni-ddf652388cce1d14dc1a9dc7c44c5b6ccbb9c367.tar.gz
skyhanni-ddf652388cce1d14dc1a9dc7c44c5b6ccbb9c367.tar.bz2
skyhanni-ddf652388cce1d14dc1a9dc7c44c5b6ccbb9c367.zip
add action bar event, add item ability cooldown feature
Diffstat (limited to 'src/main/java/at/lorenz/mod/utils')
-rw-r--r--src/main/java/at/lorenz/mod/utils/ItemUtil.kt2
-rw-r--r--src/main/java/at/lorenz/mod/utils/ItemUtils.kt23
-rw-r--r--src/main/java/at/lorenz/mod/utils/LorenzUtils.kt13
3 files changed, 38 insertions, 0 deletions
diff --git a/src/main/java/at/lorenz/mod/utils/ItemUtil.kt b/src/main/java/at/lorenz/mod/utils/ItemUtil.kt
index fc0409e31..341b94ca8 100644
--- a/src/main/java/at/lorenz/mod/utils/ItemUtil.kt
+++ b/src/main/java/at/lorenz/mod/utils/ItemUtil.kt
@@ -208,4 +208,6 @@ object ItemUtil {
})
return this
}
+
+ fun NBTTagList.asStringSet() = (0..tagCount()).mapTo(hashSetOf()) { getStringTagAt(it) }
} \ No newline at end of file
diff --git a/src/main/java/at/lorenz/mod/utils/ItemUtils.kt b/src/main/java/at/lorenz/mod/utils/ItemUtils.kt
index 168b41ddf..6d5bf57da 100644
--- a/src/main/java/at/lorenz/mod/utils/ItemUtils.kt
+++ b/src/main/java/at/lorenz/mod/utils/ItemUtils.kt
@@ -46,4 +46,27 @@ object ItemUtils {
fun maxPetLevel(name: String) = if (name.contains("Golden Dragon")) 200 else 100
+ fun getItemsInInventoryWithSlots(withCursorItem: Boolean = false): Map<ItemStack, Int> {
+ val map: LinkedHashMap<ItemStack, Int> = LinkedHashMap()
+ val player = Minecraft.getMinecraft().thePlayer
+ if (player == null) {
+ LorenzUtils.warning("getItemsInInventoryWithSlots: player is null!")
+ return map
+ }
+ for (slot in player.openContainer.inventorySlots) {
+ if (slot.hasStack) {
+ map[slot.stack] = slot.slotNumber
+ }
+ }
+
+ if (withCursorItem) {
+ if (player.inventory != null) {
+ if (player.inventory.itemStack != null) {
+ map[player.inventory.itemStack] = -1
+ }
+ }
+ }
+
+ return map
+ }
} \ No newline at end of file
diff --git a/src/main/java/at/lorenz/mod/utils/LorenzUtils.kt b/src/main/java/at/lorenz/mod/utils/LorenzUtils.kt
index b36fbb94e..875b41af5 100644
--- a/src/main/java/at/lorenz/mod/utils/LorenzUtils.kt
+++ b/src/main/java/at/lorenz/mod/utils/LorenzUtils.kt
@@ -6,6 +6,7 @@ import net.minecraft.entity.EntityLivingBase
import net.minecraft.entity.SharedMonsterAttributes
import net.minecraft.util.ChatComponentText
import org.intellij.lang.annotations.Language
+import java.text.DecimalFormat
import java.text.SimpleDateFormat
object LorenzUtils {
@@ -114,4 +115,16 @@ object LorenzUtils {
val EntityLivingBase.baseMaxHealth: Double
get() = this.getEntityAttribute(SharedMonsterAttributes.maxHealth).baseValue
+
+ fun formatPercentage(percentage: Double): String = formatPercentage(percentage, "0.00")
+
+ fun formatPercentage(percentage: Double, format: String?): String =
+ DecimalFormat(format).format(percentage * 100).replace(',', '.') + "%"
+
+ fun formatInteger(i: Int): String = DecimalFormat("#,##0").format(i.toLong()).replace(',', '.')
+
+ fun formatDouble(d: Double, format: String?): String =
+ DecimalFormat(format).format(d).replace(',', 'x').replace('.', ',').replace('x', '.')
+
+ fun formatDouble(d: Double): String = formatDouble(d, "#,##0.0")
} \ No newline at end of file