public static void walkTo( final Entity entity, Location location, double speed, final Runnable callback) { if (entity == null || location == null) return; net.minecraft.server.v1_8_R3.Entity nmsEntityEntity = ((CraftEntity) entity).getHandle(); if (!(nmsEntityEntity instanceof EntityInsentient)) return; final EntityInsentient nmsEntity = (EntityInsentient) nmsEntityEntity; final NavigationAbstract entityNavigation = nmsEntity.getNavigation(); final PathEntity path; final boolean aiDisabled = isAIDisabled(entity); if (aiDisabled) { toggleAI(entity, true); nmsEntity.onGround = true; } path = entityNavigation.a(location.getX(), location.getY(), location.getZ()); if (path != null) { entityNavigation.a(path, 1D); entityNavigation.a(2D); final double oldSpeed = nmsEntity.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).b(); nmsEntity.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).setValue(speed); new BukkitRunnable() { @Override public void run() { if (entityNavigation.m() || path.b()) { if (callback != null) callback.run(); nmsEntity.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).setValue(oldSpeed); if (aiDisabled) toggleAI(entity, false); cancel(); } } }.runTaskTimer(DenizenAPI.getCurrentInstance(), 1, 1); } // if (!Utilities.checkLocation(location, entity.getLocation(), 20)) { // TODO: generate waypoints to the target location? else { entity.teleport(location); } }
public static void CreatureMove( org.bukkit.entity.Entity paramEntity, Location paramLocation, float paramFloat) { if (!(paramEntity instanceof Creature)) { return; } if (UtilMath.offset(paramEntity.getLocation(), paramLocation) < 0.1D) { return; } EntityCreature localEntityCreature = ((CraftCreature) paramEntity).getHandle(); NavigationAbstract localNavigationAbstract = localEntityCreature.getNavigation(); if (UtilMath.offset(paramEntity.getLocation(), paramLocation) > 24.0D) { Location localLocation = paramEntity.getLocation(); localLocation.add( UtilAlg.getTrajectory(paramEntity.getLocation(), paramLocation).multiply(24)); localNavigationAbstract.a( localLocation.getX(), localLocation.getY(), localLocation.getZ(), paramFloat); } else { localNavigationAbstract.a( paramLocation.getX(), paramLocation.getY(), paramLocation.getZ(), paramFloat); } }
public static void updateNavigation(NavigationAbstract navigation) { navigation.k(); }
public static void stopNavigation(NavigationAbstract navigation) { navigation.n(); }
public static boolean isNavigationFinished(NavigationAbstract navigation) { return navigation.m(); }