88import java .util .Iterator ;
99import java .util .LinkedList ;
1010import java .util .List ;
11+ import java .util .Map ;
1112import java .util .Set ;
1213
1314import net .minecraft .server .v1_6_R3 .EntityInsentient ;
2728import de .ntcomputer .minecraft .controllablemobs .implementation .nativeinterfaces .primitives .NativeFieldObject ;
2829
2930public abstract class AIController <E extends LivingEntity > implements Comparator <Object > {
30- private ArrayList <PathfinderGoalWrapper > actionGoals ;
31- private ArrayList <CraftAIPart <E ,?>> attachedParts ;
32- private ArrayList <CraftAIPart <E ,?>> defaultParts ;
31+ private List <PathfinderGoalWrapper > actionGoals ;
32+ private List <CraftAIPart <E ,?>> attachedParts ;
33+ private List <CraftAIPart <E ,?>> defaultParts ;
3334 private PathfinderGoalAIMonitor monitor ;
3435 CraftControllableMob <E > mob ;
3536 int lastBehaviorPriority = 1 ;
3637 public PathfinderGoalSelector selector ;
37- public HashMap <PathfinderGoal ,CraftAIPart <E ,?>> goalPartMap ;
38+ public Map <PathfinderGoal ,CraftAIPart <E ,?>> goalPartMap ;
3839
3940 public AIController (CraftControllableMob <E > mob , NativeFieldObject <EntityInsentient ,PathfinderGoalSelector > selectorField ) {
4041 this .mob = mob ;
@@ -205,12 +206,19 @@ void get(List<? super CraftAIPart<E,?>> list, Set<AIType> types) {
205206
206207 void clear () {
207208 this .clearGoals ();
209+ PathfinderGoal [] goals = new PathfinderGoal [this .attachedParts .size ()];
210+ int i = 0 ;
208211 for (CraftAIPart <E ,?> part : this .attachedParts ) {
212+ goals [i ++] = part .goal ;
209213 part .setState (AIState .UNATTACHED );
210214 }
211215 this .attachedParts .clear ();
212216 this .goalPartMap .clear ();
213217 this .monitor .reset ();
218+
219+ for (PathfinderGoal goal : goals ) {
220+ AIComponentHandlers .handleRemoved (mob , goal );
221+ }
214222 }
215223
216224 void reset () {
@@ -224,7 +232,7 @@ void reset() {
224232 // disposing
225233
226234 private void disposedCall () throws IllegalStateException {
227- if (this .selector ==null ) throw new IllegalStateException ("[ControllableMobsAPI] you must not modify AI parts after the ControllableMob has been unassigned " );
235+ if (this .selector ==null ) throw new IllegalStateException ("[ControllableMobsAPI] you must not modify AI parts after the ControllableMob has been released " );
228236 }
229237
230238 void dispose () {
0 commit comments