Skip to content

Commit

Permalink
'enhance los traces' config option
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Jan 24, 2023
1 parent 3e09e52 commit 8bfea3f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/main/java/org/mcmonkey/sentinel/SentinelPlugin.java
Expand Up @@ -206,6 +206,11 @@ public ArrayList<SentinelTrait> cleanCurrentList() {
*/
public boolean hasWorldGuard;

/**
* Whether to use smarter LOS tracing.
*/
public boolean enhanceLosTraces;

/**
* Fills the {@code vaultPerms} object if possible.
*/
Expand Down Expand Up @@ -273,6 +278,7 @@ public void loadConfigSettings() {
minShootSpeed = getConfig().getDouble("random.shoot speed minimum", 20);
workaroundDrops = getConfig().getBoolean("random.workaround drops", false) || blockEvents;
deathMessages = getConfig().getBoolean("random.death messages", true);
enhanceLosTraces = getConfig().getBoolean("random.enhance los traces", true);
try {
spectralSound = Sound.valueOf(getConfig().getString("random.spectral sound", "ENTITY_VILLAGER_YES"));
}
Expand Down
9 changes: 8 additions & 1 deletion src/main/java/org/mcmonkey/sentinel/SentinelUtilities.java
Expand Up @@ -532,7 +532,14 @@ public static boolean checkLineOfSightWithTransparency(LivingEntity start, Livin
if (!SentinelVersionCompat.v1_13) {
return start.hasLineOfSight(end);
}
return checkLineOfSightWithTransparency(start.getEyeLocation(), end.getEyeLocation());
if (checkLineOfSightWithTransparency(start.getEyeLocation(), end.getEyeLocation())) {
return true;
}
if (!SentinelPlugin.instance.enhanceLosTraces) {
return false;
}
return checkLineOfSightWithTransparency(start.getEyeLocation(), end.getLocation())
|| checkLineOfSightWithTransparency(start.getEyeLocation(), end.getLocation().add(0, 1.05, 0));
}

/**
Expand Down
Expand Up @@ -32,10 +32,10 @@ public boolean canSee(LivingEntity entity) {
if (getLivingEntity().getEyeLocation().distanceSquared(entity.getEyeLocation()) > sentinel.range * sentinel.range) {
return false;
}
if (!sentinel.ignoreLOS && !SentinelUtilities.checkLineOfSightWithTransparency(getLivingEntity(), entity)) {
if (sentinel.realistic && !SentinelUtilities.isLookingTowards(getLivingEntity().getEyeLocation(), entity.getLocation(), 90, 110)) {
return false;
}
if (sentinel.realistic && !SentinelUtilities.isLookingTowards(getLivingEntity().getEyeLocation(), entity.getLocation(), 90, 110)) {
if (!sentinel.ignoreLOS && !SentinelUtilities.checkLineOfSightWithTransparency(getLivingEntity(), entity)) {
return false;
}
return true;
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/config.yml
Expand Up @@ -95,6 +95,9 @@ random:
ignore invisible targets: true
# Whether to prevent players from damaging NPCs that are guarding them.
no guard damage: true
# If false: checks from NPC eye to target eye. If true: checks from NPC eye to multiple points on target body.
# 'true' is smarter at checking, at the cost of performance.
enhance los traces: true
# Distances used for NPCs following their guarded player
guard follow distance:
# Maximum possible distance of point to choose (relative to the guarded player)
Expand Down

0 comments on commit 8bfea3f

Please sign in to comment.