Skip to content

Commit

Permalink
NPCTag.navigator_look_at tag/mech pair
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed May 29, 2021
1 parent 80f65d3 commit 84e9010
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions plugin/src/main/java/com/denizenscript/denizen/objects/NPCTag.java
Expand Up @@ -1134,6 +1134,24 @@ else if (attribute.startsWith("list", 2)) {
return new LocationTag(object.getNavigator().getTargetAsLocation());
});

// <--[tag]
// @attribute <NPCTag.navigator_look_at>
// @returns LocationTag
// @mechanism NPCTag.navigator_look_at
// @description
// Returns the location the NPC will currently look at while moving, if any.
// -->
registerTag("navigator_look_at", (attribute, object) -> {
if (object.getNavigator().getLocalParameters().lookAtFunction() == null) {
return null;
}
Location res = object.getNavigator().getLocalParameters().lookAtFunction().apply(object.getNavigator());
if (res == null) {
return null;
}
return new LocationTag(res);
});

// <--[tag]
// @attribute <NPCTag.is_fighting>
// @returns ElementTag(Boolean)
Expand Down Expand Up @@ -1636,6 +1654,27 @@ else if (!trait.isSneaking() && mechanism.getValue().asBoolean()) {
getNavigator().getDefaultParameters().pathDistanceMargin(mechanism.getValue().asDouble());
}

// <--[mechanism]
// @object NPCTag
// @name navigator_look_at
// @input LocationTag
// @description
// Sets the location the NPC will currently look at while moving.
// Give no value to let the NPC automatically look where it's going.
// Should be set after the NPC has started moving.
// @tags
// <NPCTag.navigator_look_at>
// -->
if (mechanism.matches("navigator_look_at")) {
if (mechanism.hasValue() && mechanism.requireObject(LocationTag.class)) {
final LocationTag loc = mechanism.valueAsType(LocationTag.class);
getNavigator().getLocalParameters().lookAtFunction((n) -> loc);
}
else {
getNavigator().getLocalParameters().lookAtFunction(null);
}
}

// <--[mechanism]
// @object NPCTag
// @name name_visible
Expand Down

0 comments on commit 84e9010

Please sign in to comment.