Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package de.svdragster.rpg;
- import java.util.List;
- import net.canarymod.api.ai.AIBase;
- import net.canarymod.api.entity.living.EntityLiving;
- import net.canarymod.api.entity.living.humanoid.Player;
- import net.canarymod.api.world.position.Location;
- import net.canarymod.api.world.position.Vector3D;
- public class AIVendor implements AIBase {
- private EntityLiving mob = null;
- private Player target = null;
- private Location spawn = null;
- private boolean search = true;
- private boolean speak = true;
- public AIVendor(EntityLiving mob, Location spawn) {
- this.mob = mob;
- this.spawn = spawn;
- }
- @Override
- public boolean continueExecuting() {
- return this.target != null;
- }
- @Override
- public boolean isContinuous() {
- return true;
- }
- @Override
- public void resetTask() {
- this.target = null;
- this.mob.teleportTo(spawn);
- search = true;
- speak = true;
- }
- @Override
- public boolean shouldExecute() {
- if (this.target == null) {
- return this.getTarget();
- }
- return false;
- }
- @Override
- public void startExecuting() {
- if (search) {
- mob.getPathFinder().setPathToLocation(target.getLocation());
- mob.getPathFinder().setSpeed(0.5f);
- }
- Vector3D v = new Vector3D(mob.getLocation());
- if (v.getDistance(spawn) > 20 || !search) {
- mob.getPathFinder().setPathToLocation(spawn);
- mob.getPathFinder().setSpeed(0.5f);
- search = false;
- }
- }
- @Override
- public void updateTask() {
- if (mob.isInWater()) {
- this.resetTask();
- }
- if (target == null) {
- this.resetTask();
- return;
- }
- if (Math.abs(target.getX() - mob.getX()) < 2 && Math.abs(target.getZ() - mob.getZ()) < 2) {
- mob.lookAt(target);
- if (speak) {
- mob.playLivingSound();
- speak = false;
- }
- }
- Vector3D v = new Vector3D(mob.getLocation());
- if (v.getDistance(spawn) < 3 && !search) {
- this.resetTask();
- }
- if (v.getDistance(spawn) > 20 || !search) {
- //mob.getPathFinder().setSpeed(0.5f);
- //mob.getPathFinder().setPathToLocation(spawn);
- search = false;
- resetTask();
- } else {
- mob.getPathFinder().setPathToEntity(target);
- }
- }
- public boolean getTarget() {
- if (search) {
- List<Player> players = mob.getWorld().getPlayerList();
- Vector3D v = new Vector3D(mob.getLocation());
- for (int i=0; i<players.size(); i++) {
- Player t = players.get(i);
- if (v.getDistance(t.getLocation()) < 15) {
- this.target = t;
- mob.getPathFinder().setPathToEntity(target);
- return true;
- }
- }
- }
- this.resetTask();
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment