2012-08-10 07:21:24 +02:00
|
|
|
package net.minecraft.server;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.List;
|
|
|
|
|
2012-08-17 19:55:33 +02:00
|
|
|
import org.bukkit.craftbukkit.util.UnsafeList; // CraftBukkit
|
|
|
|
|
2012-08-10 07:21:24 +02:00
|
|
|
public class PathfinderGoalSelector {
|
|
|
|
|
2012-08-17 19:55:33 +02:00
|
|
|
// CraftBukkit start - ArrayList -> UnsafeList
|
|
|
|
private List a = new UnsafeList();
|
|
|
|
private List b = new UnsafeList();
|
|
|
|
// CraftBukkit end
|
2012-08-10 07:21:24 +02:00
|
|
|
private final MethodProfiler c;
|
2013-07-01 13:03:00 +02:00
|
|
|
private int d;
|
2012-08-10 07:21:24 +02:00
|
|
|
private int e = 3;
|
|
|
|
|
|
|
|
public PathfinderGoalSelector(MethodProfiler methodprofiler) {
|
|
|
|
this.c = methodprofiler;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void a(int i, PathfinderGoal pathfindergoal) {
|
|
|
|
this.a.add(new PathfinderGoalSelectorItem(this, i, pathfindergoal));
|
|
|
|
}
|
2012-11-06 13:05:28 +01:00
|
|
|
|
|
|
|
public void a(PathfinderGoal pathfindergoal) {
|
|
|
|
Iterator iterator = this.a.iterator();
|
|
|
|
|
|
|
|
while (iterator.hasNext()) {
|
|
|
|
PathfinderGoalSelectorItem pathfindergoalselectoritem = (PathfinderGoalSelectorItem) iterator.next();
|
|
|
|
PathfinderGoal pathfindergoal1 = pathfindergoalselectoritem.a;
|
|
|
|
|
|
|
|
if (pathfindergoal1 == pathfindergoal) {
|
|
|
|
if (this.b.contains(pathfindergoalselectoritem)) {
|
|
|
|
pathfindergoal1.d();
|
|
|
|
this.b.remove(pathfindergoalselectoritem);
|
|
|
|
}
|
|
|
|
|
|
|
|
iterator.remove();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-08-10 07:21:24 +02:00
|
|
|
|
|
|
|
public void a() {
|
2012-08-17 23:25:19 +02:00
|
|
|
// ArrayList arraylist = new ArrayList(); // CraftBukkit - remove usage
|
2012-08-10 07:21:24 +02:00
|
|
|
Iterator iterator;
|
|
|
|
PathfinderGoalSelectorItem pathfindergoalselectoritem;
|
|
|
|
|
|
|
|
if (this.d++ % this.e == 0) {
|
|
|
|
iterator = this.a.iterator();
|
|
|
|
|
|
|
|
while (iterator.hasNext()) {
|
|
|
|
pathfindergoalselectoritem = (PathfinderGoalSelectorItem) iterator.next();
|
|
|
|
boolean flag = this.b.contains(pathfindergoalselectoritem);
|
|
|
|
|
|
|
|
if (flag) {
|
|
|
|
if (this.b(pathfindergoalselectoritem) && this.a(pathfindergoalselectoritem)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
pathfindergoalselectoritem.a.d();
|
2012-08-10 07:21:24 +02:00
|
|
|
this.b.remove(pathfindergoalselectoritem);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.b(pathfindergoalselectoritem) && pathfindergoalselectoritem.a.a()) {
|
2012-08-17 23:25:19 +02:00
|
|
|
// CraftBukkit start - call method now instead of queueing
|
|
|
|
// arraylist.add(pathfindergoalselectoritem);
|
2012-10-25 05:53:23 +02:00
|
|
|
pathfindergoalselectoritem.a.c();
|
2012-08-17 23:25:19 +02:00
|
|
|
// CraftBukkit end
|
2012-08-10 07:21:24 +02:00
|
|
|
this.b.add(pathfindergoalselectoritem);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
iterator = this.b.iterator();
|
|
|
|
|
|
|
|
while (iterator.hasNext()) {
|
|
|
|
pathfindergoalselectoritem = (PathfinderGoalSelectorItem) iterator.next();
|
|
|
|
if (!pathfindergoalselectoritem.a.b()) {
|
2012-10-25 05:53:23 +02:00
|
|
|
pathfindergoalselectoritem.a.d();
|
2012-08-10 07:21:24 +02:00
|
|
|
iterator.remove();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-10 06:19:28 +02:00
|
|
|
this.c.a("goalStart");
|
2012-08-17 23:25:19 +02:00
|
|
|
// CraftBukkit start - removed usage of arraylist
|
|
|
|
/*iterator = arraylist.iterator();
|
2012-08-10 07:21:24 +02:00
|
|
|
|
|
|
|
while (iterator.hasNext()) {
|
|
|
|
pathfindergoalselectoritem = (PathfinderGoalSelectorItem) iterator.next();
|
2012-09-10 06:19:28 +02:00
|
|
|
this.c.a(pathfindergoalselectoritem.a.getClass().getSimpleName());
|
2012-10-25 05:53:23 +02:00
|
|
|
pathfindergoalselectoritem.a.c();
|
2012-09-10 06:19:28 +02:00
|
|
|
this.c.b();
|
2012-08-17 23:25:19 +02:00
|
|
|
}*/
|
|
|
|
// CraftBukkit end
|
2012-08-10 07:21:24 +02:00
|
|
|
|
2012-09-10 06:19:28 +02:00
|
|
|
this.c.b();
|
|
|
|
this.c.a("goalTick");
|
2012-08-10 07:21:24 +02:00
|
|
|
iterator = this.b.iterator();
|
|
|
|
|
|
|
|
while (iterator.hasNext()) {
|
|
|
|
pathfindergoalselectoritem = (PathfinderGoalSelectorItem) iterator.next();
|
2012-10-25 05:53:23 +02:00
|
|
|
pathfindergoalselectoritem.a.e();
|
2012-08-10 07:21:24 +02:00
|
|
|
}
|
|
|
|
|
2012-09-10 06:19:28 +02:00
|
|
|
this.c.b();
|
2012-08-10 07:21:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private boolean a(PathfinderGoalSelectorItem pathfindergoalselectoritem) {
|
2012-09-10 06:19:28 +02:00
|
|
|
this.c.a("canContinue");
|
2012-08-10 07:21:24 +02:00
|
|
|
boolean flag = pathfindergoalselectoritem.a.b();
|
|
|
|
|
2012-09-10 06:19:28 +02:00
|
|
|
this.c.b();
|
2012-08-10 07:21:24 +02:00
|
|
|
return flag;
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean b(PathfinderGoalSelectorItem pathfindergoalselectoritem) {
|
2012-09-10 06:19:28 +02:00
|
|
|
this.c.a("canUse");
|
2012-08-10 07:21:24 +02:00
|
|
|
Iterator iterator = this.a.iterator();
|
|
|
|
|
|
|
|
while (iterator.hasNext()) {
|
|
|
|
PathfinderGoalSelectorItem pathfindergoalselectoritem1 = (PathfinderGoalSelectorItem) iterator.next();
|
|
|
|
|
|
|
|
if (pathfindergoalselectoritem1 != pathfindergoalselectoritem) {
|
|
|
|
if (pathfindergoalselectoritem.b >= pathfindergoalselectoritem1.b) {
|
2012-08-17 23:25:19 +02:00
|
|
|
// CraftBukkit - switch order
|
|
|
|
if (!this.a(pathfindergoalselectoritem, pathfindergoalselectoritem1) && this.b.contains(pathfindergoalselectoritem1)) {
|
2012-09-10 06:19:28 +02:00
|
|
|
this.c.b();
|
2012-08-20 02:59:58 +02:00
|
|
|
((UnsafeList.Itr) iterator).valid = false; // CraftBukkit - mark iterator for reuse
|
2012-08-10 07:21:24 +02:00
|
|
|
return false;
|
|
|
|
}
|
2013-07-01 13:03:00 +02:00
|
|
|
// CraftBukkit - switch order
|
2012-10-25 05:53:23 +02:00
|
|
|
} else if (!pathfindergoalselectoritem1.a.i() && this.b.contains(pathfindergoalselectoritem1)) {
|
2012-09-10 06:19:28 +02:00
|
|
|
this.c.b();
|
2012-08-20 02:59:58 +02:00
|
|
|
((UnsafeList.Itr) iterator).valid = false; // CraftBukkit - mark iterator for reuse
|
2012-08-10 07:21:24 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-10 06:19:28 +02:00
|
|
|
this.c.b();
|
2012-08-10 07:21:24 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean a(PathfinderGoalSelectorItem pathfindergoalselectoritem, PathfinderGoalSelectorItem pathfindergoalselectoritem1) {
|
2012-10-25 05:53:23 +02:00
|
|
|
return (pathfindergoalselectoritem.a.j() & pathfindergoalselectoritem1.a.j()) == 0;
|
2012-08-10 07:21:24 +02:00
|
|
|
}
|
|
|
|
}
|