All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.minecraft.server.PathfinderGoalSelector Maven / Gradle / Ivy

package net.minecraft.server;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.bukkit.craftbukkit.util.UnsafeList;

import java.util.Iterator;
import java.util.List;

public class PathfinderGoalSelector {

  private static final Logger a = LogManager.getLogger();
  private final MethodProfiler d;
  private final List b = new UnsafeList<>();
  private final List c = new UnsafeList<>();
  private int e;
  private final int f = 3;

  public PathfinderGoalSelector(MethodProfiler methodprofiler) {
    this.d = methodprofiler;
  }

  public void a(int i, PathfinderGoal pathfindergoal) {
    this.b.add(new PathfinderGoalSelectorItem(i, pathfindergoal));
  }

  public void a(PathfinderGoal pathfindergoal) {
    Iterator iterator = this.b.iterator();

    while (iterator.hasNext()) {
      PathfinderGoalSelector.PathfinderGoalSelectorItem path = iterator.next();
      PathfinderGoal pathfindergoal1 = path.a;

      if (pathfindergoal1 == pathfindergoal) {
        if (this.c.contains(path)) {
          pathfindergoal1.d();
          this.c.remove(path);
        }

        iterator.remove();
      }
    }

  }

  public void a() {
    Iterator iterator;
    PathfinderGoalSelector.PathfinderGoalSelectorItem path;

    if (this.e++ % this.f == 0) {
      iterator = this.b.iterator();

      while (iterator.hasNext()) {
        path = iterator.next();
        boolean flag = this.c.contains(path);

        if (flag) {
          if (this.b(path) && this.a(path)) {
            continue;
          }

          path.a.d();
          this.c.remove(path);
        }

        if (this.b(path) && path.a.a()) {
          path.a.c();
          this.c.add(path);
        }
      }
    } else {
      iterator = this.c.iterator();

      while (iterator.hasNext()) {
        path = iterator.next();
        if (!this.a(path)) {
          path.a.d();
          iterator.remove();
        }
      }
    }
    
    iterator = this.c.iterator();

    while (iterator.hasNext()) {
      path = iterator.next();
      path.a.e();
    }
  }

  private boolean a(PathfinderGoalSelector.PathfinderGoalSelectorItem path) {
    return path.a.b();
  }

  private boolean b(PathfinderGoalSelector.PathfinderGoalSelectorItem path) {
    Iterator iterator = this.b.iterator();

    while (iterator.hasNext()) {
      PathfinderGoalSelector.PathfinderGoalSelectorItem path2 = iterator.next();

      if (path2 != path) {
        if (path.b >= path2.b) {
          if (!this.a(path, path2) && this.c.contains(path2)) {
            ((UnsafeList.Itr) iterator).valid = false; // CraftBukkit - mark iterator for reuse
            return false;
          }
        } else if (!path2.a.i() && this.c.contains(path2)) {
          ((UnsafeList.Itr) iterator).valid = false; // CraftBukkit - mark iterator for reuse
          return false;
        }
      }
    }

    return true;
  }

  private boolean a(PathfinderGoalSelector.PathfinderGoalSelectorItem path, PathfinderGoalSelector.PathfinderGoalSelectorItem path2) {
    return (path.a.j() & path2.a.j()) == 0;
  }

  static class PathfinderGoalSelectorItem {

    public PathfinderGoal a;
    public int b;

    public PathfinderGoalSelectorItem(int i, PathfinderGoal pathfindergoal) {
      this.b = i;
      this.a = pathfindergoal;
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy