001package net.minecraft.block; 002 003import cpw.mods.fml.relauncher.Side; 004import cpw.mods.fml.relauncher.SideOnly; 005import java.util.Random; 006import net.minecraft.block.material.Material; 007import net.minecraft.client.renderer.texture.IconRegister; 008import net.minecraft.creativetab.CreativeTabs; 009import net.minecraft.entity.Entity; 010import net.minecraft.entity.EntityLiving; 011import net.minecraft.entity.item.EntityTNTPrimed; 012import net.minecraft.entity.player.EntityPlayer; 013import net.minecraft.entity.projectile.EntityArrow; 014import net.minecraft.item.Item; 015import net.minecraft.util.Icon; 016import net.minecraft.world.Explosion; 017import net.minecraft.world.World; 018 019public class BlockTNT extends Block 020{ 021 @SideOnly(Side.CLIENT) 022 private Icon field_94393_a; 023 @SideOnly(Side.CLIENT) 024 private Icon field_94392_b; 025 026 public BlockTNT(int par1) 027 { 028 super(par1, Material.tnt); 029 this.setCreativeTab(CreativeTabs.tabRedstone); 030 } 031 032 @SideOnly(Side.CLIENT) 033 034 /** 035 * From the specified side and block metadata retrieves the blocks texture. Args: side, metadata 036 */ 037 public Icon getBlockTextureFromSideAndMetadata(int par1, int par2) 038 { 039 return par1 == 0 ? this.field_94392_b : (par1 == 1 ? this.field_94393_a : this.field_94336_cN); 040 } 041 042 /** 043 * Called whenever the block is added into the world. Args: world, x, y, z 044 */ 045 public void onBlockAdded(World par1World, int par2, int par3, int par4) 046 { 047 super.onBlockAdded(par1World, par2, par3, par4); 048 049 if (par1World.isBlockIndirectlyGettingPowered(par2, par3, par4)) 050 { 051 this.onBlockDestroyedByPlayer(par1World, par2, par3, par4, 1); 052 par1World.func_94571_i(par2, par3, par4); 053 } 054 } 055 056 /** 057 * Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are 058 * their own) Args: x, y, z, neighbor blockID 059 */ 060 public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, int par5) 061 { 062 if (par1World.isBlockIndirectlyGettingPowered(par2, par3, par4)) 063 { 064 this.onBlockDestroyedByPlayer(par1World, par2, par3, par4, 1); 065 par1World.func_94571_i(par2, par3, par4); 066 } 067 } 068 069 /** 070 * Returns the quantity of items to drop on block destruction. 071 */ 072 public int quantityDropped(Random par1Random) 073 { 074 return 1; 075 } 076 077 /** 078 * Called upon the block being destroyed by an explosion 079 */ 080 public void onBlockDestroyedByExplosion(World par1World, int par2, int par3, int par4, Explosion par5Explosion) 081 { 082 if (!par1World.isRemote) 083 { 084 EntityTNTPrimed entitytntprimed = new EntityTNTPrimed(par1World, (double)((float)par2 + 0.5F), (double)((float)par3 + 0.5F), (double)((float)par4 + 0.5F), par5Explosion.func_94613_c()); 085 entitytntprimed.fuse = par1World.rand.nextInt(entitytntprimed.fuse / 4) + entitytntprimed.fuse / 8; 086 par1World.spawnEntityInWorld(entitytntprimed); 087 } 088 } 089 090 /** 091 * Called right before the block is destroyed by a player. Args: world, x, y, z, metaData 092 */ 093 public void onBlockDestroyedByPlayer(World par1World, int par2, int par3, int par4, int par5) 094 { 095 this.func_94391_a(par1World, par2, par3, par4, par5, (EntityLiving)null); 096 } 097 098 public void func_94391_a(World par1World, int par2, int par3, int par4, int par5, EntityLiving par6EntityLiving) 099 { 100 if (!par1World.isRemote) 101 { 102 if ((par5 & 1) == 1) 103 { 104 EntityTNTPrimed entitytntprimed = new EntityTNTPrimed(par1World, (double)((float)par2 + 0.5F), (double)((float)par3 + 0.5F), (double)((float)par4 + 0.5F), par6EntityLiving); 105 par1World.spawnEntityInWorld(entitytntprimed); 106 par1World.playSoundAtEntity(entitytntprimed, "random.fuse", 1.0F, 1.0F); 107 } 108 } 109 } 110 111 /** 112 * Called upon block activation (right click on the block.) 113 */ 114 public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9) 115 { 116 if (par5EntityPlayer.getCurrentEquippedItem() != null && par5EntityPlayer.getCurrentEquippedItem().itemID == Item.flintAndSteel.itemID) 117 { 118 this.func_94391_a(par1World, par2, par3, par4, 1, par5EntityPlayer); 119 par1World.func_94571_i(par2, par3, par4); 120 return true; 121 } 122 else 123 { 124 return super.onBlockActivated(par1World, par2, par3, par4, par5EntityPlayer, par6, par7, par8, par9); 125 } 126 } 127 128 /** 129 * Triggered whenever an entity collides with this block (enters into the block). Args: world, x, y, z, entity 130 */ 131 public void onEntityCollidedWithBlock(World par1World, int par2, int par3, int par4, Entity par5Entity) 132 { 133 if (par5Entity instanceof EntityArrow && !par1World.isRemote) 134 { 135 EntityArrow entityarrow = (EntityArrow)par5Entity; 136 137 if (entityarrow.isBurning()) 138 { 139 this.func_94391_a(par1World, par2, par3, par4, 1, entityarrow.shootingEntity instanceof EntityLiving ? (EntityLiving)entityarrow.shootingEntity : null); 140 par1World.func_94571_i(par2, par3, par4); 141 } 142 } 143 } 144 145 /** 146 * Return whether this block can drop from an explosion. 147 */ 148 public boolean canDropFromExplosion(Explosion par1Explosion) 149 { 150 return false; 151 } 152 153 @SideOnly(Side.CLIENT) 154 public void func_94332_a(IconRegister par1IconRegister) 155 { 156 this.field_94336_cN = par1IconRegister.func_94245_a("tnt_side"); 157 this.field_94393_a = par1IconRegister.func_94245_a("tnt_top"); 158 this.field_94392_b = par1IconRegister.func_94245_a("tnt_bottom"); 159 } 160}