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; package com.volmit.iris.core;
import com.volmit.iris.Iris; 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.IrisWorlds;
import com.volmit.iris.engine.framework.IrisAccess; import com.volmit.iris.engine.framework.IrisAccess;
import com.volmit.iris.engine.object.*; import com.volmit.iris.engine.object.*;
import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.collection.KList;
import com.volmit.iris.util.math.RNG; import com.volmit.iris.util.math.RNG;
import org.bukkit.Location;
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.block.BlockPlaceEvent;
import org.bukkit.event.world.StructureGrowEvent; import org.bukkit.event.world.StructureGrowEvent;
import org.jetbrains.annotations.NotNull;
import java.util.Objects; import java.util.Objects;
public class SaplingManager implements Listener { public class SaplingManager implements Listener {
private static final boolean debugMe = false;
public SaplingManager() { public SaplingManager() {
Iris.instance.registerListener(this); Iris.instance.registerListener(this);
Iris.info("Loading Sapling Manager"); Iris.info("Loading Sapling Manager");
} }
/** /**This function does the following
* This function does the following: * <br>1. Is the sapling growing in an Iris world? No -> exit</br>
* 1. Is the sapling growing in an Iris world? No -> exit * <br>2. Is the sapling overwriting setting on in that dimension? No -> exit</br>
* 2. Is the sapling overwriting setting on in that dimension? No -> exit * <br>3. Check biome for overrides for that sapling type -> Found -> use</br>
* 3. Check biome for overrides for that sapling type -> Found -> use * <br>4. Check region ...</br>
* 4. Check region ... * <br>5. Check dimension ...</br>
* 5. Check dimension ... * <br>6. Exit if none are found</br>
* 6. Exit if none are found
* @param event Checks the given event for sapling overrides * @param event Checks the given event for sapling overrides
*/ */
@EventHandler @EventHandler
public void onStructureGrowEvent(StructureGrowEvent event) { public void onStructureGrowEvent(StructureGrowEvent event) {
// TODO: Remove this line if (debugMe)
Iris.info("Sapling grew @ " + event.getLocation() + " for " + event.getSpecies().name() + " bonemealed is " + event.isFromBonemeal()); 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 IrisAccess worldAccess;
boolean debug = true; try {
worldAccess = Objects.requireNonNull(IrisWorlds.access(event.getWorld()));
if (!debug) { } catch (Throwable e) {
// Must be iris world Iris.reportError(e);
if (!IrisWorlds.isIrisWorld(event.getWorld())) return; return;
IrisAccess worldAccess;
try {
worldAccess = Objects.requireNonNull(IrisWorlds.access(event.getWorld()));
} catch (Throwable e) {
Iris.reportError(e);
return;
}
IrisDimension dim = worldAccess.getCompound().getRootDimension();
} }
IrisTreeSettings settings = worldAccess.getCompound().getRootDimension().getSaplingSettings();
// TODO: Remove this line if (debugMe) Iris.info("Custom saplings are enabled: " + (settings.isEnabled() ? "Yes" : "No"));
IrisDimension dimension = IrisDataManager.loadAnyDimension("overworld");
// Must have override enabled // Must have override enabled
if (!dimension.isOverrideSaplings()) return; if (!settings.isEnabled()) return;
// TODO: Remove this line KList<String> treeObjects = new KList<>();
Iris.info("Should replace sapling now!");
IrisAccess worldAccess = IrisWorlds.access(event.getWorld()); // Get biome and region
assert worldAccess != null; IrisBiome biome = worldAccess.getBiome(event.getLocation().getBlockX(), event.getLocation().getBlockY(), event.getLocation().getBlockZ());
KList<String> replace = null; IrisRegion region = worldAccess.getCompound().getDefaultEngine().getRegion(event.getLocation().getBlockX(), event.getLocation().getBlockZ());
// Check biome if (debugMe)
IrisBiome biome = worldAccess.getBiome(event.getLocation().getBlockX(), event.getLocation().getBlockZ()); Iris.info("Biome name: " + biome.getName() + " | List of saplings: " + biome.getSaplings().toString());
for (IrisSapling sapling : biome.getSaplings()){ if (debugMe)
for (TreeType type : sapling.getTypes()){ Iris.info("Region name: " + region.getName() + " | List of saplings: " + region.getSaplings().toString());
if (type == event.getSpecies()){ if (debugMe)
replace = sapling.getReplace(); Iris.info("Dimension saplings: " + settings.getSaplings().toString());
// If we decide to do some sort of addition (biome + region + dim for options) we can do that here
} int saplingSize = getSaplingSize(event.getLocation());
}
} // Check biome, region and dimension
treeObjects.addAll(getSaplingsFrom(biome.getSaplings(), event.getSpecies(), saplingSize));
// Check region // Check region
if (replace == null) { if (settings.getMode() == IrisTreeModes.ALL || treeObjects.size() == 0)
IrisRegion region = worldAccess.getCompound().getDefaultEngine().getRegion(event.getLocation().getBlockX(), event.getLocation().getBlockZ()); treeObjects.addAll(getSaplingsFrom(region.getSaplings(), event.getSpecies(), saplingSize));
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 // Check dimension
if (replace == null) { if (settings.getMode() == IrisTreeModes.ALL || treeObjects.size() == 0)
for (IrisSapling sapling : dimension.getSaplings()) { treeObjects.addAll(getSaplingsFrom(settings.getSaplings(), event.getSpecies(), saplingSize));
for (TreeType type : sapling.getTypes()) {
if (type == event.getSpecies()) { if (debugMe) Iris.info("List of saplings (together): " + treeObjects);
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 // 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 // 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 // Cancel vanilla event
event.setCancelled(true); event.setCancelled(true);
// Retrieve & place the object // Retrieve & place the object
// TODO: Make this specific for this pack if (debugMe) Iris.info("Placing tree object instead of vanilla tree: " + pickedObjectString);
Iris.info("Placing tree object instead of vanilla tree: " + object); IrisObject pickedObject = IrisDataManager.loadAnyObject(pickedObjectString);
IrisObject obj = IrisDataManager.loadAnyObject(object);
obj.place(event.getLocation()); // 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) { if (a.getObject(block.getX(), block.getY(), block.getZ()) != null) {
sender.sendMessage("Found object " + a.getObject(block.getX(), block.getY(), block.getZ())); 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(() -> { J.a(() -> {
new DustRevealer(a, world, new BlockPosition(block.getX(), block.getY(), block.getZ()), a.getObject(block.getX(), block.getY(), block.getZ()), new KList<>()); 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<>(); private KList<IrisEntityInitialSpawn> entityInitialSpawns = new KList<>();
@Desc("Sapling override settings") @Desc("Sapling override settings")
@ArrayType(min = 1, type = IrisSapling.class) @ArrayType(min = 1, type = IrisTree.class)
private KList<IrisSapling> saplings = new KList<>(); private KList<IrisTree> saplings = new KList<>();
@ArrayType(min = 1, type = IrisEffect.class) @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 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; private boolean aggressiveBiomeReshuffle = false;
@Desc("Sapling override settings") @Desc("Sapling override settings")
@ArrayType(min = 1, type = IrisSapling.class) private IrisTreeSettings saplingSettings = new IrisTreeSettings();
private KList<IrisSapling> saplings = new KList<>();
@Desc("Enable sapling overrides")
private boolean overrideSaplings = false;
@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.") @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<>(); private KList<IrisEntityInitialSpawn> entityInitialSpawns = new KList<>();
@Desc("Sapling override settings") @Desc("Sapling override settings")
@ArrayType(min = 1, type = IrisSapling.class) @ArrayType(min = 1, type = IrisTree.class)
private KList<IrisSapling> saplings = new KList<>(); private KList<IrisTree> saplings = new KList<>();
@MinNumber(1) @MinNumber(1)
@MaxNumber(128) @MaxNumber(128)
@@ -11,23 +11,23 @@ import org.bukkit.TreeType;
@Accessors(chain = true) @Accessors(chain = true)
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
@Desc("Sapling override settings") @Desc("Tree replace options")
@Data @Data
public class IrisSapling { public class IrisTree {
@Required @Required
@Desc("The types of saplings overwritten") @Desc("The types of trees overwritten")
@ArrayType(min = 1, type = TreeType.class) @ArrayType(min = 1, type = TreeType.class)
private KList<TreeType> types; private KList<IrisTreeType> treeTypes;
@RegistryListObject @RegistryListObject
@Required @Required
@ArrayType(min = 1, type = String.class) @ArrayType(min = 1, type = String.class)
@Desc("List of objects to overwrite saplings with") @Desc("List of objects to replace trees with")
private KList<String> replace = new KList<>(); 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) @MinNumber(1)
@MaxNumber(4) @MaxNumber(5)
private int size = 1; 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;
}
}