@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; } } } }
@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); } } }
@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."); } }
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); } } } } }
/** * 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); } }
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(); }
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); } }
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; }
@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; }
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(); } }
@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(); } }
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; }
/** * 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; } }
@SuppressWarnings("unchecked") public static List<EntityAITaskEntry> getTasksList(Entity entity) { if(hasEntityAI(entity)) { EntityLiving living = (EntityLiving)entity; return living.tasks.taskEntries; } return null; }
@SuppressWarnings("unchecked") public static List<EntityAITaskEntry> getTargetTasksList(Entity entity) { if(hasEntityAI(entity)) { EntityLiving living = (EntityLiving)entity; return living.targetTasks.taskEntries; } return null; }
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(); }
public EntityAITaskEntry generateAIBase(EntityLiving entity, JSONObject json) { try { return generateAIBaseWithExceptions(entity, json); } catch (Exception e) { e.printStackTrace(); } return null; }
/** * 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; }
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)); }
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; }
public PacketUpdateAI(int entityID, List<EntityAITaskEntry> tasks,List<EntityAITaskEntry> targetTasks) { this.entityID = entityID; this.tasks = tasks; this.targetTasks = targetTasks; }
private List<EntityAITaskEntry> clone(List<EntityAITaskEntry> list) { ArrayList<EntityAITaskEntry> result = new ArrayList<EntityAITaskEntry>(); result.addAll(list); return result; }
public static JSONObject generateJSONFromAI(EntityLiving entity, EntityAITaskEntry entry) { return EntityAIFactory.instance().generateJSON(entity, entry); }
public static EntityAITaskEntry generateAIFromJSON(Entity entity, String jsonData) { if(!hasEntityAI(entity) && entity != null) return null; return EntityAIFactory.instance().generateAIBase((EntityLiving)entity,jsonData); }
public static EntityAITaskEntry createDummyAITask(EntityLiving e, String value) { JSONObject json = new JsonDummyObject(getClassFromName(value),1); return generateAIFromJSON(e, json); }
public static EntityAITaskEntry generateAIFromJSON(EntityLiving entity, JSONObject json) { return EntityAIFactory.instance().generateAIBase(entity, json); }
public EntityAITaskEntry generateAIBase(EntityLiving entity, String jsonData) { return generateAIBase(entity, new JSONObject(jsonData)); }
/** * 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; }
private EntityAINearestAttackableTarget fetchAI(){ for(EntityAITaskEntry entry : targetTasks.taskEntries) if(entry.action instanceof EntityAINearestAttackableTarget) return (EntityAINearestAttackableTarget) entry.action; return null; }
public void clearTasks(EntityAITasks tasks) { List<EntityAITaskEntry> taskEntries = new ArrayList<>(tasks.taskEntries); taskEntries.forEach(entry -> tasks.removeTask(entry.action)); }
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)); } }
public abstract EntityAITaskEntry generateAIBaseWithExceptions(EntityLiving entity, JSONObject json) throws Exception;
public abstract JSONObject generateJSON(EntityLiving entity, EntityAITaskEntry entry);