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