use of net.citizensnpcs.api.trait.trait.Inventory in project Sentinel by mcmonkey4eva.
the class SentinelTrait method grabNextItem.
public void grabNextItem() {
if (!npc.hasTrait(Inventory.class)) {
return;
}
Inventory inv = npc.getTrait(Inventory.class);
ItemStack[] items = inv.getContents();
ItemStack held = items[0];
if (held != null && held.getType() != Material.AIR) {
return;
}
for (int i = 0; i < items.length; i++) {
ItemStack item = items[i];
if (item != null) {
item = item.clone();
Material mat = item.getType();
if (isWeapon(mat)) {
if (item.getAmount() > 1) {
item.setAmount(item.getAmount() - 1);
items[i] = item;
items[0] = item.clone();
items[0].setAmount(1);
inv.setContents(items);
item = item.clone();
item.setAmount(1);
return;
} else {
items[i] = new ItemStack(Material.AIR);
items[0] = item.clone();
inv.setContents(items);
return;
}
}
}
}
}
use of net.citizensnpcs.api.trait.trait.Inventory in project Sentinel by mcmonkey4eva.
the class SentinelTrait method takeArrow.
public void takeArrow() {
if (!npc.hasTrait(Inventory.class)) {
return;
}
Inventory inv = npc.getTrait(Inventory.class);
ItemStack[] items = inv.getContents();
for (int i = 0; i < items.length; i++) {
ItemStack item = items[i];
if (item != null) {
Material mat = item.getType();
if (mat == Material.ARROW || (SentinelTarget.v1_9 && (mat == Material.TIPPED_ARROW || mat == Material.SPECTRAL_ARROW))) {
if (item.getAmount() > 1) {
item.setAmount(item.getAmount() - 1);
items[i] = item;
inv.setContents(items);
return;
} else {
items[i] = null;
inv.setContents(items);
return;
}
}
}
}
}
use of net.citizensnpcs.api.trait.trait.Inventory in project Sentinel by mcmonkey4eva.
the class SentinelTrait method swapToMelee.
public void swapToMelee() {
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);
}
}
use of net.citizensnpcs.api.trait.trait.Inventory in project Sentinel by mcmonkey4eva.
the class SentinelTrait method getArrow.
public ItemStack getArrow() {
if (!npc.hasTrait(Inventory.class)) {
return needsAmmo ? null : new ItemStack(Material.ARROW, 1);
}
Inventory inv = npc.getTrait(Inventory.class);
ItemStack[] items = inv.getContents();
for (int i = 0; i < items.length; i++) {
ItemStack item = items[i];
if (item != null) {
Material mat = item.getType();
if (SentinelTarget.v1_9) {
if (mat == Material.ARROW || mat == Material.TIPPED_ARROW || mat == Material.SPECTRAL_ARROW) {
return item.clone();
}
} else {
if (mat == Material.ARROW) {
return item.clone();
}
}
}
}
return needsAmmo ? null : new ItemStack(Material.ARROW, 1);
}
use of net.citizensnpcs.api.trait.trait.Inventory in project Sentinel by mcmonkey4eva.
the class SentinelTrait method takeSnowball.
public void takeSnowball() {
if (!npc.hasTrait(Inventory.class)) {
return;
}
Inventory inv = npc.getTrait(Inventory.class);
ItemStack[] items = inv.getContents();
for (int i = 0; i < items.length; i++) {
ItemStack item = items[i];
if (item != null) {
Material mat = item.getType();
if (mat == Material.SNOW_BALL) {
if (item.getAmount() > 1) {
item.setAmount(item.getAmount() - 1);
items[i] = item;
inv.setContents(items);
return;
} else {
items[i] = null;
inv.setContents(items);
return;
}
}
}
}
}