Skip to content

Commit

Permalink
Add a new look close setting to control enabling while pathfinding
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed Feb 25, 2020
1 parent 8843454 commit a8676cd
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 36 deletions.
45 changes: 16 additions & 29 deletions main/src/main/java/net/citizensnpcs/Settings.java
Expand Up @@ -67,15 +67,12 @@ public enum Setting {
CHAT_MAX_NUMBER_OF_TARGETS("npc.chat.options.max-number-of-targets-to-show", 2),
CHAT_MULTIPLE_TARGETS_FORMAT("npc.chat.options.multiple-targets-format",
"<target>|, <target>| & <target>| & others"),
CHAT_RANGE("npc.chat.options.range", 5),
CHECK_MINECRAFT_VERSION("advanced.check-minecraft-version", true),
DEBUG_FILE("general.debug-file", ""),
DEBUG_MODE("general.debug-mode", false),
CHAT_RANGE("npc.chat.options.range", 5), CHECK_MINECRAFT_VERSION("advanced.check-minecraft-version", true),
DEBUG_FILE("general.debug-file", ""), DEBUG_MODE("general.debug-mode", false),
DEBUG_PATHFINDING("general.debug-pathfinding", false),
DEFAULT_DISTANCE_MARGIN("npc.pathfinding.default-distance-margin", 2),
DEFAULT_LOOK_CLOSE("npc.default.look-close.enabled", false),
DEFAULT_LOOK_CLOSE_RANGE("npc.default.look-close.range", 5),
DEFAULT_NPC_LIMIT("npc.limits.default-limit", 10),
DEFAULT_LOOK_CLOSE_RANGE("npc.default.look-close.range", 5), DEFAULT_NPC_LIMIT("npc.limits.default-limit", 10),
DEFAULT_PATH_DISTANCE_MARGIN("npc.pathfinding.default-path-distance-margin", 1),
DEFAULT_PATHFINDER_UPDATE_PATH_RATE("npc.pathfinding.update-path-rate", 20),
DEFAULT_PATHFINDING_RANGE("npc.default.pathfinding.range", 25F),
Expand All @@ -95,43 +92,33 @@ public void loadFromKey(DataKey root) {
value = list;
}
},
DISABLE_TABLIST("npc.tablist.disable", true),
ERROR_COLOUR("general.color-scheme.message-error", "<c>"),
DISABLE_TABLIST("npc.tablist.disable", true), ERROR_COLOUR("general.color-scheme.message-error", "<c>"),
HIGHLIGHT_COLOUR("general.color-scheme.message-highlight", "<e>"),
KEEP_CHUNKS_LOADED("npc.chunks.always-keep-loaded", false),
LOCALE("general.translation.locale", ""),
KEEP_CHUNKS_LOADED("npc.chunks.always-keep-loaded", false), LOCALE("general.translation.locale", ""),
MAX_CONTROLLABLE_GROUND_SPEED("npc.controllable.max-ground-speed", 0.5),
MAX_NPC_LIMIT_CHECKS("npc.limits.max-permission-checks", 100),
MAX_NPC_SKIN_RETRIES("npc.skins.max-retries", -1),
MAX_PACKET_ENTRIES("npc.limits.max-packet-entries", 15),
MAX_SPEED("npc.limits.max-speed", 100),
MAX_TEXT_RANGE("npc.chat.options.max-text-range", 500),
MAX_NPC_SKIN_RETRIES("npc.skins.max-retries", -1), MAX_PACKET_ENTRIES("npc.limits.max-packet-entries", 15),
MAX_SPEED("npc.limits.max-speed", 100), MAX_TEXT_RANGE("npc.chat.options.max-text-range", 500),
MAXIMUM_ASTAR_ITERATIONS("npc.pathfinding.maximum-new-pathfinder-iterations", 50000),
MESSAGE_COLOUR("general.color-scheme.message", "<a>"),
NEW_PATHFINDER_OPENS_DOORS("npc.pathfinding.new-finder-open-doors", false),
NPC_ATTACK_DISTANCE("npc.pathfinding.attack-range", 1.75 * 1.75),
NPC_COST("economy.npc.cost", 100D),
NPC_ATTACK_DISTANCE("npc.pathfinding.attack-range", 1.75 * 1.75), NPC_COST("economy.npc.cost", 100D),
NPC_SKIN_RETRY_DELAY("npc.skins.retry-delay", 120),
NPC_SKIN_ROTATION_UPDATE_DEGREES("npc.skins.rotation-update-degrees", 90f),
NPC_SKIN_USE_LATEST("npc.skins.use-latest-by-default", false),
NPC_SKIN_VIEW_DISTANCE("npc.skins.view-distance", 100D),
PACKET_UPDATE_DELAY("npc.packets.update-delay", 30),
NPC_SKIN_VIEW_DISTANCE("npc.skins.view-distance", 100D), PACKET_UPDATE_DELAY("npc.packets.update-delay", 30),
QUICK_SELECT("npc.selection.quick-select", false),
REMOVE_PLAYERS_FROM_PLAYER_LIST("npc.player.remove-from-list", true),
SAVE_TASK_DELAY("storage.save-task.delay", 20 * 60 * 60),
SELECTION_ITEM("npc.selection.item", "stick"),
SAVE_TASK_DELAY("storage.save-task.delay", 20 * 60 * 60), SELECTION_ITEM("npc.selection.item", "stick"),
SELECTION_MESSAGE("npc.selection.message", "<b>You selected <a><npc><b>!"),
SERVER_OWNS_NPCS("npc.server-ownership", false),
STORAGE_FILE("storage.file", "saves.yml"),
STORAGE_TYPE("storage.type", "yaml"),
SUBPLUGIN_FOLDER("subplugins.folder", "plugins"),
SERVER_OWNS_NPCS("npc.server-ownership", false), STORAGE_FILE("storage.file", "saves.yml"),
STORAGE_TYPE("storage.type", "yaml"), SUBPLUGIN_FOLDER("subplugins.folder", "plugins"),
TALK_CLOSE_MAXIMUM_COOLDOWN("npc.text.max-talk-cooldown", 5),
TALK_CLOSE_MINIMUM_COOLDOWN("npc.text.min-talk-cooldown", 10),
TALK_ITEM("npc.text.talk-item", "book"),
TELEPORT_DELAY("npc.teleport-delay", -1),
USE_BOAT_CONTROLS("npc.controllable.use-boat-controls", true),
TALK_CLOSE_MINIMUM_COOLDOWN("npc.text.min-talk-cooldown", 10), TALK_ITEM("npc.text.talk-item", "book"),
TELEPORT_DELAY("npc.teleport-delay", -1), USE_BOAT_CONTROLS("npc.controllable.use-boat-controls", true),
USE_NEW_PATHFINDER("npc.pathfinding.use-new-finder", false),
USE_SCOREBOARD_TEAMS("npc.player-scoreboard-teams.enable", true);
USE_SCOREBOARD_TEAMS("npc.player-scoreboard-teams.enable", true),
DISABLE_LOOKCLOSE_WHILE_NAVIGATING("npc.default.look-close.disable-while-navigating", true);

protected String path;
protected Object value;
Expand Down
23 changes: 16 additions & 7 deletions main/src/main/java/net/citizensnpcs/trait/LookClose.java
Expand Up @@ -52,8 +52,8 @@ public LookClose() {
}

/**
* Returns whether the target can be seen. Will use realistic line of sight if {@link #setRealisticLooking(boolean)}
* is true.
* Returns whether the target can be seen. Will use realistic line of sight if
* {@link #setRealisticLooking(boolean)} is true.
*/
public boolean canSeeTarget() {
return realisticLooking && npc.getEntity() instanceof LivingEntity
Expand Down Expand Up @@ -107,8 +107,9 @@ private boolean hasInvalidTarget() {

private boolean isPluginVanished(Player player) {
for (MetadataValue meta : player.getMetadata("vanished")) {
if (meta.asBoolean())
if (meta.asBoolean()) {
return true;
}
}
return false;
}
Expand Down Expand Up @@ -139,8 +140,12 @@ private void randomLook() {

@Override
public void run() {
if (!enabled || !npc.isSpawned() || npc.getNavigator().isNavigating())
if (!enabled || !npc.isSpawned()) {
return;
}
if (npc.getNavigator().isNavigating() && Setting.DISABLE_LOOKCLOSE_WHILE_NAVIGATING.asBoolean()) {
return;
}
// TODO: remove in a later version, defaults weren't saving properly
if (randomPitchRange == null || randomPitchRange.length != 2) {
randomPitchRange = new float[] { -10, 0 };
Expand All @@ -152,7 +157,9 @@ public void run() {
if (hasInvalidTarget()) {
findNewTarget();
}
if (lookingAt == null && enableRandomLook && t <= 0) {
if (npc.getNavigator().isNavigating()) {
npc.getNavigator().setPaused(lookingAt != null);
} else if (lookingAt == null && enableRandomLook && t <= 0) {
randomLook();
t = randomLookDelay;
}
Expand All @@ -172,7 +179,8 @@ public void save(DataKey key) {
}

/**
* Enables random looking - will look at a random {@link Location} every so often if enabled.
* Enables random looking - will look at a random {@link Location} every so
* often if enabled.
*/
public void setRandomLook(boolean enableRandomLook) {
this.enableRandomLook = enableRandomLook;
Expand Down Expand Up @@ -201,7 +209,8 @@ public void setRange(int range) {
}

/**
* Enables/disables realistic looking (using line of sight checks). More computationally expensive.
* Enables/disables realistic looking (using line of sight checks). More
* computationally expensive.
*/
public void setRealisticLooking(boolean realistic) {
this.realisticLooking = realistic;
Expand Down

0 comments on commit a8676cd

Please sign in to comment.