Skip to content

Commit

Permalink
Support multi-conversion recipes.
Browse files Browse the repository at this point in the history
  • Loading branch information
tastybento committed Aug 16, 2020
1 parent ef65a66 commit 56b1a9a
Showing 1 changed file with 16 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
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;
Expand All @@ -24,6 +25,9 @@
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;
Expand Down Expand Up @@ -52,7 +56,8 @@ public class BiomeRecipe implements Comparable<BiomeRecipe> {

// Conversions
// 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 waterCoverage;
Expand All @@ -75,7 +80,7 @@ public BiomeRecipe(Greenhouses addon, Biome type, int priority) {
this.priority = priority;
mobLimit = 9; // Default
}

private void startupLog(String message) {
if (addon.getSettings().isStartupLog()) addon.log(message);
}
Expand Down Expand Up @@ -212,15 +217,15 @@ public Set<GreenhouseResult> checkRecipe(Greenhouse gh) {
* @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());
}
});
}

/**
Expand Down

0 comments on commit 56b1a9a

Please sign in to comment.