BlockUtils.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. package com.gmail.nossr50.util;
  2. import java.util.HashSet;
  3. import org.bukkit.CropState;
  4. import org.bukkit.Material;
  5. import org.bukkit.NetherWartsState;
  6. import org.bukkit.block.BlockState;
  7. import org.bukkit.material.CocoaPlant;
  8. import org.bukkit.material.CocoaPlant.CocoaPlantSize;
  9. import org.bukkit.material.Crops;
  10. import org.bukkit.material.NetherWarts;
  11. import org.bukkit.material.SmoothBrick;
  12. import com.gmail.nossr50.mcMMO;
  13. import com.gmail.nossr50.config.experience.ExperienceConfig;
  14. import com.gmail.nossr50.datatypes.skills.SkillType;
  15. import com.gmail.nossr50.skills.repair.Repair;
  16. import com.gmail.nossr50.skills.salvage.Salvage;
  17. public final class BlockUtils {
  18. private BlockUtils() {}
  19. /**
  20. * Checks to see if a given block awards XP.
  21. *
  22. * @param blockState
  23. * The {@link BlockState} of the block to check
  24. * @return true if the block awards XP, false otherwise
  25. */
  26. public static boolean shouldBeWatched(BlockState blockState) {
  27. return affectedByGigaDrillBreaker(blockState) || affectedByGreenTerra(blockState) || affectedBySuperBreaker(blockState) || isLog(blockState);
  28. }
  29. /**
  30. * Check if a given block should allow for the activation of abilities
  31. *
  32. * @param blockState
  33. * The {@link BlockState} of the block to check
  34. * @return true if the block should allow ability activation, false
  35. * otherwise
  36. */
  37. public static boolean canActivateAbilities(BlockState blockState) {
  38. switch (blockState.getType()) {
  39. case BED_BLOCK :
  40. case BREWING_STAND :
  41. case BOOKSHELF :
  42. case BURNING_FURNACE :
  43. case CAKE_BLOCK :
  44. case CHEST :
  45. case DISPENSER :
  46. case ENCHANTMENT_TABLE :
  47. case ENDER_CHEST :
  48. case FENCE_GATE :
  49. case ACACIA_FENCE_GATE :
  50. case DARK_OAK_FENCE_GATE :
  51. case SPRUCE_FENCE_GATE :
  52. case BIRCH_FENCE_GATE :
  53. case JUNGLE_FENCE_GATE :
  54. case FURNACE :
  55. case IRON_DOOR_BLOCK :
  56. case JUKEBOX :
  57. case LEVER :
  58. case NOTE_BLOCK :
  59. case STONE_BUTTON :
  60. case WOOD_BUTTON :
  61. case TRAP_DOOR :
  62. case WALL_SIGN :
  63. case WOODEN_DOOR :
  64. case WORKBENCH :
  65. case BEACON :
  66. case ANVIL :
  67. case DROPPER :
  68. case HOPPER :
  69. case TRAPPED_CHEST :
  70. case IRON_DOOR :
  71. case IRON_TRAPDOOR :
  72. case ACACIA_DOOR :
  73. case SPRUCE_DOOR :
  74. case BIRCH_DOOR :
  75. case JUNGLE_DOOR :
  76. case DARK_OAK_DOOR :
  77. case FENCE :
  78. case ACACIA_FENCE :
  79. case DARK_OAK_FENCE :
  80. case BIRCH_FENCE :
  81. case JUNGLE_FENCE :
  82. case SPRUCE_FENCE :
  83. case ARMOR_STAND :
  84. case BLACK_SHULKER_BOX :
  85. case BLUE_SHULKER_BOX :
  86. case BROWN_SHULKER_BOX :
  87. case CYAN_SHULKER_BOX :
  88. case GRAY_SHULKER_BOX :
  89. case GREEN_SHULKER_BOX :
  90. case LIGHT_BLUE_SHULKER_BOX :
  91. case LIME_SHULKER_BOX :
  92. case MAGENTA_SHULKER_BOX :
  93. case ORANGE_SHULKER_BOX :
  94. case PINK_SHULKER_BOX :
  95. case PURPLE_SHULKER_BOX :
  96. case RED_SHULKER_BOX :
  97. case SILVER_SHULKER_BOX :
  98. case WHITE_SHULKER_BOX :
  99. case YELLOW_SHULKER_BOX :
  100. return false;
  101. default :
  102. return !isMcMMOAnvil(blockState) && !mcMMO.getModManager().isCustomAbilityBlock(blockState);
  103. }
  104. }
  105. /**
  106. * Check if a given block is an ore
  107. *
  108. * @param blockState
  109. * The {@link BlockState} of the block to check
  110. * @return true if the block is an ore, false otherwise
  111. */
  112. public static boolean isOre(BlockState blockState) {
  113. return MaterialUtils.isOre(blockState.getData());
  114. }
  115. /**
  116. * Determine if a given block can be made mossy
  117. *
  118. * @param blockState
  119. * The {@link BlockState} of the block to check
  120. * @return true if the block can be made mossy, false otherwise
  121. */
  122. public static boolean canMakeMossy(BlockState blockState) {
  123. switch (blockState.getType()) {
  124. case COBBLESTONE :
  125. case DIRT :
  126. case GRASS_PATH :
  127. return true;
  128. case SMOOTH_BRICK :
  129. return ((SmoothBrick) blockState.getData()).getMaterial() == Material.STONE;
  130. case COBBLE_WALL :
  131. return blockState.getRawData() == (byte) 0x0;
  132. default :
  133. return false;
  134. }
  135. }
  136. /**
  137. * Determine if a given block should be affected by Green Terra
  138. *
  139. * @param blockState
  140. * The {@link BlockState} of the block to check
  141. * @return true if the block should affected by Green Terra, false otherwise
  142. */
  143. public static boolean affectedByGreenTerra(BlockState blockState) {
  144. if (ExperienceConfig.getInstance().isSkillBlock(SkillType.HERBALISM, blockState.getData()))
  145. return true;
  146. return mcMMO.getModManager().isCustomHerbalismBlock(blockState);
  147. }
  148. /**
  149. * Determine if a given block should be affected by Super Breaker
  150. *
  151. * @param blockState
  152. * The {@link BlockState} of the block to check
  153. * @return true if the block should affected by Super Breaker, false
  154. * otherwise
  155. */
  156. public static Boolean affectedBySuperBreaker(BlockState blockState) {
  157. if (ExperienceConfig.getInstance().isSkillBlock(SkillType.MINING, blockState.getData()))
  158. return true;
  159. return isOre(blockState) || mcMMO.getModManager().isCustomMiningBlock(blockState);
  160. }
  161. /**
  162. * Determine if a given block should be affected by Giga Drill Breaker
  163. *
  164. * @param blockState
  165. * The {@link BlockState} of the block to check
  166. * @return true if the block should affected by Giga Drill Breaker, false
  167. * otherwise
  168. */
  169. public static boolean affectedByGigaDrillBreaker(BlockState blockState) {
  170. if (ExperienceConfig.getInstance().isSkillBlock(SkillType.EXCAVATION, blockState.getData()))
  171. return true;
  172. return mcMMO.getModManager().isCustomExcavationBlock(blockState);
  173. }
  174. /**
  175. * Check if a given block is a log
  176. *
  177. * @param blockState
  178. * The {@link BlockState} of the block to check
  179. * @return true if the block is a log, false otherwise
  180. */
  181. public static boolean isLog(BlockState blockState) {
  182. if (ExperienceConfig.getInstance().isSkillBlock(SkillType.WOODCUTTING, blockState.getData()))
  183. return true;
  184. return mcMMO.getModManager().isCustomLog(blockState);
  185. }
  186. /**
  187. * Check if a given block is a leaf
  188. *
  189. * @param blockState
  190. * The {@link BlockState} of the block to check
  191. * @return true if the block is a leaf, false otherwise
  192. */
  193. public static boolean isLeaves(BlockState blockState) {
  194. switch (blockState.getType()) {
  195. case LEAVES :
  196. case LEAVES_2 :
  197. return true;
  198. default :
  199. return mcMMO.getModManager().isCustomLeaf(blockState);
  200. }
  201. }
  202. /**
  203. * Determine if a given block should be affected by Flux Mining
  204. *
  205. * @param blockState
  206. * The {@link BlockState} of the block to check
  207. * @return true if the block should affected by Flux Mining, false otherwise
  208. */
  209. public static boolean affectedByFluxMining(BlockState blockState) {
  210. switch (blockState.getType()) {
  211. case IRON_ORE :
  212. case GOLD_ORE :
  213. return true;
  214. default :
  215. return false;
  216. }
  217. }
  218. /**
  219. * Determine if a given block can activate Herbalism abilities
  220. *
  221. * @param blockState
  222. * The {@link BlockState} of the block to check
  223. * @return true if the block can be activate Herbalism abilities, false
  224. * otherwise
  225. */
  226. public static boolean canActivateHerbalism(BlockState blockState) {
  227. switch (blockState.getType()) {
  228. case DIRT :
  229. case GRASS :
  230. case GRASS_PATH :
  231. case SOIL :
  232. return false;
  233. default :
  234. return true;
  235. }
  236. }
  237. /**
  238. * Determine if a given block should be affected by Block Cracker
  239. *
  240. * @param blockState
  241. * The {@link BlockState} of the block to check
  242. * @return true if the block should affected by Block Cracker, false
  243. * otherwise
  244. */
  245. public static boolean affectedByBlockCracker(BlockState blockState) {
  246. switch (blockState.getType()) {
  247. case SMOOTH_BRICK :
  248. return ((SmoothBrick) blockState.getData()).getMaterial() == Material.STONE;
  249. default :
  250. return false;
  251. }
  252. }
  253. /**
  254. * Determine if a given block can be made into Mycelium
  255. *
  256. * @param blockState
  257. * The {@link BlockState} of the block to check
  258. * @return true if the block can be made into Mycelium, false otherwise
  259. */
  260. public static boolean canMakeShroomy(BlockState blockState) {
  261. switch (blockState.getType()) {
  262. case DIRT :
  263. case GRASS :
  264. case GRASS_PATH :
  265. return true;
  266. default :
  267. return false;
  268. }
  269. }
  270. /**
  271. * Determine if a given block is an mcMMO anvil
  272. *
  273. * @param blockState
  274. * The {@link BlockState} of the block to check
  275. * @return true if the block is an mcMMO anvil, false otherwise
  276. */
  277. public static boolean isMcMMOAnvil(BlockState blockState) {
  278. Material type = blockState.getType();
  279. return type == Repair.anvilMaterial || type == Salvage.anvilMaterial;
  280. }
  281. public static boolean isPistonPiece(BlockState blockState) {
  282. Material type = blockState.getType();
  283. return type == Material.PISTON_MOVING_PIECE || type == Material.AIR;
  284. }
  285. /**
  286. * Get a HashSet containing every transparent block
  287. *
  288. * @return HashSet with the IDs of every transparent block
  289. */
  290. public static HashSet<Material> getTransparentBlocks() {
  291. HashSet<Material> transparentBlocks = new HashSet<Material>();
  292. for (Material material : Material.values()) {
  293. if (material.isTransparent()) {
  294. transparentBlocks.add(material);
  295. }
  296. }
  297. return transparentBlocks;
  298. }
  299. }