From 2b4292f2eda13d930a49b6dfabca82e62ab516ab Mon Sep 17 00:00:00 2001 From: Warrior <50800980+Warriorrrr@users.noreply.github.com> Date: Fri, 22 Apr 2022 21:56:29 +0200 Subject: [PATCH] Fix hanging plants searching up instead of down. --- .../skills/herbalism/HerbalismManager.java | 16 ++++++++++------ .../com/gmail/nossr50/util/MaterialMapStore.java | 15 +++++++++++++-- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java b/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java index ddefee49e..aae793b6d 100644 --- a/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java +++ b/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java @@ -578,7 +578,7 @@ public class HerbalismManager extends SkillManager { if (isChorusBranch(brokenBlock.getType())) { brokenBlocks = getBrokenChorusBlocks(brokenBlock); } else { - brokenBlocks = getBlocksBrokenAbove(brokenBlock, false); + brokenBlocks = getBlocksBrokenAboveOrBelow(brokenBlock, false, mcMMO.getMaterialMapStore().isMultiBlockHangingPlant(brokenBlock.getType())); } return brokenBlocks; @@ -599,9 +599,11 @@ public class HerbalismManager extends SkillManager { * Multi-block plants are hard-coded and kept in {@link MaterialMapStore} * * @param originBlock The point of the "break" + * @param inclusive Whether to include the origin block + * @param below Whether to search down instead of up. * @return A set of blocks above the target block which can be assumed to be broken */ - private HashSet getBlocksBrokenAbove(BlockState originBlock, boolean inclusive) { + private HashSet getBlocksBrokenAboveOrBelow(BlockState originBlock, boolean inclusive, boolean below) { HashSet brokenBlocks = new HashSet<>(); Block block = originBlock.getBlock(); @@ -612,16 +614,18 @@ public class HerbalismManager extends SkillManager { //Limit our search int maxHeight = 512; + final BlockFace relativeFace = below ? BlockFace.DOWN : BlockFace.UP; + // Search vertically for multi-block plants, exit early if any non-multi block plants for (int y = 0; y < maxHeight; y++) { //TODO: Should this grab state? It would be more expensive.. - Block relativeUpBlock = block.getRelative(BlockFace.UP, y); + Block relativeBlock = block.getRelative(relativeFace, y); //Abandon our search if the block isn't multi - if(!mcMMO.getMaterialMapStore().isMultiBlockPlant(relativeUpBlock.getType())) + if (isOneBlockPlant(relativeBlock.getType())) break; - brokenBlocks.add(relativeUpBlock); + brokenBlocks.add(relativeBlock); } return brokenBlocks; @@ -634,7 +638,7 @@ public class HerbalismManager extends SkillManager { * @return true if the block is not contained in the collection of multi-block plants */ private boolean isOneBlockPlant(Material material) { - return !mcMMO.getMaterialMapStore().isMultiBlockPlant(material); + return !mcMMO.getMaterialMapStore().isMultiBlockPlant(material) && !mcMMO.getMaterialMapStore().isMultiBlockHangingPlant(material); } /** diff --git a/src/main/java/com/gmail/nossr50/util/MaterialMapStore.java b/src/main/java/com/gmail/nossr50/util/MaterialMapStore.java index 90104acce..2d1c39a9e 100644 --- a/src/main/java/com/gmail/nossr50/util/MaterialMapStore.java +++ b/src/main/java/com/gmail/nossr50/util/MaterialMapStore.java @@ -24,6 +24,7 @@ public class MaterialMapStore { private final @NotNull HashSet blockCrackerWhiteList; private final @NotNull HashSet canMakeShroomyWhiteList; private final @NotNull HashSet multiBlockPlant; + private final @NotNull HashSet multiBlockHangingPlant; private final @NotNull HashSet foodItemWhiteList; private final @NotNull HashSet glassBlocks; @@ -71,6 +72,7 @@ public class MaterialMapStore { blockCrackerWhiteList = new HashSet<>(); canMakeShroomyWhiteList = new HashSet<>(); multiBlockPlant = new HashSet<>(); + multiBlockHangingPlant = new HashSet<>(); foodItemWhiteList = new HashSet<>(); glassBlocks = new HashSet<>(); @@ -121,6 +123,7 @@ public class MaterialMapStore { fillBlockCrackerWhiteList(); fillShroomyWhiteList(); fillMultiBlockPlantSet(); + fillMultiBlockHangingPlantSet(); fillFoodWhiteList(); fillGlassBlockWhiteList(); fillArmors(); @@ -137,6 +140,10 @@ public class MaterialMapStore { return multiBlockPlant.contains(material.getKey().getKey()); } + public boolean isMultiBlockHangingPlant(@NotNull Material material) { + return multiBlockHangingPlant.contains(material.getKey().getKey()); + } + public boolean isAbilityActivationBlackListed(@NotNull Material material) { return abilityBlackList.contains(material.getKey().getKey()); @@ -974,8 +981,12 @@ public class MaterialMapStore { multiBlockPlant.add("large_fern"); multiBlockPlant.add("tall_grass"); multiBlockPlant.add("bamboo"); - multiBlockPlant.add("weeping_vines_plant"); - multiBlockPlant.add("twisted_vines_plant"); + } + + private void fillMultiBlockHangingPlantSet() { + multiBlockHangingPlant.add("weeping_vines_plant"); + multiBlockHangingPlant.add("twisted_vines_plant"); + multiBlockHangingPlant.add("cave_vines_plant"); } private void fillShroomyWhiteList()