/** * Add a predefined {@link com.dsh105.echopet.compat.api.ai.PetGoal} to a {@link * com.dsh105.echopet.api.pet.Pet} from the API * * @param pet the {@link com.dsh105.echopet.api.pet.Pet} to add the goal to * @param goalType type of goal */ public void addGoal(IPet pet, GoalType goalType) { if (pet == null) { EchoPet.LOG.severe( "Failed to add PetGoal to Pet AI through the EchoPetAPI. Pet cannot be null."); return; } if (goalType == GoalType.ATTACK) { pet.getEntityPet() .getPetGoalSelector() .addGoal( new SafeConstructor<APetGoalMeleeAttack>( ReflectionUtil.getVersionedClass("entity.ai.PetGoalMeleeAttack"), ReflectionUtil.getVersionedClass("entity.EntityPet"), double.class, int.class) .newInstance( pet.getEntityPet(), EchoPet.getConfig().getDouble("attack.lockRange", 0.0D), EchoPet.getConfig().getInt("attack.ticksBetweenAttacks", 20)), 3); } else if (goalType == GoalType.FLOAT) { pet.getEntityPet() .getPetGoalSelector() .addGoal( new SafeConstructor<APetGoalFloat>( ReflectionUtil.getVersionedClass("entity.ai.PetGoalFloat"), ReflectionUtil.getVersionedClass("entity.EntityPet")) .newInstance(pet.getEntityPet()), 0); } else if (goalType == GoalType.FOLLOW_OWNER) { pet.getEntityPet() .getPetGoalSelector() .addGoal( new SafeConstructor<APetGoalFollowOwner>( ReflectionUtil.getVersionedClass("entity.ai.PetGoalFollowOwner"), ReflectionUtil.getVersionedClass("entity.EntityPet"), double.class, double.class, double.class) .newInstance( pet.getEntityPet(), pet.getEntityPet().getSizeCategory().getStartWalk(pet.getPetType()), pet.getEntityPet().getSizeCategory().getStopWalk(pet.getPetType()), pet.getEntityPet().getSizeCategory().getTeleport(pet.getPetType())), 1); } else if (goalType == GoalType.LOOK_AT_PLAYER) { pet.getEntityPet() .getPetGoalSelector() .addGoal( new SafeConstructor<APetGoalLookAtPlayer>( ReflectionUtil.getVersionedClass("entity.ai.PetGoalLookAtPlayer"), ReflectionUtil.getVersionedClass("entity.EntityPet"), Class.class, float.class) .newInstance(pet.getEntityPet(), ReflectionUtil.getNMSClass("EntityHuman"), 8.0F), 2); } }
/** * Remove a goal from a {@link com.dsh105.echopet.api.pet.Pet}'s AI * * <p>The goal is identified using a string, initiated when the goal is added to the {@link * com.dsh105.echopet.api.pet.Pet} * * @param pet {@link com.dsh105.echopet.api.pet.Pet} to remove the goal from * @param identifier String that identifies a {@link com.dsh105.echopet.compat.api.ai.PetGoal} */ public void removeGoal(IPet pet, String identifier) { if (pet == null) { EchoPet.LOG.severe( "Failed to remove PetGoal from Pet AI through the EchoPetAPI. Pet cannot be null."); return; } pet.getEntityPet().getPetGoalSelector().removeGoal(identifier); }
/** * Add an implementation of {@link com.dsh105.echopet.compat.api.ai.PetGoal} to a {@link * com.dsh105.echopet.api.pet.Pet} * * @param pet the {@link com.dsh105.echopet.api.pet.Pet} to add the {@link * com.dsh105.echopet.compat.api.ai.PetGoal} to * @param goal the {@link com.dsh105.echopet.compat.api.ai.PetGoal} to add * @param identifier a {@link java.lang.String} to identify the goal */ public void addGoal(IPet pet, PetGoal goal, String identifier, int priority) { if (pet == null) { EchoPet.LOG.severe( "Failed to add PetGoal to Pet AI through the EchoPetAPI. Pet cannot be null."); return; } if (goal == null) { EchoPet.LOG.severe( "Failed to add PetGoal to Pet AI through the EchoPetAPI. Goal cannot be null."); return; } pet.getEntityPet().getPetGoalSelector().addGoal(identifier, goal, priority); }
/** * Set a target for the {@link com.dsh105.echopet.api.pet.Pet} to attack * * @param pet the attacker * @param target the {@link org.bukkit.entity.LivingEntity} for the {@link * com.dsh105.echopet.api.pet.Pet} to attack */ public void setAttackTarget(IPet pet, LivingEntity target) { if (pet == null) { EchoPet.LOG.severe( "Failed to set attack target for Pet through the EchoPetAPI. Pet cannot be null."); return; } if (target == null) { EchoPet.LOG.severe( "Failed to set attack target for Pet through the EchoPetAPI. Target cannot be null."); return; } if (pet.getEntityPet().getPetGoalSelector().getGoal("Attack") != null) { pet.getCraftPet().setTarget(target); } }