Fix chorus blocks ignoring blockstore.

This commit is contained in:
t00thpick1 2019-01-19 17:02:24 -05:00
parent a073984621
commit eb1f097d18

View File

@ -42,58 +42,32 @@ public class Herbalism {
} }
} }
public static HashSet<Block> findChorusPlant(Block target) { private static int calculateChorusPlantDrops(Block target) {
return findChorusPlant(target, new HashSet<Block>()); return calculateChorusPlantDropsRecursive(target, new HashSet<>());
} }
private static HashSet<Block> findChorusPlant(Block target, HashSet<Block> traversed) { private static int calculateChorusPlantDropsRecursive(Block target, HashSet<Block> traversed) {
if (target.getType() != Material.CHORUS_PLANT) { if (target.getType() != Material.CHORUS_PLANT)
return traversed; return 0;
}
// Prevent any infinite loops, who needs more than 64 chorus anyways // Prevent any infinite loops, who needs more than 64 chorus anyways
if (traversed.size() > 64) if (traversed.size() > 64)
{ return 0;
return traversed;
}
traversed.add(target); if (!traversed.add(target))
return 0;
Block relative = target.getRelative(BlockFace.UP, 1); int dropAmount = 0;
if (!traversed.contains(relative)) {
if (relative.getType() == Material.CHORUS_PLANT) {
traversed.addAll(findChorusPlant(relative, traversed));
}
}
relative = target.getRelative(BlockFace.NORTH, 1); if (mcMMO.getPlaceStore().isTrue(target))
if (!traversed.contains(relative)) { mcMMO.getPlaceStore().setFalse(target);
if (relative.getType() == Material.CHORUS_PLANT) { else
traversed.addAll(findChorusPlant(relative, traversed)); dropAmount++;
}
}
relative = target.getRelative(BlockFace.SOUTH, 1); for (BlockFace blockFace : new BlockFace[] { BlockFace.UP, BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST ,BlockFace.WEST})
if (!traversed.contains(relative)) { dropAmount += calculateChorusPlantDropsRecursive(target.getRelative(blockFace, 1), traversed);
if (relative.getType() == Material.CHORUS_PLANT) {
traversed.addAll(findChorusPlant(relative, traversed));
}
}
relative = target.getRelative(BlockFace.EAST, 1); return dropAmount;
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;
} }
/** /**
@ -113,15 +87,7 @@ public class Herbalism {
dropAmount = 1; dropAmount = 1;
if (block.getRelative(BlockFace.DOWN, 1).getType() == Material.END_STONE) { if (block.getRelative(BlockFace.DOWN, 1).getType() == Material.END_STONE) {
HashSet<Block> blocks = findChorusPlant(block); dropAmount = calculateChorusPlantDrops(block);
dropAmount = blocks.size();
/*
* 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