Extend horse modifiers to save saddle and armor

This commit is contained in:
fullwall 2013-07-30 11:15:51 +08:00
parent 8fd93f82af
commit 53c975cce8
2 changed files with 24 additions and 0 deletions

View File

@ -5,12 +5,14 @@ import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.MobEntityController;
import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.trait.HorseModifiers;
import net.citizensnpcs.util.NMS;
import net.citizensnpcs.util.Util;
import net.minecraft.server.v1_6_R2.EntityHorse;
import net.minecraft.server.v1_6_R2.World;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_6_R2.CraftServer;
import org.bukkit.craftbukkit.v1_6_R2.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_6_R2.entity.CraftHorse;
@ -27,6 +29,12 @@ public class HorseController extends MobEntityController {
return (Horse) super.getBukkitEntity();
}
@Override
public void spawn(Location at, NPC npc) {
npc.getTrait(HorseModifiers.class);
super.spawn(at, npc);
}
public static class EntityHorseNPC extends EntityHorse implements NPCHolder {
private int jumpTicks;
private final CitizensNPC npc;

View File

@ -7,12 +7,17 @@ import org.bukkit.entity.Horse;
import org.bukkit.entity.Horse.Color;
import org.bukkit.entity.Horse.Style;
import org.bukkit.entity.Horse.Variant;
import org.bukkit.inventory.ItemStack;
public class HorseModifiers extends Trait {
@Persist("armor")
private ItemStack armor = null;
@Persist("carryingChest")
private boolean carryingChest;
@Persist("color")
private Color color = Color.CREAMY;
@Persist("saddle")
private ItemStack saddle = null;
@Persist("style")
private Style style = Style.NONE;
@Persist("type")
@ -39,6 +44,15 @@ public class HorseModifiers extends Trait {
updateModifiers();
}
@Override
public void run() {
if (npc.getBukkitEntity() instanceof Horse) {
Horse horse = (Horse) npc.getBukkitEntity();
saddle = horse.getInventory().getSaddle();
armor = horse.getInventory().getArmor();
}
}
public void setCarryingChest(boolean carryingChest) {
this.carryingChest = carryingChest;
updateModifiers();
@ -66,6 +80,8 @@ public class HorseModifiers extends Trait {
horse.setColor(color);
horse.setStyle(style);
horse.setVariant(type);
horse.getInventory().setArmor(armor);
horse.getInventory().setSaddle(saddle);
}
}
}