From 1cb9c7b05754227867db8b094d7a1c80840e6383 Mon Sep 17 00:00:00 2001 From: fullwall Date: Sun, 10 Feb 2013 22:26:58 +0800 Subject: [PATCH] Fix EnderDragon NPC movement --- .../java/net/citizensnpcs/EventListen.java | 10 ++++----- .../npc/entity/EnderDragonController.java | 21 ++++++++++++++++--- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/main/java/net/citizensnpcs/EventListen.java b/src/main/java/net/citizensnpcs/EventListen.java index acbf004e5..74d73ab96 100644 --- a/src/main/java/net/citizensnpcs/EventListen.java +++ b/src/main/java/net/citizensnpcs/EventListen.java @@ -59,13 +59,17 @@ import com.google.common.collect.ListMultimap; public class EventListen implements Listener { private final NPCRegistry npcRegistry = CitizensAPI.getNPCRegistry(); - private final ListMultimap toRespawn = ArrayListMultimap.create(); private final Map registries; + private final ListMultimap toRespawn = ArrayListMultimap.create(); EventListen(Map registries) { this.registries = registries; } + private Iterable getAllNPCs() { + return Iterables. concat(npcRegistry, Iterables.concat(registries.values())); + } + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onChunkLoad(ChunkLoadEvent event) { ChunkCoord coord = toCoord(event.getChunk()); @@ -95,10 +99,6 @@ public class EventListen implements Listener { } } - private Iterable getAllNPCs() { - return Iterables. concat(npcRegistry, Iterables.concat(registries.values())); - } - @EventHandler(ignoreCancelled = true) public void onEntityChangedWorld(EntityTeleportEvent event) { if (event.getFrom() == null || event.getTo() == null) diff --git a/src/main/java/net/citizensnpcs/npc/entity/EnderDragonController.java b/src/main/java/net/citizensnpcs/npc/entity/EnderDragonController.java index 85fdee4f5..bdaacfe0f 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/EnderDragonController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/EnderDragonController.java @@ -53,7 +53,6 @@ public class EnderDragonController extends MobEntityController { this.npc = (CitizensNPC) npc; if (npc != null) { NMS.clearGoals(goalSelector, targetSelector); - } } @@ -65,9 +64,16 @@ public class EnderDragonController extends MobEntityController { @Override public void c() { - if (npc != null) + if (npc != null) { npc.update(); - else + if (motX != 0 || motY != 0 || motZ != 0) { + motX *= 0.98; + motY *= 0.98; + motZ *= 0.98; + yaw = getCorrectYaw(locX + motX, locZ + motZ); + setPosition(locX + motX, locY + motY, locZ + motZ); + } + } else super.c(); } @@ -109,6 +115,15 @@ public class EnderDragonController extends MobEntityController { 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 public NPC getNPC() { return npc;