Search in sources :

Example 6 with Agent

use of org.spongepowered.api.entity.living.Agent 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

Agent (org.spongepowered.api.entity.living.Agent)6 AITask (org.spongepowered.api.entity.ai.task.AITask)5 Goal (org.spongepowered.api.entity.ai.Goal)4 Test (org.junit.Test)3 IMixinEntityAIBase (org.spongepowered.common.interfaces.ai.IMixinEntityAIBase)2 BlockQueueEntry (com.karanumcoding.adamantineshield.db.queue.BlockQueueEntry)1 Date (java.util.Date)1 Iterator (java.util.Iterator)1 EntityAIBase (net.minecraft.entity.ai.EntityAIBase)1 EntityAITasks (net.minecraft.entity.ai.EntityAITasks)1 BlockSnapshot (org.spongepowered.api.block.BlockSnapshot)1 AITaskType (org.spongepowered.api.entity.ai.task.AITaskType)1 AbstractAITask (org.spongepowered.api.entity.ai.task.AbstractAITask)1 Player (org.spongepowered.api.entity.living.player.Player)1 Listener (org.spongepowered.api.event.Listener)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 IMixinEntityAITasks (org.spongepowered.common.interfaces.ai.IMixinEntityAITasks)1