2
0

BlockUtils.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  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.skills.repair.Repair;
  14. import com.gmail.nossr50.skills.salvage.Salvage;
  15. public final class BlockUtils {
  16. private BlockUtils() {}
  17. /**
  18. * Checks to see if a given block awards XP.
  19. *
  20. * @param blockState The {@link BlockState} of the block to check
  21. * @return true if the block awards XP, false otherwise
  22. */
  23. public static boolean shouldBeWatched(BlockState blockState) {
  24. return affectedByGigaDrillBreaker(blockState) || affectedByGreenTerra(blockState) || affectedBySuperBreaker(blockState) || isLog(blockState);
  25. }
  26. /**
  27. * Check if a given block should allow for the activation of abilities
  28. *
  29. * @param blockState The {@link BlockState} of the block to check
  30. * @return true if the block should allow ability activation, false otherwise
  31. */
  32. public static boolean canActivateAbilities(BlockState blockState) {
  33. switch (blockState.getType()) {
  34. case BED_BLOCK:
  35. case BREWING_STAND:
  36. case BOOKSHELF:
  37. case BURNING_FURNACE:
  38. case CAKE_BLOCK:
  39. case CHEST:
  40. case DISPENSER:
  41. case ENCHANTMENT_TABLE:
  42. case ENDER_CHEST:
  43. case FENCE_GATE:
  44. case ACACIA_FENCE_GATE:
  45. case DARK_OAK_FENCE_GATE:
  46. case SPRUCE_FENCE_GATE:
  47. case BIRCH_FENCE_GATE:
  48. case JUNGLE_FENCE_GATE:
  49. case FURNACE:
  50. case IRON_DOOR_BLOCK:
  51. case JUKEBOX:
  52. case LEVER:
  53. case NOTE_BLOCK:
  54. case STONE_BUTTON:
  55. case WOOD_BUTTON:
  56. case TRAP_DOOR:
  57. case WALL_SIGN:
  58. case WOODEN_DOOR:
  59. case WORKBENCH:
  60. case BEACON:
  61. case ANVIL:
  62. case DROPPER:
  63. case HOPPER:
  64. case TRAPPED_CHEST:
  65. case IRON_DOOR:
  66. case IRON_TRAPDOOR:
  67. case ACACIA_DOOR:
  68. case SPRUCE_DOOR:
  69. case BIRCH_DOOR:
  70. case JUNGLE_DOOR:
  71. case DARK_OAK_DOOR:
  72. case FENCE:
  73. case ACACIA_FENCE:
  74. case DARK_OAK_FENCE:
  75. case BIRCH_FENCE:
  76. case JUNGLE_FENCE:
  77. case SPRUCE_FENCE:
  78. case ARMOR_STAND:
  79. return false;
  80. default:
  81. return !isMcMMOAnvil(blockState) && !mcMMO.getModManager().isCustomAbilityBlock(blockState);
  82. }
  83. }
  84. /**
  85. * Check if a given block is an ore
  86. *
  87. * @param blockState The {@link BlockState} of the block to check
  88. * @return true if the block is an ore, false otherwise
  89. */
  90. public static boolean isOre(BlockState blockState) {
  91. return MaterialUtils.isOre(blockState.getData());
  92. }
  93. /**
  94. * Determine if a given block can be made mossy
  95. *
  96. * @param blockState The {@link BlockState} of the block to check
  97. * @return true if the block can be made mossy, false otherwise
  98. */
  99. public static boolean canMakeMossy(BlockState blockState) {
  100. switch (blockState.getType()) {
  101. case COBBLESTONE:
  102. case DIRT:
  103. return true;
  104. case SMOOTH_BRICK:
  105. return ((SmoothBrick) blockState.getData()).getMaterial() == Material.STONE;
  106. case COBBLE_WALL:
  107. return blockState.getRawData() == (byte) 0x0;
  108. default:
  109. return false;
  110. }
  111. }
  112. /**
  113. * Determine if a given block should be affected by Green Terra
  114. *
  115. * @param blockState The {@link BlockState} of the block to check
  116. * @return true if the block should affected by Green Terra, false otherwise
  117. */
  118. public static boolean affectedByGreenTerra(BlockState blockState) {
  119. switch (blockState.getType()) {
  120. case BROWN_MUSHROOM:
  121. case CACTUS:
  122. case CHORUS_PLANT:
  123. case CHORUS_FLOWER:
  124. case DOUBLE_PLANT:
  125. case MELON_BLOCK:
  126. case LONG_GRASS:
  127. case PUMPKIN:
  128. case RED_MUSHROOM:
  129. case RED_ROSE:
  130. case SUGAR_CANE_BLOCK:
  131. case VINE:
  132. case WATER_LILY:
  133. case YELLOW_FLOWER:
  134. return true;
  135. case CARROT:
  136. case POTATO:
  137. return blockState.getRawData() == CropState.RIPE.getData();
  138. case CROPS:
  139. return ((Crops) blockState.getData()).getState() == CropState.RIPE;
  140. case NETHER_WARTS:
  141. return ((NetherWarts) blockState.getData()).getState() == NetherWartsState.RIPE;
  142. case COCOA:
  143. return ((CocoaPlant) blockState.getData()).getSize() == CocoaPlantSize.LARGE;
  144. default:
  145. return mcMMO.getModManager().isCustomHerbalismBlock(blockState);
  146. }
  147. }
  148. /**
  149. * Determine if a given block should be affected by Super Breaker
  150. *
  151. * @param blockState The {@link BlockState} of the block to check
  152. * @return true if the block should affected by Super Breaker, false otherwise
  153. */
  154. public static Boolean affectedBySuperBreaker(BlockState blockState) {
  155. switch (blockState.getType()) {
  156. case END_BRICKS:
  157. case ENDER_STONE:
  158. case GLOWSTONE:
  159. case HARD_CLAY:
  160. case MOSSY_COBBLESTONE:
  161. case NETHERRACK:
  162. case OBSIDIAN:
  163. case PACKED_ICE:
  164. case PURPUR_BLOCK:
  165. case PURPUR_PILLAR:
  166. case PURPUR_SLAB:
  167. case PURPUR_STAIRS:
  168. case SANDSTONE:
  169. case STAINED_CLAY:
  170. case STONE:
  171. case PRISMARINE:
  172. case RED_SANDSTONE:
  173. return true;
  174. default:
  175. return isOre(blockState) || mcMMO.getModManager().isCustomMiningBlock(blockState);
  176. }
  177. }
  178. /**
  179. * Determine if a given block should be affected by Giga Drill Breaker
  180. *
  181. * @param blockState The {@link BlockState} of the block to check
  182. * @return true if the block should affected by Giga Drill Breaker, false otherwise
  183. */
  184. public static boolean affectedByGigaDrillBreaker(BlockState blockState) {
  185. switch (blockState.getType()) {
  186. case CLAY:
  187. case DIRT:
  188. case GRASS:
  189. case GRAVEL:
  190. case MYCEL:
  191. case SAND:
  192. case SNOW:
  193. case SNOW_BLOCK:
  194. case SOUL_SAND:
  195. return true;
  196. default:
  197. return mcMMO.getModManager().isCustomExcavationBlock(blockState);
  198. }
  199. }
  200. /**
  201. * Check if a given block is a log
  202. *
  203. * @param blockState The {@link BlockState} of the block to check
  204. * @return true if the block is a log, false otherwise
  205. */
  206. public static boolean isLog(BlockState blockState) {
  207. switch (blockState.getType()) {
  208. case LOG:
  209. case LOG_2:
  210. case HUGE_MUSHROOM_1:
  211. case HUGE_MUSHROOM_2:
  212. return true;
  213. default:
  214. return mcMMO.getModManager().isCustomLog(blockState);
  215. }
  216. }
  217. /**
  218. * Check if a given block is a leaf
  219. *
  220. * @param blockState The {@link BlockState} of the block to check
  221. * @return true if the block is a leaf, false otherwise
  222. */
  223. public static boolean isLeaves(BlockState blockState) {
  224. switch (blockState.getType()) {
  225. case LEAVES:
  226. case LEAVES_2:
  227. return true;
  228. default:
  229. return mcMMO.getModManager().isCustomLeaf(blockState);
  230. }
  231. }
  232. /**
  233. * Determine if a given block should be affected by Flux Mining
  234. *
  235. * @param blockState The {@link BlockState} of the block to check
  236. * @return true if the block should affected by Flux Mining, false otherwise
  237. */
  238. public static boolean affectedByFluxMining(BlockState blockState) {
  239. switch (blockState.getType()) {
  240. case IRON_ORE:
  241. case GOLD_ORE:
  242. return true;
  243. default:
  244. return false;
  245. }
  246. }
  247. /**
  248. * Determine if a given block can activate Herbalism abilities
  249. *
  250. * @param blockState The {@link BlockState} of the block to check
  251. * @return true if the block can be activate Herbalism abilities, false otherwise
  252. */
  253. public static boolean canActivateHerbalism(BlockState blockState) {
  254. switch (blockState.getType()) {
  255. case DIRT:
  256. case GRASS:
  257. case SOIL:
  258. return false;
  259. default:
  260. return true;
  261. }
  262. }
  263. /**
  264. * Determine if a given block should be affected by Block Cracker
  265. *
  266. * @param blockState The {@link BlockState} of the block to check
  267. * @return true if the block should affected by Block Cracker, false otherwise
  268. */
  269. public static boolean affectedByBlockCracker(BlockState blockState) {
  270. switch (blockState.getType()) {
  271. case SMOOTH_BRICK:
  272. return ((SmoothBrick) blockState.getData()).getMaterial() == Material.STONE;
  273. default:
  274. return false;
  275. }
  276. }
  277. /**
  278. * Determine if a given block can be made into Mycelium
  279. *
  280. * @param blockState 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. return true;
  288. default:
  289. return false;
  290. }
  291. }
  292. /**
  293. * Determine if a given block is an mcMMO anvil
  294. *
  295. * @param blockState The {@link BlockState} of the block to check
  296. * @return true if the block is an mcMMO anvil, false otherwise
  297. */
  298. public static boolean isMcMMOAnvil(BlockState blockState) {
  299. Material type = blockState.getType();
  300. return type == Repair.anvilMaterial || type == Salvage.anvilMaterial;
  301. }
  302. public static boolean isPistonPiece(BlockState blockState) {
  303. Material type = blockState.getType();
  304. return type == Material.PISTON_MOVING_PIECE || type == Material.AIR;
  305. }
  306. /**
  307. * Get a HashSet containing every transparent block
  308. *
  309. * @return HashSet with the IDs of every transparent block
  310. */
  311. public static HashSet<Byte> getTransparentBlocks() {
  312. HashSet<Byte> transparentBlocks = new HashSet<Byte>();
  313. for (Material material : Material.values()) {
  314. if (material.isTransparent()) {
  315. transparentBlocks.add((byte) material.getId());
  316. }
  317. }
  318. return transparentBlocks;
  319. }
  320. }