<commit_before>package com.creativemd.littletiles.common.items;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import javax.annotation.Nullable;

import com.creativemd.creativecore.CreativeCore;
import com.creativemd.creativecore.common.utils.ColorUtils;
import com.creativemd.creativecore.gui.container.SubContainer;
import com.creativemd.creativecore.gui.container.SubGui;
import com.creativemd.creativecore.gui.opener.GuiHandler;
import com.creativemd.creativecore.gui.opener.IGuiCreator;
import com.creativemd.littletiles.LittleTiles;
import com.creativemd.littletiles.common.container.SubContainerTileContainer;
import com.creativemd.littletiles.common.gui.SubGuiTileContainer;
import com.creativemd.littletiles.common.ingredients.BlockIngredient;
import com.creativemd.littletiles.common.ingredients.BlockIngredient.BlockIngredients;
import com.creativemd.littletiles.common.ingredients.ColorUnit;
import com.creativemd.littletiles.common.tiles.LittleTile;
import com.creativemd.littletiles.common.tiles.LittleTileBlock;
import com.creativemd.littletiles.common.tiles.LittleTileBlockColored;
import com.creativemd.littletiles.common.tiles.vec.LittleTileSize;

import net.minecraft.block.Block;
import net.minecraft.block.BlockAir;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagFloat;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class ItemTileContainer extends Item implements IGuiCreator{
	
	public static int colorUnitMaximum = 1000000;
	public static int inventoryWidth = 6;
	public static int inventoryHeight = 4;
	public static int inventorySize = inventoryWidth*inventoryHeight;
	public static int maxStackSize = 64;
	public static int maxStackSizeOfTiles = maxStackSize*LittleTile.maxTilesPerBlock;
	
	public ItemTileContainer()
	{
		setCreativeTab(LittleTiles.littleTab);
		setMaxStackSize(1);
	}
	
	@Override
	@SideOnly(Side.CLIENT)
	public void addInformation(ItemStack stack, @Nullable World worldIn, List<String> tooltip, ITooltipFlag flagIn)
	{
		
	}
	
	public static void saveInventory(ItemStack stack, List<BlockIngredient> inventory)
	{
		if(!stack.hasTagCompound())
			stack.setTagCompound(new NBTTagCompound());
		
		NBTTagList list = new NBTTagList();
		int i = 0;
		for (BlockIngredient ingredient : inventory) {
			if(ingredient.block instanceof BlockAir)
				continue;
			if(i >= inventorySize)
				break;
			NBTTagCompound nbt = new NBTTagCompound();
			nbt.setString("block", Block.REGISTRY.getNameForObject(ingredient.block).toString());
			nbt.setInteger("meta", ingredient.meta);
			nbt.setDouble("volume", ingredient.value);
			list.appendTag(nbt);
			i++;
		}
		
		stack.getTagCompound().setTag("inv", list);
	}
	
	public static List<BlockIngredient> loadInventory(ItemStack stack)
	{
		if(!stack.hasTagCompound())
			stack.setTagCompound(new NBTTagCompound());
		
		List<BlockIngredient> inventory = new ArrayList<>();
		
		NBTTagList list = stack.getTagCompound().getTagList("inv", 10);
		int size = Math.min(inventorySize, list.tagCount());
		for (int i = 0; i < size; i++) {
			NBTTagCompound nbt = list.getCompoundTagAt(i);
			Block block = Block.getBlockFromName(nbt.getString("block"));
			if(block instanceof BlockAir)
				continue;
			inventory.add(new BlockIngredient(block, nbt.getInteger("meta"), nbt.getDouble("volume")));
		}
		return inventory;
	}
	
	public static BlockIngredients drainBlocks(ItemStack stack, BlockIngredients ingredients, boolean simulate)
	{
		List<BlockIngredient> inventory = loadInventory(stack);
		for (Iterator<BlockIngredient> iterator = ingredients.getIngredients().iterator(); iterator.hasNext();) {
			BlockIngredient ingredient = iterator.next();
			
			for (Iterator iterator2 = inventory.iterator(); iterator2.hasNext();) {
				BlockIngredient invIngredient = (BlockIngredient) iterator2.next();
				if(invIngredient.equals(ingredient))
				{
					double amount = Math.min(invIngredient.value, ingredient.value);
					ingredient.value -= amount;
					invIngredient.value -= amount;
					if(ingredient.value <= 0)
					{
						iterator.remove();
						break;
					}
					if(invIngredient.value <= 0)
						iterator2.remove();
				}
			}
		}
		
		if(!simulate)
			saveInventory(stack, inventory);<commit_msg>Fixed LittleBag loading empty block ingredients<commit_after>package com.creativemd.littletiles.common.items;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import javax.annotation.Nullable;

import com.creativemd.creativecore.CreativeCore;
import com.creativemd.creativecore.common.utils.ColorUtils;
import com.creativemd.creativecore.gui.container.SubContainer;
import com.creativemd.creativecore.gui.container.SubGui;
import com.creativemd.creativecore.gui.opener.GuiHandler;
import com.creativemd.creativecore.gui.opener.IGuiCreator;
import com.creativemd.littletiles.LittleTiles;
import com.creativemd.littletiles.common.container.SubContainerTileContainer;
import com.creativemd.littletiles.common.gui.SubGuiTileContainer;
import com.creativemd.littletiles.common.ingredients.BlockIngredient;
import com.creativemd.littletiles.common.ingredients.BlockIngredient.BlockIngredients;
import com.creativemd.littletiles.common.ingredients.ColorUnit;
import com.creativemd.littletiles.common.tiles.LittleTile;
import com.creativemd.littletiles.common.tiles.LittleTileBlock;
import com.creativemd.littletiles.common.tiles.LittleTileBlockColored;
import com.creativemd.littletiles.common.tiles.vec.LittleTileSize;

import net.minecraft.block.Block;
import net.minecraft.block.BlockAir;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagFloat;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class ItemTileContainer extends Item implements IGuiCreator{
	
	public static int colorUnitMaximum = 1000000;
	public static int inventoryWidth = 6;
	public static int inventoryHeight = 4;
	public static int inventorySize = inventoryWidth*inventoryHeight;
	public static int maxStackSize = 64;
	public static int maxStackSizeOfTiles = maxStackSize*LittleTile.maxTilesPerBlock;
	
	public ItemTileContainer()
	{
		setCreativeTab(LittleTiles.littleTab);
		setMaxStackSize(1);
	}
	
	@Override
	@SideOnly(Side.CLIENT)
	public void addInformation(ItemStack stack, @Nullable World worldIn, List<String> tooltip, ITooltipFlag flagIn)
	{
		
	}
	
	public static void saveInventory(ItemStack stack, List<BlockIngredient> inventory)
	{
		if(!stack.hasTagCompound())
			stack.setTagCompound(new NBTTagCompound());
		
		NBTTagList list = new NBTTagList();
		int i = 0;
		for (BlockIngredient ingredient : inventory) {
			if(ingredient.block instanceof BlockAir)
				continue;
			if(i >= inventorySize)
				break;
			NBTTagCompound nbt = new NBTTagCompound();
			nbt.setString("block", Block.REGISTRY.getNameForObject(ingredient.block).toString());
			nbt.setInteger("meta", ingredient.meta);
			nbt.setDouble("volume", ingredient.value);
			list.appendTag(nbt);
			i++;
		}
		
		stack.getTagCompound().setTag("inv", list);
	}
	
	public static List<BlockIngredient> loadInventory(ItemStack stack)
	{
		if(!stack.hasTagCompound())
			stack.setTagCompound(new NBTTagCompound());
		
		List<BlockIngredient> inventory = new ArrayList<>();
		
		NBTTagList list = stack.getTagCompound().getTagList("inv", 10);
		int size = Math.min(inventorySize, list.tagCount());
		for (int i = 0; i < size; i++) {
			NBTTagCompound nbt = list.getCompoundTagAt(i);
			Block block = Block.getBlockFromName(nbt.getString("block"));
			if(block instanceof BlockAir)
				continue;
			if(nbt.getDouble("volume") > 0)
				inventory.add(new BlockIngredient(block, nbt.getInteger("meta"), nbt.getDouble("volume")));
		}
		return inventory;
	}
	
	public static BlockIngredients drainBlocks(ItemStack stack, BlockIngredients ingredients, boolean simulate)
	{
		List<BlockIngredient> inventory = loadInventory(stack);
		for (Iterator<BlockIngredient> iterator = ingredients.getIngredients().iterator(); iterator.hasNext();) {
			BlockIngredient ingredient = iterator.next();
			
			for (Iterator iterator2 = inventory.iterator(); iterator2.hasNext();) {
				BlockIngredient invIngredient = (BlockIngredient) iterator2.next();
				if(invIngredient.equals(ingredient))
				{
					double amount = Math.min(invIngredient.value, ingredient.value);
					ingredient.value -= amount;
					invIngredient.value -= amount;
					if(ingredient.value <= 0)
					{
						iterator.remove();
						break;
					}
					if(invIngredient.value <= 0)
						iterator2.remove();
				}
			}
		}
		
		if(!simulate)
			saveInventory(stack, inventory);
{'fraction_non_alphanumeric': 0.10892710892710893, 'fraction_numerical': 0.004606879606879607, 'mean_word_length': 5.4354413702239786, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3753514', 'n_tokens_mistral': 3510, 'n_tokens_neox': 3159, 'n_words': 540}