Skip to content

NPCTag.can_navigate_to Tag & NPCTag Modernization#2811

Open
MC-Samuel wants to merge 9 commits into
DenizenScript:devfrom
MC-Samuel:NPCTag-updates
Open

NPCTag.can_navigate_to Tag & NPCTag Modernization#2811
MC-Samuel wants to merge 9 commits into
DenizenScript:devfrom
MC-Samuel:NPCTag-updates

Conversation

@MC-Samuel

Copy link
Copy Markdown
Contributor
  • Added NPCTag.can_navigate_to[<location>] tag
  • Updated mechanisms from old method to tagProcessor
  • Modernized tags that require a specific ObjectType as a parameter
  • Converted most ListTags to a simpler format

list.add(anchor.getName());
}
return list;
return new ListTag(object.getCitizen().getOrAddTrait(Anchors.class).getAnchors(), anchor -> new ElementTag(anchor.getName()));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these can be plain elements

Comment thread plugin/src/main/java/com/denizenscript/denizen/objects/NPCTag.java
}
tagProcessor.registerTag(LocationTag.class, ElementTag.class, "pose", (attribute, object, param) -> {
Pose pose = object.getCitizen().getOrAddTrait(Poses.class).getPose(param.asString());
return new LocationTag(org.bukkit.Bukkit.getWorlds().get(0), 0, 0, 0, pose.getYaw(), pose.getPitch());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless there's some specific input conflict, can probably clean this FQN up

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bump?

// Returns whether an NPC can navigate to a specified location.
// -->
tagProcessor.registerTag(ElementTag.class, LocationTag.class, "can_navigate_to", (attribute, object, param) -> {
return new ElementTag(object.npc.getNavigator().canNavigateTo(param));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably #getCitizen like the rest of the tags/mechs?

}
else {
mechanism.echoError("Must set waypoint_provider to 'wander' before setting wander_xrange!");
if (mechanism.requireInteger()) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why undo the early return? Usually less nesting is nicer to read and follow

else {
BukkitImplDeprecations.assignmentRemove.warn(mechanism.context);
object.getCitizen().getOrAddTrait(AssignmentTrait.class).clearAssignments(null);
object.npc.removeTrait(AssignmentTrait.class);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe do #getCitizen for these ones as well, so that they're not randomly different from themselves/the rest of the tags/mechs

Comment thread plugin/src/main/java/com/denizenscript/denizen/objects/NPCTag.java
Comment on lines +1523 to +1524
HologramTrait hologram = object.getCitizen().getOrAddTrait(HologramTrait.class);
hologram.setLineHeight(input.asDouble());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably single line here

}
}
tagProcessor.registerMechanism("owner", false, PlayerTag.class, (object, mechanism, input) -> {
object.getCitizen().getOrAddTrait(Owner.class).setOwner(input.getPlayerEntity());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about the alternative String behavior this had? Are we sure it's safe to remove?

Material mat = item.getMaterial().getMaterial();
Entity npcEntity = getEntity();
tagProcessor.registerMechanism("item_type", false, ItemTag.class, (object, mechanism, input) -> {
Material mat = input.getMaterial().getMaterial();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#getBukkitMaterial

Comment on lines +1779 to +1782
if (mechanism.requireBoolean()) {
if (!object.getCitizen().hasTrait(SneakingTrait.class)) {
object.getCitizen().addTrait(SneakingTrait.class);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Early return would be nicer here, also that hasTrait -> addTrait is just legacy code from before getOrAddTrait I believe, so can be removed.

Comment on lines +1961 to +1934
final LocationTag loc = mechanism.valueAsType(LocationTag.class);
getNavigator().getLocalParameters().lookAtFunction((n) -> loc);
object.getNavigator().getLocalParameters().lookAtFunction((n) -> mechanism.valueAsType(LocationTag.class));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would have it parse the location repeatedly every time the lookAt function is called

Comment on lines +1864 to +1869
if (input.asBoolean()) {
object.getNavigator().getDefaultParameters().stuckAction(TeleportStuckAction.INSTANCE);
}
else {
object.getNavigator().getDefaultParameters().stuckAction(null);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could be just tern

}
tagProcessor.registerTag(LocationTag.class, ElementTag.class, "pose", (attribute, object, param) -> {
Pose pose = object.getCitizen().getOrAddTrait(Poses.class).getPose(param.asString());
return new LocationTag(org.bukkit.Bukkit.getWorlds().get(0), 0, 0, 0, pose.getYaw(), pose.getPitch());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bump?

}
else {
mechanism.echoError("Must set waypoint_provider to 'wander' before setting wander_yrange!");
if (mechanism.requireInteger()) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove the early return?

Comment thread plugin/src/main/java/com/denizenscript/denizen/objects/NPCTag.java
Comment thread plugin/src/main/java/com/denizenscript/denizen/objects/NPCTag.java
}
}
tagProcessor.registerMechanism("owner", false, (object, mechanism) -> {
object.getCitizen().getOrAddTrait(Owner.class).setOwner(mechanism.getValue().canBeType(PlayerTag.class) ? mechanism.valueAsType(PlayerTag.class).getPlayerEntity() : null);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the owner can also be an OfflinePlayer looking at Citizens? No reason to limit it to getPlayerEntity here if that's the case.

}
SneakingTrait trait = getCitizen().getOrAddTrait(SneakingTrait.class);
SneakingTrait trait = object.getCitizen().getOrAddTrait(SneakingTrait.class);
if (trait.isSneaking() && !mechanism.getValue().asBoolean()) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mechanism#getValue -> input

// @input ElementTag
// @description
// Sets the NPC's nickname.
// Sets the NPC's nickname. Leave blank to remove the nickname.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly on second thought I'm not sure if I like this, if the entire mechanism was just being added sure, but seeing as this is already present in an existing feature (that isn't being deprecated or anything) adding duplicate functionality just for the sake of it seems a bit messy.
Not forbidding this if you really want it or anything, but just my opinion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants