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

91 lines
2.8 KiB
Java
Raw Normal View History

2012-02-03 10:20:48 +01:00
package net.citizensnpcs.npc.entity;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.editor.Equipable;
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;
import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.trait.Saddle;
import net.citizensnpcs.util.Messaging;
import net.citizensnpcs.util.StringHelper;
import net.minecraft.server.EntityPig;
import net.minecraft.server.EntityWeatherLighting;
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.Material;
import org.bukkit.entity.Pig;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
public class CitizensPigNPC extends CitizensMobNPC implements Equipable {
2012-02-03 10:20:48 +01:00
public CitizensPigNPC(int id, String name) {
super(id, name, EntityPigNPC.class);
2012-02-03 10:20:48 +01:00
}
@Override
public void equip(Player equipper) {
ItemStack hand = equipper.getItemInHand();
if (hand.getType() == Material.SADDLE) {
if (!getBukkitEntity().hasSaddle()) {
getTrait(Saddle.class).toggle();
equipper.setItemInHand(null);
Messaging.send(equipper, StringHelper.wrap(getName()) + " is now saddled.");
}
} else {
if (getBukkitEntity().hasSaddle()) {
equipper.getWorld().dropItemNaturally(getBukkitEntity().getLocation(),
new ItemStack(Material.SADDLE, 1));
getTrait(Saddle.class).toggle();
Messaging.send(equipper, StringHelper.wrap(getName()) + " is no longer saddled.");
}
}
}
2012-03-27 16:42:15 +02:00
@Override
public Pig getBukkitEntity() {
return (Pig) getHandle().getBukkitEntity();
}
public static class EntityPigNPC extends EntityPig implements NPCHolder {
2012-04-19 05:52:07 +02:00
private final CitizensNPC npc;
public EntityPigNPC(World world) {
this(world, null);
}
public EntityPigNPC(World world, NPC npc) {
super(world);
this.npc = (CitizensNPC) npc;
2012-07-18 17:42:43 +02:00
if (npc != null) {
goalSelector = new PathfinderGoalSelector();
targetSelector = new PathfinderGoalSelector();
}
}
2012-03-27 16:42:15 +02:00
@Override
public void a(EntityWeatherLighting entityweatherlighting) {
2012-07-18 17:42:43 +02:00
if (npc == null)
super.a(entityweatherlighting);
2012-03-27 16:42:15 +02:00
}
2012-07-19 14:58:22 +02:00
@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();
}
}
2012-02-03 10:20:48 +01:00
}