package nl.lang2619.bagginses.helpers;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
/**
* Created by Tim on 4/12/2015.
*/
public class ItemHelper {
public static ItemStack cloneItemStack(ItemStack itemStack, int stackSize)
{
ItemStack clonedItemStack = itemStack.copy();
clonedItemStack.stackSize = stackSize;
return clonedItemStack;
}
public static boolean equalsIgnoreStackSize(ItemStack itemStack1, ItemStack itemStack2)
{
if (itemStack1 != null && itemStack2 != null)
{
// Sort on itemID
if (Item.getIdFromItem(itemStack1.getItem()) - Item.getIdFromItem(itemStack2.getItem()) == 0)
{
// Sort on item
if (itemStack1.getItem() == itemStack2.getItem())
{
// Then sort on meta
if (itemStack1.getItemDamage() == itemStack2.getItemDamage())
{
// Then sort on NBT
if (itemStack1.hasTagCompound() && itemStack2.hasTagCompound())
{
// Then sort on stack size
if (ItemStack.areItemStackTagsEqual(itemStack1, itemStack2))
{
return true;
}
}
else if (!itemStack1.hasTagCompound() && !itemStack2.hasTagCompound())
{
return true;
}
}
}
}
}
return false;
}
public static boolean hasOwnerUUID(ItemStack itemStack)
{
return NBTHelper.hasTag(itemStack, Names.NBT.OWNER_UUID_MOST_SIG) && NBTHelper.hasTag(itemStack, Names.NBT.OWNER_UUID_LEAST_SIG);
}
public static boolean hasOwnerName(ItemStack itemStack)
{
return NBTHelper.hasTag(itemStack, Names.NBT.OWNER);
}
public static void setOwner(ItemStack itemStack, EntityPlayer entityPlayer)
{
setOwnerName(itemStack, entityPlayer);
setOwnerUUID(itemStack, entityPlayer);
}
public static void setOwnerUUID(ItemStack itemStack, EntityPlayer entityPlayer)
{
NBTHelper.setLong(itemStack, Names.NBT.OWNER_UUID_MOST_SIG, entityPlayer.getUniqueID().getMostSignificantBits());
NBTHelper.setLong(itemStack, Names.NBT.OWNER_UUID_LEAST_SIG, entityPlayer.getUniqueID().getLeastSignificantBits());
}
public static void setOwnerName(ItemStack itemStack, EntityPlayer entityPlayer)
{
NBTHelper.setString(itemStack, Names.NBT.OWNER, entityPlayer.getName());
}
}