use of org.spongepowered.api.entity.ai.task.AITask 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.task.AITask 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.task.AITask in project SpongeForge by SpongePowered.
the class MixinEntityAIBase method addModAIType.
@SuppressWarnings({ "unchecked", "ConstantConditions" })
@Inject(method = "<init>", at = @At(value = "RETURN"))
public void addModAIType(CallbackInfo ci) {
// Only set a type if we have none
if (((AITask<Agent>) this).getType() != null) {
return;
}
// API custom tasks handle types differently, ignore
if (AbstractAITask.class.isAssignableFrom(getClass())) {
return;
}
// Handle adding mod/un-implemented Minecraft tasks.
final Optional<AITaskType> optModType = AITaskTypeModule.getInstance().getByAIClass(getClass());
if (!optModType.isPresent()) {
PluginContainer container = (PluginContainer) Loader.instance().activeModContainer();
// FML couldn't figure out the mod...give the task to Minecraft
if (container == null) {
// May need to log this...
container = SpongeImpl.getMinecraftPlugin();
}
final String idAndName = getClass().getSimpleName();
((IMixinEntityAIBase) this).setType(AITaskTypeModule.getInstance().createAITaskType(container, idAndName, idAndName, (Class<? extends AITask<? extends Agent>>) getClass()));
}
}
Aggregations