use of org.bukkit.inventory.ItemStack in project Bukkit by Bukkit.
the class PotionTest method ItemStackConversion.
@Test
public void ItemStackConversion() {
Potion potion = new Potion(PotionType.POISON);
ItemStack itemstack = potion.toItemStack(1);
assertThat(itemstack.getType(), is(Material.POTION));
assertTrue(itemstack.getAmount() == 1);
assertTrue(itemstack.getDurability() == potion.toDamageValue());
}
use of org.bukkit.inventory.ItemStack in project Bukkit by Bukkit.
the class PotionTest method applyToItemStack.
@Test
public void applyToItemStack() {
Potion potion = new Potion(PotionType.POISON);
ItemStack stack = new ItemStack(Material.POTION, 1);
potion.apply(stack);
assertTrue(stack.getDurability() == potion.toDamageValue());
}
use of org.bukkit.inventory.ItemStack in project Denizen-For-Bukkit by DenizenScript.
the class dInventory method setSlots.
/**
* Set items in an inventory, starting with a specified slot
*
* @param slot The slot to start from
* @param items The items to add
* @return The resulting dInventory
*/
public dInventory setSlots(int slot, ItemStack[] items, int c) {
if (inventory == null || items == null) {
return this;
}
for (int i = 0; i < c; i++) {
if (i >= items.length || items[i] == null) {
inventory.setItem(slot + i, new ItemStack(Material.AIR));
}
ItemStack item = items[i];
if (slot + i < 0 || slot + i >= inventory.getSize()) {
break;
}
inventory.setItem(slot + i, item);
}
if (Depends.citizens != null && dNPC.matches(idHolder)) {
// TODO: Directly store holder
dNPC.valueOf(idHolder).getInventoryTrait().setContents(inventory.getContents());
}
return this;
}
use of org.bukkit.inventory.ItemStack in project Denizen-For-Bukkit by DenizenScript.
the class dInventory method getEquipment.
public dList getEquipment() {
ItemStack[] equipment = null;
if (inventory instanceof PlayerInventory) {
equipment = ((PlayerInventory) inventory).getArmorContents();
} else if (inventory instanceof HorseInventory) {
equipment = new ItemStack[] { ((HorseInventory) inventory).getSaddle(), ((HorseInventory) inventory).getArmor() };
}
if (equipment == null) {
return null;
}
dList equipmentList = new dList();
for (ItemStack item : equipment) {
equipmentList.add(new dItem(item).identify());
}
return equipmentList;
}
use of org.bukkit.inventory.ItemStack in project Denizen-For-Bukkit by DenizenScript.
the class dInventory method add.
/////////////////////
// INVENTORY MANIPULATION
/////////////////
// Somewhat simplified version of CraftBukkit's current code
public dInventory add(int slot, ItemStack... items) {
if (inventory == null || items == null) {
return this;
}
for (int i = 0; i < items.length; i++) {
ItemStack item = items[i];
if (item == null) {
continue;
}
int amount = item.getAmount();
int max = item.getMaxStackSize();
while (true) {
// Do we already have a stack of it?
int firstPartial = firstPartial(slot, item);
// Drat! no partial stack
if (firstPartial == -1) {
// Find a free spot!
int firstFree = firstEmpty(slot);
if (firstFree == -1) {
// No space at all!
break;
} else {
// More than a single stack!
if (amount > max) {
ItemStack clone = item.clone();
clone.setAmount(max);
inventory.setItem(firstFree, clone);
item.setAmount(amount -= max);
} else {
// Just store it
inventory.setItem(firstFree, item);
break;
}
}
} else {
// So, apparently it might only partially fit, well lets do just that
ItemStack partialItem = inventory.getItem(firstPartial);
int partialAmount = partialItem.getAmount();
int total = amount + partialAmount;
// Check if it fully fits
if (total <= max) {
partialItem.setAmount(total);
break;
}
// It fits partially
partialItem.setAmount(max);
item.setAmount(amount = total - max);
}
}
}
return this;
}
Aggregations