@@ -26,15 +26,13 @@ import com.lambda.interaction.managers.rotating.Rotation.Companion.dist
2626import com.lambda.interaction.managers.rotating.Rotation.Companion.rotation
2727import com.lambda.interaction.managers.rotating.Rotation.Companion.rotationTo
2828import com.lambda.threading.runSafe
29- import com.lambda.util.EntityUtils.EntityGroup
30- import com.lambda.util.EntityUtils.entityGroup
3129import com.lambda.util.NamedEnum
3230import com.lambda.util.extension.fullHealth
3331import com.lambda.util.math.distSq
3432import com.lambda.util.world.fastEntitySearch
3533import net.minecraft.client.network.ClientPlayerEntity
3634import net.minecraft.client.network.OtherClientPlayerEntity
37- import net.minecraft.client.toast.SystemToast.hide
35+ import net.minecraft.entity.Entity
3836import net.minecraft.entity.LivingEntity
3937import java.util.*
4038
@@ -76,7 +74,7 @@ abstract class Targeting(
7674 * @param entity The [LivingEntity] being evaluated.
7775 * @return `true` if the entity is valid for targeting, `false` otherwise.
7876 */
79- open fun validate (player : ClientPlayerEntity , entity : LivingEntity ) =
77+ open fun validate (player : ClientPlayerEntity , entity : Entity ) =
8078 targets.isSelected(entity) && (entity !is OtherClientPlayerEntity || ! entity.isFriend)
8179
8280 /* *
@@ -107,23 +105,23 @@ abstract class Targeting(
107105 * Validates whether a given entity is targetable for combat based on the field of view limit and other settings.
108106 *
109107 * @param player The [ClientPlayerEntity] performing the targeting.
110- * @param entity The [LivingEntity ] being evaluated.
108+ * @param entity The [Entity ] being evaluated.
111109 * @return `true` if the entity is valid for targeting, `false` otherwise.
112110 */
113- override fun validate (player : ClientPlayerEntity , entity : LivingEntity ): Boolean {
111+ override fun validate (player : ClientPlayerEntity , entity : Entity ): Boolean {
114112 if (fov < 180 && player.rotation dist player.eyePos.rotationTo(entity.pos) > fov) return false
115113 if (entity.uuid in illegalTargets) return false
116- if (entity.isDead) return false
114+ if (( entity as ? LivingEntity )? .isDead == true ) return false
117115 return super .validate(player, entity)
118116 }
119117
120118 /* *
121119 * Gets the best target for combat based on the current settings and priority.
122120 *
123- * @return The best [LivingEntity ] target, or `null` if no valid target is found.
121+ * @return The best [Entity ] target, or `null` if no valid target is found.
124122 */
125- fun target (): LivingEntity ? = runSafe {
126- return @runSafe fastEntitySearch<LivingEntity >(targetingRange) {
123+ inline fun < reified T : Entity > target (): T ? = runSafe {
124+ return @runSafe fastEntitySearch<T >(targetingRange) {
127125 validate(player, it)
128126 }.minByOrNull {
129127 priority.factor(this , it)
@@ -140,19 +138,21 @@ abstract class Targeting(
140138 /* *
141139 * Enum representing the different priority factors used for determining the best target.
142140 *
143- * @property factor A lambda function that calculates the priority factor for a given [LivingEntity ].
141+ * @property factor A lambda function that calculates the priority factor for a given [Entity ].
144142 */
145143 @Suppress(" Unused" )
146- enum class Priority (val factor : SafeContext .(LivingEntity ) -> Double ) {
144+ enum class Priority (val factor : SafeContext .(Entity ) -> Double ) {
147145 /* *
148146 * Prioritizes entities based on their distance from the player.
149147 */
150148 Distance ({ player.pos distSq it.pos }),
151149
152150 /* *
153151 * Prioritizes entities based on their health.
152+ * Entities that aren't an instanceof LivingEntity will be treated as if they have Double.MAX_VALUE health,
153+ * therefore having least priority
154154 */
155- Health ({ it .fullHealth }),
155+ Health ({ (it as ? LivingEntity )? .fullHealth ? : Double . MAX_VALUE }),
156156
157157 /* *
158158 * Prioritizes entities based on their angle relative to the player's field of view.
0 commit comments