Advertisement
Guest User

ItemMagnesiumAndSteel

a guest
Mar 15th, 2015
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. package com.smith.mod.items;
  2.  
  3. import com.smith.mod.Debugger;
  4.  
  5. import net.minecraft.block.Block;
  6. import net.minecraft.block.BlockTNT;
  7. import net.minecraft.block.state.IBlockState;
  8. import net.minecraft.entity.player.EntityPlayer;
  9. import net.minecraft.init.Blocks;
  10. import net.minecraft.item.Item;
  11. import net.minecraft.item.ItemStack;
  12. import net.minecraft.util.BlockPos;
  13. import net.minecraft.util.EnumFacing;
  14. import net.minecraft.world.World;
  15.  
  16. public class ItemMagnesiumAndSteel extends Item
  17. {
  18.  
  19. public ItemMagnesiumAndSteel()
  20. {
  21. this.maxStackSize = 1;
  22. this.setMaxDamage(192);
  23. }
  24.  
  25. /**
  26. * Called when a Block is right-clicked with this Item
  27. *
  28. * @param pos The block being right-clicked
  29. * @param side The side being right-clicked
  30. */
  31. public boolean onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ)
  32. {
  33.  
  34. BlockPos posSide = pos.offset(side);
  35.  
  36. if (!playerIn.canPlayerEdit(posSide, side, stack))
  37. {
  38. return false;
  39. }
  40. else
  41. {
  42.  
  43.  
  44. if (worldIn.getBlockState(pos).getBlock() instanceof BlockTNT)
  45. {
  46.  
  47. ((BlockTNT) worldIn.getBlockState(pos).getBlock()).explode(worldIn, pos, worldIn.getBlockState(pos).withProperty(BlockTNT.EXPLODE, Boolean.valueOf(true)), playerIn);
  48. worldIn.setBlockToAir(pos);
  49.  
  50. }
  51.  
  52. else if (worldIn.isAirBlock(posSide) && worldIn.getBlockState(pos).getBlock() != Blocks.tnt)
  53. {
  54. worldIn.playSoundEffect((double)posSide.getX() + 0.5D, (double)posSide.getY() + 0.5D, (double)posSide.getZ() + 0.5D, "fire.ignite", 1.0F, itemRand.nextFloat() * 0.4F + 0.8F);
  55. worldIn.setBlockState(posSide, Blocks.fire.getDefaultState());
  56. }
  57.  
  58. stack.damageItem(1, playerIn);
  59. return true;
  60. }
  61. }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement