示例#1
0
  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);
    }
  }
示例#2
0
 public static void setSpeed(Entity entity, double speed) {
   net.minecraft.server.v1_8_R3.Entity nmsEntityEntity = ((CraftEntity) entity).getHandle();
   if (!(nmsEntityEntity instanceof EntityInsentient)) return;
   EntityInsentient nmsEntity = (EntityInsentient) nmsEntityEntity;
   nmsEntity.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).setValue(speed);
 }
示例#3
0
 public static double getSpeed(Entity entity) {
   net.minecraft.server.v1_8_R3.Entity nmsEntityEntity = ((CraftEntity) entity).getHandle();
   if (!(nmsEntityEntity instanceof EntityInsentient)) return 0.0;
   EntityInsentient nmsEntity = (EntityInsentient) nmsEntityEntity;
   return nmsEntity.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).b();
 }