use of net.citizensnpcs.api.trait.trait.Inventory in project Sentinel by mcmonkey4eva.
the class SentinelTrait method swapToRanged.
public void swapToRanged() {
if (!npc.hasTrait(Inventory.class)) {
return;
}
int i = 0;
Inventory inv = npc.getTrait(Inventory.class);
ItemStack[] items = inv.getContents();
ItemStack held = items[0] == null ? null : items[0].clone();
boolean edit = false;
while (!isRanged() && i < items.length - 1) {
i++;
if (items[i] != null && items[i].getType() != Material.AIR) {
items[0] = items[i].clone();
items[i] = new ItemStack(Material.AIR);
inv.setContents(items);
edit = true;
}
}
if (edit) {
items[i] = held;
inv.setContents(items);
}
}