mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-19 18:55:18 +00:00
Rename & rewrite, add limits & checks, better delete
This commit is contained in:
parent
944ef83805
commit
af1b17cb98
@ -77,7 +77,7 @@ public class Iris extends VolmitPlugin implements Listener {
|
|||||||
public static BKLink linkBK;
|
public static BKLink linkBK;
|
||||||
public static MultiverseCoreLink linkMultiverseCore;
|
public static MultiverseCoreLink linkMultiverseCore;
|
||||||
public static MythicMobsLink linkMythicMobs;
|
public static MythicMobsLink linkMythicMobs;
|
||||||
public static SaplingManager saplingManager;
|
public static TreeManager saplingManager;
|
||||||
private static final Queue<Runnable> syncJobs = new ShurikenQueue<>();
|
private static final Queue<Runnable> syncJobs = new ShurikenQueue<>();
|
||||||
public static boolean customModels = doesSupportCustomModels();
|
public static boolean customModels = doesSupportCustomModels();
|
||||||
public static boolean awareEntities = doesSupportAwareness();
|
public static boolean awareEntities = doesSupportAwareness();
|
||||||
@ -233,7 +233,7 @@ public class Iris extends VolmitPlugin implements Listener {
|
|||||||
linkMultiverseCore = new MultiverseCoreLink();
|
linkMultiverseCore = new MultiverseCoreLink();
|
||||||
linkBK = new BKLink();
|
linkBK = new BKLink();
|
||||||
linkMythicMobs = new MythicMobsLink();
|
linkMythicMobs = new MythicMobsLink();
|
||||||
saplingManager = new SaplingManager();
|
saplingManager = new TreeManager();
|
||||||
edit = new EditManager();
|
edit = new EditManager();
|
||||||
configWatcher = new FileWatcher(getDataFile("settings.json"));
|
configWatcher = new FileWatcher(getDataFile("settings.json"));
|
||||||
J.a(() -> IO.delete(getTemp()));
|
J.a(() -> IO.delete(getTemp()));
|
||||||
|
@ -9,6 +9,7 @@ import com.volmit.iris.util.math.RNG;
|
|||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.TreeType;
|
import org.bukkit.TreeType;
|
||||||
|
import org.bukkit.block.data.type.Sapling;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.world.StructureGrowEvent;
|
import org.bukkit.event.world.StructureGrowEvent;
|
||||||
@ -16,11 +17,13 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
|
|
||||||
import java.util.Objects;
|
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.instance.registerListener(this);
|
||||||
Iris.info("Loading Sapling Manager");
|
Iris.info("Loading Sapling Manager");
|
||||||
}
|
}
|
||||||
@ -70,7 +73,9 @@ public class SaplingManager implements Listener {
|
|||||||
if (debugMe)
|
if (debugMe)
|
||||||
Iris.info("Dimension saplings: " + settings.getSaplings().toString());
|
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
|
// Check biome, region and dimension
|
||||||
treeObjects.addAll(getSaplingsFrom(biome.getSaplings(), event.getSpecies(), saplingSize));
|
treeObjects.addAll(getSaplingsFrom(biome.getSaplings(), event.getSpecies(), saplingSize));
|
||||||
@ -99,14 +104,24 @@ public class SaplingManager implements Listener {
|
|||||||
IrisObject pickedObject = IrisDataManager.loadAnyObject(pickedObjectString);
|
IrisObject pickedObject = IrisDataManager.loadAnyObject(pickedObjectString);
|
||||||
|
|
||||||
// Delete the saplings (some objects may not have blocks where the sapling is)
|
// Delete the saplings (some objects may not have blocks where the sapling is)
|
||||||
// TODO: Rewrite this to delete the saplings that matter
|
deleteSaplings(saplingLocations);
|
||||||
event.getBlocks().forEach(b -> b.setType(Material.AIR));
|
|
||||||
|
|
||||||
// Rotate and place the object
|
// Rotate and place the object
|
||||||
pickedObject.rotate(new IrisObjectRotation(), 0, 90 * RNG.r.i(0, 3), 0);
|
pickedObject.rotate(new IrisObjectRotation(), 0, 90 * RNG.r.i(0, 3), 0);
|
||||||
pickedObject.place(event.getLocation());
|
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
|
* Find all sapling types of the given TreeType in the container
|
||||||
* @param container Iris sapling config
|
* @param container Iris sapling config
|
||||||
@ -129,7 +144,6 @@ public class SaplingManager implements Listener {
|
|||||||
for (IrisTreeType configTreeType : sapling.getTreeTypes()) {
|
for (IrisTreeType configTreeType : sapling.getTreeTypes()) {
|
||||||
if (configTreeType == eventTreeType && size == sapling.getSize()) {
|
if (configTreeType == eventTreeType && size == sapling.getSize()) {
|
||||||
objects.addAll(sapling.getObjects());
|
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)
|
* 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
|
* @return The `x * x` area of saplings
|
||||||
*/
|
*/
|
||||||
private int getSaplingSize(Location location){
|
private int getSaplingSize(KList<Location> saplings){
|
||||||
// TODO: Write this
|
double size = Math.sqrt(saplings.size());
|
||||||
return 1;
|
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<>();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,5 +1,6 @@
|
|||||||
package com.volmit.iris.engine.object;
|
package com.volmit.iris.engine.object;
|
||||||
|
|
||||||
|
import com.volmit.iris.core.TreeManager;
|
||||||
import com.volmit.iris.engine.object.annotations.*;
|
import com.volmit.iris.engine.object.annotations.*;
|
||||||
import com.volmit.iris.util.collection.KList;
|
import com.volmit.iris.util.collection.KList;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
@ -17,7 +18,7 @@ public class IrisTree {
|
|||||||
|
|
||||||
@Required
|
@Required
|
||||||
@Desc("The types of trees overwritten")
|
@Desc("The types of trees overwritten")
|
||||||
@ArrayType(min = 1, type = TreeType.class)
|
@ArrayType(min = 1, type = IrisTreeType.class)
|
||||||
private KList<IrisTreeType> treeTypes;
|
private KList<IrisTreeType> treeTypes;
|
||||||
|
|
||||||
@RegistryListObject
|
@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)")
|
@Desc("The size of the square of saplings this applies to (2 means a 2 * 2 sapling area)")
|
||||||
@MinNumber(1)
|
@MinNumber(1)
|
||||||
@MaxNumber(5)
|
@MaxNumber(TreeManager.maxSaplingPlane)
|
||||||
private int size = 1;
|
private int size = 1;
|
||||||
}
|
}
|
@ -1,56 +1,49 @@
|
|||||||
package com.volmit.iris.engine.object;
|
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;
|
import org.bukkit.TreeType;
|
||||||
|
|
||||||
|
@Accessors(chain = true)
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Desc("Tree Types")
|
||||||
public enum IrisTreeType {
|
public enum IrisTreeType {
|
||||||
|
|
||||||
/**
|
@Desc("Oak tree (BIG_TREE, TREE)")
|
||||||
* Oak tree (BIG_TREE, TREE)
|
|
||||||
*/
|
|
||||||
OAK,
|
OAK,
|
||||||
/**
|
|
||||||
* Spruce tree (MEGA_REDWOOD, REDWOOD, SWAMP, TALL_REDWOOD)
|
@Desc("Spruce tree (MEGA_REDWOOD, REDWOOD, SWAMP, TALL_REDWOOD)")
|
||||||
*/
|
|
||||||
SPRUCE,
|
SPRUCE,
|
||||||
/**
|
|
||||||
* Birch tree (BIRCH, TALL_BIRCH)
|
@Desc("Birch tree (BIRCH, TALL_BIRCH)")
|
||||||
*/
|
|
||||||
BIRCH,
|
BIRCH,
|
||||||
/**
|
|
||||||
* Jungle tree (JUNGLE, SMALL_JUNGLE)
|
@Desc("Jungle tree (JUNGLE, SMALL_JUNGLE)")
|
||||||
*/
|
|
||||||
JUNGLE,
|
JUNGLE,
|
||||||
/**
|
|
||||||
* Big red mushroom; short and fat
|
@Desc("Big red mushroom; short and fat")
|
||||||
*/
|
|
||||||
RED_MUSHROOM,
|
RED_MUSHROOM,
|
||||||
/**
|
|
||||||
* Big brown mushroom; tall and umbrella-like
|
@Desc("Big brown mushroom; tall and umbrella-like")
|
||||||
*/
|
|
||||||
BROWN_MUSHROOM,
|
BROWN_MUSHROOM,
|
||||||
/**
|
|
||||||
* Acacia tree
|
@Desc("Acacia tree")
|
||||||
*/
|
|
||||||
ACACIA,
|
ACACIA,
|
||||||
/**
|
|
||||||
* Dark Oak tree
|
@Desc("Dark Oak tree")
|
||||||
*/
|
|
||||||
DARK_OAK,
|
DARK_OAK,
|
||||||
/**
|
|
||||||
* Large crimson fungus native to the nether
|
@Desc("Large crimson fungus native to the nether")
|
||||||
*/
|
|
||||||
CRIMSON_FUNGUS,
|
CRIMSON_FUNGUS,
|
||||||
/**
|
|
||||||
* Large warped fungus native to the nether
|
@Desc("Large warped fungus native to the nether")
|
||||||
*/
|
|
||||||
WARPED_FUNGUS,
|
WARPED_FUNGUS,
|
||||||
/**
|
|
||||||
* Tree with large roots which grows above lush caves
|
@Desc("Tree with large roots which grows above lush caves")
|
||||||
*/
|
|
||||||
AZALEA,
|
AZALEA,
|
||||||
/**
|
|
||||||
* The fallback type for all other non-supported growth events
|
@Desc("The fallback type for all other non-supported growth events")
|
||||||
*/
|
|
||||||
NONE;
|
NONE;
|
||||||
|
|
||||||
public static IrisTreeType fromTreeType(TreeType type){
|
public static IrisTreeType fromTreeType(TreeType type){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user