mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-19 18:55:18 +00:00
Remove unused, add & implement ANY treeSize
This commit is contained in:
parent
52cba23190
commit
aaf7ae8fc3
@ -17,8 +17,6 @@ import java.util.Objects;
|
|||||||
|
|
||||||
public class TreeManager implements Listener {
|
public class TreeManager implements Listener {
|
||||||
|
|
||||||
public static final int maxSaplingPlane = 5;
|
|
||||||
|
|
||||||
public TreeManager() {
|
public TreeManager() {
|
||||||
Iris.instance.registerListener(this);
|
Iris.instance.registerListener(this);
|
||||||
Iris.info("Loading Sapling Manager");
|
Iris.info("Loading Sapling Manager");
|
||||||
@ -191,11 +189,9 @@ public class TreeManager implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add more or find any in the dimension
|
// Add more or find any in the dimension
|
||||||
/* TODO: Implement object placement in dimension & here
|
|
||||||
if (worldAccess.getCompound().getRootDimension().getSaplingSettings().getMode().equals(IrisTreeModes.ALL) || placements.isEmpty()){
|
if (worldAccess.getCompound().getRootDimension().getSaplingSettings().getMode().equals(IrisTreeModes.ALL) || placements.isEmpty()){
|
||||||
placements.addAll(matchObjectPlacements(worldAccess.getCompound().getRootDimension().getObjects(), size, type));
|
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(RNG.r) : null;
|
||||||
@ -213,7 +209,7 @@ public class TreeManager implements Listener {
|
|||||||
objects.stream()
|
objects.stream()
|
||||||
.filter(objectPlacement -> objectPlacement.getTreeOptions().isEnabled())
|
.filter(objectPlacement -> objectPlacement.getTreeOptions().isEnabled())
|
||||||
.filter(objectPlacement -> objectPlacement.getTreeOptions().getTrees().stream().anyMatch(irisTree ->
|
.filter(objectPlacement -> objectPlacement.getTreeOptions().getTrees().stream().anyMatch(irisTree ->
|
||||||
irisTree.getSizes().stream().anyMatch(treeSize -> treeSize == size) &&
|
irisTree.getSizes().stream().anyMatch(treeSize -> treeSize == IrisTreeSize.ANY || treeSize == size) &&
|
||||||
irisTree.getTreeTypes().stream().anyMatch(treeType -> treeType == type)))
|
irisTree.getTreeTypes().stream().anyMatch(treeType -> treeType == type)))
|
||||||
.forEach(objectPlacements::add);
|
.forEach(objectPlacements::add);
|
||||||
return objectPlacements;
|
return objectPlacements;
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.volmit.iris.engine.object;
|
package com.volmit.iris.engine.object;
|
||||||
|
|
||||||
|
import com.volmit.iris.Iris;
|
||||||
import com.volmit.iris.engine.object.annotations.Desc;
|
import com.volmit.iris.engine.object.annotations.Desc;
|
||||||
import com.volmit.iris.util.collection.KList;
|
import com.volmit.iris.util.collection.KList;
|
||||||
import com.volmit.iris.util.collection.KMap;
|
import com.volmit.iris.util.collection.KMap;
|
||||||
@ -28,36 +29,26 @@ public enum IrisTreeSize {
|
|||||||
FIVE_ANY,
|
FIVE_ANY,
|
||||||
|
|
||||||
@Desc("Five by five center")
|
@Desc("Five by five center")
|
||||||
FIVE_CENTER;
|
FIVE_CENTER,
|
||||||
|
|
||||||
|
@Desc("Any size")
|
||||||
|
ANY;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* All sizes in this enum
|
* All sizes in this enum
|
||||||
*/
|
*/
|
||||||
public static final KList<IrisTreeSize> sizes = new KList<>(ONE, TWO, THREE_ANY, THREE_CENTER, FOUR, FIVE_ANY, FIVE_CENTER);
|
public static final KList<IrisTreeSize> sizes = new KList<>(ONE, TWO, THREE_ANY, THREE_CENTER, FOUR, FIVE_ANY, FIVE_CENTER);
|
||||||
|
|
||||||
/**
|
|
||||||
* The best size in this enum
|
|
||||||
*/
|
|
||||||
public static final IrisTreeSize bestSize = FIVE_CENTER;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Whether the position of the any type (not fixed at a center)
|
|
||||||
* @param treeSize The treesize to check
|
|
||||||
*/
|
|
||||||
public static boolean isAnyPosition(IrisTreeSize treeSize){
|
|
||||||
return switch (treeSize) {
|
|
||||||
case ONE, THREE_CENTER, FIVE_CENTER -> false;
|
|
||||||
default -> true;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the best size to match against from a list of sizes
|
* Get the best size to match against from a list of sizes
|
||||||
* @param sizes The list of sizes
|
* @param sizes The list of sizes
|
||||||
* @return The best size (highest & center > any)
|
* @return The best size (highest & center > any)
|
||||||
*/
|
*/
|
||||||
public static IrisTreeSize bestSizeInSizes(KList<IrisTreeSize> sizes){
|
public static IrisTreeSize bestSizeInSizes(KList<IrisTreeSize> sizes){
|
||||||
if (sizes.contains(FIVE_CENTER)){
|
if (sizes.contains(ANY)){
|
||||||
|
return ANY;
|
||||||
|
}
|
||||||
|
else if (sizes.contains(FIVE_CENTER)){
|
||||||
return FIVE_CENTER;
|
return FIVE_CENTER;
|
||||||
}
|
}
|
||||||
else if (sizes.contains(FIVE_ANY)){
|
else if (sizes.contains(FIVE_ANY)){
|
||||||
@ -82,39 +73,6 @@ public enum IrisTreeSize {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Find the best size based on a location
|
|
||||||
* @param location The location to look from
|
|
||||||
* @return The best size
|
|
||||||
*/
|
|
||||||
public static IrisTreeSize getBestSize(Location location){
|
|
||||||
return getBestSize(location, sizes.copy());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Find the best valid size based on a location and a list of sizes
|
|
||||||
* @param location The location to search from
|
|
||||||
* @param sizeList The list of sizes to pick from
|
|
||||||
* @return The best valid size
|
|
||||||
*/
|
|
||||||
public static IrisTreeSize getBestSize(Location location, KList<IrisTreeSize> sizeList){
|
|
||||||
while (sizeList.isNotEmpty()){
|
|
||||||
|
|
||||||
// Find the best size & remove from list
|
|
||||||
IrisTreeSize bestSize = bestSizeInSizes(sizeList);
|
|
||||||
assert bestSize != null;
|
|
||||||
sizeList.remove(bestSize);
|
|
||||||
|
|
||||||
// Find the best match
|
|
||||||
KList<KList<Location>> best = getPlacesIfValid(bestSize, location);
|
|
||||||
if (best != null){
|
|
||||||
return bestSize;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ONE;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if the size at a specific location is valid
|
* Check if the size at a specific location is valid
|
||||||
* @param size the IrisTreeSize to check
|
* @param size the IrisTreeSize to check
|
||||||
@ -122,6 +80,9 @@ public enum IrisTreeSize {
|
|||||||
* @return A list of locations if any match, or null if not.
|
* @return A list of locations if any match, or null if not.
|
||||||
*/
|
*/
|
||||||
public static KList<KList<Location>> getPlacesIfValid (IrisTreeSize size, Location location) {
|
public static KList<KList<Location>> getPlacesIfValid (IrisTreeSize size, Location location) {
|
||||||
|
if (size == ANY){
|
||||||
|
Iris.debug("ANY was passed to getPlacesIfValid while it should never!");
|
||||||
|
}
|
||||||
return switch (size){
|
return switch (size){
|
||||||
case ONE -> new KList<KList<Location>>(new KList<>(location));
|
case ONE -> new KList<KList<Location>>(new KList<>(location));
|
||||||
case TWO -> loopLocation(location, 2);
|
case TWO -> loopLocation(location, 2);
|
||||||
@ -130,6 +91,7 @@ public enum IrisTreeSize {
|
|||||||
case FIVE_ANY -> loopLocation(location, 5);
|
case FIVE_ANY -> loopLocation(location, 5);
|
||||||
case THREE_CENTER -> isCenterMapValid(location, 3);
|
case THREE_CENTER -> isCenterMapValid(location, 3);
|
||||||
case FIVE_CENTER -> isCenterMapValid(location, 5);
|
case FIVE_CENTER -> isCenterMapValid(location, 5);
|
||||||
|
case ANY -> null;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user