diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-08-08 02:25:22 +0200 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-08-08 02:25:22 +0200 |
commit | 7b6aac3ea8b7aebaef104097b0ac7767b27f4c80 (patch) | |
tree | 7b9e068b912256f1bfccbc717517d17aa62542b8 /src/main/java/at/hannibal2/skyhanni | |
parent | 2ac1f3d037fee016063cd7bc499d4abcfeb765d5 (diff) | |
download | skyhanni-7b6aac3ea8b7aebaef104097b0ac7767b27f4c80.tar.gz skyhanni-7b6aac3ea8b7aebaef104097b0ac7767b27f4c80.tar.bz2 skyhanni-7b6aac3ea8b7aebaef104097b0ac7767b27f4c80.zip |
code cleanup utils
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni')
26 files changed, 163 insertions, 196 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/APIUtil.kt b/src/main/java/at/hannibal2/skyhanni/utils/APIUtil.kt index 6b4bb40f6..04bd67c18 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/APIUtil.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/APIUtil.kt @@ -22,7 +22,7 @@ object APIUtil { private val parser = JsonParser() private var showApiErrors = false - val builder: HttpClientBuilder = + private val builder: HttpClientBuilder = HttpClients.custom().setUserAgent("SkyHanni/${SkyHanniMod.version}") .setDefaultHeaders( mutableListOf( @@ -60,7 +60,10 @@ object APIUtil { e.printStackTrace() } else { - CopyErrorCommand.logError(Error("Hypixel API error for url: '$urlString'", e), "Failed to load data from Hypixel API") + CopyErrorCommand.logError( + Error("Hypixel API error for url: '$urlString'", e), + "Failed to load data from Hypixel API" + ) } } } @@ -69,7 +72,10 @@ object APIUtil { if (silentError) { throw throwable } else { - CopyErrorCommand.logError(Error("Hypixel API error for url: '$urlString'", throwable), "Failed to load data from Hypixel API") + CopyErrorCommand.logError( + Error("Hypixel API error for url: '$urlString'", throwable), + "Failed to load data from Hypixel API" + ) } } finally { client.close() diff --git a/src/main/java/at/hannibal2/skyhanni/utils/BlockUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/BlockUtils.kt index a35d0de06..5a14cadf7 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/BlockUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/BlockUtils.kt @@ -26,7 +26,7 @@ object BlockUtils { .getTagList("textures", Constants.NBT.TAG_COMPOUND).getCompoundTagAt(0).getString("Value") } - fun IBlockState.isBabyCrop(): Boolean { + fun IBlockState.isBabyCrop(): Boolean { for (property in block.blockState.properties) { val name = property.name if (name != "age") continue diff --git a/src/main/java/at/hannibal2/skyhanni/utils/CombatUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/CombatUtils.kt index 8f64a2d6e..3bf5ff2f6 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/CombatUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/CombatUtils.kt @@ -13,7 +13,7 @@ object CombatUtils { var lastUpdate: Long = -1 private var skillInfo: XPInformation.SkillInfo? = null private var skillInfoLast: XPInformation.SkillInfo? = null - private const val skillType = "Combat" + private const val SKILL_TYPE = "Combat" var xpGainHourLast = -1f var xpGainHour = -1f var isKilling = false @@ -33,7 +33,7 @@ object CombatUtils { lastUpdate = System.currentTimeMillis() xpGainHourLast = xpGainHour skillInfoLast = skillInfo - skillInfo = XPInformation.getInstance().getSkillInfo(skillType) ?: return + skillInfo = XPInformation.getInstance().getSkillInfo(SKILL_TYPE) ?: return val totalXp: Float = skillInfo!!.totalXp if (lastTotalXp > 0) { val delta: Float = totalXp - lastTotalXp diff --git a/src/main/java/at/hannibal2/skyhanni/utils/EntityUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/EntityUtils.kt index 68a3d2632..6763dabeb 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/EntityUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/EntityUtils.kt @@ -162,5 +162,5 @@ object EntityUtils { fun getAllEntities(): Sequence<Entity> = Minecraft.getMinecraft()?.theWorld?.loadedEntityList?.let { if (Minecraft.getMinecraft().isCallingFromMinecraftThread) it else it.toMutableList() - }?.asSequence() ?: emptySequence<Entity>() + }?.asSequence() ?: emptySequence() }
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/utils/GuiRenderUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/GuiRenderUtils.kt index 6d9a4f94f..9c9d612f3 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/GuiRenderUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/GuiRenderUtils.kt @@ -49,7 +49,7 @@ object GuiRenderUtils { if (splitIndex == -1) { splitIndex = desiredSplitIndex } - for (i in 0 until desiredSplitIndex) { + for (i in 0 until desiredSplitIndex) { if (str[i] == '§' && i + 1 < str.length) { lastColorCode = str.substring(i, i + 2) } @@ -115,21 +115,32 @@ object GuiRenderUtils { GlStateManager.translate(0f, 0f, 100f) if (tooltipY + tooltipHeight + 6 > screenHeight) tooltipY = screenHeight - tooltipHeight - 6 // main background - GuiScreen.drawRect(tooltipX - 3, tooltipY - 3, - tooltipX + tooltipTextWidth + 3, tooltipY + tooltipHeight + 3, -0xfeffff0) + GuiScreen.drawRect( + 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) - - GuiScreen.drawRect(tooltipX + tooltipTextWidth + 2, tooltipY - 3 + 1, - tooltipX + tooltipTextWidth + 3, tooltipY + tooltipHeight + 3 - 1, borderColor) - - GuiScreen.drawRect(tooltipX - 3, tooltipY - 3, - tooltipX + tooltipTextWidth + 3, tooltipY - 3 + 1, borderColor) - - GuiScreen.drawRect(tooltipX - 3, tooltipY + tooltipHeight + 2, - tooltipX + tooltipTextWidth + 3, tooltipY + tooltipHeight + 3, borderColor) + GuiScreen.drawRect( + 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 + ) + + GuiScreen.drawRect( + tooltipX - 3, tooltipY - 3, + tooltipX + tooltipTextWidth + 3, tooltipY - 3 + 1, borderColor + ) + + GuiScreen.drawRect( + tooltipX - 3, tooltipY + tooltipHeight + 2, + tooltipX + tooltipTextWidth + 3, tooltipY + tooltipHeight + 3, borderColor + ) GlStateManager.translate(0f, 0f, -100f) GlStateManager.disableDepth() @@ -159,7 +170,13 @@ object GuiRenderUtils { GuiScreen.drawRect(x, y, x + barWidth, y + 6, 0xFF43464B.toInt()) val width = barWidth * progress GuiScreen.drawRect(x + 1, y + 1, (x + width).toInt() + 1, y + 5, 0xFF00FF00.toInt()) - if (progress != 1f) GuiScreen.drawRect((x + width).toInt() + 1, y + 1, x + barWidth - 1, y + 5, 0xFF013220.toInt()) + if (progress != 1f) GuiScreen.drawRect( + (x + width).toInt() + 1, + y + 1, + x + barWidth - 1, + y + 5, + 0xFF013220.toInt() + ) } fun renderItemAndTip(item: ItemStack?, x: Int, y: Int, mouseX: Int, mouseY: Int, color: Int = 0xFF43464B.toInt()) { @@ -173,7 +190,14 @@ object GuiRenderUtils { } } - fun renderItemAndTip(item: ItemStack?, x: Float, y: Float, mouseX: Float, mouseY: Float, color: Int = 0xFF43464B.toInt()) { + 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) } @@ -211,14 +235,24 @@ object GuiRenderUtils { GlStateManager.scale(textScale, textScale, 1f) drawString(label, xPos * inverseScale, yPos * inverseScale) - drawString("§2$current / ${DecimalFormat("0.#").format(maxValue)}☘", xPos * inverseScale, (yPos + 8) * inverseScale) - drawString("§2$progressPercentage%", (xPos + width - textWidth * textScale) * 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, 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()) - GuiScreen.drawRect(xPos + 1, yPos + 17, - if (filledWidth < 2) xPos + 1 else xPos + filledWidth - 1, yPos + 19, barColor) + GuiScreen.drawRect( + xPos + 1, yPos + 17, + if (filledWidth < 2) xPos + 1 else xPos + filledWidth - 1, yPos + 19, barColor + ) if (tooltip != "") { if (isPointInRect(mouseX, mouseY, xPos - 2, yPos - 2, width + 4, 20 + 4)) { diff --git a/src/main/java/at/hannibal2/skyhanni/utils/InventoryUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/InventoryUtils.kt index 3f81df1a5..dc36a5b0e 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/InventoryUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/InventoryUtils.kt @@ -43,7 +43,11 @@ object InventoryUtils { fun getArmor(): Array<ItemStack?> = Minecraft.getMinecraft().thePlayer.inventory.armorInventory fun inStorage() = - openInventoryName().let { (it.contains("Storage") && !it.contains("Rift Storage")) || it.contains("Ender Chest") || it.contains("Backpack")} + openInventoryName().let { + (it.contains("Storage") && !it.contains("Rift Storage")) || it.contains("Ender Chest") || it.contains( + "Backpack" + ) + } fun getItemInHand(): ItemStack? = Minecraft.getMinecraft().thePlayer.heldItem }
\ 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 3df9e4673..abbe62057 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt @@ -121,7 +121,7 @@ object ItemUtils { fun ItemStack.getInternalName_new() = NEUInternalName.from(getInternalName()) - fun ItemStack.getInternalName(): String { + fun ItemStack.getInternalName(): String { if (name == "§fWisp's Ice-Flavored Water I Splash Potion") { return "WISP_POTION" } diff --git a/src/main/java/at/hannibal2/skyhanni/utils/IteratorUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/IteratorUtils.kt deleted file mode 100644 index ca55a665f..000000000 --- a/src/main/java/at/hannibal2/skyhanni/utils/IteratorUtils.kt +++ /dev/null @@ -1,14 +0,0 @@ -package at.hannibal2.skyhanni.utils - -object IteratorUtils { - - fun <T> getOnlyElement(it: Iterator<T>, defaultValue: T): T { - if (!it.hasNext()) return defaultValue - val ret = it.next() - return if (it.hasNext()) defaultValue else ret - } - - fun <T> getOnlyElement(it: Iterable<T>, defaultValue: T): T { - return getOnlyElement(it.iterator(), defaultValue) - } -}
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/utils/JsonUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/JsonUtils.kt index 94a162c98..f9a279c46 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/JsonUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/JsonUtils.kt @@ -7,5 +7,8 @@ import kotlin.reflect.jvm.javaType import kotlin.reflect.typeOf inline fun <reified T : Any> Gson.fromJson(string: String): T = this.fromJson(string, typeOf<T>().javaType) -inline fun <reified T : Any> Gson.fromJson(jsonElement: JsonElement): T = this.fromJson(jsonElement, typeOf<T>().javaType) + +inline fun <reified T : Any> Gson.fromJson(jsonElement: JsonElement): T = + this.fromJson(jsonElement, typeOf<T>().javaType) + inline fun <reified T : Any> Gson.fromJson(reader: Reader): T = this.fromJson(reader, typeOf<T>().javaType) diff --git a/src/main/java/at/hannibal2/skyhanni/utils/LorenzLogger.kt b/src/main/java/at/hannibal2/skyhanni/utils/LorenzLogger.kt index b748b8676..0da4c5d80 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/LorenzLogger.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/LorenzLogger.kt @@ -39,7 +39,7 @@ class LorenzLogger(filePath: String) { try { createParent(File(fileName)) val handler = FileHandler(fileName) - handler.encoding ="utf-8" + handler.encoding = "utf-8" logger.addHandler(handler) logger.useParentHandlers = false handler.formatter = object : Formatter() { diff --git a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt index 673d5b70e..9c02fc1cd 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt @@ -14,7 +14,6 @@ import io.github.moulberry.notenoughupdates.mixins.AccessorGuiEditSign import io.github.moulberry.notenoughupdates.util.SkyBlockTime import net.minecraft.client.Minecraft import net.minecraft.client.gui.inventory.GuiEditSign -import net.minecraft.entity.Entity import net.minecraft.entity.EntityLivingBase import net.minecraft.entity.SharedMonsterAttributes import net.minecraft.event.ClickEvent @@ -404,11 +403,9 @@ object LorenzUtils { return new } - @Suppress("UNCHECKED_CAST") fun <K, N : Number> MutableMap<K, N>.sumAllValues(): Double { - if (values.isEmpty()) { - return 0.0 - } + if (values.isEmpty()) return 0.0 + return when (values.first()) { is Double -> values.sumOf { it.toDouble() } is Float -> values.sumOf { it.toDouble() } diff --git a/src/main/java/at/hannibal2/skyhanni/utils/LorenzVec.kt b/src/main/java/at/hannibal2/skyhanni/utils/LorenzVec.kt index 06d1f8c4a..f07ffa83e 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/LorenzVec.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/LorenzVec.kt @@ -92,7 +92,20 @@ data class LorenzVec( fun equalsIgnoreY(other: LorenzVec) = x == other.x && z == other.z - fun equals(other: LorenzVec) = x == other.x && y == other.y && z == other.z + override fun equals(other: Any?): Boolean { + if (this === other) return true + + return (other as? LorenzVec)?.let { + x == it.x && y == it.y && z == it.z + } ?: super.equals(other) + } + + override fun hashCode(): Int { + var result = x.hashCode() + result = 31 * result + y.hashCode() + result = 31 * result + z.hashCode() + return result + } fun round(decimals: Int) = LorenzVec(x.round(decimals), y.round(decimals), z.round(decimals)) @@ -112,7 +125,8 @@ data class LorenzVec( return LorenzVec(x, y, z) } - fun boundingToOffset(offX: Double, offY: Double, offZ: Double) = AxisAlignedBB(x, y, z, x + offX, y + offY, z + offZ) + fun boundingToOffset(offX: Double, offY: Double, offZ: Double) = + AxisAlignedBB(x, y, z, x + offX, y + offY, z + offZ) fun scale(scalar: Double): LorenzVec { return LorenzVec(scalar * x, scalar * y, scalar * z) diff --git a/src/main/java/at/hannibal2/skyhanni/utils/MinecraftConsoleFilter.kt b/src/main/java/at/hannibal2/skyhanni/utils/MinecraftConsoleFilter.kt index 8c653edd7..f929e7e06 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/MinecraftConsoleFilter.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/MinecraftConsoleFilter.kt @@ -143,7 +143,8 @@ class MinecraftConsoleFilter(private val loggerConfigName: String) : Filter { return Filter.Result.DENY } if (firstName == "net.minecraft.scoreboard.Scoreboard.removeObjective(Scoreboard.java:179)" || - firstName == "net.minecraft.scoreboard.Scoreboard.removeObjective(Scoreboard.java:198)") { + firstName == "net.minecraft.scoreboard.Scoreboard.removeObjective(Scoreboard.java:198)" + ) { filterConsole("IllegalArgumentException at Scoreboard.removeObjective") return Filter.Result.DENY } diff --git a/src/main/java/at/hannibal2/skyhanni/utils/MinecraftDispatcher.kt b/src/main/java/at/hannibal2/skyhanni/utils/MinecraftDispatcher.kt index 2ccbf30de..8771de215 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/MinecraftDispatcher.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/MinecraftDispatcher.kt @@ -11,6 +11,7 @@ object MinecraftDispatcher : MainCoroutineDispatcher() { override fun isDispatchNeeded(context: CoroutineContext): Boolean { return !Minecraft.getMinecraft().isCallingFromMinecraftThread } + override fun dispatch(context: CoroutineContext, block: Runnable) { Minecraft.getMinecraft().addScheduledTask(block) } diff --git a/src/main/java/at/hannibal2/skyhanni/utils/NEUInternalName.kt b/src/main/java/at/hannibal2/skyhanni/utils/NEUInternalName.kt index 8e9b8efc2..e57fc1768 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/NEUInternalName.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/NEUInternalName.kt @@ -20,9 +20,9 @@ class NEUInternalName private constructor(private val internalName: String) { return super.equals(other) } - override fun toString(): String { - return "internalName:$internalName" - } + override fun toString(): String = "internalName:$internalName" + + override fun hashCode(): Int = internalName.hashCode() // fun equals(other: String) = internalName == other }
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt b/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt index f22f26112..557048c73 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt @@ -100,7 +100,7 @@ object NEUItems { itemNameCache[itemName] = enchantmentName return enchantmentName } - var internalNameRaw = ItemResolutionQuery.findInternalNameByDisplayName(itemName, false) ?: return null + val internalNameRaw = ItemResolutionQuery.findInternalNameByDisplayName(itemName, false) ?: return null // This fixes a NEU bug with §9Hay Bale (cosmetic item) // TODO remove workaround when this is fixed in neu diff --git a/src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt b/src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt index 6db35d2af..efdb545d2 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt @@ -43,7 +43,7 @@ object NumberUtil { fun format(value: Number): String { @Suppress("NAME_SHADOWING") val value = value.toLong() - //Long.MIN_VALUE == -Long.MIN_VALUE so we need an adjustment here + //Long.MIN_VALUE == -Long.MIN_VALUE, so we need an adjustment here if (value == Long.MIN_VALUE) return format(Long.MIN_VALUE + 1) if (value < 0) return "-" + format(-value) if (value < 1000) return value.toString() //deal with small numbers diff --git a/src/main/java/at/hannibal2/skyhanni/utils/OSUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/OSUtils.kt index c95cdbeb7..63b8e01fb 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/OSUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/OSUtils.kt @@ -50,7 +50,6 @@ object OSUtils { e.printStackTrace() return false } - if (this.isKeyDown || this.isPressed) return true - return false + return this.isKeyDown || this.isPressed } } diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ParkourHelper.kt b/src/main/java/at/hannibal2/skyhanni/utils/ParkourHelper.kt index 6013dec6f..3fe7f6973 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/ParkourHelper.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/ParkourHelper.kt @@ -86,8 +86,7 @@ class ParkourHelper( next.value.offsetCenter(), colorForIndex(prev.index), 5, - false, - colorForIndex(next.index) + false ) } val nextShortcuts = current until current + lookAhead @@ -114,7 +113,7 @@ class ParkourHelper( val aabb = axisAlignedBB(location).expandBlock() event.drawFilledBoundingBox_nea(aabb, colorForIndex(index), .6f) } else { - val aabb = axisAlignedBB(location) + val aabb = axisAlignedBB(location) event.drawFilledBoundingBox_nea(aabb, colorForIndex(index), 1f) if (outline) event.outlineTopFace(aabb, 2, Color.BLACK, true) } diff --git a/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt index 80fa55ddc..672b26743 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt @@ -28,7 +28,7 @@ import kotlin.time.DurationUnit object RenderUtils { - val beaconBeam = ResourceLocation("textures/entity/beacon_beam.png") + private val beaconBeam = ResourceLocation("textures/entity/beacon_beam.png") infix fun Slot.highlight(color: LorenzColor) { highlight(color.toColor()) @@ -438,7 +438,8 @@ object RenderUtils { GlStateManager.translate(getAbsX().toFloat(), (getAbsY() + offsetY).toFloat(), 0F) var offsetX = 0 for (any in line) { - val renderable = Renderable.fromAny(any, itemScale = itemScale) ?: throw RuntimeException("Unknown render object: ${any}") + val renderable = Renderable.fromAny(any, itemScale = itemScale) + ?: throw RuntimeException("Unknown render object: $any") renderable.render(getAbsX() + offsetX, getAbsY() + offsetY) offsetX += renderable.width @@ -571,7 +572,7 @@ object RenderUtils { ) { val strLen = fr.getStringWidth(str) var factor = len / strLen.toFloat() - factor = Math.min(1f, factor) + factor = 1f.coerceAtMost(factor) TextRenderUtils.drawStringScaled(str, fr, x, y, shadow, colour, factor) } @@ -721,7 +722,6 @@ object RenderUtils { } - fun drawFilledBoundingBox(aabb: AxisAlignedBB, c: Color, alphaMultiplier: Float = 1f) { GlStateManager.enableBlend() GlStateManager.disableLighting() @@ -905,8 +905,7 @@ object RenderUtils { // TODO nea please merge with 'draw3DLine' fun RenderWorldLastEvent.draw3DLine_nea( - p1: LorenzVec, p2: LorenzVec, color: Color, lineWidth: Int, depth: Boolean, targetColor: Color? = null, - seeThroughBlocks: Boolean = true + p1: LorenzVec, p2: LorenzVec, color: Color, lineWidth: Int, depth: Boolean ) { GlStateManager.disableDepth() GlStateManager.disableCull() diff --git a/src/main/java/at/hannibal2/skyhanni/utils/SimpleTimeMark.kt b/src/main/java/at/hannibal2/skyhanni/utils/SimpleTimeMark.kt index bd682b913..977a558f4 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/SimpleTimeMark.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/SimpleTimeMark.kt @@ -5,7 +5,7 @@ import kotlin.time.Duration import kotlin.time.Duration.Companion.milliseconds @JvmInline -value class SimpleTimeMark(val millis: Long) { +value class SimpleTimeMark(private val millis: Long) { operator fun minus(other: SimpleTimeMark) = (millis - other.millis).milliseconds diff --git a/src/main/java/at/hannibal2/skyhanni/utils/SoundUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/SoundUtils.kt index 325e87211..7fd9d228f 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/SoundUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/SoundUtils.kt @@ -51,6 +51,6 @@ object SoundUtils { } fun playClickSound() { - clickSound.playSound() + clickSound.playSound() } }
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt index aaff447a9..15cab32f4 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt @@ -43,11 +43,11 @@ object StringUtils { */ fun <T> subMapWithKeysThatAreSuffixes(prefix: String, map: NavigableMap<String?, T>): Map<String?, T>? { if ("" == prefix) return map - val lastKey = createLexicographicallyNextStringOfTheSameLength(prefix) + val lastKey = nextLexicographicallyStringWithSameLength(prefix) return map.subMap(prefix, true, lastKey, false) } - fun createLexicographicallyNextStringOfTheSameLength(input: String): String { + fun nextLexicographicallyStringWithSameLength(input: String): String { val lastCharPosition = input.length - 1 val inputWithoutLastChar = input.substring(0, lastCharPosition) val lastChar = input[lastCharPosition] @@ -109,7 +109,6 @@ object StringUtils { } - fun String.removeWordsAtEnd(i: Int) = split(" ").dropLast(i).joinToString(" ") fun String.splitLines(width: Int): String { diff --git a/src/main/java/at/hannibal2/skyhanni/utils/TabListData.kt b/src/main/java/at/hannibal2/skyhanni/utils/TabListData.kt index 131b73491..e5ebc25a5 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/TabListData.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/TabListData.kt @@ -11,7 +11,6 @@ import net.minecraft.world.WorldSettings import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import net.minecraftforge.fml.relauncher.Side import net.minecraftforge.fml.relauncher.SideOnly -import java.util.* class TabListData { @@ -67,110 +66,4 @@ class TabListData { TabListUpdateEvent(cache).postAndCatch() } } - - // private val uuidMap = mutableMapOf<UUID, TabListPlayer>() -// private val tabListMap = mutableMapOf<TabListPlayer, String>() - -// class TabListPlayer(var displayName: String, var internalName: String) - -// @SubscribeEvent -// fun onWorldChange(event: LorenzWorldChangeEvent) { -// uuidMap.clear() -// tabListMap.clear() -// } - -// @SubscribeEvent -// fun onChatPacket(event: PacketEvent.ReceiveEvent) { -// val packet = event.packet -// if (packet is S38PacketPlayerListItem) { -// val action = packet.action -// if (action == S38PacketPlayerListItem.Action.UPDATE_LATENCY) return -// -// val entries = packet.entries -// if (action == S38PacketPlayerListItem.Action.REMOVE_PLAYER) { -//// println("REMOVE_PLAYER") -//// println("old: " + uuidMap.size) -// for (entry in entries) { -// val profile = entry.profile -// val id = profile.id -// val key = uuidMap.remove(id) -// tabListMap.remove(key) -// } -//// println("new: " + uuidMap.size) -// update() -// return -// } -// -// val size = entries.size -// if (size != 1) { -// println("wrong size: $size") -// return -// } -// val entry = entries[0] -// val profile = entry.profile -// val id = profile.id -// val name = profile.name -// if (name != null) { -// if (!name.contains("-")) { -// return -// } -// } -// -// val text = entry?.displayName?.formattedText ?: "" -// val formattedName = LorenzUtils.stripVanillaMessage(text) -// if (action == S38PacketPlayerListItem.Action.ADD_PLAYER) { -//// println("ADD_PLAYER") -// val tabList = TabListPlayer(formattedName, name) -// -// if (uuidMap.contains(id)) { -// val key = uuidMap.remove(id) -// val internalName = key!!.internalName -// val displayName = key.displayName -//// println("") -//// println("internalName: $internalName") -//// println("displayName: $displayName") -// tabListMap.remove(key) -// } -// -//// println("new name: $name") -//// println("new formattedName: $formattedName") -// -// uuidMap[id] = tabList -// tabListMap[tabList] = name -// update() -// return -// } -// -// if (action == S38PacketPlayerListItem.Action.UPDATE_DISPLAY_NAME) { -//// println("UPDATE_DISPLAY_NAME") -// val listPlayer = uuidMap[id] -// listPlayer?.let { -// it.displayName = formattedName -// update() -// } -//// println("old: '" + listPlayer.displayName + "'") -//// println("new: '$formattedName'") -// -// return -// } -// } -// } - -// private fun update() { -// val result = mutableListOf<String>() -// if (uuidMap.size == 80) { -// var i = 0 -// for (tabList in tabListMap.sorted().keys) { -// val contains = uuidMap.values.contains(tabList) -// if (contains) { -// val displayName = tabList.displayName -// result.add(displayName) -// i++ -// } -// } -// } else if (uuidMap.isNotEmpty()) return -// val list = result.toList() -// cache = list -// TabListUpdateEvent(list).postAndCatch() -// } }
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/utils/jsonobjects/MayorJson.java b/src/main/java/at/hannibal2/skyhanni/utils/jsonobjects/MayorJson.java index 7482902a4..6f954700c 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/jsonobjects/MayorJson.java +++ b/src/main/java/at/hannibal2/skyhanni/utils/jsonobjects/MayorJson.java @@ -35,13 +35,6 @@ public class MayorJson { } } -// public class Current { -// @Expose -// public int year; -// @Expose -// public ArrayList<Candidate> candidates; -// } - public class Election { @Expose public int year; 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 036c610bc..c554b8bde 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt @@ -40,19 +40,48 @@ interface Renderable { else -> null } - fun link(text: String, bypassChecks: Boolean = false, onClick: () -> Unit): Renderable = link(string(text), onClick, bypassChecks = bypassChecks) { true } - fun optionalLink(text: String, onClick: () -> Unit, bypassChecks: Boolean = false, condition: () -> Boolean = { true }): Renderable = + fun link(text: String, bypassChecks: Boolean = false, onClick: () -> Unit): Renderable = + link(string(text), onClick, bypassChecks = bypassChecks) { true } + + fun optionalLink( + text: String, + onClick: () -> Unit, + bypassChecks: Boolean = false, + condition: () -> Boolean = { true } + ): Renderable = link(string(text), onClick, bypassChecks, condition) - fun link(renderable: Renderable, onClick: () -> Unit, bypassChecks: Boolean = false, condition: () -> Boolean = { true }): Renderable { - return clickable(hoverable(underlined(renderable), renderable, bypassChecks, condition = condition), onClick, 0, bypassChecks, condition) + fun link( + renderable: Renderable, + onClick: () -> Unit, + bypassChecks: Boolean = false, + condition: () -> Boolean = { true } + ): Renderable { + return clickable( + hoverable(underlined(renderable), renderable, bypassChecks, condition = condition), + onClick, + 0, + bypassChecks, + condition + ) } - fun clickAndHover(text: String, tips: List<String>, bypassChecks: Boolean = false, onClick: () -> Unit): Renderable { + fun clickAndHover( + text: String, + tips: List<String>, + bypassChecks: Boolean = false, + onClick: () -> Unit + ): Renderable { return clickable(hoverTips(text, tips, bypassChecks = bypassChecks), onClick, bypassChecks = bypassChecks) } - fun clickable(render: Renderable, onClick: () -> Unit, button: Int = 0, bypassChecks: Boolean = false, condition: () -> Boolean = { true }) = + fun clickable( + render: Renderable, + onClick: () -> Unit, + button: Int = 0, + bypassChecks: Boolean = false, + condition: () -> Boolean = { true } + ) = object : Renderable { override val width: Int get() = render.width @@ -72,7 +101,12 @@ interface Renderable { } } - fun hoverTips(text: String, tips: List<String>, bypassChecks: Boolean = false, condition: () -> Boolean = { true }): Renderable { + fun hoverTips( + text: String, + tips: List<String>, + bypassChecks: Boolean = false, + condition: () -> Boolean = { true } + ): Renderable { val render = string(text) return object : Renderable { override val width: Int @@ -171,7 +205,12 @@ interface Renderable { } } - fun hoverable(hovered: Renderable, unhovered: Renderable, bypassChecks: Boolean = false, condition: () -> Boolean = { true }) = + fun hoverable( + hovered: Renderable, + unhovered: Renderable, + bypassChecks: Boolean = false, + condition: () -> Boolean = { true } + ) = object : Renderable { override val width: Int get() = max(hovered.width, unhovered.width) |