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;
|
2017-06-10 19:47:20 +02:00
|
|
|
import com.gmail.nossr50.config.experience.ExperienceConfig;
|
|
|
|
import com.gmail.nossr50.datatypes.skills.SkillType;
|
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 {
|
2017-06-10 19:47:20 +02:00
|
|
|
|
2013-03-01 06:52:01 +01:00
|
|
|
private BlockUtils() {}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks to see if a given block awards XP.
|
|
|
|
*
|
2017-06-10 19:47:20 +02:00
|
|
|
* @param blockState
|
|
|
|
* The {@link BlockState} of the block to check
|
2013-03-01 06:52:01 +01:00
|
|
|
* @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
|
|
|
|
*
|
2017-06-10 19:47:20 +02:00
|
|
|
* @param blockState
|
|
|
|
* The {@link BlockState} of the block to check
|
|
|
|
* @return true if the block should allow ability activation, false
|
|
|
|
* otherwise
|
2013-03-01 06:52:01 +01:00
|
|
|
*/
|
|
|
|
public static boolean canActivateAbilities(BlockState blockState) {
|
|
|
|
switch (blockState.getType()) {
|
2017-06-10 19:47:20 +02:00
|
|
|
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 :
|
|
|
|
case ACACIA_FENCE_GATE :
|
|
|
|
case DARK_OAK_FENCE_GATE :
|
|
|
|
case SPRUCE_FENCE_GATE :
|
|
|
|
case BIRCH_FENCE_GATE :
|
|
|
|
case JUNGLE_FENCE_GATE :
|
|
|
|
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 :
|
|
|
|
case DROPPER :
|
|
|
|
case HOPPER :
|
|
|
|
case TRAPPED_CHEST :
|
|
|
|
case IRON_DOOR :
|
|
|
|
case IRON_TRAPDOOR :
|
|
|
|
case ACACIA_DOOR :
|
|
|
|
case SPRUCE_DOOR :
|
|
|
|
case BIRCH_DOOR :
|
|
|
|
case JUNGLE_DOOR :
|
|
|
|
case DARK_OAK_DOOR :
|
|
|
|
case FENCE :
|
|
|
|
case ACACIA_FENCE :
|
|
|
|
case DARK_OAK_FENCE :
|
|
|
|
case BIRCH_FENCE :
|
|
|
|
case JUNGLE_FENCE :
|
|
|
|
case SPRUCE_FENCE :
|
|
|
|
case ARMOR_STAND :
|
2013-03-01 06:52:01 +01:00
|
|
|
return false;
|
|
|
|
|
2017-06-10 19:47:20 +02:00
|
|
|
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
|
|
|
|
*
|
2017-06-10 19:47:20 +02:00
|
|
|
* @param blockState
|
|
|
|
* The {@link BlockState} of the block to check
|
2013-03-01 06:52:01 +01:00
|
|
|
* @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
|
|
|
|
*
|
2017-06-10 19:47:20 +02:00
|
|
|
* @param blockState
|
|
|
|
* The {@link BlockState} of the block to check
|
2013-03-01 06:52:01 +01:00
|
|
|
* @return true if the block can be made mossy, false otherwise
|
|
|
|
*/
|
|
|
|
public static boolean canMakeMossy(BlockState blockState) {
|
|
|
|
switch (blockState.getType()) {
|
2017-06-10 19:47:20 +02:00
|
|
|
case COBBLESTONE :
|
|
|
|
case DIRT :
|
|
|
|
case GRASS_PATH :
|
2013-03-01 06:52:01 +01:00
|
|
|
return true;
|
|
|
|
|
2017-06-10 19:47:20 +02:00
|
|
|
case SMOOTH_BRICK :
|
2013-09-05 22:36:02 +02:00
|
|
|
return ((SmoothBrick) blockState.getData()).getMaterial() == Material.STONE;
|
|
|
|
|
2017-06-10 19:47:20 +02:00
|
|
|
case COBBLE_WALL :
|
2013-03-01 06:52:01 +01:00
|
|
|
return blockState.getRawData() == (byte) 0x0;
|
|
|
|
|
2017-06-10 19:47:20 +02:00
|
|
|
default :
|
2013-03-01 06:52:01 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine if a given block should be affected by Green Terra
|
|
|
|
*
|
2017-06-10 19:47:20 +02:00
|
|
|
* @param blockState
|
|
|
|
* The {@link BlockState} of the block to check
|
2013-03-01 06:52:01 +01:00
|
|
|
* @return true if the block should affected by Green Terra, false otherwise
|
|
|
|
*/
|
|
|
|
public static boolean affectedByGreenTerra(BlockState blockState) {
|
2017-06-10 19:47:20 +02:00
|
|
|
if (ExperienceConfig.getInstance().isSkillBlock(SkillType.HERBALISM, blockState.getData()))
|
|
|
|
return true;
|
2013-03-01 06:52:01 +01:00
|
|
|
|
2017-06-10 19:47:20 +02: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
|
|
|
|
*
|
2017-06-10 19:47:20 +02:00
|
|
|
* @param blockState
|
|
|
|
* The {@link BlockState} of the block to check
|
|
|
|
* @return true if the block should affected by Super Breaker, false
|
|
|
|
* otherwise
|
2013-03-01 06:52:01 +01:00
|
|
|
*/
|
|
|
|
public static Boolean affectedBySuperBreaker(BlockState blockState) {
|
2017-06-10 19:47:20 +02:00
|
|
|
if (ExperienceConfig.getInstance().isSkillBlock(SkillType.MINING, blockState.getData()))
|
|
|
|
return true;
|
2013-03-01 06:52:01 +01:00
|
|
|
|
2017-06-10 19:47:20 +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
|
|
|
|
*
|
2017-06-10 19:47:20 +02:00
|
|
|
* @param blockState
|
|
|
|
* The {@link BlockState} of the block to check
|
|
|
|
* @return true if the block should affected by Giga Drill Breaker, false
|
|
|
|
* otherwise
|
2013-03-01 06:52:01 +01:00
|
|
|
*/
|
|
|
|
public static boolean affectedByGigaDrillBreaker(BlockState blockState) {
|
2017-06-10 19:47:20 +02:00
|
|
|
if (ExperienceConfig.getInstance().isSkillBlock(SkillType.EXCAVATION, blockState.getData()))
|
|
|
|
return true;
|
|
|
|
return mcMMO.getModManager().isCustomExcavationBlock(blockState);
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if a given block is a log
|
|
|
|
*
|
2017-06-10 19:47:20 +02:00
|
|
|
* @param blockState
|
|
|
|
* The {@link BlockState} of the block to check
|
2013-03-01 06:52:01 +01:00
|
|
|
* @return true if the block is a log, false otherwise
|
|
|
|
*/
|
|
|
|
public static boolean isLog(BlockState blockState) {
|
2017-06-10 19:47:20 +02:00
|
|
|
if (ExperienceConfig.getInstance().isSkillBlock(SkillType.WOODCUTTING, blockState.getData()))
|
|
|
|
return true;
|
|
|
|
return mcMMO.getModManager().isCustomLog(blockState);
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if a given block is a leaf
|
|
|
|
*
|
2017-06-10 19:47:20 +02:00
|
|
|
* @param blockState
|
|
|
|
* The {@link BlockState} of the block to check
|
2013-03-01 06:52:01 +01:00
|
|
|
* @return true if the block is a leaf, false otherwise
|
|
|
|
*/
|
|
|
|
public static boolean isLeaves(BlockState blockState) {
|
|
|
|
switch (blockState.getType()) {
|
2017-06-10 19:47:20 +02:00
|
|
|
case LEAVES :
|
|
|
|
case LEAVES_2 :
|
2013-03-01 06:52:01 +01:00
|
|
|
return true;
|
|
|
|
|
2017-06-10 19:47:20 +02:00
|
|
|
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
|
|
|
|
*
|
2017-06-10 19:47:20 +02:00
|
|
|
* @param blockState
|
|
|
|
* The {@link BlockState} of the block to check
|
2013-03-01 06:52:01 +01:00
|
|
|
* @return true if the block should affected by Flux Mining, false otherwise
|
|
|
|
*/
|
|
|
|
public static boolean affectedByFluxMining(BlockState blockState) {
|
|
|
|
switch (blockState.getType()) {
|
2017-06-10 19:47:20 +02:00
|
|
|
case IRON_ORE :
|
|
|
|
case GOLD_ORE :
|
2013-03-01 06:52:01 +01:00
|
|
|
return true;
|
|
|
|
|
2017-06-10 19:47:20 +02:00
|
|
|
default :
|
2013-03-01 06:52:01 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine if a given block can activate Herbalism abilities
|
|
|
|
*
|
2017-06-10 19:47:20 +02:00
|
|
|
* @param blockState
|
|
|
|
* The {@link BlockState} of the block to check
|
|
|
|
* @return true if the block can be activate Herbalism abilities, false
|
|
|
|
* otherwise
|
2013-03-01 06:52:01 +01:00
|
|
|
*/
|
|
|
|
public static boolean canActivateHerbalism(BlockState blockState) {
|
|
|
|
switch (blockState.getType()) {
|
2017-06-10 19:47:20 +02:00
|
|
|
case DIRT :
|
|
|
|
case GRASS :
|
|
|
|
case GRASS_PATH :
|
|
|
|
case SOIL :
|
2013-03-01 06:52:01 +01:00
|
|
|
return false;
|
|
|
|
|
2017-06-10 19:47:20 +02:00
|
|
|
default :
|
2013-03-01 06:52:01 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine if a given block should be affected by Block Cracker
|
|
|
|
*
|
2017-06-10 19:47:20 +02:00
|
|
|
* @param blockState
|
|
|
|
* The {@link BlockState} of the block to check
|
|
|
|
* @return true if the block should affected by Block Cracker, false
|
|
|
|
* otherwise
|
2013-03-01 06:52:01 +01:00
|
|
|
*/
|
|
|
|
public static boolean affectedByBlockCracker(BlockState blockState) {
|
|
|
|
switch (blockState.getType()) {
|
2017-06-10 19:47:20 +02:00
|
|
|
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
|
|
|
|
2017-06-10 19:47:20 +02:00
|
|
|
default :
|
2013-03-01 06:52:01 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine if a given block can be made into Mycelium
|
|
|
|
*
|
2017-06-10 19:47:20 +02:00
|
|
|
* @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()) {
|
2017-06-10 19:47:20 +02:00
|
|
|
case DIRT :
|
|
|
|
case GRASS :
|
|
|
|
case GRASS_PATH :
|
2013-03-01 06:52:01 +01:00
|
|
|
return true;
|
|
|
|
|
2017-06-10 19:47:20 +02:00
|
|
|
default :
|
2013-03-01 06:52:01 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2013-05-16 14:41:57 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine if a given block is an mcMMO anvil
|
|
|
|
*
|
2017-06-10 19:47:20 +02:00
|
|
|
* @param blockState
|
|
|
|
* The {@link BlockState} of the block to check
|
2013-05-16 14:41:57 +02:00
|
|
|
* @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
|
|
|
|
*/
|
2017-08-05 20:50:24 +02:00
|
|
|
public static HashSet<Material> getTransparentBlocks() {
|
|
|
|
HashSet<Material> transparentBlocks = new HashSet<Material>();
|
2013-08-19 21:12:08 +02:00
|
|
|
|
|
|
|
for (Material material : Material.values()) {
|
|
|
|
if (material.isTransparent()) {
|
2017-08-05 20:53:38 +02:00
|
|
|
transparentBlocks.add(material);
|
2013-08-19 21:12:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return transparentBlocks;
|
2013-08-17 10:11:46 +02:00
|
|
|
}
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|