package org.cyclops.cyclopscore.helper;

import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;

/**
 * Contains helper methods for various itemstack specific things.
 * @author rubensworks
 */
public final class ItemStackHelpers {

    /**
     * Get the tag compound from an item safely.
     * If it does not exist yet, it will create and save a new tag compound.
     * @param itemStack The item to get the tag compound from.
     * @return The tag compound.
     */
    public static NBTTagCompound getSafeTagCompound(ItemStack itemStack) {
        if(!itemStack.hasTagCompound()) {
            itemStack.setTagCompound(new NBTTagCompound());
        }
        return itemStack.getTagCompound();
    }

}

@@ -34,16 +34,61 @@
 elper;%0A%0A
+import net.minecraft.entity.item.EntityItem;%0A
 import n
@@ -156,16 +156,112 @@
 ompound;
+%0Aimport net.minecraft.util.BlockPos;%0Aimport net.minecraft.world.World;%0A%0Aimport java.util.Random;
 %0A%0A/**%0A *
@@ -390,16 +390,72 @@
 pers %7B%0A%0A
+    private static final Random RANDOM = new Random();%0A%0A
     /**%0A
@@ -921,10 +921,1731 @@
 %0A    %7D%0A%0A
+    /**%0A     * Spawn an itemstack into the world.%0A     * @param world The world%0A     * @param pos The position%0A     * @param itemStack the item stack%0A     */%0A    public static void spawnItemStack(World world, BlockPos pos, ItemStack itemStack) %7B%0A        spawnItemStack(world, pos.getX(), pos.getY(), pos.getZ(), itemStack);%0A    %7D%0A%0A    /**%0A     * Spawn an itemstack into the world.%0A     * @param world The world%0A     * @param x X%0A     * @param y Y%0A     * @param z Z%0A     * @param itemStack the item stack%0A     */%0A    public static void spawnItemStack(World world, double x, double y, double z, ItemStack itemStack) %7B%0A        float offsetX = RANDOM.nextFloat() * 0.8F + 0.1F;%0A        float offsetY = RANDOM.nextFloat() * 0.8F + 0.1F;%0A        float offsetZ = RANDOM.nextFloat() * 0.8F + 0.1F;%0A%0A        while (itemStack.stackSize %3E 0) %7B%0A            int i = RANDOM.nextInt(21) + 10;%0A%0A            if (i %3E itemStack.stackSize) %7B%0A                i = itemStack.stackSize;%0A            %7D%0A%0A            itemStack.stackSize -= i;%0A            EntityItem entityitem = new EntityItem(world, x + (double)offsetX, y + (double)offsetY,%0A                    z + (double)offsetZ, new ItemStack(itemStack.getItem(), i, itemStack.getMetadata()));%0A%0A            if (itemStack.hasTagCompound()) %7B%0A                entityitem.getEntityItem().setTagCompound((NBTTagCompound)itemStack.getTagCompound().copy());%0A            %7D%0A%0A            float motion = 0.05F;%0A            entityitem.motionX = RANDOM.nextGaussian() * (double)motion;%0A            entityitem.motionY = RANDOM.nextGaussian() * (double)motion + 0.2D;%0A            entityitem.motionZ = RANDOM.nextGaussian() * (double)motion;%0A            world.spawnEntityInWorld(entityitem);%0A        %7D%0A    %7D%0A%0A
 %7D%0A

Add helpers for spawning items in world.