Skip to content

Commit

Permalink
Add sneak metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed Sep 20, 2021
1 parent 3a745f3 commit 81a4ad5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
Expand Up @@ -87,28 +87,33 @@ public void run(final NPC npc, Block point, ListIterator<Block> path) {
added = true;
return;
}
Runnable callback = new Runnable() {
npc.getNavigator().getLocalParameters().addRunCallback(new Runnable() {
Location dummy = new Location(null, 0, 0, 0);
boolean sneakingForScaffolding;

@Override
public void run() {
Material type = npc.getEntity().getLocation(dummy).getBlock().getType();
if (isClimbable(type)) {
if (current.next().getY() > current.previous().getY()) {
npc.getEntity().setVelocity(npc.getEntity().getVelocity().setY(0.3));
if (sneakingForScaffolding) {
npc.data().set(NPC.SNEAKING_METADATA, sneakingForScaffolding = false);
}
} else if (type.name().equals("SCAFFOLDING")) {
npc.getEntity().setVelocity(npc.getEntity().getVelocity().setY(-0.3));
npc.data().set(NPC.SNEAKING_METADATA, sneakingForScaffolding = true);
}
} else if (sneakingForScaffolding) {
npc.data().set(NPC.SNEAKING_METADATA, sneakingForScaffolding = false);
}
}
};
});
npc.getNavigator().getLocalParameters().addSingleUseCallback(new NavigatorCallback() {
@Override
public void onCompletion(CancelReason cancelReason) {
npc.data().set("running-ladder", false);
}
});
npc.getNavigator().getLocalParameters().addRunCallback(callback);
added = true;
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/net/citizensnpcs/api/npc/NPC.java
Expand Up @@ -464,6 +464,10 @@ public interface NPC extends Agent, Cloneable {
* Whether to suppress sounds. Boolean.
*/
public static final String SILENT_METADATA = "silent-sounds";
/**
* Whether to sneak. Boolean.
*/
public static final String SNEAKING_METADATA = "citizens-sneaking";
/**
* Whether to allow swimming. Boolean.
*/
Expand Down

0 comments on commit 81a4ad5

Please sign in to comment.