use of org.spongepowered.common.interfaces.ai.IMixinEntityAIBase 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