Fix Minecraft 1.10 player looking

This commit is contained in:
fullwall 2016-12-10 20:20:27 +08:00
parent e3981a15a6
commit 86d6794b43
6 changed files with 57 additions and 25 deletions

View File

@ -305,7 +305,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;
}

View File

@ -7,6 +7,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.Map;
@ -317,6 +318,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();
@ -589,7 +599,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();
@ -603,21 +614,26 @@ 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).aO >= 180F) {
((EntityInsentient) handle).aO -= 360F;
while (((EntityInsentient) handle).aQ >= 180F) {
((EntityInsentient) handle).aQ -= 360F;
}
while (((EntityInsentient) handle).aO < -180F) {
((EntityInsentient) handle).aO += 360F;
while (((EntityInsentient) handle).aQ < -180F) {
((EntityInsentient) handle).aQ += 360F;
}
} else if (handle instanceof EntityHumanNPC) {
((EntityHumanNPC) handle).setTargetLook(to);
@ -627,8 +643,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 (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).cJ(),
((EntityInsentient) handle).N());
while (((EntityLiving) handle).aQ >= 180F) {
((EntityLiving) handle).aQ -= 360F;
}
while (((EntityLiving) handle).aQ < -180F) {
((EntityLiving) handle).aQ += 360F;
}
} else if (handle instanceof EntityHumanNPC) {
((EntityHumanNPC) handle).setTargetLook(target, 10F, 40F);
}
@ -1353,6 +1382,10 @@ public class NMSImpl implements NMSBridge {
navigation.l();
}
private static final Set<EntityType> BAD_CONTROLLER_LOOK = EnumSet.of(EntityType.SILVERFISH, EntityType.ENDERMITE,
EntityType.ENDER_DRAGON, EntityType.BAT, EntityType.SLIME, EntityType.MAGMA_CUBE, EntityType.HORSE,
EntityType.GHAST);
private static final Field CRAFT_BOSSBAR_HANDLE_FIELD = NMS.getField(CraftBossBar.class, "handle");
private static final float DEFAULT_SPEED = 1F;

View File

@ -31,24 +31,24 @@ public class PlayerControllerLook {
float f1 = (float) (MathHelper.b(d3, d1) * 57.2957763671875D) - 90.0F;
float f2 = (float) -(MathHelper.b(d2, d4) * 57.2957763671875D);
this.a.pitch = a(this.a.pitch, f2, this.c);
this.a.aO = a(this.a.aO, f1, this.b);
this.a.yaw = this.a.aO;
while (this.a.aO >= 180F) {
this.a.aO -= 360F;
this.a.aQ = a(this.a.aQ, f1, this.b);
this.a.yaw = this.a.aQ;
while (this.a.aQ >= 180F) {
this.a.aQ -= 360F;
}
while (this.a.aO < -180F) {
this.a.aO += 360F;
while (this.a.aQ < -180F) {
this.a.aQ += 360F;
}
} else {
// this.a.aO = a(this.a.aO, this.a.aM, 10.0F);
// this.a.aQ = a(this.a.aQ, this.a.aO, 10.0F);
}
float f3 = MathHelper.g(this.a.aO - this.a.aM);
float f3 = MathHelper.g(this.a.aQ - this.a.aO);
if (!this.a.getNavigation().n()) {
if (f3 < -75.0F) {
this.a.aO = (this.a.aM - 75.0F);
this.a.aQ = (this.a.aO - 75.0F);
}
if (f3 > 75.0F) {
this.a.aO = (this.a.aM + 75.0F);
this.a.aQ = (this.a.aO + 75.0F);
}
}
}

View File

@ -85,7 +85,7 @@ public class PlayerControllerMove extends ControllerMove {
if (d3 < 2.500000277905201E-007D)
return;
float f = (float) Math.toDegrees(Math.atan2(d1, d0)) - 90.0F;
this.a.yaw = a(this.a.yaw, f, 30.0F);
this.a.yaw = a(this.a.yaw, f, 90.0F);
NMS.setHeadYaw(a.getBukkitEntity(), this.a.yaw);
AttributeInstance speed = this.a.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED);
speed.setValue(0.1D * this.e);

View File

@ -111,10 +111,10 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
super.A_();
if (npc == null)
return;
livingEntityBaseTick();
if (updateCounter + 1 > Setting.PACKET_UPDATE_DELAY.asInt()) {
updateEffects = true;
}
livingEntityBaseTick();
boolean navigating = npc.getNavigator().isNavigating();
updatePackets(navigating);

View File

@ -676,7 +676,7 @@ 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 EntityEnderDragon || BAD_CONTROLLER_LOOK.contains(handle.getBukkitEntity().getType())) {
if (BAD_CONTROLLER_LOOK.contains(handle.getBukkitEntity().getType())) {
if (to instanceof LivingEntity) {
look(from, ((LivingEntity) to).getEyeLocation(), false);
} else {