package net.minecraft.block;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import java.util.Random;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityTNTPrimed;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.init.Items;
import net.minecraft.util.IIcon;
import net.minecraft.world.Explosion;
import net.minecraft.world.World;
public class BlockTNT extends Block
{
@SideOnly(Side.CLIENT)
private IIcon field_150116_a;
@SideOnly(Side.CLIENT)
private IIcon field_150115_b;
private static final String __OBFID = "CL_00000324";
public BlockTNT()
{
super(Material.tnt);
this.setCreativeTab(CreativeTabs.tabRedstone);
}
/**
* Gets the block's texture. Args: side, meta
*/
@SideOnly(Side.CLIENT)
public IIcon getIcon(int side, int meta)
{
return side == 0 ? this.field_150115_b : (side == 1 ? this.field_150116_a : this.blockIcon);
}
public void onBlockAdded(World worldIn, int x, int y, int z)
{
super.onBlockAdded(worldIn, x, y, z);
if (worldIn.isBlockIndirectlyGettingPowered(x, y, z))
{
this.onBlockDestroyedByPlayer(worldIn, x, y, z, 1);
worldIn.setBlockToAir(x, y, z);
}
}
public void onNeighborBlockChange(World worldIn, int x, int y, int z, Block neighbor)
{
if (worldIn.isBlockIndirectlyGettingPowered(x, y, z))
{
this.onBlockDestroyedByPlayer(worldIn, x, y, z, 1);
worldIn.setBlockToAir(x, y, z);
}
}
/**
* Returns the quantity of items to drop on block destruction.
*/
public int quantityDropped(Random random)
{
return 1;
}
/**
* Called upon the block being destroyed by an explosion
*/
public void onBlockDestroyedByExplosion(World worldIn, int x, int y, int z, Explosion explosionIn)
{
if (!worldIn.isRemote)
{
EntityTNTPrimed entitytntprimed = new EntityTNTPrimed(worldIn, (double)((float)x + 0.5F), (double)((float)y + 0.5F), (double)((float)z + 0.5F), explosionIn.getExplosivePlacedBy());
entitytntprimed.fuse = worldIn.rand.nextInt(entitytntprimed.fuse / 4) + entitytntprimed.fuse / 8;
worldIn.spawnEntityInWorld(entitytntprimed);
}
}
public void onBlockDestroyedByPlayer(World worldIn, int x, int y, int z, int meta)
{
this.func_150114_a(worldIn, x, y, z, meta, (EntityLivingBase)null);
}
public void func_150114_a(World p_150114_1_, int p_150114_2_, int p_150114_3_, int p_150114_4_, int p_150114_5_, EntityLivingBase p_150114_6_)
{
if (!p_150114_1_.isRemote)
{
if ((p_150114_5_ & 1) == 1)
{
EntityTNTPrimed entitytntprimed = new EntityTNTPrimed(p_150114_1_, (double)((float)p_150114_2_ + 0.5F), (double)((float)p_150114_3_ + 0.5F), (double)((float)p_150114_4_ + 0.5F), p_150114_6_);
p_150114_1_.spawnEntityInWorld(entitytntprimed);
p_150114_1_.playSoundAtEntity(entitytntprimed, "game.tnt.primed", 1.0F, 1.0F);
}
}
}
/**
* Called upon block activation (right click on the block). Args : world, x, y, z, player, side, hitX, hitY, hitZ.
* Return : Swing hand (client), abort the block placement (server)
*/
public boolean onBlockActivated(World worldIn, int x, int y, int z, EntityPlayer player, int side, float subX, float subY, float subZ)
{
if (player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().getItem() == Items.flint_and_steel)
{
this.func_150114_a(worldIn, x, y, z, 1, player);
worldIn.setBlockToAir(x, y, z);
player.getCurrentEquippedItem().damageItem(1, player);
return true;
}
else
{
return super.onBlockActivated(worldIn, x, y, z, player, side, subX, subY, subZ);
}
}
public void onEntityCollidedWithBlock(World worldIn, int x, int y, int z, Entity entityIn)
{
if (entityIn instanceof EntityArrow && !worldIn.isRemote)
{
EntityArrow entityarrow = (EntityArrow)entityIn;
if (entityarrow.isBurning())
{
this.func_150114_a(worldIn, x, y, z, 1, entityarrow.shootingEntity instanceof EntityLivingBase ? (EntityLivingBase)entityarrow.shootingEntity : null);
worldIn.setBlockToAir(x, y, z);
}
}
}
/**
* Return whether this block can drop from an explosion.
*/
public boolean canDropFromExplosion(Explosion explosionIn)
{
return false;
}
@SideOnly(Side.CLIENT)
public void registerIcons(IIconRegister reg)
{
this.blockIcon = reg.registerIcon(this.getTextureName() + "_side");
this.field_150116_a = reg.registerIcon(this.getTextureName() + "_top");
this.field_150115_b = reg.registerIcon(this.getTextureName() + "_bottom");
}
}