var quantityCounter = 0;

for(i=0;i<=35;i++)
{
	if(pinv.getItemInSlot(i) != null)
	{
		var thisItem = pinv.getItemInSlot(i);
		if(thisItem.getItemID() == 466)
		{
			if(thisItem.getQuantity() > 0)
			{
				if(bombsEnabled == false)
				{
					pinv.emptySlot(i);
				}
				else
				{
					hasBombs = true;
				}
				if(placeholder == true)
				{
					var thisQuantity = thisItem.getQuantity();
					if(quantityCounter <= 64)
					{
						if(quantityCounter+thisQuantity <= 64)
						{
							pinv.emptySlot(i);
							quantityCounter += thisQuantity;
						}
						else
						{
							var quantityIncreese = 64 - quantityCounter;
							thisItem.quantity -= quantityIncreese;
							quantityCounter += quantityIncreese;
						}
					}
				}
			}
		}
	}
}

if(quantityCounter > 0)
{
	pinv.emptySlot(pinv.getSlotContainingItemDamage(bombPlaceholderId, bombPlaceholderMetadata));
	placeholder = false;
	pinv.setSlot(bombSlotId, Item(466, quantityCounter));
	
}