everything reworked

This commit is contained in:
CocoTheOwner
2021-07-18 17:21:29 +02:00
parent 20b3e95b4f
commit 944ef83805
9 changed files with 227 additions and 93 deletions
@@ -1,127 +1,148 @@
package com.volmit.iris.core;
import com.volmit.iris.Iris;
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.*;
import com.volmit.iris.util.collection.KList;
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.block.BlockPlaceEvent;
import org.bukkit.event.world.StructureGrowEvent;
import org.jetbrains.annotations.NotNull;
import java.util.Objects;
public class SaplingManager implements Listener {
private static final boolean debugMe = false;
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
/**This function does the following
* <br>1. Is the sapling growing in an Iris world? No -> exit</br>
* <br>2. Is the sapling overwriting setting on in that dimension? No -> exit</br>
* <br>3. Check biome for overrides for that sapling type -> Found -> use</br>
* <br>4. Check region ...</br>
* <br>5. Check dimension ...</br>
* <br>6. Exit if none are found</br>
* @param event Checks the given event for sapling overrides
*/
@EventHandler
public void onStructureGrowEvent(StructureGrowEvent event) {
// TODO: Remove this line
Iris.info("Sapling grew @ " + event.getLocation() + " for " + event.getSpecies().name() + " bonemealed is " + event.isFromBonemeal());
if (debugMe)
Iris.info("Sapling grew @ " + event.getLocation() + " for " + event.getSpecies().name() + " usedBoneMeal is " + event.isFromBonemeal());
// Must be iris world
if (!IrisWorlds.isIrisWorld(event.getWorld())) 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();
IrisAccess worldAccess;
try {
worldAccess = Objects.requireNonNull(IrisWorlds.access(event.getWorld()));
} catch (Throwable e) {
Iris.reportError(e);
return;
}
IrisTreeSettings settings = worldAccess.getCompound().getRootDimension().getSaplingSettings();
// TODO: Remove this line
IrisDimension dimension = IrisDataManager.loadAnyDimension("overworld");
if (debugMe) Iris.info("Custom saplings are enabled: " + (settings.isEnabled() ? "Yes" : "No"));
// Must have override enabled
if (!dimension.isOverrideSaplings()) return;
if (!settings.isEnabled()) return;
// TODO: Remove this line
Iris.info("Should replace sapling now!");
KList<String> treeObjects = new KList<>();
IrisAccess worldAccess = IrisWorlds.access(event.getWorld());
assert worldAccess != null;
KList<String> replace = null;
// Get biome and region
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());
// 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
}
}
}
if (debugMe)
Iris.info("Biome name: " + biome.getName() + " | List of saplings: " + biome.getSaplings().toString());
if (debugMe)
Iris.info("Region name: " + region.getName() + " | List of saplings: " + region.getSaplings().toString());
if (debugMe)
Iris.info("Dimension saplings: " + settings.getSaplings().toString());
int saplingSize = getSaplingSize(event.getLocation());
// Check biome, region and dimension
treeObjects.addAll(getSaplingsFrom(biome.getSaplings(), event.getSpecies(), saplingSize));
// 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
}
}
}
}
if (settings.getMode() == IrisTreeModes.ALL || treeObjects.size() == 0)
treeObjects.addAll(getSaplingsFrom(region.getSaplings(), event.getSpecies(), saplingSize));
// 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
}
}
}
}
if (settings.getMode() == IrisTreeModes.ALL || treeObjects.size() == 0)
treeObjects.addAll(getSaplingsFrom(settings.getSaplings(), event.getSpecies(), saplingSize));
if (debugMe) Iris.info("List of saplings (together): " + treeObjects);
// Check to make sure something was found
if (replace == null || replace.size() == 0) return;
if (treeObjects.size() == 0) return;
// Pick a random object from the list of objects found
String object = replace.get(RNG.r.i(0, replace.size() - 1));
String pickedObjectString = treeObjects.get(RNG.r.i(0, treeObjects.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());
if (debugMe) Iris.info("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)
// TODO: Rewrite this to delete the saplings that matter
event.getBlocks().forEach(b -> b.setType(Material.AIR));
// Rotate and place the object
pickedObject.rotate(new IrisObjectRotation(), 0, 90 * RNG.r.i(0, 3), 0);
pickedObject.place(event.getLocation());
}
/**
* 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<String> getSaplingsFrom(KList<IrisTree> container, TreeType tree, int size) {
// Translate TreeType to Iris TreeType
IrisTreeType eventTreeType = IrisTreeType.fromTreeType(tree);
KList<String> 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());
if (debugMe) Iris.info("Added replacements: " + sapling.getObjects().toString());
}
}
}
return objects;
}
/**
* Retrieve the `size * size` area of a sapling (any sapling in the area)
* @param location The location to start the search from
* @return The `x * x` area of saplings
*/
private int getSaplingSize(Location location){
// TODO: Write this
return 1;
}
}
@@ -49,6 +49,7 @@ public class DustRevealer {
if (a.getObject(block.getX(), block.getY(), block.getZ()) != null) {
sender.sendMessage("Found object " + a.getObject(block.getX(), block.getY(), block.getZ()));
Iris.info(sender.getName() + " found object " + a.getObject(block.getX(), block.getY(), block.getZ()));
J.a(() -> {
new DustRevealer(a, world, new BlockPosition(block.getX(), block.getY(), block.getZ()), a.getObject(block.getX(), block.getY(), block.getZ()), new KList<>());
});
@@ -82,8 +82,8 @@ public class IrisBiome extends IrisRegistrant implements IRare {
private KList<IrisEntityInitialSpawn> entityInitialSpawns = new KList<>();
@Desc("Sapling override settings")
@ArrayType(min = 1, type = IrisSapling.class)
private KList<IrisSapling> saplings = new KList<>();
@ArrayType(min = 1, type = IrisTree.class)
private KList<IrisTree> 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.")
@@ -74,11 +74,7 @@ public class IrisDimension extends IrisRegistrant {
private boolean aggressiveBiomeReshuffle = false;
@Desc("Sapling override settings")
@ArrayType(min = 1, type = IrisSapling.class)
private KList<IrisSapling> saplings = new KList<>();
@Desc("Enable sapling overrides")
private boolean overrideSaplings = false;
private IrisTreeSettings saplingSettings = new IrisTreeSettings();
@Desc("Instead of a flat bottom, applies a clamp (using this noise style) to the bottom instead of a flat bottom. Useful for carving out center-dimensions in a dimension composite world.")
@@ -80,8 +80,8 @@ public class IrisRegion extends IrisRegistrant implements IRare {
private KList<IrisEntityInitialSpawn> entityInitialSpawns = new KList<>();
@Desc("Sapling override settings")
@ArrayType(min = 1, type = IrisSapling.class)
private KList<IrisSapling> saplings = new KList<>();
@ArrayType(min = 1, type = IrisTree.class)
private KList<IrisTree> saplings = new KList<>();
@MinNumber(1)
@MaxNumber(128)
@@ -11,23 +11,23 @@ import org.bukkit.TreeType;
@Accessors(chain = true)
@AllArgsConstructor
@NoArgsConstructor
@Desc("Sapling override settings")
@Desc("Tree replace options")
@Data
public class IrisSapling {
public class IrisTree {
@Required
@Desc("The types of saplings overwritten")
@Desc("The types of trees overwritten")
@ArrayType(min = 1, type = TreeType.class)
private KList<TreeType> types;
private KList<IrisTreeType> treeTypes;
@RegistryListObject
@Required
@ArrayType(min = 1, type = String.class)
@Desc("List of objects to overwrite saplings with")
private KList<String> replace = new KList<>();
@Desc("List of objects to replace trees with")
private KList<String> objects = new KList<>();
@Desc("The size of the square of saplings this applies to (two means a 2 by 2 sapling area)")
@Desc("The size of the square of saplings this applies to (2 means a 2 * 2 sapling area)")
@MinNumber(1)
@MaxNumber(4)
@MaxNumber(5)
private int size = 1;
}
@@ -0,0 +1,12 @@
package com.volmit.iris.engine.object;
import com.volmit.iris.engine.object.annotations.Desc;
@Desc("Sapling override object picking options")
public enum IrisTreeModes {
@Desc("Check biome, then region, then dimension, pick the first one that has options")
FIRST,
@Desc("Check biome, regions, and dimensions, and pick any option from the total list")
ALL
}
@@ -0,0 +1,29 @@
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;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
@Accessors(chain = true)
@AllArgsConstructor
@NoArgsConstructor
@Desc("Tree growth override settings")
@Data
@EqualsAndHashCode(callSuper = false)
public class IrisTreeSettings {
@Desc("Turn replacing on and off")
boolean enabled = false;
@Desc("Object picking modes")
IrisTreeModes mode = IrisTreeModes.FIRST;
@Desc("Tree override list")
@ArrayType(min = 1, type = IrisTree.class)
private KList<IrisTree> saplings = new KList<>();
}
@@ -0,0 +1,75 @@
package com.volmit.iris.engine.object;
import org.bukkit.TreeType;
public enum IrisTreeType {
/**
* Oak tree (BIG_TREE, TREE)
*/
OAK,
/**
* Spruce tree (MEGA_REDWOOD, REDWOOD, SWAMP, TALL_REDWOOD)
*/
SPRUCE,
/**
* Birch tree (BIRCH, TALL_BIRCH)
*/
BIRCH,
/**
* Jungle tree (JUNGLE, SMALL_JUNGLE)
*/
JUNGLE,
/**
* Big red mushroom; short and fat
*/
RED_MUSHROOM,
/**
* Big brown mushroom; tall and umbrella-like
*/
BROWN_MUSHROOM,
/**
* Acacia tree
*/
ACACIA,
/**
* Dark Oak tree
*/
DARK_OAK,
/**
* Large crimson fungus native to the nether
*/
CRIMSON_FUNGUS,
/**
* Large warped fungus native to the nether
*/
WARPED_FUNGUS,
/**
* Tree with large roots which grows above lush caves
*/
AZALEA,
/**
* The fallback type for all other non-supported growth events
*/
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;
}
}