Skip to content

Commit b966238

Browse files
authored
Target Named Entities setting in Targeting.kt (#270)
1 parent d105b4d commit b966238

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/main/kotlin/com/lambda/config/groups/Targeting.kt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import net.minecraft.client.network.ClientPlayerEntity
3434
import net.minecraft.client.network.OtherClientPlayerEntity
3535
import net.minecraft.entity.Entity
3636
import net.minecraft.entity.LivingEntity
37+
import net.minecraft.entity.PlayerLikeEntity
3738
import java.util.*
3839

3940
/**
@@ -44,7 +45,7 @@ import java.util.*
4445
* are targetable, the range of targeting, and various other conditions for targeting.
4546
*
4647
* @param c The [Configurable] instance used to get and set configuration options for targeting.
47-
* @param vis The predicate used to determine whether the targeting settings are visible and active.
48+
* @param visibility The predicate used to determine whether the targeting settings are visible and active.
4849
* @param defaultRange The default range within which entities can be targeted.
4950
* @param maxRange The maximum range within which entities can be targeted.
5051
*/
@@ -101,6 +102,11 @@ abstract class Targeting(
101102
*/
102103
val priority by c.setting("${prefix}Priority", Priority.Distance, visibility = visibility).group(*baseGroup).index()
103104

105+
/**
106+
* Whether to target named entities that are not players. Configurable with default set to `true`.
107+
*/
108+
val targetNamed by c.setting("${prefix}Target Named Entities", false, visibility = visibility).group(*baseGroup).index()
109+
104110
/**
105111
* Validates whether a given entity is targetable for combat based on the field of view limit and other settings.
106112
*
@@ -111,7 +117,8 @@ abstract class Targeting(
111117
override fun validate(player: ClientPlayerEntity, entity: Entity): Boolean {
112118
if (fov < 180 && player.rotation dist player.eyePos.rotationTo(entity.pos) > fov) return false
113119
if (entity.uuid in illegalTargets) return false
114-
if ((entity as? LivingEntity)?.isDead == true) return false
120+
if (entity.hasCustomName() && entity !is PlayerLikeEntity && !targetNamed) return false
121+
if ((entity as? LivingEntity)?.isDead == true) return false
115122
return super.validate(player, entity)
116123
}
117124

0 commit comments

Comments
 (0)