Advertisement
Guest User

TNT extends BlockTNT

a guest
Feb 21st, 2016
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.03 KB | None | 0 0
  1. package TheMod;
  2.  
  3. import net.minecraft.block.Block;
  4. import net.minecraft.block.BlockTNT;
  5. import net.minecraft.block.material.Material;
  6. import net.minecraft.block.properties.PropertyBool;
  7. import net.minecraft.block.state.IBlockState;
  8. import net.minecraft.client.Minecraft;
  9. import net.minecraft.client.resources.model.ModelResourceLocation;
  10. import net.minecraft.entity.EntityLivingBase;
  11. import net.minecraft.item.Item;
  12. import net.minecraft.util.BlockPos;
  13. import net.minecraft.world.Explosion;
  14. import net.minecraft.world.World;
  15. import net.minecraftforge.client.model.ModelLoader;
  16. import net.minecraftforge.fml.common.registry.GameRegistry;
  17.  
  18.  
  19.  
  20. public class TNT extends BlockTNT {
  21.  
  22.     public static final PropertyBool EXPLODE = PropertyBool.create("explode");
  23.  
  24.     public TNT(String name, Material tnt)
  25.     {
  26.         super();
  27.         this.setDefaultState(this.blockState.getBaseState().withProperty(EXPLODE, Boolean.valueOf(false)));
  28.         this.setCreativeTab(Main.tabTheMod);
  29.         this.setHardness(blockHardness);
  30.         this.setStepSound(Block.soundTypeGrass);
  31.         this.setUnlocalizedName(name);
  32.  
  33.         System.out.println("INITIALIZING BLOCK: " + name);
  34.         GameRegistry.registerBlock(this, name);
  35.     }
  36.  
  37.     public void RegisterRenderer(String modelName)
  38.     {
  39.         System.out.println("REGISTERING BLOCK RENDERER: " + modelName);
  40.         ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(Main.Nuke), 0, new ModelResourceLocation(Main.MODID+":"+modelName, "inventory"));
  41.         Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(Item.getItemFromBlock(Main.Nuke), 0, new ModelResourceLocation(Main.MODID+":"+modelName, "inventory"));
  42.  
  43.     }
  44.  
  45.     public void onBlockDestroyedByExplosion(World worldIn, BlockPos pos, Explosion explosionIn) {
  46.         if (!worldIn.isRemote) {
  47.             EntityNukePrimed Nuke = new EntityNukePrimed(worldIn, (double) ((float) pos.getX() + 0.5F), (double) pos.getY(), (double) ((float) pos.getZ() + 0.5F), explosionIn.getExplosivePlacedBy());
  48.             Nuke.fuse = worldIn.rand.nextInt(Nuke.fuse / 4) + Nuke.fuse / 8;
  49.             worldIn.spawnEntityInWorld(Nuke);
  50.         }
  51.     }
  52.     public void onNeighborBlockChange(World worldIn, BlockPos pos, IBlockState state, Block neighborBlock)
  53.     {
  54.         if (worldIn.isBlockPowered(pos))
  55.         {
  56.             this.onBlockDestroyedByPlayer(worldIn, pos, state.withProperty(EXPLODE, Boolean.valueOf(true)));
  57.             worldIn.setBlockToAir(pos);
  58.         }
  59.     }
  60.  
  61.     public void explode(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase igniter) {
  62.         if (!worldIn.isRemote) {
  63.             if (((Boolean) state.getValue(EXPLODE)).booleanValue()) {
  64.                 EntityNukePrimed Nuke = new EntityNukePrimed(worldIn, (double) ((float) pos.getX() + 0.5F), (double) pos.getY(), (double) ((float) pos.getZ() + 0.5F), igniter);
  65.                 worldIn.spawnEntityInWorld(Nuke);
  66.                 worldIn.playSoundAtEntity(Nuke, "game.tnt.primed", 1.0F, 1.0F);
  67.             }
  68.         }
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement