From 1534dcc9320825e785b48ed59e76b1edd88d3f5d Mon Sep 17 00:00:00 2001 From: CocoTheOwner Date: Mon, 19 Jul 2021 12:07:29 +0200 Subject: [PATCH] Rework according to discussed changes --- .../com/volmit/iris/core/TreeManager.java | 148 ------------------ .../volmit/iris/engine/object/IrisBiome.java | 6 +- .../engine/object/IrisObjectPlacement.java | 3 + .../volmit/iris/engine/object/IrisRegion.java | 4 - .../volmit/iris/engine/object/IrisTree.java | 14 +- .../iris/engine/object/IrisTreeOptions.java | 22 +++ .../iris/engine/object/IrisTreeSettings.java | 6 - .../iris/engine/object/IrisTreeSize.java | 35 +++++ .../iris/engine/object/IrisTreeType.java | 32 ++-- 9 files changed, 80 insertions(+), 190 deletions(-) create mode 100644 src/main/java/com/volmit/iris/engine/object/IrisTreeOptions.java create mode 100644 src/main/java/com/volmit/iris/engine/object/IrisTreeSize.java diff --git a/src/main/java/com/volmit/iris/core/TreeManager.java b/src/main/java/com/volmit/iris/core/TreeManager.java index 7e56c2147..5cdf80bd2 100644 --- a/src/main/java/com/volmit/iris/core/TreeManager.java +++ b/src/main/java/com/volmit/iris/core/TreeManager.java @@ -68,153 +68,5 @@ public class TreeManager implements Listener { IrisBiome biome = worldAccess.getBiome(event.getLocation().getBlockX(), event.getLocation().getBlockY(), event.getLocation().getBlockZ()); IrisRegion region = worldAccess.getCompound().getDefaultEngine().getRegion(event.getLocation().getBlockX(), event.getLocation().getBlockZ()); - Iris.debug("Biome name: " + biome.getName() + " | List of saplings: " + biome.getSaplings().toString()); - Iris.debug("Region name: " + region.getName() + " | List of saplings: " + region.getSaplings().toString()); - Iris.debug("Dimension saplings: " + settings.getSaplings().toString()); - - // Get sapling location - KList saplingLocations = getSaplingPlane(event.getLocation()); - int saplingSize = getSaplingSize(saplingLocations); - - // Check biome, region and dimension - treeObjects.addAll(getSaplingsFrom(biome.getSaplings(), event.getSpecies(), saplingSize)); - - // Check region - if (settings.getMode() == IrisTreeModes.ALL || treeObjects.size() == 0) { - treeObjects.addAll(getSaplingsFrom(region.getSaplings(), event.getSpecies(), saplingSize)); - } - - // Check dimension - if (settings.getMode() == IrisTreeModes.ALL || treeObjects.size() == 0) { - treeObjects.addAll(getSaplingsFrom(settings.getSaplings(), event.getSpecies(), saplingSize)); - } - - Iris.debug("List of saplings (together): " + treeObjects); - - // Check to make sure something was found - if (treeObjects.size() == 0) { - return; - } - - // Pick a random object from the list of objects found - String pickedObjectString = treeObjects.get(RNG.r.i(0, treeObjects.size() - 1)); - - // Cancel vanilla event - event.setCancelled(true); - - // Retrieve & place the object - Iris.debug("Placing tree object instead of vanilla tree: " + pickedObjectString); - IrisObject pickedObject = IrisDataManager.loadAnyObject(pickedObjectString); - - // Delete the saplings (some objects may not have blocks where the sapling is) - deleteSaplings(saplingLocations); - - // Rotate the object randomly - pickedObject.rotate(new IrisObjectRotation(), 0, 90 * RNG.r.i(0, 3), 0); - - // TODO: Consider adding a translation to object placement. - // Place the object - pickedObject.place(event.getLocation()); - } - - /** - * Deletes all saplings at the - * @param locations sapling locations - */ - private void deleteSaplings(KList locations) { - locations.forEach(l -> { - Iris.debug("Deleting block of type: " + l.getBlock().getType()); - l.getBlock().setType(Material.AIR); - }); - } - - /** - * Find all sapling types of the given TreeType in the container - * @param container Iris sapling config - * @param tree The tree type to find - * @param size The `size * size` area of the saplings - * @return A list of found object name strings - */ - @NotNull - private KList getSaplingsFrom(KList container, TreeType tree, int size) { - - // Translate TreeType to Iris TreeType - IrisTreeType eventTreeType = IrisTreeType.fromTreeType(tree); - - KList objects = new KList<>(); - - // Loop over all saplings in the container - // and their entered sapling types - // and copy the trees in the list if matching. - for (IrisTree sapling : container) { - for (IrisTreeType configTreeType : sapling.getTreeTypes()) { - if (configTreeType == eventTreeType && size == sapling.getSize()) { - objects.addAll(sapling.getObjects()); - } - } - } - return objects; - } - - /** - * Retrieve the `size * size` area of a sapling (any sapling in the area) - * @param saplings The locations of the saplings in the plane - * @return The `x * x` area of saplings - */ - private int getSaplingSize(KList saplings){ - double size = Math.sqrt(saplings.size()); - if (size % 1 != 0) { - Iris.error("Size of sapling square array is not a power of an integer (not a square)"); - return -1; - } - return (int) size; - } - - /** - * Retrieve all saplings in a square area around the current sapling. - * This searches around the current sapling, and the next, etc, iteratively - * Note: This is limited by maxSaplingPlane - * @param location The location to search from (the originating sapling) - * @return A list of saplings in a square - */ - private KList getSaplingPlane(Location location){ - KList locations = new KList<>(); - - // TODO: Debug getBlockMap - boolean[][] map = getBlockMap(location); - - for (boolean[] row : map) { - Iris.info(Arrays.toString(row)); - } - - // TODO: Write logic here that checks for the largest possible square with the Location included - // TODO: The boolean[][] map has true's where there's another sapling of the same type, and false if not. - // TODO: Fill the locations array with the found sapling locations and return the array. The rest is hopefully done. - // Note: I tested the system. Placing objects works. Removing saplings may not work perfectly. - - return locations; - } - - /** - * Get a boolean map which indicates if at positions in all directions the same block can be found - * @param location the center location around which we search - * @return A boolean 2d map of trues and false's - */ - private boolean[][] getBlockMap(Location location) { - Material blockMaterial = location.getBlock().getType(); - int size = maxSaplingPlane * 2 - 1; - boolean[][] map = new boolean[size][size]; - - for (int i = 0; i < size; i++){ - boolean[] row = new boolean[size]; - for (int j = 0; j < size; j++){ - Vector zdir = new Vector(0, 0, 1).multiply(i - maxSaplingPlane + 1); - Vector xdir = new Vector(1, 0, 0).multiply(j - maxSaplingPlane + 1); - Material foundBlock = location.add(xdir).add(zdir).getBlock().getType(); - row[j] = blockMaterial.name().equals(foundBlock.name()); - } - map[i] = row; - } - return map; } } diff --git a/src/main/java/com/volmit/iris/engine/object/IrisBiome.java b/src/main/java/com/volmit/iris/engine/object/IrisBiome.java index 34353d1f7..cb268b35e 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisBiome.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisBiome.java @@ -81,12 +81,8 @@ public class IrisBiome extends IrisRegistrant implements IRare { @ArrayType(min = 1, type = IrisEntityInitialSpawn.class) private KList entityInitialSpawns = new KList<>(); - @Desc("Sapling override settings") - @ArrayType(min = 1, type = IrisTree.class) - private KList saplings = new KList<>(); - @ArrayType(min = 1, type = IrisEffect.class) - @Desc("Effects are ambient effects such as potion effects, random sounds, or even particles around each player. All of these effects are played via packets so two players won't see/hear each others effects.\nDue to performance reasons, effects will play arround the player even if where the effect was played is no longer in the biome the player is in.") + @Desc("Effects are ambient effects such as potion effects, random sounds, or even particles around each player. All of these effects are played via packets so two players won't see/hear each others effects.\nDue to performance reasons, effects will play around the player even if where the effect was played is no longer in the biome the player is in.") private KList effects = new KList<>(); diff --git a/src/main/java/com/volmit/iris/engine/object/IrisObjectPlacement.java b/src/main/java/com/volmit/iris/engine/object/IrisObjectPlacement.java index 67284be4e..ed716a78e 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisObjectPlacement.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisObjectPlacement.java @@ -151,6 +151,9 @@ public class IrisObjectPlacement { @Desc("The loot tables to apply to these objects") private KList loot = new KList<>(); + @Desc("Tree growth overrides for these object placements") + private IrisTreeOptions treeOptions = new IrisTreeOptions(); + public IrisObjectPlacement toPlacement(String... place) { IrisObjectPlacement p = new IrisObjectPlacement(); p.setPlace(new KList<>(place)); diff --git a/src/main/java/com/volmit/iris/engine/object/IrisRegion.java b/src/main/java/com/volmit/iris/engine/object/IrisRegion.java index 8f555ce08..47a587219 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisRegion.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisRegion.java @@ -79,10 +79,6 @@ public class IrisRegion extends IrisRegistrant implements IRare { @ArrayType(min = 1, type = IrisEntityInitialSpawn.class) private KList entityInitialSpawns = new KList<>(); - @Desc("Sapling override settings") - @ArrayType(min = 1, type = IrisTree.class) - private KList saplings = new KList<>(); - @MinNumber(1) @MaxNumber(128) @Desc("The rarity of the region") diff --git a/src/main/java/com/volmit/iris/engine/object/IrisTree.java b/src/main/java/com/volmit/iris/engine/object/IrisTree.java index 130a14a46..54154f769 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisTree.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisTree.java @@ -12,23 +12,17 @@ import org.bukkit.TreeType; @Accessors(chain = true) @AllArgsConstructor @NoArgsConstructor -@Desc("Tree replace options") +@Desc("Tree replace options for this object placer") @Data public class IrisTree { @Required - @Desc("The types of trees overwritten") + @Desc("The types of trees overwritten by this object") @ArrayType(min = 1, type = IrisTreeType.class) private KList treeTypes; - @RegistryListObject @Required - @ArrayType(min = 1, type = String.class) - @Desc("List of objects to replace trees with") - private KList objects = new KList<>(); - @Desc("The size of the square of saplings this applies to (2 means a 2 * 2 sapling area)") - @MinNumber(1) - @MaxNumber(TreeManager.maxSaplingPlane) - private int size = 1; + @ArrayType(min = 1, type = IrisTreeSize.class) + private KList sizes = new KList<>(); } \ No newline at end of file diff --git a/src/main/java/com/volmit/iris/engine/object/IrisTreeOptions.java b/src/main/java/com/volmit/iris/engine/object/IrisTreeOptions.java new file mode 100644 index 000000000..2aea54e6e --- /dev/null +++ b/src/main/java/com/volmit/iris/engine/object/IrisTreeOptions.java @@ -0,0 +1,22 @@ +package com.volmit.iris.engine.object; + +import com.volmit.iris.engine.object.annotations.Desc; +import com.volmit.iris.util.collection.KList; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.experimental.Accessors; + +@Accessors(chain = true) +@AllArgsConstructor +@NoArgsConstructor +@Desc("Tree replace options for this object placer") +@Data +public class IrisTreeOptions { + + @Desc("Toggles this object placer's tree overrides") + private boolean enabled = false; + + @Desc("Tree overrides affected by these object placements") + private KList trees = new KList<>(); +} diff --git a/src/main/java/com/volmit/iris/engine/object/IrisTreeSettings.java b/src/main/java/com/volmit/iris/engine/object/IrisTreeSettings.java index 584fc9a64..9924b1ecd 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisTreeSettings.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisTreeSettings.java @@ -1,8 +1,6 @@ package com.volmit.iris.engine.object; -import com.volmit.iris.engine.object.annotations.ArrayType; import com.volmit.iris.engine.object.annotations.Desc; -import com.volmit.iris.util.collection.KList; import lombok.AllArgsConstructor; import lombok.Data; import lombok.EqualsAndHashCode; @@ -22,8 +20,4 @@ public class IrisTreeSettings { @Desc("Object picking modes") IrisTreeModes mode = IrisTreeModes.FIRST; - - @Desc("Tree override list") - @ArrayType(min = 1, type = IrisTree.class) - private KList saplings = new KList<>(); } diff --git a/src/main/java/com/volmit/iris/engine/object/IrisTreeSize.java b/src/main/java/com/volmit/iris/engine/object/IrisTreeSize.java new file mode 100644 index 000000000..1f89ec267 --- /dev/null +++ b/src/main/java/com/volmit/iris/engine/object/IrisTreeSize.java @@ -0,0 +1,35 @@ +package com.volmit.iris.engine.object; + +import com.volmit.iris.engine.object.annotations.Desc; + +@Desc("Sapling override object picking options") +public enum IrisTreeSize { + + @Desc("Only one sapling") + ONE, + + @Desc("Two by two area") + TWO, + + @Desc("Three by three area with center") + THREE_CENTER, + + @Desc("Three by three any location") + THREE_ANY, + + @Desc("Four by four") + FOUR, + + @Desc("Five by five center") + FIVE_CENTER, + + @Desc("Five by five") + FIVE_ANY; + + public static boolean isAnySize(IrisTreeSize treeSize){ + return switch (treeSize) { + case THREE_CENTER, FIVE_CENTER -> false; + default -> true; + }; + } +} diff --git a/src/main/java/com/volmit/iris/engine/object/IrisTreeType.java b/src/main/java/com/volmit/iris/engine/object/IrisTreeType.java index 0d25f0e9d..df8728281 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisTreeType.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisTreeType.java @@ -47,22 +47,20 @@ public enum IrisTreeType { NONE; public static IrisTreeType fromTreeType(TreeType type){ - IrisTreeType irisType; - switch(type){ - case BIG_TREE, TREE -> irisType = IrisTreeType.OAK; - case MEGA_REDWOOD, REDWOOD, SWAMP, TALL_REDWOOD -> irisType = IrisTreeType.SPRUCE; - case BIRCH, TALL_BIRCH -> irisType = IrisTreeType.BIRCH; - case JUNGLE, SMALL_JUNGLE -> irisType = IrisTreeType.JUNGLE; - case RED_MUSHROOM -> irisType = IrisTreeType.RED_MUSHROOM; - case BROWN_MUSHROOM -> irisType = IrisTreeType.BROWN_MUSHROOM; - case ACACIA -> irisType = IrisTreeType.ACACIA; - case DARK_OAK -> irisType = IrisTreeType.DARK_OAK; - case CRIMSON_FUNGUS -> irisType = IrisTreeType.CRIMSON_FUNGUS; - case WARPED_FUNGUS -> irisType = IrisTreeType.WARPED_FUNGUS; - case AZALEA -> irisType = IrisTreeType.AZALEA; - //case COCOA_TREE, CHORUS_PLANT, JUNGLE_BUSH -> irisType = IrisSaplingType.NONE; - default -> irisType = IrisTreeType.NONE; - } - return irisType; + return switch(type){ + case BIG_TREE, TREE -> IrisTreeType.OAK; + case MEGA_REDWOOD, REDWOOD, SWAMP, TALL_REDWOOD -> IrisTreeType.SPRUCE; + case BIRCH, TALL_BIRCH -> IrisTreeType.BIRCH; + case JUNGLE, SMALL_JUNGLE -> IrisTreeType.JUNGLE; + case RED_MUSHROOM -> IrisTreeType.RED_MUSHROOM; + case BROWN_MUSHROOM -> IrisTreeType.BROWN_MUSHROOM; + case ACACIA -> IrisTreeType.ACACIA; + case DARK_OAK -> IrisTreeType.DARK_OAK; + case CRIMSON_FUNGUS -> IrisTreeType.CRIMSON_FUNGUS; + case WARPED_FUNGUS -> IrisTreeType.WARPED_FUNGUS; + case AZALEA -> IrisTreeType.AZALEA; + //case COCOA_TREE, CHORUS_PLANT, JUNGLE_BUSH -> IrisSaplingType.NONE; + default -> IrisTreeType.NONE; + }; } }