Guest User

Untitled

a guest
May 21st, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.61 KB | None | 0 0
  1. package codersafterdark.attributes.common.skills.mining.fortune;
  2.  
  3. import codersafterdark.attributes.utils.AttributesConstants;
  4. import codersafterdark.reskillable.api.data.PlayerData;
  5. import codersafterdark.reskillable.api.data.PlayerDataHandler;
  6. import codersafterdark.reskillable.api.data.PlayerSkillInfo;
  7. import codersafterdark.reskillable.api.unlockable.Trait;
  8. import codersafterdark.reskillable.lib.LibMisc;
  9. import net.minecraft.block.Block;
  10. import net.minecraft.entity.player.EntityPlayer;
  11. import net.minecraft.init.Blocks;
  12. import net.minecraft.item.ItemStack;
  13. import net.minecraft.util.ResourceLocation;
  14. import net.minecraftforge.event.world.BlockEvent;
  15. import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
  16.  
  17. import java.util.ArrayList;
  18. import java.util.List;
  19.  
  20. import static codersafterdark.attributes.utils.AttributesUtilMethod.nextIntInclusive;
  21.  
  22. public class FortuneBuff extends Trait {
  23.  
  24. static List<ItemStack> blockList = new ArrayList<>();
  25.  
  26. static {
  27. blockList.add(new ItemStack(Blocks.STONE));
  28. blockList.add(new ItemStack(Blocks.BROWN_MUSHROOM_BLOCK));
  29. blockList.add(new ItemStack(Blocks.RED_MUSHROOM_BLOCK));
  30. blockList.add(new ItemStack(Blocks.CHEST));
  31. blockList.add(new ItemStack(Blocks.GRASS));
  32. blockList.add(new ItemStack(Blocks.GRASS_PATH));
  33. }
  34.  
  35. public FortuneBuff() {
  36. super(new ResourceLocation(AttributesConstants.MODID, "fortunebuff"), 1, 3, new ResourceLocation(LibMisc.MOD_ID, "mining"), 0, "");
  37. }
  38.  
  39. @SubscribeEvent
  40. public void onBlockBreak(BlockEvent.HarvestDropsEvent event) {
  41. if (event.isCanceled()) {
  42. return;
  43. }
  44.  
  45. Block block = event.getState().getBlock();
  46. ItemStack blockStack = new ItemStack(block, 1);
  47. EntityPlayer player = event.getHarvester();
  48. PlayerData data = PlayerDataHandler.get(player);
  49. PlayerSkillInfo info = data.getSkillInfo(getParentSkill());
  50.  
  51. int fortune = 0;
  52. int value = Math.round(getParentSkill().getCap() / 3);
  53.  
  54. if (info.getLevel() == info.skill.getCap()) {
  55. fortune = 3;
  56. } else if (info.getLevel() >= (value * 2)) {
  57. fortune = 2;
  58. } else if (info.getLevel() >= value) {
  59. fortune = 1;
  60. }
  61.  
  62. if (!blockList.contains(blockStack)){
  63. for (ItemStack stack : event.getDrops()){
  64. if (stack != blockStack) {
  65. event.getDrops().remove(stack);
  66. event.getDrops().add(new ItemStack(stack.getItem(), nextIntInclusive(stack.getCount(), stack.getCount() + fortune), stack.getMetadata()));
  67. }
  68. }
  69. }
  70. }
  71. }
  72. }
Add Comment
Please, Sign In to add comment