BlockBreakEffects.java 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. package me.km.effects.passive;
  2. import me.km.KajetansMod;
  3. import me.km.api.Module;
  4. import me.km.api.ModuleListener;
  5. import me.km.api.Utils;
  6. import me.km.effects.Effect;
  7. import me.km.effects.EffectUtils;
  8. import me.km.utils.ItemStackBuilder;
  9. import net.minecraft.block.Block;
  10. import net.minecraft.block.BlockCrops;
  11. import net.minecraft.block.BlockFalling;
  12. import net.minecraft.block.material.Material;
  13. import net.minecraft.block.state.IBlockState;
  14. import net.minecraft.enchantment.EnchantmentHelper;
  15. import net.minecraft.entity.player.EntityPlayer;
  16. import net.minecraft.init.Blocks;
  17. import net.minecraft.init.Enchantments;
  18. import net.minecraft.init.Items;
  19. import net.minecraft.item.ItemStack;
  20. import net.minecraft.util.math.BlockPos;
  21. import net.minecraft.world.World;
  22. import net.minecraftforge.event.entity.player.PlayerEvent;
  23. import net.minecraftforge.event.world.BlockEvent;
  24. import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
  25. public class BlockBreakEffects extends ModuleListener
  26. {
  27. public BlockBreakEffects(Module m)
  28. {
  29. super(m);
  30. }
  31. @SubscribeEvent(receiveCanceled = false)
  32. public void onBlockBreakSkills(BlockEvent.BreakEvent e)
  33. {
  34. if(!KajetansMod.worldManager.getWorldPreferences(e.getWorld()).skills)
  35. {
  36. return;
  37. }
  38. EntityPlayer p = e.getPlayer();
  39. BlockPos pos = e.getPos();
  40. World w = e.getWorld();
  41. IBlockState state = w.getBlockState(pos);
  42. Block b = state.getBlock();
  43. ItemStack hand = p.getHeldItemMainhand();
  44. // ---------------------------------------------------------------------
  45. // Gravel-Sand-Digger
  46. // ---------------------------------------------------------------------
  47. if(b instanceof BlockFalling)
  48. {
  49. int level = EffectUtils.getEffectLevel(p, Effect.GRAVEL_SAND_DIGGER);
  50. if(level >= 1)
  51. {
  52. BlockPos dig;
  53. for(int i = 0; i < level; i++)
  54. {
  55. dig = pos.add(0, i, 0);
  56. state = w.getBlockState(dig);
  57. if(state.getBlock() instanceof BlockFalling)
  58. {
  59. Utils.breakBlock(w, dig, p);
  60. continue;
  61. }
  62. break;
  63. }
  64. }
  65. return;
  66. }
  67. // ---------------------------------------------------------------------
  68. // More Minerals
  69. // ---------------------------------------------------------------------
  70. if(EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, hand) >= 1)
  71. {
  72. if(b == Blocks.DIAMOND_ORE || b == Blocks.REDSTONE_ORE ||
  73. b == Blocks.LAPIS_ORE || b == Blocks.COAL_ORE)
  74. {
  75. if(Utils.randomBoolean() && EffectUtils.getEffectLevel(p, Effect.MORE_MINERALS) >= 1)
  76. {
  77. b.dropBlockAsItem(w, pos, state, 0);
  78. }
  79. }
  80. }
  81. // ---------------------------------------------------------------------
  82. // More Crops
  83. // ---------------------------------------------------------------------
  84. if(b instanceof BlockCrops && state.getValue(BlockCrops.AGE) == 7)
  85. {
  86. int moreCrops = EffectUtils.getEffectLevel(p, Effect.MORE_CROPS);
  87. if(moreCrops >= 1)
  88. {
  89. b.getDrops(w, pos, state, 0).stream().filter(s -> Utils.randomBoolean()).forEach((stack) ->
  90. {
  91. new ItemStackBuilder(stack, Utils.randomInt(1, moreCrops)).drop(w, pos);
  92. });
  93. }
  94. }
  95. // ---------------------------------------------------------------------
  96. // Tree Picker und More Saplings
  97. // ---------------------------------------------------------------------
  98. if((b == Blocks.LEAVES || b == Blocks.LEAVES2) && hand.getItem() != Items.SHEARS)
  99. {
  100. if(Utils.randomInt(1, 25) <= EffectUtils.getEffectLevel(p, Effect.TREE_PICKER))
  101. {
  102. Utils.dropRandomTreeItem(w, pos, state);
  103. }
  104. if(Utils.randomInt(1, 25) <= EffectUtils.getEffectLevel(p, Effect.MORE_SAPLINGS))
  105. {
  106. if(b == Blocks.LEAVES)
  107. {
  108. new ItemStackBuilder(Blocks.SAPLING, 1, b.getMetaFromState(state) % 4).drop(w, pos);
  109. }
  110. else
  111. {
  112. new ItemStackBuilder(Blocks.SAPLING, 1, (b.getMetaFromState(state) % 4) + 4).drop(w, pos);
  113. }
  114. }
  115. }
  116. }
  117. @SubscribeEvent(receiveCanceled = false)
  118. public void onBlockDamage(PlayerEvent.BreakSpeed e)
  119. {
  120. EntityPlayer p = e.getEntityPlayer();
  121. if(KajetansMod.worldManager.getWorldPreferences(p.world).skills)
  122. {
  123. float speed = e.getOriginalSpeed();
  124. if(KajetansMod.jobs.isPreferedMaterial(p, e.getState().getBlock()))
  125. {
  126. // Speed up with prefered blocks of current job
  127. int digging = EffectUtils.getEffectLevel(p, Effect.FAST_DIGGING);
  128. if(digging >= 1)
  129. {
  130. speed *= (1 + (digging / 5));
  131. }
  132. }
  133. if(p.isInsideOfMaterial(Material.WATER) && !EnchantmentHelper.getAquaAffinityModifier(p) &&
  134. KajetansMod.data.get(p).hasAquaAffinity())
  135. {
  136. speed *= 2;
  137. }
  138. e.setNewSpeed(speed);
  139. }
  140. }
  141. }