Java 类net.minecraft.entity.ai.EntityAITasks.EntityAITaskEntry 实例源码

项目:connor41-etfuturum2    文件:ServerEventHandler.java   
@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;
            }
        }
    }
}
项目:uniquecrops    文件:ItemGeneric.java   
@Override
   public void onUpdate(ItemStack stack, World world, Entity entity, int itemSlot, boolean isSelected) {

    if (stack.getItemDamage() != 20)
        return;

    if (!(entity instanceof EntityPlayer) || (entity instanceof FakePlayer))
        return;

    if (itemSlot < ((EntityPlayer)entity).inventory.getHotbarSize()) {
        List<EntityLiving> entities = entity.worldObj.getEntitiesWithinAABB(EntityLiving.class, new AxisAlignedBB(entity.getPosition().add(-range, -range, -range), entity.getPosition().add(range, range, range)));

        for (EntityLiving ent : entities) {
            List<EntityAITaskEntry> entries = new ArrayList(ent.tasks.taskEntries);
            entries.addAll(new ArrayList(ent.targetTasks.taskEntries));

            for (EntityAITaskEntry entry : entries) {
                if (entry.action instanceof EntityAIAttackRangedBow) {
                    makeSkellyShootSlower((EntityAIAttackRangedBow)entry.action);
                }
            }
            if (ent instanceof EntityCreeper)
                ReflectionHelper.setPrivateValue(EntityCreeper.class, (EntityCreeper)ent, 60, this.FUSETIME);
        }
    }
}
项目:LightningCraft    文件:EntityUnderworldGhast.java   
@Override
protected void initEntityAI() {
    super.initEntityAI();
    EntityAIBase remove = null;
    for(EntityAITaskEntry task : this.tasks.taskEntries) {
        if(task.action.getClass().getSimpleName().equals("AIFireballAttack")) {
            remove = task.action;
            break;
        }
    }
    if(remove != null) {
        this.tasks.removeTask(remove);
        this.tasks.addTask(7, new AIUnderworldFireballAttack(this));
    } else {
        Log.logger.error(this.getName() + " failed to override Ghast fireball AI.");
    }
}
项目:Et-Futurum    文件:ServerEventHandler.java   
@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;
            }
        }
    }
}
项目:CustomAI    文件:CustomAIHelper.java   
public static void applyLists(Entity entity, List<EntityAITaskEntry> tasks, List<EntityAITaskEntry> targetTasks)
{
    if(hasEntityAI(entity))
    {
        clearExecutingTasks(entity);
        clearExecutingTargetTasks(entity);
        getTasksList(entity).clear();
        getTargetTasksList(entity).clear();
        getTargetTasksList(entity).addAll(targetTasks);
        getTasksList(entity).addAll(tasks);

        for(EntityAITaskEntry entry : tasks)
        {
            if(entry != null && entry.action != null)
            {
                setOwner(entry.action, entity);
                if(entry.action instanceof EntityAIDoorInteract)
                {
                    ((EntityLiving)entity).getNavigator().setEnterDoors(true);
                    ((EntityLiving)entity).getNavigator().setBreakDoors(true);
                }
            }
        }
    }
}
项目:enderutilities    文件:EntityUtils.java   
/**
 * 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);
    }
}
项目:EnderZoo    文件:EntityUtil.java   
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();
}
项目:EnderIO    文件:AIAttractionHandler.java   
private 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);
  }
}
项目:ObsidianSuite    文件:ObsidianAPIUtil.java   
public static boolean isEntityAITaskActive(EntityLiving entity, String AIName) {
    for(Object obj : entity.tasks.taskEntries) {
        EntityAITaskEntry taskEntry = (EntityAITaskEntry) obj;
        EntityAIBase task = taskEntry.action;
        if(task instanceof IEntityAIAnimation) {
            IEntityAIAnimation animatedTask = (IEntityAIAnimation) task;
            if(animatedTask.getAIName().equals(AIName) && animatedTask.isExecuting())
                return true;
        }
    }
    return false;
}
项目:DynamicSurroundings    文件:EmojiDataTables.java   
@Nonnull
private static ActionState eval(@Nonnull final Set<EntityAITaskEntry> entries) {
    ActionState state = ActionState.NONE;

    for (final EntityAITaskEntry task : entries) {
        final ActionState candidate = actions.get(task.action.getClass());
        if (candidate != null) {
            if (state.getPriority() < candidate.getPriority())
                state = candidate;
        }
    }
    return state;
}
项目:LightningCraft    文件:EntityLCZombie.java   
private void removeTargetTasks() {

    // remove target tasks
    Set<EntityAITaskEntry> entries = this.targetTasks.taskEntries;
    Iterator<EntityAITaskEntry> iter = entries.iterator();
    while(iter.hasNext()){
        EntityAITaskEntry e = iter.next();
        iter.remove();
    }
}
项目:CustomAI    文件:PacketUpdateAI.java   
@Override
public void encodeInto(ChannelHandlerContext ctx, ByteBuf buffer)
{
    EntityAITaskEntry[] tasksEntries = tasks.toArray(new EntityAITaskEntry[0]);
    EntityAITaskEntry[] targetTasksEntries = targetTasks.toArray(new EntityAITaskEntry[0]);
    try
    {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        DataOutputStream outputStream = new DataOutputStream(baos);

        outputStream.writeInt(entityID);

        outputStream.writeInt(tasksEntries.length);
        for(int i = 0;i<tasksEntries.length;i++)
            outputStream.writeUTF(CustomAIHelper.generateJSONFromAI(null, tasksEntries[i]).toString());

        outputStream.writeInt(targetTasksEntries.length);
        for(int i = 0;i<targetTasksEntries.length;i++)
            outputStream.writeUTF(CustomAIHelper.generateJSONFromAI(null, targetTasksEntries[i]).toString());
        outputStream.flush();
        baos.flush();
        outputStream.close();
        baos.close();
        byte[] data = baos.toByteArray();
        buffer.writeBytes(data);
    }
    catch(Exception e)
    {
        e.printStackTrace();
    }
}
项目:CustomAI    文件:GuiIAListSlot.java   
public GuiIAListSlot(int par1, EntityAITaskEntry taskEntry)
{
    super(par1);
    if(taskEntry == null || taskEntry.action == null)
        this.displayString = "[ERROR] AI Task empty";
    else
        this.displayString = CustomAIHelper.getNameForTask(taskEntry.action);
    this.task = taskEntry;
}
项目:CustomAI    文件:TileEntityAIEmitter.java   
/**
 * Check if two tasks are basically equal. Doesn't care about priority of each task
 * @param e : Entity used to process the instances of JSONObject 
 * @param task : First task of the couple to check
 * @param task2 : Second task of the couple to check
 * @return true if tasks are equal
 */
@SuppressWarnings("unchecked")
private boolean areTasksEqual(Entity e, EntityAITaskEntry task, EntityAITaskEntry task2)
{
    if(task == null || task2 == null || task.action == null || task2.action == null)
        return false;
    JSONObject firstTask = CustomAIHelper.generateJSONFromAI((EntityLiving) e, task);
    JSONObject secondTask = CustomAIHelper.generateJSONFromAI((EntityLiving) e, task2);
    if(firstTask.keySet().size() != secondTask.keySet().size())
        return false;
    else
    {
        if(!firstTask.getString("type").equals(secondTask.getString("type")))
            return false;
        Iterator<String> keys = firstTask.keys();
        while(keys.hasNext())
        {
            String key = keys.next(); 
            if(!key.equals("priority"))
            {
                try
                {
                    if(!firstTask.get(key).equals(secondTask.get(key)))
                    {
                        return false;
                    }
                }
                catch(Exception exception)
                {
                    return false;
                }
            }
        }
        return true;
    }
}
项目:CustomAI    文件:CustomAIHelper.java   
@SuppressWarnings("unchecked")
public static List<EntityAITaskEntry> getTasksList(Entity entity)
{
    if(hasEntityAI(entity))
    {
        EntityLiving living = (EntityLiving)entity;
        return living.tasks.taskEntries;
    }
    return null;
}
项目:CustomAI    文件:CustomAIHelper.java   
@SuppressWarnings("unchecked")
public static List<EntityAITaskEntry> getTargetTasksList(Entity entity)
{
    if(hasEntityAI(entity))
    {
        EntityLiving living = (EntityLiving)entity;
        return living.targetTasks.taskEntries;
    }
    return null;
}
项目:CustomAI    文件:EntityAIFactory.java   
public JSONObject generateJSON(EntityLiving entity, EntityAITaskEntry entry)
{
    Class<? extends EntityAIBase> clazz = entry.action.getClass();
    EntityAIWorker worker = this.getWorkerFromClass(clazz);
    if(worker == null)
        System.out.println(clazz);
    if(worker != null)
    {
        return worker.generateJSON(entity, entry);
    }
    return new JSONObject();
}
项目:CustomAI    文件:EntityAIFactory.java   
public EntityAITaskEntry generateAIBase(EntityLiving entity, JSONObject json)
{
    try
    {
        return generateAIBaseWithExceptions(entity, json);
    }
    catch (Exception e)
    {
        e.printStackTrace();
    }
    return null;
}
项目:enderutilities    文件:EntityUtils.java   
/**
 * 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;
}
项目:ZeldaSwordSkills    文件:EntitySkulltula.java   
public EntitySkulltula(World world) {
    super(world);
    Iterator<EntityAITaskEntry> iterator = tasks.taskEntries.iterator();
    while (iterator.hasNext()) {
        if (iterator.next().action instanceof EntityAIWander) {
            iterator.remove();
            break;
        }
    }
    this.tasks.addTask(2, new EntityAIPerch(this));
    this.tasks.addTask(5, new EntityAISeekPerch(this, 0.8D));
}
项目:EnderIO    文件:AIAttractionHandler.java   
private EntityAIBase findAITask(TileAttractor attractor, EntityLiving entity) {
  for (EntityAITaskEntry entry : entity.tasks.taskEntries) {
    if (entry.action instanceof AttractTask) {
      AttractTask at = (AttractTask) entry.action;
      if (attractor == null || at.coord.equals(BlockCoord.get(attractor)) || !at.continueExecuting()) {
        return entry.action;
      } else {
        return null;
      }
    }
  }
  return null;
}
项目:CustomAI    文件:PacketUpdateAI.java   
public PacketUpdateAI(int entityID, List<EntityAITaskEntry> tasks,List<EntityAITaskEntry> targetTasks)
{
    this.entityID = entityID;
    this.tasks = tasks;
    this.targetTasks = targetTasks;
}
项目:CustomAI    文件:TileEntityAIEmitter.java   
private List<EntityAITaskEntry> clone(List<EntityAITaskEntry> list)
{
    ArrayList<EntityAITaskEntry> result = new ArrayList<EntityAITaskEntry>();
    result.addAll(list);
    return result;
}
项目:CustomAI    文件:CustomAIHelper.java   
public static JSONObject generateJSONFromAI(EntityLiving entity, EntityAITaskEntry entry)
{
    return EntityAIFactory.instance().generateJSON(entity, entry);
}
项目:CustomAI    文件:CustomAIHelper.java   
public static EntityAITaskEntry generateAIFromJSON(Entity entity, String jsonData)
{
    if(!hasEntityAI(entity) && entity  != null)
        return null;
    return EntityAIFactory.instance().generateAIBase((EntityLiving)entity,jsonData);
}
项目:CustomAI    文件:CustomAIHelper.java   
public static EntityAITaskEntry createDummyAITask(EntityLiving e, String value)
{
    JSONObject json = new JsonDummyObject(getClassFromName(value),1);
    return generateAIFromJSON(e, json);
}
项目:CustomAI    文件:CustomAIHelper.java   
public static EntityAITaskEntry generateAIFromJSON(EntityLiving entity, JSONObject json)
{
    return EntityAIFactory.instance().generateAIBase(entity, json);
}
项目:CustomAI    文件:EntityAIFactory.java   
public EntityAITaskEntry generateAIBase(EntityLiving entity, String jsonData)
{
    return generateAIBase(entity, new JSONObject(jsonData));
}
项目:enderutilities    文件:EntityUtils.java   
/**
 * 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;
}
项目:AbyssalCraft    文件:EntityRemnant.java   
private EntityAINearestAttackableTarget fetchAI(){
    for(EntityAITaskEntry entry : targetTasks.taskEntries)
        if(entry.action instanceof EntityAINearestAttackableTarget)
            return (EntityAINearestAttackableTarget) entry.action;
    return null;
}
项目:dragon-mounts    文件:DragonBrain.java   
public void clearTasks(EntityAITasks tasks) {
    List<EntityAITaskEntry> taskEntries = new ArrayList<>(tasks.taskEntries);
    taskEntries.forEach(entry -> tasks.removeTask(entry.action));
}
项目:Rubedo    文件:EntityLivingEventHandler.java   
private void updateLivingAI(EntityLiving entity) {
    EntityAITaskEntry wanderTask = null;
    EntityAITaskEntry rangedAttackTask = null;

    for (Object task : entity.tasks.taskEntries) {
        EntityAITaskEntry taskEntry = (EntityAITaskEntry) task;

        if (taskEntry.action instanceof EntityAIWander)
            wanderTask = taskEntry;
        if (taskEntry.action instanceof EntityAIArrowAttack)
            rangedAttackTask = taskEntry;
    }

    if (entity instanceof EntitySkeleton && rangedAttackTask != null) {
        entity.tasks.addTask(3, new EntityAIFallBack(
                (EntitySkeleton) entity, EntityPlayer.class, 7.0F, 1.8D));
    }

    if (wanderTask != null) {
        entity.tasks.taskEntries.remove(wanderTask);
        float moveSpeed = 1.0F;
        if (entity instanceof EntityChicken)
            moveSpeed = 1.0F;
        else if (entity instanceof EntityCow)
            moveSpeed = 1.0F;
        else if (entity instanceof EntityCreeper)
            moveSpeed = 0.8F;
        else if (entity instanceof EntityHorse)
            moveSpeed = 0.7F;
        else if (entity instanceof EntityIronGolem)
            moveSpeed = 0.6F;
        else if (entity instanceof EntityOcelot)
            moveSpeed = 0.8F;
        else if (entity instanceof EntityPig)
            moveSpeed = 1.0F;
        else if (entity instanceof EntitySheep)
            moveSpeed = 1.0F;
        else if (entity instanceof EntitySkeleton)
            moveSpeed = 1.0F;
        else if (entity instanceof EntitySnowman)
            moveSpeed = 1.0F;
        else if (entity instanceof EntityVillager)
            moveSpeed = 0.6F;
        else if (entity instanceof EntityWitch)
            moveSpeed = 1.0F;
        else if (entity instanceof EntityWither)
            moveSpeed = 1.0F;
        else if (entity instanceof EntityWolf)
            moveSpeed = 1.0F;
        else if (entity instanceof EntityZombie)
            moveSpeed = 1.0F;
        else
            moveSpeed = 0.85F;

        entity.tasks.addTask(((EntityAITaskEntry) wanderTask).priority,
                new EntityAITweakedWandering((EntityCreature) entity,
                        moveSpeed));
    }
}
项目:CustomAI    文件:EntityAIWorker.java   
public abstract EntityAITaskEntry generateAIBaseWithExceptions(EntityLiving entity, JSONObject json) throws Exception;
项目:CustomAI    文件:EntityAIWorker.java   
public abstract JSONObject generateJSON(EntityLiving entity, EntityAITaskEntry entry);