mirror of
				https://github.com/mcMMO-Dev/mcMMO.git
				synced 2025-11-04 02:53:43 +01:00 
			
		
		
		
	Fix hanging plants searching up instead of down. (#4766)
This commit is contained in:
		@@ -578,7 +578,7 @@ public class HerbalismManager extends SkillManager {
 | 
				
			|||||||
        if (isChorusBranch(brokenBlock.getType())) {
 | 
					        if (isChorusBranch(brokenBlock.getType())) {
 | 
				
			||||||
            brokenBlocks = getBrokenChorusBlocks(brokenBlock);
 | 
					            brokenBlocks = getBrokenChorusBlocks(brokenBlock);
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            brokenBlocks = getBlocksBrokenAbove(brokenBlock, false);
 | 
					            brokenBlocks = getBlocksBrokenAboveOrBelow(brokenBlock, false, mcMMO.getMaterialMapStore().isMultiBlockHangingPlant(brokenBlock.getType()));
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return brokenBlocks;
 | 
					        return brokenBlocks;
 | 
				
			||||||
@@ -599,9 +599,11 @@ public class HerbalismManager extends SkillManager {
 | 
				
			|||||||
     * Multi-block plants are hard-coded and kept in {@link MaterialMapStore}
 | 
					     * Multi-block plants are hard-coded and kept in {@link MaterialMapStore}
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @param originBlock The point of the "break"
 | 
					     * @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
 | 
					     * @return A set of blocks above the target block which can be assumed to be broken
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    private HashSet<Block> getBlocksBrokenAbove(BlockState originBlock, boolean inclusive) {
 | 
					    private HashSet<Block> getBlocksBrokenAboveOrBelow(BlockState originBlock, boolean inclusive, boolean below) {
 | 
				
			||||||
        HashSet<Block> brokenBlocks = new HashSet<>();
 | 
					        HashSet<Block> brokenBlocks = new HashSet<>();
 | 
				
			||||||
        Block block = originBlock.getBlock();
 | 
					        Block block = originBlock.getBlock();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -612,16 +614,18 @@ public class HerbalismManager extends SkillManager {
 | 
				
			|||||||
        //Limit our search
 | 
					        //Limit our search
 | 
				
			||||||
        int maxHeight = 512;
 | 
					        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
 | 
					        // Search vertically for multi-block plants, exit early if any non-multi block plants
 | 
				
			||||||
        for (int y = 0; y < maxHeight; y++) {
 | 
					        for (int y = 0; y < maxHeight; y++) {
 | 
				
			||||||
            //TODO: Should this grab state? It would be more expensive..
 | 
					            //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
 | 
					            //Abandon our search if the block isn't multi
 | 
				
			||||||
            if(!mcMMO.getMaterialMapStore().isMultiBlockPlant(relativeUpBlock.getType()))
 | 
					            if (isOneBlockPlant(relativeBlock.getType()))
 | 
				
			||||||
                break;
 | 
					                break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            brokenBlocks.add(relativeUpBlock);
 | 
					            brokenBlocks.add(relativeBlock);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return brokenBlocks;
 | 
					        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
 | 
					     * @return true if the block is not contained in the collection of multi-block plants
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    private boolean isOneBlockPlant(Material material) {
 | 
					    private boolean isOneBlockPlant(Material material) {
 | 
				
			||||||
        return !mcMMO.getMaterialMapStore().isMultiBlockPlant(material);
 | 
					        return !mcMMO.getMaterialMapStore().isMultiBlockPlant(material) && !mcMMO.getMaterialMapStore().isMultiBlockHangingPlant(material);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -24,6 +24,7 @@ public class MaterialMapStore {
 | 
				
			|||||||
    private final @NotNull HashSet<String> blockCrackerWhiteList;
 | 
					    private final @NotNull HashSet<String> blockCrackerWhiteList;
 | 
				
			||||||
    private final @NotNull HashSet<String> canMakeShroomyWhiteList;
 | 
					    private final @NotNull HashSet<String> canMakeShroomyWhiteList;
 | 
				
			||||||
    private final @NotNull HashSet<String> multiBlockPlant;
 | 
					    private final @NotNull HashSet<String> multiBlockPlant;
 | 
				
			||||||
 | 
					    private final @NotNull HashSet<String> multiBlockHangingPlant;
 | 
				
			||||||
    private final @NotNull HashSet<String> foodItemWhiteList;
 | 
					    private final @NotNull HashSet<String> foodItemWhiteList;
 | 
				
			||||||
    private final @NotNull HashSet<String> glassBlocks;
 | 
					    private final @NotNull HashSet<String> glassBlocks;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -71,6 +72,7 @@ public class MaterialMapStore {
 | 
				
			|||||||
        blockCrackerWhiteList = new HashSet<>();
 | 
					        blockCrackerWhiteList = new HashSet<>();
 | 
				
			||||||
        canMakeShroomyWhiteList = new HashSet<>();
 | 
					        canMakeShroomyWhiteList = new HashSet<>();
 | 
				
			||||||
        multiBlockPlant = new HashSet<>();
 | 
					        multiBlockPlant = new HashSet<>();
 | 
				
			||||||
 | 
					        multiBlockHangingPlant = new HashSet<>();
 | 
				
			||||||
        foodItemWhiteList = new HashSet<>();
 | 
					        foodItemWhiteList = new HashSet<>();
 | 
				
			||||||
        glassBlocks = new HashSet<>();
 | 
					        glassBlocks = new HashSet<>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -121,6 +123,7 @@ public class MaterialMapStore {
 | 
				
			|||||||
        fillBlockCrackerWhiteList();
 | 
					        fillBlockCrackerWhiteList();
 | 
				
			||||||
        fillShroomyWhiteList();
 | 
					        fillShroomyWhiteList();
 | 
				
			||||||
        fillMultiBlockPlantSet();
 | 
					        fillMultiBlockPlantSet();
 | 
				
			||||||
 | 
					        fillMultiBlockHangingPlantSet();
 | 
				
			||||||
        fillFoodWhiteList();
 | 
					        fillFoodWhiteList();
 | 
				
			||||||
        fillGlassBlockWhiteList();
 | 
					        fillGlassBlockWhiteList();
 | 
				
			||||||
        fillArmors();
 | 
					        fillArmors();
 | 
				
			||||||
@@ -137,6 +140,10 @@ public class MaterialMapStore {
 | 
				
			|||||||
        return multiBlockPlant.contains(material.getKey().getKey());
 | 
					        return multiBlockPlant.contains(material.getKey().getKey());
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public boolean isMultiBlockHangingPlant(@NotNull Material material) {
 | 
				
			||||||
 | 
					        return multiBlockHangingPlant.contains(material.getKey().getKey());
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public boolean isAbilityActivationBlackListed(@NotNull Material material)
 | 
					    public boolean isAbilityActivationBlackListed(@NotNull Material material)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        return abilityBlackList.contains(material.getKey().getKey());
 | 
					        return abilityBlackList.contains(material.getKey().getKey());
 | 
				
			||||||
@@ -974,8 +981,12 @@ public class MaterialMapStore {
 | 
				
			|||||||
        multiBlockPlant.add("large_fern");
 | 
					        multiBlockPlant.add("large_fern");
 | 
				
			||||||
        multiBlockPlant.add("tall_grass");
 | 
					        multiBlockPlant.add("tall_grass");
 | 
				
			||||||
        multiBlockPlant.add("bamboo");
 | 
					        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()
 | 
					    private void fillShroomyWhiteList()
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user