2013-03-01 06:52:01 +01:00
|
|
|
package com.gmail.nossr50.util;
|
|
|
|
|
2013-08-17 10:11:46 +02:00
|
|
|
import java.util.HashSet;
|
|
|
|
|
2013-03-01 06:52:01 +01:00
|
|
|
import org.bukkit.CropState;
|
2013-08-19 21:12:08 +02:00
|
|
|
import org.bukkit.Material;
|
2013-04-05 04:24:02 +02:00
|
|
|
import org.bukkit.NetherWartsState;
|
2013-03-01 06:52:01 +01:00
|
|
|
import org.bukkit.block.BlockState;
|
|
|
|
import org.bukkit.material.CocoaPlant;
|
|
|
|
import org.bukkit.material.CocoaPlant.CocoaPlantSize;
|
2013-09-10 15:28:07 +02:00
|
|
|
import org.bukkit.material.Crops;
|
2013-04-05 04:24:02 +02:00
|
|
|
import org.bukkit.material.NetherWarts;
|
2013-09-10 15:28:07 +02:00
|
|
|
import org.bukkit.material.SmoothBrick;
|
2013-03-01 06:52:01 +01:00
|
|
|
|
2014-03-03 18:27:45 +01:00
|
|
|
import com.gmail.nossr50.mcMMO;
|
2013-05-21 17:11:55 +02:00
|
|
|
import com.gmail.nossr50.skills.repair.Repair;
|
2013-03-06 18:31:48 +01:00
|
|
|
import com.gmail.nossr50.skills.salvage.Salvage;
|
2013-03-01 06:52:01 +01:00
|
|
|
|
|
|
|
public final class BlockUtils {
|
|
|
|
private BlockUtils() {}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks to see if a given block awards XP.
|
|
|
|
*
|
|
|
|
* @param blockState The {@link BlockState} of the block to check
|
|
|
|
* @return true if the block awards XP, false otherwise
|
|
|
|
*/
|
|
|
|
public static boolean shouldBeWatched(BlockState blockState) {
|
2013-05-16 14:41:57 +02:00
|
|
|
return affectedByGigaDrillBreaker(blockState) || affectedByGreenTerra(blockState) || affectedBySuperBreaker(blockState) || isLog(blockState);
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if a given block should allow for the activation of abilities
|
|
|
|
*
|
|
|
|
* @param blockState The {@link BlockState} of the block to check
|
|
|
|
* @return true if the block should allow ability activation, false otherwise
|
|
|
|
*/
|
|
|
|
public static boolean canActivateAbilities(BlockState blockState) {
|
|
|
|
switch (blockState.getType()) {
|
|
|
|
case BED_BLOCK:
|
|
|
|
case BREWING_STAND:
|
|
|
|
case BOOKSHELF:
|
|
|
|
case BURNING_FURNACE:
|
|
|
|
case CAKE_BLOCK:
|
|
|
|
case CHEST:
|
|
|
|
case DISPENSER:
|
|
|
|
case ENCHANTMENT_TABLE:
|
|
|
|
case ENDER_CHEST:
|
|
|
|
case FENCE_GATE:
|
2016-03-06 05:36:21 +01:00
|
|
|
case ACACIA_FENCE_GATE:
|
|
|
|
case DARK_OAK_FENCE_GATE:
|
|
|
|
case SPRUCE_FENCE_GATE:
|
|
|
|
case BIRCH_FENCE_GATE:
|
|
|
|
case JUNGLE_FENCE_GATE:
|
2013-03-01 06:52:01 +01:00
|
|
|
case FURNACE:
|
|
|
|
case IRON_DOOR_BLOCK:
|
|
|
|
case JUKEBOX:
|
|
|
|
case LEVER:
|
|
|
|
case NOTE_BLOCK:
|
|
|
|
case STONE_BUTTON:
|
|
|
|
case WOOD_BUTTON:
|
|
|
|
case TRAP_DOOR:
|
|
|
|
case WALL_SIGN:
|
|
|
|
case WOODEN_DOOR:
|
|
|
|
case WORKBENCH:
|
|
|
|
case BEACON:
|
|
|
|
case ANVIL:
|
2013-03-16 17:22:22 +01:00
|
|
|
case DROPPER:
|
|
|
|
case HOPPER:
|
|
|
|
case TRAPPED_CHEST:
|
2014-12-18 07:36:02 +01:00
|
|
|
case IRON_DOOR:
|
2015-07-26 04:29:19 +02:00
|
|
|
case IRON_TRAPDOOR:
|
|
|
|
case ACACIA_DOOR:
|
|
|
|
case SPRUCE_DOOR:
|
|
|
|
case BIRCH_DOOR:
|
|
|
|
case JUNGLE_DOOR:
|
|
|
|
case DARK_OAK_DOOR:
|
2016-03-06 05:36:21 +01:00
|
|
|
case FENCE:
|
2015-07-26 04:29:19 +02:00
|
|
|
case ACACIA_FENCE:
|
|
|
|
case DARK_OAK_FENCE:
|
|
|
|
case BIRCH_FENCE:
|
|
|
|
case JUNGLE_FENCE:
|
2016-03-06 05:36:21 +01:00
|
|
|
case SPRUCE_FENCE:
|
2015-07-26 04:29:19 +02:00
|
|
|
case ARMOR_STAND:
|
2013-03-01 06:52:01 +01:00
|
|
|
return false;
|
|
|
|
|
|
|
|
default:
|
2015-07-26 04:29:19 +02:00
|
|
|
return !isMcMMOAnvil(blockState) && !mcMMO.getModManager().isCustomAbilityBlock(blockState);
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if a given block is an ore
|
|
|
|
*
|
|
|
|
* @param blockState The {@link BlockState} of the block to check
|
|
|
|
* @return true if the block is an ore, false otherwise
|
|
|
|
*/
|
|
|
|
public static boolean isOre(BlockState blockState) {
|
2013-10-31 19:29:06 +01:00
|
|
|
return MaterialUtils.isOre(blockState.getData());
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine if a given block can be made mossy
|
|
|
|
*
|
|
|
|
* @param blockState The {@link BlockState} of the block to check
|
|
|
|
* @return true if the block can be made mossy, false otherwise
|
|
|
|
*/
|
|
|
|
public static boolean canMakeMossy(BlockState blockState) {
|
|
|
|
switch (blockState.getType()) {
|
|
|
|
case COBBLESTONE:
|
|
|
|
case DIRT:
|
2016-03-12 07:12:27 +01:00
|
|
|
case GRASS_PATH:
|
2013-03-01 06:52:01 +01:00
|
|
|
return true;
|
|
|
|
|
|
|
|
case SMOOTH_BRICK:
|
2013-09-05 22:36:02 +02:00
|
|
|
return ((SmoothBrick) blockState.getData()).getMaterial() == Material.STONE;
|
|
|
|
|
2013-03-01 06:52:01 +01:00
|
|
|
case COBBLE_WALL:
|
|
|
|
return blockState.getRawData() == (byte) 0x0;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine if a given block should be affected by Green Terra
|
|
|
|
*
|
|
|
|
* @param blockState The {@link BlockState} of the block to check
|
|
|
|
* @return true if the block should affected by Green Terra, false otherwise
|
|
|
|
*/
|
|
|
|
public static boolean affectedByGreenTerra(BlockState blockState) {
|
|
|
|
switch (blockState.getType()) {
|
|
|
|
case BROWN_MUSHROOM:
|
|
|
|
case CACTUS:
|
2016-03-11 15:20:23 +01:00
|
|
|
case CHORUS_PLANT:
|
|
|
|
case CHORUS_FLOWER:
|
2013-12-02 18:08:12 +01:00
|
|
|
case DOUBLE_PLANT:
|
2013-03-01 06:52:01 +01:00
|
|
|
case MELON_BLOCK:
|
2013-12-02 18:08:12 +01:00
|
|
|
case LONG_GRASS:
|
2013-03-01 06:52:01 +01:00
|
|
|
case PUMPKIN:
|
|
|
|
case RED_MUSHROOM:
|
|
|
|
case RED_ROSE:
|
|
|
|
case SUGAR_CANE_BLOCK:
|
|
|
|
case VINE:
|
|
|
|
case WATER_LILY:
|
|
|
|
case YELLOW_FLOWER:
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case CARROT:
|
|
|
|
case POTATO:
|
2016-06-19 23:33:43 +02:00
|
|
|
case BEETROOT_BLOCK:
|
2013-03-01 06:52:01 +01:00
|
|
|
return blockState.getRawData() == CropState.RIPE.getData();
|
|
|
|
|
2013-09-05 22:36:02 +02:00
|
|
|
case CROPS:
|
|
|
|
return ((Crops) blockState.getData()).getState() == CropState.RIPE;
|
|
|
|
|
2013-03-01 06:52:01 +01:00
|
|
|
case NETHER_WARTS:
|
2013-04-05 04:24:02 +02:00
|
|
|
return ((NetherWarts) blockState.getData()).getState() == NetherWartsState.RIPE;
|
2013-03-01 06:52:01 +01:00
|
|
|
|
|
|
|
case COCOA:
|
|
|
|
return ((CocoaPlant) blockState.getData()).getSize() == CocoaPlantSize.LARGE;
|
|
|
|
|
|
|
|
default:
|
2014-02-03 20:48:43 +01:00
|
|
|
return mcMMO.getModManager().isCustomHerbalismBlock(blockState);
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine if a given block should be affected by Super Breaker
|
|
|
|
*
|
|
|
|
* @param blockState The {@link BlockState} of the block to check
|
|
|
|
* @return true if the block should affected by Super Breaker, false otherwise
|
|
|
|
*/
|
|
|
|
public static Boolean affectedBySuperBreaker(BlockState blockState) {
|
|
|
|
switch (blockState.getType()) {
|
2016-03-11 15:20:23 +01:00
|
|
|
case END_BRICKS:
|
2013-03-01 06:52:01 +01:00
|
|
|
case ENDER_STONE:
|
|
|
|
case GLOWSTONE:
|
2013-12-02 18:08:12 +01:00
|
|
|
case HARD_CLAY:
|
2013-03-01 06:52:01 +01:00
|
|
|
case MOSSY_COBBLESTONE:
|
|
|
|
case NETHERRACK:
|
|
|
|
case OBSIDIAN:
|
2013-12-02 18:08:12 +01:00
|
|
|
case PACKED_ICE:
|
2016-03-11 15:20:23 +01:00
|
|
|
case PURPUR_BLOCK:
|
|
|
|
case PURPUR_PILLAR:
|
|
|
|
case PURPUR_SLAB:
|
|
|
|
case PURPUR_STAIRS:
|
2013-03-01 06:52:01 +01:00
|
|
|
case SANDSTONE:
|
2013-12-02 18:08:12 +01:00
|
|
|
case STAINED_CLAY:
|
2013-03-01 06:52:01 +01:00
|
|
|
case STONE:
|
2015-07-26 04:29:19 +02:00
|
|
|
case PRISMARINE:
|
|
|
|
case RED_SANDSTONE:
|
2016-03-11 15:20:23 +01:00
|
|
|
|
2013-03-01 06:52:01 +01:00
|
|
|
return true;
|
|
|
|
|
|
|
|
default:
|
2015-07-26 04:29:19 +02:00
|
|
|
return isOre(blockState) || mcMMO.getModManager().isCustomMiningBlock(blockState);
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine if a given block should be affected by Giga Drill Breaker
|
|
|
|
*
|
|
|
|
* @param blockState The {@link BlockState} of the block to check
|
|
|
|
* @return true if the block should affected by Giga Drill Breaker, false otherwise
|
|
|
|
*/
|
|
|
|
public static boolean affectedByGigaDrillBreaker(BlockState blockState) {
|
|
|
|
switch (blockState.getType()) {
|
|
|
|
case CLAY:
|
|
|
|
case DIRT:
|
|
|
|
case GRASS:
|
2016-03-12 07:12:27 +01:00
|
|
|
case GRASS_PATH:
|
2013-03-01 06:52:01 +01:00
|
|
|
case GRAVEL:
|
|
|
|
case MYCEL:
|
|
|
|
case SAND:
|
2013-07-11 20:41:23 +02:00
|
|
|
case SNOW:
|
|
|
|
case SNOW_BLOCK:
|
2013-03-01 06:52:01 +01:00
|
|
|
case SOUL_SAND:
|
|
|
|
return true;
|
|
|
|
|
|
|
|
default:
|
2014-02-03 20:48:43 +01:00
|
|
|
return mcMMO.getModManager().isCustomExcavationBlock(blockState);
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if a given block is a log
|
|
|
|
*
|
|
|
|
* @param blockState The {@link BlockState} of the block to check
|
|
|
|
* @return true if the block is a log, false otherwise
|
|
|
|
*/
|
|
|
|
public static boolean isLog(BlockState blockState) {
|
|
|
|
switch (blockState.getType()) {
|
|
|
|
case LOG:
|
2013-12-02 18:08:12 +01:00
|
|
|
case LOG_2:
|
2013-03-01 06:52:01 +01:00
|
|
|
case HUGE_MUSHROOM_1:
|
|
|
|
case HUGE_MUSHROOM_2:
|
|
|
|
return true;
|
|
|
|
|
|
|
|
default:
|
2014-02-03 20:48:43 +01:00
|
|
|
return mcMMO.getModManager().isCustomLog(blockState);
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if a given block is a leaf
|
|
|
|
*
|
|
|
|
* @param blockState The {@link BlockState} of the block to check
|
|
|
|
* @return true if the block is a leaf, false otherwise
|
|
|
|
*/
|
|
|
|
public static boolean isLeaves(BlockState blockState) {
|
|
|
|
switch (blockState.getType()) {
|
|
|
|
case LEAVES:
|
2013-12-02 18:08:12 +01:00
|
|
|
case LEAVES_2:
|
2013-03-01 06:52:01 +01:00
|
|
|
return true;
|
|
|
|
|
|
|
|
default:
|
2014-02-03 20:48:43 +01:00
|
|
|
return mcMMO.getModManager().isCustomLeaf(blockState);
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine if a given block should be affected by Flux Mining
|
|
|
|
*
|
|
|
|
* @param blockState The {@link BlockState} of the block to check
|
|
|
|
* @return true if the block should affected by Flux Mining, false otherwise
|
|
|
|
*/
|
|
|
|
public static boolean affectedByFluxMining(BlockState blockState) {
|
|
|
|
switch (blockState.getType()) {
|
|
|
|
case IRON_ORE:
|
|
|
|
case GOLD_ORE:
|
|
|
|
return true;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine if a given block can activate Herbalism abilities
|
|
|
|
*
|
|
|
|
* @param blockState The {@link BlockState} of the block to check
|
|
|
|
* @return true if the block can be activate Herbalism abilities, false otherwise
|
|
|
|
*/
|
|
|
|
public static boolean canActivateHerbalism(BlockState blockState) {
|
|
|
|
switch (blockState.getType()) {
|
|
|
|
case DIRT:
|
|
|
|
case GRASS:
|
2016-03-12 07:12:27 +01:00
|
|
|
case GRASS_PATH:
|
2013-03-01 06:52:01 +01:00
|
|
|
case SOIL:
|
|
|
|
return false;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine if a given block should be affected by Block Cracker
|
|
|
|
*
|
|
|
|
* @param blockState The {@link BlockState} of the block to check
|
|
|
|
* @return true if the block should affected by Block Cracker, false otherwise
|
|
|
|
*/
|
|
|
|
public static boolean affectedByBlockCracker(BlockState blockState) {
|
|
|
|
switch (blockState.getType()) {
|
|
|
|
case SMOOTH_BRICK:
|
2013-09-05 22:36:02 +02:00
|
|
|
return ((SmoothBrick) blockState.getData()).getMaterial() == Material.STONE;
|
2013-03-01 06:52:01 +01:00
|
|
|
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine if a given block can be made into Mycelium
|
|
|
|
*
|
|
|
|
* @param blockState The {@link BlockState} of the block to check
|
2013-12-02 18:08:12 +01:00
|
|
|
* @return true if the block can be made into Mycelium, false otherwise
|
2013-03-01 06:52:01 +01:00
|
|
|
*/
|
|
|
|
public static boolean canMakeShroomy(BlockState blockState) {
|
|
|
|
switch (blockState.getType()) {
|
|
|
|
case DIRT:
|
|
|
|
case GRASS:
|
2016-03-12 07:12:27 +01:00
|
|
|
case GRASS_PATH:
|
2013-03-01 06:52:01 +01:00
|
|
|
return true;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2013-05-16 14:41:57 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine if a given block is an mcMMO anvil
|
|
|
|
*
|
|
|
|
* @param blockState The {@link BlockState} of the block to check
|
|
|
|
* @return true if the block is an mcMMO anvil, false otherwise
|
|
|
|
*/
|
2013-05-21 17:11:55 +02:00
|
|
|
public static boolean isMcMMOAnvil(BlockState blockState) {
|
2013-09-13 15:12:21 +02:00
|
|
|
Material type = blockState.getType();
|
2013-05-16 14:41:57 +02:00
|
|
|
|
2013-03-06 18:31:48 +01:00
|
|
|
return type == Repair.anvilMaterial || type == Salvage.anvilMaterial;
|
2013-05-16 14:41:57 +02:00
|
|
|
}
|
2013-08-17 10:11:46 +02:00
|
|
|
|
2014-06-15 14:22:32 +02:00
|
|
|
public static boolean isPistonPiece(BlockState blockState) {
|
|
|
|
Material type = blockState.getType();
|
|
|
|
|
|
|
|
return type == Material.PISTON_MOVING_PIECE || type == Material.AIR;
|
|
|
|
}
|
|
|
|
|
2013-08-17 10:11:46 +02:00
|
|
|
/**
|
|
|
|
* Get a HashSet containing every transparent block
|
|
|
|
*
|
|
|
|
* @return HashSet with the IDs of every transparent block
|
|
|
|
*/
|
|
|
|
public static HashSet<Byte> getTransparentBlocks() {
|
2013-08-19 21:12:08 +02:00
|
|
|
HashSet<Byte> transparentBlocks = new HashSet<Byte>();
|
|
|
|
|
|
|
|
for (Material material : Material.values()) {
|
|
|
|
if (material.isTransparent()) {
|
|
|
|
transparentBlocks.add((byte) material.getId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return transparentBlocks;
|
2013-08-17 10:11:46 +02:00
|
|
|
}
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|