Herbalism.java 6.2 KB

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