Herbalism.java 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. package com.gmail.nossr50.skills.herbalism;
  2. import org.bukkit.Material;
  3. import org.bukkit.block.Block;
  4. import org.bukkit.block.BlockFace;
  5. import org.bukkit.block.BlockState;
  6. import org.bukkit.material.SmoothBrick;
  7. import com.gmail.nossr50.mcMMO;
  8. import com.gmail.nossr50.config.AdvancedConfig;
  9. import com.gmail.nossr50.util.skills.SkillUtils;
  10. import java.util.ArrayList;
  11. import java.util.LinkedHashSet;
  12. import java.util.List;
  13. public class Herbalism {
  14. public static int farmersDietRankLevel1 = AdvancedConfig.getInstance().getFarmerDietRankChange();
  15. public static int farmersDietRankLevel2 = farmersDietRankLevel1 * 2;
  16. public static int farmersDietMaxLevel = farmersDietRankLevel1 * 5;
  17. public static int greenThumbStageChangeLevel = AdvancedConfig.getInstance().getGreenThumbStageChange();
  18. public static int greenThumbStageMaxLevel = greenThumbStageChangeLevel * 4;
  19. /**
  20. * Convert blocks affected by the Green Thumb & Green Terra abilities.
  21. *
  22. * @param blockState The {@link BlockState} to check ability activation for
  23. * @return true if the ability was successful, false otherwise
  24. */
  25. protected static boolean convertGreenTerraBlocks(BlockState blockState) {
  26. switch (blockState.getType()) {
  27. case COBBLE_WALL:
  28. blockState.setRawData((byte) 0x1);
  29. return true;
  30. case SMOOTH_BRICK:
  31. ((SmoothBrick) blockState.getData()).setMaterial(Material.MOSSY_COBBLESTONE);
  32. return true;
  33. case DIRT:
  34. blockState.setType(Material.GRASS);
  35. return true;
  36. case COBBLESTONE:
  37. blockState.setType(Material.MOSSY_COBBLESTONE);
  38. return true;
  39. default:
  40. return false;
  41. }
  42. }
  43. public static List<Block> findChorusPlant(Block target) {
  44. return findChorusPlant(target, true);
  45. }
  46. private static List<Block> findChorusPlant(Block target, boolean origin) {
  47. List<Block> blocks = new ArrayList<Block>();
  48. if(target.getType() != Material.CHORUS_PLANT) {
  49. return blocks;
  50. }
  51. blocks.add(target);
  52. Block relative = target.getRelative(BlockFace.UP, 1);
  53. if(relative.getType() == Material.CHORUS_PLANT) {
  54. blocks.addAll(findChorusPlant(relative, false));
  55. }
  56. if(origin || target.getRelative(BlockFace.DOWN, 1).getType() == Material.CHORUS_PLANT) {
  57. relative = target.getRelative(BlockFace.NORTH, 1);
  58. if(relative.getType() == Material.CHORUS_PLANT) {
  59. blocks.addAll(findChorusPlant(relative, false));
  60. }
  61. relative = target.getRelative(BlockFace.SOUTH, 1);
  62. if(relative.getType() == Material.CHORUS_PLANT) {
  63. blocks.addAll(findChorusPlant(relative, false));
  64. }
  65. relative = target.getRelative(BlockFace.EAST, 1);
  66. if(relative.getType() == Material.CHORUS_PLANT) {
  67. blocks.addAll(findChorusPlant(relative, false));
  68. }
  69. relative = target.getRelative(BlockFace.WEST, 1);
  70. if(relative.getType() == Material.CHORUS_PLANT) {
  71. blocks.addAll(findChorusPlant(relative, false));
  72. }
  73. }
  74. return new ArrayList<Block>(new LinkedHashSet<Block>(blocks));
  75. }
  76. /**
  77. * Calculate the drop amounts for multi block plants based on the blocks relative to them.
  78. *
  79. * @param blockState The {@link BlockState} of the bottom block of the plant
  80. * @return the number of bonus drops to award from the blocks in this plant
  81. */
  82. protected static int calculateMultiBlockPlantDrops(BlockState blockState) {
  83. Block block = blockState.getBlock();
  84. Material blockType = blockState.getType();
  85. int dropAmount = mcMMO.getPlaceStore().isTrue(block) ? 0 : 1;
  86. if(blockType == Material.CHORUS_PLANT) {
  87. dropAmount = 1;
  88. if(block.getRelative(BlockFace.DOWN, 1).getType() == Material.ENDER_STONE) {
  89. List<Block> blocks = findChorusPlant(block);
  90. dropAmount = blocks.size();
  91. /*for(Block b : blocks) {
  92. b.breakNaturally();
  93. }*/
  94. }
  95. }
  96. else {
  97. // Handle the two blocks above it - cacti & sugar cane can only grow 3 high naturally
  98. for (int y = 1; y < 3; y++) {
  99. Block relativeBlock = block.getRelative(BlockFace.UP, y);
  100. if (relativeBlock.getType() != blockType) {
  101. break;
  102. }
  103. if (mcMMO.getPlaceStore().isTrue(relativeBlock)) {
  104. mcMMO.getPlaceStore().setFalse(relativeBlock);
  105. }
  106. else {
  107. dropAmount++;
  108. }
  109. }
  110. }
  111. return dropAmount;
  112. }
  113. /**
  114. * Convert blocks affected by the Green Thumb & Green Terra abilities.
  115. *
  116. * @param blockState The {@link BlockState} to check ability activation for
  117. * @return true if the ability was successful, false otherwise
  118. */
  119. protected static boolean convertShroomThumb(BlockState blockState) {
  120. switch (blockState.getType()) {
  121. case DIRT:
  122. case GRASS:
  123. blockState.setType(Material.MYCEL);
  124. return true;
  125. default:
  126. return false;
  127. }
  128. }
  129. /**
  130. * Check if the block has a recently grown crop from Green Thumb
  131. *
  132. * @param blockState The {@link BlockState} to check green thumb regrown for
  133. * @return true if the block is recently regrown, false otherwise
  134. */
  135. public static boolean isRecentlyRegrown(BlockState blockState) {
  136. return blockState.hasMetadata(mcMMO.greenThumbDataKey) && !SkillUtils.cooldownExpired(blockState.getMetadata(mcMMO.greenThumbDataKey).get(0).asInt(), 1);
  137. }
  138. }