package totemic_commons.pokefenn.block.music;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraftforge.common.util.ForgeDirection;
import totemic_commons.pokefenn.block.BlockTileTotemic;
import totemic_commons.pokefenn.lib.Strings;
import totemic_commons.pokefenn.network.PacketHandler;
import totemic_commons.pokefenn.network.client.PacketSound;
import totemic_commons.pokefenn.recipe.HandlerInitiation;
import totemic_commons.pokefenn.tileentity.music.TileWindChime;
import totemic_commons.pokefenn.util.TotemUtil;

/**
 * Created by Pokefenn.
 * Licensed under MIT (If this is one of my Mods)
 */
public class BlockWindChime extends BlockTileTotemic
{
    public BlockWindChime()
    {
        super(Material.iron);
        setBlockName(Strings.WIND_CHIME_NAME);
        setBlockBounds(0.2F, 0.0F, 0.2F, 0.8F, 1F, 0.8F);
    }

    @Override
    public void onNeighborBlockChange(World world, int x, int y, int z, Block neighbor)
    {
        breakStuffs(world, x, y, z);
    }

    @Override
    public boolean canPlaceBlockAt(World world, int x, int y, int z)
    {
        return world.isAirBlock(x, y-1, z) && world.isSideSolid(x, y+1, z, ForgeDirection.DOWN);
    }

    public void breakStuffs(World world, int x, int y, int z)
    {
        if(!world.isRemote)
        {
            if(!canPlaceBlockAt(world, x, y, z))
            {
                world.setBlockToAir(x, y, z);
                dropBlockAsItem(world, x, y, z, new ItemStack(this));
            }
        }
    }

    @Override
    public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ)
    {
        TileWindChime tileWindChime = (TileWindChime) world.getTileEntity(x, y, z);

        if(!world.isRemote && player.isSneaking() && !tileWindChime.isPlaying && tileWindChime.canPlay)
        {
            tileWindChime.canPlay = false;
            PacketHandler.sendAround(new PacketSound(x, y, z, "windChime"), world.getTileEntity(x, y, z));
            TotemUtil.playMusicFromBlockForCeremonySelector(world, x, y, z, HandlerInitiation.windChime, 0);
            ((WorldServer)world).func_147487_a("note", x + 0.5D, y - 0.5D, z + 0.5D, 6, 0.0D, 0.0D, 0.0D, 0.0D);
            ((WorldServer)world).func_147487_a("fireworksSpark", x + 0.5D, y - 0.5D, z + 0.5D, 6, 0.0D, 0.0D, 0.0D, 0.0D);
        }
        return true;
    }

    @Override
    public IIcon getIcon(int side, int meta) {
        return Blocks.planks.getIcon(0, 0);
    }

    @Override
    public int getRenderType()
    {
        return -1;
    }

    @Override
    public boolean isOpaqueCube()
    {
        return false;
    }

    @Override
    public boolean renderAsNormalBlock()
    {
        return false;
    }

    @Override
    public TileEntity createNewTileEntity(World var1, int var2)
    {
        return new TileWindChime();
    }

    /*
    @Override
    public int getMaximumMusic(World world, int x, int y, int z, boolean isFromPlayer, EntityPlayer player)
    {
        return 60;
    }

    @Override
    public int getMusicOutput(World world, int x, int y, int z, boolean isFromPlayer, EntityPlayer player)
    {
        return world.getBlock(x, y + 1, z) != null && world.getBlock(x, y, z).getMaterial() == Material.leaves ? 5 : 4;
    }

    @Override
    public int getRange(World world, int x, int y, int z, boolean isFromPlayer, EntityPlayer player)
    {
        return 7;
    }
    */
}

@@ -40,16 +40,94 @@
 music;%0A%0A
+import cpw.mods.fml.relauncher.Side;%0Aimport cpw.mods.fml.relauncher.SideOnly;%0A
 import n
@@ -1216,16 +1216,43 @@
  0.8F);%0A
+        setHardness(1.5F);%0A
     %7D%0A%0A 
@@ -2792,32 +2792,59 @@
 rn true;%0A    %7D%0A%0A
+    @SideOnly(Side.CLIENT)%0A
     @Override%0A  
@@ -2885,16 +2885,20 @@
 nt meta)
+%0A   
  %7B%0A     
@@ -2918,14 +2918,29 @@
 cks.
-planks
+stained_hardened_clay
 .get

Change Wind Chime hardness and icon