123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 |
- package com.gmail.nossr50.skills.herbalism;
- import com.gmail.nossr50.config.AdvancedConfig;
- import com.gmail.nossr50.mcMMO;
- import com.gmail.nossr50.util.skills.SkillUtils;
- import org.bukkit.Material;
- import org.bukkit.block.Block;
- import org.bukkit.block.BlockFace;
- import org.bukkit.block.BlockState;
- import java.util.HashSet;
- public class Herbalism {
- public static int farmersDietRankLevel1 = AdvancedConfig.getInstance().getFarmerDietRankChange();
- public static int farmersDietRankLevel2 = farmersDietRankLevel1 * 2;
- public static int farmersDietMaxLevel = farmersDietRankLevel1 * 5;
- public static int greenThumbStageChangeLevel = AdvancedConfig.getInstance().getGreenThumbStageChange();
- public static int greenThumbStageMaxLevel = greenThumbStageChangeLevel * 4;
- /**
- * Convert blocks affected by the Green Thumb & Green Terra abilities.
- *
- * @param blockState
- * The {@link BlockState} to check ability activation for
- * @return true if the ability was successful, false otherwise
- */
- protected static boolean convertGreenTerraBlocks(BlockState blockState) {
- switch (blockState.getType()) {
- case COBBLESTONE_WALL:
- blockState.setType(Material.MOSSY_COBBLESTONE_WALL);
- return true;
- case STONE_BRICKS:
- blockState.setType(Material.MOSSY_STONE_BRICKS);
- return true;
- case DIRT :
- case GRASS_PATH :
- blockState.setType(Material.GRASS_BLOCK);
- return true;
- case COBBLESTONE :
- blockState.setType(Material.MOSSY_COBBLESTONE);
- return true;
- default :
- return false;
- }
- }
- public static HashSet<Block> findChorusPlant(Block target) {
- return findChorusPlant(target, new HashSet<Block>());
- }
- private static HashSet<Block> findChorusPlant(Block target, HashSet<Block> traversed) {
- if (target.getType() != Material.CHORUS_PLANT) {
- return traversed;
- }
- // Prevent any infinite loops, who needs more than 64 chorus anyways
- if (traversed.size() > 64)
- {
- return traversed;
- }
- traversed.add(target);
- Block relative = target.getRelative(BlockFace.UP, 1);
- if (!traversed.contains(relative)) {
- if (relative.getType() == Material.CHORUS_PLANT) {
- traversed.addAll(findChorusPlant(relative, traversed));
- }
- }
- relative = target.getRelative(BlockFace.NORTH, 1);
- if (!traversed.contains(relative)) {
- if (relative.getType() == Material.CHORUS_PLANT) {
- traversed.addAll(findChorusPlant(relative, traversed));
- }
- }
- relative = target.getRelative(BlockFace.SOUTH, 1);
- if (!traversed.contains(relative)) {
- if (relative.getType() == Material.CHORUS_PLANT) {
- traversed.addAll(findChorusPlant(relative, traversed));
- }
- }
- relative = target.getRelative(BlockFace.EAST, 1);
- if (!traversed.contains(relative)) {
- if (relative.getType() == Material.CHORUS_PLANT) {
- traversed.addAll(findChorusPlant(relative, traversed));
- }
- }
- relative = target.getRelative(BlockFace.WEST, 1);
- if (!traversed.contains(relative)) {
- if (relative.getType() == Material.CHORUS_PLANT) {
- traversed.addAll(findChorusPlant(relative, traversed));
- }
- }
- return traversed;
- }
- /**
- * Calculate the drop amounts for multi block plants based on the blocks
- * relative to them.
- *
- * @param blockState
- * The {@link BlockState} of the bottom block of the plant
- * @return the number of bonus drops to award from the blocks in this plant
- */
- protected static int calculateMultiBlockPlantDrops(BlockState blockState) {
- Block block = blockState.getBlock();
- Material blockType = blockState.getType();
- int dropAmount = mcMMO.getPlaceStore().isTrue(block) ? 0 : 1;
- if (blockType == Material.CHORUS_PLANT) {
- dropAmount = 1;
- if (block.getRelative(BlockFace.DOWN, 1).getType() == Material.END_STONE) {
- HashSet<Block> blocks = findChorusPlant(block);
- dropAmount = blocks.size();
- /*
- * for(Block b : blocks) {
- * b.breakNaturally();
- * }
- */
- }
- } else {
- // Handle the two blocks above it - cacti & sugar cane can only grow 3 high naturally
- for (int y = 1; y < 3; y++) {
- Block relativeBlock = block.getRelative(BlockFace.UP, y);
- if (relativeBlock.getType() != blockType) {
- break;
- }
- if (mcMMO.getPlaceStore().isTrue(relativeBlock)) {
- mcMMO.getPlaceStore().setFalse(relativeBlock);
- } else {
- dropAmount++;
- }
- }
- }
- return dropAmount;
- }
- /**
- * Convert blocks affected by the Green Thumb & Green Terra abilities.
- *
- * @param blockState
- * The {@link BlockState} to check ability activation for
- * @return true if the ability was successful, false otherwise
- */
- protected static boolean convertShroomThumb(BlockState blockState) {
- switch (blockState.getType()) {
- case DIRT :
- case GRASS_BLOCK:
- case GRASS_PATH :
- blockState.setType(Material.MYCELIUM);
- return true;
- default :
- return false;
- }
- }
- /**
- * Check if the block has a recently grown crop from Green Thumb
- *
- * @param blockState
- * The {@link BlockState} to check green thumb regrown for
- * @return true if the block is recently regrown, false otherwise
- */
- public static boolean isRecentlyRegrown(BlockState blockState) {
- return blockState.hasMetadata(mcMMO.greenThumbDataKey) && !SkillUtils.cooldownExpired(blockState.getMetadata(mcMMO.greenThumbDataKey).get(0).asInt(), 1);
- }
- }
|