package common.block;

import common.entity.item.EntityNuke;
import common.init.Blocks;
import common.init.SoundEvent;
import common.item.CheatTab;
import common.material.Material;
import common.model.Model;
import common.model.ModelProvider;
import common.util.BlockPos;
import common.world.Explosion;
import common.world.State;
import common.world.World;
import common.world.AWorldServer;

public class BlockNuke extends Block
{
    public BlockNuke()
    {
        super(Material.tnt);
        this.setTab(CheatTab.tabTech);
    }

    public void onBlockAdded(AWorldServer worldIn, BlockPos pos, State state)
    {
        super.onBlockAdded(worldIn, pos, state);

        if (worldIn.isBlockPowered(pos))
        {
            this.explode(worldIn, pos);
            worldIn.setBlockToAir(pos);
        }
    }
    
    public void onNeighborBlockChange(World worldIn, BlockPos pos, State state, Block neighborBlock)
    {
        if (worldIn.isBlockPowered(pos))
        {
            this.explode(worldIn, pos);
            worldIn.setBlockToAir(pos);
        }
    }
    
    public void onBlockDestroyedByExplosion(World worldIn, BlockPos pos, Explosion explosionIn, State prevState)
    {
        if (!worldIn.client)
        {
        	worldIn.setState(pos, Blocks.obsidian.getState(), 2);
        }
    }

    public void explode(World worldIn, BlockPos pos)
    {
        if (!worldIn.client)
        {
        	EntityNuke entitytntprimed = new EntityNuke(worldIn, (double)((float)pos.getX() + 0.5F), (double)pos.getY(), (double)((float)pos.getZ() + 0.5F));
            worldIn.spawnEntityInWorld(entitytntprimed);
            worldIn.playSoundAtEntity(entitytntprimed, SoundEvent.FUSE, 1.0F);
        }
    }
    
    public boolean canDropFromExplosion(Explosion explosionIn)
    {
        return false;
    }
    
    public boolean isXrayVisible()
    {
        return true;
    }

    public Model getModel(ModelProvider provider, String name, State state) {
    	return provider.getModel("nuke_side").add().nswe().d("nuke_bottom").u("nuke_top");
    }
}
