From a674fadca3df765d3ba3ef3ba5af5371bacdf9a9 Mon Sep 17 00:00:00 2001 From: fullwall Date: Wed, 11 Mar 2015 00:24:28 +0800 Subject: [PATCH] Fix missing translations for player looking --- .../npc/entity/EntityHumanNPC.java | 4 +-- src/main/java/net/citizensnpcs/util/NMS.java | 26 ++++++++++++------- .../util/nms/PlayerControllerLook.java | 16 +++++------- 3 files changed, 25 insertions(+), 21 deletions(-) diff --git a/src/main/java/net/citizensnpcs/npc/entity/EntityHumanNPC.java b/src/main/java/net/citizensnpcs/npc/entity/EntityHumanNPC.java index 2090eca12..3e8fb8f75 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/EntityHumanNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/EntityHumanNPC.java @@ -197,9 +197,9 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder { // swallow } - AttributeInstance range = this.getAttributeInstance(GenericAttributes.b); + AttributeInstance range = getAttributeInstance(GenericAttributes.b); if (range == null) { - range = this.getAttributeMap().b(GenericAttributes.b); + range = getAttributeMap().b(GenericAttributes.b); } range.setValue(Setting.DEFAULT_PATHFINDING_RANGE.asDouble()); diff --git a/src/main/java/net/citizensnpcs/util/NMS.java b/src/main/java/net/citizensnpcs/util/NMS.java index 98d3bae12..d6401c343 100644 --- a/src/main/java/net/citizensnpcs/util/NMS.java +++ b/src/main/java/net/citizensnpcs/util/NMS.java @@ -172,7 +172,7 @@ public class NMS { f5 = entity.world.getType( new BlockPosition(MathHelper.floor(entity.locX), MathHelper.floor(entity.getBoundingBox().b) - 1, MathHelper.floor(entity.locZ))) - .getBlock().frictionFactor * 0.91F; + .getBlock().frictionFactor * 0.91F; } float f6 = 0.1627714F / (f5 * f5 * f5); @@ -189,7 +189,7 @@ public class NMS { f5 = entity.world.getType( new BlockPosition(MathHelper.floor(entity.locX), MathHelper.floor(entity.getBoundingBox().b) - 1, MathHelper.floor(entity.locZ))) - .getBlock().frictionFactor * 0.91F; + .getBlock().frictionFactor * 0.91F; } if (entity.k_()) { @@ -245,7 +245,7 @@ public class NMS { @SuppressWarnings("deprecation") private static Constructor getCustomEntityConstructor(Class clazz, EntityType type) throws SecurityException, - NoSuchMethodException { + NoSuchMethodException { Constructor constructor = ENTITY_CONSTRUCTOR_CACHE.get(clazz); if (constructor == null) { constructor = clazz.getConstructor(World.class); @@ -356,11 +356,23 @@ public class NMS { Entity handle = getHandle(entity); if (handle == null) return; + yaw = clampYaw(yaw); handle.yaw = yaw; setHeadYaw(handle, yaw); handle.pitch = pitch; } + public static float clampYaw(float yaw) { + while (yaw < -180.0F) { + yaw += 360.0F; + } + + while (yaw >= 180.0F) { + yaw -= 360.0F; + } + return yaw; + } + @SuppressWarnings("deprecation") public static void minecartItemLogic(EntityMinecartAbstract minecart) { NPC npc = ((NPCHolder) minecart).getNPC(); @@ -504,13 +516,7 @@ public class NMS { if (!(en instanceof EntityLiving)) return; EntityLiving handle = (EntityLiving) en; - while (yaw < -180.0F) { - yaw += 360.0F; - } - - while (yaw >= 180.0F) { - yaw -= 360.0F; - } + yaw = clampYaw(yaw); handle.aK = yaw; if (!(handle instanceof EntityHuman)) handle.aI = yaw; diff --git a/src/main/java/net/citizensnpcs/util/nms/PlayerControllerLook.java b/src/main/java/net/citizensnpcs/util/nms/PlayerControllerLook.java index 476e59207..ba1e519a3 100644 --- a/src/main/java/net/citizensnpcs/util/nms/PlayerControllerLook.java +++ b/src/main/java/net/citizensnpcs/util/nms/PlayerControllerLook.java @@ -5,8 +5,6 @@ import net.minecraft.server.v1_8_R2.Entity; import net.minecraft.server.v1_8_R2.EntityLiving; import net.minecraft.server.v1_8_R2.MathHelper; -import org.bukkit.craftbukkit.v1_8_R2.TrigMath; - public class PlayerControllerLook { private final EntityHumanNPC a; private float b; @@ -29,24 +27,24 @@ public class PlayerControllerLook { double d2 = this.g - this.a.locZ; double d3 = Math.sqrt(d0 * d0 + d2 * d2); - float f = (float) (TrigMath.atan2(d2, d0) * 180.0D / 3.141592741012573D) - 90.0F; - float f1 = (float) (-(TrigMath.atan2(d1, d3) * 180.0D / 3.141592741012573D)); + float f = (float) (MathHelper.b(d2, d0) * 180.0D / 3.141592741012573D) - 90.0F; + float f1 = (float) (-(MathHelper.b(d1, d3) * 180.0D / 3.141592741012573D)); this.a.pitch = a(this.a.pitch, f1, this.c); - this.a.aI = a(this.a.aI, f, this.b); + this.a.aK = a(this.a.aK, f, this.b); } else { - this.a.aI = a(this.a.aI, this.a.aG, 10.0F); + this.a.aK = a(this.a.aK, this.a.aI, 10.0F); } - float f2 = MathHelper.g(this.a.aI - this.a.aG); + float f2 = MathHelper.g(this.a.aK - this.a.aI); if (!this.a.getNavigation().m()) { if (f2 < -75.0F) { - this.a.aI = (this.a.aG - 75.0F); + this.a.aK = (this.a.aI - 75.0F); } if (f2 > 75.0F) - this.a.aI = (this.a.aG + 75.0F); + this.a.aK = (this.a.aI + 75.0F); } }