This is completely untested but it probably works. Maybe Fixes #2966

This commit is contained in:
t00thpick1 2016-06-23 21:22:40 -04:00
parent 2bed26f18a
commit 3bb920f22c

View File

@ -10,10 +10,12 @@ import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.AdvancedConfig; import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.util.skills.SkillUtils; import com.gmail.nossr50.util.skills.SkillUtils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
public class Herbalism { public class Herbalism {
public static int farmersDietRankLevel1 = AdvancedConfig.getInstance().getFarmerDietRankChange(); public static int farmersDietRankLevel1 = AdvancedConfig.getInstance().getFarmerDietRankChange();
public static int farmersDietRankLevel2 = farmersDietRankLevel1 * 2; public static int farmersDietRankLevel2 = farmersDietRankLevel1 * 2;
public static int farmersDietMaxLevel = farmersDietRankLevel1 * 5; public static int farmersDietMaxLevel = farmersDietRankLevel1 * 5;
@ -24,7 +26,8 @@ public class Herbalism {
/** /**
* Convert blocks affected by the Green Thumb & Green Terra abilities. * 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 * @return true if the ability was successful, false otherwise
*/ */
protected static boolean convertGreenTerraBlocks(BlockState blockState) { protected static boolean convertGreenTerraBlocks(BlockState blockState) {
@ -51,53 +54,66 @@ public class Herbalism {
} }
} }
public static List<Block> findChorusPlant(Block target) { public static HashSet<Block> findChorusPlant(Block target) {
return findChorusPlant(target, true); return findChorusPlant(target, new HashSet<Block>());
} }
private static List<Block> findChorusPlant(Block target, boolean origin) { private static HashSet<Block> findChorusPlant(Block target, HashSet<Block> traversed) {
List<Block> blocks = new ArrayList<Block>();
if (target.getType() != Material.CHORUS_PLANT) { if (target.getType() != Material.CHORUS_PLANT) {
return blocks; return traversed;
}
// Prevent any infinite loops, who needs more than 64 chorus anyways
if (traversed.size() > 64)
{
return traversed;
} }
blocks.add(target); traversed.add(target);
Block relative = target.getRelative(BlockFace.UP, 1); Block relative = target.getRelative(BlockFace.UP, 1);
if (!traversed.contains(relative)) {
if (relative.getType() == Material.CHORUS_PLANT) { if (relative.getType() == Material.CHORUS_PLANT) {
blocks.addAll(findChorusPlant(relative, false)); traversed.addAll(findChorusPlant(relative, traversed));
}
} }
if(origin || target.getRelative(BlockFace.DOWN, 1).getType() == Material.CHORUS_PLANT) {
relative = target.getRelative(BlockFace.NORTH, 1); relative = target.getRelative(BlockFace.NORTH, 1);
if (!traversed.contains(relative)) {
if (relative.getType() == Material.CHORUS_PLANT) { if (relative.getType() == Material.CHORUS_PLANT) {
blocks.addAll(findChorusPlant(relative, false)); traversed.addAll(findChorusPlant(relative, traversed));
}
} }
relative = target.getRelative(BlockFace.SOUTH, 1); relative = target.getRelative(BlockFace.SOUTH, 1);
if (!traversed.contains(relative)) {
if (relative.getType() == Material.CHORUS_PLANT) { if (relative.getType() == Material.CHORUS_PLANT) {
blocks.addAll(findChorusPlant(relative, false)); traversed.addAll(findChorusPlant(relative, traversed));
}
} }
relative = target.getRelative(BlockFace.EAST, 1); relative = target.getRelative(BlockFace.EAST, 1);
if (!traversed.contains(relative)) {
if (relative.getType() == Material.CHORUS_PLANT) { if (relative.getType() == Material.CHORUS_PLANT) {
blocks.addAll(findChorusPlant(relative, false)); traversed.addAll(findChorusPlant(relative, traversed));
}
} }
relative = target.getRelative(BlockFace.WEST, 1); relative = target.getRelative(BlockFace.WEST, 1);
if (!traversed.contains(relative)) {
if (relative.getType() == Material.CHORUS_PLANT) { if (relative.getType() == Material.CHORUS_PLANT) {
blocks.addAll(findChorusPlant(relative, false)); traversed.addAll(findChorusPlant(relative, traversed));
} }
} }
return new ArrayList<Block>(new LinkedHashSet<Block>(blocks)); 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 * @return the number of bonus drops to award from the blocks in this plant
*/ */
protected static int calculateMultiBlockPlantDrops(BlockState blockState) { protected static int calculateMultiBlockPlantDrops(BlockState blockState) {
@ -109,16 +125,17 @@ public class Herbalism {
dropAmount = 1; dropAmount = 1;
if (block.getRelative(BlockFace.DOWN, 1).getType() == Material.ENDER_STONE) { if (block.getRelative(BlockFace.DOWN, 1).getType() == Material.ENDER_STONE) {
List<Block> blocks = findChorusPlant(block); HashSet<Block> blocks = findChorusPlant(block);
dropAmount = blocks.size(); 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 // Handle the two blocks above it - cacti & sugar cane can only grow 3 high naturally
for (int y = 1; y < 3; y++) { for (int y = 1; y < 3; y++) {
Block relativeBlock = block.getRelative(BlockFace.UP, y); Block relativeBlock = block.getRelative(BlockFace.UP, y);
@ -129,8 +146,7 @@ public class Herbalism {
if (mcMMO.getPlaceStore().isTrue(relativeBlock)) { if (mcMMO.getPlaceStore().isTrue(relativeBlock)) {
mcMMO.getPlaceStore().setFalse(relativeBlock); mcMMO.getPlaceStore().setFalse(relativeBlock);
} } else {
else {
dropAmount++; dropAmount++;
} }
} }
@ -142,7 +158,8 @@ public class Herbalism {
/** /**
* Convert blocks affected by the Green Thumb & Green Terra abilities. * 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 * @return true if the ability was successful, false otherwise
*/ */
protected static boolean convertShroomThumb(BlockState blockState) { protected static boolean convertShroomThumb(BlockState blockState) {
@ -161,7 +178,8 @@ public class Herbalism {
/** /**
* Check if the block has a recently grown crop from Green Thumb * 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 * @return true if the block is recently regrown, false otherwise
*/ */
public static boolean isRecentlyRegrown(BlockState blockState) { public static boolean isRecentlyRegrown(BlockState blockState) {