Citizens2/src/main/java/net/citizensnpcs/npc/entity/CitizensSilverfishNPC.java

78 lines
2.4 KiB
Java
Raw Normal View History

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;
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;
import net.citizensnpcs.util.Util;
import net.minecraft.server.EntitySilverfish;
2012-03-02 10:59:02 +01:00
import net.minecraft.server.PathfinderGoalSelector;
import net.minecraft.server.World;
2012-02-03 10:20:48 +01:00
import org.bukkit.entity.Silverfish;
import org.bukkit.util.Vector;
public class CitizensSilverfishNPC extends CitizensMobNPC {
2012-02-03 10:20:48 +01:00
public CitizensSilverfishNPC(int id, String name) {
super(id, name, EntitySilverfishNPC.class);
2012-02-03 10:20:48 +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;
public EntitySilverfishNPC(World world) {
this(world, null);
}
public EntitySilverfishNPC(World world, NPC npc) {
super(world);
this.npc = (CitizensNPC) npc;
2012-07-19 17:10:30 +02:00
if (npc != null) {
goalSelector = new PathfinderGoalSelector();
targetSelector = new PathfinderGoalSelector();
}
}
@Override
2012-07-19 17:10:30 +02:00
public void b_(double x, double y, double z) {
if (npc == null) {
super.b_(x, y, z);
return;
}
2012-07-28 09:02:57 +02:00
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0)
return;
2012-07-28 09:02:57 +02:00
NPCPushEvent event = Util.callPushEvent(npc, new Vector(x, y, z));
if (!event.isCancelled())
super.b_(x, y, z);
2012-07-19 17:10:30 +02:00
// when another entity collides, b_ is called to push the NPC
2012-07-28 09:02:57 +02:00
// so we prevent b_ from doing anything if the event is cancelled.
}
@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);
}
@Override
public NPC getNPC() {
return npc;
}
2012-07-19 17:10:30 +02:00
@Override
public void z_() {
super.z_();
if (npc != null)
npc.update();
}
}
2012-02-03 10:20:48 +01:00
}