Skip to content

Commit 4acd9fe

Browse files
committed
added hasBehavior(AIType...)
1 parent 4857fdf commit 4acd9fe

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

src/java/de/ntcomputer/minecraft/controllablemobs/api/ControllableMobAI.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,12 @@ public interface ControllableMobAI<E extends LivingEntity> {
8989
*/
9090
public boolean hasBehavior(AIType type);
9191

92+
/**
93+
* Checks whether the entity has a behavior of at least one of the given type.
94+
* @param types the types to check for
95+
* @return true, if this mob has an AI behavior of at least one of the specified types, and false otherwise
96+
* @throws IllegalArgumentException when types is null or empty
97+
*/
98+
public boolean hasBehavior(AIType... types) throws IllegalArgumentException;
99+
92100
}

src/java/de/ntcomputer/minecraft/controllablemobs/implementation/CraftControllableMobAI.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,10 @@ public boolean hasBehavior(AIType type) {
8383
return parts.toArray(new AIPart[0]);
8484
}
8585

86+
@Override
87+
public boolean hasBehavior(AIType... types) throws IllegalArgumentException {
88+
if(types==null || types.length==0) throw new IllegalArgumentException("types must not be null or empty");
89+
return this.dispatcher.contains(types);
90+
}
91+
8692
}

src/java/de/ntcomputer/minecraft/controllablemobs/implementation/ai/AIDispatcher.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ public boolean contains(AIType type) {
4040
return false;
4141
}
4242

43+
public boolean contains(AIType... types) {
44+
for(AIType type: types) {
45+
if(this.goalController.contains(type)) return true;
46+
if(this.targetController.contains(type)) return true;
47+
}
48+
return false;
49+
}
50+
4351
public void get(List<AIPart<E,?>> list, AIType[] types) {
4452
Set<AIType> typeSet = null;
4553
if(types!=null) {

0 commit comments

Comments
 (0)