Advertisement
Guest User

Untitled

a guest
Aug 2nd, 2017
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.59 KB | None | 0 0
  1. package com.mod.drakania.items;
  2.  
  3. import com.mod.drakania.init.ItemMod;
  4.  
  5. import net.minecraft.block.Block;
  6. import net.minecraft.creativetab.CreativeTabs;
  7. import net.minecraft.enchantment.EnchantmentHelper;
  8. import net.minecraft.entity.EntityLivingBase;
  9. import net.minecraft.entity.player.EntityPlayer;
  10. import net.minecraft.item.Item;
  11. import net.minecraft.item.Item.ToolMaterial;
  12. import net.minecraft.item.ItemPickaxe;
  13. import net.minecraft.item.ItemStack;
  14. import net.minecraft.util.Vec3;
  15. import net.minecraft.world.World;
  16. import net.minecraftforge.common.ForgeHooks;
  17. import net.minecraftforge.common.MinecraftForge;
  18. import net.minecraftforge.event.world.BlockEvent.BreakEvent;
  19.  
  20. public class ItemHammer extends ItemPickaxeDraka
  21. {
  22.  
  23. public ItemHammer(ToolMaterial p_i45347_1_)
  24. {
  25. super(p_i45347_1_);
  26.  
  27. }
  28. public boolean getIsRepairable(ItemStack input, ItemStack repair)
  29.  
  30.  
  31. {
  32.  
  33. if(repair.getItem() == ItemMod.drakanium_ingot)
  34.  
  35. {
  36.  
  37. return true;
  38.  
  39. }
  40.  
  41. return true;
  42.  
  43. }
  44. public boolean onBlockDestroyed(ItemStack stack, World world, Block block, int x, int y, int z, EntityLivingBase entity) {
  45. if(entity instanceof EntityPlayer) {
  46.  
  47. EntityPlayer player = (EntityPlayer)entity;
  48.  
  49. Vec3 lookVec = player.getLookVec();
  50. double xLook = Math.abs(lookVec.xCoord);
  51. double yLook = Math.abs(lookVec.yCoord);
  52. double zLook = Math.abs(lookVec.zCoord);
  53.  
  54.  
  55. double max = Math.max(xLook, Math.max(yLook, zLook));
  56.  
  57.  
  58.  
  59. int addX = 1;
  60. int addY = 1;
  61. int addZ = 1;
  62.  
  63. if(max == xLook) {
  64. y -= 1;
  65. z -= 1;
  66. addX = 3;
  67. } else if(max == yLook) {
  68. x -= 1;
  69. z -= 1;
  70. addY = 3;
  71. } else if(max == zLook) {
  72. x -= 1;
  73. y -= 1;
  74. addZ = 3;
  75. }
  76.  
  77. for(int xOffset = 0; xOffset < 3; xOffset += addX) {
  78. for(int yOffset = 0; yOffset < 3; yOffset += addY) {
  79. for(int zOffset = 0; zOffset < 3; zOffset += addZ) {
  80.  
  81. Block currentBlock = world.getBlock(x + xOffset, y + yOffset, z + zOffset);
  82. int blockMetadata = world.getBlockMetadata(x + xOffset, y + yOffset, z + zOffset);
  83.  
  84. BreakEvent event = new BreakEvent(x + xOffset, y + yOffset, x + zOffset, world, currentBlock, blockMetadata, (EntityPlayer)player);
  85. event.setCanceled(!player.capabilities.isCreativeMode);
  86.  
  87.  
  88. if(currentBlock.getBlockHardness(world, x + xOffset, y + yOffset, z + zOffset) >= 0) {
  89. event.setCanceled(false);
  90. }
  91.  
  92. MinecraftForge.EVENT_BUS.post(event);
  93.  
  94. if(!event.isCanceled()) {
  95. currentBlock.harvestBlock(world, (EntityPlayer)player, x + xOffset, y + yOffset, z + zOffset, blockMetadata);
  96. world.setBlockToAir(x + xOffset, y + yOffset, z + zOffset);
  97.  
  98. boolean hasSilk = EnchantmentHelper.getSilkTouchModifier(player);
  99. boolean canSilk = currentBlock.canSilkHarvest(world, (EntityPlayer)player, x + xOffset, y + yOffset, z + zOffset, blockMetadata);
  100. if(ForgeHooks.canHarvestBlock(currentBlock, (EntityPlayer)player, blockMetadata) && (!hasSilk || hasSilk && !canSilk)) {
  101.  
  102.  
  103. int exp = currentBlock.getExpDrop(world, blockMetadata, EnchantmentHelper.getFortuneModifier(player));
  104. currentBlock.dropXpOnBlockBreak(world, x + xOffset, y + yOffset, z + zOffset, exp);
  105. }
  106. }
  107. }
  108. }
  109. }
  110. return true;
  111. }
  112. return false;
  113.  
  114. }
  115.  
  116.  
  117.  
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement