Java Code Examples for net.minecraft.item.ItemStack#isStackable()
The following examples show how to use
net.minecraft.item.ItemStack#isStackable() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StackHelper.java From AgriCraft with MIT License | 6 votes |
/** * Determines if two ItemStacks are compatible as to be merged. * <br> * Two ItemStacks, a & b, are considered compatible if and only if: * <ul> * <li>both are non-null</li> * <li>both are non-empty</li> * <li>both have the same item</li> * <li>both are stackable</li> * <li>both have no subtypes or have the same metadata</li> * <li>both have the same item as determined by {@link #areItemsEqual()}</li> * <li>both have the same damage</li> * <li>both have equivalent NBTTags as determined by {@link #areItemStackTagsEqual()}</li> * </ul> * * @param a * @param b * @return */ public static final boolean areCompatible(@Nonnull ItemStack a, @Nonnull ItemStack b) { // Validate Preconditions.checkNotNull(a); Preconditions.checkNotNull(b); // The following is 'borrowed' from ItemHandlerHelper.canItemsStack if (a.isEmpty() || b.isEmpty() || a.getItem() != b.getItem()) { return false; } if (!a.isStackable()) { return false; } if (a.getHasSubtypes() && a.getMetadata() != b.getMetadata()) { return false; } if (a.hasTagCompound() != b.hasTagCompound()) { return false; } return (!a.hasTagCompound() || a.getTagCompound().equals(b.getTagCompound())) && a.areCapsCompatible(b); }
Example 2
Source File: RecipeBook_1_12.java From multiconnect with MIT License | 5 votes |
private boolean canStackAddMore(ItemStack existingStack, ItemStack stack) { return !existingStack.isEmpty() && existingStack.getItem() == stack.getItem() && ItemStack.areTagsEqual(existingStack, stack) && existingStack.isStackable() && existingStack.getCount() < existingStack.getMaxCount() && existingStack.getCount() < 64; }
Example 3
Source File: TileItemTranslocator.java From Translocators with MIT License | 5 votes |
private boolean hasEmptySpace(InventoryRange inv) { for(int slot : inv.slots) { ItemStack stack = inv.inv.getStackInSlot(slot); if(inv.canInsertItem(slot, new ItemStack(Items.diamond)) && (stack == null || stack.isStackable() && stack.stackSize < Math.min(stack.getMaxStackSize(), inv.inv.getInventoryStackLimit()))) return true; } return false; }
Example 4
Source File: InventoryUtils.java From CodeChickenLib with GNU Lesser General Public License v2.1 | 5 votes |
public static boolean canStack(ItemStack stack1, ItemStack stack2) { return stack1 == null || stack2 == null || (stack1.getItem() == stack2.getItem() && (!stack2.getHasSubtypes() || stack2.getItemDamage() == stack1.getItemDamage()) && ItemStack.areItemStackTagsEqual(stack2, stack1)) && stack1.isStackable(); }
Example 5
Source File: InventoryUtils.java From CodeChickenLib with GNU Lesser General Public License v2.1 | 4 votes |
public static boolean canStack(@Nonnull ItemStack stack1, @Nonnull ItemStack stack2) { return stack1.isEmpty() || stack2.isEmpty() || (stack1.getItem() == stack2.getItem() && (stack2.getDamage() == stack1.getDamage()) && ItemStack.areItemStackTagsEqual(stack2, stack1)) && stack1.isStackable(); }
Example 6
Source File: ContainerPedestal.java From Artifacts with MIT License | 4 votes |
@Override protected boolean mergeItemStack(ItemStack itemstack, int i, int j, boolean flag) { // The default implementation in Slot doesn't take into account the Slot.isItemValid() and Slot.getSlotStackLimit() values. // So here is a modified implementation. I have only modified the parts with a comment. boolean flag1 = false; int k = i; if (flag) { k = j - 1; } if (itemstack.isStackable()) { while (itemstack.stackSize > 0 && (!flag && k < j || flag && k >= i)) { Slot slot = (Slot)inventorySlots.get(k); ItemStack itemstack1 = slot.getStack(); if (flag) { k--; } else { k++; } // Check if item is valid: if (!slot.isItemValid(itemstack)) { continue; } if (itemstack1 != null && itemstack1.getItem() == itemstack.getItem() && (!itemstack.getHasSubtypes() || itemstack.getItemDamage() == itemstack1.getItemDamage()) && ItemStack.areItemStackTagsEqual(itemstack, itemstack1)) { //ItemStack.areItemStacksEqual(par0ItemStack, par1ItemStack) //ItemStack.areItemStackTagsEqual(par0ItemStack, par1ItemStack) int i1 = itemstack1.stackSize + itemstack.stackSize; // Don't put more items than the slot can take: int maxItemsInDest = Math.min(itemstack1.getMaxStackSize(), slot.getSlotStackLimit()); if (i1 <= maxItemsInDest) { itemstack.stackSize = 0; itemstack1.stackSize = i1; slot.onSlotChanged(); flag1 = true; } else if (itemstack1.stackSize < maxItemsInDest) { itemstack.stackSize -= maxItemsInDest - itemstack1.stackSize; itemstack1.stackSize = maxItemsInDest; slot.onSlotChanged(); flag1 = true; } } } } if (itemstack.stackSize > 0) { int l; if (flag) { l = j - 1; } else { l = i; } do { if ((flag || l >= j) && (!flag || l < i)) { break; } Slot slot1 = (Slot)inventorySlots.get(l); ItemStack itemstack2 = slot1.getStack(); if (flag) { l--; } else { l++; } // Check if item is valid: if (!slot1.isItemValid(itemstack)) { continue; } if (itemstack2 == null) { // Don't put more items than the slot can take: int nbItemsInDest = Math.min(itemstack.stackSize, slot1.getSlotStackLimit()); ItemStack itemStack1 = itemstack.copy(); itemstack.stackSize -= nbItemsInDest; itemStack1.stackSize = nbItemsInDest; slot1.putStack(itemStack1); slot1.onSlotChanged(); // itemstack.stackSize = 0; flag1 = true; break; } } while (true); } return flag1; }