2012-02-03 10:20:48 +01:00
|
|
|
package net.citizensnpcs.npc.entity;
|
|
|
|
|
2012-03-12 11:45:36 +01:00
|
|
|
import net.citizensnpcs.api.npc.NPC;
|
2012-03-11 02:11:28 +01:00
|
|
|
import net.citizensnpcs.api.trait.trait.Equipment;
|
|
|
|
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;
|
2012-07-09 10:46:53 +02:00
|
|
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
2012-03-11 02:11:28 +01:00
|
|
|
import net.citizensnpcs.util.Messaging;
|
2012-02-04 07:48:23 +01:00
|
|
|
import net.minecraft.server.EntityEnderman;
|
2012-03-02 10:59:02 +01:00
|
|
|
import net.minecraft.server.PathfinderGoalSelector;
|
2012-02-04 07:48:23 +01:00
|
|
|
import net.minecraft.server.World;
|
2012-02-03 10:20:48 +01:00
|
|
|
|
2012-03-11 02:11:28 +01:00
|
|
|
import org.bukkit.Material;
|
2012-02-04 07:48:23 +01:00
|
|
|
import org.bukkit.entity.Enderman;
|
2012-03-11 02:11:28 +01:00
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
import org.bukkit.material.MaterialData;
|
2012-02-04 07:48:23 +01:00
|
|
|
|
2012-03-11 02:11:28 +01:00
|
|
|
public class CitizensEndermanNPC extends CitizensMobNPC implements Equipable {
|
2012-02-03 10:20:48 +01:00
|
|
|
|
2012-05-13 13:41:21 +02:00
|
|
|
public CitizensEndermanNPC(int id, String name) {
|
|
|
|
super(id, name, EntityEndermanNPC.class);
|
2012-02-03 10:20:48 +01:00
|
|
|
}
|
2012-02-04 07:48:23 +01:00
|
|
|
|
2012-03-11 02:11:28 +01:00
|
|
|
@Override
|
|
|
|
public void equip(Player equipper) {
|
|
|
|
ItemStack hand = equipper.getItemInHand();
|
|
|
|
if (!hand.getType().isBlock()) {
|
|
|
|
Messaging.sendError(equipper, "Invalid block!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
MaterialData carried = getBukkitEntity().getCarriedMaterial();
|
|
|
|
if (carried.getItemType() == Material.AIR) {
|
|
|
|
if (hand.getType() == Material.AIR) {
|
|
|
|
Messaging.sendError(equipper, "Invalid block!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
equipper.getWorld().dropItemNaturally(getBukkitEntity().getLocation(), carried.toItemStack(1));
|
|
|
|
getBukkitEntity().setCarriedMaterial(hand.getData());
|
|
|
|
}
|
|
|
|
|
|
|
|
ItemStack set = hand;
|
|
|
|
if (set.getType() != Material.AIR) {
|
|
|
|
if (hand.getAmount() > 1)
|
|
|
|
hand.setAmount(hand.getAmount() - 1);
|
|
|
|
else
|
|
|
|
hand = null;
|
|
|
|
equipper.setItemInHand(hand);
|
|
|
|
set.setAmount(1);
|
|
|
|
}
|
|
|
|
getTrait(Equipment.class).set(0, set);
|
|
|
|
}
|
|
|
|
|
2012-03-27 16:42:15 +02:00
|
|
|
@Override
|
|
|
|
public Enderman getBukkitEntity() {
|
|
|
|
return (Enderman) getHandle().getBukkitEntity();
|
|
|
|
}
|
|
|
|
|
2012-07-09 10:46:53 +02:00
|
|
|
public static class EntityEndermanNPC extends EntityEnderman 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 EntityEndermanNPC(World world) {
|
|
|
|
this(world, null);
|
|
|
|
}
|
|
|
|
|
2012-04-20 16:45:09 +02:00
|
|
|
public EntityEndermanNPC(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-18 17:42:43 +02:00
|
|
|
if (npc != null) {
|
|
|
|
goalSelector = new PathfinderGoalSelector();
|
|
|
|
targetSelector = new PathfinderGoalSelector();
|
|
|
|
}
|
2012-02-04 07:48:23 +01: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.
|
|
|
|
}
|
|
|
|
|
2012-02-04 07:48:23 +01:00
|
|
|
@Override
|
2012-03-01 16:12:47 +01:00
|
|
|
public void d_() {
|
2012-07-18 17:42:43 +02:00
|
|
|
if (npc == null)
|
|
|
|
super.d_();
|
2012-02-04 07:48:23 +01:00
|
|
|
}
|
2012-02-04 15:31:16 +01:00
|
|
|
|
|
|
|
@Override
|
2012-03-01 16:12:47 +01:00
|
|
|
public void e() {
|
2012-05-03 23:38:23 +02:00
|
|
|
if (npc != null)
|
|
|
|
npc.update();
|
|
|
|
else
|
|
|
|
super.e();
|
2012-02-04 15:31:16 +01:00
|
|
|
}
|
2012-03-27 16:42:15 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public NPC getNPC() {
|
|
|
|
return npc;
|
|
|
|
}
|
2012-02-04 07:48:23 +01:00
|
|
|
}
|
2012-02-03 10:20:48 +01:00
|
|
|
}
|