Rename & rewrite, add limits & checks, better delete

This commit is contained in:
CocoTheOwner 2021-07-18 18:00:10 +02:00
parent 944ef83805
commit af1b17cb98
4 changed files with 74 additions and 51 deletions

View File

@ -77,7 +77,7 @@ public class Iris extends VolmitPlugin implements Listener {
public static BKLink linkBK;
public static MultiverseCoreLink linkMultiverseCore;
public static MythicMobsLink linkMythicMobs;
public static SaplingManager saplingManager;
public static TreeManager saplingManager;
private static final Queue<Runnable> syncJobs = new ShurikenQueue<>();
public static boolean customModels = doesSupportCustomModels();
public static boolean awareEntities = doesSupportAwareness();
@ -233,7 +233,7 @@ public class Iris extends VolmitPlugin implements Listener {
linkMultiverseCore = new MultiverseCoreLink();
linkBK = new BKLink();
linkMythicMobs = new MythicMobsLink();
saplingManager = new SaplingManager();
saplingManager = new TreeManager();
edit = new EditManager();
configWatcher = new FileWatcher(getDataFile("settings.json"));
J.a(() -> IO.delete(getTemp()));

View File

@ -9,6 +9,7 @@ import com.volmit.iris.util.math.RNG;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.TreeType;
import org.bukkit.block.data.type.Sapling;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.world.StructureGrowEvent;
@ -16,11 +17,13 @@ import org.jetbrains.annotations.NotNull;
import java.util.Objects;
public class SaplingManager implements Listener {
public class TreeManager implements Listener {
private static final boolean debugMe = false;
private static final boolean debugMe = true;
public SaplingManager() {
public static final int maxSaplingPlane = 5;
public TreeManager() {
Iris.instance.registerListener(this);
Iris.info("Loading Sapling Manager");
}
@ -70,7 +73,9 @@ public class SaplingManager implements Listener {
if (debugMe)
Iris.info("Dimension saplings: " + settings.getSaplings().toString());
int saplingSize = getSaplingSize(event.getLocation());
// Get sapling location
KList<Location> saplingLocations = getSaplingPlane(event.getLocation());
int saplingSize = getSaplingSize(saplingLocations);
// Check biome, region and dimension
treeObjects.addAll(getSaplingsFrom(biome.getSaplings(), event.getSpecies(), saplingSize));
@ -99,14 +104,24 @@ public class SaplingManager implements Listener {
IrisObject pickedObject = IrisDataManager.loadAnyObject(pickedObjectString);
// Delete the saplings (some objects may not have blocks where the sapling is)
// TODO: Rewrite this to delete the saplings that matter
event.getBlocks().forEach(b -> b.setType(Material.AIR));
deleteSaplings(saplingLocations);
// Rotate and place the object
pickedObject.rotate(new IrisObjectRotation(), 0, 90 * RNG.r.i(0, 3), 0);
pickedObject.place(event.getLocation());
}
/**
* Deletes all saplings at the
* @param locations sapling locations
*/
private void deleteSaplings(KList<Location> locations) {
locations.forEach(l -> {
if (debugMe) Iris.info("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
@ -129,7 +144,6 @@ public class SaplingManager implements Listener {
for (IrisTreeType configTreeType : sapling.getTreeTypes()) {
if (configTreeType == eventTreeType && size == sapling.getSize()) {
objects.addAll(sapling.getObjects());
if (debugMe) Iris.info("Added replacements: " + sapling.getObjects().toString());
}
}
}
@ -138,11 +152,26 @@ public class SaplingManager implements Listener {
/**
* Retrieve the `size * size` area of a sapling (any sapling in the area)
* @param location The location to start the search from
* @param saplings The locations of the saplings in the plane
* @return The `x * x` area of saplings
*/
private int getSaplingSize(Location location){
// TODO: Write this
return 1;
private int getSaplingSize(KList<Location> 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<Location> getSaplingPlane(Location location){
return new KList<>();
}
}

View File

@ -1,5 +1,6 @@
package com.volmit.iris.engine.object;
import com.volmit.iris.core.TreeManager;
import com.volmit.iris.engine.object.annotations.*;
import com.volmit.iris.util.collection.KList;
import lombok.AllArgsConstructor;
@ -17,7 +18,7 @@ public class IrisTree {
@Required
@Desc("The types of trees overwritten")
@ArrayType(min = 1, type = TreeType.class)
@ArrayType(min = 1, type = IrisTreeType.class)
private KList<IrisTreeType> treeTypes;
@RegistryListObject
@ -28,6 +29,6 @@ public class IrisTree {
@Desc("The size of the square of saplings this applies to (2 means a 2 * 2 sapling area)")
@MinNumber(1)
@MaxNumber(5)
@MaxNumber(TreeManager.maxSaplingPlane)
private int size = 1;
}

View File

@ -1,56 +1,49 @@
package com.volmit.iris.engine.object;
import com.volmit.iris.engine.object.annotations.Desc;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.bukkit.TreeType;
@Accessors(chain = true)
@NoArgsConstructor
@Desc("Tree Types")
public enum IrisTreeType {
/**
* Oak tree (BIG_TREE, TREE)
*/
@Desc("Oak tree (BIG_TREE, TREE)")
OAK,
/**
* Spruce tree (MEGA_REDWOOD, REDWOOD, SWAMP, TALL_REDWOOD)
*/
@Desc("Spruce tree (MEGA_REDWOOD, REDWOOD, SWAMP, TALL_REDWOOD)")
SPRUCE,
/**
* Birch tree (BIRCH, TALL_BIRCH)
*/
@Desc("Birch tree (BIRCH, TALL_BIRCH)")
BIRCH,
/**
* Jungle tree (JUNGLE, SMALL_JUNGLE)
*/
@Desc("Jungle tree (JUNGLE, SMALL_JUNGLE)")
JUNGLE,
/**
* Big red mushroom; short and fat
*/
@Desc("Big red mushroom; short and fat")
RED_MUSHROOM,
/**
* Big brown mushroom; tall and umbrella-like
*/
@Desc("Big brown mushroom; tall and umbrella-like")
BROWN_MUSHROOM,
/**
* Acacia tree
*/
@Desc("Acacia tree")
ACACIA,
/**
* Dark Oak tree
*/
@Desc("Dark Oak tree")
DARK_OAK,
/**
* Large crimson fungus native to the nether
*/
@Desc("Large crimson fungus native to the nether")
CRIMSON_FUNGUS,
/**
* Large warped fungus native to the nether
*/
@Desc("Large warped fungus native to the nether")
WARPED_FUNGUS,
/**
* Tree with large roots which grows above lush caves
*/
@Desc("Tree with large roots which grows above lush caves")
AZALEA,
/**
* The fallback type for all other non-supported growth events
*/
@Desc("The fallback type for all other non-supported growth events")
NONE;
public static IrisTreeType fromTreeType(TreeType type){