001 package net.minecraft.block;
002
003 import java.util.Random;
004 import net.minecraft.block.material.Material;
005 import net.minecraft.creativetab.CreativeTabs;
006 import net.minecraft.entity.Entity;
007 import net.minecraft.entity.item.EntityTNTPrimed;
008 import net.minecraft.entity.player.EntityPlayer;
009 import net.minecraft.entity.projectile.EntityArrow;
010 import net.minecraft.item.Item;
011 import net.minecraft.world.Explosion;
012 import net.minecraft.world.World;
013
014 public class BlockTNT extends Block
015 {
016 public BlockTNT(int par1, int par2)
017 {
018 super(par1, par2, Material.tnt);
019 this.setCreativeTab(CreativeTabs.tabRedstone);
020 }
021
022 /**
023 * Returns the block texture based on the side being looked at. Args: side
024 */
025 public int getBlockTextureFromSide(int par1)
026 {
027 return par1 == 0 ? this.blockIndexInTexture + 2 : (par1 == 1 ? this.blockIndexInTexture + 1 : this.blockIndexInTexture);
028 }
029
030 /**
031 * Called whenever the block is added into the world. Args: world, x, y, z
032 */
033 public void onBlockAdded(World par1World, int par2, int par3, int par4)
034 {
035 super.onBlockAdded(par1World, par2, par3, par4);
036
037 if (par1World.isBlockIndirectlyGettingPowered(par2, par3, par4))
038 {
039 this.onBlockDestroyedByPlayer(par1World, par2, par3, par4, 1);
040 par1World.setBlockWithNotify(par2, par3, par4, 0);
041 }
042 }
043
044 /**
045 * Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are
046 * their own) Args: x, y, z, neighbor blockID
047 */
048 public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, int par5)
049 {
050 if (par5 > 0 && Block.blocksList[par5].canProvidePower() && par1World.isBlockIndirectlyGettingPowered(par2, par3, par4))
051 {
052 this.onBlockDestroyedByPlayer(par1World, par2, par3, par4, 1);
053 par1World.setBlockWithNotify(par2, par3, par4, 0);
054 }
055 }
056
057 /**
058 * Returns the quantity of items to drop on block destruction.
059 */
060 public int quantityDropped(Random par1Random)
061 {
062 return 1;
063 }
064
065 /**
066 * Called upon the block being destroyed by an explosion
067 */
068 public void onBlockDestroyedByExplosion(World par1World, int par2, int par3, int par4)
069 {
070 if (!par1World.isRemote)
071 {
072 EntityTNTPrimed var5 = new EntityTNTPrimed(par1World, (double)((float)par2 + 0.5F), (double)((float)par3 + 0.5F), (double)((float)par4 + 0.5F));
073 var5.fuse = par1World.rand.nextInt(var5.fuse / 4) + var5.fuse / 8;
074 par1World.spawnEntityInWorld(var5);
075 }
076 }
077
078 /**
079 * Called right before the block is destroyed by a player. Args: world, x, y, z, metaData
080 */
081 public void onBlockDestroyedByPlayer(World par1World, int par2, int par3, int par4, int par5)
082 {
083 if (!par1World.isRemote)
084 {
085 if ((par5 & 1) == 1)
086 {
087 EntityTNTPrimed var6 = new EntityTNTPrimed(par1World, (double)((float)par2 + 0.5F), (double)((float)par3 + 0.5F), (double)((float)par4 + 0.5F));
088 par1World.spawnEntityInWorld(var6);
089 par1World.playSoundAtEntity(var6, "random.fuse", 1.0F, 1.0F);
090 }
091 }
092 }
093
094 /**
095 * Called upon block activation (right click on the block.)
096 */
097 public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9)
098 {
099 if (par5EntityPlayer.getCurrentEquippedItem() != null && par5EntityPlayer.getCurrentEquippedItem().itemID == Item.flintAndSteel.itemID)
100 {
101 this.onBlockDestroyedByPlayer(par1World, par2, par3, par4, 1);
102 par1World.setBlockWithNotify(par2, par3, par4, 0);
103 return true;
104 }
105 else
106 {
107 return super.onBlockActivated(par1World, par2, par3, par4, par5EntityPlayer, par6, par7, par8, par9);
108 }
109 }
110
111 /**
112 * Triggered whenever an entity collides with this block (enters into the block). Args: world, x, y, z, entity
113 */
114 public void onEntityCollidedWithBlock(World par1World, int par2, int par3, int par4, Entity par5Entity)
115 {
116 if (par5Entity instanceof EntityArrow && !par1World.isRemote)
117 {
118 EntityArrow var6 = (EntityArrow)par5Entity;
119
120 if (var6.isBurning())
121 {
122 this.onBlockDestroyedByPlayer(par1World, par2, par3, par4, 1);
123 par1World.setBlockWithNotify(par2, par3, par4, 0);
124 }
125 }
126 }
127
128 /**
129 * Return whether this block can drop from an explosion.
130 */
131 public boolean canDropFromExplosion(Explosion par1Explosion)
132 {
133 return false;
134 }
135 }