2012-02-03 10:20:48 +01:00
|
|
|
package net.citizensnpcs.npc.entity;
|
|
|
|
|
2012-07-28 09:02:57 +02:00
|
|
|
import net.citizensnpcs.api.event.NPCPushEvent;
|
2012-03-12 11:45:36 +01:00
|
|
|
import net.citizensnpcs.api.npc.NPC;
|
2012-04-19 05:52:07 +02:00
|
|
|
import net.citizensnpcs.npc.CitizensNPC;
|
2012-12-14 15:07:25 +01:00
|
|
|
import net.citizensnpcs.npc.MobEntityController;
|
2012-07-19 17:10:30 +02:00
|
|
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
2012-09-01 12:05:22 +02:00
|
|
|
import net.citizensnpcs.util.NMS;
|
2012-07-27 18:01:52 +02:00
|
|
|
import net.citizensnpcs.util.Util;
|
2014-04-12 16:59:56 +02:00
|
|
|
import net.minecraft.server.v1_7_R3.EntityEnderDragon;
|
|
|
|
import net.minecraft.server.v1_7_R3.World;
|
2012-02-03 10:20:48 +01:00
|
|
|
|
2012-10-12 06:16:44 +02:00
|
|
|
import org.bukkit.Bukkit;
|
2014-04-12 16:59:56 +02:00
|
|
|
import org.bukkit.craftbukkit.v1_7_R3.CraftServer;
|
|
|
|
import org.bukkit.craftbukkit.v1_7_R3.entity.CraftEnderDragon;
|
|
|
|
import org.bukkit.craftbukkit.v1_7_R3.entity.CraftEntity;
|
2012-02-04 07:48:23 +01:00
|
|
|
import org.bukkit.entity.EnderDragon;
|
2012-07-27 18:01:52 +02:00
|
|
|
import org.bukkit.util.Vector;
|
2012-02-04 07:48:23 +01:00
|
|
|
|
2012-12-08 13:08:58 +01:00
|
|
|
public class EnderDragonController extends MobEntityController {
|
|
|
|
public EnderDragonController() {
|
|
|
|
super(EntityEnderDragonNPC.class);
|
2012-02-03 10:20:48 +01:00
|
|
|
}
|
2012-02-04 07:48:23 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public EnderDragon getBukkitEntity() {
|
2012-08-12 08:39:44 +02:00
|
|
|
return (EnderDragon) super.getBukkitEntity();
|
2012-02-04 07:48:23 +01:00
|
|
|
}
|
|
|
|
|
2012-10-12 06:16:44 +02:00
|
|
|
public static class EnderDragonNPC extends CraftEnderDragon implements NPCHolder {
|
|
|
|
private final CitizensNPC npc;
|
|
|
|
|
|
|
|
public EnderDragonNPC(EntityEnderDragonNPC entity) {
|
|
|
|
super((CraftServer) Bukkit.getServer(), entity);
|
|
|
|
this.npc = entity.npc;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public NPC getNPC() {
|
|
|
|
return npc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-19 17:10:30 +02:00
|
|
|
public static class EntityEnderDragonNPC extends EntityEnderDragon implements NPCHolder {
|
2012-04-19 05:52:07 +02:00
|
|
|
private final CitizensNPC npc;
|
2012-03-12 11:45:36 +01:00
|
|
|
|
2012-10-28 05:54:18 +01:00
|
|
|
public EntityEnderDragonNPC(World world) {
|
|
|
|
this(world, null);
|
|
|
|
}
|
|
|
|
|
2012-04-20 16:45:09 +02:00
|
|
|
public EntityEnderDragonNPC(World world, NPC npc) {
|
2012-02-04 07:48:23 +01:00
|
|
|
super(world);
|
2012-04-20 16:45:09 +02:00
|
|
|
this.npc = (CitizensNPC) npc;
|
2012-07-19 17:10:30 +02:00
|
|
|
if (npc != null) {
|
2012-09-01 12:05:22 +02:00
|
|
|
NMS.clearGoals(goalSelector, targetSelector);
|
2012-07-19 17:10:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-29 14:37:27 +01:00
|
|
|
@Override
|
2014-03-23 10:34:02 +01:00
|
|
|
protected String aS() {
|
|
|
|
return npc == null ? super.aS() : npc.data().get(NPC.HURT_SOUND_METADATA, super.aS());
|
2014-01-29 14:37:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-03-23 10:34:02 +01:00
|
|
|
protected String aT() {
|
|
|
|
return npc == null ? super.aT() : npc.data().get(NPC.DEATH_SOUND_METADATA, super.aT());
|
2014-01-29 14:37:27 +01:00
|
|
|
}
|
|
|
|
|
2013-07-09 16:01:00 +02:00
|
|
|
@Override
|
2014-03-23 10:34:02 +01:00
|
|
|
public boolean bN() {
|
2013-07-09 16:01:00 +02:00
|
|
|
if (npc == null)
|
2014-03-23 10:34:02 +01:00
|
|
|
return super.bN();
|
2013-07-09 16:01:00 +02:00
|
|
|
boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true);
|
|
|
|
if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault))
|
2014-03-23 10:34:02 +01:00
|
|
|
return super.bN();
|
|
|
|
if (super.bN()) {
|
2013-09-20 18:01:39 +02:00
|
|
|
unleash(true, false); // clearLeash with client update
|
2013-07-09 18:08:19 +02:00
|
|
|
}
|
2013-07-09 16:01:00 +02:00
|
|
|
return false; // shouldLeash
|
|
|
|
}
|
|
|
|
|
2012-09-01 12:05:22 +02:00
|
|
|
@Override
|
2014-03-23 10:34:02 +01:00
|
|
|
public void bp() {
|
2013-07-02 06:36:00 +02:00
|
|
|
if (npc == null) {
|
2014-03-23 10:34:02 +01:00
|
|
|
super.bp();
|
2013-07-02 06:36:00 +02:00
|
|
|
}
|
2012-09-01 12:05:22 +02:00
|
|
|
}
|
|
|
|
|
2012-07-19 17:10:30 +02:00
|
|
|
@Override
|
2014-04-12 16:59:56 +02:00
|
|
|
public void collide(net.minecraft.server.v1_7_R3.Entity entity) {
|
2013-12-01 10:24:54 +01:00
|
|
|
// this method is called by both the entities involved - cancelling
|
|
|
|
// it will not stop the NPC from moving.
|
|
|
|
super.collide(entity);
|
|
|
|
if (npc != null)
|
|
|
|
Util.callCollisionEvent(npc, entity.getBukkitEntity());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void e() {
|
2013-02-10 15:26:58 +01:00
|
|
|
if (npc != null) {
|
2012-10-28 05:54:18 +01:00
|
|
|
npc.update();
|
2013-02-10 15:26:58 +01:00
|
|
|
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);
|
|
|
|
}
|
2013-12-01 10:24:54 +01:00
|
|
|
} else {
|
|
|
|
super.e();
|
|
|
|
}
|
2012-02-04 07:48:23 +01:00
|
|
|
}
|
|
|
|
|
2012-08-02 15:44:59 +02:00
|
|
|
@Override
|
|
|
|
public void g(double x, double y, double z) {
|
|
|
|
if (npc == null) {
|
|
|
|
super.g(x, y, z);
|
|
|
|
return;
|
|
|
|
}
|
2012-09-07 12:25:54 +02:00
|
|
|
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
|
|
|
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
|
|
|
|
super.g(x, y, z);
|
2012-08-02 15:44:59 +02:00
|
|
|
return;
|
2012-09-07 12:25:54 +02:00
|
|
|
}
|
2012-08-04 07:39:04 +02:00
|
|
|
Vector vector = new Vector(x, y, z);
|
|
|
|
NPCPushEvent event = Util.callPushEvent(npc, vector);
|
|
|
|
if (!event.isCancelled()) {
|
|
|
|
vector = event.getCollisionVector();
|
|
|
|
super.g(vector.getX(), vector.getY(), vector.getZ());
|
|
|
|
}
|
2012-08-02 15:44:59 +02:00
|
|
|
// when another entity collides, this method is called to push the
|
|
|
|
// NPC so we prevent it from doing anything if the event is
|
|
|
|
// cancelled.
|
2012-02-04 15:31:16 +01:00
|
|
|
}
|
2012-03-27 16:42:15 +02:00
|
|
|
|
2012-10-12 06:16:44 +02:00
|
|
|
@Override
|
2013-01-19 13:42:03 +01:00
|
|
|
public CraftEntity getBukkitEntity() {
|
2012-10-12 06:16:44 +02:00
|
|
|
if (bukkitEntity == null && npc != null)
|
|
|
|
bukkitEntity = new EnderDragonNPC(this);
|
|
|
|
return super.getBukkitEntity();
|
|
|
|
}
|
|
|
|
|
2013-02-10 15:26:58 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-03-27 16:42:15 +02:00
|
|
|
@Override
|
|
|
|
public NPC getNPC() {
|
|
|
|
return npc;
|
|
|
|
}
|
2014-01-21 05:25:14 +01:00
|
|
|
|
|
|
|
@Override
|
2014-02-20 04:57:24 +01:00
|
|
|
protected String t() {
|
2014-03-23 10:34:02 +01:00
|
|
|
return npc == null ? super.aS() : npc.data().get(NPC.AMBIENT_SOUND_METADATA, super.t());
|
2014-01-21 05:25:14 +01:00
|
|
|
}
|
2014-01-29 14:37:27 +01:00
|
|
|
|
|
|
|
@Override
|
2014-02-20 04:57:24 +01:00
|
|
|
protected void w() {
|
|
|
|
if (npc == null) {
|
|
|
|
super.w();
|
|
|
|
}
|
2014-01-29 14:37:27 +01:00
|
|
|
}
|
2012-02-04 07:48:23 +01:00
|
|
|
}
|
2012-02-03 10:20:48 +01:00
|
|
|
}
|