BlockChecks.java 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. package com.gmail.nossr50.util;
  2. import org.bukkit.CropState;
  3. import org.bukkit.block.BlockState;
  4. import org.bukkit.material.CocoaPlant;
  5. import org.bukkit.material.CocoaPlant.CocoaPlantSize;
  6. import com.gmail.nossr50.config.Config;
  7. import com.gmail.nossr50.mods.ModChecks;
  8. public final class BlockChecks {
  9. private BlockChecks() {}
  10. /**
  11. * Checks to see if a given block awards XP.
  12. *
  13. * @param blockState The {@link BlockState} of the block to check
  14. * @return true if the block awards XP, false otherwise
  15. */
  16. public static boolean shouldBeWatched(BlockState blockState) {
  17. switch (blockState.getType()) {
  18. case BROWN_MUSHROOM:
  19. case CACTUS:
  20. case CLAY:
  21. case COAL_ORE:
  22. case DIAMOND_ORE:
  23. case DIRT:
  24. case ENDER_STONE:
  25. case GLOWING_REDSTONE_ORE:
  26. case GLOWSTONE:
  27. case GOLD_ORE:
  28. case GRASS:
  29. case GRAVEL:
  30. case IRON_ORE:
  31. case LAPIS_ORE:
  32. case LOG:
  33. case MELON_BLOCK:
  34. case MOSSY_COBBLESTONE:
  35. case MYCEL:
  36. case NETHERRACK:
  37. case OBSIDIAN:
  38. case PUMPKIN:
  39. case RED_MUSHROOM:
  40. case RED_ROSE:
  41. case REDSTONE_ORE:
  42. case SAND:
  43. case SANDSTONE:
  44. case SOUL_SAND:
  45. case STONE:
  46. case SUGAR_CANE_BLOCK:
  47. case VINE:
  48. case WATER_LILY:
  49. case YELLOW_FLOWER:
  50. case COCOA:
  51. case EMERALD_ORE:
  52. case CARROT:
  53. case POTATO:
  54. return true;
  55. default:
  56. return ModChecks.getCustomBlock(blockState) != null;
  57. }
  58. }
  59. /**
  60. * Check if a given block should allow for the activation of abilities
  61. *
  62. * @param blockState The {@link BlockState} of the block to check
  63. * @return true if the block should allow ability activation, false otherwise
  64. */
  65. public static boolean canActivateAbilities(BlockState blockState) {
  66. switch (blockState.getType()) {
  67. case BED_BLOCK:
  68. case BREWING_STAND:
  69. case BOOKSHELF:
  70. case BURNING_FURNACE:
  71. case CAKE_BLOCK:
  72. case CHEST:
  73. case DISPENSER:
  74. case ENCHANTMENT_TABLE:
  75. case ENDER_CHEST:
  76. case FENCE_GATE:
  77. case FURNACE:
  78. case IRON_DOOR_BLOCK:
  79. case JUKEBOX:
  80. case LEVER:
  81. case NOTE_BLOCK:
  82. case STONE_BUTTON:
  83. case WOOD_BUTTON:
  84. case TRAP_DOOR:
  85. case WALL_SIGN:
  86. case WOODEN_DOOR:
  87. case WORKBENCH:
  88. case BEACON:
  89. case ANVIL:
  90. return false;
  91. default:
  92. int blockId = blockState.getTypeId();
  93. if (blockId == Config.getInstance().getRepairAnvilId() || blockId == Config.getInstance().getSalvageAnvilId()) {
  94. return false;
  95. }
  96. if (ModChecks.isCustomAbilityBlock(blockState)) {
  97. return false;
  98. }
  99. return true;
  100. }
  101. }
  102. /**
  103. * Check if a given block is an ore
  104. *
  105. * @param blockState The {@link BlockState} of the block to check
  106. * @return true if the block is an ore, false otherwise
  107. */
  108. public static boolean isOre(BlockState blockState) {
  109. switch (blockState.getType()) {
  110. case COAL_ORE:
  111. case DIAMOND_ORE:
  112. case GLOWING_REDSTONE_ORE:
  113. case GOLD_ORE:
  114. case IRON_ORE:
  115. case LAPIS_ORE:
  116. case REDSTONE_ORE:
  117. case EMERALD_ORE:
  118. return true;
  119. default:
  120. return ModChecks.isCustomOreBlock(blockState);
  121. }
  122. }
  123. /**
  124. * Determine if a given block can be made mossy
  125. *
  126. * @param blockState The {@link BlockState} of the block to check
  127. * @return true if the block can be made mossy, false otherwise
  128. */
  129. public static boolean canMakeMossy(BlockState blockState) {
  130. switch (blockState.getType()) {
  131. case COBBLESTONE:
  132. case DIRT:
  133. return true;
  134. case SMOOTH_BRICK:
  135. case COBBLE_WALL:
  136. return blockState.getRawData() == (byte) 0x0;
  137. default:
  138. return false;
  139. }
  140. }
  141. /**
  142. * Determine if a given block should be affected by Green Terra
  143. *
  144. * @param blockState The {@link BlockState} of the block to check
  145. * @return true if the block should affected by Green Terra, false otherwise
  146. */
  147. public static boolean affectedByGreenTerra(BlockState blockState) {
  148. switch (blockState.getType()) {
  149. case BROWN_MUSHROOM:
  150. case CACTUS:
  151. case MELON_BLOCK:
  152. case PUMPKIN:
  153. case RED_MUSHROOM:
  154. case RED_ROSE:
  155. case SUGAR_CANE_BLOCK:
  156. case VINE:
  157. case WATER_LILY:
  158. case YELLOW_FLOWER:
  159. return true;
  160. case CARROT:
  161. case CROPS:
  162. case POTATO:
  163. return blockState.getRawData() == CropState.RIPE.getData();
  164. case NETHER_WARTS:
  165. return blockState.getRawData() == (byte) 0x3;
  166. case COCOA:
  167. return ((CocoaPlant) blockState.getData()).getSize() == CocoaPlantSize.LARGE;
  168. default:
  169. return ModChecks.isCustomHerbalismBlock(blockState);
  170. }
  171. }
  172. /**
  173. * Determine if a given block should be affected by Super Breaker
  174. *
  175. * @param blockState The {@link BlockState} of the block to check
  176. * @return true if the block should affected by Super Breaker, false otherwise
  177. */
  178. public static Boolean affectedBySuperBreaker(BlockState blockState) {
  179. switch (blockState.getType()) {
  180. case COAL_ORE:
  181. case DIAMOND_ORE:
  182. case ENDER_STONE:
  183. case GLOWING_REDSTONE_ORE:
  184. case GLOWSTONE:
  185. case GOLD_ORE:
  186. case IRON_ORE:
  187. case LAPIS_ORE:
  188. case MOSSY_COBBLESTONE:
  189. case NETHERRACK:
  190. case OBSIDIAN:
  191. case REDSTONE_ORE:
  192. case SANDSTONE:
  193. case STONE:
  194. case EMERALD_ORE:
  195. return true;
  196. default:
  197. return ModChecks.isCustomMiningBlock(blockState);
  198. }
  199. }
  200. /**
  201. * Determine if a given block should be affected by Giga Drill Breaker
  202. *
  203. * @param blockState The {@link BlockState} of the block to check
  204. * @return true if the block should affected by Giga Drill Breaker, false otherwise
  205. */
  206. public static boolean affectedByGigaDrillBreaker(BlockState blockState) {
  207. switch (blockState.getType()) {
  208. case CLAY:
  209. case DIRT:
  210. case GRASS:
  211. case GRAVEL:
  212. case MYCEL:
  213. case SAND:
  214. case SOUL_SAND:
  215. return true;
  216. default:
  217. return ModChecks.isCustomExcavationBlock(blockState);
  218. }
  219. }
  220. /**
  221. * Determine if a given block should be affected by Tree Feller
  222. *
  223. * @param blockState The {@link BlockState} of the block to check
  224. * @return true if the block should affected by Tree Feller, false otherwise
  225. */
  226. public static boolean affectedByTreeFeller(BlockState blockState) {
  227. switch (blockState.getType()) {
  228. case LOG:
  229. case LEAVES:
  230. case HUGE_MUSHROOM_1:
  231. case HUGE_MUSHROOM_2:
  232. return true;
  233. default:
  234. return ModChecks.isCustomWoodcuttingBlock(blockState);
  235. }
  236. }
  237. /**
  238. * Check if a given block is a log
  239. *
  240. * @param blockState The {@link BlockState} of the block to check
  241. * @return true if the block is a log, false otherwise
  242. */
  243. public static boolean isLog(BlockState blockState) {
  244. switch (blockState.getType()) {
  245. case LOG:
  246. case HUGE_MUSHROOM_1:
  247. case HUGE_MUSHROOM_2:
  248. return true;
  249. default:
  250. return ModChecks.isCustomLogBlock(blockState);
  251. }
  252. }
  253. /**
  254. * Check if a given block is a leaf
  255. *
  256. * @param blockState The {@link BlockState} of the block to check
  257. * @return true if the block is a leaf, false otherwise
  258. */
  259. public static boolean isLeaves(BlockState blockState) {
  260. switch (blockState.getType()) {
  261. case LEAVES:
  262. return true;
  263. default:
  264. return ModChecks.isCustomLeafBlock(blockState);
  265. }
  266. }
  267. /**
  268. * Determine if a given block should be affected by Flux Mining
  269. *
  270. * @param blockState The {@link BlockState} of the block to check
  271. * @return true if the block should affected by Flux Mining, false otherwise
  272. */
  273. public static boolean affectedByFluxMining(BlockState blockState) {
  274. switch (blockState.getType()) {
  275. case IRON_ORE:
  276. case GOLD_ORE:
  277. return true;
  278. default:
  279. return false;
  280. }
  281. }
  282. /**
  283. * Determine if a given block can activate Herbalism abilities
  284. *
  285. * @param blockState The {@link BlockState} of the block to check
  286. * @return true if the block can be made mossy, false otherwise
  287. */
  288. public static boolean canActivateHerbalism(BlockState blockState) {
  289. switch (blockState.getType()) {
  290. case DIRT:
  291. case GRASS:
  292. case SOIL:
  293. return false;
  294. default:
  295. return true;
  296. }
  297. }
  298. /**
  299. * Determine if a given block should be affected by Block Cracker
  300. *
  301. * @param blockState The {@link BlockState} of the block to check
  302. * @return true if the block should affected by Block Cracker, false otherwise
  303. */
  304. public static boolean affectedByBlockCracker(BlockState blockState) {
  305. switch (blockState.getType()) {
  306. case SMOOTH_BRICK:
  307. return blockState.getRawData() == (byte) 0x0;
  308. default:
  309. return false;
  310. }
  311. }
  312. }