Fix dragon yaw and make it same as rider yaw. Refactor out redundant calculation of yaw

This commit is contained in:
fullwall 2022-02-20 22:34:29 +08:00
parent 97d4c3b117
commit 897c511757
21 changed files with 111 additions and 227 deletions

View File

@ -128,6 +128,20 @@ public class Util {
return center; return center;
} }
public static float getDragonYaw(Entity entity, double motX, double motZ) {
Location location = entity.getLocation(AT_LOCATION);
double x = location.getX();
double z = location.getZ();
double tX = x + motX;
double tZ = z + motZ;
if (z > tZ)
return (float) (-Math.toDegrees(Math.atan((x - tX) / (z - tZ))));
if (z < tZ) {
return (float) (-Math.toDegrees(Math.atan((x - tX) / (z - tZ)))) + 180.0F;
}
return location.getYaw();
}
public static Scoreboard getDummyScoreboard() { public static Scoreboard getDummyScoreboard() {
return DUMMY_SCOREBOARD; return DUMMY_SCOREBOARD;
} }

View File

@ -112,15 +112,6 @@ public class EnderDragonController extends MobEntityController {
return super.getBukkitEntity(); return super.getBukkitEntity();
} }
private float getCorrectYaw(double tX, double tZ) {
if (locZ > tZ)
return (float) (-Math.toDegrees(Math.atan((locX - tX) / (locZ - tZ))));
if (locZ < tZ) {
return (float) (-Math.toDegrees(Math.atan((locX - tX) / (locZ - tZ)))) + 180.0F;
}
return yaw;
}
@Override @Override
public NPC getNPC() { public NPC getNPC() {
return npc; return npc;
@ -150,11 +141,16 @@ public class EnderDragonController extends MobEntityController {
public void n() { public void n() {
if (npc != null) { if (npc != null) {
npc.update(); npc.update();
if (getBukkitEntity().getPassenger() != null) {
yaw = getBukkitEntity().getPassenger().getLocation().getYaw() - 180;
}
if (motX != 0 || motY != 0 || motZ != 0) { if (motX != 0 || motY != 0 || motZ != 0) {
motX *= 0.98; motX *= 0.98;
motY *= 0.98; motY *= 0.98;
motZ *= 0.98; motZ *= 0.98;
yaw = getCorrectYaw(locX + motX, locZ + motZ); if (getBukkitEntity().getPassenger() == null) {
yaw = Util.getDragonYaw(getBukkitEntity(), motX, motZ);
}
setPosition(locX + motX, locY + motY, locZ + motZ); setPosition(locX + motX, locY + motY, locZ + motZ);
} }
} else { } else {

View File

@ -370,15 +370,6 @@ public class NMSImpl implements NMSBridge {
return new Location(entity.getWorld(), controller.d(), controller.e(), controller.f()); return new Location(entity.getWorld(), controller.d(), controller.e(), controller.f());
} }
private float getDragonYaw(Entity handle, double tX, double tZ) {
if (handle.locZ > tZ)
return (float) (-Math.toDegrees(Math.atan((handle.locX - tX) / (handle.locZ - tZ))));
if (handle.locZ < tZ) {
return (float) (-Math.toDegrees(Math.atan((handle.locX - tX) / (handle.locZ - tZ)))) + 180.0F;
}
return handle.yaw;
}
@Override @Override
public GameProfileRepository getGameProfileRepository() { public GameProfileRepository getGameProfileRepository() {
return ((CraftServer) Bukkit.getServer()).getServer().getGameProfileRepository(); return ((CraftServer) Bukkit.getServer()).getServer().getGameProfileRepository();
@ -733,7 +724,7 @@ public class NMSImpl implements NMSBridge {
if (zDiff < 0.0) if (zDiff < 0.0)
yaw += Math.abs(180 - yaw) * 2; yaw += Math.abs(180 - yaw) * 2;
if (handle instanceof EntityEnderDragon) { if (handle instanceof EntityEnderDragon) {
yaw = getDragonYaw(handle, to.getX(), to.getZ()); yaw = Util.getDragonYaw(handle.getBukkitEntity(), xDiff, zDiff);
} else { } else {
yaw = yaw - 90; yaw = yaw - 90;
} }

View File

@ -113,15 +113,6 @@ public class EnderDragonController extends MobEntityController {
return super.getBukkitEntity(); return super.getBukkitEntity();
} }
private float getCorrectYaw(double tX, double tZ) {
if (locZ > tZ)
return (float) (-Math.toDegrees(Math.atan((locX - tX) / (locZ - tZ))));
if (locZ < tZ) {
return (float) (-Math.toDegrees(Math.atan((locX - tX) / (locZ - tZ)))) + 180.0F;
}
return yaw;
}
@Override @Override
public NPC getNPC() { public NPC getNPC() {
return npc; return npc;
@ -151,11 +142,16 @@ public class EnderDragonController extends MobEntityController {
public void n() { public void n() {
if (npc != null) { if (npc != null) {
npc.update(); npc.update();
if (getBukkitEntity().getPassenger() != null) {
yaw = getBukkitEntity().getPassenger().getLocation().getYaw() - 180;
}
if (motX != 0 || motY != 0 || motZ != 0) { if (motX != 0 || motY != 0 || motZ != 0) {
motX *= 0.98; motX *= 0.98;
motY *= 0.98; motY *= 0.98;
motZ *= 0.98; motZ *= 0.98;
yaw = getCorrectYaw(locX + motX, locZ + motZ); if (getBukkitEntity().getPassenger() == null) {
yaw = Util.getDragonYaw(getBukkitEntity(), motX, motZ);
}
setPosition(locX + motX, locY + motY, locZ + motZ); setPosition(locX + motX, locY + motY, locZ + motZ);
} }
} else { } else {

View File

@ -389,15 +389,6 @@ public class NMSImpl implements NMSBridge {
return new Location(entity.getWorld(), controller.d(), controller.e(), controller.f()); return new Location(entity.getWorld(), controller.d(), controller.e(), controller.f());
} }
private float getDragonYaw(Entity handle, double tX, double tZ) {
if (handle.locZ > tZ)
return (float) (-Math.toDegrees(Math.atan((handle.locX - tX) / (handle.locZ - tZ))));
if (handle.locZ < tZ) {
return (float) (-Math.toDegrees(Math.atan((handle.locX - tX) / (handle.locZ - tZ)))) + 180.0F;
}
return handle.yaw;
}
@Override @Override
public GameProfileRepository getGameProfileRepository() { public GameProfileRepository getGameProfileRepository() {
return ((CraftServer) Bukkit.getServer()).getServer().getGameProfileRepository(); return ((CraftServer) Bukkit.getServer()).getServer().getGameProfileRepository();
@ -787,7 +778,7 @@ public class NMSImpl implements NMSBridge {
if (zDiff < 0.0) if (zDiff < 0.0)
yaw += Math.abs(180 - yaw) * 2; yaw += Math.abs(180 - yaw) * 2;
if (handle instanceof EntityEnderDragon) { if (handle instanceof EntityEnderDragon) {
yaw = getDragonYaw(handle, to.getX(), to.getZ()); yaw = Util.getDragonYaw(handle.getBukkitEntity(), xDiff, zDiff);
} else { } else {
yaw = yaw - 90; yaw = yaw - 90;
} }

View File

@ -116,15 +116,6 @@ public class EnderDragonController extends MobEntityController {
return super.getBukkitEntity(); return super.getBukkitEntity();
} }
private float getCorrectYaw(double tX, double tZ) {
if (locZ > tZ)
return (float) (-Math.toDegrees(Math.atan((locX - tX) / (locZ - tZ))));
if (locZ < tZ) {
return (float) (-Math.toDegrees(Math.atan((locX - tX) / (locZ - tZ)))) + 180.0F;
}
return yaw;
}
@Override @Override
public NPC getNPC() { public NPC getNPC() {
return npc; return npc;
@ -154,11 +145,16 @@ public class EnderDragonController extends MobEntityController {
public void n() { public void n() {
if (npc != null) { if (npc != null) {
npc.update(); npc.update();
if (getBukkitEntity().getPassenger() != null) {
yaw = getBukkitEntity().getPassenger().getLocation().getYaw() - 180;
}
if (motX != 0 || motY != 0 || motZ != 0) { if (motX != 0 || motY != 0 || motZ != 0) {
motX *= 0.98; motX *= 0.98;
motY *= 0.98; motY *= 0.98;
motZ *= 0.98; motZ *= 0.98;
yaw = getCorrectYaw(locX + motX, locZ + motZ); if (getBukkitEntity().getPassenger() == null) {
yaw = Util.getDragonYaw(getBukkitEntity(), motX, motZ);
}
setPosition(locX + motX, locY + motY, locZ + motZ); setPosition(locX + motX, locY + motY, locZ + motZ);
} }
} else { } else {

View File

@ -393,15 +393,6 @@ public class NMSImpl implements NMSBridge {
return new Location(entity.getWorld(), controller.d(), controller.e(), controller.f()); return new Location(entity.getWorld(), controller.d(), controller.e(), controller.f());
} }
private float getDragonYaw(Entity handle, double tX, double tZ) {
if (handle.locZ > tZ)
return (float) (-Math.toDegrees(Math.atan((handle.locX - tX) / (handle.locZ - tZ))));
if (handle.locZ < tZ) {
return (float) (-Math.toDegrees(Math.atan((handle.locX - tX) / (handle.locZ - tZ)))) + 180.0F;
}
return handle.yaw;
}
@Override @Override
public GameProfileRepository getGameProfileRepository() { public GameProfileRepository getGameProfileRepository() {
return ((CraftServer) Bukkit.getServer()).getServer().getGameProfileRepository(); return ((CraftServer) Bukkit.getServer()).getServer().getGameProfileRepository();
@ -794,7 +785,7 @@ public class NMSImpl implements NMSBridge {
if (zDiff < 0.0) if (zDiff < 0.0)
yaw += Math.abs(180 - yaw) * 2; yaw += Math.abs(180 - yaw) * 2;
if (handle instanceof EntityEnderDragon) { if (handle instanceof EntityEnderDragon) {
yaw = getDragonYaw(handle, to.getX(), to.getZ()); yaw = Util.getDragonYaw(handle.getBukkitEntity(), xDiff, zDiff);
} else { } else {
yaw = yaw - 90; yaw = yaw - 90;
} }

View File

@ -122,15 +122,6 @@ public class EnderDragonController extends MobEntityController {
return super.getBukkitEntity(); return super.getBukkitEntity();
} }
private float getCorrectYaw(double tX, double tZ) {
if (locZ > tZ)
return (float) (-Math.toDegrees(Math.atan((locX - tX) / (locZ - tZ))));
if (locZ < tZ) {
return (float) (-Math.toDegrees(Math.atan((locX - tX) / (locZ - tZ)))) + 180.0F;
}
return yaw;
}
@Override @Override
public NPC getNPC() { public NPC getNPC() {
return npc; return npc;
@ -160,11 +151,16 @@ public class EnderDragonController extends MobEntityController {
public void movementTick() { public void movementTick() {
if (npc != null) { if (npc != null) {
npc.update(); npc.update();
if (getBukkitEntity().getPassenger() != null) {
yaw = getBukkitEntity().getPassenger().getLocation().getYaw() - 180;
}
if (motX != 0 || motY != 0 || motZ != 0) { if (motX != 0 || motY != 0 || motZ != 0) {
motX *= 0.98; motX *= 0.98;
motY *= 0.98; motY *= 0.98;
motZ *= 0.98; motZ *= 0.98;
yaw = getCorrectYaw(locX + motX, locZ + motZ); if (getBukkitEntity().getPassenger() == null) {
yaw = Util.getDragonYaw(getBukkitEntity(), motX, motZ);
}
setPosition(locX + motX, locY + motY, locZ + motZ); setPosition(locX + motX, locY + motY, locZ + motZ);
} }
} else { } else {

View File

@ -415,15 +415,6 @@ public class NMSImpl implements NMSBridge {
return new Location(entity.getWorld(), controller.d(), controller.e(), controller.f()); return new Location(entity.getWorld(), controller.d(), controller.e(), controller.f());
} }
private float getDragonYaw(Entity handle, double tX, double tZ) {
if (handle.locZ > tZ)
return (float) (-Math.toDegrees(Math.atan((handle.locX - tX) / (handle.locZ - tZ))));
if (handle.locZ < tZ) {
return (float) (-Math.toDegrees(Math.atan((handle.locX - tX) / (handle.locZ - tZ)))) + 180.0F;
}
return handle.yaw;
}
@Override @Override
public GameProfileRepository getGameProfileRepository() { public GameProfileRepository getGameProfileRepository() {
return ((CraftServer) Bukkit.getServer()).getServer().getGameProfileRepository(); return ((CraftServer) Bukkit.getServer()).getServer().getGameProfileRepository();
@ -830,7 +821,7 @@ public class NMSImpl implements NMSBridge {
if (zDiff < 0.0) if (zDiff < 0.0)
yaw += Math.abs(180 - yaw) * 2; yaw += Math.abs(180 - yaw) * 2;
if (handle instanceof EntityEnderDragon) { if (handle instanceof EntityEnderDragon) {
yaw = getDragonYaw(handle, to.getX(), to.getZ()); yaw = Util.getDragonYaw(handle.getBukkitEntity(), xDiff, zDiff);
} else { } else {
yaw = yaw - 90; yaw = yaw - 90;
} }

View File

@ -113,15 +113,6 @@ public class EnderDragonController extends MobEntityController {
return super.getBukkitEntity(); return super.getBukkitEntity();
} }
private float getCorrectYaw(double tX, double tZ) {
if (locZ > tZ)
return (float) (-Math.toDegrees(Math.atan((locX - tX) / (locZ - tZ))));
if (locZ < tZ) {
return (float) (-Math.toDegrees(Math.atan((locX - tX) / (locZ - tZ)))) + 180.0F;
}
return yaw;
}
@Override @Override
public NPC getNPC() { public NPC getNPC() {
return npc; return npc;
@ -159,10 +150,15 @@ public class EnderDragonController extends MobEntityController {
public void movementTick() { public void movementTick() {
if (npc != null) { if (npc != null) {
npc.update(); npc.update();
if (getRidingPassenger() != null) {
yaw = getRidingPassenger().getBukkitYaw() - 180;
}
Vec3D mot = getMot(); Vec3D mot = getMot();
if (mot.getX() != 0 || mot.getY() != 0 || mot.getZ() != 0) { if (mot.getX() != 0 || mot.getY() != 0 || mot.getZ() != 0) {
mot = mot.d(0.98, 0.98, 0.98); mot = mot.d(0.98, 0.98, 0.98);
yaw = getCorrectYaw(locX + mot.getX(), locZ + mot.getZ()); if (getRidingPassenger() == null) {
yaw = Util.getDragonYaw(getBukkitEntity(), mot.x, mot.z);
}
setPosition(locX + mot.getX(), locY + mot.getY(), locZ + mot.getZ()); setPosition(locX + mot.getX(), locY + mot.getY(), locZ + mot.getZ());
setMot(mot); setMot(mot);
} }

View File

@ -458,15 +458,6 @@ public class NMSImpl implements NMSBridge {
return new Location(entity.getWorld(), controller.d(), controller.e(), controller.f()); return new Location(entity.getWorld(), controller.d(), controller.e(), controller.f());
} }
private float getDragonYaw(Entity handle, double tX, double tZ) {
if (handle.locZ > tZ)
return (float) (-Math.toDegrees(Math.atan((handle.locX - tX) / (handle.locZ - tZ))));
if (handle.locZ < tZ) {
return (float) (-Math.toDegrees(Math.atan((handle.locX - tX) / (handle.locZ - tZ)))) + 180.0F;
}
return handle.yaw;
}
@Override @Override
public GameProfileRepository getGameProfileRepository() { public GameProfileRepository getGameProfileRepository() {
return ((CraftServer) Bukkit.getServer()).getServer().getGameProfileRepository(); return ((CraftServer) Bukkit.getServer()).getServer().getGameProfileRepository();
@ -898,7 +889,7 @@ public class NMSImpl implements NMSBridge {
if (zDiff < 0.0) if (zDiff < 0.0)
yaw += Math.abs(180 - yaw) * 2; yaw += Math.abs(180 - yaw) * 2;
if (handle instanceof EntityEnderDragon) { if (handle instanceof EntityEnderDragon) {
yaw = getDragonYaw(handle, to.getX(), to.getZ()); yaw = Util.getDragonYaw(handle.getBukkitEntity(), xDiff, zDiff);
} else { } else {
yaw = yaw - 90; yaw = yaw - 90;
} }

View File

@ -105,15 +105,6 @@ public class EnderDragonController extends MobEntityController {
return super.getBukkitEntity(); return super.getBukkitEntity();
} }
private float getCorrectYaw(double tX, double tZ) {
if (locZ() > tZ)
return (float) (-Math.toDegrees(Math.atan((locX() - tX) / (locZ() - tZ))));
if (locZ() < tZ) {
return (float) (-Math.toDegrees(Math.atan((locX() - tX) / (locX() - tZ)))) + 180.0F;
}
return yaw;
}
@Override @Override
public NPC getNPC() { public NPC getNPC() {
return npc; return npc;
@ -162,10 +153,15 @@ public class EnderDragonController extends MobEntityController {
NMSImpl.updateMinecraftAIState(npc, this); NMSImpl.updateMinecraftAIState(npc, this);
} }
if (npc != null && !npc.useMinecraftAI()) { if (npc != null && !npc.useMinecraftAI()) {
if (getRidingPassenger() != null) {
yaw = getRidingPassenger().getBukkitYaw() - 180;
}
Vec3D mot = getMot(); Vec3D mot = getMot();
if (mot.getX() != 0 || mot.getY() != 0 || mot.getZ() != 0) { if (mot.getX() != 0 || mot.getY() != 0 || mot.getZ() != 0) {
mot = mot.d(0.98, 0.98, 0.98); mot = mot.d(0.98, 0.98, 0.98);
yaw = getCorrectYaw(locX() + mot.getX(), locZ() + mot.getZ()); if (getRidingPassenger() == null) {
yaw = Util.getDragonYaw(getBukkitEntity(), mot.x, mot.z);
}
setPosition(locX() + mot.getX(), locY() + mot.getY(), locZ() + mot.getZ()); setPosition(locX() + mot.getX(), locY() + mot.getY(), locZ() + mot.getZ());
setMot(mot); setMot(mot);
} }

View File

@ -467,15 +467,6 @@ public class NMSImpl implements NMSBridge {
return new Location(entity.getWorld(), controller.d(), controller.e(), controller.f()); return new Location(entity.getWorld(), controller.d(), controller.e(), controller.f());
} }
private float getDragonYaw(Entity handle, double tX, double tZ) {
if (handle.locZ() > tZ)
return (float) (-Math.toDegrees(Math.atan((handle.locX() - tX) / (handle.locZ() - tZ))));
if (handle.locZ() < tZ) {
return (float) (-Math.toDegrees(Math.atan((handle.locX() - tX) / (handle.locZ() - tZ)))) + 180.0F;
}
return handle.yaw;
}
@Override @Override
public GameProfileRepository getGameProfileRepository() { public GameProfileRepository getGameProfileRepository() {
return ((CraftServer) Bukkit.getServer()).getServer().getGameProfileRepository(); return ((CraftServer) Bukkit.getServer()).getServer().getGameProfileRepository();
@ -910,7 +901,7 @@ public class NMSImpl implements NMSBridge {
if (zDiff < 0.0) if (zDiff < 0.0)
yaw += Math.abs(180 - yaw) * 2; yaw += Math.abs(180 - yaw) * 2;
if (handle instanceof EntityEnderDragon) { if (handle instanceof EntityEnderDragon) {
yaw = getDragonYaw(handle, to.getX(), to.getZ()); yaw = Util.getDragonYaw(handle.getBukkitEntity(), xDiff, zDiff);
} else { } else {
yaw = yaw - 90; yaw = yaw - 90;
} }

View File

@ -98,15 +98,6 @@ public class EnderDragonController extends MobEntityController {
return super.getBukkitEntity(); return super.getBukkitEntity();
} }
private float getCorrectYaw(double tX, double tZ) {
if (locZ() > tZ)
return (float) (-Math.toDegrees(Math.atan((locX() - tX) / (locZ() - tZ))));
if (locZ() < tZ) {
return (float) (-Math.toDegrees(Math.atan((locX() - tX) / (locX() - tZ)))) + 180.0F;
}
return yaw;
}
@Override @Override
public NPC getNPC() { public NPC getNPC() {
return npc; return npc;
@ -155,10 +146,15 @@ public class EnderDragonController extends MobEntityController {
NMSImpl.updateMinecraftAIState(npc, this); NMSImpl.updateMinecraftAIState(npc, this);
} }
if (npc != null && !npc.useMinecraftAI()) { if (npc != null && !npc.useMinecraftAI()) {
if (getRidingPassenger() != null) {
yaw = getRidingPassenger().getBukkitYaw() - 180;
}
Vec3D mot = getMot(); Vec3D mot = getMot();
if (mot.getX() != 0 || mot.getY() != 0 || mot.getZ() != 0) { if (mot.getX() != 0 || mot.getY() != 0 || mot.getZ() != 0) {
mot = mot.d(0.98, 0.98, 0.98); mot = mot.d(0.98, 0.98, 0.98);
yaw = getCorrectYaw(locX() + mot.getX(), locZ() + mot.getZ()); if (getRidingPassenger() == null) {
yaw = Util.getDragonYaw(getBukkitEntity(), mot.x, mot.z);
}
setPosition(locX() + mot.getX(), locY() + mot.getY(), locZ() + mot.getZ()); setPosition(locX() + mot.getX(), locY() + mot.getY(), locZ() + mot.getZ());
setMot(mot); setMot(mot);
} }

View File

@ -473,15 +473,6 @@ public class NMSImpl implements NMSBridge {
return new Location(entity.getWorld(), controller.d(), controller.e(), controller.f()); return new Location(entity.getWorld(), controller.d(), controller.e(), controller.f());
} }
private float getDragonYaw(Entity handle, double tX, double tZ) {
if (handle.locZ() > tZ)
return (float) (-Math.toDegrees(Math.atan((handle.locX() - tX) / (handle.locZ() - tZ))));
if (handle.locZ() < tZ) {
return (float) (-Math.toDegrees(Math.atan((handle.locX() - tX) / (handle.locZ() - tZ)))) + 180.0F;
}
return handle.yaw;
}
@Override @Override
public GameProfileRepository getGameProfileRepository() { public GameProfileRepository getGameProfileRepository() {
return ((CraftServer) Bukkit.getServer()).getServer().getGameProfileRepository(); return ((CraftServer) Bukkit.getServer()).getServer().getGameProfileRepository();
@ -930,7 +921,7 @@ public class NMSImpl implements NMSBridge {
if (zDiff < 0.0) if (zDiff < 0.0)
yaw += Math.abs(180 - yaw) * 2; yaw += Math.abs(180 - yaw) * 2;
if (handle.getBukkitEntity().getType() == EntityType.ENDER_DRAGON) { if (handle.getBukkitEntity().getType() == EntityType.ENDER_DRAGON) {
yaw = getDragonYaw(handle, to.getX(), to.getZ()); yaw = Util.getDragonYaw(handle.getBukkitEntity(), xDiff, zDiff);
} else { } else {
yaw = yaw - 90; yaw = yaw - 90;
} }

View File

@ -62,10 +62,15 @@ public class EnderDragonController extends MobEntityController {
NMSImpl.updateMinecraftAIState(npc, this); NMSImpl.updateMinecraftAIState(npc, this);
} }
if (npc != null && !npc.useMinecraftAI()) { if (npc != null && !npc.useMinecraftAI()) {
if (getFirstPassenger() != null) {
setYRot(getFirstPassenger().getBukkitYaw() - 180);
}
Vec3 mot = getDeltaMovement(); Vec3 mot = getDeltaMovement();
if (mot.x != 0 || mot.y != 0 || mot.z != 0) { if (mot.x != 0 || mot.y != 0 || mot.z != 0) {
mot = mot.multiply(0.98, 0.98, 0.98); mot = mot.multiply(0.98, 0.98, 0.98);
setYRot(getCorrectYaw(getX() + mot.x, getZ() + mot.z)); if (getFirstPassenger() == null) {
setYRot(Util.getDragonYaw(getBukkitEntity(), mot.x, mot.z));
}
setPos(getX() + mot.x, getY() + mot.y, getZ() + mot.z); setPos(getX() + mot.x, getY() + mot.y, getZ() + mot.z);
setDeltaMovement(mot); setDeltaMovement(mot);
} }
@ -115,15 +120,6 @@ public class EnderDragonController extends MobEntityController {
return super.getBukkitEntity(); return super.getBukkitEntity();
} }
private float getCorrectYaw(double tX, double tZ) {
if (getZ() > tZ)
return (float) (-Math.toDegrees(Math.atan((getX() - tX) / (getZ() - tZ))));
if (getZ() < tZ) {
return (float) (-Math.toDegrees(Math.atan((getX() - tX) / (getX() - tZ)))) + 180.0F;
}
return getYRot();
}
@Override @Override
protected SoundEvent getDeathSound() { protected SoundEvent getDeathSound() {
return NMSImpl.getSoundEffect(npc, super.getDeathSound(), NPC.DEATH_SOUND_METADATA); return NMSImpl.getSoundEffect(npc, super.getDeathSound(), NPC.DEATH_SOUND_METADATA);

View File

@ -486,15 +486,6 @@ public class NMSImpl implements NMSBridge {
controller.getWantedZ()); controller.getWantedZ());
} }
private float getDragonYaw(Entity handle, double tX, double tZ) {
if (handle.getZ() > tZ)
return (float) (-Math.toDegrees(Math.atan((handle.getX() - tX) / (handle.getZ() - tZ))));
if (handle.getZ() < tZ) {
return (float) (-Math.toDegrees(Math.atan((handle.getX() - tX) / (handle.getZ() - tZ)))) + 180.0F;
}
return handle.getYRot();
}
@Override @Override
public GameProfileRepository getGameProfileRepository() { public GameProfileRepository getGameProfileRepository() {
return ((CraftServer) Bukkit.getServer()).getServer().getProfileRepository(); return ((CraftServer) Bukkit.getServer()).getServer().getProfileRepository();
@ -934,7 +925,7 @@ public class NMSImpl implements NMSBridge {
if (zDiff < 0.0) if (zDiff < 0.0)
yaw += Math.abs(180 - yaw) * 2; yaw += Math.abs(180 - yaw) * 2;
if (handle.getBukkitEntity().getType() == EntityType.ENDER_DRAGON) { if (handle.getBukkitEntity().getType() == EntityType.ENDER_DRAGON) {
yaw = getDragonYaw(handle, to.getX(), to.getZ()); yaw = Util.getDragonYaw(handle.getBukkitEntity(), xDiff, zDiff);
} else { } else {
yaw = yaw - 90; yaw = yaw - 90;
} }

View File

@ -64,10 +64,15 @@ public class EnderDragonController extends MobEntityController {
NMSImpl.updateMinecraftAIState(npc, this); NMSImpl.updateMinecraftAIState(npc, this);
} }
if (npc != null && !npc.useMinecraftAI()) { if (npc != null && !npc.useMinecraftAI()) {
if (getFirstPassenger() != null) {
setYRot(getFirstPassenger().getBukkitYaw() - 180);
}
Vec3 mot = getDeltaMovement(); Vec3 mot = getDeltaMovement();
if (mot.x != 0 || mot.y != 0 || mot.z != 0) { if (mot.x != 0 || mot.y != 0 || mot.z != 0) {
mot = mot.multiply(0.98, 0.98, 0.98); mot = mot.multiply(0.98, 0.98, 0.98);
setYRot(getCorrectYaw(getX() + mot.x, getZ() + mot.z)); if (getFirstPassenger() == null) {
setYRot(Util.getDragonYaw(getBukkitEntity(), mot.x, mot.z));
}
setPos(getX() + mot.x, getY() + mot.y, getZ() + mot.z); setPos(getX() + mot.x, getY() + mot.y, getZ() + mot.z);
setDeltaMovement(mot); setDeltaMovement(mot);
} }
@ -117,15 +122,6 @@ public class EnderDragonController extends MobEntityController {
return super.getBukkitEntity(); return super.getBukkitEntity();
} }
private float getCorrectYaw(double tX, double tZ) {
if (getZ() > tZ)
return (float) (-Math.toDegrees(Math.atan((getX() - tX) / (getZ() - tZ))));
if (getZ() < tZ) {
return (float) (-Math.toDegrees(Math.atan((getX() - tX) / (getX() - tZ)))) + 180.0F;
}
return getYRot();
}
@Override @Override
protected SoundEvent getDeathSound() { protected SoundEvent getDeathSound() {
return NMSImpl.getSoundEffect(npc, super.getDeathSound(), NPC.DEATH_SOUND_METADATA); return NMSImpl.getSoundEffect(npc, super.getDeathSound(), NPC.DEATH_SOUND_METADATA);

View File

@ -490,15 +490,6 @@ public class NMSImpl implements NMSBridge {
controller.getWantedZ()); controller.getWantedZ());
} }
private float getDragonYaw(Entity handle, double tX, double tZ) {
if (handle.getZ() > tZ)
return (float) (-Math.toDegrees(Math.atan((handle.getX() - tX) / (handle.getZ() - tZ))));
if (handle.getZ() < tZ) {
return (float) (-Math.toDegrees(Math.atan((handle.getX() - tX) / (handle.getZ() - tZ)))) + 180.0F;
}
return handle.getYRot();
}
@Override @Override
public GameProfileRepository getGameProfileRepository() { public GameProfileRepository getGameProfileRepository() {
return ((CraftServer) Bukkit.getServer()).getServer().getProfileRepository(); return ((CraftServer) Bukkit.getServer()).getServer().getProfileRepository();
@ -937,7 +928,7 @@ public class NMSImpl implements NMSBridge {
if (zDiff < 0.0) if (zDiff < 0.0)
yaw += Math.abs(180 - yaw) * 2; yaw += Math.abs(180 - yaw) * 2;
if (handle.getBukkitEntity().getType() == EntityType.ENDER_DRAGON) { if (handle.getBukkitEntity().getType() == EntityType.ENDER_DRAGON) {
yaw = getDragonYaw(handle, to.getX(), to.getZ()); yaw = Util.getDragonYaw(handle.getBukkitEntity(), xDiff, zDiff);
} else { } else {
yaw = yaw - 90; yaw = yaw - 90;
} }

View File

@ -56,14 +56,27 @@ public class EnderDragonController extends MobEntityController {
} }
} }
@Override
protected String bo() {
return NMSImpl.getSoundEffect(npc, super.bo(), NPC.HURT_SOUND_METADATA);
}
@Override @Override
protected String bp() { protected String bp() {
return NMSImpl.getSoundEffect(npc, super.bp(), NPC.DEATH_SOUND_METADATA); return NMSImpl.getSoundEffect(npc, super.bp(), NPC.DEATH_SOUND_METADATA);
} }
@Override @Override
protected String bo() { public boolean cc() {
return NMSImpl.getSoundEffect(npc, super.bo(), NPC.HURT_SOUND_METADATA); if (npc == null)
return super.cc();
boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true);
if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault))
return super.cc();
if (super.cc()) {
unleash(true, false); // clearLeash with client update
}
return false; // shouldLeash
} }
@Override @Override
@ -80,6 +93,13 @@ public class EnderDragonController extends MobEntityController {
return npc == null ? super.d(save) : false; return npc == null ? super.d(save) : false;
} }
@Override
protected void D() {
if (npc == null) {
super.D();
}
}
@Override @Override
public void enderTeleportTo(double d0, double d1, double d2) { public void enderTeleportTo(double d0, double d1, double d2) {
if (npc == null) if (npc == null)
@ -99,11 +119,6 @@ public class EnderDragonController extends MobEntityController {
} }
} }
@Override
protected String z() {
return NMSImpl.getSoundEffect(npc, super.z(), NPC.AMBIENT_SOUND_METADATA);
}
@Override @Override
public CraftEntity getBukkitEntity() { public CraftEntity getBukkitEntity() {
if (npc != null && !(bukkitEntity instanceof NPCHolder)) if (npc != null && !(bukkitEntity instanceof NPCHolder))
@ -111,54 +126,35 @@ public class EnderDragonController extends MobEntityController {
return super.getBukkitEntity(); return super.getBukkitEntity();
} }
private float getCorrectYaw(double tX, double tZ) {
if (locZ > tZ)
return (float) (-Math.toDegrees(Math.atan((locX - tX) / (locZ - tZ))));
if (locZ < tZ) {
return (float) (-Math.toDegrees(Math.atan((locX - tX) / (locZ - tZ)))) + 180.0F;
}
return yaw;
}
@Override @Override
public NPC getNPC() { public NPC getNPC() {
return npc; return npc;
} }
@Override
public boolean cc() {
if (npc == null)
return super.cc();
boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true);
if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault))
return super.cc();
if (super.cc()) {
unleash(true, false); // clearLeash with client update
}
return false; // shouldLeash
}
@Override
protected void D() {
if (npc == null) {
super.D();
}
}
@Override @Override
public void m() { public void m() {
if (npc != null) { if (npc != null) {
npc.update(); npc.update();
if (getBukkitEntity().getPassenger() != null) {
yaw = getBukkitEntity().getPassenger().getLocation().getYaw() - 180;
}
if (motX != 0 || motY != 0 || motZ != 0) { if (motX != 0 || motY != 0 || motZ != 0) {
motX *= 0.98; motX *= 0.98;
motY *= 0.98; motY *= 0.98;
motZ *= 0.98; motZ *= 0.98;
yaw = getCorrectYaw(locX + motX, locZ + motZ); if (getBukkitEntity().getPassenger() == null) {
yaw = Util.getDragonYaw(getBukkitEntity(), motX, motZ);
}
setPosition(locX + motX, locY + motY, locZ + motZ); setPosition(locX + motX, locY + motY, locZ + motZ);
} }
} else { } else {
super.m(); super.m();
} }
} }
@Override
protected String z() {
return NMSImpl.getSoundEffect(npc, super.z(), NPC.AMBIENT_SOUND_METADATA);
}
} }
} }

View File

@ -322,15 +322,6 @@ public class NMSImpl implements NMSBridge {
return new Location(entity.getWorld(), controller.d(), controller.e(), controller.f()); return new Location(entity.getWorld(), controller.d(), controller.e(), controller.f());
} }
private float getDragonYaw(Entity handle, double tX, double tZ) {
if (handle.locZ > tZ)
return (float) (-Math.toDegrees(Math.atan((handle.locX - tX) / (handle.locZ - tZ))));
if (handle.locZ < tZ) {
return (float) (-Math.toDegrees(Math.atan((handle.locX - tX) / (handle.locZ - tZ)))) + 180.0F;
}
return handle.yaw;
}
@Override @Override
public GameProfileRepository getGameProfileRepository() { public GameProfileRepository getGameProfileRepository() {
return ((CraftServer) Bukkit.getServer()).getServer().getGameProfileRepository(); return ((CraftServer) Bukkit.getServer()).getServer().getGameProfileRepository();
@ -665,7 +656,7 @@ public class NMSImpl implements NMSBridge {
if (zDiff < 0.0) if (zDiff < 0.0)
yaw += Math.abs(180 - yaw) * 2; yaw += Math.abs(180 - yaw) * 2;
if (handle instanceof EntityEnderDragon) { if (handle instanceof EntityEnderDragon) {
yaw = getDragonYaw(handle, to.getX(), to.getZ()); yaw = Util.getDragonYaw(handle.getBukkitEntity(), xDiff, zDiff);
} else { } else {
yaw = yaw - 90; yaw = yaw - 90;
} }