From 21e5cb0dd6386342822a22d491f1221c8cedbac5 Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Tue, 8 Dec 2020 15:07:53 -0500 Subject: [PATCH] [cleanup] Replace deprecated Kotlin functions, use property access syntax --- .../kami/module/modules/combat/AutoLog.kt | 4 +-- .../kami/module/modules/combat/CrystalAura.kt | 28 +++++++++---------- .../module/modules/combat/CrystalBasePlace.kt | 8 +++--- .../kami/module/modules/render/BossStack.kt | 2 +- .../kami/module/modules/render/Nametags.kt | 25 +++++++++-------- .../module/modules/render/Trajectories.kt | 4 +-- .../me/zeroeightsix/kami/util/EntityUtils.kt | 10 +++++-- .../kami/util/graphics/font/FontGlyphs.kt | 4 +-- .../kami/util/graphics/font/TextComponent.kt | 6 ++-- 9 files changed, 48 insertions(+), 43 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/combat/AutoLog.kt b/src/main/java/me/zeroeightsix/kami/module/modules/combat/AutoLog.kt index 525ef21db..a9d9e39e8 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/combat/AutoLog.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/combat/AutoLog.kt @@ -63,7 +63,7 @@ object AutoLog : Module() { } private fun checkCrystals(): Boolean { - val maxSelfDamage = CombatManager.crystalMap.values.maxBy { it.second }?.second ?: 0.0f + val maxSelfDamage = CombatManager.crystalMap.values.maxByOrNull { it.second }?.second ?: 0.0f return CombatUtils.getHealthSmart(mc.player) - maxSelfDamage < health.value } @@ -94,7 +94,7 @@ object AutoLog : Module() { val reasonText = getReason(reason, additionalInfo) val screen = getScreen() // do this before disconnecting - mc.getSoundHandler().playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) + mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) mc.connection?.networkManager?.closeChannel(TextComponentString("")) mc.loadWorld(null as WorldClient?) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/combat/CrystalAura.kt b/src/main/java/me/zeroeightsix/kami/module/modules/combat/CrystalAura.kt index 425a9d8c2..04e2f3823 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/combat/CrystalAura.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/combat/CrystalAura.kt @@ -163,8 +163,8 @@ object CrystalAura : Module() { // Minecraft sends sounds packets a tick before removing the crystal lol if (it.packet is SPacketSoundEffect - && it.packet.getCategory() == SoundCategory.BLOCKS - && it.packet.getSound() == SoundEvents.ENTITY_GENERIC_EXPLODE) { + && it.packet.category == SoundCategory.BLOCKS + && it.packet.sound == SoundEvents.ENTITY_GENERIC_EXPLODE) { val crystalList = CrystalUtils.getCrystalList(Vec3d(it.packet.x, it.packet.y, it.packet.z), 6.0f) for (crystal in crystalList) { @@ -381,10 +381,10 @@ object CrystalAura : Module() { /* General */ private fun getHand(): EnumHand? { - val serverSideItem = if (spoofHotbar.value) mc.player.inventory.getStackInSlot(PlayerPacketManager.serverSideHotbar).getItem() else null + val serverSideItem = if (spoofHotbar.value) mc.player.inventory.getStackInSlot(PlayerPacketManager.serverSideHotbar).item else null return when (Items.END_CRYSTAL) { - mc.player.heldItemOffhand.getItem() -> EnumHand.OFF_HAND - mc.player.heldItemMainhand.getItem() -> EnumHand.MAIN_HAND + mc.player.heldItemOffhand.item -> EnumHand.OFF_HAND + mc.player.heldItemMainhand.item -> EnumHand.MAIN_HAND serverSideItem -> EnumHand.MAIN_HAND else -> null } @@ -393,7 +393,7 @@ object CrystalAura : Module() { private fun noSuicideCheck(selfDamage: Float) = CombatUtils.getHealthSmart(mc.player) - selfDamage > noSuicideThreshold.value private fun isHoldingTool(): Boolean { - val item = mc.player.heldItemMainhand.getItem() + val item = mc.player.heldItemMainhand.item return item is ItemTool || item is ItemSword } @@ -404,14 +404,14 @@ object CrystalAura : Module() { || forcePlaceArmorDura.value > 0.0f && getMinArmorDura() <= forcePlaceArmorDura.value) private fun getMinArmorDura() = - (CombatManager.target?.let { target -> - target.armorInventoryList - .filter { !it.isEmpty() && it.isItemStackDamageable } - .maxBy { it.itemDamage } - ?.let { - (it.maxDamage - it.itemDamage) * 100 / it.maxDamage - } - }) ?: 100 + (CombatManager.target?.let { target -> + target.armorInventoryList + .filter { !it.isEmpty && it.isItemStackDamageable } + .maxByOrNull { it.itemDamage } + ?.let { + (it.maxDamage - it.itemDamage) * 100 / it.maxDamage + } + }) ?: 100 private fun countValidCrystal(): Int { var count = 0 diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/combat/CrystalBasePlace.kt b/src/main/java/me/zeroeightsix/kami/module/modules/combat/CrystalBasePlace.kt index 4c70dc0e8..76c63d720 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/combat/CrystalBasePlace.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/combat/CrystalBasePlace.kt @@ -108,7 +108,7 @@ object CrystalBasePlace : Module() { private val isHoldingObby get() = isObby(mc.player.heldItemMainhand) || isObby(mc.player.inventory.getStackInSlot(PlayerPacketManager.serverSideHotbar)) - private fun isObby(itemStack: ItemStack) = Block.getBlockFromItem(itemStack.getItem()) == Blocks.OBSIDIAN + private fun isObby(itemStack: ItemStack) = Block.getBlockFromItem(itemStack.item) == Blocks.OBSIDIAN private fun getObby(): Int? { val slots = InventoryUtils.getSlotsHotbar(49) @@ -143,9 +143,9 @@ object CrystalBasePlace : Module() { val eyePos = mc.player.getPositionEyes(1.0f) val posList = VectorUtils.getBlockPosInSphere(eyePos, range.value) val maxCurrentDamage = CombatManager.placeMap.entries - .filter { eyePos.distanceTo(it.key.toVec3d()) < range.value } - .map { it.value.first } - .max() ?: 0.0f + .filter { eyePos.distanceTo(it.key.toVec3d()) < range.value } + .map { it.value.first } + .maxOrNull() ?: 0.0f for (pos in posList) { // Placeable check diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/render/BossStack.kt b/src/main/java/me/zeroeightsix/kami/module/modules/render/BossStack.kt index 39791aecd..78199e338 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/render/BossStack.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/render/BossStack.kt @@ -81,7 +81,7 @@ object BossStack : Module() { it.health / it.maxHealth } ?: return null - return list.minBy { + return list.minByOrNull { abs(it.percent - closestBossHealth) } } diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/render/Nametags.kt b/src/main/java/me/zeroeightsix/kami/module/modules/render/Nametags.kt index ff3e2b55f..d908d0888 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/render/Nametags.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/render/Nametags.kt @@ -54,12 +54,12 @@ object Nametags : Module() { private val range = register(Settings.integerBuilder("Range").withValue(64).withRange(0, 128).withStep(4).withVisibility { page.value == Page.ENTITY_TYPE }) /* Content */ - private val line1left = register(Settings.enumBuilder(ContentType::class.java, "Line1Left").withValue(ContentType.NONE).withVisibility { page.value == Page.CONTENT }) - private val line1center = register(Settings.enumBuilder(ContentType::class.java, "Line1Center").withValue(ContentType.NONE).withVisibility { page.value == Page.CONTENT }) - private val line1right = register(Settings.enumBuilder(ContentType::class.java, "Line1Right").withValue(ContentType.NONE).withVisibility { page.value == Page.CONTENT }) - private val line2left = register(Settings.enumBuilder(ContentType::class.java, "Line2Left").withValue(ContentType.NAME).withVisibility { page.value == Page.CONTENT }) - private val line2center = register(Settings.enumBuilder(ContentType::class.java, "Line2Center").withValue(ContentType.PING).withVisibility { page.value == Page.CONTENT }) - private val line2right = register(Settings.enumBuilder(ContentType::class.java, "Line2Right").withValue(ContentType.TOTAL_HP).withVisibility { page.value == Page.CONTENT }) + private val line1left = register(Settings.enumBuilder(ContentType::class.java, "Line1Left").withValue(ContentType.NONE).withVisibility { page.value == Page.CONTENT }) + private val line1center = register(Settings.enumBuilder(ContentType::class.java, "Line1Center").withValue(ContentType.NONE).withVisibility { page.value == Page.CONTENT }) + private val line1right = register(Settings.enumBuilder(ContentType::class.java, "Line1Right").withValue(ContentType.NONE).withVisibility { page.value == Page.CONTENT }) + private val line2left = register(Settings.enumBuilder(ContentType::class.java, "Line2Left").withValue(ContentType.NAME).withVisibility { page.value == Page.CONTENT }) + private val line2center = register(Settings.enumBuilder(ContentType::class.java, "Line2Center").withValue(ContentType.PING).withVisibility { page.value == Page.CONTENT }) + private val line2right = register(Settings.enumBuilder(ContentType::class.java, "Line2Right").withValue(ContentType.TOTAL_HP).withVisibility { page.value == Page.CONTENT }) private val dropItemCount = register(Settings.booleanBuilder("DropItemCount").withValue(true).withVisibility { page.value == Page.CONTENT && items.value }) private val maxDropItems = register(Settings.integerBuilder("MaxDropItems").withValue(5).withRange(2, 16).withStep(1).withVisibility { page.value == Page.CONTENT && items.value }) @@ -184,9 +184,9 @@ object Nametags : Module() { itemList.add(itemStack to getEnchantmentText(itemStack)) } - if (itemList.isEmpty() || itemList.count { !it.first.isEmpty() } == 0) return + if (itemList.isEmpty() || itemList.count { !it.first.isEmpty } == 0) return val halfHeight = textComponent.getHeight(2, true, customFont.value) / 2.0 + margins.value + 2.0 - val halfWidth = (itemList.count { !it.first.isEmpty() } * 28) / 2f + val halfWidth = (itemList.count { !it.first.isEmpty } * 28) / 2f glPushMatrix() glTranslatef(screenPos.x.toFloat(), screenPos.y.toFloat(), 0f) // Translate to nametag pos @@ -200,8 +200,11 @@ object Nametags : Module() { if (itemFrame.value) { glTranslatef(0f, -margins.value, 0f) val duraHeight = if (drawDura) FontRenderAdapter.getFontHeight(customFont = customFont.value) + 2f else 0f - val enchantmentHeight = if (enchantment.value) (itemList.map { it.second.getHeight(2, customFont = customFont.value) }.max() - ?: 0f) + 4f else 0f + val enchantmentHeight = if (enchantment.value) { + (itemList.map { it.second.getHeight(2, customFont = customFont.value) }.maxOrNull() ?: 0f) + 4f + } else { + 0f + } val height = 16 + duraHeight + enchantmentHeight * 0.6f val posBegin = Vec2d(-halfWidth - margins.value.toDouble(), -height - margins.value.toDouble()) val posEnd = Vec2d(halfWidth + margins.value.toDouble(), margins.value.toDouble()) @@ -212,7 +215,7 @@ object Nametags : Module() { if (drawDura) glTranslatef(0f, -FontRenderAdapter.getFontHeight(customFont = customFont.value) - 2f, 0f) for ((itemStack, enchantmentText) in itemList) { - if (itemStack.isEmpty()) continue + if (itemStack.isEmpty) continue drawItem(itemStack, enchantmentText, drawDura) } glColor4f(1f, 1f, 1f, 1f) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/render/Trajectories.kt b/src/main/java/me/zeroeightsix/kami/module/modules/render/Trajectories.kt index aa776675c..b98ca5a49 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/render/Trajectories.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/render/Trajectories.kt @@ -147,7 +147,7 @@ object Trajectories : Module() { rayTraceResult.entityHit = entity resultList.add(rayTraceResult) } - collision = resultList.minBy { it.hitVec.distanceTo(position) } + collision = resultList.minByOrNull { it.hitVec.distanceTo(position) } } collision?.let { @@ -190,7 +190,7 @@ object Trajectories : Module() { } } - private fun getThrowingType(itemStack: ItemStack?): ThrowingType? = when (itemStack?.getItem()) { + private fun getThrowingType(itemStack: ItemStack?): ThrowingType? = when (itemStack?.item) { Items.BOW -> ThrowingType.BOW Items.EXPERIENCE_BOTTLE -> ThrowingType.EXPERIENCE Items.SPLASH_POTION, Items.LINGERING_POTION -> ThrowingType.POTION diff --git a/src/main/java/me/zeroeightsix/kami/util/EntityUtils.kt b/src/main/java/me/zeroeightsix/kami/util/EntityUtils.kt index 7365fe6ae..b5e30f0a6 100644 --- a/src/main/java/me/zeroeightsix/kami/util/EntityUtils.kt +++ b/src/main/java/me/zeroeightsix/kami/util/EntityUtils.kt @@ -89,7 +89,7 @@ object EntityUtils { return false } - fun isDrivenByPlayer(entity: Entity) = mc.player != null && entity == mc.player.getRidingEntity() + fun isDrivenByPlayer(entity: Entity) = mc.player != null && entity == mc.player.ridingEntity fun isAboveWater(entity: Entity?) = isAboveWater(entity, false) @@ -157,11 +157,15 @@ object EntityUtils { for (currentEntity in mc.world.loadedEntityList) { if (currentEntity.getDistance(mc.player) > range) continue /* Entities within specified blocks radius */ if (currentEntity !is EntityItem) continue /* Entites that are dropped item */ - if (Item.getIdFromItem(currentEntity.item.getItem()) != itemId) continue /* Dropped items that are has give item id */ + if (Item.getIdFromItem(currentEntity.item.item) != itemId) continue /* Dropped items that are has give item id */ entityList.add(currentEntity) } return entityList } - fun getDroppedItem(itemId: Int, range: Float) = getDroppedItems(itemId, range)?.minBy { mc.player.getDistance(it) }?.positionVector?.toBlockPos() + fun getDroppedItem(itemId: Int, range: Float) = + getDroppedItems(itemId, range) + ?.minByOrNull { mc.player.getDistance(it) } + ?.positionVector + ?.toBlockPos() } \ No newline at end of file diff --git a/src/main/java/me/zeroeightsix/kami/util/graphics/font/FontGlyphs.kt b/src/main/java/me/zeroeightsix/kami/util/graphics/font/FontGlyphs.kt index b55d730dc..e5387b835 100644 --- a/src/main/java/me/zeroeightsix/kami/util/graphics/font/FontGlyphs.kt +++ b/src/main/java/me/zeroeightsix/kami/util/graphics/font/FontGlyphs.kt @@ -74,7 +74,7 @@ class FontGlyphs(val style: Style, private val font: Font, private val fallbackF // Loads the basic 256 characters on init fontHeight = loadGlyphChunk(0)?.let { chunk -> chunkMap[0] = chunk - chunk.charInfoArray.maxBy { it.height }?.height?.toFloat() ?: 64.0f + chunk.charInfoArray.maxByOrNull { it.height }?.height?.toFloat() ?: 64.0f } ?: 64.0f } @@ -179,7 +179,7 @@ class FontGlyphs(val style: Style, private val font: Font, private val fallbackF private fun createTexture(bufferedImage: BufferedImage): DynamicTexture? { return try { val dynamicTexture = DynamicTexture(bufferedImage) - dynamicTexture.loadTexture(Wrapper.minecraft.getResourceManager()) + dynamicTexture.loadTexture(Wrapper.minecraft.resourceManager) val textureId = dynamicTexture.glTextureId // Tells Gl that our texture isn't a repeating texture (edges are not connecting to each others) diff --git a/src/main/java/me/zeroeightsix/kami/util/graphics/font/TextComponent.kt b/src/main/java/me/zeroeightsix/kami/util/graphics/font/TextComponent.kt index 4120302b6..8b88c31b0 100644 --- a/src/main/java/me/zeroeightsix/kami/util/graphics/font/TextComponent.kt +++ b/src/main/java/me/zeroeightsix/kami/util/graphics/font/TextComponent.kt @@ -1,6 +1,5 @@ package me.zeroeightsix.kami.util.graphics.font -import me.zeroeightsix.kami.util.Wrapper import me.zeroeightsix.kami.util.color.ColorHolder import me.zeroeightsix.kami.util.math.Vec2d import org.lwjgl.opengl.GL11.* @@ -10,7 +9,6 @@ import kotlin.math.max * Renders multi line text easily */ class TextComponent(val separator: String = " ") { - private val fontRenderer = Wrapper.minecraft.fontRenderer private val textLines = ArrayList() var currentLine = 0 set(value) { @@ -31,7 +29,7 @@ class TextComponent(val separator: String = " ") { constructor(string: String, separator: String = " ", vararg delimiters: String = arrayOf(separator)) : this(separator) { val lines = string.lines() for (line in lines) { - for (splitText in line.split(delimiters = *delimiters)) { + for (splitText in line.split(delimiters = delimiters)) { add(splitText) } if (line != lines.last()) currentLine++ @@ -113,7 +111,7 @@ class TextComponent(val separator: String = " ") { fun getWidth(customFont: Boolean = FontRenderAdapter.useCustomFont) = textLines.map { it?.getWidth(customFont) ?: 0f - }.max() ?: 0f + }.maxOrNull() ?: 0f fun getHeight(lineSpace: Int, skipEmptyLines: Boolean = false, customFont: Boolean = FontRenderAdapter.useCustomFont) = FontRenderAdapter.getFontHeight(customFont = customFont) * getLines(skipEmptyLines) + lineSpace * (getLines(skipEmptyLines) - 1)