Search in sources :

Example 1 with AITask

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
    }
}
Also used : Agent(org.spongepowered.api.entity.living.Agent) AITaskEvent(org.spongepowered.api.event.entity.ai.AITaskEvent) Goal(org.spongepowered.api.entity.ai.Goal) IMixinEntityAIBase(org.spongepowered.common.interfaces.ai.IMixinEntityAIBase) EntityAIBase(net.minecraft.entity.ai.EntityAIBase) Iterator(java.util.Iterator) EntityAITasks(net.minecraft.entity.ai.EntityAITasks) IMixinEntityAITasks(org.spongepowered.common.interfaces.ai.IMixinEntityAITasks) IMixinEntity(org.spongepowered.common.interfaces.entity.IMixinEntity) AITask(org.spongepowered.api.entity.ai.task.AITask) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 2 with AITask

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;
}
Also used : Goal(org.spongepowered.api.entity.ai.Goal) IMixinEntityAIBase(org.spongepowered.common.interfaces.ai.IMixinEntityAIBase) EntityAIBase(net.minecraft.entity.ai.EntityAIBase) EntityAITasks(net.minecraft.entity.ai.EntityAITasks) IMixinEntityAITasks(org.spongepowered.common.interfaces.ai.IMixinEntityAITasks) AITask(org.spongepowered.api.entity.ai.task.AITask)

Example 3 with AITask

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()));
    }
}
Also used : Agent(org.spongepowered.api.entity.living.Agent) PluginContainer(org.spongepowered.api.plugin.PluginContainer) AITaskType(org.spongepowered.api.entity.ai.task.AITaskType) IMixinEntityAIBase(org.spongepowered.common.interfaces.ai.IMixinEntityAIBase) AbstractAITask(org.spongepowered.api.entity.ai.task.AbstractAITask) AITask(org.spongepowered.api.entity.ai.task.AITask) Inject(org.spongepowered.asm.mixin.injection.Inject)

Aggregations

AITask (org.spongepowered.api.entity.ai.task.AITask)3 IMixinEntityAIBase (org.spongepowered.common.interfaces.ai.IMixinEntityAIBase)3 EntityAIBase (net.minecraft.entity.ai.EntityAIBase)2 EntityAITasks (net.minecraft.entity.ai.EntityAITasks)2 Goal (org.spongepowered.api.entity.ai.Goal)2 Agent (org.spongepowered.api.entity.living.Agent)2 IMixinEntityAITasks (org.spongepowered.common.interfaces.ai.IMixinEntityAITasks)2 Iterator (java.util.Iterator)1 AITaskType (org.spongepowered.api.entity.ai.task.AITaskType)1 AbstractAITask (org.spongepowered.api.entity.ai.task.AbstractAITask)1 AITaskEvent (org.spongepowered.api.event.entity.ai.AITaskEvent)1 PluginContainer (org.spongepowered.api.plugin.PluginContainer)1 Overwrite (org.spongepowered.asm.mixin.Overwrite)1 Inject (org.spongepowered.asm.mixin.injection.Inject)1 IMixinEntity (org.spongepowered.common.interfaces.entity.IMixinEntity)1