Fix ridable mobs not looking up/down while not in motion

This commit is contained in:
William Blake Galbreath
2019-05-18 01:27:25 -05:00
parent d20b5799eb
commit a589f65f1d

View File

@@ -1,11 +1,11 @@
From e4504b2ee0d50998f0d405860f5d34d6f1d08ec9 Mon Sep 17 00:00:00 2001 From c9543a4248fea54a7443375e7074f7af940aec86 Mon Sep 17 00:00:00 2001
From: William Blake Galbreath <blake.galbreath@gmail.com> From: William Blake Galbreath <blake.galbreath@gmail.com>
Date: Tue, 30 Apr 2019 19:17:21 -0500 Date: Tue, 30 Apr 2019 19:17:21 -0500
Subject: [PATCH] Integrate ridables Subject: [PATCH] Integrate ridables
--- ---
.../server/ControllerLookDolphin.java | 4 +- .../server/ControllerLookDolphin.java | 4 +-
.../java/net/minecraft/server/Entity.java | 9 ++- .../java/net/minecraft/server/Entity.java | 10 ++-
.../net/minecraft/server/EntityAgeable.java | 2 +- .../net/minecraft/server/EntityAgeable.java | 2 +-
.../net/minecraft/server/EntityChicken.java | 2 +- .../net/minecraft/server/EntityChicken.java | 2 +-
.../net/minecraft/server/EntityDolphin.java | 17 +++- .../net/minecraft/server/EntityDolphin.java | 17 +++-
@@ -31,12 +31,12 @@ Subject: [PATCH] Integrate ridables
.../net/minecraft/server/EntitySquid.java | 46 +++++++++++ .../net/minecraft/server/EntitySquid.java | 46 +++++++++++
.../server/EntityTameableAnimal.java | 6 ++ .../server/EntityTameableAnimal.java | 6 ++
.../net/minecraft/server/EntityTypes.java | 6 ++ .../net/minecraft/server/EntityTypes.java | 6 ++
.../purpur/controller/ControllerLookWASD.java | 46 +++++++++++ .../purpur/controller/ControllerLookWASD.java | 74 ++++++++++++++++++
.../purpur/controller/ControllerMoveWASD.java | 77 +++++++++++++++++++ .../purpur/controller/ControllerMoveWASD.java | 77 +++++++++++++++++++
.../controller/ControllerMoveWASDFlying.java | 58 ++++++++++++++ .../controller/ControllerMoveWASDFlying.java | 58 ++++++++++++++
.../controller/ControllerMoveWASDWater.java | 42 ++++++++++ .../controller/ControllerMoveWASDWater.java | 42 ++++++++++
.../craftbukkit/entity/CraftLivingEntity.java | 10 +++ .../craftbukkit/entity/CraftLivingEntity.java | 10 +++
32 files changed, 533 insertions(+), 72 deletions(-) 32 files changed, 562 insertions(+), 72 deletions(-)
create mode 100644 src/main/java/net/pl3x/purpur/controller/ControllerLookWASD.java create mode 100644 src/main/java/net/pl3x/purpur/controller/ControllerLookWASD.java
create mode 100644 src/main/java/net/pl3x/purpur/controller/ControllerMoveWASD.java create mode 100644 src/main/java/net/pl3x/purpur/controller/ControllerMoveWASD.java
create mode 100644 src/main/java/net/pl3x/purpur/controller/ControllerMoveWASDFlying.java create mode 100644 src/main/java/net/pl3x/purpur/controller/ControllerMoveWASDFlying.java
@@ -64,10 +64,18 @@ index 454627f65..df3d6cf28 100644
this.d = false; this.d = false;
this.a.aM = this.a(this.a.aM, this.h() + 20.0F, this.b); this.a.aM = this.a(this.a.aM, this.h() + 20.0F, this.b);
diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java
index ab0995c2c..1490f95c4 100644 index ab0995c2c..e39510e20 100644
--- a/src/main/java/net/minecraft/server/Entity.java --- a/src/main/java/net/minecraft/server/Entity.java
+++ b/src/main/java/net/minecraft/server/Entity.java +++ b/src/main/java/net/minecraft/server/Entity.java
@@ -101,6 +101,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke @@ -78,6 +78,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
protected CraftEntity bukkitEntity;
PlayerChunkMap.EntityTracker tracker; // Paper
+ public PlayerChunkMap.EntityTracker getTracker() { return tracker; } // Purpur
Throwable addedToWorldStack; // Paper - entity debug
public CraftEntity getBukkitEntity() {
if (bukkitEntity == null) {
@@ -101,6 +102,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
private int id; private int id;
public boolean i; public final boolean blocksEntitySpawning() { return this.i; } // Paper - OBFHELPER public boolean i; public final boolean blocksEntitySpawning() { return this.i; } // Paper - OBFHELPER
public final List<Entity> passengers; public final List<Entity> passengers;
@@ -75,7 +83,7 @@ index ab0995c2c..1490f95c4 100644
protected int j; protected int j;
private Entity vehicle; private Entity vehicle;
public boolean attachedToPlayer; public boolean attachedToPlayer;
@@ -134,7 +135,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke @@ -134,7 +136,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
public double H; public double H;
public double I; public double I;
public double J; public double J;
@@ -84,7 +92,7 @@ index ab0995c2c..1490f95c4 100644
public boolean noclip; public boolean noclip;
public float M; public float M;
protected final Random random; protected final Random random;
@@ -2067,6 +2068,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke @@ -2067,6 +2069,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
// Spigot end // Spigot end
if (!this.world.isClientSide && entity instanceof EntityHuman && !(this.getRidingPassenger() instanceof EntityHuman)) { if (!this.world.isClientSide && entity instanceof EntityHuman && !(this.getRidingPassenger() instanceof EntityHuman)) {
this.passengers.add(0, entity); this.passengers.add(0, entity);
@@ -92,7 +100,7 @@ index ab0995c2c..1490f95c4 100644
} else { } else {
this.passengers.add(entity); this.passengers.add(entity);
} }
@@ -2105,6 +2107,11 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke @@ -2105,6 +2108,11 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
return false; return false;
} }
// Spigot end // Spigot end
@@ -966,15 +974,17 @@ index 77d4bbce1..73116e48f 100644
this.be = SystemUtils.a("entity", IRegistry.ENTITY_TYPE.getKey(this)); this.be = SystemUtils.a("entity", IRegistry.ENTITY_TYPE.getKey(this));
diff --git a/src/main/java/net/pl3x/purpur/controller/ControllerLookWASD.java b/src/main/java/net/pl3x/purpur/controller/ControllerLookWASD.java diff --git a/src/main/java/net/pl3x/purpur/controller/ControllerLookWASD.java b/src/main/java/net/pl3x/purpur/controller/ControllerLookWASD.java
new file mode 100644 new file mode 100644
index 000000000..851ab80e4 index 000000000..99e184d36
--- /dev/null --- /dev/null
+++ b/src/main/java/net/pl3x/purpur/controller/ControllerLookWASD.java +++ b/src/main/java/net/pl3x/purpur/controller/ControllerLookWASD.java
@@ -0,0 +1,46 @@ @@ -0,0 +1,74 @@
+package net.pl3x.purpur.controller; +package net.pl3x.purpur.controller;
+ +
+import net.minecraft.server.ControllerLook; +import net.minecraft.server.ControllerLook;
+import net.minecraft.server.EntityHuman; +import net.minecraft.server.EntityHuman;
+import net.minecraft.server.EntityInsentient; +import net.minecraft.server.EntityInsentient;
+import net.minecraft.server.MathHelper;
+import net.minecraft.server.PacketPlayOutEntity;
+ +
+public class ControllerLookWASD extends ControllerLook { +public class ControllerLookWASD extends ControllerLook {
+ protected final EntityInsentient entity; + protected final EntityInsentient entity;
@@ -1005,20 +1015,46 @@ index 000000000..851ab80e4
+ } + }
+ +
+ public void setYawPitch(float yaw, float pitch) { + public void setYawPitch(float yaw, float pitch) {
+ entity.lastYaw = entity.yaw = (yaw + yawOffset) % 360.0F; + entity.yaw = normalizeYaw(yaw + yawOffset);
+ entity.setRenderYawOffset(entity.lastYaw); + entity.lastYaw = entity.yaw;
+ entity.setHeadRotation(entity.lastYaw); + entity.setRenderYawOffset(entity.yaw);
+ entity.pitch = (pitch + pitchOffset) % 360.0F; + entity.setHeadRotation(entity.yaw);
+ entity.pitch = normalizePitch(pitch + pitchOffset);
+
+ entity.getTracker().broadcast(new PacketPlayOutEntity
+ .PacketPlayOutEntityLook(entity.getId(),
+ (byte) MathHelper.d(entity.yaw * 256.0F / 360.0F),
+ (byte) MathHelper.d(entity.pitch * 256.0F / 360.0F),
+ entity.onGround));
+ } + }
+ +
+ public void setOffsets(float yaw, float pitch) { + public void setOffsets(float yaw, float pitch) {
+ yawOffset = yaw; + yawOffset = yaw;
+ pitchOffset = pitch; + pitchOffset = pitch;
+ } + }
+
+ public float normalizeYaw(float yaw) {
+ yaw %= 360.0f;
+ if (yaw >= 180.0f) {
+ yaw -= 360.0f;
+ } else if (yaw < -180.0f) {
+ yaw += 360.0f;
+ }
+ return yaw;
+ }
+
+ public float normalizePitch(float pitch) {
+ if (pitch > 90.0f) {
+ pitch = 90.0f;
+ } else if (pitch < -90.0f) {
+ pitch = -90.0f;
+ }
+ return pitch;
+ }
+} +}
diff --git a/src/main/java/net/pl3x/purpur/controller/ControllerMoveWASD.java b/src/main/java/net/pl3x/purpur/controller/ControllerMoveWASD.java diff --git a/src/main/java/net/pl3x/purpur/controller/ControllerMoveWASD.java b/src/main/java/net/pl3x/purpur/controller/ControllerMoveWASD.java
new file mode 100644 new file mode 100644
index 000000000..4f7dec9bc index 000000000..d64a66274
--- /dev/null --- /dev/null
+++ b/src/main/java/net/pl3x/purpur/controller/ControllerMoveWASD.java +++ b/src/main/java/net/pl3x/purpur/controller/ControllerMoveWASD.java
@@ -0,0 +1,77 @@ @@ -0,0 +1,77 @@
@@ -1065,25 +1101,25 @@ index 000000000..4f7dec9bc
+ forward *= 0.5F; + forward *= 0.5F;
+ } + }
+ +
+ float yaw = rider.yaw; + float yawOffset = 0;
+ if (strafe != 0) { + if (strafe != 0) {
+ if (forward == 0) { + if (forward == 0) {
+ yaw += strafe > 0 ? -90 : 90; + yawOffset += strafe > 0 ? -90 : 90;
+ forward = Math.abs(strafe * 2); + forward = Math.abs(strafe * 2);
+ } else { + } else {
+ yaw += strafe > 0 ? -30 : 30; + yawOffset += strafe > 0 ? -30 : 30;
+ strafe /= 2; + strafe /= 2;
+ if (forward < 0) { + if (forward < 0) {
+ yaw += strafe > 0 ? -110 : 110; + yawOffset += strafe > 0 ? -110 : 110;
+ forward *= -1; + forward *= -1;
+ } + }
+ } + }
+ } else if (forward < 0) { + } else if (forward < 0) {
+ yaw -= 180; + yawOffset -= 180;
+ forward *= -1; + forward *= -1;
+ } + }
+ +
+ ((ControllerLookWASD) entity.getControllerLook()).setOffsets(yaw - rider.yaw, 0); + ((ControllerLookWASD) entity.getControllerLook()).setOffsets(yawOffset, 0);
+ +
+ if (rider.isJumping()) { + if (rider.isJumping()) {
+ //RidableSpacebarEvent event = new RidableSpacebarEvent(entity); + //RidableSpacebarEvent event = new RidableSpacebarEvent(entity);