From aaf7ae8fc316a8ee0f724c05a22ab27bfdc80070 Mon Sep 17 00:00:00 2001 From: CocoTheOwner Date: Wed, 21 Jul 2021 11:25:22 +0200 Subject: [PATCH] Remove unused, add & implement ANY treeSize --- .../com/volmit/iris/core/TreeManager.java | 6 +- .../iris/engine/object/IrisTreeSize.java | 64 ++++--------------- 2 files changed, 14 insertions(+), 56 deletions(-) diff --git a/src/main/java/com/volmit/iris/core/TreeManager.java b/src/main/java/com/volmit/iris/core/TreeManager.java index 49a310231..9cc4e4faa 100644 --- a/src/main/java/com/volmit/iris/core/TreeManager.java +++ b/src/main/java/com/volmit/iris/core/TreeManager.java @@ -17,8 +17,6 @@ import java.util.Objects; public class TreeManager implements Listener { - public static final int maxSaplingPlane = 5; - public TreeManager() { Iris.instance.registerListener(this); Iris.info("Loading Sapling Manager"); @@ -191,11 +189,9 @@ public class TreeManager implements Listener { } // 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()){ placements.addAll(matchObjectPlacements(worldAccess.getCompound().getRootDimension().getObjects(), size, type)); } - */ // Check if no matches were found, return a random one if they are return placements.isNotEmpty() ? placements.getRandom(RNG.r) : null; @@ -213,7 +209,7 @@ public class TreeManager implements Listener { objects.stream() .filter(objectPlacement -> objectPlacement.getTreeOptions().isEnabled()) .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))) .forEach(objectPlacements::add); return objectPlacements; diff --git a/src/main/java/com/volmit/iris/engine/object/IrisTreeSize.java b/src/main/java/com/volmit/iris/engine/object/IrisTreeSize.java index 41c6efff5..fe707e9e5 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisTreeSize.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisTreeSize.java @@ -1,5 +1,6 @@ package com.volmit.iris.engine.object; +import com.volmit.iris.Iris; import com.volmit.iris.engine.object.annotations.Desc; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.collection.KMap; @@ -28,36 +29,26 @@ public enum IrisTreeSize { FIVE_ANY, @Desc("Five by five center") - FIVE_CENTER; + FIVE_CENTER, + + @Desc("Any size") + ANY; /** * All sizes in this enum */ public static final KList 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 * @param sizes The list of sizes * @return The best size (highest & center > any) */ public static IrisTreeSize bestSizeInSizes(KList sizes){ - if (sizes.contains(FIVE_CENTER)){ + if (sizes.contains(ANY)){ + return ANY; + } + else if (sizes.contains(FIVE_CENTER)){ return FIVE_CENTER; } 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 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> best = getPlacesIfValid(bestSize, location); - if (best != null){ - return bestSize; - } - } - return ONE; - - } - /** * Check if the size at a specific location is valid * @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. */ public static KList> getPlacesIfValid (IrisTreeSize size, Location location) { + if (size == ANY){ + Iris.debug("ANY was passed to getPlacesIfValid while it should never!"); + } return switch (size){ case ONE -> new KList>(new KList<>(location)); case TWO -> loopLocation(location, 2); @@ -130,6 +91,7 @@ public enum IrisTreeSize { case FIVE_ANY -> loopLocation(location, 5); case THREE_CENTER -> isCenterMapValid(location, 3); case FIVE_CENTER -> isCenterMapValid(location, 5); + case ANY -> null; }; }