Skip to content

Commit

Permalink
Fix Guardians, EnderDragon looking and update how bats/silverfish/end…
Browse files Browse the repository at this point in the history
…ermite looking is handled
  • Loading branch information
fullwall committed Nov 28, 2016
1 parent bc9374d commit 3a612d6
Show file tree
Hide file tree
Showing 11 changed files with 99 additions and 59 deletions.
Expand Up @@ -111,7 +111,7 @@ public void A_() {
super.A_();
if (npc == null)
return;
livingEntityBaseTick();
livingEntityBaseTick();
if (updateCounter + 1 > Setting.PACKET_UPDATE_DELAY.asInt()) {
updateEffects = true;
}
Expand All @@ -122,7 +122,6 @@ public void A_() {
&& 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;
}
Expand All @@ -141,6 +140,17 @@ public void A_() {
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
Expand Down Expand Up @@ -284,6 +294,11 @@ public SkinPacketTracker getSkinTracker() {
return skinTracker;
}

@Override
protected float h(float f, float f1) {
return f1;
}

private void initialise(MinecraftServer minecraftServer) {
Socket socket = new EmptySocket();
NetworkManager conn = null;
Expand Down
Expand Up @@ -53,15 +53,6 @@ protected void a(double d0, boolean flag, IBlockData block, BlockPosition blockp
}
}

@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);
Expand Down Expand Up @@ -182,6 +173,16 @@ public boolean m_() {
}
}

@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) {
Expand Down
Expand Up @@ -53,15 +53,6 @@ protected void a(double d0, boolean flag, IBlockData block, BlockPosition blockp
}
}

@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);
Expand Down Expand Up @@ -182,6 +173,16 @@ public boolean m_() {
}
}

@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) {
Expand Down
Expand Up @@ -187,9 +187,8 @@ protected void L() {

@Override
public void M() {
if (npc == null) {
super.M();
} else {
super.M();
if (npc != null) {
NMS.setStepHeight(getBukkitEntity(), 1);
npc.update();
}
Expand Down
Expand Up @@ -188,9 +188,8 @@ protected void L() {

@Override
public void M() {
if (npc == null) {
super.M();
} else {
super.M();
if (npc != null) {
NMS.setStepHeight(getBukkitEntity(), 1);
npc.update();
}
Expand Down
Expand Up @@ -188,9 +188,8 @@ protected void L() {

@Override
public void M() {
if (npc == null) {
super.M();
} else {
super.M();
if (npc != null) {
NMS.setStepHeight(getBukkitEntity(), 1);
npc.update();
}
Expand Down
Expand Up @@ -188,9 +188,8 @@ protected void L() {

@Override
public void M() {
if (npc == null) {
super.M();
} else {
super.M();
if (npc != null) {
NMS.setStepHeight(getBukkitEntity(), 1);
npc.update();
}
Expand Down
Expand Up @@ -188,9 +188,8 @@ protected void L() {

@Override
public void M() {
if (npc == null) {
super.M();
} else {
super.M();
if (npc != null) {
NMS.setStepHeight(getBukkitEntity(), 1);
npc.update();
}
Expand Down
Expand Up @@ -55,15 +55,6 @@ public void a(boolean flag) {
}
}

@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);
Expand Down Expand Up @@ -159,6 +150,14 @@ protected void L() {
super.L();
}
}

@Override
public void M() {
super.M();
if (npc != null) {
npc.update();
}
}
}

public static class PolarBearNPC extends CraftPolarBear implements NPCHolder {
Expand Down
Expand Up @@ -142,10 +142,8 @@ protected void L() {

@Override
public void M() {
if (npc == null) {
super.M();
} else {
NMSImpl.updateAI(this);
super.M();
if (npc != null) {
npc.update();
}
}
Expand Down
Expand Up @@ -8,6 +8,7 @@
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;
Expand Down Expand Up @@ -334,6 +335,15 @@ public BoundingBox getBoundingBox(org.bukkit.entity.Entity handle) {
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();
Expand Down Expand Up @@ -620,7 +630,8 @@ public void look(org.bukkit.entity.Entity entity, float yaw, float pitch) {
@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();
Expand All @@ -634,22 +645,27 @@ public void look(org.bukkit.entity.Entity entity, Location to, boolean headOnly)
double pitch = Math.toDegrees(Math.acos(yDiff / distanceY)) - 90;
if (zDiff < 0.0)
yaw += Math.abs(180 - yaw) * 2;

if (handle instanceof EntityEnderDragon) {
yaw = getDragonYaw(handle, to.getX(), to.getZ());
} else {
yaw = yaw - 90;
}
if (headOnly) {
setHeadYaw(entity, (float) yaw - 90);
setHeadYaw(entity, (float) yaw);
} else {
look(entity, (float) yaw - 90, (float) pitch);
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);
Expand All @@ -659,8 +675,21 @@ public void look(org.bukkit.entity.Entity entity, Location to, boolean headOnly)
@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);
}
Expand Down Expand Up @@ -1396,8 +1425,10 @@ public static void updateNavigation(NavigationAbstract navigation) {
navigation.l();
}

private static final Field CRAFT_BOSSBAR_HANDLE_FIELD = NMS.getField(CraftBossBar.class, "handle");
private static final Set<EntityType> 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");
Expand Down

0 comments on commit 3a612d6

Please sign in to comment.