BlockUtils.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. package com.gmail.nossr50.util;
  2. import com.gmail.nossr50.config.experience.ExperienceConfig;
  3. import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
  4. import com.gmail.nossr50.mcMMO;
  5. import com.gmail.nossr50.skills.repair.Repair;
  6. import com.gmail.nossr50.skills.salvage.Salvage;
  7. import org.bukkit.Material;
  8. import org.bukkit.block.BlockState;
  9. import org.bukkit.block.data.Ageable;
  10. import org.bukkit.block.data.BlockData;
  11. import java.util.HashSet;
  12. public final class BlockUtils {
  13. private BlockUtils() {}
  14. /**
  15. * Checks to see if a given block awards XP.
  16. *
  17. * @param blockState
  18. * The {@link BlockState} of the block to check
  19. * @return true if the block awards XP, false otherwise
  20. */
  21. public static boolean shouldBeWatched(BlockState blockState) {
  22. return affectedByGigaDrillBreaker(blockState) || affectedByGreenTerra(blockState) || affectedBySuperBreaker(blockState) || isLog(blockState);
  23. }
  24. /**
  25. * Check if a given block should allow for the activation of abilities
  26. *
  27. * @param blockState
  28. * The {@link BlockState} of the block to check
  29. * @return true if the block should allow ability activation, false
  30. * otherwise
  31. */
  32. public static boolean canActivateAbilities(BlockState blockState) {
  33. switch (blockState.getType()) {
  34. case BLACK_BED:
  35. case BLUE_BED:
  36. case BROWN_BED:
  37. case CYAN_BED:
  38. case GRAY_BED:
  39. case GREEN_BED:
  40. case LIGHT_BLUE_BED:
  41. case LIGHT_GRAY_BED:
  42. case LIME_BED:
  43. case MAGENTA_BED:
  44. case ORANGE_BED:
  45. case PINK_BED:
  46. case PURPLE_BED:
  47. case RED_BED:
  48. case WHITE_BED:
  49. case YELLOW_BED:
  50. case BREWING_STAND :
  51. case BOOKSHELF :
  52. case CAKE:
  53. case CHEST :
  54. case DISPENSER :
  55. case ENCHANTING_TABLE:
  56. case ENDER_CHEST :
  57. case OAK_FENCE_GATE:
  58. case ACACIA_FENCE_GATE :
  59. case DARK_OAK_FENCE_GATE :
  60. case SPRUCE_FENCE_GATE :
  61. case BIRCH_FENCE_GATE :
  62. case JUNGLE_FENCE_GATE :
  63. case FURNACE :
  64. case JUKEBOX :
  65. case LEVER :
  66. case NOTE_BLOCK :
  67. case STONE_BUTTON :
  68. case OAK_BUTTON:
  69. case BIRCH_BUTTON:
  70. case ACACIA_BUTTON:
  71. case DARK_OAK_BUTTON:
  72. case JUNGLE_BUTTON:
  73. case SPRUCE_BUTTON:
  74. case ACACIA_TRAPDOOR:
  75. case BIRCH_TRAPDOOR:
  76. case DARK_OAK_TRAPDOOR:
  77. case JUNGLE_TRAPDOOR:
  78. case OAK_TRAPDOOR:
  79. case SPRUCE_TRAPDOOR:
  80. case WALL_SIGN :
  81. case CRAFTING_TABLE:
  82. case BEACON :
  83. case ANVIL :
  84. case DROPPER :
  85. case HOPPER :
  86. case TRAPPED_CHEST :
  87. case IRON_DOOR :
  88. case IRON_TRAPDOOR :
  89. case OAK_DOOR:
  90. case ACACIA_DOOR :
  91. case SPRUCE_DOOR :
  92. case BIRCH_DOOR :
  93. case JUNGLE_DOOR :
  94. case DARK_OAK_DOOR :
  95. case OAK_FENCE:
  96. case ACACIA_FENCE :
  97. case DARK_OAK_FENCE :
  98. case BIRCH_FENCE :
  99. case JUNGLE_FENCE :
  100. case SPRUCE_FENCE :
  101. case ARMOR_STAND :
  102. case BLACK_SHULKER_BOX :
  103. case BLUE_SHULKER_BOX :
  104. case BROWN_SHULKER_BOX :
  105. case CYAN_SHULKER_BOX :
  106. case GRAY_SHULKER_BOX :
  107. case GREEN_SHULKER_BOX :
  108. case LIGHT_BLUE_SHULKER_BOX :
  109. case LIME_SHULKER_BOX :
  110. case MAGENTA_SHULKER_BOX :
  111. case ORANGE_SHULKER_BOX :
  112. case PINK_SHULKER_BOX :
  113. case PURPLE_SHULKER_BOX :
  114. case RED_SHULKER_BOX :
  115. case LIGHT_GRAY_SHULKER_BOX:
  116. case WHITE_SHULKER_BOX :
  117. case YELLOW_SHULKER_BOX :
  118. return false;
  119. default :
  120. return !isMcMMOAnvil(blockState) && !mcMMO.getModManager().isCustomAbilityBlock(blockState);
  121. }
  122. }
  123. /**
  124. * Check if a given block is an ore
  125. *
  126. * @param blockState
  127. * The {@link BlockState} of the block to check
  128. * @return true if the block is an ore, false otherwise
  129. */
  130. public static boolean isOre(BlockState blockState) {
  131. return MaterialUtils.isOre(blockState.getType());
  132. }
  133. /**
  134. * Determine if a given block can be made mossy
  135. *
  136. * @param blockState
  137. * The {@link BlockState} of the block to check
  138. * @return true if the block can be made mossy, false otherwise
  139. */
  140. public static boolean canMakeMossy(BlockState blockState) {
  141. switch (blockState.getType()) {
  142. case COBBLESTONE :
  143. case DIRT :
  144. case GRASS_PATH :
  145. return true;
  146. case STONE_BRICKS:
  147. return true;
  148. case COBBLESTONE_WALL:
  149. return true;
  150. default :
  151. return false;
  152. }
  153. }
  154. /**
  155. * Determine if a given block should be affected by Green Terra
  156. *
  157. * @param blockState
  158. * The {@link BlockState} of the block to check
  159. * @return true if the block should affected by Green Terra, false otherwise
  160. */
  161. public static boolean affectedByGreenTerra(BlockState blockState) {
  162. if (ExperienceConfig.getInstance().doesBlockGiveSkillXP(PrimarySkillType.HERBALISM, blockState.getBlockData())) {
  163. return true;
  164. }
  165. return mcMMO.getModManager().isCustomHerbalismBlock(blockState);
  166. }
  167. /**
  168. * Determine if a given block should be affected by Super Breaker
  169. *
  170. * @param blockState
  171. * The {@link BlockState} of the block to check
  172. * @return true if the block should affected by Super Breaker, false
  173. * otherwise
  174. */
  175. public static Boolean affectedBySuperBreaker(BlockState blockState) {
  176. if (ExperienceConfig.getInstance().doesBlockGiveSkillXP(PrimarySkillType.MINING, blockState.getBlockData()))
  177. return true;
  178. return isOre(blockState) || mcMMO.getModManager().isCustomMiningBlock(blockState);
  179. }
  180. /**
  181. * Determine if a given block should be affected by Giga Drill Breaker
  182. *
  183. * @param blockState
  184. * The {@link BlockState} of the block to check
  185. * @return true if the block should affected by Giga Drill Breaker, false
  186. * otherwise
  187. */
  188. public static boolean affectedByGigaDrillBreaker(BlockState blockState) {
  189. if (ExperienceConfig.getInstance().doesBlockGiveSkillXP(PrimarySkillType.EXCAVATION, blockState.getBlockData()))
  190. return true;
  191. return mcMMO.getModManager().isCustomExcavationBlock(blockState);
  192. }
  193. /**
  194. * Check if a given block is a log
  195. *
  196. * @param blockState
  197. * The {@link BlockState} of the block to check
  198. * @return true if the block is a log, false otherwise
  199. */
  200. public static boolean isLog(BlockState blockState) {
  201. if (ExperienceConfig.getInstance().doesBlockGiveSkillXP(PrimarySkillType.WOODCUTTING, blockState.getBlockData()))
  202. return true;
  203. return mcMMO.getModManager().isCustomLog(blockState);
  204. }
  205. /**
  206. * Check if a given block is a leaf
  207. *
  208. * @param blockState
  209. * The {@link BlockState} of the block to check
  210. * @return true if the block is a leaf, false otherwise
  211. */
  212. public static boolean isLeaves(BlockState blockState) {
  213. switch (blockState.getType()) {
  214. case OAK_LEAVES:
  215. case ACACIA_LEAVES:
  216. case BIRCH_LEAVES:
  217. case DARK_OAK_LEAVES:
  218. case JUNGLE_LEAVES:
  219. case SPRUCE_LEAVES:
  220. return true;
  221. default :
  222. return mcMMO.getModManager().isCustomLeaf(blockState);
  223. }
  224. }
  225. /**
  226. * Determine if a given block should be affected by Flux Mining
  227. *
  228. * @param blockState
  229. * The {@link BlockState} of the block to check
  230. * @return true if the block should affected by Flux Mining, false otherwise
  231. */
  232. public static boolean affectedByFluxMining(BlockState blockState) {
  233. switch (blockState.getType()) {
  234. case IRON_ORE :
  235. case GOLD_ORE :
  236. return true;
  237. default :
  238. return false;
  239. }
  240. }
  241. /**
  242. * Determine if a given block can activate Herbalism abilities
  243. *
  244. * @param blockState
  245. * The {@link BlockState} of the block to check
  246. * @return true if the block can be activate Herbalism abilities, false
  247. * otherwise
  248. */
  249. public static boolean canActivateHerbalism(BlockState blockState) {
  250. switch (blockState.getType()) {
  251. case DIRT :
  252. case GRASS :
  253. case GRASS_PATH :
  254. case FARMLAND:
  255. return false;
  256. default :
  257. return true;
  258. }
  259. }
  260. /**
  261. * Determine if a given block should be affected by Block Cracker
  262. *
  263. * @param blockState
  264. * The {@link BlockState} of the block to check
  265. * @return true if the block should affected by Block Cracker, false
  266. * otherwise
  267. */
  268. public static boolean affectedByBlockCracker(BlockState blockState) {
  269. switch (blockState.getType()) {
  270. case STONE_BRICKS:
  271. return true;
  272. default :
  273. return false;
  274. }
  275. }
  276. /**
  277. * Determine if a given block can be made into Mycelium
  278. *
  279. * @param blockState
  280. * The {@link BlockState} of the block to check
  281. * @return true if the block can be made into Mycelium, false otherwise
  282. */
  283. public static boolean canMakeShroomy(BlockState blockState) {
  284. switch (blockState.getType()) {
  285. case DIRT :
  286. case GRASS :
  287. case GRASS_PATH :
  288. return true;
  289. default :
  290. return false;
  291. }
  292. }
  293. /**
  294. * Determine if a given block is an mcMMO anvil
  295. *
  296. * @param blockState
  297. * The {@link BlockState} of the block to check
  298. * @return true if the block is an mcMMO anvil, false otherwise
  299. */
  300. public static boolean isMcMMOAnvil(BlockState blockState) {
  301. Material type = blockState.getType();
  302. return type == Repair.anvilMaterial || type == Salvage.anvilMaterial;
  303. }
  304. public static boolean isPistonPiece(BlockState blockState) {
  305. Material type = blockState.getType();
  306. return type == Material.MOVING_PISTON || type == Material.AIR;
  307. }
  308. /**
  309. * Get a HashSet containing every transparent block
  310. *
  311. * @return HashSet with the IDs of every transparent block
  312. */
  313. public static HashSet<Material> getTransparentBlocks() {
  314. HashSet<Material> transparentBlocks = new HashSet<Material>();
  315. for (Material material : Material.values()) {
  316. if (material.isTransparent()) {
  317. transparentBlocks.add(material);
  318. }
  319. }
  320. return transparentBlocks;
  321. }
  322. public static boolean isFullyGrown(BlockState blockState) {
  323. BlockData data = blockState.getBlockData();
  324. if (data.getMaterial() == Material.CACTUS || data.getMaterial() == Material.SUGAR_CANE)
  325. return true;
  326. if (data instanceof Ageable)
  327. {
  328. Ageable ageable = (Ageable) data;
  329. return ageable.getAge() == ageable.getMaximumAge();
  330. }
  331. return true;
  332. }
  333. }