@Override
	public ItemStack tryAdd(ItemStack stack)
	{
		int free = getNextCompatibleIndex(stack.item, 0);
		if(free == -1)
			return stack;
		else
		{ 
			ItemStack comp = getStackIn(free);
			if(comp == null)
				comp = new ItemStack();
			if(comp.nbr+stack.nbr <= stack.item.getMaxInStack())
			{
				this.putStack(free, new ItemStack(stack.item, stack.nbr+comp.nbr));
				return null;
			}
			else
			{
				boolean flag = true;
				do
				{
					free = getNextCompatibleIndex(stack.item, 0);
					if(free == -1)
						flag = false;
					ItemStack is = getStackIn(free);
					stack.nbr-=stack.item.getMaxInStack()-(is == null ? 0 : is.nbr);
					
					ItemStack added = new ItemStack(stack.item,stack.item.getMaxInStack());
					this.putStack(free, added);
					if(stack.nbr <= 0)
						return null;
					else if(stack.nbr <= stack.item.getMaxInStack())
						return tryAdd(stack);
				}while(flag);
				return stack;
			}
		}
	}