mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-22 18:45:54 +01:00
Add Mob#lookAt API (#5633)
This commit is contained in:
parent
4bacecd164
commit
68c67e6800
99
Spigot-API-Patches/0306-Add-Mob-lookAt-API.patch
Normal file
99
Spigot-API-Patches/0306-Add-Mob-lookAt-API.patch
Normal file
@ -0,0 +1,99 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: BillyGalbreath <blake.galbreath@gmail.com>
|
||||
Date: Fri, 14 May 2021 13:42:06 -0500
|
||||
Subject: [PATCH] Add Mob#lookAt API
|
||||
|
||||
|
||||
diff --git a/src/main/java/org/bukkit/entity/Mob.java b/src/main/java/org/bukkit/entity/Mob.java
|
||||
index d726453c041a980576312b6bee96a07837f37974..7d4ce660adb21e579e564796568945ee20f0ca59 100644
|
||||
--- a/src/main/java/org/bukkit/entity/Mob.java
|
||||
+++ b/src/main/java/org/bukkit/entity/Mob.java
|
||||
@@ -23,6 +23,88 @@ public interface Mob extends LivingEntity, Lootable {
|
||||
* @return True if mob is exposed to daylight
|
||||
*/
|
||||
boolean isInDaylight();
|
||||
+
|
||||
+ /**
|
||||
+ * Instruct this Mob to look at a specific Location
|
||||
+ * <p>
|
||||
+ * Useful when implementing custom mob goals
|
||||
+ *
|
||||
+ * @param location location to look at
|
||||
+ */
|
||||
+ void lookAt(@NotNull org.bukkit.Location location);
|
||||
+
|
||||
+ /**
|
||||
+ * Instruct this Mob to look at a specific Location
|
||||
+ * <p>
|
||||
+ * Useful when implementing custom mob goals
|
||||
+ *
|
||||
+ * @param location location to look at
|
||||
+ * @param headRotationSpeed head rotation speed
|
||||
+ * @param maxHeadPitch max head pitch rotation
|
||||
+ */
|
||||
+ void lookAt(@NotNull org.bukkit.Location location, float headRotationSpeed, float maxHeadPitch);
|
||||
+
|
||||
+ /**
|
||||
+ * Instruct this Mob to look at a specific Entity
|
||||
+ * <p>
|
||||
+ * If a LivingEntity, look at eye location
|
||||
+ * <p>
|
||||
+ * Useful when implementing custom mob goals
|
||||
+ *
|
||||
+ * @param entity entity to look at
|
||||
+ */
|
||||
+ void lookAt(@NotNull Entity entity);
|
||||
+
|
||||
+ /**
|
||||
+ * Instruct this Mob to look at a specific Entity
|
||||
+ * <p>
|
||||
+ * If a LivingEntity, look at eye location
|
||||
+ * <p>
|
||||
+ * Useful when implementing custom mob goals
|
||||
+ *
|
||||
+ * @param entity entity to look at
|
||||
+ * @param headRotationSpeed head rotation speed
|
||||
+ * @param maxHeadPitch max head pitch rotation
|
||||
+ */
|
||||
+ void lookAt(@NotNull Entity entity, float headRotationSpeed, float maxHeadPitch);
|
||||
+
|
||||
+ /**
|
||||
+ * Instruct this Mob to look at a specific position
|
||||
+ * <p>
|
||||
+ * Useful when implementing custom mob goals
|
||||
+ *
|
||||
+ * @param x x coordinate
|
||||
+ * @param y y coordinate
|
||||
+ * @param z z coordinate
|
||||
+ */
|
||||
+ void lookAt(double x, double y, double z);
|
||||
+
|
||||
+ /**
|
||||
+ * Instruct this Mob to look at a specific position
|
||||
+ * <p>
|
||||
+ * Useful when implementing custom mob goals
|
||||
+ *
|
||||
+ * @param x x coordinate
|
||||
+ * @param y y coordinate
|
||||
+ * @param z z coordinate
|
||||
+ * @param headRotationSpeed head rotation speed
|
||||
+ * @param maxHeadPitch max head pitch rotation
|
||||
+ */
|
||||
+ void lookAt(double x, double y, double z, float headRotationSpeed, float maxHeadPitch);
|
||||
+
|
||||
+ /**
|
||||
+ * Gets the head rotation speed
|
||||
+ *
|
||||
+ * @return the head rotation speed
|
||||
+ */
|
||||
+ int getHeadRotationSpeed();
|
||||
+
|
||||
+ /**
|
||||
+ * Gets the max head pitch rotation
|
||||
+ *
|
||||
+ * @return the max head pitch rotation
|
||||
+ */
|
||||
+ int getMaxHeadPitch();
|
||||
// Paper end
|
||||
|
||||
/**
|
127
Spigot-Server-Patches/0739-Add-Mob-lookAt-API.patch
Normal file
127
Spigot-Server-Patches/0739-Add-Mob-lookAt-API.patch
Normal file
@ -0,0 +1,127 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: BillyGalbreath <blake.galbreath@gmail.com>
|
||||
Date: Fri, 14 May 2021 13:42:17 -0500
|
||||
Subject: [PATCH] Add Mob#lookAt API
|
||||
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/world/entity/EntityInsentient.java b/src/main/java/net/minecraft/world/entity/EntityInsentient.java
|
||||
index a246edd09854dabf095da75c9d200f5cf26e7138..837bf1b02a66602892c2f572b38b17de6ba6d266 100644
|
||||
--- a/src/main/java/net/minecraft/world/entity/EntityInsentient.java
|
||||
+++ b/src/main/java/net/minecraft/world/entity/EntityInsentient.java
|
||||
@@ -852,14 +852,17 @@ public abstract class EntityInsentient extends EntityLiving {
|
||||
|
||||
protected void mobTick() {}
|
||||
|
||||
+ public int getMaxHeadXRot() { return O(); } // Paper - OBFHELPER
|
||||
public int O() {
|
||||
return 40;
|
||||
}
|
||||
|
||||
+ public int getMaxHeadYRot() { return Q(); } // Paper - OBFHELPER
|
||||
public int Q() {
|
||||
return 75;
|
||||
}
|
||||
|
||||
+ public int getHeadRotSpeed() { return ep(); } // Paper - OBFHELPER
|
||||
public int ep() {
|
||||
return 10;
|
||||
}
|
||||
diff --git a/src/main/java/net/minecraft/world/entity/ai/control/ControllerLook.java b/src/main/java/net/minecraft/world/entity/ai/control/ControllerLook.java
|
||||
index 3ce9edde641c8b8eea75479615bcd2866ffd2198..dadbaa7f43b8678b09c649e19a6eac8ec8b47d9d 100644
|
||||
--- a/src/main/java/net/minecraft/world/entity/ai/control/ControllerLook.java
|
||||
+++ b/src/main/java/net/minecraft/world/entity/ai/control/ControllerLook.java
|
||||
@@ -20,18 +20,28 @@ public class ControllerLook {
|
||||
this.a = entityinsentient;
|
||||
}
|
||||
|
||||
+ public void lookAt(Vec3D vec3d) { a(vec3d); } // Paper - OBFHELPER
|
||||
public void a(Vec3D vec3d) {
|
||||
this.a(vec3d.x, vec3d.y, vec3d.z);
|
||||
}
|
||||
|
||||
+ // Paper start
|
||||
+ public void lookAt(Entity entity) {
|
||||
+ this.lookAt(entity.locX(), getWantedY(entity), entity.locZ());
|
||||
+ }
|
||||
+ // Paper end
|
||||
+
|
||||
+ public void lookAt(Entity entity, float f, float f1) { a(entity, f, f1); } // Paper - OBFHELPER
|
||||
public void a(Entity entity, float f, float f1) {
|
||||
this.a(entity.locX(), b(entity), entity.locZ(), f, f1);
|
||||
}
|
||||
|
||||
+ public void lookAt(double d0, double d1, double d2) { a(d0, d1, d2); } // Paper - OBFHELPER
|
||||
public void a(double d0, double d1, double d2) {
|
||||
this.a(d0, d1, d2, (float) this.a.ep(), (float) this.a.O());
|
||||
}
|
||||
|
||||
+ public void lookAt(double d0, double d1, double d2, float f, float f1) { a(d0, d1, d2, f, f1); } // Paper - OBFHELPER
|
||||
public void a(double d0, double d1, double d2, float f, float f1) {
|
||||
this.e = d0;
|
||||
this.f = d1;
|
||||
@@ -103,6 +113,7 @@ public class ControllerLook {
|
||||
return f + f4;
|
||||
}
|
||||
|
||||
+ public static double getWantedY(Entity entity) { return b(entity); } // Paper - OBFHELPER
|
||||
private static double b(Entity entity) {
|
||||
return entity instanceof EntityLiving ? entity.getHeadY() : (entity.getBoundingBox().minY + entity.getBoundingBox().maxY) / 2.0D;
|
||||
}
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftMob.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftMob.java
|
||||
index 06cbe63ef04e0de824ac0b9d545b6da1f53701b3..125be4ca56d38c6cba1d1f4e7587abda075ee491 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftMob.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftMob.java
|
||||
@@ -84,5 +84,53 @@ public abstract class CraftMob extends CraftLivingEntity implements Mob {
|
||||
public boolean isInDaylight() {
|
||||
return getHandle().isInDaylight();
|
||||
}
|
||||
+
|
||||
+ @Override
|
||||
+ public void lookAt(@org.jetbrains.annotations.NotNull org.bukkit.Location location) {
|
||||
+ com.google.common.base.Preconditions.checkNotNull(location, "location cannot be null");
|
||||
+ com.google.common.base.Preconditions.checkArgument(location.getWorld().equals(getWorld()), "location in a different world");
|
||||
+ getHandle().getControllerLook().lookAt(location.getX(), location.getY(), location.getZ());
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public void lookAt(@org.jetbrains.annotations.NotNull org.bukkit.Location location, float headRotationSpeed, float maxHeadPitch) {
|
||||
+ com.google.common.base.Preconditions.checkNotNull(location, "location cannot be null");
|
||||
+ com.google.common.base.Preconditions.checkArgument(location.getWorld().equals(getWorld()), "location in a different world");
|
||||
+ getHandle().getControllerLook().lookAt(location.getX(), location.getY(), location.getZ(), headRotationSpeed, maxHeadPitch);
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public void lookAt(@org.jetbrains.annotations.NotNull org.bukkit.entity.Entity entity) {
|
||||
+ com.google.common.base.Preconditions.checkNotNull(entity, "entity cannot be null");
|
||||
+ com.google.common.base.Preconditions.checkArgument(entity.getWorld().equals(getWorld()), "entity in a different world");
|
||||
+ getHandle().getControllerLook().lookAt(((CraftEntity) entity).getHandle());
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public void lookAt(@org.jetbrains.annotations.NotNull org.bukkit.entity.Entity entity, float headRotationSpeed, float maxHeadPitch) {
|
||||
+ com.google.common.base.Preconditions.checkNotNull(entity, "entity cannot be null");
|
||||
+ com.google.common.base.Preconditions.checkArgument(entity.getWorld().equals(getWorld()), "entity in a different world");
|
||||
+ getHandle().getControllerLook().lookAt(((CraftEntity) entity).getHandle(), headRotationSpeed, maxHeadPitch);
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public void lookAt(double x, double y, double z) {
|
||||
+ getHandle().getControllerLook().lookAt(x, y, z);
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public void lookAt(double x, double y, double z, float headRotationSpeed, float maxHeadPitch) {
|
||||
+ getHandle().getControllerLook().lookAt(x, y, z, headRotationSpeed, maxHeadPitch);
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public int getHeadRotationSpeed() {
|
||||
+ return getHandle().getHeadRotSpeed();
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public int getMaxHeadPitch() {
|
||||
+ return getHandle().getMaxHeadXRot();
|
||||
+ }
|
||||
// Paper end
|
||||
}
|
Loading…
Reference in New Issue
Block a user