diff --git a/src/main/java/world/bentobox/greenhouses/greenhouse/BiomeRecipe.java b/src/main/java/world/bentobox/greenhouses/greenhouse/BiomeRecipe.java index e9eb60f..d179e99 100644 --- a/src/main/java/world/bentobox/greenhouses/greenhouse/BiomeRecipe.java +++ b/src/main/java/world/bentobox/greenhouses/greenhouse/BiomeRecipe.java @@ -5,6 +5,7 @@ import java.util.EnumMap; import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Optional; import java.util.Random; import java.util.Set; @@ -24,6 +25,9 @@ import org.bukkit.entity.EntityType; import org.bukkit.util.BoundingBox; import org.bukkit.util.Vector; +import com.google.common.collect.ArrayListMultimap; +import com.google.common.collect.Multimap; + import world.bentobox.bentobox.util.Util; import world.bentobox.greenhouses.Greenhouses; import world.bentobox.greenhouses.data.Greenhouse; @@ -52,7 +56,8 @@ public class BiomeRecipe implements Comparable { // Conversions // Original Material, Original Type, New Material, New Type, Probability - private final Map conversionBlocks = new EnumMap<>(Material.class); + //private final Map conversionBlocks = new EnumMap<>(Material.class); + private Multimap conversionBlocks = ArrayListMultimap.create(); private int mobLimit; private int waterCoverage; @@ -75,7 +80,7 @@ public class BiomeRecipe implements Comparable { this.priority = priority; mobLimit = 9; // Default } - + private void startupLog(String message) { if (addon.getSettings().isStartupLog()) addon.log(message); } @@ -212,15 +217,15 @@ public class BiomeRecipe implements Comparable { * @param b - block to check */ public void convertBlock(Block b) { - GreenhouseBlockConversions bc = conversionBlocks.get(b.getType()); - if (bc == null || random.nextDouble() > bc.getProbability()) { - return; - } - // Check if the block is in the right area, up, down, n,s,e,w - if (adjBlocks.stream().map(b::getRelative).map(Block::getType).anyMatch(m -> bc.getLocalMaterial() == null || m == bc.getLocalMaterial())) { - // Convert! - b.setType(bc.getNewMaterial()); - } + conversionBlocks.get(b.getType()).stream().filter(Objects::nonNull) + .filter(bc -> random.nextDouble() < bc.getProbability()) + .forEach(bc -> { + // Check if the block is in the right area, up, down, n,s,e,w + if (adjBlocks.stream().map(b::getRelative).map(Block::getType).anyMatch(m -> bc.getLocalMaterial() == null || m == bc.getLocalMaterial())) { + // Convert! + b.setType(bc.getNewMaterial()); + } + }); } /**