[cleanup] Replace deprecated Kotlin functions, use property access syntax

This commit is contained in:
Xiaro 2020-12-08 15:07:53 -05:00
parent 6820df847c
commit 21e5cb0dd6
No known key found for this signature in database
GPG Key ID: 996D265D6E155377
9 changed files with 48 additions and 43 deletions

View File

@ -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?)

View File

@ -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

View File

@ -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

View File

@ -81,7 +81,7 @@ object BossStack : Module() {
it.health / it.maxHealth
} ?: return null
return list.minBy {
return list.minByOrNull {
abs(it.percent - closestBossHealth)
}
}

View File

@ -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>(ContentType::class.java, "Line1Left").withValue(ContentType.NONE).withVisibility { page.value == Page.CONTENT })
private val line1center = register(Settings.enumBuilder<ContentType>(ContentType::class.java, "Line1Center").withValue(ContentType.NONE).withVisibility { page.value == Page.CONTENT })
private val line1right = register(Settings.enumBuilder<ContentType>(ContentType::class.java, "Line1Right").withValue(ContentType.NONE).withVisibility { page.value == Page.CONTENT })
private val line2left = register(Settings.enumBuilder<ContentType>(ContentType::class.java, "Line2Left").withValue(ContentType.NAME).withVisibility { page.value == Page.CONTENT })
private val line2center = register(Settings.enumBuilder<ContentType>(ContentType::class.java, "Line2Center").withValue(ContentType.PING).withVisibility { page.value == Page.CONTENT })
private val line2right = register(Settings.enumBuilder<ContentType>(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)

View File

@ -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

View File

@ -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()
}

View File

@ -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)

View File

@ -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<TextLine?>()
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)