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

65 lines
1.8 KiB
Java

package net.citizensnpcs.npc.entity;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.npc.CitizensMobNPC;
import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.ai.NPCHolder;
import net.minecraft.server.EntityCreeper;
import net.minecraft.server.EntityWeatherLighting;
import net.minecraft.server.PathfinderGoalSelector;
import net.minecraft.server.World;
import org.bukkit.entity.Creeper;
public class CitizensCreeperNPC extends CitizensMobNPC {
public CitizensCreeperNPC(int id, String name) {
super(id, name, EntityCreeperNPC.class);
}
@Override
public Creeper getBukkitEntity() {
return (Creeper) getHandle().getBukkitEntity();
}
public static class EntityCreeperNPC extends EntityCreeper implements NPCHolder {
private final CitizensNPC npc;
public EntityCreeperNPC(World world) {
this(world, null);
}
public EntityCreeperNPC(World world, NPC npc) {
super(world);
this.npc = (CitizensNPC) npc;
if (npc != null) {
goalSelector = new PathfinderGoalSelector();
targetSelector = new PathfinderGoalSelector();
}
}
@Override
public void a(EntityWeatherLighting entityweatherlighting) {
if (npc == null)
super.a(entityweatherlighting);
}
@Override
public void b_(double x, double y, double z) {
// when another entity collides, b_ is called to push the NPC
// so we prevent b_ from doing anything.
}
@Override
public NPC getNPC() {
return npc;
}
@Override
public void z_() {
super.z_();
if (npc != null)
npc.update();
}
}
}