use of org.spongepowered.api.entity.ai.Goal in project SpongeCommon by SpongePowered.
the class MixinEntityAITasks method removeTask.
/**
* @author Zidane - November 30th, 2015
* @reason Integrate Sponge events into the AI task removal.
*
* @param aiBase
*/
@SuppressWarnings({ "rawtypes" })
@Overwrite
public void removeTask(EntityAIBase aiBase) {
final Iterator iterator = this.taskEntries.iterator();
while (iterator.hasNext()) {
final EntityAITasks.EntityAITaskEntry entityaitaskentry = (EntityAITasks.EntityAITaskEntry) iterator.next();
final EntityAIBase otherAiBase = entityaitaskentry.action;
// Sponge start
if (otherAiBase.equals(aiBase)) {
AITaskEvent.Remove event = null;
if (ShouldFire.AI_TASK_EVENT_REMOVE && this.owner != null && !((IMixinEntity) this.owner).isInConstructPhase()) {
event = SpongeEventFactory.createAITaskEventRemove(Sponge.getCauseStackManager().getCurrentCause(), (Goal) this, (Agent) this.owner, (AITask) otherAiBase, entityaitaskentry.priority);
SpongeImpl.postEvent(event);
}
if (event == null || !event.isCancelled()) {
if (entityaitaskentry.using) {
entityaitaskentry.using = false;
otherAiBase.resetTask();
this.executingTaskEntries.remove(entityaitaskentry);
}
iterator.remove();
return;
}
}
// Sponge end
}
}
use of org.spongepowered.api.entity.ai.Goal in project SpongeAPI by SpongePowered.
the class SpongeAITaskEventTest method testAITaskEventRemove_invalidTargetAgentAndGoalOwner.
@Test(expected = IllegalArgumentException.class)
public void testAITaskEventRemove_invalidTargetAgentAndGoalOwner() {
Agent targetEntity = mock(Agent.class);
Agent secondEntity = mock(Agent.class);
Goal goal = mock(Goal.class);
Mockito.when(goal.getOwner()).thenReturn(secondEntity);
SpongeEventFactory.createAITaskEventRemove(Cause.of(EventContext.empty(), mock(Game.class)), goal, targetEntity, mock(AITask.class), 0);
}
use of org.spongepowered.api.entity.ai.Goal in project SpongeCommon by SpongePowered.
the class MixinEntityAITasks method goal$removeTasks.
public Goal<?> goal$removeTasks(AITaskType type) {
Iterator<EntityAITasks.EntityAITaskEntry> iterator = this.taskEntries.iterator();
while (iterator.hasNext()) {
final EntityAITasks.EntityAITaskEntry entityaitaskentry = iterator.next();
final EntityAIBase otherAiBase = entityaitaskentry.action;
final AITask<?> otherTask = (AITask<?>) otherAiBase;
if (otherTask.getType().equals(type)) {
if (this.executingTaskEntries.contains(entityaitaskentry)) {
otherAiBase.resetTask();
this.executingTaskEntries.remove(entityaitaskentry);
}
iterator.remove();
}
}
return (Goal<?>) this;
}
use of org.spongepowered.api.entity.ai.Goal in project SpongeCommon by SpongePowered.
the class GoalTypeModule method createGoalType.
private GoalType createGoalType(String combinedId, String name) {
@SuppressWarnings("unchecked") final SpongeGoalType newType = new SpongeGoalType(combinedId, name, (Class<Goal<?>>) (Class<?>) EntityAITasks.class);
this.goalTypes.put(combinedId, newType);
return newType;
}
use of org.spongepowered.api.entity.ai.Goal in project SpongeAPI by SpongePowered.
the class SpongeAITaskEventTest method testAITaskEventAdd_invalidTargetAgentAndGoalOwner.
@Test(expected = IllegalArgumentException.class)
public void testAITaskEventAdd_invalidTargetAgentAndGoalOwner() {
Agent targetEntity = mock(Agent.class);
Agent secondEntity = mock(Agent.class);
Goal goal = mock(Goal.class);
Mockito.when(goal.getOwner()).thenReturn(secondEntity);
SpongeEventFactory.createAITaskEventAdd(Cause.of(EventContext.empty(), mock(Game.class)), 0, 0, goal, targetEntity, mock(AITask.class));
}
Aggregations