From 3a612d64b7fa1fb1ca1da328e947e011567f1afb Mon Sep 17 00:00:00 2001 From: fullwall Date: Tue, 29 Nov 2016 00:25:28 +0800 Subject: [PATCH] Fix Guardians, EnderDragon looking and update how bats/silverfish/endermite looking is handled --- .../nms/v1_11_R1/entity/EntityHumanNPC.java | 19 ++++++- .../v1_11_R1/entity/GuardianController.java | 19 ++++--- .../entity/GuardianElderController.java | 19 ++++--- .../nms/v1_11_R1/entity/HorseController.java | 5 +- .../entity/HorseDonkeyController.java | 5 +- .../v1_11_R1/entity/HorseMuleController.java | 5 +- .../entity/HorseSkeletonController.java | 5 +- .../entity/HorseZombieController.java | 5 +- .../v1_11_R1/entity/PolarBearController.java | 17 +++--- .../nms/v1_11_R1/entity/VexController.java | 6 +- .../nms/v1_11_R1/util/NMSImpl.java | 55 +++++++++++++++---- 11 files changed, 100 insertions(+), 60 deletions(-) diff --git a/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/entity/EntityHumanNPC.java b/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/entity/EntityHumanNPC.java index 98d7b7c1e..80cf0ac4c 100644 --- a/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/entity/EntityHumanNPC.java +++ b/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/entity/EntityHumanNPC.java @@ -111,7 +111,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable super.A_(); if (npc == null) return; - livingEntityBaseTick(); + livingEntityBaseTick(); if (updateCounter + 1 > Setting.PACKET_UPDATE_DELAY.asInt()) { updateEffects = true; } @@ -122,7 +122,6 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable && Util.isLoaded(getBukkitEntity().getLocation(LOADED_LOCATION))) { g(0, 0); } - if (Math.abs(motX) < EPSILON && Math.abs(motY) < EPSILON && Math.abs(motZ) < EPSILON) { motX = motY = motZ = 0; } @@ -141,6 +140,17 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable npc.update(); } + private float bodyControla(float paramFloat1, float paramFloat2, float paramFloat3) { + float f = MathHelper.g(paramFloat1 - paramFloat2); + if (f < -paramFloat3) { + f = -paramFloat3; + } + if (f >= paramFloat3) { + f = paramFloat3; + } + return paramFloat1 - f; + } + @Override public void collide(net.minecraft.server.v1_11_R1.Entity entity) { // this method is called by both the entities involved - cancelling @@ -284,6 +294,11 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable return skinTracker; } + @Override + protected float h(float f, float f1) { + return f1; + } + private void initialise(MinecraftServer minecraftServer) { Socket socket = new EmptySocket(); NetworkManager conn = null; diff --git a/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/entity/GuardianController.java b/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/entity/GuardianController.java index 59410f06c..7bcf72246 100644 --- a/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/entity/GuardianController.java +++ b/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/entity/GuardianController.java @@ -53,15 +53,6 @@ public class GuardianController extends MobEntityController { } } - @Override - public void A_() { - if (npc == null) { - super.A_(); - } else { - npc.update(); - } - } - @Override protected SoundEffect bW() { return NMSImpl.getSoundEffect(npc, super.bW(), NPC.DEATH_SOUND_METADATA); @@ -182,6 +173,16 @@ public class GuardianController extends MobEntityController { } } + @Override + public void n() { + if (npc == null) { + super.n(); + } else { + NMSImpl.updateAI(this); + npc.update(); + } + } + @Override public void setSize(float f, float f1) { if (npc == null) { diff --git a/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/entity/GuardianElderController.java b/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/entity/GuardianElderController.java index 9f43a2f9f..48852b38e 100644 --- a/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/entity/GuardianElderController.java +++ b/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/entity/GuardianElderController.java @@ -53,15 +53,6 @@ public class GuardianElderController extends MobEntityController { } } - @Override - public void A_() { - if (npc == null) { - super.A_(); - } else { - npc.update(); - } - } - @Override protected SoundEffect bW() { return NMSImpl.getSoundEffect(npc, super.bW(), NPC.DEATH_SOUND_METADATA); @@ -182,6 +173,16 @@ public class GuardianElderController extends MobEntityController { } } + @Override + public void n() { + if (npc == null) { + super.n(); + } else { + NMSImpl.updateAI(this); + npc.update(); + } + } + @Override public void setSize(float f, float f1) { if (npc == null) { diff --git a/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/entity/HorseController.java b/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/entity/HorseController.java index 7d9fe4650..5cd2786b1 100644 --- a/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/entity/HorseController.java +++ b/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/entity/HorseController.java @@ -187,9 +187,8 @@ public class HorseController extends MobEntityController { @Override public void M() { - if (npc == null) { - super.M(); - } else { + super.M(); + if (npc != null) { NMS.setStepHeight(getBukkitEntity(), 1); npc.update(); } diff --git a/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/entity/HorseDonkeyController.java b/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/entity/HorseDonkeyController.java index 134f087d8..ca58125d4 100644 --- a/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/entity/HorseDonkeyController.java +++ b/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/entity/HorseDonkeyController.java @@ -188,9 +188,8 @@ public class HorseDonkeyController extends MobEntityController { @Override public void M() { - if (npc == null) { - super.M(); - } else { + super.M(); + if (npc != null) { NMS.setStepHeight(getBukkitEntity(), 1); npc.update(); } diff --git a/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/entity/HorseMuleController.java b/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/entity/HorseMuleController.java index 77c912cc5..92b44c53a 100644 --- a/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/entity/HorseMuleController.java +++ b/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/entity/HorseMuleController.java @@ -188,9 +188,8 @@ public class HorseMuleController extends MobEntityController { @Override public void M() { - if (npc == null) { - super.M(); - } else { + super.M(); + if (npc != null) { NMS.setStepHeight(getBukkitEntity(), 1); npc.update(); } diff --git a/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/entity/HorseSkeletonController.java b/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/entity/HorseSkeletonController.java index 9765360f2..8e74e49a0 100644 --- a/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/entity/HorseSkeletonController.java +++ b/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/entity/HorseSkeletonController.java @@ -188,9 +188,8 @@ public class HorseSkeletonController extends MobEntityController { @Override public void M() { - if (npc == null) { - super.M(); - } else { + super.M(); + if (npc != null) { NMS.setStepHeight(getBukkitEntity(), 1); npc.update(); } diff --git a/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/entity/HorseZombieController.java b/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/entity/HorseZombieController.java index 92eb56678..59ea73422 100644 --- a/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/entity/HorseZombieController.java +++ b/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/entity/HorseZombieController.java @@ -188,9 +188,8 @@ public class HorseZombieController extends MobEntityController { @Override public void M() { - if (npc == null) { - super.M(); - } else { + super.M(); + if (npc != null) { NMS.setStepHeight(getBukkitEntity(), 1); npc.update(); } diff --git a/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/entity/PolarBearController.java b/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/entity/PolarBearController.java index 88314b8d0..af78a6ee9 100644 --- a/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/entity/PolarBearController.java +++ b/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/entity/PolarBearController.java @@ -55,15 +55,6 @@ public class PolarBearController extends MobEntityController { } } - @Override - public void A_() { - super.A_(); - if (npc != null) { - NMSImpl.updateAI(this); - npc.update(); - } - } - @Override protected SoundEffect bW() { return NMSImpl.getSoundEffect(npc, super.bW(), NPC.DEATH_SOUND_METADATA); @@ -159,6 +150,14 @@ public class PolarBearController extends MobEntityController { super.L(); } } + + @Override + public void M() { + super.M(); + if (npc != null) { + npc.update(); + } + } } public static class PolarBearNPC extends CraftPolarBear implements NPCHolder { diff --git a/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/entity/VexController.java b/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/entity/VexController.java index 14d494b81..d86cb494c 100644 --- a/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/entity/VexController.java +++ b/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/entity/VexController.java @@ -142,10 +142,8 @@ public class VexController extends MobEntityController { @Override public void M() { - if (npc == null) { - super.M(); - } else { - NMSImpl.updateAI(this); + super.M(); + if (npc != null) { npc.update(); } } diff --git a/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/util/NMSImpl.java b/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/util/NMSImpl.java index a1e49de8b..4b6547760 100644 --- a/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/util/NMSImpl.java +++ b/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/util/NMSImpl.java @@ -8,6 +8,7 @@ import java.net.URL; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.EnumSet; import java.util.Iterator; import java.util.List; import java.util.Random; @@ -334,6 +335,15 @@ public class NMSImpl implements NMSBridge { return new BoundingBox(bb.a, bb.b, bb.c, bb.d, bb.e, bb.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 public GameProfileRepository getGameProfileRepository() { return ((CraftServer) Bukkit.getServer()).getServer().getGameProfileRepository(); @@ -620,7 +630,8 @@ public class NMSImpl implements NMSBridge { @Override public void look(org.bukkit.entity.Entity entity, Location to, boolean headOnly) { Entity handle = NMSImpl.getHandle(entity); - if (headOnly || (!(handle instanceof EntityInsentient) && !(handle instanceof EntityHumanNPC))) { + if (headOnly || BAD_CONTROLLER_LOOK.contains(handle.getBukkitEntity().getType()) + || (!(handle instanceof EntityInsentient) && !(handle instanceof EntityHumanNPC))) { Location fromLocation = entity.getLocation(FROM_LOCATION); double xDiff, yDiff, zDiff; xDiff = to.getX() - fromLocation.getX(); @@ -634,22 +645,27 @@ public class NMSImpl implements NMSBridge { double pitch = Math.toDegrees(Math.acos(yDiff / distanceY)) - 90; if (zDiff < 0.0) yaw += Math.abs(180 - yaw) * 2; - - if (headOnly) { - setHeadYaw(entity, (float) yaw - 90); + if (handle instanceof EntityEnderDragon) { + yaw = getDragonYaw(handle, to.getX(), to.getZ()); } else { - look(entity, (float) yaw - 90, (float) pitch); + yaw = yaw - 90; } + if (headOnly) { + setHeadYaw(entity, (float) yaw); + } else { + look(entity, (float) yaw, (float) pitch); + } + return; } if (handle instanceof EntityInsentient) { ((EntityInsentient) handle).getControllerLook().a(to.getX(), to.getY(), to.getZ(), to.getYaw(), to.getPitch()); - while (((EntityInsentient) handle).aP >= 180F) { - ((EntityInsentient) handle).aP -= 360F; + while (((EntityLiving) handle).aP >= 180F) { + ((EntityLiving) handle).aP -= 360F; } - while (((EntityInsentient) handle).aP < -180F) { - ((EntityInsentient) handle).aP += 360F; + while (((EntityLiving) handle).aP < -180F) { + ((EntityLiving) handle).aP += 360F; } } else if (handle instanceof EntityHumanNPC) { ((EntityHumanNPC) handle).setTargetLook(to); @@ -659,8 +675,21 @@ public class NMSImpl implements NMSBridge { @Override public void look(org.bukkit.entity.Entity from, org.bukkit.entity.Entity to) { Entity handle = NMSImpl.getHandle(from), target = NMSImpl.getHandle(to); - if (handle instanceof EntityInsentient) { - ((EntityInsentient) handle).getControllerLook().a(target, 10.0F, ((EntityInsentient) handle).N()); + if (handle instanceof EntityEnderDragon || BAD_CONTROLLER_LOOK.contains(handle.getBukkitEntity().getType())) { + if (to instanceof LivingEntity) { + look(from, ((LivingEntity) to).getEyeLocation(), false); + } else { + look(from, to.getLocation(), false); + } + } else if (handle instanceof EntityInsentient) { + ((EntityInsentient) handle).getControllerLook().a(target, ((EntityInsentient) handle).cL(), + ((EntityInsentient) handle).N()); + while (((EntityLiving) handle).aP >= 180F) { + ((EntityLiving) handle).aP -= 360F; + } + while (((EntityLiving) handle).aP < -180F) { + ((EntityLiving) handle).aP += 360F; + } } else if (handle instanceof EntityHumanNPC) { ((EntityHumanNPC) handle).setTargetLook(target, 10F, 40F); } @@ -1396,8 +1425,10 @@ public class NMSImpl implements NMSBridge { navigation.l(); } - private static final Field CRAFT_BOSSBAR_HANDLE_FIELD = NMS.getField(CraftBossBar.class, "handle"); + private static final Set BAD_CONTROLLER_LOOK = EnumSet.of(EntityType.SILVERFISH, EntityType.ENDERMITE, + EntityType.ENDER_DRAGON, EntityType.BAT); + private static final Field CRAFT_BOSSBAR_HANDLE_FIELD = NMS.getField(CraftBossBar.class, "handle"); private static final float DEFAULT_SPEED = 1F; private static final Field ENDERDRAGON_BATTLE_BAR_FIELD = NMS.getField(EnderDragonBattle.class, "c"); private static final Field ENDERDRAGON_BATTLE_FIELD = NMS.getField(EntityEnderDragon.class, "bJ");