Search in sources :

Example 1 with AITaskType

use of org.spongepowered.api.entity.ai.task.AITaskType 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)1 AITaskType (org.spongepowered.api.entity.ai.task.AITaskType)1 AbstractAITask (org.spongepowered.api.entity.ai.task.AbstractAITask)1 Agent (org.spongepowered.api.entity.living.Agent)1 PluginContainer (org.spongepowered.api.plugin.PluginContainer)1 Inject (org.spongepowered.asm.mixin.injection.Inject)1 IMixinEntityAIBase (org.spongepowered.common.interfaces.ai.IMixinEntityAIBase)1