mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-18 18:23:06 +00:00
Fix tree type size matcher
This commit is contained in:
parent
b217162cad
commit
cd3f9af232
@ -222,29 +222,20 @@ public class TreeManager implements Listener {
|
|||||||
private IrisObjectPlacement getObjectPlacement(IrisAccess worldAccess, Location location, TreeType type, IrisTreeSize size) {
|
private IrisObjectPlacement getObjectPlacement(IrisAccess worldAccess, Location location, TreeType type, IrisTreeSize size) {
|
||||||
|
|
||||||
KList<IrisObjectPlacement> placements = new KList<>();
|
KList<IrisObjectPlacement> placements = new KList<>();
|
||||||
KList<IrisObjectPlacement> allObjects = new KList<>();
|
|
||||||
boolean isUseAll = ((Engine) worldAccess.getEngineAccess(location.getBlockY())).getDimension().getTreeSettings().getMode().equals(IrisTreeModes.ALL);
|
boolean isUseAll = ((Engine) worldAccess.getEngineAccess(location.getBlockY())).getDimension().getTreeSettings().getMode().equals(IrisTreeModes.ALL);
|
||||||
|
|
||||||
// Retrieve objectPlacements of type `species` from biome
|
// Retrieve objectPlacements of type `species` from biome
|
||||||
IrisBiome biome = worldAccess.getBiome(location.getBlockX(), location.getBlockY(), location.getBlockZ());
|
IrisBiome biome = worldAccess.getBiome(location.getBlockX(), location.getBlockY(), location.getBlockZ());
|
||||||
placements.addAll(matchObjectPlacements(biome.getObjects(), size, type));
|
placements.addAll(matchObjectPlacements(biome.getObjects(), size, type));
|
||||||
allObjects.addAll(biome.getObjects());
|
|
||||||
|
|
||||||
// Add more or find any in the region
|
// Add more or find any in the region
|
||||||
if (isUseAll || placements.isEmpty()) {
|
if (isUseAll || placements.isEmpty()) {
|
||||||
IrisRegion region = worldAccess.getCompound().getEngineForHeight(location.getBlockY()).getRegion(location.getBlockX(), location.getBlockZ());
|
IrisRegion region = worldAccess.getCompound().getEngineForHeight(location.getBlockY()).getRegion(location.getBlockX(), location.getBlockZ());
|
||||||
placements.addAll(matchObjectPlacements(region.getObjects(), size, type));
|
placements.addAll(matchObjectPlacements(region.getObjects(), size, type));
|
||||||
allObjects.addAll(region.getObjects());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Add more or find any in the dimension
|
|
||||||
// Add object placer to dimension
|
|
||||||
// if (isUseAll || placements.isEmpty()){
|
|
||||||
// placements.addAll(matchObjectPlacements(worldAccess.getCompound().getRootDimension().getObjects(), size, type));
|
|
||||||
// }
|
|
||||||
|
|
||||||
// Check if no matches were found, return a random one if they are
|
// Check if no matches were found, return a random one if they are
|
||||||
return placements.isNotEmpty() ? placements.getRandom(RNG.r) : null;
|
return placements.isNotEmpty() ? placements.getRandom() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -257,13 +248,17 @@ public class TreeManager implements Listener {
|
|||||||
*/
|
*/
|
||||||
private KList<IrisObjectPlacement> matchObjectPlacements(KList<IrisObjectPlacement> objects, IrisTreeSize size, TreeType type) {
|
private KList<IrisObjectPlacement> matchObjectPlacements(KList<IrisObjectPlacement> objects, IrisTreeSize size, TreeType type) {
|
||||||
|
|
||||||
Predicate<IrisTree> isValid = irisTree -> (
|
KList<IrisObjectPlacement> p = new KList<>();
|
||||||
irisTree.isAnySize() || irisTree.getSizes().stream().anyMatch(treeSize -> treeSize.doesMatch(size))) && (
|
|
||||||
irisTree.isAnyTree() || irisTree.getTreeTypes().stream().anyMatch(treeType -> treeType.equals(type)));
|
|
||||||
|
|
||||||
objects.removeIf(objectPlacement -> objectPlacement.getTrees().stream().noneMatch(isValid));
|
for(IrisObjectPlacement i : objects)
|
||||||
|
{
|
||||||
|
if(i.matches(size, type))
|
||||||
|
{
|
||||||
|
p.add(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return objects;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -36,6 +36,7 @@ import lombok.EqualsAndHashCode;
|
|||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
import lombok.experimental.Accessors;
|
import lombok.experimental.Accessors;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.TreeType;
|
||||||
import org.bukkit.block.data.BlockData;
|
import org.bukkit.block.data.BlockData;
|
||||||
|
|
||||||
@EqualsAndHashCode()
|
@EqualsAndHashCode()
|
||||||
@ -214,6 +215,18 @@ public class IrisObjectPlacement {
|
|||||||
|
|
||||||
private transient AtomicCache<TableCache> cache = new AtomicCache<>();
|
private transient AtomicCache<TableCache> cache = new AtomicCache<>();
|
||||||
|
|
||||||
|
public boolean matches(IrisTreeSize size, TreeType type) {
|
||||||
|
for(IrisTree i : getTrees())
|
||||||
|
{
|
||||||
|
if(i.matches(size, type))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
private static class TableCache {
|
private static class TableCache {
|
||||||
final transient WeightedRandom<IrisLootTable> global = new WeightedRandom<>();
|
final transient WeightedRandom<IrisLootTable> global = new WeightedRandom<>();
|
||||||
final transient KMap<Material, WeightedRandom<IrisLootTable>> basic = new KMap<>();
|
final transient KMap<Material, WeightedRandom<IrisLootTable>> basic = new KMap<>();
|
||||||
|
@ -50,4 +50,29 @@ public class IrisTree {
|
|||||||
|
|
||||||
@Desc("If enabled, overrides trees of any size")
|
@Desc("If enabled, overrides trees of any size")
|
||||||
private boolean anySize;
|
private boolean anySize;
|
||||||
|
|
||||||
|
public boolean matches(IrisTreeSize size, TreeType type) {
|
||||||
|
if(!matchesSize(size))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return matchesType(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean matchesSize(IrisTreeSize size) {
|
||||||
|
for(IrisTreeSize i : getSizes())
|
||||||
|
{
|
||||||
|
if((i.getDepth() == size.getDepth() && i.getWidth() == size.getWidth()) || (i.getDepth() == size.getWidth() && i.getWidth() == size.getDepth()))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean matchesType(TreeType type) {
|
||||||
|
return getTreeTypes().contains(type);
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user