Java Code Examples for net.minecraft.item.ItemStack#getMaxStackSize()

The following examples show how to use net.minecraft.item.ItemStack#getMaxStackSize() . 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: InfusionRecipe.java    From PneumaticCraft with GNU General Public License v3.0 6 votes vote down vote up
public static boolean areItemStacksEqual(ItemStack stack0, ItemStack stack1, boolean fuzzy)
  {
if (stack0==null && stack1!=null) return false;
if (stack0!=null && stack1==null) return false;
if (stack0==null && stack1==null) return true;

//nbt
boolean t1=ThaumcraftApiHelper.areItemStackTagsEqualForCrafting(stack0, stack1);		
if (!t1) return false;

if (fuzzy) {
	Integer od = OreDictionary.getOreID(stack0);
	if (od!=-1) {
		ItemStack[] ores = OreDictionary.getOres(od).toArray(new ItemStack[]{});
		if (ThaumcraftApiHelper.containsMatch(false, new ItemStack[]{stack1}, ores))
			return true;
	}
}

//damage
boolean damage = stack0.getItemDamage() == stack1.getItemDamage() ||
		stack1.getItemDamage() == OreDictionary.WILDCARD_VALUE;		

      return stack0.getItem() != stack1.getItem() ? false : (!damage ? false : stack0.stackSize <= stack0.getMaxStackSize() );
  }
 
Example 2
Source File: InfusionEnchantmentRecipe.java    From ForbiddenMagic with Do What The F*ck You Want To Public License 6 votes vote down vote up
protected boolean areItemStacksEqual(ItemStack stack0, ItemStack stack1, boolean fuzzy)
  {
if (stack0==null && stack1!=null) return false;
if (stack0!=null && stack1==null) return false;
if (stack0==null && stack1==null) return true;
boolean t1=ThaumcraftApiHelper.areItemStackTagsEqualForCrafting(stack0, stack1);
if (!t1) return false;
if (fuzzy) {
	int od = OreDictionary.getOreID(stack0);
	if (od!=-1) {
		ItemStack[] ores = OreDictionary.getOres(od).toArray(new ItemStack[]{});
		if (ThaumcraftApiHelper.containsMatch(false, new ItemStack[]{stack1}, ores))
			return true;
	}
}
      return stack0.getItem() != stack1.getItem() ? false : (stack0.getItemDamage() != stack1.getItemDamage() ? false : stack0.stackSize <= stack0.getMaxStackSize() );
  }
 
Example 3
Source File: InventoryUtils.java    From OpenModsLib with MIT License 6 votes vote down vote up
public static boolean tryMergeStacks(@Nonnull ItemStack stackToMerge, @Nonnull ItemStack stackInSlot) {
	if (stackInSlot.isEmpty() || !stackInSlot.isItemEqual(stackToMerge) || !ItemStack.areItemStackTagsEqual(stackToMerge, stackInSlot)) return false;

	int newStackSize = stackInSlot.getCount() + stackToMerge.getCount();

	final int maxStackSize = stackToMerge.getMaxStackSize();
	if (newStackSize <= maxStackSize) {
		stackToMerge.setCount(0);
		stackInSlot.setCount(newStackSize);
		return true;
	} else if (stackInSlot.getCount() < maxStackSize) {
		stackToMerge.shrink(maxStackSize - stackInSlot.getCount());
		stackInSlot.setCount(maxStackSize);
		return true;
	}

	return false;
}
 
Example 4
Source File: InfusionRecipe.java    From GardenCollection with MIT License 6 votes vote down vote up
public static boolean areItemStacksEqual(ItemStack stack0, ItemStack stack1, boolean fuzzy)
  {
if (stack0==null && stack1!=null) return false;
if (stack0!=null && stack1==null) return false;
if (stack0==null && stack1==null) return true;

//nbt
boolean t1=ThaumcraftApiHelper.areItemStackTagsEqualForCrafting(stack0, stack1);		
if (!t1) return false;

if (fuzzy) {
	Integer od = OreDictionary.getOreID(stack0);
	if (od!=-1) {
		ItemStack[] ores = OreDictionary.getOres(od).toArray(new ItemStack[]{});
		if (ThaumcraftApiHelper.containsMatch(false, new ItemStack[]{stack1}, ores))
			return true;
	}
}

//damage
boolean damage = stack0.getItemDamage() == stack1.getItemDamage() ||
		stack1.getItemDamage() == OreDictionary.WILDCARD_VALUE;		

      return stack0.getItem() != stack1.getItem() ? false : (!damage ? false : stack0.stackSize <= stack0.getMaxStackSize() );
  }
 
Example 5
Source File: HarvesterTileEntity.java    From EmergingTechnology with MIT License 5 votes vote down vote up
private boolean outputsFull() {

        ItemStack[] outputStacks = this.getOutputStacks();

        boolean isFull = true;

        for (ItemStack itemStack : outputStacks) {
            if (itemStack.getCount() < itemStack.getMaxStackSize()) {
                isFull = false;
            }
        }

        return isFull;
    }
 
Example 6
Source File: MultiblockReactorSimulator.java    From reactor_simulator with MIT License 5 votes vote down vote up
/**
 * Attempt to distribute a stack of ingots to a given access port, sensitive to the amount and type of ingots already in it.
 * @param port The port to which we're distributing ingots.
 * @param itemsToDistribute The stack of ingots to distribute. Will be modified during the operation and may be returned with stack size 0.
 * @param distributeToInputs Should we try to send ingots to input ports?
 * @return The number of waste items distributed, i.e. the differential in stack size for wasteToDistribute.
 */
private int tryDistributeItems(TileEntityReactorAccessPort port, ItemStack itemsToDistribute, boolean distributeToInputs) {
  ItemStack existingStack = port.getStackInSlot(TileEntityReactorAccessPort.SLOT_OUTLET);
  int initialWasteAmount = itemsToDistribute.stackSize;
  if (!port.isInlet() || (distributeToInputs || attachedAccessPorts.size() < 2)) {
    // Dump waste preferentially to outlets, unless we only have one access port
    if (existingStack == null) {
      if (itemsToDistribute.stackSize > port.getInventoryStackLimit()) {
        ItemStack newStack = itemsToDistribute.splitStack(port.getInventoryStackLimit());
        port.setInventorySlotContents(TileEntityReactorAccessPort.SLOT_OUTLET, newStack);
      } else {
        port.setInventorySlotContents(TileEntityReactorAccessPort.SLOT_OUTLET, itemsToDistribute.copy());
        itemsToDistribute.stackSize = 0;
      }
    } else if (existingStack.isItemEqual(itemsToDistribute)) {
      if (existingStack.stackSize + itemsToDistribute.stackSize <= existingStack.getMaxStackSize()) {
        existingStack.stackSize += itemsToDistribute.stackSize;
        itemsToDistribute.stackSize = 0;
      } else {
        int amt = existingStack.getMaxStackSize() - existingStack.stackSize;
        itemsToDistribute.stackSize -= existingStack.getMaxStackSize() - existingStack.stackSize;
        existingStack.stackSize += amt;
      }
    }

    port.onItemsReceived();
  }

  return initialWasteAmount - itemsToDistribute.stackSize;
}
 
Example 7
Source File: ContainerCreationStation.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected void rightClickSlot(int slotNum, EntityPlayer player)
{
    // Not a crafting output slot
    if (this.craftingOutputSlotLeft != slotNum && this.craftingOutputSlotRight != slotNum)
    {
        super.rightClickSlot(slotNum, player);
        return;
    }

    SlotItemHandlerGeneric slot = this.getSlotItemHandler(slotNum);

    if (slot != null && slot.getHasStack())
    {
        ItemStack stackOrig = slot.getStack().copy();
        int num = stackOrig.getMaxStackSize() / stackOrig.getCount();

        while (num-- > 0)
        {
            super.rightClickSlot(slotNum, player);

            // Ran out of some of the ingredients, so the crafting result changed, stop here
            if (InventoryUtils.areItemStacksEqual(stackOrig, slot.getStack()) == false)
            {
                break;
            }
        }
    }
}
 
Example 8
Source File: MixinEntityItem.java    From Hyperium with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Inject(method = "searchForOtherItemsNearby", at = @At("HEAD"), cancellable = true)
private void stopSearchWhenFullStack(CallbackInfo ci) {
    ItemStack stack = getEntityItem();
    if (stack.stackSize > stack.getMaxStackSize()) {
        ci.cancel();
    }
}
 
Example 9
Source File: TileEntityEtherealMacerator.java    From Electro-Magic-Tools with GNU General Public License v3.0 5 votes vote down vote up
private boolean canSmelt() {
    if (this.slots[0] == null) {
        return false;
    } else {
        ItemStack itemstack = FurnaceRecipes.smelting().getSmeltingResult(this.slots[0]);
        if (itemstack == null)
            return false;
        if (this.slots[2] == null)
            return true;
        if (!this.slots[2].isItemEqual(itemstack))
            return false;
        int result = slots[2].stackSize + (itemstack.stackSize * 2);
        return (result <= getInventoryStackLimit() && result <= itemstack.getMaxStackSize());
    }
}
 
Example 10
Source File: ContainerHandyBag.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected void rightClickSlot(int slotNum, EntityPlayer player)
{
    // Not a crafting output slot
    if (slotNum != this.craftingSlot)
    {
        super.rightClickSlot(slotNum, player);
        return;
    }

    SlotItemHandlerGeneric slot = this.getSlotItemHandler(slotNum);

    if (slot != null && slot.getHasStack())
    {
        ItemStack stackOrig = slot.getStack().copy();
        int num = stackOrig.getMaxStackSize() / stackOrig.getCount();

        while (num-- > 0)
        {
            super.rightClickSlot(slotNum, player);

            // Ran out of some of the ingredients, so the crafting result changed, stop here
            if (InventoryUtils.areItemStacksEqual(stackOrig, slot.getStack()) == false)
            {
                break;
            }
        }
    }
}
 
Example 11
Source File: FastTransferManager.java    From NotEnoughItems with MIT License 5 votes vote down vote up
public void retrieveItem(GuiContainer window, int toSlot) {
    Slot slot = window.inventorySlots.getSlot(toSlot);
    ItemStack slotStack = slot.getStack();
    if (slotStack == null ||
            slotStack.stackSize == slot.getSlotStackLimit() ||
            slotStack.stackSize == slotStack.getMaxStackSize())
        return;

    generateSlotMap(window.inventorySlots, slotStack);

    Integer destZone = slotZoneMap.get(toSlot);
    if (destZone == null)//slots that don't accept
        return;

    int firstZoneSlot = findShiftClickDestinationSlot(window.inventorySlots, toSlot);
    int firstZone = -1;
    if (firstZoneSlot != -1) {
        Integer integer = slotZoneMap.get(firstZoneSlot);
        if (integer != null) {
            firstZone = integer;
            if (retrieveItemFromZone(window, firstZone, toSlot))
                return;
        }
    }

    for (int zone = 0; zone < slotZones.size(); zone++) {
        if (zone == destZone || zone == firstZone)
            continue;

        if (retrieveItemFromZone(window, zone, toSlot))
            return;
    }

    retrieveItemFromZone(window, destZone, toSlot);
}
 
Example 12
Source File: ContainerCookingPot.java    From TFC2 with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Called to transfer a stack from one inventory to the other eg. when shift clicking.
 */
@Override
public ItemStack transferStackInSlotTFC(EntityPlayer player, int slotNum)
{
	ItemStack origStack = ItemStack.EMPTY;
	Slot slot = (Slot)this.inventorySlots.get(slotNum);

	if (slot != null && slot.getHasStack())
	{
		ItemStack slotStack = slot.getStack();
		origStack = slotStack.copy();

		if (slotNum < 36)
		{
			if (!this.mergeItemStack(slotStack, 36, inventorySlots.size()-1, false))
				return ItemStack.EMPTY;
		}
		else
		{
			if (!this.mergeItemStack(slotStack, 0, 36, false))
				return ItemStack.EMPTY;
		}

		if (slotStack.getMaxStackSize() <= 0)
			slot.putStack(ItemStack.EMPTY);
		else
			slot.onSlotChanged();

		if (slotStack.getMaxStackSize() == origStack.getMaxStackSize())
			return ItemStack.EMPTY;

		slot.onTake(player, slotStack);
	}

	return origStack;
}
 
Example 13
Source File: TileEntityTFOven.java    From TofuCraftReload with MIT License 5 votes vote down vote up
@Override
public boolean canWork() {
    if (energy >= POWER) { //If energy is suitable
        if (((ItemStack) this.inventory.get(0)).isEmpty()) {
            return false;
        } else {
            ItemStack itemstack = FurnaceRecipes.instance().getSmeltingResult(this.inventory.get(0));

            if (itemstack.isEmpty()) {
                return false;
            } else {
                ItemStack itemstack1 = this.inventory.get(1);

                if (itemstack1.isEmpty()) {
                    return true;
                } else if (!itemstack1.isItemEqual(itemstack)) {
                    return false;
                } else if (itemstack1.getCount() + itemstack.getCount() <= this.getInventoryStackLimit() && itemstack1.getCount() + itemstack.getCount() <= itemstack1.getMaxStackSize())  // Forge fix: make furnace respect stack sizes in furnace recipes
                {
                    return true;
                } else {
                    return itemstack1.getCount() + itemstack.getCount() <= itemstack.getMaxStackSize(); // Forge fix: make furnace respect stack sizes in furnace recipes
                }
            }
        }
    }
    return false;
}
 
Example 14
Source File: InventoryPartBarrel.java    From BetterChests with GNU Lesser General Public License v3.0 5 votes vote down vote up
public String getAmountDescr() {
	ItemStack stack = getDummy();
	int stacksize = stack.getMaxStackSize();
	int totalAmount = getTotalAmountOfItems();
	String text;
	if (totalAmount >= stacksize && stacksize > 1) {
		text = (totalAmount / stacksize) + "x" + stacksize + "+" + (totalAmount % stacksize);
	} else {
		text = "" + totalAmount;
	}
	return text;
}
 
Example 15
Source File: BlockHandler.java    From BetterChests with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public int getMaxCapacity(@Nonnull ItemStack itemPrototype) {
	return barrel.getChestPart().getActualSize() * itemPrototype.getMaxStackSize();
}
 
Example 16
Source File: GuiContainer.java    From NotEnoughItems with MIT License 4 votes vote down vote up
/**
 * Draws the given slot: any item in it, the slot's background, the hovered highlight, etc.
 *
 * @param slotIn The slot to draw
 */
private void drawSlot(Slot slotIn) {
    int i = slotIn.xDisplayPosition;
    int j = slotIn.yDisplayPosition;
    ItemStack itemstack = slotIn.getStack();
    boolean flag = false;
    boolean flag1 = slotIn == this.clickedSlot && this.draggedStack != null && !this.isRightMouseClick;
    ItemStack itemstack1 = this.mc.thePlayer.inventory.getItemStack();
    String s = null;

    if (slotIn == this.clickedSlot && this.draggedStack != null && this.isRightMouseClick && itemstack != null) {
        itemstack = itemstack.copy();
        itemstack.stackSize /= 2;
    } else if (this.dragSplitting && this.dragSplittingSlots.contains(slotIn) && itemstack1 != null) {
        if (this.dragSplittingSlots.size() == 1) {
            return;
        }

        if (Container.canAddItemToSlot(slotIn, itemstack1, true) && this.inventorySlots.canDragIntoSlot(slotIn)) {
            itemstack = itemstack1.copy();
            flag = true;
            Container.computeStackSize(this.dragSplittingSlots, this.dragSplittingLimit, itemstack, slotIn.getStack() == null ? 0 : slotIn.getStack().stackSize);

            if (itemstack.stackSize > itemstack.getMaxStackSize()) {
                s = TextFormatting.YELLOW + "" + itemstack.getMaxStackSize();
                itemstack.stackSize = itemstack.getMaxStackSize();
            }

            if (itemstack.stackSize > slotIn.getItemStackLimit(itemstack)) {
                s = TextFormatting.YELLOW + "" + slotIn.getItemStackLimit(itemstack);
                itemstack.stackSize = slotIn.getItemStackLimit(itemstack);
            }
        } else {
            this.dragSplittingSlots.remove(slotIn);
            this.updateActivePotionEffects();
        }
    }

    this.zLevel = 100.0F;
    this.itemRender.zLevel = 100.0F;

    if (itemstack == null && slotIn.canBeHovered()) {
        TextureAtlasSprite textureatlassprite = slotIn.getBackgroundSprite();

        if (textureatlassprite != null) {
            GlStateManager.disableLighting();
            this.mc.getTextureManager().bindTexture(slotIn.getBackgroundLocation());
            this.drawTexturedModalRect(i, j, textureatlassprite, 16, 16);
            GlStateManager.enableLighting();
            flag1 = true;
        }
    }

    if (!flag1) {
        if (flag) {
            drawRect(i, j, i + 16, j + 16, -2130706433);
        }

        GlStateManager.enableDepth();
        manager.renderSlotUnderlay(slotIn);
        manager.drawSlotItem(slotIn, itemstack, i, j, s);
        manager.renderSlotOverlay(slotIn);
        //this.itemRender.renderItemAndEffectIntoGUI(this.mc.thePlayer, itemstack, i, j);
        //this.itemRender.renderItemOverlayIntoGUI(this.fontRendererObj, itemstack, i, j, s);
    }

    this.itemRender.zLevel = 0.0F;
    this.zLevel = 0.0F;
}
 
Example 17
Source File: DefaultOverlayHandler.java    From NotEnoughItems with MIT License 4 votes vote down vote up
@SuppressWarnings("unchecked")
private void moveIngredients(GuiContainer gui, List<IngredientDistribution> assignedIngredients, int quantity)
{        
    for(IngredientDistribution distrib : assignedIngredients)
    {
        ItemStack pstack = distrib.permutation;
        int transferCap = quantity*pstack.stackSize;
        int transferred = 0;
        
        int destSlotIndex = 0;
        Slot dest = distrib.slots[0];
        int slotTransferred = 0;
        int slotTransferCap = pstack.getMaxStackSize();
        
        for(Slot slot : (List<Slot>)gui.inventorySlots.inventorySlots)
        {
            if(!slot.getHasStack() || !canMoveFrom(slot, gui))
                continue;
            
            ItemStack stack = slot.getStack();
            if(!InventoryUtils.canStack(stack, pstack))
                continue;
            
            FastTransferManager.clickSlot(gui, slot.slotNumber);
            int amount = Math.min(transferCap-transferred, stack.stackSize);
            for(int c = 0; c < amount; c++)
            {
                FastTransferManager.clickSlot(gui, dest.slotNumber, 1);
                transferred++;
                slotTransferred++;
                if(slotTransferred >= slotTransferCap)
                {
                    destSlotIndex++;
                    if(destSlotIndex == distrib.slots.length)
                    {
                        dest = null;
                        break;
                    }
                    dest = distrib.slots[destSlotIndex];
                    slotTransferred = 0;
                }
            }
            FastTransferManager.clickSlot(gui, slot.slotNumber);
            if(transferred >= transferCap || dest == null)
                break;
        }
    }       
}
 
Example 18
Source File: DefaultOverlayHandler.java    From NotEnoughItems with MIT License 4 votes vote down vote up
@SuppressWarnings ("unchecked")
private void moveIngredients(GuiContainer gui, List<IngredientDistribution> assignedIngredients, int quantity) {
    for (IngredientDistribution distrib : assignedIngredients) {
        ItemStack pstack = distrib.permutation;
        int transferCap = quantity * pstack.getCount();
        int transferred = 0;

        int destSlotIndex = 0;
        Slot dest = distrib.slots[0];
        int slotTransferred = 0;
        int slotTransferCap = pstack.getMaxStackSize();

        for (Slot slot : gui.inventorySlots.inventorySlots) {
            if (!slot.getHasStack() || !canMoveFrom(slot, gui)) {
                continue;
            }

            ItemStack stack = slot.getStack();
            if (!InventoryUtils.canStack(stack, pstack)) {
                continue;
            }

            FastTransferManager.clickSlot(gui, slot.slotNumber);
            int amount = Math.min(transferCap - transferred, stack.getCount());
            for (int c = 0; c < amount; c++) {
                FastTransferManager.clickSlot(gui, dest.slotNumber, 1);
                transferred++;
                slotTransferred++;
                if (slotTransferred >= slotTransferCap) {
                    destSlotIndex++;
                    if (destSlotIndex == distrib.slots.length) {
                        dest = null;
                        break;
                    }
                    dest = distrib.slots[destSlotIndex];
                    slotTransferred = 0;
                }
            }
            FastTransferManager.clickSlot(gui, slot.slotNumber);
            if (transferred >= transferCap || dest == null) {
                break;
            }
        }
    }
}
 
Example 19
Source File: TileEntityBase.java    From PneumaticCraft with GNU General Public License v3.0 4 votes vote down vote up
private boolean canStack(ItemStack stack1, ItemStack stack2){
    return stack1.isItemEqual(stack2) && ItemStack.areItemStackTagsEqual(stack1, stack2) && stack1.stackSize + stack2.stackSize <= stack1.getMaxStackSize();
}
 
Example 20
Source File: InventoryUtils.java    From enderutilities with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Extract items from the given slot until the resulting stack's stackSize equals amount
 */
public static ItemStack extractItemsFromSlot(IItemHandler inv, int slot, int amount)
{
    ItemStack stackExtract = inv.extractItem(slot, amount, false);

    if (stackExtract.isEmpty())
    {
        return ItemStack.EMPTY;
    }

    if ((stackExtract.getMaxStackSize() * SLOT_ITER_LIMIT) < amount && inv instanceof IItemHandlerModifiable)
    {
        amount -= stackExtract.getCount();
        ItemStack stackSlot = inv.getStackInSlot(slot);

        if (stackSlot.isEmpty() == false)
        {
            if (stackSlot.getCount() <= amount)
            {
                stackExtract.grow(stackSlot.getCount());
                ((IItemHandlerModifiable) inv).setStackInSlot(slot, ItemStack.EMPTY);
            }
            else
            {
                stackExtract.grow(amount);
                stackSlot = stackSlot.copy();
                stackSlot.shrink(amount);
                ((IItemHandlerModifiable) inv).setStackInSlot(slot, stackSlot);
            }
        }

        return stackExtract;
    }

    int loops = 0;

    while (stackExtract.getCount() < amount && loops < SLOT_ITER_LIMIT)
    {
        ItemStack stackTmp = inv.extractItem(slot, amount - stackExtract.getCount(), false);

        if (stackTmp.isEmpty())
        {
            break;
        }

        stackExtract.grow(stackTmp.getCount());
        loops++;
    }

    //System.out.printf("extractItemsFromSlot(): slot: %d, requested amount: %d, loops %d, extracted: %s\n", slot, amount, loops, stack);
    return stackExtract;
}