mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-19 10:43:14 +00:00
Basic sapling manager logic. Needs polishing
This commit is contained in:
parent
8da9156bb5
commit
8d6a2e8882
@ -5,8 +5,9 @@ import com.volmit.iris.engine.IrisEngine;
|
||||
import com.volmit.iris.engine.IrisWorldManager;
|
||||
import com.volmit.iris.engine.IrisWorlds;
|
||||
import com.volmit.iris.engine.framework.IrisAccess;
|
||||
import com.volmit.iris.engine.object.IrisBiome;
|
||||
import com.volmit.iris.engine.object.IrisDimension;
|
||||
import com.volmit.iris.engine.object.*;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
import org.bukkit.TreeType;
|
||||
import org.bukkit.block.data.type.Sapling;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@ -20,29 +21,107 @@ public class SaplingManager implements Listener {
|
||||
|
||||
public SaplingManager() {
|
||||
Iris.instance.registerListener(this);
|
||||
Iris.info("Loading Sapling Manager");
|
||||
}
|
||||
|
||||
/**
|
||||
* This function does the following:
|
||||
* 1. Is the sapling growing in an Iris world? No -> exit
|
||||
* 2. Is the sapling overwriting setting on in that dimension? No -> exit
|
||||
* 3. Check biome for overrides for that sapling type -> Found -> use
|
||||
* 4. Check region ...
|
||||
* 5. Check dimension ...
|
||||
* 6. Exit if none are found
|
||||
* @param event Checks the given event for sapling overrides
|
||||
*/
|
||||
@EventHandler
|
||||
public void onStructureGrowEvent(StructureGrowEvent event) {
|
||||
|
||||
// Must be iris world
|
||||
if (!IrisWorlds.isIrisWorld(event.getWorld())) return;
|
||||
// TODO: Remove this line
|
||||
Iris.info("Sapling grew @ " + event.getLocation() + " for " + event.getSpecies().name() + " bonemealed is " + event.isFromBonemeal());
|
||||
|
||||
IrisAccess worldAccess;
|
||||
try {
|
||||
worldAccess = Objects.requireNonNull(IrisWorlds.access(event.getWorld()));
|
||||
} catch (Throwable e){
|
||||
Iris.reportError(e);
|
||||
return;
|
||||
|
||||
// TODO: Remove if statement here once Iris worlds are creatable again
|
||||
boolean debug = true;
|
||||
|
||||
if (!debug) {
|
||||
// Must be iris world
|
||||
if (!IrisWorlds.isIrisWorld(event.getWorld())) return;
|
||||
|
||||
IrisAccess worldAccess;
|
||||
try {
|
||||
worldAccess = Objects.requireNonNull(IrisWorlds.access(event.getWorld()));
|
||||
} catch (Throwable e) {
|
||||
Iris.reportError(e);
|
||||
return;
|
||||
}
|
||||
|
||||
IrisDimension dim = worldAccess.getCompound().getRootDimension();
|
||||
}
|
||||
IrisDimension dim = worldAccess.getCompound().getDefaultEngine().getDimension();
|
||||
|
||||
// Must have override enabled
|
||||
if (!dim.isOverrideSaplings()) return;
|
||||
|
||||
// TODO: Remove this line
|
||||
Iris.info("Sapling grew @ " + event.getLocation() + " for " + event.getSpecies().name() + " bonemealed is " + event.isFromBonemeal() + " by player " + Objects.requireNonNull(event.getPlayer()).getName());
|
||||
IrisDimension dimension = IrisDataManager.loadAnyDimension("overworld");
|
||||
|
||||
|
||||
// Must have override enabled
|
||||
if (!dimension.isOverrideSaplings()) return;
|
||||
|
||||
// TODO: Remove this line
|
||||
Iris.info("Should replace sapling now!");
|
||||
|
||||
IrisAccess worldAccess = IrisWorlds.access(event.getWorld());
|
||||
assert worldAccess != null;
|
||||
KList<String> replace = null;
|
||||
|
||||
// Check biome
|
||||
IrisBiome biome = worldAccess.getBiome(event.getLocation().getBlockX(), event.getLocation().getBlockZ());
|
||||
for (IrisSapling sapling : biome.getSaplings()){
|
||||
for (TreeType type : sapling.getTypes()){
|
||||
if (type == event.getSpecies()){
|
||||
replace = sapling.getReplace();
|
||||
// If we decide to do some sort of addition (biome + region + dim for options) we can do that here
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check region
|
||||
if (replace == null) {
|
||||
IrisRegion region = worldAccess.getCompound().getDefaultEngine().getRegion(event.getLocation().getBlockX(), event.getLocation().getBlockZ());
|
||||
for (IrisSapling sapling : region.getSaplings()) {
|
||||
for (TreeType type : sapling.getTypes()) {
|
||||
if (type == event.getSpecies()) {
|
||||
replace = sapling.getReplace();
|
||||
// If we decide to do some sort of addition (biome + region + dim for options) we can do that here
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check dimension
|
||||
if (replace == null) {
|
||||
for (IrisSapling sapling : dimension.getSaplings()) {
|
||||
for (TreeType type : sapling.getTypes()) {
|
||||
if (type == event.getSpecies()) {
|
||||
replace = sapling.getReplace();
|
||||
// If we decide to do some sort of addition (biome + region + dim for options) we can do that here
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check to make sure something was found
|
||||
if (replace == null || replace.size() == 0) return;
|
||||
|
||||
// Pick a random object from the list of objects found
|
||||
String object = replace.get(RNG.r.i(0, replace.size() - 1));
|
||||
|
||||
// Cancel vanilla event
|
||||
event.setCancelled(true);
|
||||
|
||||
// Retrieve & place the object
|
||||
// TODO: Make this specific for this pack
|
||||
Iris.info("Placing tree object instead of vanilla tree: " + object);
|
||||
IrisObject obj = IrisDataManager.loadAnyObject(object);
|
||||
obj.place(event.getLocation());
|
||||
}
|
||||
}
|
||||
|
@ -30,5 +30,4 @@ public class IrisSapling {
|
||||
@MinNumber(1)
|
||||
@MaxNumber(4)
|
||||
private int size = 1;
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user