Skip to content

Commit

Permalink
Add new AI API
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed Apr 20, 2020
1 parent 7a37f5f commit e5fad8b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/main/java/net/citizensnpcs/api/npc/AbstractNPC.java
Expand Up @@ -380,6 +380,11 @@ public void setProtected(boolean isProtected) {
data().setPersistent(NPC.DEFAULT_PROTECTED_METADATA, isProtected);
}

@Override
public void setUseMinecraftAI(boolean use) {
data().setPersistent(NPC.USE_MINECRAFT_AI_METADATA, use);
}

private void teleport(final Entity entity, Location location, int delay) {
final Entity passenger = entity.getPassenger();
entity.eject();
Expand Down Expand Up @@ -433,4 +438,9 @@ public void update() {
goalController.run();
}
}

@Override
public boolean useMinecraftAI() {
return data().get(NPC.USE_MINECRAFT_AI_METADATA, false);
}
}
15 changes: 15 additions & 0 deletions src/main/java/net/citizensnpcs/api/npc/NPC.java
Expand Up @@ -265,6 +265,12 @@ public interface NPC extends Agent, Cloneable {
*/
public void setProtected(boolean isProtected);

/**
* Set the NPC to use Minecraft AI where possible. Note that the NPC may not always behave exactly like a Minecraft
* mob would because of additional Citizens APIs.
*/
public void setUseMinecraftAI(boolean use);

/**
* Attempts to spawn this NPC.
*
Expand Down Expand Up @@ -295,6 +301,11 @@ public interface NPC extends Agent, Cloneable {
*/
public void teleport(Location location, TeleportCause cause);

/**
* Whether the NPC is currently set to use Minecraft AI. Defaults to false.
*/
public boolean useMinecraftAI();

/**
* The Minecraft ambient sound played. String - Minecraft sound name
*/
Expand Down Expand Up @@ -413,4 +424,8 @@ public interface NPC extends Agent, Cloneable {
* Whether to prevent NPC being targeted by hostile mobs. Boolean.
*/
public static final String TARGETABLE_METADATA = "protected-target";
/**
* Whether to use Minecraft AI. Boolean.
*/
public static final String USE_MINECRAFT_AI_METADATA = "minecraft-ai";
}

0 comments on commit e5fad8b

Please sign in to comment.