[1.16] Fix MobGoals#getAllGoals not actually returning all goals (#3670)

This commit is contained in:
MiniDigger | Martin 2020-06-28 21:57:31 +02:00
parent ce5894ab46
commit 5000be556c
2 changed files with 38 additions and 2 deletions

View file

@ -162,7 +162,11 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ MOVE,
+ LOOK,
+ JUMP,
+ TARGET
+ TARGET,
+ /**
+ * Used to map vanilla goals, that are a behavior goal but don't have a type set...
+ */
+ UNKNOWN_BEHAVIOR,
+
+}
diff --git a/src/main/java/com/destroystokyo/paper/entity/ai/MobGoals.java b/src/main/java/com/destroystokyo/paper/entity/ai/MobGoals.java

View file

@ -312,6 +312,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ return GoalType.LOOK;
+ case JUMP:
+ return GoalType.JUMP;
+ case UNKNOWN_BEHAVIOR:
+ return GoalType.UNKNOWN_BEHAVIOR;
+ case TARGET:
+ return GoalType.TARGET;
+ default:
@ -335,6 +337,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ return PathfinderGoal.Type.LOOK;
+ case JUMP:
+ return PathfinderGoal.Type.JUMP;
+ case UNKNOWN_BEHAVIOR:
+ return PathfinderGoal.Type.UNKNOWN_BEHAVIOR;
+ case TARGET:
+ return PathfinderGoal.Type.TARGET;
+ default:
@ -400,6 +404,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ this.handle = handle;
+
+ this.setTypes(MobGoalHelper.paperToVanilla(handle.getTypes()));
+ if (this.getGoalTypes().size() == 0) {
+ this.getGoalTypes().addUnchecked(Type.UNKNOWN_BEHAVIOR);
+ }
+ }
+
+ @Override
@ -752,8 +759,17 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
--- a/src/main/java/net/minecraft/server/PathfinderGoal.java
+++ b/src/main/java/net/minecraft/server/PathfinderGoal.java
@@ -0,0 +0,0 @@ public abstract class PathfinderGoal {
private final EnumSet<PathfinderGoal.Type> a = EnumSet.noneOf(PathfinderGoal.Type.class); // Paper unused, but dummy to prevent plugins from crashing as hard. Theyll need to support paper in a special case if this is super important, but really doesn't seem like it would be.
private final OptimizedSmallEnumSet<Type> goalTypes = new OptimizedSmallEnumSet<>(PathfinderGoal.Type.class); // Paper - remove streams from pathfindergoalselector
public PathfinderGoal() {}
- public PathfinderGoal() {}
+ // Paper start make sure goaltypes is never empty
+ public PathfinderGoal() {
+ if (this.goalTypes.size() == 0) {
+ this.goalTypes.addUnchecked(Type.UNKNOWN_BEHAVIOR);
+ }
+ }
+ // paper end
- public abstract boolean a();
+ public boolean a() { return this.shouldActivate(); } public boolean shouldActivate() { return false;} public boolean shouldActivate2() { return a(); } // Paper - OBFHELPER, for both directions...
@ -783,6 +799,22 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
// Paper start - remove streams from pathfindergoalselector
this.goalTypes.clear();
this.goalTypes.addAllUnchecked(enumset);
+ // make sure its never empty
+ if (this.goalTypes.size() == 0) {
+ this.goalTypes.addUnchecked(Type.UNKNOWN_BEHAVIOR);
+ }
// Paper end - remove streams from pathfindergoalselector
}
@@ -0,0 +0,0 @@ public abstract class PathfinderGoal {
public static enum Type {
- MOVE, LOOK, JUMP, TARGET;
+ MOVE, LOOK, JUMP, TARGET, UNKNOWN_BEHAVIOR; // Paper - add unknown
private Type() {}
}
diff --git a/src/main/java/net/minecraft/server/PathfinderGoalSelector.java b/src/main/java/net/minecraft/server/PathfinderGoalSelector.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/server/PathfinderGoalSelector.java