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-02-04 09:13:20 +01:00
|
|
|
import net.citizensnpcs.npc.CitizensMobNPC;
|
2012-04-19 05:52:07 +02:00
|
|
|
import net.citizensnpcs.npc.CitizensNPC;
|
2012-07-19 17:10:30 +02:00
|
|
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
2012-08-03 15:18:10 +02:00
|
|
|
import net.citizensnpcs.util.NMSReflection;
|
2012-07-27 18:01:52 +02:00
|
|
|
import net.citizensnpcs.util.Util;
|
2012-02-04 07:48:23 +01:00
|
|
|
import net.minecraft.server.EntitySilverfish;
|
|
|
|
import net.minecraft.server.World;
|
2012-02-03 10:20:48 +01:00
|
|
|
|
2012-02-04 07:48:23 +01:00
|
|
|
import org.bukkit.entity.Silverfish;
|
2012-07-27 18:01:52 +02:00
|
|
|
import org.bukkit.util.Vector;
|
2012-02-04 07:48:23 +01:00
|
|
|
|
|
|
|
public class CitizensSilverfishNPC extends CitizensMobNPC {
|
2012-02-03 10:20:48 +01:00
|
|
|
|
2012-05-13 13:41:21 +02:00
|
|
|
public CitizensSilverfishNPC(int id, String name) {
|
|
|
|
super(id, name, EntitySilverfishNPC.class);
|
2012-02-03 10:20:48 +01:00
|
|
|
}
|
2012-02-04 07:48:23 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public Silverfish getBukkitEntity() {
|
|
|
|
return (Silverfish) getHandle().getBukkitEntity();
|
|
|
|
}
|
|
|
|
|
2012-07-19 17:10:30 +02:00
|
|
|
public static class EntitySilverfishNPC extends EntitySilverfish implements NPCHolder {
|
2012-04-19 05:52:07 +02:00
|
|
|
private final CitizensNPC npc;
|
2012-03-12 11:45:36 +01:00
|
|
|
|
2012-05-03 23:38:23 +02:00
|
|
|
public EntitySilverfishNPC(World world) {
|
|
|
|
this(world, null);
|
|
|
|
}
|
|
|
|
|
2012-04-20 16:45:09 +02:00
|
|
|
public EntitySilverfishNPC(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-08-03 15:18:10 +02:00
|
|
|
NMSReflection.clearGoals(goalSelector, targetSelector);
|
2012-07-19 17:10:30 +02:00
|
|
|
}
|
2012-02-04 07:48:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-08-02 15:44:59 +02:00
|
|
|
public void bc() {
|
|
|
|
super.bc();
|
|
|
|
if (npc != null)
|
|
|
|
npc.update();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void be() {
|
|
|
|
if (npc == null)
|
|
|
|
super.be();
|
|
|
|
else
|
|
|
|
npc.update();
|
2012-07-28 09:02:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void collide(net.minecraft.server.Entity entity) {
|
|
|
|
// this method is called by both the entities involved - cancelling
|
|
|
|
// it will not stop the NPC from moving.
|
|
|
|
super.collide(entity);
|
|
|
|
Util.callCollisionEvent(npc, entity);
|
2012-02-04 07:48:23 +01:00
|
|
|
}
|
2012-07-09 15:35:57 +02:00
|
|
|
|
2012-07-28 10:15:12 +02:00
|
|
|
@Override
|
2012-08-02 15:44:59 +02:00
|
|
|
public void g(double x, double y, double z) {
|
|
|
|
if (npc == null) {
|
|
|
|
super.g(x, y, z);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0)
|
|
|
|
return;
|
|
|
|
NPCPushEvent event = Util.callPushEvent(npc, new Vector(x, y, z));
|
|
|
|
if (!event.isCancelled())
|
|
|
|
super.g(x, y, z);
|
|
|
|
// 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-07-28 10:15:12 +02:00
|
|
|
}
|
|
|
|
|
2012-07-09 15:35:57 +02:00
|
|
|
@Override
|
|
|
|
public NPC getNPC() {
|
|
|
|
return npc;
|
|
|
|
}
|
2012-02-04 07:48:23 +01:00
|
|
|
}
|
2012-02-03 10:20:48 +01:00
|
|
|
}
|