From 3bb920f22c6fb7bd8e94b7131ac7f1d040cc3605 Mon Sep 17 00:00:00 2001 From: t00thpick1 Date: Thu, 23 Jun 2016 21:22:40 -0400 Subject: [PATCH] This is completely untested but it probably works. Maybe Fixes #2966 --- .../nossr50/skills/herbalism/Herbalism.java | 148 ++++++++++-------- 1 file changed, 83 insertions(+), 65 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/skills/herbalism/Herbalism.java b/src/main/java/com/gmail/nossr50/skills/herbalism/Herbalism.java index ce55d3ba1..81a3c76d2 100644 --- a/src/main/java/com/gmail/nossr50/skills/herbalism/Herbalism.java +++ b/src/main/java/com/gmail/nossr50/skills/herbalism/Herbalism.java @@ -10,10 +10,12 @@ import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.config.AdvancedConfig; import com.gmail.nossr50.util.skills.SkillUtils; import java.util.ArrayList; +import java.util.HashSet; import java.util.LinkedHashSet; import java.util.List; public class Herbalism { + public static int farmersDietRankLevel1 = AdvancedConfig.getInstance().getFarmerDietRankChange(); public static int farmersDietRankLevel2 = farmersDietRankLevel1 * 2; public static int farmersDietMaxLevel = farmersDietRankLevel1 * 5; @@ -24,80 +26,94 @@ public class Herbalism { /** * Convert blocks affected by the Green Thumb & Green Terra abilities. * - * @param blockState The {@link BlockState} to check ability activation for + * @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 COBBLE_WALL: + case COBBLE_WALL : blockState.setRawData((byte) 0x1); return true; - case SMOOTH_BRICK: + case SMOOTH_BRICK : ((SmoothBrick) blockState.getData()).setMaterial(Material.MOSSY_COBBLESTONE); return true; - case DIRT: - case GRASS_PATH: + case DIRT : + case GRASS_PATH : blockState.setType(Material.GRASS); return true; - case COBBLESTONE: + case COBBLESTONE : blockState.setType(Material.MOSSY_COBBLESTONE); return true; - default: + default : return false; } } - - public static List findChorusPlant(Block target) { - return findChorusPlant(target, true); + + public static HashSet findChorusPlant(Block target) { + return findChorusPlant(target, new HashSet()); } - - private static List findChorusPlant(Block target, boolean origin) { - List blocks = new ArrayList(); - - if(target.getType() != Material.CHORUS_PLANT) { - return blocks; + + private static HashSet findChorusPlant(Block target, HashSet traversed) { + if (target.getType() != Material.CHORUS_PLANT) { + return traversed; } - - blocks.add(target); - + // 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(relative.getType() == Material.CHORUS_PLANT) { - blocks.addAll(findChorusPlant(relative, false)); - } - - if(origin || target.getRelative(BlockFace.DOWN, 1).getType() == Material.CHORUS_PLANT) { - relative = target.getRelative(BlockFace.NORTH, 1); - if(relative.getType() == Material.CHORUS_PLANT) { - blocks.addAll(findChorusPlant(relative, false)); - } - - relative = target.getRelative(BlockFace.SOUTH, 1); - if(relative.getType() == Material.CHORUS_PLANT) { - blocks.addAll(findChorusPlant(relative, false)); - } - - relative = target.getRelative(BlockFace.EAST, 1); - if(relative.getType() == Material.CHORUS_PLANT) { - blocks.addAll(findChorusPlant(relative, false)); - } - - relative = target.getRelative(BlockFace.WEST, 1); - if(relative.getType() == Material.CHORUS_PLANT) { - blocks.addAll(findChorusPlant(relative, false)); + if (!traversed.contains(relative)) { + if (relative.getType() == Material.CHORUS_PLANT) { + traversed.addAll(findChorusPlant(relative, traversed)); } } - - return new ArrayList(new LinkedHashSet(blocks)); + + 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. + * 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 + * @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) { @@ -105,20 +121,21 @@ public class Herbalism { Material blockType = blockState.getType(); int dropAmount = mcMMO.getPlaceStore().isTrue(block) ? 0 : 1; - if(blockType == Material.CHORUS_PLANT) { + if (blockType == Material.CHORUS_PLANT) { dropAmount = 1; - - if(block.getRelative(BlockFace.DOWN, 1).getType() == Material.ENDER_STONE) { - List blocks = findChorusPlant(block); - + + if (block.getRelative(BlockFace.DOWN, 1).getType() == Material.ENDER_STONE) { + HashSet blocks = findChorusPlant(block); + dropAmount = blocks.size(); - - /*for(Block b : blocks) { - b.breakNaturally(); - }*/ + + /* + * for(Block b : blocks) { + * b.breakNaturally(); + * } + */ } - } - else { + } 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); @@ -129,8 +146,7 @@ public class Herbalism { if (mcMMO.getPlaceStore().isTrue(relativeBlock)) { mcMMO.getPlaceStore().setFalse(relativeBlock); - } - else { + } else { dropAmount++; } } @@ -142,18 +158,19 @@ public class Herbalism { /** * Convert blocks affected by the Green Thumb & Green Terra abilities. * - * @param blockState The {@link BlockState} to check ability activation for + * @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: - case GRASS_PATH: + case DIRT : + case GRASS : + case GRASS_PATH : blockState.setType(Material.MYCEL); return true; - default: + default : return false; } } @@ -161,7 +178,8 @@ public class Herbalism { /** * Check if the block has a recently grown crop from Green Thumb * - * @param blockState The {@link BlockState} to check green thumb regrown for + * @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) {