Add aggressive mob API (#9838)

This commit is contained in:
booky10 2023-11-11 22:17:36 +01:00
parent 5cca94a05e
commit cbce3a66aa
7 changed files with 77 additions and 4 deletions

View file

@ -40,14 +40,18 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ * Set if zombie has its arms raised
+ *
+ * @param raised True to raise arms
+ * @deprecated use {{@link #setAggressive(boolean)}}
+ */
+ @Deprecated
+ void setArmsRaised(boolean raised);
+
+ /**
+ * Check if zombie has arms raised
+ *
+ * @return True if arms are raised
+ * @deprecated use {@link #isAggressive()}
+ */
+ @Deprecated
+ boolean isArmsRaised();
+
+ /**

View file

@ -10,8 +10,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+++ b/src/main/java/org/bukkit/entity/Mob.java
@@ -0,0 +0,0 @@ public interface Mob extends LivingEntity, Lootable {
*/
@Nullable
public Sound getAmbientSound();
void setAggressive(boolean aggressive);
// Paper end
+
+ // Paper start
+ /**

View file

@ -633,6 +633,49 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ */
+ @org.jetbrains.annotations.Nullable
+ Llama getCaravanTail();
+ // Paper end
}
diff --git a/src/main/java/org/bukkit/entity/Mob.java b/src/main/java/org/bukkit/entity/Mob.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/org/bukkit/entity/Mob.java
+++ b/src/main/java/org/bukkit/entity/Mob.java
@@ -0,0 +0,0 @@ public interface Mob extends LivingEntity, Lootable {
*/
@Nullable
public Sound getAmbientSound();
+
+ // Paper start
+ /**
+ * Some mobs will raise their arm(s) when aggressive:
+ * <ul>
+ * <li>{@link Drowned}</li>
+ * <li>{@link Piglin}</li>
+ * <li>{@link Skeleton}</li>
+ * <li>{@link Zombie}</li>
+ * <li>{@link ZombieVillager}</li>
+ * <li>{@link Illusioner}</li>
+ * <li>{@link Vindicator}</li>
+ * <li>{@link Panda}</li>
+ * <li>{@link Pillager}</li>
+ * <li>{@link PiglinBrute}</li>
+ * </ul>
+ * <p>
+ * Note: This doesn't always show the actual aggressive state as
+ * set by {@link #setAggressive(boolean)}. {@link Panda}'s are always
+ * aggressive if their combined {@link Panda.Gene} is {@link Panda.Gene#AGGRESSIVE}.
+ *
+ * @return wether the mob is aggressive or not
+ */
+ boolean isAggressive();
+
+ /**
+ * Some mobs will raise their arm(s) when aggressive,
+ * see {@link #isAggressive()} for full list.
+ *
+ * @param aggressive wether the mob should be aggressive or not
+ * @see #isAggressive()
+ */
+ void setAggressive(boolean aggressive);
+ // Paper end
}
diff --git a/src/main/java/org/bukkit/entity/MushroomCow.java b/src/main/java/org/bukkit/entity/MushroomCow.java

View file

@ -32,13 +32,17 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ * Sets that the Entity is "charging" up an attack, by raising its hands
+ *
+ * @param raiseHands Whether the entities hands are raised to charge attack
+ * @deprecated use {@link #isAggressive()}
+ */
+ @Deprecated
+ void setChargingAttack(boolean raiseHands);
+
+ /**
+ * Alias to {@link LivingEntity#isHandRaised()}, if the entity is charging an attack
+ * @return If entities hands are raised
+ * @deprecated use {@link #isHandRaised()}
+ */
+ @Deprecated
+ default boolean isChargingAttack() {
+ return isHandRaised();
+ }

View file

@ -9,7 +9,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftMob.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftMob.java
@@ -0,0 +0,0 @@ public abstract class CraftMob extends CraftLivingEntity implements Mob {
getHandle().setLeftHanded(leftHanded);
this.getHandle().setAggressive(aggressive);
}
// Paper end
+

View file

@ -23,4 +23,5 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ getHandle().setLeftHanded(leftHanded);
+ }
// Paper end
}
// Paper start

View file

@ -837,6 +837,27 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ public void setPickupCooldown(int cooldown) {
+ throw new UnsupportedOperationException("Hopper minecarts don't have cooldowns");
+ }
+ // Paper end
}
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftMob.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftMob.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftMob.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftMob.java
@@ -0,0 +0,0 @@ public abstract class CraftMob extends CraftLivingEntity implements Mob {
return getHandle().getMaxHeadXRot();
}
// Paper end
+
+ // Paper start
+ @Override
+ public boolean isAggressive() {
+ return this.getHandle().isAggressive();
+ }
+
+ @Override
+ public void setAggressive(boolean aggressive) {
+ this.getHandle().setAggressive(aggressive);
+ }
+ // Paper end
}
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftMushroomCow.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftMushroomCow.java