package totemic_commons.pokefenn.item.equipment;

import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import totemic_commons.pokefenn.ModBlocks;
import totemic_commons.pokefenn.block.BlockCedarLog;
import totemic_commons.pokefenn.item.ItemTotemic;
import totemic_commons.pokefenn.lib.Strings;

/**
 * Created by Pokefenn.
 * Licensed under MIT (If this is one of my Mods)
 */
public class ItemBarkStripper extends ItemTotemic
{
    public int time = 0;

    public ItemBarkStripper()
    {
        super(Strings.BARK_STRIPPER_NAME);
        setMaxStackSize(1);
        setMaxDamage(126);
    }

    @Override
    public boolean onItemUse(ItemStack itemStack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ)
    {
        if(player.isSneaking())
            return false;

        Block block = world.getBlock(x, y, z);
        if(block instanceof BlockCedarLog)
        {
            if(!world.isRemote)
            {
                time++;
                if(time > 4)
                {
                    time = 0;
                    //Random random = new Random();

                    world.setBlock(x, y, z, ModBlocks.redCedarStripped);
                    //EntityItem bark = new EntityItem(world, block.blockX, block.blockY, block.blockZ, new ItemStack(ModItems.subItems, 1 + random.nextInt(3), ItemTotemicItems.cedarBark));
                    //world.spawnEntityInWorld(bark);
                    itemStack.damageItem(1, player);
                }
            }
            return true;
        }
        return false;
    }

}

@@ -159,24 +159,65 @@
 .ItemStack;%0A
+import net.minecraft.nbt.NBTTagCompound;%0A
 import net.m
@@ -428,16 +428,63 @@
 Strings;
+%0Aimport totemic_commons.pokefenn.util.ItemUtil;
 %0A%0A/**%0A *
@@ -615,34 +615,8 @@
 c%0A%7B%0A
-    public int time = 0;%0A%0A
     
@@ -1120,32 +1120,173 @@
 )%0A            %7B%0A
+                NBTTagCompound tag = ItemUtil.getOrCreateTag(itemStack);%0A                int time = tag.getInteger(Strings.INSTR_TIME_KEY);%0A%0A
                 
@@ -1322,10 +1322,11 @@
 me %3E
- 4
+= 5
 )%0A  
@@ -1413,20 +1413,18 @@
 m = 
-new Random()
+world.rand
 ;%0A%0A 
@@ -1801,32 +1801,95 @@
                %7D
+%0A%0A                tag.setInteger(Strings.INSTR_TIME_KEY, time);
 %0A            %7D%0A 

Fix bark stripper as well