<commit_before>package net.mcft.copy.betterstorage.utils;

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

import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;

public class InventoryUtils {
	
	/** Standard decrStackSize which modifies stackSize directly. */
	public static ItemStack unsafeDecreaseStackSize(IInventory inventory, int slot, int amount) {
		ItemStack stack = inventory.getStackInSlot(slot);
		if (stack == null) return null;
		amount = Math.min(amount, stack.stackSize);
		if (amount < stack.stackSize) {
			stack.stackSize -= amount;
			stack = stack.copy();
			stack.stackSize = amount;
		} else inventory.setInventorySlotContents(slot, null);
		return stack;
	}
	
	/** Returns if the inventory has a specific item. */
	public static boolean hasItem(IInventory inventory, Item item) {
		for (int i = 0; i < inventory.getSizeInventory(); i++) {
			ItemStack stack = inventory.getStackInSlot(i);
			if (stack != null && stack.getItem() == item) return true;
		}
		return false;
	}
	/** Finds and returns a specific item in the inventory, null if none found. */
	public static ItemStack findItem(IInventory inventory, Item item) {
		for (int i = 0; i < inventory.getSizeInventory(); i++) {
			ItemStack stack = inventory.getStackInSlot(i);
			if (stack != null && stack.getItem() == item) return stack;
		}
		return null;
	}
	/** Finds and returns the slot a specific item is in, -1 if none found. */
	public static int findItemSlot(IInventory inventory, Item item) {
		for (int i = 0; i < inventory.getSizeInventory(); i++) {
			ItemStack stack = inventory.getStackInSlot(i);
			if (stack != null && stack.getItem() == item) return i;
		}
		return -1;
	}

	/** Returns a list of items of the specific type in the inventory. */
	public static int countItems(IInventory inventory, Item item) {
		int count = 0;
		for (int i = 0; i < inventory.getSizeInventory(); i++) {
			ItemStack stack = inventory.getStackInSlot(i);
			if (stack != null && stack.getItem() == item) count++;
		}
		return count;
	}
	/** Returns a list of items of the specific type in the inventory. */
	public static List<ItemStack> findItems(IInventory inventory, Item item) {
		List<ItemStack> list = new ArrayList<ItemStack>();
		for (int i = 0; i < inventory.getSizeInventory(); i++) {
			ItemStack stack = inventory.getStackInSlot(i);
			if (stack != null && stack.getItem() == item) list.add(stack);
		}
		return list;
	}
	/** Returns a list of slot indices which hold a specific item type in the inventory. */
	public static List<Integer> findItemSlots(IInventory inventory, Item item) {
		List<Integer> list = new ArrayList<Integer>();
		for (int i = 0; i < inventory.getSizeInventory(); i++) {
			ItemStack stack = inventory.getStackInSlot(i);
			if (stack != null && stack.getItem() == item) list.add(i);
		}
		return list;
	}
	
}<commit_msg>Add InventoryUtils.copyStack<commit_after>package net.mcft.copy.betterstorage.utils;

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

import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;

public class InventoryUtils {
	
	/** Standard decrStackSize which modifies stackSize directly. */
	public static ItemStack unsafeDecreaseStackSize(IInventory inventory, int slot, int amount) {
		ItemStack stack = inventory.getStackInSlot(slot);
		if (stack == null) return null;
		amount = Math.min(amount, stack.stackSize);
		if (amount < stack.stackSize) {
			stack.stackSize -= amount;
			stack = stack.copy();
			stack.stackSize = amount;
		} else inventory.setInventorySlotContents(slot, null);
		return stack;
	}
	
	/** Returns if the inventory has a specific item. */
	public static boolean hasItem(IInventory inventory, Item item) {
		for (int i = 0; i < inventory.getSizeInventory(); i++) {
			ItemStack stack = inventory.getStackInSlot(i);
			if (stack != null && stack.getItem() == item) return true;
		}
		return false;
	}
	/** Finds and returns a specific item in the inventory, null if none found. */
	public static ItemStack findItem(IInventory inventory, Item item) {
		for (int i = 0; i < inventory.getSizeInventory(); i++) {
			ItemStack stack = inventory.getStackInSlot(i);
			if (stack != null && stack.getItem() == item) return stack;
		}
		return null;
	}
	/** Finds and returns the slot a specific item is in, -1 if none found. */
	public static int findItemSlot(IInventory inventory, Item item) {
		for (int i = 0; i < inventory.getSizeInventory(); i++) {
			ItemStack stack = inventory.getStackInSlot(i);
			if (stack != null && stack.getItem() == item) return i;
		}
		return -1;
	}

	/** Returns a list of items of the specific type in the inventory. */
	public static int countItems(IInventory inventory, Item item) {
		int count = 0;
		for (int i = 0; i < inventory.getSizeInventory(); i++) {
			ItemStack stack = inventory.getStackInSlot(i);
			if (stack != null && stack.getItem() == item) count++;
		}
		return count;
	}
	/** Returns a list of items of the specific type in the inventory. */
	public static List<ItemStack> findItems(IInventory inventory, Item item) {
		List<ItemStack> list = new ArrayList<ItemStack>();
		for (int i = 0; i < inventory.getSizeInventory(); i++) {
			ItemStack stack = inventory.getStackInSlot(i);
			if (stack != null && stack.getItem() == item) list.add(stack);
		}
		return list;
	}
	/** Returns a list of slot indices which hold a specific item type in the inventory. */
	public static List<Integer> findItemSlots(IInventory inventory, Item item) {
		List<Integer> list = new ArrayList<Integer>();
		for (int i = 0; i < inventory.getSizeInventory(); i++) {
			ItemStack stack = inventory.getStackInSlot(i);
			if (stack != null && stack.getItem() == item) list.add(i);
		}
		return list;
	}
	
	public static ItemStack copyStack(ItemStack stack, int stackSize) {
		ItemStack copy = new ItemStack(stack.itemID, stackSize, stack.getItemDamage());
		if (stack.stackTagCompound != null)
			copy.stackTagCompound = (NBTTagCompound)stack.stackTagCompound.copy();
		return copy;
	}
	
}
{'fraction_non_alphanumeric': 0.12534637326813367, 'fraction_numerical': 0.00293398533007335, 'mean_word_length': 4.0543657331136735, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 15, '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': '2011483', 'n_tokens_mistral': 2021, 'n_tokens_neox': 1887, 'n_words': 609}