use of org.bukkit.craftbukkit.v1_8_R2.inventory.CraftItemStack in project MyPet by xXKeyleXx.
the class CustomInventory method addItem.
public int addItem(org.bukkit.inventory.ItemStack itemAdd) {
if (itemAdd == null) {
return 0;
}
itemAdd = itemAdd.clone();
for (int i = 0; i < this.getSize(); i++) {
CraftItemStack craftItem = CraftItemStack.asCraftMirror(getItem(i));
if (ItemStackComparator.compareItem(itemAdd, craftItem)) {
if (craftItem.getAmount() >= craftItem.getMaxStackSize()) {
continue;
}
while (craftItem.getAmount() < craftItem.getMaxStackSize() && itemAdd.getAmount() > 0) {
craftItem.setAmount(craftItem.getAmount() + 1);
itemAdd.setAmount(itemAdd.getAmount() - 1);
}
if (itemAdd.getAmount() == 0) {
break;
}
}
}
if (itemAdd.getAmount() > 0) {
for (int i = 0; i < this.getSize(); i++) {
if (getItem(i) == null) {
if (itemAdd.getAmount() <= itemAdd.getMaxStackSize()) {
setItem(i, CraftItemStack.asNMSCopy(itemAdd.clone()));
itemAdd.setAmount(0);
break;
} else {
CraftItemStack itemStack = (CraftItemStack) itemAdd.clone();
itemStack.setAmount(itemStack.getMaxStackSize());
setItem(i, CraftItemStack.asNMSCopy(itemStack));
itemAdd.setAmount(itemAdd.getAmount() - itemStack.getMaxStackSize());
}
if (itemAdd.getAmount() == 0) {
break;
}
}
}
}
return itemAdd.getAmount();
}
use of org.bukkit.craftbukkit.v1_8_R2.inventory.CraftItemStack in project MyPet by xXKeyleXx.
the class CustomInventory method addItem.
public int addItem(org.bukkit.inventory.ItemStack itemAdd) {
if (itemAdd == null) {
return 0;
}
itemAdd = itemAdd.clone();
for (int i = 0; i < this.getSize(); i++) {
CraftItemStack craftItem = CraftItemStack.asCraftMirror(getItem(i));
if (ItemStackComparator.compareItem(itemAdd, craftItem)) {
if (craftItem.getAmount() >= craftItem.getMaxStackSize()) {
continue;
}
while (craftItem.getAmount() < craftItem.getMaxStackSize() && itemAdd.getAmount() > 0) {
craftItem.setAmount(craftItem.getAmount() + 1);
itemAdd.setAmount(itemAdd.getAmount() - 1);
}
if (itemAdd.getAmount() == 0) {
break;
}
}
}
if (itemAdd.getAmount() > 0) {
for (int i = 0; i < this.getSize(); i++) {
if (getItem(i) == null) {
if (itemAdd.getAmount() <= itemAdd.getMaxStackSize()) {
setItem(i, CraftItemStack.asNMSCopy(itemAdd.clone()));
itemAdd.setAmount(0);
break;
} else {
CraftItemStack itemStack = (CraftItemStack) itemAdd.clone();
itemStack.setAmount(itemStack.getMaxStackSize());
setItem(i, CraftItemStack.asNMSCopy(itemStack));
itemAdd.setAmount(itemAdd.getAmount() - itemStack.getMaxStackSize());
}
if (itemAdd.getAmount() == 0) {
break;
}
}
}
}
return itemAdd.getAmount();
}
use of org.bukkit.craftbukkit.v1_8_R2.inventory.CraftItemStack in project MyPet by xXKeyleXx.
the class CustomInventory method addItem.
public int addItem(org.bukkit.inventory.ItemStack itemAdd) {
if (itemAdd == null) {
return 0;
}
itemAdd = itemAdd.clone();
for (int i = 0; i < this.getSize(); i++) {
CraftItemStack craftItem = CraftItemStack.asCraftMirror(getItem(i));
if (ItemStackComparator.compareItem(itemAdd, craftItem)) {
if (craftItem.getAmount() >= craftItem.getMaxStackSize()) {
continue;
}
while (craftItem.getAmount() < craftItem.getMaxStackSize() && itemAdd.getAmount() > 0) {
craftItem.setAmount(craftItem.getAmount() + 1);
itemAdd.setAmount(itemAdd.getAmount() - 1);
}
if (itemAdd.getAmount() == 0) {
break;
}
}
}
if (itemAdd.getAmount() > 0) {
for (int i = 0; i < this.getSize(); i++) {
if (getItem(i) == null) {
if (itemAdd.getAmount() <= itemAdd.getMaxStackSize()) {
setItem(i, CraftItemStack.asNMSCopy(itemAdd.clone()));
itemAdd.setAmount(0);
break;
} else {
CraftItemStack itemStack = (CraftItemStack) itemAdd.clone();
itemStack.setAmount(itemStack.getMaxStackSize());
setItem(i, CraftItemStack.asNMSCopy(itemStack));
itemAdd.setAmount(itemAdd.getAmount() - itemStack.getMaxStackSize());
}
if (itemAdd.getAmount() == 0) {
break;
}
}
}
}
return itemAdd.getAmount();
}
use of org.bukkit.craftbukkit.v1_8_R2.inventory.CraftItemStack in project MyPet by xXKeyleXx.
the class CustomInventory method addItem.
public int addItem(org.bukkit.inventory.ItemStack itemAdd) {
if (itemAdd == null) {
return 0;
}
itemAdd = itemAdd.clone();
for (int i = 0; i < this.getSize(); i++) {
CraftItemStack craftItem = CraftItemStack.asCraftMirror(getItem(i));
if (ItemStackComparator.compareItem(itemAdd, craftItem)) {
if (craftItem.getAmount() >= craftItem.getMaxStackSize()) {
continue;
}
while (craftItem.getAmount() < craftItem.getMaxStackSize() && itemAdd.getAmount() > 0) {
craftItem.setAmount(craftItem.getAmount() + 1);
itemAdd.setAmount(itemAdd.getAmount() - 1);
}
if (itemAdd.getAmount() == 0) {
break;
}
}
}
if (itemAdd.getAmount() > 0) {
for (int i = 0; i < this.getSize(); i++) {
if (getItem(i) == null) {
if (itemAdd.getAmount() <= itemAdd.getMaxStackSize()) {
setItem(i, CraftItemStack.asNMSCopy(itemAdd.clone()));
itemAdd.setAmount(0);
break;
} else {
CraftItemStack itemStack = (CraftItemStack) itemAdd.clone();
itemStack.setAmount(itemStack.getMaxStackSize());
setItem(i, CraftItemStack.asNMSCopy(itemStack));
itemAdd.setAmount(itemAdd.getAmount() - itemStack.getMaxStackSize());
}
if (itemAdd.getAmount() == 0) {
break;
}
}
}
}
return itemAdd.getAmount();
}
use of org.bukkit.craftbukkit.v1_8_R2.inventory.CraftItemStack in project Essentials by EssentialsX.
the class v1_8_R1SpawnerProvider method setEntityType.
@Override
public ItemStack setEntityType(ItemStack is, EntityType type) {
net.minecraft.server.v1_8_R1.ItemStack itemStack;
CraftItemStack craftStack = CraftItemStack.asCraftCopy(is);
itemStack = CraftItemStack.asNMSCopy(craftStack);
NBTTagCompound tag = itemStack.getTag();
if (tag == null) {
tag = new NBTTagCompound();
itemStack.setTag(tag);
}
if (!tag.hasKey("BlockEntityTag")) {
tag.set("BlockEntityTag", new NBTTagCompound());
}
tag = itemStack.getTag().getCompound("BlockEntityTag");
tag.setString("EntityId", type.getName());
ItemStack bukkitItemStack = CraftItemStack.asCraftMirror(itemStack).clone();
return setDisplayName(bukkitItemStack, type);
}
Aggregations