mcMMO/src/main/java/com/gmail/nossr50/util/BlockChecks.java

308 lines
8.1 KiB
Java
Raw Normal View History

2012-04-27 11:47:11 +02:00
package com.gmail.nossr50.util;
2012-05-18 17:15:30 +02:00
import org.bukkit.CropState;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.inventory.ItemStack;
2012-12-25 07:01:10 +01:00
import org.bukkit.material.MaterialData;
2012-04-27 11:47:11 +02:00
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.config.mods.CustomBlocksConfig;
2012-04-27 11:47:11 +02:00
public class BlockChecks {
private static Config configInstance = Config.getInstance();
private static boolean customBlocksEnabled = configInstance.getBlockModsEnabled();
2012-04-27 11:47:11 +02:00
/**
* Checks to see if a block type awards XP.
*
* @param block Block to check
2012-04-27 11:47:11 +02:00
* @return true if the block type awards XP, false otherwise
*/
public static boolean shouldBeWatched(Block block) {
switch (block.getType()) {
2012-04-27 11:47:11 +02:00
case BROWN_MUSHROOM:
case CACTUS:
case CLAY:
case COAL_ORE:
case DIAMOND_ORE:
case DIRT:
case ENDER_STONE:
case GLOWING_REDSTONE_ORE:
case GLOWSTONE:
case GOLD_ORE:
case GRASS:
case GRAVEL:
case IRON_ORE:
case LAPIS_ORE:
case LOG:
case MELON_BLOCK:
case MOSSY_COBBLESTONE:
case MYCEL:
case NETHERRACK:
case OBSIDIAN:
case PUMPKIN:
case RED_MUSHROOM:
case RED_ROSE:
case REDSTONE_ORE:
case SAND:
case SANDSTONE:
case SOUL_SAND:
case STONE:
case SUGAR_CANE_BLOCK:
case VINE:
case WATER_LILY:
case YELLOW_FLOWER:
case COCOA:
case EMERALD_ORE:
case CARROT:
case POTATO:
2012-04-27 11:47:11 +02:00
return true;
default:
ItemStack item = (new MaterialData(block.getTypeId(), block.getData())).toItemStack(1);
2012-12-25 07:01:10 +01:00
if (customBlocksEnabled && CustomBlocksConfig.getInstance().customItems.contains(item)) {
return true;
}
2013-01-10 04:43:21 +01:00
return false;
2012-04-27 11:47:11 +02:00
}
}
/**
* Check if a block should allow for the activation of abilities.
*
* @param block Block to check
2012-04-27 11:47:11 +02:00
* @return true if the block should allow ability activation, false otherwise
*/
public static boolean abilityBlockCheck(Block block) {
ItemStack item = (new MaterialData(block.getTypeId(), block.getData())).toItemStack(1);
2012-12-25 07:01:10 +01:00
if (customBlocksEnabled && CustomBlocksConfig.getInstance().customAbilityBlocks.contains(item)) {
2012-07-03 03:05:55 +02:00
return false;
}
switch (block.getType()) {
2012-04-27 11:47:11 +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:
2012-04-27 11:47:11 +02:00
case FENCE_GATE:
case FURNACE:
case IRON_DOOR_BLOCK:
case JUKEBOX:
case LEVER:
case NOTE_BLOCK:
case STONE_BUTTON:
case WOOD_BUTTON:
2012-04-27 11:47:11 +02:00
case TRAP_DOOR:
case WALL_SIGN:
case WOODEN_DOOR:
case WORKBENCH:
case BEACON:
case ANVIL:
2012-04-27 11:47:11 +02:00
return false;
default:
if (block.getTypeId() == Config.getInstance().getRepairAnvilId() || block.getTypeId() == Config.getInstance().getSalvageAnvilId()) {
2012-07-03 03:05:55 +02:00
return false;
}
2013-01-10 04:43:21 +01:00
return true;
2012-04-27 11:47:11 +02:00
}
}
/**
* Check if a block type is an ore.
*
* @param block Block to check
2012-04-27 11:47:11 +02:00
* @return true if the Block is an ore, false otherwise
*/
public static boolean isOre(Block block) {
switch (block.getType()) {
2012-04-27 11:47:11 +02:00
case COAL_ORE:
case DIAMOND_ORE:
case GLOWING_REDSTONE_ORE:
case GOLD_ORE:
case IRON_ORE:
case LAPIS_ORE:
case REDSTONE_ORE:
case EMERALD_ORE:
2012-04-27 11:47:11 +02:00
return true;
default:
if (customBlocksEnabled && ModChecks.isCustomOreBlock(block)) {
return true;
}
2013-01-10 04:43:21 +01:00
return false;
2012-04-27 11:47:11 +02:00
}
}
/**
* Check if a block can be made mossy.
*
* @param block The block to check
* @return true if the block can be made mossy, false otherwise
*/
public static boolean makeMossy(Block block) {
switch (block.getType()) {
case COBBLESTONE:
case DIRT:
return true;
case SMOOTH_BRICK:
case COBBLE_WALL:
if (block.getData() == 0) {
return true;
}
default:
return false;
}
}
/**
* Check if a block is affected by Herbalism abilities.
*
* @param block Block to check
* @return true if the block is affected, false otherwise
*/
2013-01-10 05:03:17 +01:00
public static boolean canBeGreenTerra(Block block) {
switch (block.getType()) {
case BROWN_MUSHROOM:
case CACTUS:
case MELON_BLOCK:
case NETHER_WARTS:
case PUMPKIN:
case RED_MUSHROOM:
case RED_ROSE:
case SUGAR_CANE_BLOCK:
case VINE:
case WATER_LILY:
case YELLOW_FLOWER:
case COCOA:
case CARROT:
case POTATO:
return true;
2012-05-18 17:15:30 +02:00
case CROPS:
if (block.getData() == CropState.RIPE.getData()) {
return true;
}
2013-01-10 04:43:21 +01:00
return false;
2012-05-18 17:15:30 +02:00
default:
ItemStack item = (new MaterialData(block.getTypeId(), block.getData())).toItemStack(1);
2012-12-25 07:01:10 +01:00
if (customBlocksEnabled && CustomBlocksConfig.getInstance().customHerbalismBlocks.contains(item)) {
return true;
}
2013-01-10 04:43:21 +01:00
return false;
}
}
/**
* Check to see if a block is broken by Super Breaker.
*
* @param block Block to check
* @return true if the block would be broken by Super Breaker, false otherwise
*/
public static Boolean canBeSuperBroken(Block block) {
switch (block.getType()) {
case COAL_ORE:
case DIAMOND_ORE:
case ENDER_STONE:
case GLOWING_REDSTONE_ORE:
case GLOWSTONE:
case GOLD_ORE:
case IRON_ORE:
case LAPIS_ORE:
case MOSSY_COBBLESTONE:
case NETHERRACK:
case OBSIDIAN:
case REDSTONE_ORE:
case SANDSTONE:
case STONE:
case EMERALD_ORE:
return true;
default:
ItemStack item = (new MaterialData(block.getTypeId(), block.getData())).toItemStack(1);
2012-12-25 07:01:10 +01:00
if (customBlocksEnabled && CustomBlocksConfig.getInstance().customMiningBlocks.contains(item)) {
return true;
}
2013-01-10 04:43:21 +01:00
return false;
}
}
/**
* Check to see if a block can be broken by Giga Drill Breaker.
*
* @param block Block to check
* @return true if the block can be broken by Giga Drill Breaker, false otherwise
*/
public static boolean canBeGigaDrillBroken(Block block) {
switch (block.getType()) {
case CLAY:
case DIRT:
case GRASS:
case GRAVEL:
case MYCEL:
case SAND:
case SOUL_SAND:
return true;
default:
ItemStack item = (new MaterialData(block.getTypeId(), block.getData())).toItemStack(1);
2012-12-25 07:01:10 +01:00
if (customBlocksEnabled && CustomBlocksConfig.getInstance().customExcavationBlocks.contains(item)) {
return true;
}
2013-01-10 04:43:21 +01:00
return false;
}
}
/**
* Checks if the block is affected by Tree Feller.
*
* @param block Block to check
* @return true if the block is affected by Tree Feller, false otherwise
*/
public static boolean treeFellerCompatible(Block block) {
switch (block.getType()) {
case LOG:
case LEAVES:
case AIR:
return true;
default:
ItemStack item = (new MaterialData(block.getTypeId(), block.getData())).toItemStack(1);
2012-12-25 07:01:10 +01:00
if (customBlocksEnabled && CustomBlocksConfig.getInstance().customWoodcuttingBlocks.contains(item)) {
return true;
}
2013-01-10 04:43:21 +01:00
return false;
}
}
2012-05-18 17:15:30 +02:00
2013-01-10 05:03:17 +01:00
public static boolean isLog (Block block) {
2012-05-18 17:15:30 +02:00
if (block.getType().equals(Material.LOG) || (customBlocksEnabled && ModChecks.isCustomLogBlock(block))) {
return true;
}
2013-01-10 04:43:21 +01:00
return false;
2012-05-18 17:15:30 +02:00
}
2012-04-27 11:47:11 +02:00
}