mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-09 09:16:34 +00:00
Merge pull request #43 from PolyhedralDev/agnostic
Platform-agnostic engine & TerraScript structures
This commit is contained in:
@@ -1,211 +0,0 @@
|
||||
package com.dfsek.terra;
|
||||
|
||||
import com.dfsek.tectonic.loading.TypeRegistry;
|
||||
import com.dfsek.terra.api.bukkit.BukkitWorldHandle;
|
||||
import com.dfsek.terra.api.generic.TerraPlugin;
|
||||
import com.dfsek.terra.api.generic.world.WorldHandle;
|
||||
import com.dfsek.terra.biome.grid.master.TerraBiomeGrid;
|
||||
import com.dfsek.terra.biome.palette.PaletteHolder;
|
||||
import com.dfsek.terra.biome.palette.PaletteLayer;
|
||||
import com.dfsek.terra.carving.CarverPalette;
|
||||
import com.dfsek.terra.command.TerraCommand;
|
||||
import com.dfsek.terra.command.structure.LocateCommand;
|
||||
import com.dfsek.terra.config.base.ConfigPack;
|
||||
import com.dfsek.terra.config.base.PluginConfig;
|
||||
import com.dfsek.terra.config.lang.LangUtil;
|
||||
import com.dfsek.terra.config.loaders.ImageLoaderLoader;
|
||||
import com.dfsek.terra.config.loaders.MaterialSetLoader;
|
||||
import com.dfsek.terra.config.loaders.ProbabilityCollectionLoader;
|
||||
import com.dfsek.terra.config.loaders.RangeLoader;
|
||||
import com.dfsek.terra.config.loaders.config.FloraLayerLoader;
|
||||
import com.dfsek.terra.config.loaders.config.GridSpawnLoader;
|
||||
import com.dfsek.terra.config.loaders.config.NoiseBuilderLoader;
|
||||
import com.dfsek.terra.config.loaders.config.OreConfigLoader;
|
||||
import com.dfsek.terra.config.loaders.config.OreHolderLoader;
|
||||
import com.dfsek.terra.config.loaders.config.StructureFeatureLoader;
|
||||
import com.dfsek.terra.config.loaders.config.TreeLayerLoader;
|
||||
import com.dfsek.terra.config.loaders.palette.CarverPaletteLoader;
|
||||
import com.dfsek.terra.config.loaders.palette.PaletteHolderLoader;
|
||||
import com.dfsek.terra.config.loaders.palette.PaletteLayerLoader;
|
||||
import com.dfsek.terra.debug.Debug;
|
||||
import com.dfsek.terra.generation.TerraChunkGenerator;
|
||||
import com.dfsek.terra.generation.config.NoiseBuilder;
|
||||
import com.dfsek.terra.generation.items.flora.FloraLayer;
|
||||
import com.dfsek.terra.generation.items.flora.TerraFlora;
|
||||
import com.dfsek.terra.generation.items.ores.Ore;
|
||||
import com.dfsek.terra.generation.items.ores.OreConfig;
|
||||
import com.dfsek.terra.generation.items.ores.OreHolder;
|
||||
import com.dfsek.terra.generation.items.tree.TreeLayer;
|
||||
import com.dfsek.terra.image.ImageLoader;
|
||||
import com.dfsek.terra.listeners.EventListener;
|
||||
import com.dfsek.terra.listeners.SpigotListener;
|
||||
import com.dfsek.terra.procgen.GridSpawn;
|
||||
import com.dfsek.terra.registry.ConfigRegistry;
|
||||
import com.dfsek.terra.structure.features.Feature;
|
||||
import com.dfsek.terra.util.MaterialSet;
|
||||
import com.dfsek.terra.util.PaperUtil;
|
||||
import com.dfsek.terra.util.StructureTypeEnum;
|
||||
import org.bstats.bukkit.Metrics;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.polydev.gaea.GaeaPlugin;
|
||||
import org.polydev.gaea.generation.GaeaChunkGenerator;
|
||||
import org.polydev.gaea.lang.Language;
|
||||
import org.polydev.gaea.math.ProbabilityCollection;
|
||||
import org.polydev.gaea.math.Range;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
|
||||
public class Terra extends GaeaPlugin implements TerraPlugin {
|
||||
private final Map<String, TerraChunkGenerator> generatorMap = new HashMap<>();
|
||||
private final Map<World, TerraWorld> worldMap = new HashMap<>();
|
||||
private final Map<String, ConfigPack> worlds = new HashMap<>();
|
||||
private final ConfigRegistry registry = new ConfigRegistry();
|
||||
private final PluginConfig config = new PluginConfig();
|
||||
private WorldHandle handle = new BukkitWorldHandle();
|
||||
|
||||
public void reload() {
|
||||
Map<World, TerraWorld> newMap = new HashMap<>();
|
||||
worldMap.forEach((world, tw) -> {
|
||||
String packID = tw.getConfig().getTemplate().getID();
|
||||
newMap.put(world, new TerraWorld(world, registry.get(packID)));
|
||||
});
|
||||
worldMap.clear();
|
||||
worldMap.putAll(newMap);
|
||||
}
|
||||
|
||||
public void setHandle(WorldHandle handle) {
|
||||
getLogger().warning("|-------------------------------------------------------|");
|
||||
getLogger().warning("A third-party addon has injected a custom WorldHandle!");
|
||||
getLogger().warning("If you encounter issues, try *without* the addon before");
|
||||
getLogger().warning("reporting to Terra. Report issues with the addon to the");
|
||||
getLogger().warning("addon's maintainers!");
|
||||
getLogger().warning("|-------------------------------------------------------|");
|
||||
this.handle = handle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
TerraChunkGenerator.saveAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
Debug.setLogger(getLogger()); // Set debug logger.
|
||||
|
||||
saveDefaultConfig();
|
||||
|
||||
Metrics metrics = new Metrics(this, 9017); // Set up bStats.
|
||||
metrics.addCustomChart(new Metrics.SingleLineChart("worlds", worldMap::size)); // World number chart.
|
||||
|
||||
config.load(this); // Load master config.yml
|
||||
LangUtil.load(config.getLanguage(), this); // Load language.
|
||||
Debug.setDebug(isDebug());
|
||||
|
||||
registry.loadAll(this); // Load all config packs.
|
||||
|
||||
PluginCommand c = Objects.requireNonNull(getCommand("terra"));
|
||||
TerraCommand command = new TerraCommand(this); // Set up main Terra command.
|
||||
c.setExecutor(command);
|
||||
c.setTabCompleter(command);
|
||||
|
||||
LocateCommand locate = new LocateCommand(command, false);
|
||||
PluginCommand locatePl = Objects.requireNonNull(getCommand("locate"));
|
||||
locatePl.setExecutor(locate); // Override locate command. Once Paper accepts StructureLocateEvent this will be unneeded on Paper implementations.
|
||||
locatePl.setTabCompleter(locate);
|
||||
|
||||
|
||||
long save = config.getDataSaveInterval();
|
||||
Bukkit.getScheduler().runTaskTimerAsynchronously(this, TerraChunkGenerator::saveAll, save, save); // Schedule population data saving
|
||||
|
||||
Bukkit.getPluginManager().registerEvents(new EventListener(this), this); // Register master event listener
|
||||
Bukkit.getPluginManager().registerEvents(new SpigotListener(this), this); // Register Spigot event listener, once Paper accepts StructureLocateEvent PR Spigot and Paper events will be separate.
|
||||
|
||||
PaperUtil.checkPaper(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable ChunkGenerator getDefaultWorldGenerator(@NotNull String worldName, @Nullable String id) {
|
||||
return generatorMap.computeIfAbsent(worldName, name -> {
|
||||
if(!registry.contains(id)) throw new IllegalArgumentException("No such config pack \"" + id + "\"");
|
||||
worlds.put(worldName, registry.get(id));
|
||||
return new TerraChunkGenerator(registry.get(id), this);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDebug() {
|
||||
return config.isDebug();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends GaeaChunkGenerator> getGeneratorClass() {
|
||||
return TerraChunkGenerator.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Language getLanguage() {
|
||||
return LangUtil.getLanguage();
|
||||
}
|
||||
|
||||
public void registerAllLoaders(TypeRegistry registry) {
|
||||
registry.registerLoader(ProbabilityCollection.class, new ProbabilityCollectionLoader())
|
||||
.registerLoader(Range.class, new RangeLoader())
|
||||
.registerLoader(CarverPalette.class, new CarverPaletteLoader())
|
||||
.registerLoader(GridSpawn.class, new GridSpawnLoader())
|
||||
.registerLoader(PaletteHolder.class, new PaletteHolderLoader())
|
||||
.registerLoader(PaletteLayer.class, new PaletteLayerLoader())
|
||||
.registerLoader(Biome.class, (t, o, l) -> Biome.valueOf((String) o))
|
||||
.registerLoader(BlockData.class, (t, o, l) -> Bukkit.createBlockData((String) o))
|
||||
.registerLoader(Material.class, (t, o, l) -> Material.matchMaterial((String) o))
|
||||
.registerLoader(FloraLayer.class, new FloraLayerLoader())
|
||||
.registerLoader(Ore.Type.class, (t, o, l) -> Ore.Type.valueOf((String) o))
|
||||
.registerLoader(OreConfig.class, new OreConfigLoader())
|
||||
.registerLoader(NoiseBuilder.class, new NoiseBuilderLoader())
|
||||
.registerLoader(TreeLayer.class, new TreeLayerLoader(this))
|
||||
.registerLoader(MaterialSet.class, new MaterialSetLoader())
|
||||
.registerLoader(OreHolder.class, new OreHolderLoader())
|
||||
.registerLoader(Feature.class, new StructureFeatureLoader())
|
||||
.registerLoader(ImageLoader.class, new ImageLoaderLoader())
|
||||
.registerLoader(EntityType.class, (t, o, l) -> EntityType.valueOf((String) o))
|
||||
.registerLoader(TerraBiomeGrid.Type.class, (t, o, l) -> TerraBiomeGrid.Type.valueOf((String) o))
|
||||
.registerLoader(StructureTypeEnum.class, (t, o, l) -> StructureTypeEnum.valueOf((String) o))
|
||||
.registerLoader(ImageLoader.Channel.class, (t, o, l) -> ImageLoader.Channel.valueOf((String) o))
|
||||
.registerLoader(ImageLoader.Align.class, (t, o, l) -> ImageLoader.Align.valueOf((String) o))
|
||||
.registerLoader(TerraFlora.Search.class, (t, o, l) -> TerraFlora.Search.valueOf((String) o));
|
||||
}
|
||||
|
||||
public ConfigRegistry getRegistry() {
|
||||
return registry;
|
||||
}
|
||||
|
||||
public TerraWorld getWorld(World w) {
|
||||
if(!(w.getGenerator() instanceof TerraChunkGenerator)) throw new IllegalArgumentException("Not a Terra world!");
|
||||
if(!worlds.containsKey(w.getName())) {
|
||||
getLogger().warning("Unexpected world load detected: \"" + w.getName() + "\"");
|
||||
return new TerraWorld(w, ((TerraChunkGenerator) w.getGenerator()).getConfigPack());
|
||||
}
|
||||
return worldMap.computeIfAbsent(w, world -> new TerraWorld(w, worlds.get(w.getName())));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public PluginConfig getTerraConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WorldHandle getHandle() {
|
||||
return handle;
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
package com.dfsek.terra;
|
||||
|
||||
import org.bukkit.World;
|
||||
import org.polydev.gaea.profiler.DataType;
|
||||
import org.polydev.gaea.profiler.Measurement;
|
||||
import org.polydev.gaea.profiler.WorldProfiler;
|
||||
|
||||
public class TerraProfiler extends WorldProfiler {
|
||||
public TerraProfiler(World w) {
|
||||
super(w);
|
||||
this
|
||||
.addMeasurement(new Measurement(1500000, DataType.PERIOD_MILLISECONDS), "FloraTime")
|
||||
.addMeasurement(new Measurement(10000000, DataType.PERIOD_MILLISECONDS), "TreeTime")
|
||||
.addMeasurement(new Measurement(1500000, DataType.PERIOD_MILLISECONDS), "OreTime")
|
||||
.addMeasurement(new Measurement(5000000, DataType.PERIOD_MILLISECONDS), "CaveTime")
|
||||
.addMeasurement(new Measurement(1500000, DataType.PERIOD_MILLISECONDS), "StructureTime")
|
||||
.addMeasurement(new Measurement(1500000, DataType.PERIOD_MILLISECONDS), "ElevationTime");
|
||||
}
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
package com.dfsek.terra;
|
||||
|
||||
import com.dfsek.terra.biome.BiomeZone;
|
||||
import com.dfsek.terra.biome.grid.master.TerraBiomeGrid;
|
||||
import com.dfsek.terra.biome.grid.master.TerraRadialBiomeGrid;
|
||||
import com.dfsek.terra.biome.grid.master.TerraStandardBiomeGrid;
|
||||
import com.dfsek.terra.config.base.ConfigPack;
|
||||
import com.dfsek.terra.config.base.ConfigPackTemplate;
|
||||
import com.dfsek.terra.config.builder.biomegrid.BiomeGridBuilder;
|
||||
import com.dfsek.terra.debug.Debug;
|
||||
import com.dfsek.terra.generation.TerraChunkGenerator;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.polydev.gaea.biome.BiomeGrid;
|
||||
|
||||
public class TerraWorld {
|
||||
private final TerraBiomeGrid grid;
|
||||
private final BiomeZone zone;
|
||||
private final ConfigPack config;
|
||||
private boolean safe;
|
||||
private final TerraProfiler profiler;
|
||||
|
||||
|
||||
public TerraWorld(World w, ConfigPack c) {
|
||||
safe = true;
|
||||
config = c;
|
||||
profiler = new TerraProfiler(w);
|
||||
|
||||
ConfigPackTemplate template = config.getTemplate();
|
||||
|
||||
int zoneSize = template.getGrids().size();
|
||||
|
||||
BiomeGrid[] definedGrids = new BiomeGrid[zoneSize];
|
||||
for(int i = 0; i < zoneSize; i++) {
|
||||
String partName = template.getGrids().get(i);
|
||||
try {
|
||||
BiomeGridBuilder g = config.getBiomeGrid(partName);
|
||||
BiomeGrid b = g.build(w, c);
|
||||
definedGrids[i] = b;
|
||||
} catch(NullPointerException e) {
|
||||
safe = false;
|
||||
Debug.stack(e);
|
||||
Bukkit.getLogger().severe("No such BiomeGrid " + partName);
|
||||
Bukkit.getLogger().severe("Please check configuration files for errors. Configuration errors will have been reported during initialization.");
|
||||
Bukkit.getLogger().severe("ONLY report this to Terra if you are SURE your config is error-free.");
|
||||
Bukkit.getLogger().severe("Terrain will NOT generate properly at this point. Correct your config before using your server!");
|
||||
}
|
||||
}
|
||||
zone = new BiomeZone(w, c, definedGrids);
|
||||
|
||||
if(template.getGridType().equals(TerraBiomeGrid.Type.RADIAL)) {
|
||||
BiomeGrid internal = config.getBiomeGrid(template.getRadialInternalGrid()).build(w, c);
|
||||
grid = new TerraRadialBiomeGrid(w, template.getGridFreqX(), template.getGridFreqZ(), zone, config, template.getRadialGridRadius(), internal);
|
||||
} else grid = new TerraStandardBiomeGrid(w, template.getGridFreqX(), template.getGridFreqZ(), zone, config);
|
||||
}
|
||||
|
||||
public static boolean isTerraWorld(World w) {
|
||||
return w.getGenerator() instanceof TerraChunkGenerator;
|
||||
}
|
||||
|
||||
public TerraBiomeGrid getGrid() {
|
||||
return grid;
|
||||
}
|
||||
|
||||
public ConfigPack getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
public BiomeZone getZone() {
|
||||
return zone;
|
||||
}
|
||||
|
||||
public boolean isSafe() {
|
||||
return safe;
|
||||
}
|
||||
|
||||
public TerraProfiler getProfiler() {
|
||||
return profiler;
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
package com.dfsek.terra.api.bukkit;
|
||||
|
||||
import com.dfsek.terra.api.generic.world.WorldHandle;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
|
||||
public class BukkitWorldHandle implements WorldHandle {
|
||||
@Override
|
||||
public void setBlockData(Block block, BlockData data, boolean physics) {
|
||||
block.setBlockData(data, physics);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockData getBlockData(Block block) {
|
||||
return block.getBlockData();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Material getType(Block block) {
|
||||
return block.getType();
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
package com.dfsek.terra.api.generic;
|
||||
|
||||
import com.dfsek.terra.api.generic.world.WorldHandle;
|
||||
|
||||
public interface TerraPlugin {
|
||||
WorldHandle getHandle();
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package com.dfsek.terra.api.generic.world;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
|
||||
/**
|
||||
* Interface to be implemented for world manipulation.
|
||||
*/
|
||||
public interface WorldHandle {
|
||||
void setBlockData(Block block, BlockData data, boolean physics);
|
||||
|
||||
BlockData getBlockData(Block block);
|
||||
|
||||
Material getType(Block block);
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
package com.dfsek.terra.async;
|
||||
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.biome.grid.master.TerraBiomeGrid;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.polydev.gaea.biome.Biome;
|
||||
import org.polydev.gaea.generation.GenerationPhase;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* Runnable that locates a biome asynchronously
|
||||
*/
|
||||
public class AsyncBiomeFinder extends AsyncFeatureFinder<Biome> {
|
||||
|
||||
public AsyncBiomeFinder(TerraBiomeGrid grid, Biome target, @NotNull Location origin, int startRadius, int maxRadius, Consumer<Vector> callback, Terra main) {
|
||||
super(grid, target, origin, startRadius, maxRadius, callback, main);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to get biome at location
|
||||
*
|
||||
* @param x X coordinate
|
||||
* @param z Z coordinate
|
||||
* @return Biome at coordinates
|
||||
*/
|
||||
@Override
|
||||
public boolean isValid(int x, int z, Biome target) {
|
||||
int res = main.getTerraConfig().getBiomeSearchResolution();
|
||||
return getGrid().getBiome(x * res, z * res, GenerationPhase.POST_GEN).equals(target);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector finalizeVector(Vector orig) {
|
||||
return orig.multiply(main.getTerraConfig().getBiomeSearchResolution());
|
||||
}
|
||||
}
|
||||
@@ -1,98 +0,0 @@
|
||||
package com.dfsek.terra.async;
|
||||
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.biome.grid.master.TerraBiomeGrid;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public abstract class AsyncFeatureFinder<T> implements Runnable {
|
||||
protected final TerraBiomeGrid grid;
|
||||
protected final T target;
|
||||
protected final int startRadius;
|
||||
protected final int maxRadius;
|
||||
protected final int centerX;
|
||||
protected final int centerZ;
|
||||
protected final World world;
|
||||
private final Consumer<Vector> callback;
|
||||
protected int searchSize = 1;
|
||||
protected final Terra main;
|
||||
|
||||
public AsyncFeatureFinder(TerraBiomeGrid grid, T target, @NotNull Location origin, int startRadius, int maxRadius, Consumer<Vector> callback, Terra main) {
|
||||
this.grid = grid;
|
||||
this.target = target;
|
||||
this.main = main;
|
||||
this.startRadius = startRadius;
|
||||
this.maxRadius = maxRadius;
|
||||
this.centerX = origin.getBlockX();
|
||||
this.centerZ = origin.getBlockZ();
|
||||
this.world = origin.getWorld();
|
||||
this.callback = callback;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
int x = centerX;
|
||||
int z = centerZ;
|
||||
|
||||
x /= searchSize;
|
||||
z /= searchSize;
|
||||
|
||||
int run = 1;
|
||||
boolean toggle = true;
|
||||
boolean found = false;
|
||||
|
||||
main:
|
||||
for(int i = startRadius; i < maxRadius; i++) {
|
||||
for(int j = 0; j < run; j++) {
|
||||
if(isValid(x, z, target)) {
|
||||
found = true;
|
||||
break main;
|
||||
}
|
||||
if(toggle) x += 1;
|
||||
else x -= 1;
|
||||
}
|
||||
for(int j = 0; j < run; j++) {
|
||||
if(isValid(x, z, target)) {
|
||||
found = true;
|
||||
break main;
|
||||
}
|
||||
if(toggle) z += 1;
|
||||
else z -= 1;
|
||||
}
|
||||
run++;
|
||||
toggle = !toggle;
|
||||
}
|
||||
Vector finalSpawn = found ? finalizeVector(new Vector(x, 0, z)) : null;
|
||||
Bukkit.getScheduler().runTask(main, () -> callback.accept(finalSpawn));
|
||||
}
|
||||
|
||||
|
||||
public abstract Vector finalizeVector(Vector orig);
|
||||
|
||||
public abstract boolean isValid(int x, int z, T target);
|
||||
|
||||
public T getTarget() {
|
||||
return target;
|
||||
}
|
||||
|
||||
public World getWorld() {
|
||||
return world;
|
||||
}
|
||||
|
||||
public TerraBiomeGrid getGrid() {
|
||||
return grid;
|
||||
}
|
||||
|
||||
public int getSearchSize() {
|
||||
return searchSize;
|
||||
}
|
||||
|
||||
public void setSearchSize(int searchSize) {
|
||||
this.searchSize = searchSize;
|
||||
}
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
package com.dfsek.terra.async;
|
||||
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.biome.UserDefinedBiome;
|
||||
import com.dfsek.terra.biome.grid.master.TerraBiomeGrid;
|
||||
import com.dfsek.terra.generation.items.TerraStructure;
|
||||
import com.dfsek.terra.procgen.GridSpawn;
|
||||
import com.dfsek.terra.structure.Rotation;
|
||||
import com.dfsek.terra.structure.Structure;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.polydev.gaea.util.FastRandom;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* Runnable to locate structures asynchronously
|
||||
*/
|
||||
public class AsyncStructureFinder extends AsyncFeatureFinder<TerraStructure> {
|
||||
public AsyncStructureFinder(TerraBiomeGrid grid, TerraStructure target, @NotNull Location origin, int startRadius, int maxRadius, Consumer<Vector> callback, Terra main) {
|
||||
super(grid, target, origin, startRadius, maxRadius, callback, main);
|
||||
setSearchSize(target.getSpawn().getWidth() + 2 * target.getSpawn().getSeparation());
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if coordinate pair is a valid structure spawn
|
||||
*
|
||||
* @param x X coordinate
|
||||
* @param z Z coordinate
|
||||
* @return Whether location is a valid spawn for StructureConfig
|
||||
*/
|
||||
public boolean isValid(int x, int z, TerraStructure target) {
|
||||
World world = getWorld();
|
||||
Location spawn = target.getSpawn().getChunkSpawn(x, z, world.getSeed()).toLocation(world);
|
||||
if(!((UserDefinedBiome) grid.getBiome(spawn)).getConfig().getStructures().contains(target)) return false;
|
||||
Random r2 = new FastRandom(spawn.hashCode());
|
||||
Structure struc = target.getStructures().get(r2);
|
||||
Rotation rotation = Rotation.fromDegrees(r2.nextInt(4) * 90);
|
||||
for(int y = target.getSpawnStart().get(r2); y > target.getBound().getMin(); y--) {
|
||||
if(!target.getBound().isInRange(y)) return false;
|
||||
spawn.setY(y);
|
||||
if(!struc.checkSpawns(spawn, rotation, main)) continue;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector finalizeVector(Vector orig) {
|
||||
GridSpawn spawn = target.getSpawn();
|
||||
return spawn.getChunkSpawn(orig.getBlockX(), orig.getBlockZ(), world.getSeed());
|
||||
}
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
package com.dfsek.terra.biome;
|
||||
|
||||
import com.dfsek.terra.config.base.ConfigPack;
|
||||
import com.dfsek.terra.config.base.ConfigPackTemplate;
|
||||
import com.dfsek.terra.image.ImageLoader;
|
||||
import org.bukkit.World;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.polydev.gaea.biome.BiomeGrid;
|
||||
import org.polydev.gaea.biome.NormalizationUtil;
|
||||
import org.polydev.gaea.math.FastNoiseLite;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Holds 1D array of BiomeGrids.
|
||||
*/
|
||||
public class BiomeZone {
|
||||
private final BiomeGrid[] grids;
|
||||
private final FastNoiseLite noise;
|
||||
@Nullable
|
||||
private final ImageLoader imageLoader;
|
||||
private final boolean useImage;
|
||||
private final ImageLoader.Channel channel;
|
||||
|
||||
public BiomeZone(World w, ConfigPack wc, BiomeGrid[] grids) {
|
||||
this.noise = new FastNoiseLite((int) w.getSeed() + 2);
|
||||
this.noise.setNoiseType(FastNoiseLite.NoiseType.OpenSimplex2);
|
||||
this.noise.setFractalType(FastNoiseLite.FractalType.FBm);
|
||||
this.noise.setFractalOctaves(4);
|
||||
ConfigPackTemplate t = wc.getTemplate();
|
||||
this.noise.setFrequency(1D / t.getZoneFreq());
|
||||
this.grids = grids;
|
||||
imageLoader = t.getImageLoader();
|
||||
useImage = t.isFromImage();
|
||||
channel = t.getZoneChannel();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get BiomeGrid at location
|
||||
*
|
||||
* @param x X coordinate
|
||||
* @param z Z coordinate
|
||||
* @return BiomeGrid at coordinates.
|
||||
*/
|
||||
public BiomeGrid getGrid(int x, int z) {
|
||||
return grids[NormalizationUtil.normalize(useImage ? Objects.requireNonNull(imageLoader).getNoiseVal(x, z, channel) : noise.getNoise(x, z), grids.length, 4)];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of BiomeGrids this BiomeZone holds.
|
||||
*
|
||||
* @return Number of grids
|
||||
*/
|
||||
public int getSize() {
|
||||
return grids.length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the normalized grid noise at location
|
||||
*
|
||||
* @param x X coordinate
|
||||
* @param z Z coordinate
|
||||
* @return Normalized noise at coordinates
|
||||
*/
|
||||
public int getNoise(int x, int z) {
|
||||
return NormalizationUtil.normalize(useImage ? Objects.requireNonNull(imageLoader).getNoiseVal(x, z, channel) : noise.getNoise(x, z), grids.length, 4);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get raw grid noise at location
|
||||
*
|
||||
* @param x X coordinate
|
||||
* @param z Z coordinate
|
||||
* @return Raw noise at coordinates
|
||||
*/
|
||||
public double getRawNoise(int x, int z) {
|
||||
return useImage ? Objects.requireNonNull(imageLoader).getNoiseVal(x, z, channel) : noise.getNoise(x, z);
|
||||
}
|
||||
}
|
||||
@@ -1,97 +0,0 @@
|
||||
package com.dfsek.terra.biome;
|
||||
|
||||
import com.dfsek.terra.config.base.ConfigPack;
|
||||
import com.dfsek.terra.config.builder.GeneratorBuilder;
|
||||
import com.dfsek.terra.config.templates.BiomeTemplate;
|
||||
import com.dfsek.terra.generation.UserDefinedDecorator;
|
||||
import org.bukkit.World;
|
||||
import org.polydev.gaea.biome.Biome;
|
||||
import org.polydev.gaea.biome.Decorator;
|
||||
import org.polydev.gaea.biome.Generator;
|
||||
import org.polydev.gaea.structures.features.Feature;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Class representing a config-defined biome
|
||||
*/
|
||||
public class UserDefinedBiome implements Biome {
|
||||
private final GeneratorBuilder gen;
|
||||
private final UserDefinedDecorator decorator;
|
||||
private final org.bukkit.block.Biome vanilla;
|
||||
private final String id;
|
||||
private final BiomeTemplate config;
|
||||
private final ConfigPack pack;
|
||||
private UserDefinedBiome erode;
|
||||
|
||||
|
||||
public UserDefinedBiome(org.bukkit.block.Biome vanilla, UserDefinedDecorator dec, GeneratorBuilder gen, BiomeTemplate config, ConfigPack pack) {
|
||||
this.vanilla = vanilla;
|
||||
this.decorator = dec;
|
||||
this.gen = gen;
|
||||
this.id = config.getID();
|
||||
this.config = config;
|
||||
this.pack = pack;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Vanilla biome to represent the custom biome.
|
||||
*
|
||||
* @return Biome - The Vanilla biome.
|
||||
*/
|
||||
@Override
|
||||
public org.bukkit.block.Biome getVanillaBiome() {
|
||||
return vanilla;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Generator instance used to generate the biome.
|
||||
*
|
||||
* @return Generator - The terrain generation instance.
|
||||
*/
|
||||
@Override
|
||||
public Generator getGenerator() {
|
||||
return gen.build(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a list of Structure Features to be applied to all structures in the biome.
|
||||
*
|
||||
* @return List<Feature> - The list of Features.
|
||||
*/
|
||||
@Override
|
||||
public List<Feature> getStructureFeatures() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Decorator instance containing information about the population in the biome.
|
||||
*
|
||||
* @return Decorator - the Decorator instance.
|
||||
*/
|
||||
@Override
|
||||
public Decorator getDecorator() {
|
||||
return decorator;
|
||||
}
|
||||
|
||||
public String getID() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public UserDefinedBiome getErode() {
|
||||
if(erode == null) {
|
||||
erode = (config.getErode() == null) ? this : pack.getBiome(config.getErode());
|
||||
}
|
||||
return erode;
|
||||
}
|
||||
|
||||
|
||||
public BiomeTemplate getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Generator getGenerator(World w) {
|
||||
return gen.build(w.getSeed());
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
package com.dfsek.terra.biome.grid;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.polydev.gaea.biome.Biome;
|
||||
import org.polydev.gaea.biome.BiomeGrid;
|
||||
import org.polydev.gaea.generation.GenerationPhase;
|
||||
|
||||
/**
|
||||
* BiomeGrid implementation that holds a single biome.
|
||||
*/
|
||||
public class SingleBiomeGrid extends BiomeGrid {
|
||||
private final Biome biome;
|
||||
|
||||
public SingleBiomeGrid(World w, Biome biome) {
|
||||
super(w, 0, 0, 1, 1);
|
||||
this.biome = biome;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Biome getBiome(int x, int z, GenerationPhase phase) {
|
||||
return biome;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Biome getBiome(Location l) {
|
||||
return biome;
|
||||
}
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
package com.dfsek.terra.biome.grid;
|
||||
|
||||
import com.dfsek.terra.config.base.ConfigPack;
|
||||
import com.dfsek.terra.config.base.ConfigPackTemplate;
|
||||
import com.dfsek.terra.image.ImageLoader;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.polydev.gaea.biome.Biome;
|
||||
import org.polydev.gaea.biome.BiomeGrid;
|
||||
import org.polydev.gaea.biome.NormalizationUtil;
|
||||
import org.polydev.gaea.generation.GenerationPhase;
|
||||
|
||||
public class UserDefinedGrid extends BiomeGrid {
|
||||
private final ImageLoader imageLoader;
|
||||
private final boolean fromImage;
|
||||
private final ImageLoader.Channel channelX;
|
||||
private final ImageLoader.Channel channelZ;
|
||||
|
||||
public UserDefinedGrid(World w, double freq1, double freq2, Biome[][] b, ConfigPack c) {
|
||||
super(w, freq1, freq2, b.length, b[0].length);
|
||||
super.setGrid(b);
|
||||
ConfigPackTemplate t = c.getTemplate();
|
||||
imageLoader = t.getImageLoader();
|
||||
fromImage = t.isFromImage();
|
||||
channelX = t.getBiomeXChannel();
|
||||
channelZ = t.getBiomeZChannel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Biome getBiome(int x, int z, GenerationPhase phase) {
|
||||
if(fromImage) {
|
||||
double xi = imageLoader.getNoiseVal(x, z, channelX);
|
||||
double zi = imageLoader.getNoiseVal(x, z, channelZ);
|
||||
return super.getGrid()[NormalizationUtil.normalize(xi, getSizeX(), 4)][NormalizationUtil.normalize(zi, getSizeZ(), 4)];
|
||||
}
|
||||
return super.getBiome(x, z, phase);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Biome getBiome(Location l, GenerationPhase phase) {
|
||||
return this.getBiome(l.getBlockX(), l.getBlockZ(), phase);
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
package com.dfsek.terra.biome.grid.master;
|
||||
|
||||
import com.dfsek.terra.biome.grid.UserDefinedGrid;
|
||||
import org.bukkit.World;
|
||||
import org.polydev.gaea.biome.BiomeGrid;
|
||||
|
||||
public abstract class TerraBiomeGrid extends BiomeGrid {
|
||||
public TerraBiomeGrid(World w, double freq1, double freq2, int sizeX, int sizeZ) {
|
||||
super(w, freq1, freq2, sizeX, sizeZ);
|
||||
}
|
||||
|
||||
public abstract UserDefinedGrid getGrid(int x, int z);
|
||||
|
||||
public enum Type {
|
||||
RADIAL, STANDARD
|
||||
}
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
package com.dfsek.terra.biome.grid.master;
|
||||
|
||||
import com.dfsek.terra.biome.BiomeZone;
|
||||
import com.dfsek.terra.biome.UserDefinedBiome;
|
||||
import com.dfsek.terra.biome.grid.UserDefinedGrid;
|
||||
import com.dfsek.terra.biome.postprocessing.CoordinatePerturb;
|
||||
import com.dfsek.terra.biome.postprocessing.ErosionNoise;
|
||||
import com.dfsek.terra.config.base.ConfigPack;
|
||||
import com.dfsek.terra.config.base.ConfigPackTemplate;
|
||||
import com.dfsek.terra.procgen.math.Vector2;
|
||||
import net.jafama.FastMath;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.polydev.gaea.biome.Biome;
|
||||
import org.polydev.gaea.biome.BiomeGrid;
|
||||
import org.polydev.gaea.generation.GenerationPhase;
|
||||
|
||||
public class TerraRadialBiomeGrid extends TerraBiomeGrid {
|
||||
private static final int failNum = 0;
|
||||
private final BiomeZone zone;
|
||||
private final double radiusSq;
|
||||
private final BiomeGrid internal;
|
||||
private CoordinatePerturb perturb;
|
||||
private ErosionNoise erode;
|
||||
|
||||
public TerraRadialBiomeGrid(World w, double freq1, double freq2, BiomeZone zone, ConfigPack c, double radius, BiomeGrid internal) {
|
||||
super(w, freq1, freq2, 0, 0);
|
||||
ConfigPackTemplate t = c.getTemplate();
|
||||
if(c.getTemplate().isBlend()) {
|
||||
perturb = new CoordinatePerturb(t.getBlendFreq(), t.getBlendAmp(), w.getSeed());
|
||||
}
|
||||
this.zone = zone;
|
||||
if(c.getTemplate().isErode()) {
|
||||
erode = new ErosionNoise(t.getErodeFreq(), t.getErodeThresh(), t.getErodeOctaves(), w.getSeed());
|
||||
}
|
||||
this.radiusSq = FastMath.pow2(radius);
|
||||
this.internal = internal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserDefinedGrid getGrid(int x, int z) {
|
||||
return (UserDefinedGrid) zone.getGrid(x, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Biome getBiome(int x, int z, GenerationPhase phase) {
|
||||
int xp = x, zp = z;
|
||||
if(perturb != null && (phase.equals(GenerationPhase.PALETTE_APPLY) || phase.equals(GenerationPhase.POPULATE))) {
|
||||
Vector2 perturbCoords = perturb.getShiftedCoords(x, z);
|
||||
xp = (int) perturbCoords.getX();
|
||||
zp = (int) perturbCoords.getZ();
|
||||
}
|
||||
|
||||
UserDefinedBiome b;
|
||||
if(x * x + z * z > radiusSq) {
|
||||
b = (UserDefinedBiome) zone.getGrid(xp, zp).getBiome(xp, zp, phase);
|
||||
} else {
|
||||
b = (UserDefinedBiome) internal.getBiome(xp, zp, phase);
|
||||
}
|
||||
if(erode != null && erode.isEroded(xp, zp)) return b.getErode();
|
||||
return b;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Biome getBiome(Location l, GenerationPhase phase) {
|
||||
return getBiome(l.getBlockX(), l.getBlockZ(), phase);
|
||||
}
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
package com.dfsek.terra.biome.grid.master;
|
||||
|
||||
import com.dfsek.terra.biome.BiomeZone;
|
||||
import com.dfsek.terra.biome.UserDefinedBiome;
|
||||
import com.dfsek.terra.biome.grid.UserDefinedGrid;
|
||||
import com.dfsek.terra.biome.postprocessing.CoordinatePerturb;
|
||||
import com.dfsek.terra.biome.postprocessing.ErosionNoise;
|
||||
import com.dfsek.terra.config.base.ConfigPack;
|
||||
import com.dfsek.terra.config.base.ConfigPackTemplate;
|
||||
import com.dfsek.terra.procgen.math.Vector2;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.polydev.gaea.biome.Biome;
|
||||
import org.polydev.gaea.generation.GenerationPhase;
|
||||
|
||||
public class TerraStandardBiomeGrid extends TerraBiomeGrid {
|
||||
private static final int failNum = 0;
|
||||
private final BiomeZone zone;
|
||||
private CoordinatePerturb perturb;
|
||||
private ErosionNoise erode;
|
||||
|
||||
public TerraStandardBiomeGrid(World w, double freq1, double freq2, BiomeZone zone, ConfigPack c) {
|
||||
super(w, freq1, freq2, 0, 0);
|
||||
ConfigPackTemplate t = c.getTemplate();
|
||||
if(c.getTemplate().isBlend()) {
|
||||
perturb = new CoordinatePerturb(t.getBlendFreq(), t.getBlendAmp(), w.getSeed());
|
||||
}
|
||||
this.zone = zone;
|
||||
if(c.getTemplate().isErode()) {
|
||||
erode = new ErosionNoise(t.getErodeFreq(), t.getErodeThresh(), t.getErodeOctaves(), w.getSeed());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserDefinedGrid getGrid(int x, int z) {
|
||||
return (UserDefinedGrid) zone.getGrid(x, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Biome getBiome(int x, int z, GenerationPhase phase) {
|
||||
int xp = x, zp = z;
|
||||
if(perturb != null && (phase.equals(GenerationPhase.PALETTE_APPLY) || phase.equals(GenerationPhase.POPULATE))) {
|
||||
Vector2 perturbCoords = perturb.getShiftedCoords(x, z);
|
||||
xp = (int) perturbCoords.getX();
|
||||
zp = (int) perturbCoords.getZ();
|
||||
}
|
||||
|
||||
UserDefinedBiome b = (UserDefinedBiome) zone.getGrid(xp, zp).getBiome(xp, zp, phase);
|
||||
if(erode != null && erode.isEroded(xp, zp)) return b.getErode();
|
||||
return b;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Biome getBiome(Location l, GenerationPhase phase) {
|
||||
return getBiome(l.getBlockX(), l.getBlockZ(), phase);
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package com.dfsek.terra.biome.palette;
|
||||
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.polydev.gaea.world.palette.Palette;
|
||||
|
||||
public class PaletteHolder {
|
||||
private final Palette<BlockData>[] palettes;
|
||||
|
||||
protected PaletteHolder(Palette<BlockData>[] palettes) {
|
||||
this.palettes = palettes;
|
||||
}
|
||||
|
||||
public Palette<BlockData> getPalette(int y) {
|
||||
return palettes[y];
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
package com.dfsek.terra.biome.palette;
|
||||
|
||||
import com.dfsek.terra.util.PaletteUtil;
|
||||
import net.jafama.FastMath;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.polydev.gaea.world.palette.Palette;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class PaletteHolderBuilder {
|
||||
private final TreeMap<Integer, Palette<BlockData>> paletteMap = new TreeMap<>();
|
||||
|
||||
public PaletteHolderBuilder add(int y, Palette<BlockData> palette) {
|
||||
paletteMap.put(y, palette);
|
||||
return this;
|
||||
}
|
||||
|
||||
@SuppressWarnings({"unchecked", "rawtypes", "RedundantSuppression"})
|
||||
public PaletteHolder build() {
|
||||
Palette<BlockData>[] palettes = new Palette[paletteMap.lastKey() + 1];
|
||||
for(int y = 0; y <= FastMath.max(paletteMap.lastKey(), 255); y++) {
|
||||
Palette<BlockData> d = PaletteUtil.BLANK_PALETTE;
|
||||
for(Map.Entry<Integer, Palette<BlockData>> e : paletteMap.entrySet()) {
|
||||
if(e.getKey() >= y) {
|
||||
d = e.getValue();
|
||||
break;
|
||||
}
|
||||
}
|
||||
palettes[y] = d;
|
||||
}
|
||||
return new PaletteHolder(palettes);
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
package com.dfsek.terra.biome.palette;
|
||||
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.polydev.gaea.math.ProbabilityCollection;
|
||||
|
||||
public class PaletteLayer {
|
||||
private final ProbabilityCollection<BlockData> layer;
|
||||
private final int size;
|
||||
|
||||
public PaletteLayer(@NotNull ProbabilityCollection<BlockData> layer, int size) {
|
||||
this.layer = layer;
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ProbabilityCollection<BlockData> getLayer() {
|
||||
return layer;
|
||||
}
|
||||
|
||||
public int getSize() {
|
||||
return size;
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package com.dfsek.terra.biome.palette;
|
||||
|
||||
import org.polydev.gaea.world.palette.Palette;
|
||||
|
||||
public class SinglePalette<E> extends Palette<E> {
|
||||
private final E item;
|
||||
|
||||
public SinglePalette(E item) {
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public E get(int i, int i1, int i2) {
|
||||
return item;
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
package com.dfsek.terra.biome.postprocessing;
|
||||
|
||||
import com.dfsek.terra.procgen.math.Vector2;
|
||||
import org.polydev.gaea.math.FastNoiseLite;
|
||||
|
||||
/**
|
||||
* Offset a coordinate pair by an amount.
|
||||
*/
|
||||
public class CoordinatePerturb {
|
||||
private final FastNoiseLite perturbX;
|
||||
private final FastNoiseLite perturbZ;
|
||||
private final double amplitude;
|
||||
|
||||
/**
|
||||
* Create a CoordinatePerturb object with a given frequency, amplitude, and seed.
|
||||
*
|
||||
* @param frequency Noise frequency
|
||||
* @param amplitude Offset amplitude
|
||||
* @param seed Noise seed
|
||||
*/
|
||||
public CoordinatePerturb(double frequency, double amplitude, long seed) {
|
||||
perturbX = new FastNoiseLite((int) seed);
|
||||
perturbX.setNoiseType(FastNoiseLite.NoiseType.OpenSimplex2);
|
||||
perturbX.setFrequency(frequency);
|
||||
perturbZ = new FastNoiseLite((int) seed + 1);
|
||||
perturbZ.setNoiseType(FastNoiseLite.NoiseType.OpenSimplex2);
|
||||
perturbZ.setFrequency(frequency);
|
||||
this.amplitude = amplitude;
|
||||
}
|
||||
|
||||
/**
|
||||
* Offset a coordinate pair
|
||||
*
|
||||
* @param x X coordinate
|
||||
* @param z Z coordinate
|
||||
* @return Vector2 containing offset coordinates
|
||||
*/
|
||||
public Vector2 getShiftedCoords(int x, int z) {
|
||||
return new Vector2(perturbX.getNoise(x, z) * amplitude + x, perturbZ.getNoise(x, z) * amplitude + z);
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
package com.dfsek.terra.biome.postprocessing;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
import org.polydev.gaea.math.FastNoiseLite;
|
||||
|
||||
/**
|
||||
* Class to hold noise function to determine erosion.
|
||||
*/
|
||||
public class ErosionNoise {
|
||||
private final double thresh;
|
||||
private final FastNoiseLite noise;
|
||||
|
||||
public ErosionNoise(double freq1, double thresh, int octaves, long seed) {
|
||||
FastNoiseLite main = new FastNoiseLite((int) (seed + 1));
|
||||
main.setNoiseType(FastNoiseLite.NoiseType.OpenSimplex2);
|
||||
main.setFractalType(FastNoiseLite.FractalType.FBm);
|
||||
main.setFractalOctaves(octaves);
|
||||
main.setFrequency(freq1);
|
||||
this.thresh = thresh;
|
||||
this.noise = main;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get whether a location is eroded
|
||||
*
|
||||
* @param x X coordinate
|
||||
* @param z Z coordinate
|
||||
* @return Whether location is eroded
|
||||
*/
|
||||
public boolean isEroded(int x, int z) {
|
||||
double abs = FastMath.pow(noise.getNoise(x, z), 2);
|
||||
return abs < thresh;
|
||||
}
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
package com.dfsek.terra.carving;
|
||||
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.biome.UserDefinedBiome;
|
||||
import com.dfsek.terra.biome.grid.master.TerraBiomeGrid;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.polydev.gaea.biome.Biome;
|
||||
import org.polydev.gaea.generation.GenerationPhase;
|
||||
import org.polydev.gaea.math.MathUtil;
|
||||
import org.polydev.gaea.util.FastRandom;
|
||||
import org.polydev.gaea.util.GlueList;
|
||||
import org.polydev.gaea.world.carving.Worm;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
public class CarverCache {
|
||||
|
||||
private final World w;
|
||||
private final Map<Long, List<Worm.WormPoint>> carvers = new HashMap<>();
|
||||
private final Terra main;
|
||||
|
||||
public CarverCache(World w, Terra main) {
|
||||
this.w = w;
|
||||
this.main = main;
|
||||
}
|
||||
|
||||
public List<Worm.WormPoint> getPoints(int chunkX, int chunkZ, UserDefinedCarver carver) {
|
||||
if(carvers.size() > main.getTerraConfig().getCacheSize() * 2) carvers.clear();
|
||||
return carvers.computeIfAbsent((((long) chunkX) << 32) | (chunkZ & 0xffffffffL), key -> {
|
||||
TerraBiomeGrid grid = main.getWorld(w).getGrid();
|
||||
if(carver.isChunkCarved(w, chunkX, chunkZ, new FastRandom(MathUtil.getCarverChunkSeed(chunkX, chunkZ, w.getSeed() + carver.hashCode())))) {
|
||||
long seed = MathUtil.getCarverChunkSeed(chunkX, chunkZ, w.getSeed());
|
||||
carver.getSeedVar().setValue(seed);
|
||||
Random r = new FastRandom(seed);
|
||||
Worm carving = carver.getWorm(seed, new Vector((chunkX << 4) + r.nextInt(16), carver.getConfig().getHeight().get(r), (chunkZ << 4) + r.nextInt(16)));
|
||||
List<Worm.WormPoint> points = new GlueList<>();
|
||||
for(int i = 0; i < carving.getLength(); i++) {
|
||||
carving.step();
|
||||
Biome biome = grid.getBiome(carving.getRunning().toLocation(w), GenerationPhase.POPULATE);
|
||||
if(!((UserDefinedBiome) biome).getConfig().getCarvers().containsKey(carver)) { // Stop if we enter a biome this carver is not present in
|
||||
return new GlueList<>();
|
||||
}
|
||||
points.add(carving.getPoint());
|
||||
}
|
||||
return points;
|
||||
}
|
||||
return new GlueList<>();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
package com.dfsek.terra.carving;
|
||||
|
||||
import com.dfsek.terra.util.MaterialSet;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.polydev.gaea.math.ProbabilityCollection;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
@SuppressWarnings({"unchecked", "rawtypes", "RedundantSuppression"})
|
||||
public class CarverPalette {
|
||||
private final boolean blacklist;
|
||||
private final MaterialSet replace;
|
||||
private final TreeMap<Integer, ProbabilityCollection<BlockData>> map = new TreeMap<>();
|
||||
private ProbabilityCollection<BlockData>[] layers;
|
||||
|
||||
public CarverPalette(MaterialSet replaceable, boolean blacklist) {
|
||||
this.blacklist = blacklist;
|
||||
this.replace = replaceable;
|
||||
}
|
||||
|
||||
public CarverPalette add(ProbabilityCollection<BlockData> collection, int y) {
|
||||
map.put(y, collection);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ProbabilityCollection<BlockData> get(int y) {
|
||||
return layers[y];
|
||||
}
|
||||
|
||||
public boolean canReplace(Material material) {
|
||||
return blacklist != replace.contains(material);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the palette to an array.
|
||||
*/
|
||||
public void build() {
|
||||
int size = map.lastKey() + 1;
|
||||
layers = new ProbabilityCollection[size];
|
||||
for(int y = 0; y < size; y++) {
|
||||
ProbabilityCollection<BlockData> d = new ProbabilityCollection<BlockData>().add(Material.AIR.createBlockData(), 1); // Blank layer
|
||||
for(Map.Entry<Integer, ProbabilityCollection<BlockData>> e : map.entrySet()) {
|
||||
if(e.getKey() >= y) {
|
||||
d = e.getValue();
|
||||
break;
|
||||
}
|
||||
}
|
||||
layers[y] = d;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
package com.dfsek.terra.carving;
|
||||
|
||||
import com.dfsek.terra.procgen.GridSpawn;
|
||||
import com.dfsek.terra.procgen.voxel.DeformedSphere;
|
||||
import com.dfsek.terra.procgen.voxel.Tube;
|
||||
import com.dfsek.terra.procgen.voxel.VoxelGeometry;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.polydev.gaea.math.FastNoiseLite;
|
||||
import org.polydev.gaea.math.MathUtil;
|
||||
import org.polydev.gaea.util.FastRandom;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class Cavern {
|
||||
private final Node node;
|
||||
private final long seed;
|
||||
|
||||
public Cavern(World w) {
|
||||
this.node = new Node(w);
|
||||
this.seed = w.getSeed();
|
||||
}
|
||||
|
||||
public VoxelGeometry carveChunk(int chunkX, int chunkZ) {
|
||||
long seedC = MathUtil.getCarverChunkSeed(chunkX, chunkZ, seed);
|
||||
Random chunk = new FastRandom(seedC);
|
||||
Vector org = node.getNodeLocation((chunkX << 4) + 8, (chunkZ << 4) + 8).clone().setY(chunk.nextInt(128));
|
||||
VoxelGeometry carve = VoxelGeometry.getBlank();
|
||||
|
||||
FastNoiseLite smpl = new FastNoiseLite((int) seedC);
|
||||
smpl.setFrequency(0.01f);
|
||||
smpl.setNoiseType(FastNoiseLite.NoiseType.OpenSimplex2);
|
||||
Bukkit.getLogger().info("Cavern: " + org.toString());
|
||||
carve.merge(new DeformedSphere(org.clone(), chunk.nextInt(4) + 3, 0.75, smpl));
|
||||
|
||||
Vector _00 = new Vector(org.getX() + 16, new FastRandom(MathUtil.getCarverChunkSeed(chunkX + 1, chunkZ, seed)).nextInt(128), org.getZ());
|
||||
|
||||
carve.merge(new Tube(org, _00, 4));
|
||||
return carve;
|
||||
}
|
||||
|
||||
public static class Node {
|
||||
private final long seed;
|
||||
private final GridSpawn spawn = new GridSpawn(16, 0, 0);
|
||||
|
||||
public Node(World w) {
|
||||
this.seed = w.getSeed();
|
||||
}
|
||||
|
||||
public Vector getNodeLocation(int x, int z) {
|
||||
return spawn.getNearestSpawn(x, z, seed);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,176 +0,0 @@
|
||||
package com.dfsek.terra.carving;
|
||||
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.biome.UserDefinedBiome;
|
||||
import com.dfsek.terra.config.templates.BiomeTemplate;
|
||||
import com.dfsek.terra.config.templates.CarverTemplate;
|
||||
import com.dfsek.terra.math.RandomFunction;
|
||||
import net.jafama.FastMath;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.polydev.gaea.generation.GenerationPhase;
|
||||
import org.polydev.gaea.math.Range;
|
||||
import org.polydev.gaea.util.FastRandom;
|
||||
import org.polydev.gaea.world.carving.Carver;
|
||||
import org.polydev.gaea.world.carving.Worm;
|
||||
import parsii.eval.Expression;
|
||||
import parsii.eval.Parser;
|
||||
import parsii.eval.Scope;
|
||||
import parsii.eval.Variable;
|
||||
import parsii.tokenizer.ParseException;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
public class UserDefinedCarver extends Carver {
|
||||
private final double[] start; // 0, 1, 2 = x, y, z.
|
||||
private final double[] mutate; // 0, 1, 2 = x, y, z. 3 = radius.
|
||||
private final Range length;
|
||||
private final long hash;
|
||||
private final int topCut;
|
||||
private final int bottomCut;
|
||||
private final CarverTemplate config;
|
||||
private final Expression xRad;
|
||||
private final Expression yRad;
|
||||
private final Expression zRad;
|
||||
private final Variable lengthVar;
|
||||
private final Variable position;
|
||||
private final Variable seedVar;
|
||||
private final Map<World, CarverCache> cacheMap = new HashMap<>();
|
||||
private double step = 2;
|
||||
private Range recalc = new Range(8, 10);
|
||||
private double recalcMagnitude = 3;
|
||||
private final Terra main;
|
||||
|
||||
public UserDefinedCarver(Range height, Range length, double[] start, double[] mutate, List<String> radii, Scope parent, long hash, int topCut, int bottomCut, CarverTemplate config, Terra main) throws ParseException {
|
||||
super(height.getMin(), height.getMax());
|
||||
this.length = length;
|
||||
this.start = start;
|
||||
this.mutate = mutate;
|
||||
this.hash = hash;
|
||||
this.topCut = topCut;
|
||||
this.bottomCut = bottomCut;
|
||||
this.config = config;
|
||||
this.main = main;
|
||||
|
||||
Parser p = new Parser();
|
||||
|
||||
p.registerFunction("rand", new RandomFunction());
|
||||
|
||||
Scope s = new Scope().withParent(parent);
|
||||
|
||||
lengthVar = s.create("length");
|
||||
position = s.create("position");
|
||||
seedVar = s.create("seed");
|
||||
|
||||
|
||||
xRad = p.parse(radii.get(0), s);
|
||||
yRad = p.parse(radii.get(1), s);
|
||||
zRad = p.parse(radii.get(2), s);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Worm getWorm(long l, Vector vector) {
|
||||
Random r = new FastRandom(l + hash);
|
||||
return new UserDefinedWorm(length.get(r) / 2, r, vector, topCut, bottomCut);
|
||||
}
|
||||
|
||||
protected Variable getSeedVar() {
|
||||
return seedVar;
|
||||
}
|
||||
|
||||
protected Variable getLengthVar() {
|
||||
return lengthVar;
|
||||
}
|
||||
|
||||
protected Variable getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
public void setStep(double step) {
|
||||
this.step = step;
|
||||
}
|
||||
|
||||
public void setRecalc(Range recalc) {
|
||||
this.recalc = recalc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void carve(int chunkX, int chunkZ, World w, BiConsumer<Vector, CarvingType> consumer) {
|
||||
CarverCache cache = cacheMap.computeIfAbsent(w, world -> new CarverCache(world, main));
|
||||
int carvingRadius = getCarvingRadius();
|
||||
for(int x = chunkX - carvingRadius; x <= chunkX + carvingRadius; x++) {
|
||||
for(int z = chunkZ - carvingRadius; z <= chunkZ + carvingRadius; z++) {
|
||||
cache.getPoints(x, z, this).forEach(point -> {
|
||||
Vector origin = point.getOrigin();
|
||||
if(FastMath.floorDiv(origin.getBlockX(), 16) != chunkX && FastMath.floorDiv(origin.getBlockZ(), 16) != chunkZ) // We only want to carve this chunk.
|
||||
return;
|
||||
point.carve(chunkX, chunkZ, consumer);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setRecalcMagnitude(double recalcMagnitude) {
|
||||
this.recalcMagnitude = recalcMagnitude;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isChunkCarved(World w, int chunkX, int chunkZ, Random random) {
|
||||
BiomeTemplate conf = ((UserDefinedBiome) main.getWorld(w).getGrid().getBiome((chunkX << 4) + 8, (chunkZ << 4) + 8, GenerationPhase.POPULATE)).getConfig();
|
||||
if(conf.getCarvers().get(this) != null) {
|
||||
return new FastRandom(random.nextLong() + hash).nextInt(100) < conf.getCarvers().get(this);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public CarverTemplate getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
private class UserDefinedWorm extends Worm {
|
||||
private final Vector direction;
|
||||
private int steps;
|
||||
private int nextDirection = 0;
|
||||
private double[] currentRotation = new double[3];
|
||||
|
||||
public UserDefinedWorm(int length, Random r, Vector origin, int topCut, int bottomCut) {
|
||||
super(length, r, origin);
|
||||
super.setTopCut(topCut);
|
||||
super.setBottomCut(bottomCut);
|
||||
direction = new Vector((r.nextDouble() - 0.5D) * start[0], (r.nextDouble() - 0.5D) * start[1], (r.nextDouble() - 0.5D) * start[2]).normalize().multiply(step);
|
||||
position.setValue(0);
|
||||
lengthVar.setValue(length);
|
||||
setRadius(new int[] {(int) (xRad.evaluate()), (int) (yRad.evaluate()), (int) (zRad.evaluate())});
|
||||
}
|
||||
|
||||
@Override
|
||||
public WormPoint getPoint() {
|
||||
return new WormPoint(getRunning().clone(), getRadius(), config.getCutTop(), config.getCutBottom());
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void step() {
|
||||
if(steps == nextDirection) {
|
||||
direction.rotateAroundX(FastMath.toRadians((getRandom().nextGaussian()) * mutate[0] * recalcMagnitude));
|
||||
direction.rotateAroundY(FastMath.toRadians((getRandom().nextGaussian()) * mutate[1] * recalcMagnitude));
|
||||
direction.rotateAroundZ(FastMath.toRadians((getRandom().nextGaussian()) * mutate[2] * recalcMagnitude));
|
||||
currentRotation = new double[] {(getRandom().nextGaussian()) * mutate[0],
|
||||
(getRandom().nextGaussian()) * mutate[1],
|
||||
(getRandom().nextGaussian()) * mutate[2]};
|
||||
nextDirection += recalc.get(getRandom());
|
||||
}
|
||||
steps++;
|
||||
position.setValue(steps);
|
||||
setRadius(new int[] {(int) (xRad.evaluate()), (int) (yRad.evaluate()), (int) (zRad.evaluate())});
|
||||
direction.rotateAroundX(FastMath.toRadians(currentRotation[0] * mutate[0]));
|
||||
direction.rotateAroundY(FastMath.toRadians(currentRotation[1] * mutate[1]));
|
||||
direction.rotateAroundZ(FastMath.toRadians(currentRotation[2] * mutate[2]));
|
||||
getRunning().add(direction);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
package com.dfsek.terra.command;
|
||||
|
||||
import com.dfsek.terra.generation.TerraChunkGenerator;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.polydev.gaea.command.WorldCommand;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class FixChunkCommand extends WorldCommand {
|
||||
public FixChunkCommand(org.polydev.gaea.command.Command parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(@NotNull Player player, @NotNull Command command, @NotNull String s, @NotNull String[] strings, World world) {
|
||||
TerraChunkGenerator.fixChunk(player.getLocation().getChunk());
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "fixchunk";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<org.polydev.gaea.command.Command> getSubCommands() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int arguments() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompletions(@NotNull CommandSender commandSender, @NotNull String s, @NotNull String[] strings) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
package com.dfsek.terra.command;
|
||||
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.polydev.gaea.command.WorldCommand;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class OreCommand extends WorldCommand {
|
||||
public OreCommand(org.polydev.gaea.command.Command parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World w) {
|
||||
/*
|
||||
Block bl = sender.getTargetBlockExact(25);
|
||||
if(args.length > 0) {
|
||||
OreConfig ore = TerraWorld.getWorld(w).getConfig().getOre(args[0]);
|
||||
if(ore == null) {
|
||||
LangUtil.send("command.ore.invalid-ore", sender, args[0]);
|
||||
return true;
|
||||
}
|
||||
if(bl == null) {
|
||||
LangUtil.send("command.ore.out-of-range", sender);
|
||||
return true;
|
||||
}
|
||||
Vector source = new Vector(FastMath.floorMod(bl.getX(), 16), bl.getY(), FastMath.floorMod(bl.getZ(), 16));
|
||||
ore.doVein(source, bl.getChunk(), new FastRandom());
|
||||
} else {
|
||||
LangUtil.send("command.ore.main-menu", sender);
|
||||
}
|
||||
*/
|
||||
return true;
|
||||
|
||||
|
||||
// TODO: implementation
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "ore";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<org.polydev.gaea.command.Command> getSubCommands() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int arguments() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
package com.dfsek.terra.command;
|
||||
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.config.base.ConfigPackTemplate;
|
||||
import com.dfsek.terra.config.lang.LangUtil;
|
||||
import com.dfsek.terra.registry.ConfigRegistry;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.polydev.gaea.command.Command;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class PacksCommand extends Command {
|
||||
public PacksCommand(Command parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "packs";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Command> getSubCommands() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(@NotNull CommandSender commandSender, org.bukkit.command.@NotNull Command command, @NotNull String s, @NotNull String[] strings) {
|
||||
|
||||
ConfigRegistry registry = ((Terra) getMain()).getRegistry();
|
||||
|
||||
if(registry.entries().size() == 0) {
|
||||
LangUtil.send("command.packs.none", commandSender);
|
||||
return true;
|
||||
}
|
||||
|
||||
LangUtil.send("command.packs.main", commandSender);
|
||||
registry.entries().forEach(entry -> {
|
||||
ConfigPackTemplate template = entry.getTemplate();
|
||||
LangUtil.send("command.packs.pack", commandSender, template.getID(), template.getAuthor(), template.getVersion());
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int arguments() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompletions(@NotNull CommandSender commandSender, @NotNull String s, @NotNull String[] strings) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
package com.dfsek.terra.command;
|
||||
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.config.lang.LangUtil;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.polydev.gaea.command.Command;
|
||||
import org.polydev.gaea.command.DebugCommand;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class ReloadCommand extends Command implements DebugCommand {
|
||||
public ReloadCommand(Command parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "reload";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Command> getSubCommands() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(@NotNull CommandSender sender, org.bukkit.command.@NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
((Terra) getMain()).getTerraConfig().load(getMain());
|
||||
LangUtil.load(((Terra) getMain()).getTerraConfig().getLanguage(), getMain()); // Load language.
|
||||
if(!((Terra) getMain()).getRegistry().loadAll((Terra) getMain())) {
|
||||
LangUtil.send("command.reload-error", sender);
|
||||
return true;
|
||||
}
|
||||
((Terra) getMain()).reload();
|
||||
LangUtil.send("command.reload", sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int arguments() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
package com.dfsek.terra.command;
|
||||
|
||||
import com.dfsek.terra.config.lang.LangUtil;
|
||||
import com.dfsek.terra.generation.TerraChunkGenerator;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.polydev.gaea.command.Command;
|
||||
import org.polydev.gaea.command.WorldCommand;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class SaveDataCommand extends WorldCommand {
|
||||
public SaveDataCommand(Command parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "save-data";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Command> getSubCommands() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int arguments() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(@NotNull Player sender, org.bukkit.command.@NotNull Command command, @NotNull String label, @NotNull String[] args, World w) {
|
||||
TerraChunkGenerator.saveAll();
|
||||
LangUtil.send("debug.data-save", sender, w.getName());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
package com.dfsek.terra.command;
|
||||
|
||||
import com.dfsek.terra.command.biome.BiomeCommand;
|
||||
import com.dfsek.terra.command.geometry.GeometryCommand;
|
||||
import com.dfsek.terra.command.image.ImageCommand;
|
||||
import com.dfsek.terra.command.profile.ProfileCommand;
|
||||
import com.dfsek.terra.command.structure.StructureCommand;
|
||||
import com.dfsek.terra.config.lang.LangUtil;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.polydev.gaea.GaeaPlugin;
|
||||
import org.polydev.gaea.command.Command;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class TerraCommand extends Command {
|
||||
private final List<Command> commands = Arrays.asList(new ReloadCommand(this),
|
||||
new BiomeCommand(this),
|
||||
new OreCommand(this),
|
||||
new ProfileCommand(this),
|
||||
new SaveDataCommand(this),
|
||||
new StructureCommand(this),
|
||||
new ImageCommand(this),
|
||||
new GeometryCommand(this),
|
||||
new FixChunkCommand(this),
|
||||
new VersionCommand(this),
|
||||
new PacksCommand(this));
|
||||
|
||||
public TerraCommand(GaeaPlugin main) {
|
||||
super(main);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "terra";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Command> getSubCommands() {
|
||||
return commands;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(@NotNull CommandSender sender, org.bukkit.command.@NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
LangUtil.send("command.main-menu", sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int arguments() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
package com.dfsek.terra.command;
|
||||
|
||||
import com.dfsek.terra.config.lang.LangUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.polydev.gaea.command.Command;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class VersionCommand extends Command {
|
||||
public VersionCommand(Command parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "version";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Command> getSubCommands() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(@NotNull CommandSender sender, org.bukkit.command.@NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
Plugin gaea = Objects.requireNonNull(Bukkit.getPluginManager().getPlugin("Gaea"));
|
||||
String gaeaVersion = gaea.getDescription().getVersion();
|
||||
|
||||
String terraVersion = getMain().getDescription().getVersion();
|
||||
LangUtil.send("command.version", sender, terraVersion, gaeaVersion);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int arguments() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
package com.dfsek.terra.command.biome;
|
||||
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.biome.UserDefinedBiome;
|
||||
import com.dfsek.terra.biome.grid.master.TerraBiomeGrid;
|
||||
import com.dfsek.terra.config.lang.LangUtil;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.polydev.gaea.command.WorldCommand;
|
||||
import org.polydev.gaea.generation.GenerationPhase;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class BiomeCommand extends WorldCommand {
|
||||
public BiomeCommand(org.polydev.gaea.command.Command parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World w) {
|
||||
TerraBiomeGrid grid = ((Terra) getMain()).getWorld(sender.getWorld()).getGrid();
|
||||
UserDefinedBiome biome = (UserDefinedBiome) grid.getBiome(sender.getLocation(), GenerationPhase.POPULATE);
|
||||
LangUtil.send("command.biome.in", sender, biome.getID());
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "biome";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<org.polydev.gaea.command.Command> getSubCommands() {
|
||||
return Arrays.asList(new BiomeLocateCommand(this, true), new BiomeLocateCommand(this, false), new BiomeInfoCommand(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int arguments() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
@@ -1,95 +0,0 @@
|
||||
package com.dfsek.terra.command.biome;
|
||||
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.biome.UserDefinedBiome;
|
||||
import com.dfsek.terra.carving.UserDefinedCarver;
|
||||
import com.dfsek.terra.config.base.ConfigPack;
|
||||
import com.dfsek.terra.config.lang.LangUtil;
|
||||
import com.dfsek.terra.config.templates.BiomeTemplate;
|
||||
import com.dfsek.terra.generation.TerraChunkGenerator;
|
||||
import com.dfsek.terra.generation.items.TerraStructure;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.polydev.gaea.command.WorldCommand;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class BiomeInfoCommand extends WorldCommand {
|
||||
public BiomeInfoCommand(org.polydev.gaea.command.Command parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World world) {
|
||||
String id = args[0];
|
||||
ConfigPack cfg = ((Terra) getMain()).getWorld(world).getConfig();
|
||||
UserDefinedBiome b;
|
||||
try {
|
||||
b = cfg.getBiome(id);
|
||||
} catch(IllegalArgumentException | NullPointerException e) {
|
||||
LangUtil.send("command.biome.invalid", sender, id);
|
||||
return true;
|
||||
}
|
||||
sender.sendMessage("Biome info for \"" + b.getID() + "\".");
|
||||
sender.sendMessage("Vanilla biome: " + b.getVanillaBiome());
|
||||
sender.sendMessage("Eroded by: " + b.getErode().getConfig().getID());
|
||||
|
||||
|
||||
BiomeTemplate bio = b.getConfig();
|
||||
|
||||
if(bio.getExtend() != null) sender.sendMessage("Extends: " + bio.getExtend());
|
||||
|
||||
List<TerraStructure> structureConfigs = bio.getStructures();
|
||||
|
||||
if(structureConfigs.size() == 0) sender.sendMessage("No Structures");
|
||||
else {
|
||||
sender.sendMessage("-------Structures-------");
|
||||
for(TerraStructure c : structureConfigs) {
|
||||
sender.sendMessage(" - " + c.getTemplate().getID());
|
||||
}
|
||||
}
|
||||
|
||||
Map<UserDefinedCarver, Integer> carverConfigs = bio.getCarvers();
|
||||
|
||||
if(structureConfigs.size() == 0) sender.sendMessage("No Carvers");
|
||||
else {
|
||||
sender.sendMessage("---------Carvers--------");
|
||||
for(Map.Entry<UserDefinedCarver, Integer> entry : carverConfigs.entrySet()) {
|
||||
sender.sendMessage(" - " + entry.getKey().getConfig().getID() + ": " + entry.getValue() + "%");
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "info";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<org.polydev.gaea.command.Command> getSubCommands() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int arguments() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) {
|
||||
if(!(sender instanceof Player) || !(((Player) sender).getWorld().getGenerator() instanceof TerraChunkGenerator))
|
||||
return Collections.emptyList();
|
||||
List<String> ids = ((Terra) getMain()).getWorld(((Player) sender).getWorld()).getConfig().getBiomeIDs();
|
||||
if(args.length == 1)
|
||||
return ids.stream().filter(string -> string.toUpperCase().startsWith(args[0].toUpperCase())).collect(Collectors.toList());
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
@@ -1,82 +0,0 @@
|
||||
package com.dfsek.terra.command.biome;
|
||||
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.async.AsyncBiomeFinder;
|
||||
import com.dfsek.terra.biome.UserDefinedBiome;
|
||||
import com.dfsek.terra.config.lang.LangUtil;
|
||||
import com.dfsek.terra.generation.TerraChunkGenerator;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.polydev.gaea.command.WorldCommand;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class BiomeLocateCommand extends WorldCommand {
|
||||
private final boolean tp;
|
||||
|
||||
public BiomeLocateCommand(org.polydev.gaea.command.Command parent, boolean teleport) {
|
||||
super(parent);
|
||||
this.tp = teleport;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World world) {
|
||||
String id = args[0];
|
||||
int maxRadius;
|
||||
try {
|
||||
maxRadius = Integer.parseInt(args[1]);
|
||||
} catch(NumberFormatException e) {
|
||||
LangUtil.send("command.biome.invalid-radius", sender, args[1]);
|
||||
return true;
|
||||
}
|
||||
UserDefinedBiome b;
|
||||
try {
|
||||
b = ((Terra) getMain()).getWorld(world).getConfig().getBiome(id);
|
||||
} catch(IllegalArgumentException | NullPointerException e) {
|
||||
LangUtil.send("command.biome.invalid", sender, id);
|
||||
return true;
|
||||
}
|
||||
Bukkit.getScheduler().runTaskAsynchronously(getMain(), new AsyncBiomeFinder(((Terra) getMain()).getWorld(world).getGrid(), b, sender.getLocation().clone().multiply((1D / ((Terra) getMain()).getTerraConfig().getBiomeSearchResolution())), 0, maxRadius, location -> {
|
||||
if(location != null) {
|
||||
LangUtil.send("command.biome.biome-found", sender, String.valueOf(location.getBlockX()), String.valueOf(location.getBlockZ()));
|
||||
if(tp) {
|
||||
Location l = new Location(sender.getWorld(), location.getX(), sender.getLocation().getY(), location.getZ());
|
||||
Bukkit.getScheduler().runTask(getMain(), () -> sender.teleport(l));
|
||||
}
|
||||
} else LangUtil.send("command.biome.unable-to-locate", sender);
|
||||
}, (Terra) getMain()));
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return tp ? "teleport" : "locate";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<org.polydev.gaea.command.Command> getSubCommands() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int arguments() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) {
|
||||
if(!(sender instanceof Player) || !(((Player) sender).getWorld().getGenerator() instanceof TerraChunkGenerator))
|
||||
return Collections.emptyList();
|
||||
List<String> ids = ((Terra) getMain()).getWorld(((Player) sender).getWorld()).getConfig().getBiomeIDs();
|
||||
if(args.length == 1)
|
||||
return ids.stream().filter(string -> string.toUpperCase().startsWith(args[0].toUpperCase())).collect(Collectors.toList());
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
@@ -1,75 +0,0 @@
|
||||
package com.dfsek.terra.command.geometry;
|
||||
|
||||
import com.dfsek.terra.config.lang.LangUtil;
|
||||
import com.dfsek.terra.procgen.voxel.DeformedSphere;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.polydev.gaea.command.PlayerCommand;
|
||||
import org.polydev.gaea.math.FastNoiseLite;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class DeformedSphereCommand extends PlayerCommand {
|
||||
public DeformedSphereCommand(org.polydev.gaea.command.Command parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
int radius;
|
||||
try {
|
||||
radius = Integer.parseInt(args[0]);
|
||||
} catch(NumberFormatException e) {
|
||||
LangUtil.send("command.geometry.deform.invalid-radius", sender, args[0]);
|
||||
return true;
|
||||
}
|
||||
double deform;
|
||||
try {
|
||||
deform = Double.parseDouble(args[1]);
|
||||
} catch(NumberFormatException e) {
|
||||
LangUtil.send("command.geometry.deform.invalid-deform", sender, args[1]);
|
||||
return true;
|
||||
}
|
||||
|
||||
double freq;
|
||||
try {
|
||||
freq = Float.parseFloat(args[2]);
|
||||
} catch(NumberFormatException e) {
|
||||
LangUtil.send("command.geometry.deform.invalid-frequency", sender, args[2]);
|
||||
return true;
|
||||
}
|
||||
FastNoiseLite n = new FastNoiseLite((int) sender.getWorld().getSeed());
|
||||
n.setNoiseType(FastNoiseLite.NoiseType.OpenSimplex2);
|
||||
n.setFrequency(freq);
|
||||
DeformedSphere sphere = new DeformedSphere(sender.getLocation().toVector(), radius, deform, n);
|
||||
for(Vector v : sphere.getGeometry()) {
|
||||
v.toLocation(sender.getWorld()).getBlock().setType(Material.STONE);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "deformedsphere";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<org.polydev.gaea.command.Command> getSubCommands() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int arguments() {
|
||||
return 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
package com.dfsek.terra.command.geometry;
|
||||
|
||||
import com.dfsek.terra.config.lang.LangUtil;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.polydev.gaea.command.DebugCommand;
|
||||
import org.polydev.gaea.command.PlayerCommand;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class GeometryCommand extends PlayerCommand implements DebugCommand {
|
||||
public GeometryCommand(org.polydev.gaea.command.Command parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
LangUtil.send("command.geometry.main-menu", sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "geometry";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<org.polydev.gaea.command.Command> getSubCommands() {
|
||||
return Arrays.asList(new SphereCommand(this), new TubeCommand(this), new DeformedSphereCommand(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int arguments() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
package com.dfsek.terra.command.geometry;
|
||||
|
||||
import com.dfsek.terra.config.lang.LangUtil;
|
||||
import com.dfsek.terra.procgen.voxel.Sphere;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.polydev.gaea.command.PlayerCommand;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class SphereCommand extends PlayerCommand {
|
||||
public SphereCommand(org.polydev.gaea.command.Command parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
int radius;
|
||||
try {
|
||||
radius = Integer.parseInt(args[0]);
|
||||
} catch(NumberFormatException e) {
|
||||
LangUtil.send("command.geometry.sphere.invalid-radius", sender, args[0]);
|
||||
return true;
|
||||
}
|
||||
Sphere sphere = new Sphere(sender.getLocation().toVector(), radius);
|
||||
for(Vector v : sphere.getGeometry()) {
|
||||
v.toLocation(sender.getWorld()).getBlock().setType(Material.STONE);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "sphere";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<org.polydev.gaea.command.Command> getSubCommands() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int arguments() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
package com.dfsek.terra.command.geometry;
|
||||
|
||||
import com.dfsek.terra.config.lang.LangUtil;
|
||||
import com.dfsek.terra.procgen.voxel.Tube;
|
||||
import com.dfsek.terra.util.structure.WorldEditUtil;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.polydev.gaea.command.PlayerCommand;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class TubeCommand extends PlayerCommand {
|
||||
public TubeCommand(org.polydev.gaea.command.Command parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
Location[] l = WorldEditUtil.getSelectionPositions(sender);
|
||||
if(l == null) return true;
|
||||
int radius;
|
||||
try {
|
||||
radius = Integer.parseInt(args[0]);
|
||||
} catch(NumberFormatException e) {
|
||||
LangUtil.send("command.geometry.tube.invalid-radius", sender, args[0]);
|
||||
return true;
|
||||
}
|
||||
Tube tube = new Tube(l[0].toVector(), l[1].toVector(), radius);
|
||||
for(Vector v : tube.getGeometry()) {
|
||||
v.toLocation(sender.getWorld()).getBlock().setType(Material.STONE);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "tube";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<org.polydev.gaea.command.Command> getSubCommands() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int arguments() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
package com.dfsek.terra.command.image;
|
||||
|
||||
import com.dfsek.terra.command.image.gui.GUICommand;
|
||||
import com.dfsek.terra.config.lang.LangUtil;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.polydev.gaea.command.WorldCommand;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class ImageCommand extends WorldCommand {
|
||||
public ImageCommand(org.polydev.gaea.command.Command parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World w) {
|
||||
LangUtil.send("command.image.main-menu", sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "image";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<org.polydev.gaea.command.Command> getSubCommands() {
|
||||
return Arrays.asList(new RenderCommand(this), new GUICommand(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int arguments() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
package com.dfsek.terra.command.image;
|
||||
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.config.lang.LangUtil;
|
||||
import com.dfsek.terra.image.WorldImageGenerator;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.polydev.gaea.command.WorldCommand;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class RenderCommand extends WorldCommand {
|
||||
public RenderCommand(org.polydev.gaea.command.Command parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World world) {
|
||||
try {
|
||||
WorldImageGenerator g = new WorldImageGenerator(world, Integer.parseInt(args[0]), Integer.parseInt(args[1]), (Terra) getMain());
|
||||
g.drawWorld(sender.getLocation().getBlockX(), sender.getLocation().getBlockZ());
|
||||
File file = new File(getMain().getDataFolder() + File.separator + "export" + File.separator + "map" + File.separator + "map_" + System.currentTimeMillis() + ".png");
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
file.mkdirs();
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
file.createNewFile();
|
||||
g.save(file);
|
||||
LangUtil.send("command.image.render.save", sender, file.getAbsolutePath());
|
||||
return true;
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
LangUtil.send("command.image.render.error", sender);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "render";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<org.polydev.gaea.command.Command> getSubCommands() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int arguments() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
package com.dfsek.terra.command.image.gui;
|
||||
|
||||
import com.dfsek.terra.config.lang.LangUtil;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.polydev.gaea.command.DebugCommand;
|
||||
import org.polydev.gaea.command.WorldCommand;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class GUICommand extends WorldCommand implements DebugCommand {
|
||||
public GUICommand(org.polydev.gaea.command.Command parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World world) {
|
||||
LangUtil.send("command.image.gui.main-menu", sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "gui";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<org.polydev.gaea.command.Command> getSubCommands() {
|
||||
return Arrays.asList(new StepGUICommand(this), new RawGUICommand(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int arguments() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
package com.dfsek.terra.command.image.gui;
|
||||
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.config.lang.LangUtil;
|
||||
import com.dfsek.terra.image.ImageLoader;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.polydev.gaea.command.WorldCommand;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class RawGUICommand extends WorldCommand {
|
||||
public RawGUICommand(org.polydev.gaea.command.Command parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World world) {
|
||||
if(!getMain().isDebug()) {
|
||||
LangUtil.send("command.image.gui.debug", sender);
|
||||
return true;
|
||||
}
|
||||
ImageLoader loader = ((Terra) getMain()).getWorld(world).getConfig().getTemplate().getImageLoader();
|
||||
if(loader != null) loader.debug(false, sender.getWorld(), (Terra) getMain());
|
||||
else ImageLoader.debugWorld(false, world, (Terra) getMain());
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "raw";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<org.polydev.gaea.command.Command> getSubCommands() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int arguments() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
package com.dfsek.terra.command.image.gui;
|
||||
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.config.lang.LangUtil;
|
||||
import com.dfsek.terra.image.ImageLoader;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.polydev.gaea.command.WorldCommand;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class StepGUICommand extends WorldCommand {
|
||||
public StepGUICommand(org.polydev.gaea.command.Command parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World world) {
|
||||
if(!getMain().isDebug()) {
|
||||
LangUtil.send("command.image.gui.debug", sender);
|
||||
return true;
|
||||
}
|
||||
ImageLoader loader = ((Terra) getMain()).getWorld(world).getConfig().getTemplate().getImageLoader();
|
||||
if(loader != null) loader.debug(true, sender.getWorld(), (Terra) getMain());
|
||||
else ImageLoader.debugWorld(true, world, (Terra) getMain());
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "step";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<org.polydev.gaea.command.Command> getSubCommands() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int arguments() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
package com.dfsek.terra.command.profile;
|
||||
|
||||
import com.dfsek.terra.config.lang.LangUtil;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.polydev.gaea.command.WorldCommand;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class ProfileCommand extends WorldCommand {
|
||||
public ProfileCommand(org.polydev.gaea.command.Command parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World w) {
|
||||
LangUtil.send("command.profile.main-menu", sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "profile";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<org.polydev.gaea.command.Command> getSubCommands() {
|
||||
return Arrays.asList(new QueryCommand(this), new ResetCommand(this), new StartCommand(this), new StopCommand(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int arguments() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
package com.dfsek.terra.command.profile;
|
||||
|
||||
import com.dfsek.terra.Terra;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.polydev.gaea.command.WorldCommand;
|
||||
import org.polydev.gaea.profiler.WorldProfiler;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class QueryCommand extends WorldCommand {
|
||||
public QueryCommand(org.polydev.gaea.command.Command parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World world) {
|
||||
WorldProfiler profile = ((Terra) getMain()).getWorld(world).getProfiler();
|
||||
sender.sendMessage(profile.getResultsFormatted());
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "query";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<org.polydev.gaea.command.Command> getSubCommands() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int arguments() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
package com.dfsek.terra.command.profile;
|
||||
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.config.lang.LangUtil;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.polydev.gaea.command.WorldCommand;
|
||||
import org.polydev.gaea.profiler.WorldProfiler;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class ResetCommand extends WorldCommand {
|
||||
public ResetCommand(org.polydev.gaea.command.Command parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World world) {
|
||||
WorldProfiler profile = ((Terra) getMain()).getWorld(world).getProfiler();
|
||||
profile.reset();
|
||||
LangUtil.send("command.profile.reset", sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "reset";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<org.polydev.gaea.command.Command> getSubCommands() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int arguments() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
package com.dfsek.terra.command.profile;
|
||||
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.config.lang.LangUtil;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.polydev.gaea.command.WorldCommand;
|
||||
import org.polydev.gaea.profiler.WorldProfiler;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class StartCommand extends WorldCommand {
|
||||
public StartCommand(org.polydev.gaea.command.Command parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World world) {
|
||||
WorldProfiler profile = ((Terra) getMain()).getWorld(world).getProfiler();
|
||||
profile.setProfiling(true);
|
||||
LangUtil.send("command.profile.start", sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "start";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<org.polydev.gaea.command.Command> getSubCommands() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int arguments() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
package com.dfsek.terra.command.profile;
|
||||
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.config.lang.LangUtil;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.polydev.gaea.command.WorldCommand;
|
||||
import org.polydev.gaea.profiler.WorldProfiler;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class StopCommand extends WorldCommand {
|
||||
public StopCommand(org.polydev.gaea.command.Command parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World world) {
|
||||
WorldProfiler profile = ((Terra) getMain()).getWorld(world).getProfiler();
|
||||
profile.setProfiling(false);
|
||||
LangUtil.send("command.profile.stop", sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "stop";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<org.polydev.gaea.command.Command> getSubCommands() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int arguments() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
package com.dfsek.terra.command.structure;
|
||||
|
||||
import com.dfsek.terra.config.lang.LangUtil;
|
||||
import com.dfsek.terra.structure.InitializationException;
|
||||
import com.dfsek.terra.structure.Structure;
|
||||
import com.dfsek.terra.util.structure.WorldEditUtil;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.polydev.gaea.command.PlayerCommand;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class ExportCommand extends PlayerCommand {
|
||||
public ExportCommand(org.polydev.gaea.command.Command parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
Location[] l = WorldEditUtil.getSelectionLocations(sender);
|
||||
if(l == null) return true;
|
||||
Location l1 = l[0];
|
||||
Location l2 = l[1];
|
||||
Structure structure;
|
||||
try {
|
||||
structure = new Structure(l1, l2, args[0]);
|
||||
} catch(InitializationException e) {
|
||||
sender.sendMessage(e.getMessage());
|
||||
return true;
|
||||
}
|
||||
try {
|
||||
File file = new File(getMain().getDataFolder() + File.separator + "export" + File.separator + "structures", args[0] + ".tstructure");
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
file.getParentFile().mkdirs();
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
file.createNewFile();
|
||||
structure.save(file);
|
||||
LangUtil.send("command.structure.export", sender, file.getAbsolutePath());
|
||||
} catch(IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "export";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<org.polydev.gaea.command.Command> getSubCommands() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int arguments() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
@@ -1,86 +0,0 @@
|
||||
package com.dfsek.terra.command.structure;
|
||||
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.async.AsyncStructureFinder;
|
||||
import com.dfsek.terra.config.lang.LangUtil;
|
||||
import com.dfsek.terra.generation.TerraChunkGenerator;
|
||||
import com.dfsek.terra.generation.items.TerraStructure;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.polydev.gaea.command.WorldCommand;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class LocateCommand extends WorldCommand {
|
||||
private final boolean tp;
|
||||
|
||||
public LocateCommand(org.polydev.gaea.command.Command parent, boolean tp) {
|
||||
super(parent);
|
||||
this.tp = tp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World world) {
|
||||
String id = args[0];
|
||||
int maxRadius;
|
||||
try {
|
||||
maxRadius = Integer.parseInt(args[1]);
|
||||
} catch(NumberFormatException e) {
|
||||
LangUtil.send("command.structure.invalid-radius", sender, args[1]);
|
||||
return true;
|
||||
}
|
||||
TerraStructure s;
|
||||
try {
|
||||
s = Objects.requireNonNull(((Terra) getMain()).getWorld(world).getConfig().getStructure(id));
|
||||
} catch(IllegalArgumentException | NullPointerException e) {
|
||||
LangUtil.send("command.structure.invalid", sender, id);
|
||||
return true;
|
||||
}
|
||||
Bukkit.getScheduler().runTaskAsynchronously(getMain(), new AsyncStructureFinder(((Terra) getMain()).getWorld(world).getGrid(), s, sender.getLocation(), 0, maxRadius, (location) -> {
|
||||
if(sender.isOnline()) {
|
||||
if(location != null) {
|
||||
sender.sendMessage("Located structure at (" + location.getBlockX() + ", " + location.getBlockZ() + ").");
|
||||
if(tp) {
|
||||
int finalX = location.getBlockX();
|
||||
int finalZ = location.getBlockZ();
|
||||
Bukkit.getScheduler().runTask(getMain(), () -> sender.teleport(new Location(sender.getWorld(), finalX, sender.getLocation().getY(), finalZ)));
|
||||
}
|
||||
} else sender.sendMessage("Unable to locate structure. ");
|
||||
}
|
||||
}, (Terra) getMain()));
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return tp ? "teleport" : "locate";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<org.polydev.gaea.command.Command> getSubCommands() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int arguments() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) {
|
||||
if(!(sender instanceof Player) || !(((Player) sender).getWorld().getGenerator() instanceof TerraChunkGenerator))
|
||||
return Collections.emptyList();
|
||||
List<String> ids = ((Terra) getMain()).getWorld(((Player) sender).getWorld()).getConfig().getStructureIDs();
|
||||
if(args.length == 1)
|
||||
return ids.stream().filter(string -> string.toUpperCase().startsWith(args[0].toUpperCase())).collect(Collectors.toList());
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
package com.dfsek.terra.command.structure;
|
||||
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.structure.StructureSpawnRequirement;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.polydev.gaea.command.DebugCommand;
|
||||
import org.polydev.gaea.command.WorldCommand;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class SpawnCommand extends WorldCommand implements DebugCommand {
|
||||
public SpawnCommand(org.polydev.gaea.command.Command parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World world) {
|
||||
Location p = sender.getLocation();
|
||||
int x = p.getBlockX();
|
||||
int y = p.getBlockY();
|
||||
int z = p.getBlockZ();
|
||||
boolean air = StructureSpawnRequirement.AIR.getInstance(world, (Terra) getMain()).matches(x, y, z);
|
||||
boolean ground = StructureSpawnRequirement.LAND.getInstance(world, (Terra) getMain()).matches(x, y, z);
|
||||
boolean sea = StructureSpawnRequirement.OCEAN.getInstance(world, (Terra) getMain()).matches(x, y, z);
|
||||
|
||||
sender.sendMessage("AIR: " + air + "\nLAND: " + ground + "\nOCEAN: " + sea);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "spawn";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<org.polydev.gaea.command.Command> getSubCommands() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int arguments() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
package com.dfsek.terra.command.structure;
|
||||
|
||||
import com.dfsek.terra.command.structure.load.LoadCommand;
|
||||
import com.dfsek.terra.config.lang.LangUtil;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.polydev.gaea.command.PlayerCommand;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class StructureCommand extends PlayerCommand {
|
||||
public StructureCommand(org.polydev.gaea.command.Command parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
LangUtil.send("command.structure.main-menu", sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "structure";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<org.polydev.gaea.command.Command> getSubCommands() {
|
||||
return Arrays.asList(new ExportCommand(this), new LoadCommand(this), new LocateCommand(this, false), new LocateCommand(this, true), new SpawnCommand(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int arguments() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
package com.dfsek.terra.command.structure.load;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.polydev.gaea.command.DebugCommand;
|
||||
import org.polydev.gaea.command.PlayerCommand;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class LoadCommand extends PlayerCommand implements DebugCommand {
|
||||
public LoadCommand(org.polydev.gaea.command.Command parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
public List<String> getStructureNames() {
|
||||
List<String> names = new ArrayList<>();
|
||||
File structureDir = new File(getMain().getDataFolder() + File.separator + "export" + File.separator + "structures");
|
||||
if(!structureDir.exists()) return Collections.emptyList();
|
||||
Path structurePath = structureDir.toPath();
|
||||
|
||||
FilenameFilter filter = (dir, name) -> name.endsWith(".tstructure");
|
||||
for(File f : structureDir.listFiles(filter)) {
|
||||
String path = structurePath.relativize(f.toPath()).toString();
|
||||
names.add(path.substring(0, path.length() - 11));
|
||||
}
|
||||
return names;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "load";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<org.polydev.gaea.command.Command> getSubCommands() {
|
||||
return Arrays.asList(new LoadRawCommand(this), new LoadFullCommand(this, true), new LoadFullCommand(this, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int arguments() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
package com.dfsek.terra.command.structure.load;
|
||||
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.config.lang.LangUtil;
|
||||
import com.dfsek.terra.structure.Rotation;
|
||||
import com.dfsek.terra.structure.Structure;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.polydev.gaea.command.DebugCommand;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class LoadFullCommand extends LoadCommand implements DebugCommand {
|
||||
private final boolean chunk;
|
||||
|
||||
public LoadFullCommand(org.polydev.gaea.command.Command parent, boolean chunk) {
|
||||
super(parent);
|
||||
this.chunk = chunk;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String s, @NotNull String[] args) {
|
||||
try {
|
||||
Rotation r;
|
||||
try {
|
||||
r = Rotation.fromDegrees(Integer.parseInt(args[1]));
|
||||
} catch(NumberFormatException e) {
|
||||
LangUtil.send("command.structure.invalid-rotation", sender, args[1]);
|
||||
return true;
|
||||
}
|
||||
Structure struc = Structure.load(new File(getMain().getDataFolder() + File.separator + "export" + File.separator + "structures", args[0] + ".tstructure"));
|
||||
if(chunk) struc.paste(sender.getLocation(), sender.getLocation().getChunk(), r, (Terra) getMain());
|
||||
else struc.paste(sender.getLocation(), r, (Terra) getMain());
|
||||
//sender.sendMessage(String.valueOf(struc.checkSpawns(sender.getLocation(), r)));
|
||||
} catch(IOException e) {
|
||||
e.printStackTrace();
|
||||
LangUtil.send("command.structure.invalid", sender, args[0]);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return chunk ? "chunk" : "full";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<org.polydev.gaea.command.Command> getSubCommands() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int arguments() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompletions(@NotNull CommandSender commandSender, @NotNull String s, @NotNull String[] args) {
|
||||
switch(args.length) {
|
||||
case 1:
|
||||
return getStructureNames().stream().filter(string -> string.toUpperCase().startsWith(args[0].toUpperCase())).collect(Collectors.toList());
|
||||
case 2:
|
||||
return Stream.of("0", "90", "180", "270").filter(string -> string.toUpperCase().startsWith(args[1].toUpperCase())).collect(Collectors.toList());
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
@@ -1,116 +0,0 @@
|
||||
package com.dfsek.terra.command.structure.load;
|
||||
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.api.generic.world.WorldHandle;
|
||||
import com.dfsek.terra.config.lang.LangUtil;
|
||||
import com.dfsek.terra.structure.Structure;
|
||||
import com.dfsek.terra.structure.StructureContainedBlock;
|
||||
import com.dfsek.terra.structure.StructureInfo;
|
||||
import com.dfsek.terra.structure.StructureSpawnRequirement;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.polydev.gaea.command.DebugCommand;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class LoadRawCommand extends LoadCommand implements DebugCommand {
|
||||
public LoadRawCommand(org.polydev.gaea.command.Command parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
private static void setTerraSign(Sign sign, String data) {
|
||||
sign.setLine(0, "[TERRA]");
|
||||
if(data.length() > 16) {
|
||||
sign.setLine(2, data.substring(0, 16));
|
||||
sign.setLine(3, data.substring(16));
|
||||
} else sign.setLine(2, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String s, @NotNull String[] args) {
|
||||
try {
|
||||
WorldHandle handle = ((Terra) getMain()).getHandle();
|
||||
Structure struc = Structure.load(new File(getMain().getDataFolder() + File.separator + "export" + File.separator + "structures", args[0] + ".tstructure"));
|
||||
StructureInfo info = struc.getStructureInfo();
|
||||
int centerX = info.getCenterX();
|
||||
int centerZ = info.getCenterZ();
|
||||
for(StructureContainedBlock[][] level0 : struc.getRawStructure()) {
|
||||
for(StructureContainedBlock[] level1 : level0) {
|
||||
for(StructureContainedBlock block : level1) {
|
||||
Location bLocation = sender.getLocation().add(block.getX() - centerX, block.getY(), block.getZ() - centerZ);
|
||||
if(!block.getPull().equals(StructureContainedBlock.Pull.NONE)) {
|
||||
handle.setBlockData(bLocation.getBlock(), Material.OAK_SIGN.createBlockData(), false);
|
||||
Sign sign = (Sign) bLocation.getBlock().getState();
|
||||
sign.setLine(1, "[PULL=" + block.getPull() + "_" + block.getPullOffset() + "]");
|
||||
String data = block.getBlockData().getAsString(true);
|
||||
setTerraSign(sign, data);
|
||||
sign.update();
|
||||
} else if(!block.getRequirement().equals(StructureSpawnRequirement.BLANK)) {
|
||||
handle.setBlockData(bLocation.getBlock(), Material.OAK_SIGN.createBlockData(), false);
|
||||
Sign sign = (Sign) bLocation.getBlock().getState();
|
||||
sign.setLine(1, "[SPAWN=" + block.getRequirement() + "]");
|
||||
String data = block.getBlockData().getAsString(true);
|
||||
setTerraSign(sign, data);
|
||||
sign.update();
|
||||
} else {
|
||||
handle.setBlockData(bLocation.getBlock(), block.getBlockData(), false);
|
||||
if(block.getState() != null) {
|
||||
block.getState().getState(bLocation.getBlock().getState()).update(true, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(int y = 0; y < struc.getStructureInfo().getSizeY(); y++) {
|
||||
StructureContainedBlock block = struc.getRawStructure()[centerX][centerZ][y];
|
||||
if(block.getRequirement().equals(StructureSpawnRequirement.BLANK) && block.getPull().equals(StructureContainedBlock.Pull.NONE)) {
|
||||
Location bLocation = sender.getLocation().add(block.getX() - centerX, block.getY(), block.getZ() - centerZ);
|
||||
handle.setBlockData(bLocation.getBlock(), Material.OAK_SIGN.createBlockData(), false);
|
||||
Sign sign = (Sign) bLocation.getBlock().getState();
|
||||
sign.setLine(1, "[CENTER]");
|
||||
String data = block.getBlockData().getAsString(true);
|
||||
setTerraSign(sign, data);
|
||||
sign.update();
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch(IOException e) {
|
||||
e.printStackTrace();
|
||||
LangUtil.send("command.structure.invalid", sender, args[0]);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "raw";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<org.polydev.gaea.command.Command> getSubCommands() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int arguments() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompletions(@NotNull CommandSender commandSender, @NotNull String s, @NotNull String[] args) {
|
||||
if(args.length == 1) {
|
||||
return getStructureNames().stream().filter(string -> string.toUpperCase().startsWith(args[0].toUpperCase())).collect(Collectors.toList());
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
@@ -1,237 +0,0 @@
|
||||
package com.dfsek.terra.config.base;
|
||||
|
||||
import com.dfsek.tectonic.abstraction.AbstractConfigLoader;
|
||||
import com.dfsek.tectonic.exception.ConfigException;
|
||||
import com.dfsek.tectonic.exception.LoadException;
|
||||
import com.dfsek.tectonic.loading.ConfigLoader;
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.biome.UserDefinedBiome;
|
||||
import com.dfsek.terra.biome.grid.master.TerraBiomeGrid;
|
||||
import com.dfsek.terra.carving.UserDefinedCarver;
|
||||
import com.dfsek.terra.config.builder.biomegrid.BiomeGridBuilder;
|
||||
import com.dfsek.terra.config.exception.FileMissingException;
|
||||
import com.dfsek.terra.config.factories.BiomeFactory;
|
||||
import com.dfsek.terra.config.factories.BiomeGridFactory;
|
||||
import com.dfsek.terra.config.factories.CarverFactory;
|
||||
import com.dfsek.terra.config.factories.FloraFactory;
|
||||
import com.dfsek.terra.config.factories.OreFactory;
|
||||
import com.dfsek.terra.config.factories.PaletteFactory;
|
||||
import com.dfsek.terra.config.factories.StructureFactory;
|
||||
import com.dfsek.terra.config.factories.TerraFactory;
|
||||
import com.dfsek.terra.config.factories.TreeFactory;
|
||||
import com.dfsek.terra.config.files.FolderLoader;
|
||||
import com.dfsek.terra.config.files.Loader;
|
||||
import com.dfsek.terra.config.files.ZIPLoader;
|
||||
import com.dfsek.terra.config.lang.LangUtil;
|
||||
import com.dfsek.terra.config.loaders.LootTableLoader;
|
||||
import com.dfsek.terra.config.loaders.StructureLoader;
|
||||
import com.dfsek.terra.config.templates.AbstractableTemplate;
|
||||
import com.dfsek.terra.config.templates.BiomeGridTemplate;
|
||||
import com.dfsek.terra.config.templates.BiomeTemplate;
|
||||
import com.dfsek.terra.config.templates.CarverTemplate;
|
||||
import com.dfsek.terra.config.templates.FloraTemplate;
|
||||
import com.dfsek.terra.config.templates.OreTemplate;
|
||||
import com.dfsek.terra.config.templates.PaletteTemplate;
|
||||
import com.dfsek.terra.config.templates.StructureTemplate;
|
||||
import com.dfsek.terra.config.templates.TreeTemplate;
|
||||
import com.dfsek.terra.generation.items.TerraStructure;
|
||||
import com.dfsek.terra.generation.items.ores.Ore;
|
||||
import com.dfsek.terra.registry.BiomeGridRegistry;
|
||||
import com.dfsek.terra.registry.BiomeRegistry;
|
||||
import com.dfsek.terra.registry.CarverRegistry;
|
||||
import com.dfsek.terra.registry.FloraRegistry;
|
||||
import com.dfsek.terra.registry.OreRegistry;
|
||||
import com.dfsek.terra.registry.PaletteRegistry;
|
||||
import com.dfsek.terra.registry.StructureRegistry;
|
||||
import com.dfsek.terra.registry.TerraRegistry;
|
||||
import com.dfsek.terra.registry.TreeRegistry;
|
||||
import com.dfsek.terra.structure.Structure;
|
||||
import com.dfsek.terra.util.StructureTypeEnum;
|
||||
import org.polydev.gaea.biome.Biome;
|
||||
import org.polydev.gaea.structures.loot.LootTable;
|
||||
import org.polydev.gaea.tree.Tree;
|
||||
import org.polydev.gaea.world.Flora;
|
||||
import org.polydev.gaea.world.palette.Palette;
|
||||
import parsii.eval.Scope;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
/**
|
||||
* Represents a Terra configuration pack.
|
||||
*/
|
||||
public class ConfigPack {
|
||||
private final ConfigPackTemplate template = new ConfigPackTemplate();
|
||||
private final BiomeRegistry biomeRegistry = new BiomeRegistry();
|
||||
private final BiomeGridRegistry biomeGridRegistry = new BiomeGridRegistry(biomeRegistry);
|
||||
private final StructureRegistry structureRegistry = new StructureRegistry();
|
||||
private final CarverRegistry carverRegistry = new CarverRegistry();
|
||||
private final PaletteRegistry paletteRegistry = new PaletteRegistry();
|
||||
private final FloraRegistry floraRegistry = new FloraRegistry();
|
||||
private final OreRegistry oreRegistry = new OreRegistry();
|
||||
private final TreeRegistry treeRegistry = new TreeRegistry();
|
||||
|
||||
private final AbstractConfigLoader abstractConfigLoader = new AbstractConfigLoader();
|
||||
private final ConfigLoader selfLoader = new ConfigLoader();
|
||||
private final Scope varScope = new Scope();
|
||||
|
||||
private final Map<StructureTypeEnum, TerraStructure> structureMap = new HashMap<>();
|
||||
|
||||
{
|
||||
abstractConfigLoader
|
||||
.registerLoader(Palette.class, paletteRegistry)
|
||||
.registerLoader(Biome.class, biomeRegistry)
|
||||
.registerLoader(UserDefinedCarver.class, carverRegistry)
|
||||
.registerLoader(Flora.class, floraRegistry)
|
||||
.registerLoader(Ore.class, oreRegistry)
|
||||
.registerLoader(Tree.class, treeRegistry)
|
||||
.registerLoader(TerraStructure.class, structureRegistry);
|
||||
}
|
||||
|
||||
public ConfigPack(File folder, Terra main) throws ConfigException {
|
||||
long l = System.nanoTime();
|
||||
|
||||
main.registerAllLoaders(selfLoader);
|
||||
main.registerAllLoaders(abstractConfigLoader);
|
||||
|
||||
File pack = new File(folder, "pack.yml");
|
||||
|
||||
try {
|
||||
selfLoader.load(template, new FileInputStream(pack));
|
||||
} catch(FileNotFoundException e) {
|
||||
throw new FileMissingException("No pack.yml file found in " + folder.getAbsolutePath(), e);
|
||||
}
|
||||
|
||||
load(new FolderLoader(folder.toPath()), l, main);
|
||||
}
|
||||
|
||||
public ConfigPack(ZipFile file, Terra main) throws ConfigException {
|
||||
long l = System.nanoTime();
|
||||
|
||||
main.registerAllLoaders(selfLoader);
|
||||
main.registerAllLoaders(abstractConfigLoader);
|
||||
|
||||
InputStream stream = null;
|
||||
|
||||
try {
|
||||
Enumeration<? extends ZipEntry> entries = file.entries();
|
||||
while(entries.hasMoreElements()) {
|
||||
ZipEntry entry = entries.nextElement();
|
||||
if(entry.getName().equals("pack.yml")) stream = file.getInputStream(entry);
|
||||
}
|
||||
} catch(IOException e) {
|
||||
throw new LoadException("Unable to load pack.yml from ZIP file", e);
|
||||
}
|
||||
if(stream == null) throw new FileMissingException("No pack.yml file found in " + file.getName());
|
||||
|
||||
selfLoader.load(template, stream);
|
||||
|
||||
load(new ZIPLoader(file), l, main);
|
||||
}
|
||||
|
||||
private void load(Loader loader, long start, Terra main) throws ConfigException {
|
||||
for(Map.Entry<String, Double> var : template.getVariables().entrySet()) {
|
||||
varScope.create(var.getKey()).setValue(var.getValue());
|
||||
}
|
||||
abstractConfigLoader.registerLoader(Structure.class, new StructureLoader(loader))
|
||||
.registerLoader(LootTable.class, new LootTableLoader(loader)); // These loaders need access to the Loader instance to get files.
|
||||
loader
|
||||
.open("palettes").then(streams -> buildAll(new PaletteFactory(), paletteRegistry, abstractConfigLoader.load(streams, PaletteTemplate::new), main)).close()
|
||||
.open("ores").then(streams -> buildAll(new OreFactory(), oreRegistry, abstractConfigLoader.load(streams, OreTemplate::new), main)).close()
|
||||
.open("flora").then(streams -> buildAll(new FloraFactory(), floraRegistry, abstractConfigLoader.load(streams, FloraTemplate::new), main)).close()
|
||||
.open("carving").then(streams -> buildAll(new CarverFactory(this), carverRegistry, abstractConfigLoader.load(streams, CarverTemplate::new), main)).close()
|
||||
.open("structures/trees").then(streams -> buildAll(new TreeFactory(), treeRegistry, abstractConfigLoader.load(streams, TreeTemplate::new), main)).close()
|
||||
.open("structures/single").then(streams -> buildAll(new StructureFactory(), structureRegistry, abstractConfigLoader.load(streams, StructureTemplate::new), main)).close()
|
||||
.open("biomes").then(streams -> buildAll(new BiomeFactory(this), biomeRegistry, abstractConfigLoader.load(streams, () -> new BiomeTemplate(this)), main)).close()
|
||||
.open("grids").then(streams -> buildAll(new BiomeGridFactory(), biomeGridRegistry, abstractConfigLoader.load(streams, BiomeGridTemplate::new), main)).close();
|
||||
for(UserDefinedBiome b : biomeRegistry.entries()) {
|
||||
try {
|
||||
Objects.requireNonNull(b.getErode()); // Throws NPE if it cannot load erosion biomes.
|
||||
} catch(NullPointerException e) {
|
||||
throw new LoadException("Invalid erosion biome defined in biome \"" + b.getID() + "\"", e);
|
||||
}
|
||||
}
|
||||
|
||||
for(String gridName : template.getGrids()) {
|
||||
if(!biomeGridRegistry.contains(gridName)) throw new LoadException("No such BiomeGrid \"" + gridName + "\"");
|
||||
}
|
||||
|
||||
if(template.getGridType().equals(TerraBiomeGrid.Type.RADIAL) && !biomeGridRegistry.contains(template.getRadialInternalGrid())) {
|
||||
throw new LoadException("No such BiomeGrid \"" + template.getRadialInternalGrid() + "\"");
|
||||
}
|
||||
|
||||
template.getStructureLocatables().forEach((type, name) -> structureMap.put(Objects.requireNonNull(type), Objects.requireNonNull(structureRegistry.get(name))));
|
||||
|
||||
LangUtil.log("config-pack.loaded", Level.INFO, template.getID(), String.valueOf((System.nanoTime() - start) / 1000000D), template.getAuthor(), template.getVersion());
|
||||
}
|
||||
|
||||
private <C extends AbstractableTemplate, O> void buildAll(TerraFactory<C, O> factory, TerraRegistry<O> registry, List<C> configTemplates, Terra main) throws LoadException {
|
||||
for(C template : configTemplates) registry.add(template.getID(), factory.build(template, main));
|
||||
}
|
||||
|
||||
public UserDefinedBiome getBiome(String id) {
|
||||
return biomeRegistry.get(id);
|
||||
}
|
||||
|
||||
public BiomeGridBuilder getBiomeGrid(String id) {
|
||||
return biomeGridRegistry.get(id);
|
||||
}
|
||||
|
||||
public List<String> getBiomeIDs() {
|
||||
List<String> biomeIDs = new ArrayList<>();
|
||||
biomeRegistry.forEach(biome -> biomeIDs.add(biome.getID()));
|
||||
return biomeIDs;
|
||||
}
|
||||
|
||||
public TerraStructure getStructure(String id) {
|
||||
return structureRegistry.get(id);
|
||||
}
|
||||
|
||||
public Set<TerraStructure> getStructures() {
|
||||
return structureRegistry.entries();
|
||||
}
|
||||
|
||||
public Collection<UserDefinedCarver> getCarvers() {
|
||||
return carverRegistry.entries();
|
||||
}
|
||||
|
||||
public UserDefinedCarver getCarver(String id) {
|
||||
return carverRegistry.get(id);
|
||||
}
|
||||
|
||||
public List<String> getStructureIDs() {
|
||||
List<String> ids = new ArrayList<>();
|
||||
structureRegistry.forEach(structure -> ids.add(structure.getTemplate().getID()));
|
||||
return ids;
|
||||
}
|
||||
|
||||
public TreeRegistry getTreeRegistry() {
|
||||
return treeRegistry;
|
||||
}
|
||||
|
||||
public ConfigPackTemplate getTemplate() {
|
||||
return template;
|
||||
}
|
||||
|
||||
public Scope getVarScope() {
|
||||
return varScope;
|
||||
}
|
||||
|
||||
public TerraStructure getStructureLocatable(StructureTypeEnum type) {
|
||||
return structureMap.get(type);
|
||||
}
|
||||
}
|
||||
@@ -1,262 +0,0 @@
|
||||
package com.dfsek.terra.config.base;
|
||||
|
||||
import com.dfsek.tectonic.annotations.Default;
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.tectonic.config.ValidatedConfigTemplate;
|
||||
import com.dfsek.tectonic.exception.ValidationException;
|
||||
import com.dfsek.terra.biome.grid.master.TerraBiomeGrid;
|
||||
import com.dfsek.terra.generation.config.NoiseBuilder;
|
||||
import com.dfsek.terra.image.ImageLoader;
|
||||
import com.dfsek.terra.util.StructureTypeEnum;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@SuppressWarnings({"unused", "FieldMayBeFinal"})
|
||||
public class ConfigPackTemplate implements ValidatedConfigTemplate {
|
||||
@Value("id")
|
||||
private String id;
|
||||
|
||||
@Value("noise")
|
||||
private Map<String, NoiseBuilder> noiseBuilderMap;
|
||||
|
||||
@Value("variables")
|
||||
@Default
|
||||
private Map<String, Double> variables = new HashMap<>();
|
||||
|
||||
@Value("locatable")
|
||||
@Default
|
||||
private Map<StructureTypeEnum, String> structureLocatables = new HashMap<>();
|
||||
|
||||
@Value("grids")
|
||||
private List<String> grids;
|
||||
|
||||
@Value("frequencies.grid-x")
|
||||
@Default
|
||||
private int gridFreqX = 4096;
|
||||
|
||||
@Value("frequencies.grid-z")
|
||||
@Default
|
||||
private int gridFreqZ = 4096;
|
||||
|
||||
@Value("frequencies.zone")
|
||||
@Default
|
||||
private int zoneFreq = 2048;
|
||||
|
||||
@Value("blend.enable")
|
||||
@Default
|
||||
private boolean blend = false;
|
||||
|
||||
@Value("blend.frequency")
|
||||
@Default
|
||||
private double blendFreq = 0.1;
|
||||
|
||||
@Value("blend.amplitude")
|
||||
@Default
|
||||
private double blendAmp = 4.0D;
|
||||
|
||||
@Value("erode.enable")
|
||||
@Default
|
||||
private boolean erode = false;
|
||||
|
||||
@Value("erode.frequency")
|
||||
@Default
|
||||
private double erodeFreq = 0.001D;
|
||||
|
||||
@Value("erode.threshold")
|
||||
@Default
|
||||
private double erodeThresh = 0.0015D;
|
||||
|
||||
@Value("erode.octaves")
|
||||
@Default
|
||||
private int erodeOctaves = 5;
|
||||
|
||||
@Value("vanilla.mobs")
|
||||
@Default
|
||||
private boolean vanillaMobs = true;
|
||||
|
||||
@Value("vanilla.caves")
|
||||
@Default
|
||||
private boolean vanillaCaves = false;
|
||||
|
||||
@Value("vanilla.decorations")
|
||||
@Default
|
||||
private boolean vanillaDecorations = false;
|
||||
|
||||
@Value("vanilla.structures")
|
||||
@Default
|
||||
private boolean vanillaStructures = false;
|
||||
|
||||
@Value("author")
|
||||
@Default
|
||||
private String author = "Anon Y. Mous";
|
||||
|
||||
@Value("disable.sapling")
|
||||
@Default
|
||||
private boolean disableSaplings = false;
|
||||
|
||||
@Value("version")
|
||||
@Default
|
||||
private String version = "0.1.0";
|
||||
|
||||
@Value("grid-options.type")
|
||||
@Default
|
||||
private TerraBiomeGrid.Type gridType = TerraBiomeGrid.Type.STANDARD;
|
||||
|
||||
@Value("grid-options.radial.radius")
|
||||
@Default
|
||||
private double radius = 1000D;
|
||||
|
||||
@Value("grid-options.radial.internal-grid")
|
||||
@Default
|
||||
private String internalGrid = null;
|
||||
|
||||
@Value("image.enable")
|
||||
@Default
|
||||
private boolean fromImage = false;
|
||||
|
||||
@Value("image.channels.biome-x")
|
||||
@Default
|
||||
private ImageLoader.Channel biomeXChannel = ImageLoader.Channel.RED;
|
||||
@Value("image.channels.biome-z")
|
||||
@Default
|
||||
private ImageLoader.Channel biomeZChannel = ImageLoader.Channel.GREEN;
|
||||
@Value("image.channels.zone")
|
||||
@Default
|
||||
private ImageLoader.Channel zoneChannel = ImageLoader.Channel.BLUE;
|
||||
|
||||
@Value("image")
|
||||
@Default
|
||||
private ImageLoader imageLoader = null;
|
||||
|
||||
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public boolean isDisableSaplings() {
|
||||
return disableSaplings;
|
||||
}
|
||||
|
||||
public String getID() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getAuthor() {
|
||||
return author;
|
||||
}
|
||||
|
||||
public boolean vanillaMobs() {
|
||||
return vanillaMobs;
|
||||
}
|
||||
|
||||
public boolean vanillaCaves() {
|
||||
return vanillaCaves;
|
||||
}
|
||||
|
||||
public boolean vanillaDecorations() {
|
||||
return vanillaDecorations;
|
||||
}
|
||||
|
||||
public boolean vanillaStructures() {
|
||||
return vanillaStructures;
|
||||
}
|
||||
|
||||
public Map<String, NoiseBuilder> getNoiseBuilderMap() {
|
||||
return noiseBuilderMap;
|
||||
}
|
||||
|
||||
public Map<String, Double> getVariables() {
|
||||
return variables;
|
||||
}
|
||||
|
||||
public Map<StructureTypeEnum, String> getStructureLocatables() {
|
||||
return structureLocatables;
|
||||
}
|
||||
|
||||
public List<String> getGrids() {
|
||||
return grids;
|
||||
}
|
||||
|
||||
public int getGridFreqX() {
|
||||
return gridFreqX;
|
||||
}
|
||||
|
||||
public int getGridFreqZ() {
|
||||
return gridFreqZ;
|
||||
}
|
||||
|
||||
public int getZoneFreq() {
|
||||
return zoneFreq;
|
||||
}
|
||||
|
||||
public boolean isBlend() {
|
||||
return blend;
|
||||
}
|
||||
|
||||
public double getBlendFreq() {
|
||||
return blendFreq;
|
||||
}
|
||||
|
||||
public double getBlendAmp() {
|
||||
return blendAmp;
|
||||
}
|
||||
|
||||
public boolean isErode() {
|
||||
return erode;
|
||||
}
|
||||
|
||||
public double getErodeFreq() {
|
||||
return erodeFreq;
|
||||
}
|
||||
|
||||
public double getErodeThresh() {
|
||||
return erodeThresh;
|
||||
}
|
||||
|
||||
public int getErodeOctaves() {
|
||||
return erodeOctaves;
|
||||
}
|
||||
|
||||
public double getRadialGridRadius() {
|
||||
return radius;
|
||||
}
|
||||
|
||||
public String getRadialInternalGrid() {
|
||||
return internalGrid;
|
||||
}
|
||||
|
||||
public TerraBiomeGrid.Type getGridType() {
|
||||
return gridType;
|
||||
}
|
||||
|
||||
public ImageLoader.Channel getBiomeXChannel() {
|
||||
return biomeXChannel;
|
||||
}
|
||||
|
||||
public ImageLoader.Channel getBiomeZChannel() {
|
||||
return biomeZChannel;
|
||||
}
|
||||
|
||||
public boolean isFromImage() {
|
||||
return fromImage;
|
||||
}
|
||||
|
||||
public ImageLoader.Channel getZoneChannel() {
|
||||
return zoneChannel;
|
||||
}
|
||||
|
||||
public ImageLoader getImageLoader() {
|
||||
return imageLoader;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean validate() throws ValidationException {
|
||||
if(gridType.equals(TerraBiomeGrid.Type.RADIAL) && internalGrid == null)
|
||||
throw new ValidationException("No internal BiomeGrid specified");
|
||||
if(biomeZChannel.equals(biomeXChannel) || zoneChannel.equals(biomeXChannel) || zoneChannel.equals(biomeZChannel))
|
||||
throw new ValidationException("2 objects share the same image channels: biome-x and biome-z");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,87 +0,0 @@
|
||||
package com.dfsek.terra.config.base;
|
||||
|
||||
import com.dfsek.tectonic.annotations.Default;
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.tectonic.config.ConfigTemplate;
|
||||
import com.dfsek.tectonic.exception.ConfigException;
|
||||
import com.dfsek.tectonic.loading.ConfigLoader;
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.debug.Debug;
|
||||
import org.polydev.gaea.GaeaPlugin;
|
||||
import org.polydev.gaea.util.JarUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.time.Duration;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@SuppressWarnings("FieldMayBeFinal")
|
||||
public class PluginConfig implements ConfigTemplate {
|
||||
@Value("debug")
|
||||
@Default
|
||||
private boolean debug = false;
|
||||
|
||||
@Value("language")
|
||||
@Default
|
||||
private String language = "en_us";
|
||||
|
||||
@Value("data-save")
|
||||
@Default
|
||||
private Duration dataSave = Duration.parse("PT6M");
|
||||
|
||||
@Value("biome-search-resolution")
|
||||
@Default
|
||||
private int biomeSearch = 4;
|
||||
|
||||
@Value("cache-size")
|
||||
@Default
|
||||
private int cacheSize = 384;
|
||||
|
||||
@Value("dump-default")
|
||||
@Default
|
||||
private boolean dumpDefaultConfig = true;
|
||||
|
||||
public void load(GaeaPlugin main) {
|
||||
Logger logger = main.getLogger();
|
||||
logger.info("Loading config values");
|
||||
try(FileInputStream file = new FileInputStream(new File(main.getDataFolder(), "config.yml"))) {
|
||||
ConfigLoader loader = new ConfigLoader();
|
||||
loader.load(this, file);
|
||||
if(dumpDefaultConfig) { // Don't dump default config if already loaded.
|
||||
try(JarFile jar = new JarFile(new File(Terra.class.getProtectionDomain().getCodeSource().getLocation().toURI()))) {
|
||||
JarUtil.copyResourcesToDirectory(jar, "packs", new File(main.getDataFolder(), "packs").toString());
|
||||
} catch(IOException | URISyntaxException e) {
|
||||
Debug.error("Failed to dump default config files!");
|
||||
e.printStackTrace();
|
||||
Debug.error("Report this to Terra!");
|
||||
}
|
||||
}
|
||||
} catch(ConfigException | IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
logger.info("Debug: " + isDebug());
|
||||
}
|
||||
|
||||
public String getLanguage() {
|
||||
return language;
|
||||
}
|
||||
|
||||
public boolean isDebug() {
|
||||
return debug;
|
||||
}
|
||||
|
||||
public long getDataSaveInterval() {
|
||||
return dataSave.toMillis() / 20L;
|
||||
}
|
||||
|
||||
public int getBiomeSearchResolution() {
|
||||
return biomeSearch;
|
||||
}
|
||||
|
||||
public int getCacheSize() {
|
||||
return cacheSize;
|
||||
}
|
||||
}
|
||||
@@ -1,97 +0,0 @@
|
||||
package com.dfsek.terra.config.builder;
|
||||
|
||||
import com.dfsek.terra.biome.palette.PaletteHolder;
|
||||
import com.dfsek.terra.generation.config.NoiseBuilder;
|
||||
import com.dfsek.terra.generation.config.WorldGenerator;
|
||||
import parsii.eval.Scope;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class GeneratorBuilder {
|
||||
private final Map<Long, WorldGenerator> gens = new HashMap<>();
|
||||
|
||||
private String noiseEquation;
|
||||
|
||||
private String elevationEquation;
|
||||
|
||||
private Scope varScope;
|
||||
|
||||
private Map<String, NoiseBuilder> noiseBuilderMap;
|
||||
|
||||
private PaletteHolder palettes;
|
||||
|
||||
private PaletteHolder slantPalettes;
|
||||
|
||||
private boolean preventInterpolation;
|
||||
|
||||
private boolean interpolateElevation;
|
||||
|
||||
public WorldGenerator build(long seed) {
|
||||
return gens.computeIfAbsent(seed, k -> new WorldGenerator(seed, noiseEquation, elevationEquation, varScope, noiseBuilderMap, palettes, slantPalettes, preventInterpolation, interpolateElevation));
|
||||
}
|
||||
|
||||
public String getNoiseEquation() {
|
||||
return noiseEquation;
|
||||
}
|
||||
|
||||
public void setNoiseEquation(String noiseEquation) {
|
||||
this.noiseEquation = noiseEquation;
|
||||
}
|
||||
|
||||
public String getElevationEquation() {
|
||||
return elevationEquation;
|
||||
}
|
||||
|
||||
public void setElevationEquation(String elevationEquation) {
|
||||
this.elevationEquation = elevationEquation;
|
||||
}
|
||||
|
||||
public Scope getVarScope() {
|
||||
return varScope;
|
||||
}
|
||||
|
||||
public void setVarScope(Scope varScope) {
|
||||
this.varScope = varScope;
|
||||
}
|
||||
|
||||
public Map<String, NoiseBuilder> getNoiseBuilderMap() {
|
||||
return noiseBuilderMap;
|
||||
}
|
||||
|
||||
public void setNoiseBuilderMap(Map<String, NoiseBuilder> noiseBuilderMap) {
|
||||
this.noiseBuilderMap = noiseBuilderMap;
|
||||
}
|
||||
|
||||
public PaletteHolder getPalettes() {
|
||||
return palettes;
|
||||
}
|
||||
|
||||
public void setPalettes(PaletteHolder palettes) {
|
||||
this.palettes = palettes;
|
||||
}
|
||||
|
||||
public PaletteHolder getSlantPalettes() {
|
||||
return slantPalettes;
|
||||
}
|
||||
|
||||
public void setSlantPalettes(PaletteHolder slantPalettes) {
|
||||
this.slantPalettes = slantPalettes;
|
||||
}
|
||||
|
||||
public boolean isPreventInterpolation() {
|
||||
return preventInterpolation;
|
||||
}
|
||||
|
||||
public void setPreventInterpolation(boolean preventInterpolation) {
|
||||
this.preventInterpolation = preventInterpolation;
|
||||
}
|
||||
|
||||
public void setInterpolateElevation(boolean interpolateElevation) {
|
||||
this.interpolateElevation = interpolateElevation;
|
||||
}
|
||||
|
||||
public boolean interpolateElevation() {
|
||||
return interpolateElevation;
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
package com.dfsek.terra.config.builder.biomegrid;
|
||||
|
||||
import com.dfsek.terra.config.base.ConfigPack;
|
||||
import org.bukkit.World;
|
||||
import org.polydev.gaea.biome.BiomeGrid;
|
||||
|
||||
public interface BiomeGridBuilder {
|
||||
BiomeGrid build(World world, ConfigPack config);
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
package com.dfsek.terra.config.builder.biomegrid;
|
||||
|
||||
import com.dfsek.terra.biome.grid.SingleBiomeGrid;
|
||||
import com.dfsek.terra.config.base.ConfigPack;
|
||||
import org.bukkit.World;
|
||||
import org.polydev.gaea.biome.Biome;
|
||||
|
||||
public class SingleGridBuilder implements BiomeGridBuilder {
|
||||
private final Biome biome;
|
||||
|
||||
public SingleGridBuilder(Biome biome) {
|
||||
this.biome = biome;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SingleBiomeGrid build(World world, ConfigPack config) {
|
||||
return new SingleBiomeGrid(world, biome);
|
||||
}
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
package com.dfsek.terra.config.builder.biomegrid;
|
||||
|
||||
import com.dfsek.terra.biome.grid.UserDefinedGrid;
|
||||
import com.dfsek.terra.config.base.ConfigPack;
|
||||
import org.bukkit.World;
|
||||
import org.polydev.gaea.biome.Biome;
|
||||
|
||||
public class UserDefinedGridBuilder implements BiomeGridBuilder {
|
||||
private double xFreq;
|
||||
private double zFreq;
|
||||
|
||||
private Biome[][] biomes;
|
||||
|
||||
@Override
|
||||
public UserDefinedGrid build(World world, ConfigPack config) {
|
||||
return new UserDefinedGrid(world, 1D / xFreq, 1D / zFreq, biomes, config);
|
||||
}
|
||||
|
||||
public double getXFreq() {
|
||||
return xFreq;
|
||||
}
|
||||
|
||||
public void setXFreq(double xFreq) {
|
||||
this.xFreq = xFreq;
|
||||
}
|
||||
|
||||
public double getZFreq() {
|
||||
return zFreq;
|
||||
}
|
||||
|
||||
public void setZFreq(double zFreq) {
|
||||
this.zFreq = zFreq;
|
||||
}
|
||||
|
||||
public Biome[][] getBiomes() {
|
||||
return biomes;
|
||||
}
|
||||
|
||||
public void setBiomes(Biome[][] biomes) {
|
||||
this.biomes = biomes;
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
package com.dfsek.terra.config.exception;
|
||||
|
||||
import com.dfsek.tectonic.exception.ConfigException;
|
||||
|
||||
public class FileMissingException extends ConfigException {
|
||||
private static final long serialVersionUID = 4489395640246760802L;
|
||||
|
||||
public FileMissingException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public FileMissingException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
package com.dfsek.terra.config.factories;
|
||||
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.biome.UserDefinedBiome;
|
||||
import com.dfsek.terra.config.base.ConfigPack;
|
||||
import com.dfsek.terra.config.builder.GeneratorBuilder;
|
||||
import com.dfsek.terra.config.templates.BiomeTemplate;
|
||||
import com.dfsek.terra.generation.UserDefinedDecorator;
|
||||
import org.polydev.gaea.math.ProbabilityCollection;
|
||||
|
||||
public class BiomeFactory implements TerraFactory<BiomeTemplate, UserDefinedBiome> {
|
||||
private final ConfigPack pack;
|
||||
|
||||
public BiomeFactory(ConfigPack pack) {
|
||||
this.pack = pack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserDefinedBiome build(BiomeTemplate template, Terra main) {
|
||||
UserDefinedDecorator decorator = new UserDefinedDecorator(new ProbabilityCollection<>(), new ProbabilityCollection<>(), 0, 0);
|
||||
GeneratorBuilder generatorBuilder = new GeneratorBuilder();
|
||||
generatorBuilder.setElevationEquation(template.getElevationEquation());
|
||||
generatorBuilder.setNoiseEquation(template.getNoiseEquation());
|
||||
generatorBuilder.setNoiseBuilderMap(template.getPack().getTemplate().getNoiseBuilderMap());
|
||||
generatorBuilder.setPalettes(template.getPalette());
|
||||
generatorBuilder.setSlantPalettes(template.getSlantPalette());
|
||||
generatorBuilder.setVarScope(pack.getVarScope());
|
||||
generatorBuilder.setInterpolateElevation(template.interpolateElevation());
|
||||
|
||||
|
||||
return new UserDefinedBiome(template.getVanilla(), decorator, generatorBuilder, template, pack);
|
||||
}
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
package com.dfsek.terra.config.factories;
|
||||
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.biome.UserDefinedBiome;
|
||||
import com.dfsek.terra.config.builder.biomegrid.BiomeGridBuilder;
|
||||
import com.dfsek.terra.config.builder.biomegrid.UserDefinedGridBuilder;
|
||||
import com.dfsek.terra.config.templates.BiomeGridTemplate;
|
||||
import org.polydev.gaea.biome.Biome;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class BiomeGridFactory implements TerraFactory<BiomeGridTemplate, BiomeGridBuilder> {
|
||||
|
||||
@Override
|
||||
public UserDefinedGridBuilder build(BiomeGridTemplate config, Terra main) {
|
||||
|
||||
UserDefinedGridBuilder holder = new UserDefinedGridBuilder();
|
||||
holder.setXFreq(config.getXFreq());
|
||||
holder.setZFreq(config.getZFreq());
|
||||
|
||||
int xSize = config.getGrid().size();
|
||||
int zSize = config.getGrid().get(0).size();
|
||||
|
||||
Biome[][] biomes = new UserDefinedBiome[xSize][zSize];
|
||||
|
||||
for(int x = 0; x < xSize; x++) {
|
||||
List<Biome> layer = config.getGrid().get(x);
|
||||
if(!(layer.size() == zSize)) throw new IllegalArgumentException();
|
||||
for(int z = 0; z < zSize; z++) {
|
||||
biomes[x][z] = layer.get(z);
|
||||
}
|
||||
}
|
||||
holder.setBiomes(biomes);
|
||||
|
||||
return holder;
|
||||
}
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
package com.dfsek.terra.config.factories;
|
||||
|
||||
import com.dfsek.tectonic.exception.LoadException;
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.carving.UserDefinedCarver;
|
||||
import com.dfsek.terra.config.base.ConfigPack;
|
||||
import com.dfsek.terra.config.templates.CarverTemplate;
|
||||
import org.polydev.gaea.math.MathUtil;
|
||||
import parsii.tokenizer.ParseException;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class CarverFactory implements TerraFactory<CarverTemplate, UserDefinedCarver> {
|
||||
private final ConfigPack pack;
|
||||
|
||||
public CarverFactory(ConfigPack pack) {
|
||||
this.pack = pack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserDefinedCarver build(CarverTemplate config, Terra main) throws LoadException {
|
||||
double[] start = new double[] {config.getStartX(), config.getStartY(), config.getStartZ()};
|
||||
double[] mutate = new double[] {config.getMutateX(), config.getMutateY(), config.getMutateZ()};
|
||||
List<String> radius = Arrays.asList(config.getRadMX(), config.getRadMY(), config.getRadMZ());
|
||||
long hash = MathUtil.hashToLong(config.getID());
|
||||
UserDefinedCarver carver;
|
||||
try {
|
||||
carver = new UserDefinedCarver(config.getHeight(), config.getLength(), start, mutate, radius, pack.getVarScope(), hash, config.getCutTop(), config.getCutBottom(), config, main);
|
||||
} catch(ParseException e) {
|
||||
throw new LoadException("Unable to parse radius equations", e);
|
||||
}
|
||||
carver.setRecalc(config.getRecalc());
|
||||
carver.setRecalcMagnitude(config.getRecaclulateMagnitude());
|
||||
return carver;
|
||||
}
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
package com.dfsek.terra.config.factories;
|
||||
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.biome.palette.PaletteLayer;
|
||||
import com.dfsek.terra.config.templates.FloraTemplate;
|
||||
import com.dfsek.terra.generation.items.flora.TerraFlora;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.polydev.gaea.util.FastRandom;
|
||||
import org.polydev.gaea.world.Flora;
|
||||
import org.polydev.gaea.world.palette.Palette;
|
||||
import org.polydev.gaea.world.palette.RandomPalette;
|
||||
|
||||
public class FloraFactory implements TerraFactory<FloraTemplate, Flora> {
|
||||
@Override
|
||||
public TerraFlora build(FloraTemplate config, Terra main) {
|
||||
Palette<BlockData> palette = new RandomPalette<>(new FastRandom(2403));
|
||||
for(PaletteLayer layer : config.getFloraPalette()) {
|
||||
palette.add(layer.getLayer(), layer.getSize());
|
||||
}
|
||||
return new TerraFlora(palette, config.doPhysics(), config.isCeiling(), config.getIrrigable(), config.getSpawnable(), config.getReplaceable(), config.getRotatable(), config.getMaxPlacements(), config.getSearch(), config.isSpawnBlacklist(), config.getIrrigableOffset(), main);
|
||||
}
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
package com.dfsek.terra.config.factories;
|
||||
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.config.templates.OreTemplate;
|
||||
import com.dfsek.terra.generation.items.ores.DeformedSphereOre;
|
||||
import com.dfsek.terra.generation.items.ores.Ore;
|
||||
import com.dfsek.terra.generation.items.ores.VanillaOre;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
|
||||
public class OreFactory implements TerraFactory<OreTemplate, Ore> {
|
||||
@Override
|
||||
public Ore build(OreTemplate config, Terra main) {
|
||||
BlockData m = config.getMaterial();
|
||||
switch(config.getType()) {
|
||||
case SPHERE:
|
||||
return new DeformedSphereOre(m, config.getReplaceable(), config.doPhysics(), config.getDeform(), config.getDeformFrequency(), config.getSize(), main);
|
||||
case VANILLA:
|
||||
return new VanillaOre(m, config.getReplaceable(), config.doPhysics(), config.getSize(), main);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
package com.dfsek.terra.config.factories;
|
||||
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.biome.palette.PaletteLayer;
|
||||
import com.dfsek.terra.config.templates.PaletteTemplate;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.polydev.gaea.math.FastNoiseLite;
|
||||
import org.polydev.gaea.util.FastRandom;
|
||||
import org.polydev.gaea.world.palette.Palette;
|
||||
import org.polydev.gaea.world.palette.RandomPalette;
|
||||
import org.polydev.gaea.world.palette.SimplexPalette;
|
||||
|
||||
public class PaletteFactory implements TerraFactory<PaletteTemplate, Palette<BlockData>> {
|
||||
@Override
|
||||
public Palette<BlockData> build(PaletteTemplate config, Terra main) {
|
||||
Palette<BlockData> palette;
|
||||
if(config.isSimplex()) {
|
||||
FastNoiseLite noise = new FastNoiseLite((int) config.getSeed());
|
||||
noise.setFrequency(config.getFrequency());
|
||||
palette = new SimplexPalette<>(noise);
|
||||
} else palette = new RandomPalette<>(new FastRandom(config.getSeed()));
|
||||
|
||||
for(PaletteLayer layer : config.getPalette()) {
|
||||
palette.add(layer.getLayer(), layer.getSize());
|
||||
}
|
||||
return palette;
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
package com.dfsek.terra.config.factories;
|
||||
|
||||
import com.dfsek.tectonic.exception.LoadException;
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.config.templates.StructureTemplate;
|
||||
import com.dfsek.terra.generation.items.TerraStructure;
|
||||
|
||||
public class StructureFactory implements TerraFactory<StructureTemplate, TerraStructure> {
|
||||
@Override
|
||||
public TerraStructure build(StructureTemplate config, Terra main) throws LoadException {
|
||||
return new TerraStructure(config.getStructures(), config.getBound(), config.getY(), config.getSpawn(), config.getLoot(), config);
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
package com.dfsek.terra.config.factories;
|
||||
|
||||
import com.dfsek.tectonic.config.ConfigTemplate;
|
||||
import com.dfsek.tectonic.exception.LoadException;
|
||||
import com.dfsek.terra.Terra;
|
||||
|
||||
public interface TerraFactory<C extends ConfigTemplate, O> {
|
||||
O build(C config, Terra main) throws LoadException;
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
package com.dfsek.terra.config.factories;
|
||||
|
||||
import com.dfsek.tectonic.exception.LoadException;
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.config.templates.TreeTemplate;
|
||||
import com.dfsek.terra.generation.items.tree.TerraTree;
|
||||
import org.polydev.gaea.tree.Tree;
|
||||
|
||||
public class TreeFactory implements TerraFactory<TreeTemplate, Tree> {
|
||||
@Override
|
||||
public Tree build(TreeTemplate config, Terra main) throws LoadException {
|
||||
return new TerraTree(config.getSpawnable(), config.getyOffset(), config.getStructures());
|
||||
}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
package com.dfsek.terra.config.files;
|
||||
|
||||
import com.dfsek.tectonic.exception.ConfigException;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface ExceptionalConsumer<T> {
|
||||
void accept(T t) throws ConfigException;
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
package com.dfsek.terra.config.files;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* Load all {@code *.yml} files from a {@link java.nio.file.Path}.
|
||||
*/
|
||||
public class FolderLoader extends Loader {
|
||||
private final Path path;
|
||||
|
||||
public FolderLoader(Path path) {
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream get(String singleFile) throws IOException {
|
||||
return new FileInputStream(new File(path.toFile(), singleFile));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void load(String directory) {
|
||||
File newPath = new File(path.toFile(), directory);
|
||||
newPath.mkdirs();
|
||||
try(Stream<Path> paths = Files.walk(newPath.toPath())) {
|
||||
paths.filter(Files::isRegularFile).filter(file -> file.toString().toLowerCase().endsWith(".yml")).forEach(file -> {
|
||||
try {
|
||||
streams.add(new FileInputStream(file.toFile()));
|
||||
} catch(FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
} catch(IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
package com.dfsek.terra.config.files;
|
||||
|
||||
import com.dfsek.tectonic.exception.ConfigException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class Loader {
|
||||
protected final List<InputStream> streams = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Do something with the InputStreams.
|
||||
*
|
||||
* @param consumer Something to do with the streams.
|
||||
*/
|
||||
public Loader then(ExceptionalConsumer<List<InputStream>> consumer) throws ConfigException {
|
||||
consumer.accept(streams);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a single file from this Loader.
|
||||
*
|
||||
* @param singleFile File to get
|
||||
* @return InputStream from file.
|
||||
*/
|
||||
public abstract InputStream get(String singleFile) throws IOException;
|
||||
|
||||
/**
|
||||
* Open a subdirectory.
|
||||
*
|
||||
* @param directory Directory to open
|
||||
*/
|
||||
public Loader open(String directory) {
|
||||
if(streams.size() != 0) throw new IllegalStateException("Attempted to load new directory before closing existing InputStreams");
|
||||
load(directory);
|
||||
return this;
|
||||
}
|
||||
|
||||
protected abstract void load(String directory);
|
||||
|
||||
/**
|
||||
* Close all InputStreams opened.
|
||||
*/
|
||||
public Loader close() {
|
||||
streams.forEach(input -> {
|
||||
try {
|
||||
input.close();
|
||||
} catch(IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
streams.clear();
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
package com.dfsek.terra.config.files;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Enumeration;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
public class ZIPLoader extends Loader {
|
||||
private final ZipFile file;
|
||||
|
||||
public ZIPLoader(ZipFile file) {
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream get(String singleFile) throws IOException {
|
||||
Enumeration<? extends ZipEntry> entries = file.entries();
|
||||
while(entries.hasMoreElements()) {
|
||||
ZipEntry entry = entries.nextElement();
|
||||
if(!entry.isDirectory() && entry.getName().equals(singleFile)) return file.getInputStream(entry);
|
||||
}
|
||||
throw new IllegalArgumentException("No such file: " + singleFile);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void load(String directory) {
|
||||
Enumeration<? extends ZipEntry> entries = file.entries();
|
||||
while(entries.hasMoreElements()) {
|
||||
ZipEntry entry = entries.nextElement();
|
||||
if(!entry.isDirectory() && entry.getName().startsWith(directory) && entry.getName().endsWith(".yml")) {
|
||||
try {
|
||||
streams.add(file.getInputStream(entry));
|
||||
} catch(IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
package com.dfsek.terra.config.lang;
|
||||
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.debug.Debug;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.polydev.gaea.lang.Language;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static org.polydev.gaea.util.JarUtil.copyResourcesToDirectory;
|
||||
|
||||
public final class LangUtil {
|
||||
private static Language language;
|
||||
private static Logger logger;
|
||||
|
||||
public static void load(String langID, JavaPlugin main) {
|
||||
logger = main.getLogger();
|
||||
File file = new File(main.getDataFolder(), "lang");
|
||||
try(JarFile jar = new JarFile(new File(Terra.class.getProtectionDomain().getCodeSource().getLocation().toURI()))) {
|
||||
copyResourcesToDirectory(jar, "lang", file.toString());
|
||||
} catch(IOException | URISyntaxException e) {
|
||||
Debug.error("Failed to dump language files!");
|
||||
e.printStackTrace();
|
||||
Debug.error("Report this to Terra!");
|
||||
}
|
||||
try {
|
||||
language = new Language(new File(main.getDataFolder(), "lang" + File.separator + langID + ".yml"));
|
||||
} catch(InvalidConfigurationException | IOException e) {
|
||||
logger.severe("Unable to load language: " + langID);
|
||||
e.printStackTrace();
|
||||
logger.severe("Double-check your configuration before reporting this to Terra!");
|
||||
}
|
||||
}
|
||||
|
||||
public static Language getLanguage() {
|
||||
return language;
|
||||
}
|
||||
|
||||
public static void log(String messageID, Level level, String... args) {
|
||||
language.getMessage(messageID).log(logger, level, args);
|
||||
}
|
||||
|
||||
public static void send(String messageID, CommandSender sender, String... args) {
|
||||
language.getMessage(messageID).send(sender, args);
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
package com.dfsek.terra.config.loaders;
|
||||
|
||||
import com.dfsek.tectonic.exception.LoadException;
|
||||
import com.dfsek.tectonic.loading.ConfigLoader;
|
||||
import com.dfsek.tectonic.loading.TypeLoader;
|
||||
import com.dfsek.terra.image.ImageLoader;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Map;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class ImageLoaderLoader implements TypeLoader<ImageLoader> {
|
||||
@Override
|
||||
public ImageLoader load(Type type, Object o, ConfigLoader configLoader) throws LoadException {
|
||||
Map<String, Object> map = (Map<String, Object>) o;
|
||||
File image = new File((String) map.get("file"));
|
||||
try {
|
||||
return new ImageLoader(image, (ImageLoader.Align) configLoader.loadType(ImageLoader.Align.class, map.get("align")));
|
||||
} catch(IOException e) {
|
||||
throw new LoadException("Unable to load image", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
package com.dfsek.terra.config.loaders;
|
||||
|
||||
import com.dfsek.tectonic.exception.LoadException;
|
||||
import com.dfsek.tectonic.loading.ConfigLoader;
|
||||
import com.dfsek.tectonic.loading.TypeLoader;
|
||||
import com.dfsek.terra.config.files.Loader;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.json.simple.parser.ParseException;
|
||||
import org.polydev.gaea.structures.loot.LootTable;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.Type;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class LootTableLoader implements TypeLoader<LootTable> {
|
||||
private final Loader loader;
|
||||
|
||||
public LootTableLoader(Loader loader) {
|
||||
this.loader = loader;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LootTable load(Type type, Object o, ConfigLoader configLoader) throws LoadException {
|
||||
try(InputStream stream = loader.get("structures/loot/" + o + ".json")) {
|
||||
return new LootTable(IOUtils.toString(stream, StandardCharsets.UTF_8));
|
||||
} catch(IOException | ParseException | NullPointerException e) {
|
||||
throw new LoadException("Unable to load loot", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
package com.dfsek.terra.config.loaders;
|
||||
|
||||
import com.dfsek.tectonic.exception.LoadException;
|
||||
import com.dfsek.tectonic.loading.ConfigLoader;
|
||||
import com.dfsek.tectonic.loading.TypeLoader;
|
||||
import com.dfsek.terra.util.MaterialSet;
|
||||
import org.bukkit.Material;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.List;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class MaterialSetLoader implements TypeLoader<MaterialSet> {
|
||||
@Override
|
||||
public MaterialSet load(Type type, Object o, ConfigLoader configLoader) throws LoadException {
|
||||
List<String> stringData = (List<String>) o;
|
||||
MaterialSet set = new MaterialSet();
|
||||
|
||||
for(String string : stringData) {
|
||||
try {
|
||||
if(string.startsWith("#")) set.addTag(string.substring(1));
|
||||
else set.add((Material) configLoader.loadType(Material.class, string));
|
||||
} catch(NullPointerException e) {
|
||||
throw new LoadException("Invalid data identifier \"" + string + "\"", e);
|
||||
}
|
||||
}
|
||||
|
||||
return set;
|
||||
}
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
package com.dfsek.terra.config.loaders;
|
||||
|
||||
import com.dfsek.tectonic.exception.LoadException;
|
||||
import com.dfsek.tectonic.loading.ConfigLoader;
|
||||
import com.dfsek.tectonic.loading.TypeLoader;
|
||||
import org.polydev.gaea.math.ProbabilityCollection;
|
||||
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class ProbabilityCollectionLoader implements TypeLoader<ProbabilityCollection<Object>> {
|
||||
@Override
|
||||
public ProbabilityCollection<Object> load(Type type, Object o, ConfigLoader configLoader) throws LoadException {
|
||||
|
||||
|
||||
ProbabilityCollection<Object> collection = new ProbabilityCollection<>();
|
||||
|
||||
if(type instanceof ParameterizedType) {
|
||||
ParameterizedType pType = (ParameterizedType) type;
|
||||
Type generic = pType.getActualTypeArguments()[0];
|
||||
if(o instanceof Map) {
|
||||
Map<Object, Integer> map = (Map<Object, Integer>) o;
|
||||
for(Map.Entry<Object, Integer> entry : map.entrySet()) {
|
||||
collection.add(configLoader.loadType(generic, entry.getKey()), entry.getValue());
|
||||
}
|
||||
} else if(o instanceof List) {
|
||||
List<Map<Object, Integer>> map = (List<Map<Object, Integer>>) o;
|
||||
for(Map<Object, Integer> l : map) {
|
||||
for(Map.Entry<Object, Integer> entry : l.entrySet()) {
|
||||
collection.add(configLoader.loadType(generic, entry.getKey()), entry.getValue());
|
||||
}
|
||||
}
|
||||
} else throw new LoadException("Malformed Probability Collection: " + o);
|
||||
} else throw new LoadException("Unable to load config! Could not retrieve parameterized type: " + type);
|
||||
|
||||
|
||||
return collection;
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
package com.dfsek.terra.config.loaders;
|
||||
|
||||
import com.dfsek.tectonic.exception.LoadException;
|
||||
import com.dfsek.tectonic.loading.ConfigLoader;
|
||||
import com.dfsek.tectonic.loading.TypeLoader;
|
||||
import org.polydev.gaea.math.Range;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Map;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class RangeLoader implements TypeLoader<Range> {
|
||||
@Override
|
||||
public Range load(Type type, Object o, ConfigLoader configLoader) throws LoadException {
|
||||
Map<String, Integer> map = (Map<String, Integer>) o;
|
||||
return new Range(map.get("min"), map.get("max"));
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
package com.dfsek.terra.config.loaders;
|
||||
|
||||
import com.dfsek.tectonic.exception.LoadException;
|
||||
import com.dfsek.tectonic.loading.ConfigLoader;
|
||||
import com.dfsek.tectonic.loading.TypeLoader;
|
||||
import com.dfsek.terra.config.files.Loader;
|
||||
import com.dfsek.terra.structure.Structure;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
public class StructureLoader implements TypeLoader<Structure> {
|
||||
private final Loader loader;
|
||||
|
||||
public StructureLoader(Loader loader) {
|
||||
this.loader = loader;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Structure load(Type type, Object o, ConfigLoader configLoader) throws LoadException {
|
||||
try(InputStream stream = loader.get("structures/data/" + o + ".tstructure")) {
|
||||
return Structure.fromStream(stream);
|
||||
} catch(IOException | ClassNotFoundException e) {
|
||||
throw new LoadException("Unable to load structure", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
package com.dfsek.terra.config.loaders;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.polydev.gaea.math.ProbabilityCollection;
|
||||
import org.polydev.gaea.tree.Tree;
|
||||
import org.polydev.gaea.world.Flora;
|
||||
import org.polydev.gaea.world.palette.Palette;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Class to hold Type instances for types with generics.
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public final class Types {
|
||||
public static final Type MATERIAL_SET_TYPE;
|
||||
public static final Type MATERIAL_PROBABILITY_COLLECTION_TYPE;
|
||||
public static final Type BLOCK_DATA_PALETTE_TYPE;
|
||||
public static final Type BLOCK_DATA_PROBABILITY_COLLECTION_TYPE;
|
||||
public static final Type FLORA_PROBABILITY_COLLECTION_TYPE;
|
||||
public static final Type TREE_PROBABILITY_COLLECTION_TYPE;
|
||||
|
||||
static {
|
||||
MATERIAL_SET_TYPE = getType("materialSet");
|
||||
MATERIAL_PROBABILITY_COLLECTION_TYPE = getType("materialProbabilityCollection");
|
||||
BLOCK_DATA_PALETTE_TYPE = getType("blockDataPalette");
|
||||
BLOCK_DATA_PROBABILITY_COLLECTION_TYPE = getType("blockDataProbabilityCollection");
|
||||
FLORA_PROBABILITY_COLLECTION_TYPE = getType("floraProbabilityCollection");
|
||||
TREE_PROBABILITY_COLLECTION_TYPE = getType("treeProbabilityCollection");
|
||||
}
|
||||
|
||||
private Set<Material> materialSet;
|
||||
private Palette<BlockData> blockDataPalette;
|
||||
private ProbabilityCollection<Material> materialProbabilityCollection;
|
||||
private ProbabilityCollection<BlockData> blockDataProbabilityCollection;
|
||||
private ProbabilityCollection<Flora> floraProbabilityCollection;
|
||||
private ProbabilityCollection<Tree> treeProbabilityCollection;
|
||||
|
||||
private static Type getType(String dummyFieldName) {
|
||||
try {
|
||||
return Types.class.getDeclaredField(dummyFieldName).getGenericType();
|
||||
} catch(NoSuchFieldException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
package com.dfsek.terra.config.loaders.config;
|
||||
|
||||
import com.dfsek.tectonic.exception.LoadException;
|
||||
import com.dfsek.tectonic.loading.ConfigLoader;
|
||||
import com.dfsek.tectonic.loading.TypeLoader;
|
||||
import com.dfsek.terra.config.loaders.Types;
|
||||
import com.dfsek.terra.generation.items.flora.FloraLayer;
|
||||
import org.polydev.gaea.math.FastNoiseLite;
|
||||
import org.polydev.gaea.math.ProbabilityCollection;
|
||||
import org.polydev.gaea.math.Range;
|
||||
import org.polydev.gaea.world.Flora;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Map;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class FloraLayerLoader implements TypeLoader<FloraLayer> {
|
||||
@Override
|
||||
public FloraLayer load(Type type, Object o, ConfigLoader configLoader) throws LoadException {
|
||||
Map<String, Object> map = (Map<String, Object>) o;
|
||||
double density = ((Number) map.get("density")).doubleValue();
|
||||
Range range = (Range) configLoader.loadType(Range.class, map.get("y"));
|
||||
if(range == null) throw new LoadException("Flora range unspecified");
|
||||
ProbabilityCollection<Flora> items = (ProbabilityCollection<Flora>) configLoader.loadType(Types.FLORA_PROBABILITY_COLLECTION_TYPE, map.get("items"));
|
||||
|
||||
if(map.containsKey("simplex-frequency")) {
|
||||
FastNoiseLite noiseLite = new FastNoiseLite();
|
||||
noiseLite.setFrequency((Double) map.get("simplex-frequency"));
|
||||
return new FloraLayer(density, range, items, noiseLite);
|
||||
}
|
||||
|
||||
return new FloraLayer(density, range, items, null);
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
package com.dfsek.terra.config.loaders.config;
|
||||
|
||||
import com.dfsek.tectonic.loading.ConfigLoader;
|
||||
import com.dfsek.tectonic.loading.TypeLoader;
|
||||
import com.dfsek.terra.procgen.GridSpawn;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Map;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class GridSpawnLoader implements TypeLoader<GridSpawn> {
|
||||
@Override
|
||||
public GridSpawn load(Type type, Object o, ConfigLoader configLoader) {
|
||||
Map<String, Integer> map = (Map<String, Integer>) o;
|
||||
return new GridSpawn(map.get("width"), map.get("padding"), map.getOrDefault("seed", 0));
|
||||
}
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
package com.dfsek.terra.config.loaders.config;
|
||||
|
||||
import com.dfsek.tectonic.config.Configuration;
|
||||
import com.dfsek.tectonic.exception.ConfigException;
|
||||
import com.dfsek.tectonic.exception.LoadException;
|
||||
import com.dfsek.tectonic.loading.ConfigLoader;
|
||||
import com.dfsek.tectonic.loading.TypeLoader;
|
||||
import com.dfsek.terra.generation.config.NoiseBuilder;
|
||||
import org.polydev.gaea.math.FastNoiseLite;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Map;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class NoiseBuilderLoader implements TypeLoader<NoiseBuilder> {
|
||||
private static final ConfigLoader LOADER = new ConfigLoader();
|
||||
|
||||
static {
|
||||
LOADER.registerLoader(FastNoiseLite.NoiseType.class, (t, object, cf) -> FastNoiseLite.NoiseType.valueOf((String) object));
|
||||
LOADER.registerLoader(FastNoiseLite.FractalType.class, (t, object, cf) -> FastNoiseLite.FractalType.valueOf((String) object));
|
||||
LOADER.registerLoader(FastNoiseLite.DomainWarpType.class, (t, object, cf) -> FastNoiseLite.DomainWarpType.valueOf((String) object));
|
||||
LOADER.registerLoader(FastNoiseLite.RotationType3D.class, (t, object, cf) -> FastNoiseLite.RotationType3D.valueOf((String) object));
|
||||
LOADER.registerLoader(FastNoiseLite.CellularReturnType.class, (t, object, cf) -> FastNoiseLite.CellularReturnType.valueOf((String) object));
|
||||
LOADER.registerLoader(FastNoiseLite.CellularDistanceFunction.class, (t, object, cf) -> FastNoiseLite.CellularDistanceFunction.valueOf((String) object));
|
||||
}
|
||||
|
||||
@Override
|
||||
public NoiseBuilder load(Type type, Object o, ConfigLoader configLoader) throws LoadException {
|
||||
NoiseBuilder builder = new NoiseBuilder();
|
||||
try {
|
||||
LOADER.load(builder, new Configuration((Map<String, Object>) o));
|
||||
} catch(ConfigException e) {
|
||||
throw new LoadException("Could not load noise", e);
|
||||
}
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
package com.dfsek.terra.config.loaders.config;
|
||||
|
||||
import com.dfsek.tectonic.exception.LoadException;
|
||||
import com.dfsek.tectonic.loading.ConfigLoader;
|
||||
import com.dfsek.tectonic.loading.TypeLoader;
|
||||
import com.dfsek.terra.generation.items.ores.OreConfig;
|
||||
import org.polydev.gaea.math.Range;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Map;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class OreConfigLoader implements TypeLoader<OreConfig> {
|
||||
@Override
|
||||
public OreConfig load(Type type, Object o, ConfigLoader configLoader) throws LoadException {
|
||||
Map<String, Integer> map = (Map<String, Integer>) o;
|
||||
Range amount = new Range(map.get("min"), map.get("max"));
|
||||
Range height = new Range(map.get("min-height"), map.get("max-height"));
|
||||
return new OreConfig(amount, height);
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package com.dfsek.terra.config.loaders.config;
|
||||
|
||||
import com.dfsek.tectonic.exception.LoadException;
|
||||
import com.dfsek.tectonic.loading.ConfigLoader;
|
||||
import com.dfsek.tectonic.loading.TypeLoader;
|
||||
import com.dfsek.terra.generation.items.ores.Ore;
|
||||
import com.dfsek.terra.generation.items.ores.OreConfig;
|
||||
import com.dfsek.terra.generation.items.ores.OreHolder;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Map;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class OreHolderLoader implements TypeLoader<OreHolder> {
|
||||
@Override
|
||||
public OreHolder load(Type type, Object o, ConfigLoader configLoader) throws LoadException {
|
||||
OreHolder holder = new OreHolder();
|
||||
Map<String, Object> map = (Map<String, Object>) o;
|
||||
|
||||
for(Map.Entry<String, Object> entry : map.entrySet()) {
|
||||
holder.add((Ore) configLoader.loadType(Ore.class, entry.getKey()), (OreConfig) configLoader.loadType(OreConfig.class, entry.getValue()));
|
||||
}
|
||||
|
||||
return holder;
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
package com.dfsek.terra.config.loaders.config;
|
||||
|
||||
import com.dfsek.tectonic.exception.LoadException;
|
||||
import com.dfsek.tectonic.loading.ConfigLoader;
|
||||
import com.dfsek.tectonic.loading.TypeLoader;
|
||||
import com.dfsek.terra.structure.features.EntityFeature;
|
||||
import com.dfsek.terra.structure.features.Feature;
|
||||
import com.dfsek.terra.util.MaterialSet;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.polydev.gaea.math.Range;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Map;
|
||||
|
||||
@SuppressWarnings({"unchecked", "SwitchStatementWithTooFewBranches"}) // We will do more features laterTM
|
||||
public class StructureFeatureLoader implements TypeLoader<Feature> {
|
||||
@Override
|
||||
public Feature load(Type type, Object o, ConfigLoader configLoader) throws LoadException {
|
||||
Map<String, Object> map = (Map<String, Object>) o;
|
||||
switch((String) map.get("type")) {
|
||||
case "ENTITY_FEATURE":
|
||||
MaterialSet stand = (MaterialSet) configLoader.loadType(MaterialSet.class, map.get("spawnable-on"));
|
||||
MaterialSet in = (MaterialSet) configLoader.loadType(MaterialSet.class, map.get("spawnable-in"));
|
||||
Range amount = (Range) configLoader.loadType(Range.class, map.get("amount"));
|
||||
EntityType entityType = (EntityType) configLoader.loadType(EntityType.class, map.get("entity"));
|
||||
Integer height = (Integer) configLoader.loadType(Integer.class, map.get("in-height"));
|
||||
return new EntityFeature(entityType, amount, stand, in, height);
|
||||
default:
|
||||
throw new LoadException("Invalid feature type: \"" + map.get("type") + "\"");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
package com.dfsek.terra.config.loaders.config;
|
||||
|
||||
import com.dfsek.tectonic.exception.LoadException;
|
||||
import com.dfsek.tectonic.loading.ConfigLoader;
|
||||
import com.dfsek.tectonic.loading.TypeLoader;
|
||||
import com.dfsek.terra.config.loaders.Types;
|
||||
import com.dfsek.terra.generation.items.tree.TreeLayer;
|
||||
import org.polydev.gaea.GaeaPlugin;
|
||||
import org.polydev.gaea.math.FastNoiseLite;
|
||||
import org.polydev.gaea.math.ProbabilityCollection;
|
||||
import org.polydev.gaea.math.Range;
|
||||
import org.polydev.gaea.tree.Tree;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Map;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class TreeLayerLoader implements TypeLoader<TreeLayer> {
|
||||
private final GaeaPlugin main;
|
||||
|
||||
public TreeLayerLoader(GaeaPlugin main) {
|
||||
this.main = main;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TreeLayer load(Type type, Object o, ConfigLoader configLoader) throws LoadException {
|
||||
Map<String, Object> map = (Map<String, Object>) o;
|
||||
double density = ((Number) map.get("density")).doubleValue();
|
||||
Range range = (Range) configLoader.loadType(Range.class, map.get("y"));
|
||||
if(range == null) throw new LoadException("Tree range unspecified");
|
||||
ProbabilityCollection<Tree> items = (ProbabilityCollection<Tree>) configLoader.loadType(Types.TREE_PROBABILITY_COLLECTION_TYPE, map.get("items"));
|
||||
|
||||
if(map.containsKey("simplex-frequency")) {
|
||||
FastNoiseLite noiseLite = new FastNoiseLite();
|
||||
noiseLite.setFrequency((Double) map.get("simplex-frequency"));
|
||||
return new TreeLayer(density, range, items, noiseLite, main);
|
||||
}
|
||||
|
||||
return new TreeLayer(density, range, items, null, main);
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
package com.dfsek.terra.config.loaders.palette;
|
||||
|
||||
import com.dfsek.tectonic.config.Configuration;
|
||||
import com.dfsek.tectonic.exception.LoadException;
|
||||
import com.dfsek.tectonic.loading.ConfigLoader;
|
||||
import com.dfsek.tectonic.loading.TypeLoader;
|
||||
import com.dfsek.terra.carving.CarverPalette;
|
||||
import com.dfsek.terra.config.loaders.Types;
|
||||
import com.dfsek.terra.util.MaterialSet;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.polydev.gaea.math.ProbabilityCollection;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class CarverPaletteLoader implements TypeLoader<CarverPalette> {
|
||||
|
||||
|
||||
@Override
|
||||
public CarverPalette load(Type type, Object o, ConfigLoader configLoader) throws LoadException {
|
||||
Configuration configuration = new Configuration((Map<String, Object>) o);
|
||||
CarverPalette palette = new CarverPalette((MaterialSet) configLoader.loadType(MaterialSet.class, configuration.get("replace")), (Boolean) configuration.get("replace-blacklist"));
|
||||
|
||||
for(Map<String, Object> map : (List<Map<String, Object>>) configuration.get("layers")) {
|
||||
ProbabilityCollection<BlockData> layer = (ProbabilityCollection<BlockData>) configLoader.loadType(Types.BLOCK_DATA_PROBABILITY_COLLECTION_TYPE, map.get("materials"));
|
||||
palette.add(layer, (Integer) map.get("y"));
|
||||
}
|
||||
palette.build();
|
||||
return palette;
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
package com.dfsek.terra.config.loaders.palette;
|
||||
|
||||
import com.dfsek.tectonic.exception.LoadException;
|
||||
import com.dfsek.tectonic.loading.ConfigLoader;
|
||||
import com.dfsek.tectonic.loading.TypeLoader;
|
||||
import com.dfsek.terra.biome.palette.PaletteHolder;
|
||||
import com.dfsek.terra.biome.palette.PaletteHolderBuilder;
|
||||
import com.dfsek.terra.config.loaders.Types;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.polydev.gaea.world.palette.Palette;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class PaletteHolderLoader implements TypeLoader<PaletteHolder> {
|
||||
@Override
|
||||
public PaletteHolder load(Type type, Object o, ConfigLoader configLoader) throws LoadException {
|
||||
List<Map<String, Integer>> palette = (List<Map<String, Integer>>) o;
|
||||
PaletteHolderBuilder builder = new PaletteHolderBuilder();
|
||||
for(Map<String, Integer> layer : palette) {
|
||||
for(Map.Entry<String, Integer> entry : layer.entrySet()) {
|
||||
builder.add(entry.getValue(), (Palette<BlockData>) configLoader.loadType(Types.BLOCK_DATA_PALETTE_TYPE, entry.getKey()));
|
||||
}
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
package com.dfsek.terra.config.loaders.palette;
|
||||
|
||||
import com.dfsek.tectonic.exception.LoadException;
|
||||
import com.dfsek.tectonic.loading.ConfigLoader;
|
||||
import com.dfsek.tectonic.loading.TypeLoader;
|
||||
import com.dfsek.terra.biome.palette.PaletteLayer;
|
||||
import com.dfsek.terra.config.loaders.Types;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.polydev.gaea.math.ProbabilityCollection;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Map;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class PaletteLayerLoader implements TypeLoader<PaletteLayer> {
|
||||
@Override
|
||||
public PaletteLayer load(Type type, Object o, ConfigLoader configLoader) throws LoadException {
|
||||
Map<String, Object> map = (Map<String, Object>) o;
|
||||
ProbabilityCollection<BlockData> collection = (ProbabilityCollection<BlockData>) configLoader.loadType(Types.BLOCK_DATA_PROBABILITY_COLLECTION_TYPE, map.get("materials"));
|
||||
if(collection == null) throw new LoadException("Collection is null: " + map.get("materials"));
|
||||
return new PaletteLayer(collection, (Integer) map.get("layers"));
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
package com.dfsek.terra.config.templates;
|
||||
|
||||
import com.dfsek.tectonic.config.ConfigTemplate;
|
||||
|
||||
public abstract class AbstractableTemplate implements ConfigTemplate {
|
||||
public abstract String getID();
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
package com.dfsek.terra.config.templates;
|
||||
|
||||
import com.dfsek.tectonic.annotations.Abstractable;
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import org.polydev.gaea.biome.Biome;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class BiomeGridTemplate extends AbstractableTemplate {
|
||||
|
||||
@Value("grid")
|
||||
@Abstractable
|
||||
private List<List<Biome>> grid;
|
||||
|
||||
@Value("id")
|
||||
private String id;
|
||||
|
||||
@Value("frequency.x")
|
||||
@Abstractable
|
||||
private double xFreq;
|
||||
|
||||
@Value("frequency.z")
|
||||
@Abstractable
|
||||
private double zFreq;
|
||||
|
||||
public String getID() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public List<List<Biome>> getGrid() {
|
||||
return grid;
|
||||
}
|
||||
|
||||
public double getXFreq() {
|
||||
return xFreq;
|
||||
}
|
||||
|
||||
public double getZFreq() {
|
||||
return zFreq;
|
||||
}
|
||||
}
|
||||
@@ -1,241 +0,0 @@
|
||||
package com.dfsek.terra.config.templates;
|
||||
|
||||
import com.dfsek.tectonic.annotations.Abstractable;
|
||||
import com.dfsek.tectonic.annotations.Default;
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.tectonic.config.ValidatedConfigTemplate;
|
||||
import com.dfsek.tectonic.exception.ValidationException;
|
||||
import com.dfsek.terra.biome.palette.PaletteHolder;
|
||||
import com.dfsek.terra.biome.palette.SinglePalette;
|
||||
import com.dfsek.terra.carving.UserDefinedCarver;
|
||||
import com.dfsek.terra.config.base.ConfigPack;
|
||||
import com.dfsek.terra.generation.items.TerraStructure;
|
||||
import com.dfsek.terra.generation.items.flora.FloraLayer;
|
||||
import com.dfsek.terra.generation.items.ores.OreHolder;
|
||||
import com.dfsek.terra.generation.items.tree.TreeLayer;
|
||||
import com.dfsek.terra.math.BlankFunction;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.polydev.gaea.util.GlueList;
|
||||
import org.polydev.gaea.world.palette.Palette;
|
||||
import parsii.eval.Parser;
|
||||
import parsii.eval.Scope;
|
||||
import parsii.tokenizer.ParseException;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@SuppressWarnings({"FieldMayBeFinal", "unused"})
|
||||
public class BiomeTemplate extends AbstractableTemplate implements ValidatedConfigTemplate {
|
||||
|
||||
private final ConfigPack pack;
|
||||
@Value("id")
|
||||
private String id;
|
||||
|
||||
@Value("extends")
|
||||
@Default
|
||||
private String extend = null;
|
||||
|
||||
@Value("palette")
|
||||
@Abstractable
|
||||
private PaletteHolder palette;
|
||||
@Value("slant.palette")
|
||||
@Abstractable
|
||||
@Default
|
||||
private PaletteHolder slantPalette = null;
|
||||
@Value("vanilla")
|
||||
@Abstractable
|
||||
private Biome vanilla;
|
||||
@Value("erode")
|
||||
@Abstractable
|
||||
@Default
|
||||
private String erode = null;
|
||||
@Value("structures")
|
||||
@Abstractable
|
||||
@Default
|
||||
private List<TerraStructure> structures = new GlueList<>();
|
||||
@Value("carving")
|
||||
@Abstractable
|
||||
@Default
|
||||
private Map<UserDefinedCarver, Integer> carvers = new HashMap<>();
|
||||
@Value("noise-equation")
|
||||
@Abstractable
|
||||
private String noiseEquation;
|
||||
@Value("ores")
|
||||
@Abstractable
|
||||
@Default
|
||||
private OreHolder oreHolder = new OreHolder();
|
||||
@Value("ocean.level")
|
||||
@Abstractable
|
||||
@Default
|
||||
private int seaLevel = 62;
|
||||
@Value("ocean.palette")
|
||||
@Abstractable
|
||||
@Default
|
||||
private Palette<BlockData> oceanPalette = new SinglePalette<>(Material.WATER.createBlockData());
|
||||
|
||||
@Value("elevation.equation")
|
||||
@Default
|
||||
@Abstractable
|
||||
private String elevationEquation = null;
|
||||
|
||||
@Value("flora")
|
||||
@Abstractable
|
||||
@Default
|
||||
private List<FloraLayer> flora = new GlueList<>();
|
||||
|
||||
@Value("trees")
|
||||
@Abstractable
|
||||
@Default
|
||||
private List<TreeLayer> trees = new GlueList<>();
|
||||
|
||||
@Value("slabs.enable")
|
||||
@Abstractable
|
||||
@Default
|
||||
private boolean doSlabs = false;
|
||||
|
||||
@Value("slabs.threshold")
|
||||
@Abstractable
|
||||
@Default
|
||||
private double slabThreshold = 0.0075D;
|
||||
|
||||
@Value("slabs.palettes")
|
||||
@Abstractable
|
||||
@Default
|
||||
private Map<Material, Palette<BlockData>> slabPalettes;
|
||||
|
||||
@Value("slabs.stair-palettes")
|
||||
@Abstractable
|
||||
@Default
|
||||
private Map<Material, Palette<BlockData>> stairPalettes;
|
||||
|
||||
@Value("slant.threshold")
|
||||
@Abstractable
|
||||
@Default
|
||||
private double slantThreshold = 0.1;
|
||||
|
||||
@Value("interpolate-elevation")
|
||||
@Abstractable
|
||||
@Default
|
||||
private boolean interpolateElevation = true;
|
||||
|
||||
public boolean interpolateElevation() {
|
||||
return interpolateElevation;
|
||||
}
|
||||
|
||||
public String getExtend() {
|
||||
return extend;
|
||||
}
|
||||
|
||||
public double getSlantThreshold() {
|
||||
return slantThreshold;
|
||||
}
|
||||
|
||||
public double getSlabThreshold() {
|
||||
return slabThreshold;
|
||||
}
|
||||
|
||||
public List<FloraLayer> getFlora() {
|
||||
return flora;
|
||||
}
|
||||
|
||||
public boolean doSlabs() {
|
||||
return doSlabs;
|
||||
}
|
||||
|
||||
public Map<Material, Palette<BlockData>> getSlabPalettes() {
|
||||
return slabPalettes;
|
||||
}
|
||||
|
||||
public Map<Material, Palette<BlockData>> getStairPalettes() {
|
||||
return stairPalettes;
|
||||
}
|
||||
|
||||
public BiomeTemplate(ConfigPack pack) {
|
||||
this.pack = pack;
|
||||
}
|
||||
|
||||
public String getElevationEquation() {
|
||||
return elevationEquation;
|
||||
}
|
||||
|
||||
public ConfigPack getPack() {
|
||||
return pack;
|
||||
}
|
||||
|
||||
public int getSeaLevel() {
|
||||
return seaLevel;
|
||||
}
|
||||
|
||||
public Palette<BlockData> getOceanPalette() {
|
||||
return oceanPalette;
|
||||
}
|
||||
|
||||
public String getID() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public PaletteHolder getPalette() {
|
||||
return palette;
|
||||
}
|
||||
|
||||
public List<TreeLayer> getTrees() {
|
||||
return trees;
|
||||
}
|
||||
|
||||
public PaletteHolder getSlantPalette() {
|
||||
return slantPalette;
|
||||
}
|
||||
|
||||
public Biome getVanilla() {
|
||||
return vanilla;
|
||||
}
|
||||
|
||||
public String getErode() {
|
||||
return erode;
|
||||
}
|
||||
|
||||
public List<TerraStructure> getStructures() {
|
||||
return structures;
|
||||
}
|
||||
|
||||
public Map<UserDefinedCarver, Integer> getCarvers() {
|
||||
return carvers;
|
||||
}
|
||||
|
||||
public String getNoiseEquation() {
|
||||
return noiseEquation;
|
||||
}
|
||||
|
||||
public OreHolder getOreHolder() {
|
||||
return oreHolder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean validate() throws ValidationException {
|
||||
Parser tester = new Parser();
|
||||
Scope testScope = new Scope().withParent(pack.getVarScope());
|
||||
testScope.create("x");
|
||||
testScope.create("y");
|
||||
testScope.create("z");
|
||||
testScope.create("seed");
|
||||
|
||||
pack.getTemplate().getNoiseBuilderMap().forEach((id, builder) -> tester.registerFunction(id, new BlankFunction(builder.getDimensions()))); // Register dummy functions
|
||||
|
||||
try {
|
||||
tester.parse(noiseEquation, testScope);
|
||||
} catch(ParseException e) {
|
||||
throw new ValidationException("Invalid noise equation: ", e);
|
||||
}
|
||||
|
||||
try {
|
||||
if(elevationEquation != null) tester.parse(elevationEquation, testScope);
|
||||
} catch(ParseException e) {
|
||||
throw new ValidationException("Invalid elevation equation: ", e);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,205 +0,0 @@
|
||||
package com.dfsek.terra.config.templates;
|
||||
|
||||
import com.dfsek.tectonic.annotations.Abstractable;
|
||||
import com.dfsek.tectonic.annotations.Default;
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.terra.carving.CarverPalette;
|
||||
import com.dfsek.terra.util.MaterialSet;
|
||||
import org.bukkit.Material;
|
||||
import org.polydev.gaea.math.Range;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@SuppressWarnings({"unused", "FieldMayBeFinal"})
|
||||
public class CarverTemplate extends AbstractableTemplate {
|
||||
@Value("id")
|
||||
private String id;
|
||||
|
||||
@Value("step")
|
||||
@Abstractable
|
||||
@Default
|
||||
private int step = 2;
|
||||
|
||||
@Value("recalculate-magnitude")
|
||||
@Default
|
||||
@Abstractable
|
||||
private double recaclulateMagnitude = 4;
|
||||
|
||||
@Value("recalculate-direction")
|
||||
@Abstractable
|
||||
@Default
|
||||
private Range recalc = new Range(8, 10);
|
||||
|
||||
@Value("length")
|
||||
@Abstractable
|
||||
private Range length;
|
||||
|
||||
@Value("start.x")
|
||||
@Abstractable
|
||||
private double startX;
|
||||
|
||||
@Value("start.y")
|
||||
@Abstractable
|
||||
private double startY;
|
||||
|
||||
@Value("start.z")
|
||||
@Abstractable
|
||||
private double startZ;
|
||||
|
||||
@Value("start.radius.x")
|
||||
@Abstractable
|
||||
private String radMX;
|
||||
|
||||
@Value("start.radius.y")
|
||||
@Abstractable
|
||||
private String radMY;
|
||||
|
||||
@Value("start.radius.z")
|
||||
@Abstractable
|
||||
private String radMZ;
|
||||
|
||||
@Value("start.height")
|
||||
@Abstractable
|
||||
private Range height;
|
||||
|
||||
@Value("cut.bottom")
|
||||
@Abstractable
|
||||
@Default
|
||||
private int cutBottom = 0;
|
||||
|
||||
@Value("cut.top")
|
||||
@Abstractable
|
||||
@Default
|
||||
private int cutTop = 0;
|
||||
|
||||
@Value("mutate.x")
|
||||
@Abstractable
|
||||
private double mutateX;
|
||||
|
||||
@Value("mutate.y")
|
||||
@Abstractable
|
||||
private double mutateY;
|
||||
|
||||
@Value("mutate.z")
|
||||
@Abstractable
|
||||
private double mutateZ;
|
||||
|
||||
@Value("palette.top")
|
||||
@Abstractable
|
||||
private CarverPalette top;
|
||||
|
||||
@Value("palette.bottom")
|
||||
@Abstractable
|
||||
private CarverPalette bottom;
|
||||
|
||||
@Value("palette.outer")
|
||||
@Abstractable
|
||||
private CarverPalette outer;
|
||||
|
||||
@Value("palette.inner")
|
||||
@Abstractable
|
||||
private CarverPalette inner;
|
||||
|
||||
@Value("shift")
|
||||
@Abstractable
|
||||
@Default
|
||||
private Map<Material, MaterialSet> shift = new HashMap<>();
|
||||
|
||||
@Value("update")
|
||||
@Abstractable
|
||||
@Default
|
||||
private MaterialSet update = new MaterialSet();
|
||||
|
||||
public String getID() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public int getStep() {
|
||||
return step;
|
||||
}
|
||||
|
||||
public Range getLength() {
|
||||
return length;
|
||||
}
|
||||
|
||||
public double getStartX() {
|
||||
return startX;
|
||||
}
|
||||
|
||||
public double getStartY() {
|
||||
return startY;
|
||||
}
|
||||
|
||||
public double getStartZ() {
|
||||
return startZ;
|
||||
}
|
||||
|
||||
public String getRadMX() {
|
||||
return radMX;
|
||||
}
|
||||
|
||||
public String getRadMY() {
|
||||
return radMY;
|
||||
}
|
||||
|
||||
public String getRadMZ() {
|
||||
return radMZ;
|
||||
}
|
||||
|
||||
public Range getHeight() {
|
||||
return height;
|
||||
}
|
||||
|
||||
public int getCutBottom() {
|
||||
return cutBottom;
|
||||
}
|
||||
|
||||
public int getCutTop() {
|
||||
return cutTop;
|
||||
}
|
||||
|
||||
public double getMutateX() {
|
||||
return mutateX;
|
||||
}
|
||||
|
||||
public double getMutateY() {
|
||||
return mutateY;
|
||||
}
|
||||
|
||||
public double getMutateZ() {
|
||||
return mutateZ;
|
||||
}
|
||||
|
||||
public CarverPalette getTop() {
|
||||
return top;
|
||||
}
|
||||
|
||||
public CarverPalette getBottom() {
|
||||
return bottom;
|
||||
}
|
||||
|
||||
public CarverPalette getOuter() {
|
||||
return outer;
|
||||
}
|
||||
|
||||
public CarverPalette getInner() {
|
||||
return inner;
|
||||
}
|
||||
|
||||
public Map<Material, MaterialSet> getShift() {
|
||||
return shift;
|
||||
}
|
||||
|
||||
public MaterialSet getUpdate() {
|
||||
return update;
|
||||
}
|
||||
|
||||
public Range getRecalc() {
|
||||
return recalc;
|
||||
}
|
||||
|
||||
public double getRecaclulateMagnitude() {
|
||||
return recaclulateMagnitude;
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user