package com.creativemd.littletiles.common.items;

import java.util.List;

import javax.annotation.Nullable;

import com.creativemd.creativecore.CreativeCore;
import com.creativemd.creativecore.common.utils.WorldUtils;
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.SubContainerHammer;
import com.creativemd.littletiles.common.gui.SubGuiHammer;
import com.creativemd.littletiles.common.tileentity.TileEntityLittleTiles;
import com.creativemd.littletiles.common.tiles.preview.LittleTilePreview;

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.tileentity.TileEntity;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
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 ItemHammer extends Item implements IGuiCreator{
	
	public ItemHammer()
	{
		setCreativeTab(LittleTiles.littleTab);
		setMaxStackSize(1);
	}
	
	@Override
	@SideOnly(Side.CLIENT)
	public void addInformation(ItemStack stack, @Nullable World worldIn, List<String> tooltip, ITooltipFlag flagIn)
	{
		tooltip.add("used for hammering normal");
		tooltip.add("blocks into small pieces");
		tooltip.add("shift+rightclick will harvest and");
		tooltip.add("drop all tiles inside one block");
	}
	
	@Override
	public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand)
    {
		if(hand == EnumHand.OFF_HAND || player.isSneaking())
			return new ActionResult(EnumActionResult.PASS, player.getHeldItem(hand)); 
		if(!world.isRemote)
			GuiHandler.openGuiItem(player, world);
        return new ActionResult(EnumActionResult.SUCCESS, player.getHeldItem(hand));
    }
	
	@Override
	public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
    {
		if(player.isSneaking())
		{
			TileEntity tileEntity = world.getTileEntity(pos);
			if(tileEntity instanceof TileEntityLittleTiles)
			{
				if(!world.isRemote)
				{
					if(((TileEntityLittleTiles) tileEntity).getTiles().size() <= 1)
					{
						WorldUtils.dropItem(world, ((TileEntityLittleTiles) tileEntity).getTiles().get(0).getDrops(), pos);
					}else{
						ItemStack drop = new ItemStack(LittleTiles.multiTiles);
						LittleTilePreview.saveTiles(world, ((TileEntityLittleTiles) tileEntity).getTiles(), drop);
						WorldUtils.dropItem(world, drop, pos);
					}
					world.setBlockToAir(pos);
				}
				return EnumActionResult.SUCCESS;
			}
		}
        return EnumActionResult.PASS;
    }
	
	@Override
	@SideOnly(Side.CLIENT)
	public SubGui getGui(EntityPlayer player, ItemStack stack, World world, BlockPos pos, IBlockState state) {
		return new SubGuiHammer();
	}

	@Override
	public SubContainer getContainer(EntityPlayer player, ItemStack stack, World world, BlockPos pos, IBlockState state) {
		return new SubContainerHammer(player);
	}
	
}

@@ -1857,110 +1857,8 @@
 %22);%0A
-%09%09tooltip.add(%22shift+rightclick will harvest and%22);%0A%09%09tooltip.add(%22drop all tiles inside one block%22);%0A
 %09%7D%0A%09
@@ -2278,881 +2278,8 @@
 ide%0A
-%09public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)%0A    %7B%0A%09%09if(player.isSneaking())%0A%09%09%7B%0A%09%09%09TileEntity tileEntity = world.getTileEntity(pos);%0A%09%09%09if(tileEntity instanceof TileEntityLittleTiles)%0A%09%09%09%7B%0A%09%09%09%09if(!world.isRemote)%0A%09%09%09%09%7B%0A%09%09%09%09%09if(((TileEntityLittleTiles) tileEntity).getTiles().size() %3C= 1)%0A%09%09%09%09%09%7B%0A%09%09%09%09%09%09WorldUtils.dropItem(world, ((TileEntityLittleTiles) tileEntity).getTiles().get(0).getDrops(), pos);%0A%09%09%09%09%09%7Delse%7B%0A%09%09%09%09%09%09ItemStack drop = new ItemStack(LittleTiles.multiTiles);%0A%09%09%09%09%09%09LittleTilePreview.saveTiles(world, ((TileEntityLittleTiles) tileEntity).getTiles(), drop);%0A%09%09%09%09%09%09WorldUtils.dropItem(world, drop, pos);%0A%09%09%09%09%09%7D%0A%09%09%09%09%09world.setBlockToAir(pos);%0A%09%09%09%09%7D%0A%09%09%09%09return EnumActionResult.SUCCESS;%0A%09%09%09%7D%0A%09%09%7D%0A        return EnumActionResult.PASS;%0A    %7D%0A%09%0A%09@Override%0A
 %09@Si

Remove Hammer's ability to remove an entire block