net.minecraft.entity.ai.EntityAITasks.EntityAITaskEntry Java Examples

The following examples show how to use net.minecraft.entity.ai.EntityAITasks.EntityAITaskEntry. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ServerEventHandler.java    From Et-Futurum with The Unlicense 6 votes vote down vote up
@SubscribeEvent
public void spawnEvent(EntityJoinWorldEvent event) {
	if (event.entity instanceof EntityPig) {
		EntityPig pig = (EntityPig) event.entity;
		if (EtFuturum.enableBeetroot)
			pig.tasks.addTask(4, new EntityAITempt(pig, 1.2, ModItems.beetroot, false));
	} else if (event.entity instanceof EntityChicken) {
		EntityChicken chicken = (EntityChicken) event.entity;
		if (EtFuturum.enableBeetroot)
			chicken.tasks.addTask(3, new EntityAITempt(chicken, 1.0D, ModItems.beetroot_seeds, false));
	} else if (event.entity instanceof EntityWolf) {
		EntityWolf wolf = (EntityWolf) event.entity;
		if (EtFuturum.enableRabbit)
			wolf.targetTasks.addTask(4, new EntityAITargetNonTamed(wolf, EntityRabbit.class, 200, false));
	} else if (event.entity instanceof EntityVillager) {
		EntityVillager villager = (EntityVillager) event.entity;
		for (Object obj : villager.tasks.taskEntries) {
			EntityAITaskEntry entry = (EntityAITaskEntry) obj;
			if (entry.action instanceof EntityAIOpenDoor) {
				villager.tasks.removeTask(entry.action);
				villager.tasks.addTask(entry.priority, new EntityAIOpenCustomDoor(villager, true));
				break;
			}
		}
	}
}
 
Example #2
Source File: EntityUtils.java    From enderutilities with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Removes the (last found) dummy blocker AI task, if any
 * @param tasks
 */
public static void removeDummyAIBlockerTask(EntityAITasks tasks)
{
    EntityAIBase task = null;

    for (EntityAITaskEntry taskEntry : tasks.taskEntries)
    {
        if (taskEntry.action instanceof EntityAIDummyBlockerTask)
        {
            task = taskEntry.action;
        }

        // Restore the default mutex bits.
        // TODO: If modded mob tasks use this bit, then we should store the original value so we can restore it.
        if (taskEntry.action instanceof EntityAIFindEntityNearestPlayer)
        {
            taskEntry.action.setMutexBits(taskEntry.action.getMutexBits() & 0x7F);
        }
    }

    if (task != null)
    {
        tasks.removeTask(task);
    }
}
 
Example #3
Source File: EntityUtil.java    From EnderZoo with Creative Commons Zero v1.0 Universal 6 votes vote down vote up
public static void cancelCurrentTasks(EntityLiving ent) {
  Iterator<EntityAITaskEntry> iterator = ent.tasks.taskEntries.iterator();
  List<EntityAITasks.EntityAITaskEntry> currentTasks = new ArrayList<EntityAITasks.EntityAITaskEntry>();
  while (iterator.hasNext()) {
    EntityAITaskEntry entityaitaskentry = iterator.next();
    if (entityaitaskentry != null) {
      currentTasks.add(entityaitaskentry);
    }
  }
  // Only available way to stop current execution is to remove all current
  // tasks, then re-add them
  for (EntityAITaskEntry task : currentTasks) {
    ent.tasks.removeTask(task.action);
    ent.tasks.addTask(task.priority, task.action);
  }
  ent.getNavigator().clearPathEntity();
}
 
Example #4
Source File: EntityUtils.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Removes all AI tasks from the given EntityAITasks object
 * @param tasks the EntityAITasks object to remove the tasks from
 * @return true if at least some tasks were removed
 */
public static boolean removeAllAITasks(EntityAITasks tasks)
{
    List<EntityAITaskEntry> taskList = new ArrayList<EntityAITaskEntry>(tasks.taskEntries);

    for (EntityAITaskEntry taskEntry : taskList)
    {
        tasks.removeTask(taskEntry.action);
    }

    return taskList.isEmpty() == false;
}
 
Example #5
Source File: EntityUtils.java    From enderutilities with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Adds the AI task 'task' to 'entity' after all the existing tasks of types in 'afterTasks' 
 * @param living
 * @param task
 * @param afterTasks
 * @return
 */
public static <T extends EntityAIBase> boolean addAITaskAfterTasks(EntityLiving living, EntityAIBase task, boolean replaceMatching, Class<T>[] afterTasks)
{
    int priority = -1;
    Iterator<EntityAITaskEntry> taskEntryIter = living.tasks.taskEntries.iterator();

    while (taskEntryIter.hasNext())
    {
        EntityAITaskEntry taskEntry = taskEntryIter.next();
        //System.out.printf("addAITaskAfterTasks() - start - task: %s\n", taskEntry.action);

        // If this entity already has the same AI task
        if (taskEntry.action.getClass() == task.getClass())
        {
            // Replace the old matching task with the new instance
            if (replaceMatching)
            {
                //System.out.printf("addAITaskAfterTasks() - task already present - replacing %s with %s\n", taskEntry.action, task);
                int p = taskEntry.priority;
                living.tasks.removeTask(taskEntry.action);
                living.tasks.addTask(p, task);
            }
            //else System.out.printf("addAITaskAfterTasks() - task already present: %s (not replacing)\n", task);

            return true;
        }

        for (Class<T> clazz : afterTasks)
        {
            if (priority <= taskEntry.priority && taskEntry.action.getClass() == clazz)
            {
                priority = taskEntry.priority + 1;
            }
        }
    }

    // Didn't find any matching AI tasks, insert ours as the highest priority task
    if (priority == -1)
    {
        //System.out.printf("addAITaskAfterTasks() - no matches for afterTasks\n");
        priority = 0;
    }

    //System.out.printf("addAITaskAfterTasks() - priority: %d\n", priority);

    living.tasks.addTask(priority, task);

    return true;
}