diff --git a/src/main/kotlin/com/lambda/config/groups/Targeting.kt b/src/main/kotlin/com/lambda/config/groups/Targeting.kt index 7163303e8..7cc483ff8 100644 --- a/src/main/kotlin/com/lambda/config/groups/Targeting.kt +++ b/src/main/kotlin/com/lambda/config/groups/Targeting.kt @@ -26,15 +26,13 @@ import com.lambda.interaction.managers.rotating.Rotation.Companion.dist import com.lambda.interaction.managers.rotating.Rotation.Companion.rotation import com.lambda.interaction.managers.rotating.Rotation.Companion.rotationTo import com.lambda.threading.runSafe -import com.lambda.util.EntityUtils.EntityGroup -import com.lambda.util.EntityUtils.entityGroup import com.lambda.util.NamedEnum import com.lambda.util.extension.fullHealth import com.lambda.util.math.distSq import com.lambda.util.world.fastEntitySearch import net.minecraft.client.network.ClientPlayerEntity import net.minecraft.client.network.OtherClientPlayerEntity -import net.minecraft.client.toast.SystemToast.hide +import net.minecraft.entity.Entity import net.minecraft.entity.LivingEntity import java.util.* @@ -76,7 +74,7 @@ abstract class Targeting( * @param entity The [LivingEntity] being evaluated. * @return `true` if the entity is valid for targeting, `false` otherwise. */ - open fun validate(player: ClientPlayerEntity, entity: LivingEntity) = + open fun validate(player: ClientPlayerEntity, entity: Entity) = targets.isSelected(entity) && (entity !is OtherClientPlayerEntity || !entity.isFriend) /** @@ -107,23 +105,23 @@ abstract class Targeting( * Validates whether a given entity is targetable for combat based on the field of view limit and other settings. * * @param player The [ClientPlayerEntity] performing the targeting. - * @param entity The [LivingEntity] being evaluated. + * @param entity The [Entity] being evaluated. * @return `true` if the entity is valid for targeting, `false` otherwise. */ - override fun validate(player: ClientPlayerEntity, entity: LivingEntity): Boolean { + override fun validate(player: ClientPlayerEntity, entity: Entity): Boolean { if (fov < 180 && player.rotation dist player.eyePos.rotationTo(entity.pos) > fov) return false if (entity.uuid in illegalTargets) return false - if (entity.isDead) return false + if ((entity as? LivingEntity)?.isDead == true) return false return super.validate(player, entity) } /** * Gets the best target for combat based on the current settings and priority. * - * @return The best [LivingEntity] target, or `null` if no valid target is found. + * @return The best [Entity] target, or `null` if no valid target is found. */ - fun target(): LivingEntity? = runSafe { - return@runSafe fastEntitySearch(targetingRange) { + inline fun target(): T? = runSafe { + return@runSafe fastEntitySearch(targetingRange) { validate(player, it) }.minByOrNull { priority.factor(this, it) @@ -140,10 +138,10 @@ abstract class Targeting( /** * Enum representing the different priority factors used for determining the best target. * - * @property factor A lambda function that calculates the priority factor for a given [LivingEntity]. + * @property factor A lambda function that calculates the priority factor for a given [Entity]. */ @Suppress("Unused") - enum class Priority(val factor: SafeContext.(LivingEntity) -> Double) { + enum class Priority(val factor: SafeContext.(Entity) -> Double) { /** * Prioritizes entities based on their distance from the player. */ @@ -151,8 +149,10 @@ abstract class Targeting( /** * Prioritizes entities based on their health. + * Entities that aren't an instanceof LivingEntity will be treated as if they have Double.MAX_VALUE health, + * therefore having least priority */ - Health({ it.fullHealth }), + Health({ (it as? LivingEntity)?.fullHealth ?: Double.MAX_VALUE }), /** * Prioritizes entities based on their angle relative to the player's field of view. diff --git a/src/main/kotlin/com/lambda/module/modules/combat/CrystalAura.kt b/src/main/kotlin/com/lambda/module/modules/combat/CrystalAura.kt index c43c70eb1..423f25e5f 100644 --- a/src/main/kotlin/com/lambda/module/modules/combat/CrystalAura.kt +++ b/src/main/kotlin/com/lambda/module/modules/combat/CrystalAura.kt @@ -245,7 +245,7 @@ object CrystalAura : Module( private fun SafeContext.tick() { // Update the target - currentTarget = targeting.target() + currentTarget = targeting.target() // Update the blueprint currentTarget?.let { diff --git a/src/main/kotlin/com/lambda/module/modules/combat/KillAura.kt b/src/main/kotlin/com/lambda/module/modules/combat/KillAura.kt index eb666107e..0edb2f756 100644 --- a/src/main/kotlin/com/lambda/module/modules/combat/KillAura.kt +++ b/src/main/kotlin/com/lambda/module/modules/combat/KillAura.kt @@ -36,7 +36,7 @@ import com.lambda.util.item.ItemStackUtils.attackDamage import com.lambda.util.item.ItemStackUtils.attackSpeed import com.lambda.util.math.random import com.lambda.util.player.SlotUtils.hotbarStacks -import net.minecraft.entity.LivingEntity +import net.minecraft.entity.Entity import net.minecraft.item.ItemStack import net.minecraft.network.packet.c2s.play.PlayerInteractEntityC2SPacket import net.minecraft.util.Hand @@ -59,8 +59,8 @@ object KillAura : Module( // Targeting private val targeting = Targeting.Combat(c = this, baseGroup = arrayOf(Group.Targeting)) - val target: LivingEntity? - get() = targeting.target() + val target: Entity? + get() = targeting.target() private var prevEntity = target private var validServerRot = false diff --git a/src/main/kotlin/com/lambda/module/modules/movement/BackTrack.kt b/src/main/kotlin/com/lambda/module/modules/movement/BackTrack.kt index 53006851b..70b0e687a 100644 --- a/src/main/kotlin/com/lambda/module/modules/movement/BackTrack.kt +++ b/src/main/kotlin/com/lambda/module/modules/movement/BackTrack.kt @@ -95,7 +95,7 @@ object BackTrack : Module( init { listen { val prevTarget = target - target = if (KillAura.isDisabled) null else KillAura.target + target = KillAura.target.takeIf { KillAura.isEnabled } as? LivingEntity val currentTarget = target if (prevTarget != currentTarget || currentTarget == null) {