From 01d073e6dd147cec1c1849e062017ecb7b5d3789 Mon Sep 17 00:00:00 2001 From: aPunch Date: Tue, 7 Feb 2012 04:37:12 -0600 Subject: [PATCH] moved NPC rotation to LookClose trait, fix name color saving --- lib/CitizensAPI.jar | Bin 23688 -> 23702 bytes src/net/citizensnpcs/NPCUpdater.java | 34 --------------- src/net/citizensnpcs/npc/CitizensNPC.java | 4 +- src/net/citizensnpcs/npc/NPCInventory.java | 3 +- .../npc/entity/CitizensHumanNPC.java | 6 ++- src/net/citizensnpcs/trait/LookClose.java | 39 ++++++++++++++---- 6 files changed, 40 insertions(+), 46 deletions(-) diff --git a/lib/CitizensAPI.jar b/lib/CitizensAPI.jar index 41f4bc27bc164edca1de41f8af0be03f85078d61..95400e3fceb2ead497caaf2cc13c7d524991ab9e 100644 GIT binary patch delta 5086 zcmZXYby(9~*vDan3>nh7(MS)FmeEK{jV|dDq@;y`goq&E=*AJ!NJuw=q;yM)N(l%8 z3c|bXdEWQBe4qVsKEM0>yW^a5?RT#0+%e6#sm-_~x|(?S#5kBA0ZS4I4*;JfN#X?n z{oKcb8NUdiMOT*-e#E@YS)G13}9j4|B+3TV_-0~P=n z#u8-VVaNsa#lt5viW*ZE)PZ)rl^=L?bVb&kSL z0lJ?;x#JSnP_6+c`!cT`xx`=$Juon6!*1u|h^$nWypL;U<1HD}KuOQJs4OZyL_G52 z`Y}TXSr6?IC+Gp`I^Ve~-SA<9P{&IT?n#fbb`PGhRnm3o^QxBL?JUuXlFX}fhj_l1 zN+3DnjRA#Aj!14qC_~@J>Ftlb&Rv332@eRpniqc=(slNG^qdRi>h>OpURt?dv&P6p zzs2tyKjh+E%i}wwy%dY#ia5_=yKbfUQ_6Bh-a`n3^vHQ>^ma}Ub}G$3oyug1+-F-R zXXZ?)Wg(pI(fO`l<%m1PmYGQqq2E2A45vZyQ&UWGR6MUj41&W2WjPX=6z&DVGDHa} z994v>&onmk$r&3ro||~U?A+Ima?d>{Yx<{(t!D~1Nu6?pUiH5H1W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BZ$BfEmC}1eT9Ar-UbYf{_)XHhs{ z*BnZS`9Dt!Y|%-p-4ght6Tvxp^Sh&ii%JK!+%|+F#BA7!pXmSB0|6p!Xvrmw@T>g~;!Wh> diff --git a/src/net/citizensnpcs/NPCUpdater.java b/src/net/citizensnpcs/NPCUpdater.java index 1138779d4..29149b54b 100644 --- a/src/net/citizensnpcs/NPCUpdater.java +++ b/src/net/citizensnpcs/NPCUpdater.java @@ -1,14 +1,8 @@ package net.citizensnpcs; -import org.bukkit.Location; -import org.bukkit.entity.Entity; - import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.npc.CitizensNPC; import net.citizensnpcs.npc.CitizensNPCManager; -import net.citizensnpcs.trait.LookClose; - -import net.minecraft.server.EntityLiving; public class NPCUpdater implements Runnable { private final CitizensNPCManager npcManager; @@ -24,34 +18,6 @@ public class NPCUpdater implements Runnable { continue; CitizensNPC handle = (CitizensNPC) npc; handle.update(); - - // This needs to be handled somewhere...is this the best place? - EntityLiving search = null; - if ((search = handle.getHandle().world.findNearbyPlayer(handle.getHandle(), 5)) != null - && npc.getTrait(LookClose.class).shouldLookClose()) - faceEntity(handle, search.getBukkitEntity()); } } - - private void faceEntity(CitizensNPC npc, Entity target) { - if (npc.getBukkitEntity().getWorld() != target.getWorld()) - return; - Location loc = npc.getBukkitEntity().getLocation(); - - double xDiff = target.getLocation().getX() - loc.getX(); - double yDiff = target.getLocation().getY() - loc.getY(); - double zDiff = target.getLocation().getZ() - loc.getZ(); - - double distanceXZ = Math.sqrt(xDiff * xDiff + zDiff * zDiff); - double distanceY = Math.sqrt(distanceXZ * distanceXZ + yDiff * yDiff); - - double yaw = (Math.acos(xDiff / distanceXZ) * 180 / Math.PI); - double pitch = (Math.acos(yDiff / distanceY) * 180 / Math.PI) - 90; - if (zDiff < 0.0) { - yaw = yaw + (Math.abs(180 - yaw) * 2); - } - - npc.getHandle().yaw = (float) yaw - 90; - npc.getHandle().pitch = (float) pitch; - } } \ No newline at end of file diff --git a/src/net/citizensnpcs/npc/CitizensNPC.java b/src/net/citizensnpcs/npc/CitizensNPC.java index 42a236646..19992e9e8 100644 --- a/src/net/citizensnpcs/npc/CitizensNPC.java +++ b/src/net/citizensnpcs/npc/CitizensNPC.java @@ -8,7 +8,7 @@ import net.citizensnpcs.api.npc.trait.trait.Spawned; import net.citizensnpcs.npc.ai.CitizensAI; import net.citizensnpcs.trait.Inventory; import net.citizensnpcs.util.Messaging; -import net.citizensnpcs.util.StringHelper; + import net.minecraft.server.EntityLiving; import org.bukkit.Bukkit; @@ -23,7 +23,7 @@ public abstract class CitizensNPC extends AbstractNPC { protected final NPCInventory inventory; protected CitizensNPC(CitizensNPCManager manager, int id, String name) { - super(id, StringHelper.parseColors(name)); + super(id, name); this.manager = manager; inventory = new NPCInventory(this); } diff --git a/src/net/citizensnpcs/npc/NPCInventory.java b/src/net/citizensnpcs/npc/NPCInventory.java index aa33493be..822537a1d 100644 --- a/src/net/citizensnpcs/npc/NPCInventory.java +++ b/src/net/citizensnpcs/npc/NPCInventory.java @@ -1,6 +1,7 @@ package net.citizensnpcs.npc; import net.citizensnpcs.api.npc.NPC; +import net.citizensnpcs.util.StringHelper; import net.minecraft.server.EntityHuman; import net.minecraft.server.IInventory; import net.minecraft.server.ItemStack; @@ -20,7 +21,7 @@ public class NPCInventory implements IInventory { public NPCInventory(NPC npc) { this.npc = npc; - name = npc.getFullName(); + name = StringHelper.parseColors(npc.getFullName()); contents = new ItemStack[size]; } diff --git a/src/net/citizensnpcs/npc/entity/CitizensHumanNPC.java b/src/net/citizensnpcs/npc/entity/CitizensHumanNPC.java index 97d8e41a7..c0cefda96 100644 --- a/src/net/citizensnpcs/npc/entity/CitizensHumanNPC.java +++ b/src/net/citizensnpcs/npc/entity/CitizensHumanNPC.java @@ -3,6 +3,7 @@ package net.citizensnpcs.npc.entity; import net.citizensnpcs.npc.CitizensNPC; import net.citizensnpcs.npc.CitizensNPCManager; import net.citizensnpcs.resource.lib.EntityHumanNPC; +import net.citizensnpcs.util.StringHelper; import net.minecraft.server.EntityLiving; import net.minecraft.server.ItemInWorldManager; import net.minecraft.server.WorldServer; @@ -12,6 +13,7 @@ import org.bukkit.craftbukkit.CraftWorld; import org.bukkit.entity.Player; public class CitizensHumanNPC extends CitizensNPC { + public CitizensHumanNPC(CitizensNPCManager manager, int id, String name) { super(manager, id, name); } @@ -39,8 +41,8 @@ public class CitizensHumanNPC extends CitizensNPC { @Override protected EntityLiving createHandle(Location loc) { WorldServer ws = ((CraftWorld) loc.getWorld()).getHandle(); - EntityHumanNPC handle = new EntityHumanNPC(ws.getServer().getServer(), ws, getFullName(), - new ItemInWorldManager(ws)); + EntityHumanNPC handle = new EntityHumanNPC(ws.getServer().getServer(), ws, + StringHelper.parseColors(getFullName()), new ItemInWorldManager(ws)); handle.removeFromPlayerMap(getFullName()); handle.setPositionRotation(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch()); return handle; diff --git a/src/net/citizensnpcs/trait/LookClose.java b/src/net/citizensnpcs/trait/LookClose.java index 59a627364..a2875e3ed 100644 --- a/src/net/citizensnpcs/trait/LookClose.java +++ b/src/net/citizensnpcs/trait/LookClose.java @@ -1,10 +1,15 @@ package net.citizensnpcs.trait; +import org.bukkit.Location; +import org.bukkit.entity.Entity; + import net.citizensnpcs.api.DataKey; import net.citizensnpcs.api.exception.NPCLoadException; import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.npc.trait.SaveId; import net.citizensnpcs.api.npc.trait.Trait; +import net.citizensnpcs.npc.CitizensNPC; +import net.minecraft.server.EntityLiving; @SaveId("look-close") public class LookClose implements Trait, Runnable { @@ -17,11 +22,7 @@ public class LookClose implements Trait, Runnable { @Override public void load(DataKey key) throws NPCLoadException { - try { - shouldLookClose = key.getBoolean(""); - } catch (Exception ex) { - throw new NPCLoadException("Invalid value. Valid values: true or false"); - } + shouldLookClose = key.getBoolean(""); } @Override @@ -31,8 +32,10 @@ public class LookClose implements Trait, Runnable { @Override public void run() { - // TODO Auto-generated method stub - + EntityLiving search = null; + CitizensNPC handle = (CitizensNPC) npc; + if ((search = handle.getHandle().world.findNearbyPlayer(handle.getHandle(), 5)) != null && shouldLookClose) + faceEntity(handle, search.getBukkitEntity()); } public void setLookClose(boolean shouldLookClose) { @@ -47,6 +50,28 @@ public class LookClose implements Trait, Runnable { shouldLookClose = !shouldLookClose; } + private void faceEntity(CitizensNPC npc, Entity target) { + if (npc.getBukkitEntity().getWorld() != target.getWorld()) + return; + Location loc = npc.getBukkitEntity().getLocation(); + + double xDiff = target.getLocation().getX() - loc.getX(); + double yDiff = target.getLocation().getY() - loc.getY(); + double zDiff = target.getLocation().getZ() - loc.getZ(); + + double distanceXZ = Math.sqrt(xDiff * xDiff + zDiff * zDiff); + double distanceY = Math.sqrt(distanceXZ * distanceXZ + yDiff * yDiff); + + double yaw = (Math.acos(xDiff / distanceXZ) * 180 / Math.PI); + double pitch = (Math.acos(yDiff / distanceY) * 180 / Math.PI) - 90; + if (zDiff < 0.0) { + yaw = yaw + (Math.abs(180 - yaw) * 2); + } + + npc.getHandle().yaw = (float) yaw - 90; + npc.getHandle().pitch = (float) pitch; + } + @Override public String toString() { return "LookClose{" + shouldLookClose + "}";