/** * removes the indicated task from the entity's AI tasks. */ public void removeTask(EntityAIBase par1EntityAIBase) { Iterator iterator = taskEntries.iterator(); while (iterator.hasNext()) { EntityAITaskEntry entityaitaskentry = (EntityAITaskEntry) iterator.next(); EntityAIBase entityaibase1 = entityaitaskentry.action; if (entityaibase1 == par1EntityAIBase) { if (executingTaskEntries.contains(entityaitaskentry)) { entityaibase1.resetTask(); executingTaskEntries.remove(entityaitaskentry); } iterator.remove(); } } }
@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."); } }
private String[] generateAIList(boolean target) { Iterator<Class<? extends EntityAIBase>> it = CustomAIHelper.isTarget.keySet().iterator(); ArrayList<String> list = new ArrayList<String>(); while(it.hasNext()) { Class<? extends EntityAIBase> c = it.next(); Boolean bool = CustomAIHelper.isTarget.get(c); if(bool == null) ; else if(bool) { if(target && CustomAIHelper.isSuitableForEntity((EntityLiving) entity, c)) list.add(CustomAIHelper.getNameFromClass(c)); } else { if(!target && CustomAIHelper.isSuitableForEntity((EntityLiving) entity, c)) list.add(CustomAIHelper.getNameFromClass(c)); } } return list.toArray(new String[0]); }
private String[] generateAIList(boolean target) { Iterator<Class<? extends EntityAIBase>> it = CustomAIHelper.isTarget.keySet().iterator(); ArrayList<String> list = new ArrayList<String>(); while(it.hasNext()) { Class<? extends EntityAIBase> c = it.next(); Boolean bool = CustomAIHelper.isTarget.get(c); if(bool == null) ; else if(bool) { if(target) list.add(CustomAIHelper.getNameFromClass(c)); } else { if(!target) list.add(CustomAIHelper.getNameFromClass(c)); } } return list.toArray(new String[0]); }
public EntityAIWorker getWorkerFromClass(Class<? extends EntityAIBase> c) { Set<Class<? extends EntityAIBase>[]> keys = workerRegistry.keySet(); Iterator<Class<? extends EntityAIBase>[]> it = keys.iterator(); while(it.hasNext()) { Class<? extends EntityAIBase>[] classes = it.next(); for(Class<? extends EntityAIBase> clazz : classes) { if(clazz == c) { return workerRegistry.get(classes); } } } return null; }
/** * 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 void func_85156_a(EntityAIBase p_85156_1_) { Iterator var2 = this.field_75782_a.iterator(); while(var2.hasNext()) { EntityAITaskEntry var3 = (EntityAITaskEntry)var2.next(); EntityAIBase var4 = var3.field_75733_a; if(var4 == p_85156_1_) { if(this.field_75780_b.contains(var3)) { var4.func_75251_c(); this.field_75780_b.remove(var3); } var2.remove(); } } }
/** * removes the indicated task from the entity's AI tasks. */ public void removeTask(EntityAIBase par1EntityAIBase){ Iterator iterator = taskEntries.iterator(); while(iterator.hasNext()) { EntityAITaskEntry entityaitaskentry = (EntityAITaskEntry)iterator.next(); EntityAIBase entityaibase1 = entityaitaskentry.action; if(entityaibase1 == par1EntityAIBase) { if(executingTaskEntries.contains(entityaitaskentry)) { entityaibase1.resetTask(); executingTaskEntries.remove(entityaitaskentry); } iterator.remove(); } } }
@Override public EntityAIBase getWidgetAI(IDroneBase drone, IProgWidget widget) { return new DroneEntityBase<IProgWidget, EntityLivingBase>(drone, widget) { private final List<Entity> visitedEntities = new ArrayList<Entity>(); @Override protected boolean isEntityValid(Entity entity) { return entity instanceof EntityLivingBase && !visitedEntities.contains(entity); } @Override protected boolean doAction() { visitedEntities.add(targetedEntity); boolean activated = false; ItemStack stack = drone.getInv().getStackInSlot(0); if (stack.getItem().itemInteractionForEntity(stack, drone.getFakePlayer(), targetedEntity, EnumHand.MAIN_HAND)) { activated = true; } if (!activated && targetedEntity instanceof EntityAgeable && ((EntityAgeable) targetedEntity).processInteract(drone.getFakePlayer(), EnumHand.MAIN_HAND)) { activated = true; } DroneAIBlockInteract.transferToDroneFromFakePlayer(drone); return false;//return activated; <-- will right click as long as it's sucessfully activated. } }; }
@Override public EntityAIBase getWidgetAI(IDroneBase drone, IProgWidget widget) { if (widget instanceof ProgWidgetDroneEvaluation) { return null; } else { return new EntityAIBase() {//Trick the CC program into thinking this is an executable piece. @Override public boolean shouldExecute() { return false; } }; } }
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; }
@SubscribeEvent(priority = EventPriority.LOW) public void buffedNametag(EntityInteractEvent event) { ItemStack is = event.entityPlayer.getHeldItem(); if (is == null) return; if (is.getItem() != Items.name_tag) return; if (!(event.target instanceof EntityLiving)) return; final EntityLiving ent = (EntityLiving) event.target; final String origName = ent.getCustomNameTag(); if (!Strings.isNullOrEmpty(origName)) return; NBTTagCompound tag = ent.getEntityData(); final String name = "FZMiscBuffNametags"; if (tag.hasKey(name)) return; tag.setBoolean(name, true); ent.tasks.addTask(0, new EntityAIBase() { boolean buffApplied = false; // Might not be necessary. @Override public boolean shouldExecute() { if (buffApplied) return false; buffApplied = true; if (ent.getCustomNameTag().equals(origName)) return false; float delta = 2*3; float origHealth = ent.getMaxHealth(); float newMaxHealth = origHealth + delta; ent.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(newMaxHealth); ent.heal(delta); EnumParticleTypes particleType = EnumParticleTypes.HEART; if (ent instanceof IMob) { particleType = EnumParticleTypes.SMOKE_NORMAL; } if (ent.worldObj instanceof WorldServer) { WorldServer ws = (WorldServer) ent.worldObj; ws.spawnParticle(particleType, false, ent.posX, ent.posY, ent.posZ, 8, 0.0, 0.0, 0.0, 0.0); } return false; } }); }
@Override public boolean addTask(int priority, AIBase ai) { if (ai instanceof EntityAIBase) { this.addTask(priority, (EntityAIBase) ai); } else { this.addTask(priority, new NeptuneCustomEntityAI(ai)); } return this.hasTask(ai.getClass()); }
public EntityPeep(World world){ super(world); this.timeUntilNextEasterEgg = this.rand.nextInt(6000) + 6000; EntityAIBase tempt = null; for(Object thingy : tasks.taskEntries){ EntityAITasks.EntityAITaskEntry ai = (EntityAITasks.EntityAITaskEntry)thingy; if(ai.action instanceof EntityAITempt) { tempt = ai.action; break; } } if(tempt !=null) this.tasks.removeTask(tempt); this.tasks.addTask(3, new EntityAITempt(this, 1.0D, Items.sugar, false)); }
public static String getNameForTask(Class<? extends EntityAIBase> action) { if(map.containsKey(action)) { return map.get(action); } String s = action.getCanonicalName(); if(s.contains(".")) { return s.substring(s.lastIndexOf('.')+1); } return s; }
public static String getNameForTask(EntityAIBase action) { if(map.containsKey(action.getClass())) { return map.get(action.getClass()); } String s = action.getClass().getCanonicalName(); if(s.contains(".")) { return s.substring(s.lastIndexOf('.')+1); } return s; }
public static boolean isSuitableForEntity(EntityLiving entity, Class<? extends EntityAIBase> c) { EntityAIWorker worker = EntityAIFactory.instance().getWorkerFromClass(c); if(worker == null) return false; return worker.isSuitableForEntity(entity, c); }
public static Class<? extends EntityAIBase> getClassFromName(String name) { Iterator<Class<? extends EntityAIBase>> it = map.keySet().iterator(); while(it.hasNext()) { Class<? extends EntityAIBase> c = it.next(); if(map.get(c).equals(name)) { return c; } } return null; }
public static Class<? extends EntityAIBase> tryToGetAITaskFromName(String clazz) { Set<Class<? extends EntityAIBase>> tasks = map.keySet(); Iterator<Class<? extends EntityAIBase>> it = tasks.iterator(); while(it.hasNext()) { Class<? extends EntityAIBase> c = it.next(); String s = map.get(c); if(s.equalsIgnoreCase(clazz)) { return c; } } return null; }
@Override public JSONObject createDefaultJSON(Class<? extends EntityAIBase> clazz) { JSONObject object = new JSONObject(); object.put("type", clazz.getCanonicalName()); object.put("priority", 1); if(clazz == EntityAIFleeSunEvenNotBurning.class) { object.put("Move speed", 0.9); } else if(clazz == EntityAIFollowEntity.class) { object.put("Entity class name", "none"); object.put("Move speed", 0.9); object.put("Max distance", 10f); } else if(clazz == EntityAITeleportRandomly.class) { object.put("Tick rate", 60); object.put("Play teleport sound", true); object.put("Avoid liquids", true); } else if(clazz == EntityAIRangeAttack.class) { object.put("Move speed", 0.9); object.put("Reload time", 20); object.put("Max reload time", 60); object.put("Distance from target", 10f); object.put("Projectile type", "Arrows"); } return object; }
@Override public boolean isSuitableForEntity(EntityLiving living, Class<? extends EntityAIBase> clazz) { if(clazz == EntityAIFleeSunEvenNotBurning.class && ! (living instanceof EntityCreature)) return false; return true; }
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 JSONObject createDefaultJSON(Class<? extends EntityAIBase> clazz) { EntityAIWorker worker = getWorkerFromClass(clazz); if(worker != null) { return worker.createDefaultJSON(clazz); } return new JSONObject(); }
/** * The Wolf Backpack is a handy one if you're out in the wild. It checks around for any wolves that may lurk around. * If any of them gets mad at you, it will smell the scent of it's kin on you and promptly forget about the whole * deal. Smelling like dog is awesome. * * @param player the player * @param world the world * @param backpack the backpack */ @SuppressWarnings("unchecked") public void itemWolf(EntityPlayer player, World world, ItemStack backpack) { //lastTime is in Ticks for this backpack InventoryBackpack inv = new InventoryBackpack(backpack); int lastCheckTime = inv.getLastTime() - 1; if (lastCheckTime <= 0) { lastCheckTime = 20; List<EntityWolf> wolves = world.getEntitiesWithinAABB( EntityWolf.class, AxisAlignedBB.getBoundingBox(player.posX, player.posY, player.posZ, player.posX + 1.0D, player.posY + 1.0D, player.posZ + 1.0D).expand(16.0D, 4.0D, 16.0D)); if (wolves.isEmpty()) return; for (EntityWolf wolf : wolves) { if (wolf.isAngry() && wolf.getAttackTarget() == player) { wolf.setAngry(false); wolf.setAttackTarget(null); wolf.setRevengeTarget(null); Iterator<?> i2 = wolf.targetTasks.taskEntries.iterator(); while (i2.hasNext()) { ((EntityAIBase) i2.next()).resetTask(); } } } } inv.setLastTime(lastCheckTime); inv.dirtyTime(); }
/** * All AI's with higher or equal priority value (less valued) is incremented * by one before this AI is inserted. Thus it comes before an old AI with same * priority value */ private static void insertAI(EntityAnimal animal, int priority, EntityAIBase aitask) { // System.out.println("Rewriting the animal: "+cow); // First increment the priority of every taskEntry that has same-or-higher // priority as the new one for (Object o2 : animal.tasks.taskEntries) { EntityAITaskEntry taskEntry = (EntityAITaskEntry) o2; if (taskEntry.priority >= priority) { taskEntry.priority++; } } animal.tasks.addTask(priority, aitask); }
private boolean addTask(EntityCow cow, int priority, EntityAIBase action) { for (Object obj : cow.tasks.taskEntries) { EntityAITasks.EntityAITaskEntry taskEntry = (EntityAITasks.EntityAITaskEntry) obj; if (action.getClass().isInstance(taskEntry.action)) { return false; } } cow.tasks.addTask(priority, action); return true; }
private int getPriorityOfTask(EntityLiving living, Class<? extends EntityAIBase> clazz) { for (Object obj : living.tasks.taskEntries) { EntityAITasks.EntityAITaskEntry taskEntry = (EntityAITasks.EntityAITaskEntry) obj; if (clazz.isInstance(taskEntry.action)) { return taskEntry.priority; } } return -1; }
@Override public EntityAIBase getWidgetAI(IDroneBase drone, IProgWidget widget){ return new DroneEntityBase<IProgWidget, EntityLivingBase>(drone, widget){ private final List<Entity> visitedEntities = new ArrayList<Entity>(); @Override protected boolean isEntityValid(Entity entity){ return entity instanceof EntityLivingBase && !visitedEntities.contains(entity); } @Override protected boolean doAction(){ visitedEntities.add(targetedEntity); boolean activated = false; ItemStack stack = drone.getInventory().getStackInSlot(0); if(stack != null && stack.getItem().itemInteractionForEntity(stack, drone.getFakePlayer(), targetedEntity)) { activated = true; } if(!activated && targetedEntity instanceof EntityAgeable && ((EntityAgeable)targetedEntity).interact(drone.getFakePlayer())) { activated = true; } DroneAIBlockInteract.transferToDroneFromFakePlayer(drone); return false;//return activated; <-- will right click as long as it's sucessfully activated. } }; }
@Override public EntityAIBase getWidgetAI(IDroneBase drone, IProgWidget widget){ if(widget instanceof ProgWidgetDroneEvaluation) { return null; } else { return new EntityAIBase(){//Trick the CC program into thinking this is an executable piece. @Override public boolean shouldExecute(){ return false; } }; } }
@Override public void startAttracting(TileAttractor attractor, EntityLiving entity) { EntityAIBase remove = findAITask(attractor, entity); if (remove != null) { entity.tasks.removeTask(remove); } cancelCurrentTasks(entity); entity.tasks.addTask(0, new AttractTask(entity, attractor.getTarget(), attractor.getPos())); }
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; }
@Override public void release(TileAttractor attractor, EntityLiving entity) { EntityAIBase remove = findAITask(attractor, entity); if (remove != null) { entity.tasks.removeTask(remove); cancelCurrentTasks(entity); } }
public EntityAIBase getRunningTargetAI() { return aiManager.getTargetAI(); }
public synchronized void setAction(IProgWidget widget, EntityAIBase ai) throws IllegalArgumentException { curAction = ai; newAction = true; curActionActive = true; }
@Override public EntityAIBase getWidgetAI(IDroneBase drone, IProgWidget widget) { return new DroneAICC((EntityDrone) drone, (ProgWidgetCC) widget, false); }
@Override public EntityAIBase getWidgetTargetAI(IDroneBase drone, IProgWidget widget) { return new DroneAICC((EntityDrone) drone, (ProgWidgetCC) widget, true); }
public EntityAIBase getCurrentAI() { return curWidgetAI; }
private void setActiveWidget(IProgWidget widget) { EntityAIBase targetAI = null; EntityAIBase ai = null; if (widget != null) { boolean first = widget instanceof ProgWidgetStart; targetAI = widget.getWidgetTargetAI(drone, widget); ai = widget.getWidgetAI(drone, widget); Set<IProgWidget> visitedWidgets = new HashSet<IProgWidget>();//Prevent endless loops while (!visitedWidgets.contains(widget) && targetAI == null && ai == null) { visitedWidgets.add(widget); IProgWidget oldWidget = widget; widget = widget.getOutputWidget(drone, progWidgets); if (widget == null) { if (first) { return; } else { if (stopWhenEndReached) { setActiveWidget(null); } else { gotoFirstWidget(); } return; } } else if (oldWidget.getOutputWidget() != widget) { if (addJumpBackWidget(oldWidget)) return; } targetAI = widget.getWidgetTargetAI(drone, widget); ai = widget.getWidgetAI(drone, widget); } drone.setActiveProgram(widget); } else { setLabel("Stopped"); } curActiveWidget = widget; if (curWidgetAI != null) removeTask(curWidgetAI); if (curWidgetTargetAI != null) drone.getTargetAI().removeTask(curWidgetTargetAI); if (ai != null) addTask(2, ai); if (targetAI != null) drone.getTargetAI().addTask(2, targetAI); curWidgetAI = ai; curWidgetTargetAI = targetAI; }
public EntityAIBase getTargetAI() { return curWidgetTargetAI; }
/** * START EntityAITasks code */ public void addTask(int par1, EntityAIBase par2EntityAIBase) { taskEntries.add(new EntityAITaskEntry(par1, par2EntityAIBase)); }