Skip to content

Commit c3f7493

Browse files
committed
added invocation of removed-handlers when AI is cleared
1 parent 2611295 commit c3f7493

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import java.util.Iterator;
99
import java.util.LinkedList;
1010
import java.util.List;
11+
import java.util.Map;
1112
import java.util.Set;
1213

1314
import net.minecraft.server.v1_6_R3.EntityInsentient;
@@ -27,14 +28,14 @@
2728
import de.ntcomputer.minecraft.controllablemobs.implementation.nativeinterfaces.primitives.NativeFieldObject;
2829

2930
public 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

Comments
 (0)