mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-06 15:56:14 +00:00
Dependency injection moment
This commit is contained in:
@@ -7,8 +7,8 @@ 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.base.WorldConfig;
|
||||
import com.dfsek.terra.config.lang.LangUtil;
|
||||
import com.dfsek.terra.config.loaders.ImageLoaderLoader;
|
||||
import com.dfsek.terra.config.loaders.MaterialSetLoader;
|
||||
@@ -45,6 +45,7 @@ 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;
|
||||
@@ -65,8 +66,16 @@ import java.util.Objects;
|
||||
|
||||
public class Terra extends GaeaPlugin {
|
||||
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();
|
||||
|
||||
public void invalidate() {
|
||||
worldMap.clear();
|
||||
worlds.clear();
|
||||
registry.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
TerraChunkGenerator.saveAll();
|
||||
@@ -76,16 +85,14 @@ public class Terra extends GaeaPlugin {
|
||||
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", TerraWorld::numWorlds)); // World number chart.
|
||||
metrics.addCustomChart(new Metrics.SingleLineChart("worlds", worldMap::size)); // World number chart.
|
||||
|
||||
PluginConfig.load(this); // Load master config.yml
|
||||
LangUtil.load(PluginConfig.getLanguage(), this); // Load language.
|
||||
|
||||
TerraWorld.invalidate(); // Clear/set up world cache.
|
||||
registry.loadAll(this); // Load all config packs.
|
||||
|
||||
PluginCommand c = Objects.requireNonNull(getCommand("terra"));
|
||||
@@ -111,9 +118,9 @@ public class Terra extends GaeaPlugin {
|
||||
@Override
|
||||
public @Nullable ChunkGenerator getDefaultWorldGenerator(@NotNull String worldName, @Nullable String id) {
|
||||
return generatorMap.computeIfAbsent(worldName, name -> {
|
||||
WorldConfig c = new WorldConfig(worldName, id, this);
|
||||
TerraWorld.loadWorld(c);
|
||||
return new TerraChunkGenerator(c.getConfig(), this);
|
||||
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);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -162,4 +169,8 @@ public class Terra extends GaeaPlugin {
|
||||
public ConfigRegistry getRegistry() {
|
||||
return registry;
|
||||
}
|
||||
|
||||
public TerraWorld getWorld(World w) {
|
||||
return worldMap.computeIfAbsent(w, world -> new TerraWorld(w, worlds.get(w.getName())));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ 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.base.WorldConfig;
|
||||
import com.dfsek.terra.config.builder.biomegrid.BiomeGridBuilder;
|
||||
import com.dfsek.terra.debug.Debug;
|
||||
import com.dfsek.terra.generation.TerraChunkGenerator;
|
||||
@@ -14,24 +13,16 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.polydev.gaea.biome.BiomeGrid;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class TerraWorld {
|
||||
private static final Map<World, TerraWorld> map = new HashMap<>();
|
||||
private static final Map<String, WorldConfig> loaded = new HashMap<>();
|
||||
|
||||
private final TerraBiomeGrid grid;
|
||||
private final BiomeZone zone;
|
||||
private final ConfigPack config;
|
||||
private final WorldConfig worldConfig;
|
||||
private boolean safe;
|
||||
|
||||
|
||||
private TerraWorld(World w) {
|
||||
public TerraWorld(World w, ConfigPack c) {
|
||||
safe = true;
|
||||
worldConfig = loaded.get(w.getName());
|
||||
config = worldConfig.getConfig();
|
||||
config = c;
|
||||
|
||||
ConfigPackTemplate template = config.getTemplate();
|
||||
|
||||
@@ -42,7 +33,7 @@ public class TerraWorld {
|
||||
String partName = template.getGrids().get(i);
|
||||
try {
|
||||
BiomeGridBuilder g = config.getBiomeGrid(partName);
|
||||
BiomeGrid b = g.build(w, worldConfig);
|
||||
BiomeGrid b = g.build(w, c);
|
||||
definedGrids[i] = b;
|
||||
} catch(NullPointerException e) {
|
||||
safe = false;
|
||||
@@ -53,30 +44,14 @@ public class TerraWorld {
|
||||
Bukkit.getLogger().severe("Terrain will NOT generate properly at this point. Correct your config before using your server!");
|
||||
}
|
||||
}
|
||||
zone = new BiomeZone(w, worldConfig, definedGrids);
|
||||
zone = new BiomeZone(w, c, definedGrids);
|
||||
|
||||
if(template.getGridType().equals(TerraBiomeGrid.Type.RADIAL)) {
|
||||
BiomeGrid internal = config.getBiomeGrid(template.getRadialInternalGrid()).build(w, worldConfig);
|
||||
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 void loadWorld(WorldConfig w) {
|
||||
loaded.put(w.getWorldID(), w);
|
||||
}
|
||||
|
||||
public static synchronized TerraWorld getWorld(World w) {
|
||||
return map.computeIfAbsent(w, TerraWorld::new);
|
||||
}
|
||||
|
||||
public static synchronized void invalidate() {
|
||||
map.clear();
|
||||
}
|
||||
|
||||
public static int numWorlds() {
|
||||
return map.size();
|
||||
}
|
||||
|
||||
public static boolean isTerraWorld(World w) {
|
||||
return w.getGenerator() instanceof TerraChunkGenerator;
|
||||
}
|
||||
@@ -89,10 +64,6 @@ public class TerraWorld {
|
||||
return config;
|
||||
}
|
||||
|
||||
public WorldConfig getWorldConfig() {
|
||||
return worldConfig;
|
||||
}
|
||||
|
||||
public BiomeZone getZone() {
|
||||
return zone;
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package com.dfsek.terra.async;
|
||||
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.biome.grid.master.TerraBiomeGrid;
|
||||
import com.dfsek.terra.config.base.PluginConfig;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.polydev.gaea.GaeaPlugin;
|
||||
import org.polydev.gaea.biome.Biome;
|
||||
import org.polydev.gaea.generation.GenerationPhase;
|
||||
|
||||
@@ -16,7 +16,7 @@ import java.util.function.Consumer;
|
||||
*/
|
||||
public class AsyncBiomeFinder extends AsyncFeatureFinder<Biome> {
|
||||
|
||||
public AsyncBiomeFinder(TerraBiomeGrid grid, Biome target, @NotNull Location origin, int startRadius, int maxRadius, Consumer<Vector> callback, GaeaPlugin main) {
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
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 org.polydev.gaea.GaeaPlugin;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@@ -20,9 +20,9 @@ public abstract class AsyncFeatureFinder<T> implements Runnable {
|
||||
protected final World world;
|
||||
private final Consumer<Vector> callback;
|
||||
protected int searchSize = 1;
|
||||
protected final GaeaPlugin main;
|
||||
protected final Terra main;
|
||||
|
||||
public AsyncFeatureFinder(TerraBiomeGrid grid, T target, @NotNull Location origin, int startRadius, int maxRadius, Consumer<Vector> callback, GaeaPlugin 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;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
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;
|
||||
@@ -10,7 +11,6 @@ import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.polydev.gaea.GaeaPlugin;
|
||||
import org.polydev.gaea.util.FastRandom;
|
||||
|
||||
import java.util.Random;
|
||||
@@ -20,7 +20,7 @@ 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, GaeaPlugin main) {
|
||||
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());
|
||||
}
|
||||
@@ -42,7 +42,7 @@ public class AsyncStructureFinder extends AsyncFeatureFinder<TerraStructure> {
|
||||
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)) continue;
|
||||
if(!struc.checkSpawns(spawn, rotation, main)) continue;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.dfsek.terra.biome;
|
||||
|
||||
import com.dfsek.terra.config.base.WorldConfig;
|
||||
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;
|
||||
@@ -21,16 +22,17 @@ public class BiomeZone {
|
||||
private final boolean useImage;
|
||||
private final ImageLoader.Channel channel;
|
||||
|
||||
public BiomeZone(World w, WorldConfig wc, BiomeGrid[] grids) {
|
||||
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);
|
||||
this.noise.setFrequency(1D / wc.getConfig().getTemplate().getZoneFreq());
|
||||
ConfigPackTemplate t = wc.getTemplate();
|
||||
this.noise.setFrequency(1D / t.getZoneFreq());
|
||||
this.grids = grids;
|
||||
imageLoader = wc.imageLoader;
|
||||
useImage = wc.fromImage;
|
||||
channel = wc.zoneChannel;
|
||||
imageLoader = t.getImageLoader();
|
||||
useImage = t.isFromImage();
|
||||
channel = t.getZoneChannel();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.dfsek.terra.biome.grid;
|
||||
|
||||
import com.dfsek.terra.config.base.WorldConfig;
|
||||
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;
|
||||
@@ -15,13 +16,14 @@ public class UserDefinedGrid extends BiomeGrid {
|
||||
private final ImageLoader.Channel channelX;
|
||||
private final ImageLoader.Channel channelZ;
|
||||
|
||||
public UserDefinedGrid(World w, double freq1, double freq2, Biome[][] b, WorldConfig c) {
|
||||
public UserDefinedGrid(World w, double freq1, double freq2, Biome[][] b, ConfigPack c) {
|
||||
super(w, freq1, freq2, b.length, b[0].length);
|
||||
super.setGrid(b);
|
||||
imageLoader = c.imageLoader;
|
||||
fromImage = c.fromImage;
|
||||
channelX = c.biomeXChannel;
|
||||
channelZ = c.biomeZChannel;
|
||||
ConfigPackTemplate t = c.getTemplate();
|
||||
imageLoader = t.getImageLoader();
|
||||
fromImage = t.isFromImage();
|
||||
channelX = t.getBiomeXChannel();
|
||||
channelZ = t.getBiomeZChannel();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.dfsek.terra.carving;
|
||||
|
||||
import com.dfsek.terra.TerraWorld;
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.biome.UserDefinedBiome;
|
||||
import com.dfsek.terra.biome.grid.master.TerraBiomeGrid;
|
||||
import com.dfsek.terra.config.base.PluginConfig;
|
||||
@@ -22,15 +22,17 @@ 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) {
|
||||
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() > PluginConfig.getCacheSize() * 2) carvers.clear();
|
||||
return carvers.computeIfAbsent((((long) chunkX) << 32) | (chunkZ & 0xffffffffL), key -> {
|
||||
TerraBiomeGrid grid = TerraWorld.getWorld(w).getGrid();
|
||||
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);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.dfsek.terra.carving;
|
||||
|
||||
import com.dfsek.terra.TerraWorld;
|
||||
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;
|
||||
@@ -43,8 +43,9 @@ public class UserDefinedCarver extends Carver {
|
||||
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) throws ParseException {
|
||||
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;
|
||||
@@ -53,6 +54,7 @@ public class UserDefinedCarver extends Carver {
|
||||
this.topCut = topCut;
|
||||
this.bottomCut = bottomCut;
|
||||
this.config = config;
|
||||
this.main = main;
|
||||
|
||||
Parser p = new Parser();
|
||||
|
||||
@@ -99,7 +101,7 @@ public class UserDefinedCarver extends Carver {
|
||||
|
||||
@Override
|
||||
public void carve(int chunkX, int chunkZ, World w, BiConsumer<Vector, CarvingType> consumer) {
|
||||
CarverCache cache = cacheMap.computeIfAbsent(w, CarverCache::new);
|
||||
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++) {
|
||||
@@ -119,7 +121,7 @@ public class UserDefinedCarver extends Carver {
|
||||
|
||||
@Override
|
||||
public boolean isChunkCarved(World w, int chunkX, int chunkZ, Random random) {
|
||||
BiomeTemplate conf = ((UserDefinedBiome) TerraWorld.getWorld(w).getGrid().getBiome((chunkX << 4) + 8, (chunkZ << 4) + 8, GenerationPhase.POPULATE)).getConfig();
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.dfsek.terra.command;
|
||||
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.TerraWorld;
|
||||
import com.dfsek.terra.config.base.PluginConfig;
|
||||
import com.dfsek.terra.config.lang.LangUtil;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@@ -32,7 +31,7 @@ public class ReloadCommand extends Command implements DebugCommand {
|
||||
PluginConfig.load(getMain());
|
||||
LangUtil.load(PluginConfig.getLanguage(), getMain()); // Load language.
|
||||
if(!((Terra) getMain()).getRegistry().loadAll((Terra) getMain())) LangUtil.send("command.reload-error", sender);
|
||||
TerraWorld.invalidate();
|
||||
((Terra) getMain()).invalidate();
|
||||
LangUtil.send("command.reload", sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.dfsek.terra.command.biome;
|
||||
|
||||
import com.dfsek.terra.TerraWorld;
|
||||
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;
|
||||
@@ -23,7 +23,7 @@ public class BiomeCommand extends WorldCommand {
|
||||
|
||||
@Override
|
||||
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World w) {
|
||||
TerraBiomeGrid grid = TerraWorld.getWorld(sender.getWorld()).getGrid();
|
||||
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;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.dfsek.terra.command.biome;
|
||||
|
||||
import com.dfsek.terra.TerraWorld;
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.biome.UserDefinedBiome;
|
||||
import com.dfsek.terra.carving.UserDefinedCarver;
|
||||
import com.dfsek.terra.config.base.ConfigPack;
|
||||
@@ -28,7 +28,7 @@ public class BiomeInfoCommand extends WorldCommand {
|
||||
@Override
|
||||
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World world) {
|
||||
String id = args[0];
|
||||
ConfigPack cfg = TerraWorld.getWorld(world).getConfig();
|
||||
ConfigPack cfg = ((Terra) getMain()).getWorld(world).getConfig();
|
||||
UserDefinedBiome b;
|
||||
try {
|
||||
b = cfg.getBiome(id);
|
||||
@@ -87,7 +87,7 @@ public class BiomeInfoCommand extends WorldCommand {
|
||||
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 = TerraWorld.getWorld(((Player) sender).getWorld()).getConfig().getBiomeIDs();
|
||||
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,6 +1,6 @@
|
||||
package com.dfsek.terra.command.biome;
|
||||
|
||||
import com.dfsek.terra.TerraWorld;
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.async.AsyncBiomeFinder;
|
||||
import com.dfsek.terra.biome.UserDefinedBiome;
|
||||
import com.dfsek.terra.config.base.PluginConfig;
|
||||
@@ -39,12 +39,12 @@ public class BiomeLocateCommand extends WorldCommand {
|
||||
}
|
||||
UserDefinedBiome b;
|
||||
try {
|
||||
b = TerraWorld.getWorld(world).getConfig().getBiome(id);
|
||||
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(TerraWorld.getWorld(world).getGrid(), b, sender.getLocation().clone().multiply((1D / PluginConfig.getBiomeSearchResolution())), 0, maxRadius, location -> {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(getMain(), new AsyncBiomeFinder(((Terra) getMain()).getWorld(world).getGrid(), b, sender.getLocation().clone().multiply((1D / PluginConfig.getBiomeSearchResolution())), 0, maxRadius, location -> {
|
||||
if(location != null) {
|
||||
LangUtil.send("command.biome.biome-found", sender, String.valueOf(location.getBlockX()), String.valueOf(location.getBlockZ()));
|
||||
if(tp) {
|
||||
@@ -52,7 +52,7 @@ public class BiomeLocateCommand extends WorldCommand {
|
||||
Bukkit.getScheduler().runTask(getMain(), () -> sender.teleport(l));
|
||||
}
|
||||
} else LangUtil.send("command.biome.unable-to-locate", sender);
|
||||
}, getMain()));
|
||||
}, (Terra) getMain()));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ public class BiomeLocateCommand extends WorldCommand {
|
||||
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 = TerraWorld.getWorld(((Player) sender).getWorld()).getConfig().getBiomeIDs();
|
||||
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,5 +1,6 @@
|
||||
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;
|
||||
@@ -21,7 +22,7 @@ public class RenderCommand extends WorldCommand {
|
||||
@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]));
|
||||
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
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.dfsek.terra.command.image.gui;
|
||||
|
||||
import com.dfsek.terra.TerraWorld;
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.config.base.PluginConfig;
|
||||
import com.dfsek.terra.config.lang.LangUtil;
|
||||
import com.dfsek.terra.image.ImageLoader;
|
||||
@@ -25,9 +25,9 @@ public class RawGUICommand extends WorldCommand {
|
||||
LangUtil.send("command.image.gui.debug", sender);
|
||||
return true;
|
||||
}
|
||||
ImageLoader loader = TerraWorld.getWorld(world).getWorldConfig().imageLoader;
|
||||
if(loader != null) loader.debug(false, sender.getWorld());
|
||||
else ImageLoader.debugWorld(false, world);
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.dfsek.terra.command.image.gui;
|
||||
|
||||
import com.dfsek.terra.TerraWorld;
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.config.base.PluginConfig;
|
||||
import com.dfsek.terra.config.lang.LangUtil;
|
||||
import com.dfsek.terra.image.ImageLoader;
|
||||
@@ -25,9 +25,9 @@ public class StepGUICommand extends WorldCommand {
|
||||
LangUtil.send("command.image.gui.debug", sender);
|
||||
return true;
|
||||
}
|
||||
ImageLoader loader = TerraWorld.getWorld(world).getWorldConfig().imageLoader;
|
||||
if(loader != null) loader.debug(true, sender.getWorld());
|
||||
else ImageLoader.debugWorld(true, world);
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.dfsek.terra.command.structure;
|
||||
|
||||
import com.dfsek.terra.TerraWorld;
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.async.AsyncStructureFinder;
|
||||
import com.dfsek.terra.config.lang.LangUtil;
|
||||
import com.dfsek.terra.generation.TerraChunkGenerator;
|
||||
@@ -39,12 +39,12 @@ public class LocateCommand extends WorldCommand {
|
||||
}
|
||||
TerraStructure s;
|
||||
try {
|
||||
s = Objects.requireNonNull(TerraWorld.getWorld(world).getConfig().getStructure(id));
|
||||
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(TerraWorld.getWorld(world).getGrid(), s, sender.getLocation(), 0, maxRadius, (location) -> {
|
||||
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() + ").");
|
||||
@@ -55,7 +55,7 @@ public class LocateCommand extends WorldCommand {
|
||||
}
|
||||
} else sender.sendMessage("Unable to locate structure. ");
|
||||
}
|
||||
}, getMain()));
|
||||
}, (Terra) getMain()));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ public class LocateCommand extends WorldCommand {
|
||||
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 = TerraWorld.getWorld(((Player) sender).getWorld()).getConfig().getStructureIDs();
|
||||
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,5 +1,6 @@
|
||||
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;
|
||||
@@ -24,9 +25,9 @@ public class SpawnCommand extends WorldCommand implements DebugCommand {
|
||||
int x = p.getBlockX();
|
||||
int y = p.getBlockY();
|
||||
int z = p.getBlockZ();
|
||||
boolean air = StructureSpawnRequirement.AIR.getInstance(world).matches(x, y, z);
|
||||
boolean ground = StructureSpawnRequirement.LAND.getInstance(world).matches(x, y, z);
|
||||
boolean sea = StructureSpawnRequirement.OCEAN.getInstance(world).matches(x, y, z);
|
||||
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;
|
||||
|
||||
@@ -116,7 +116,7 @@ public class ConfigPack {
|
||||
throw new FileMissingException("No pack.yml file found in " + folder.getAbsolutePath(), e);
|
||||
}
|
||||
|
||||
load(new FolderLoader(folder.toPath()), l);
|
||||
load(new FolderLoader(folder.toPath()), l, main);
|
||||
}
|
||||
|
||||
public ConfigPack(ZipFile file, Terra main) throws ConfigException {
|
||||
@@ -140,10 +140,10 @@ public class ConfigPack {
|
||||
|
||||
selfLoader.load(template, stream);
|
||||
|
||||
load(new ZIPLoader(file), l);
|
||||
load(new ZIPLoader(file), l, main);
|
||||
}
|
||||
|
||||
private void load(Loader loader, long start) throws ConfigException {
|
||||
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());
|
||||
}
|
||||
@@ -153,7 +153,7 @@ public class ConfigPack {
|
||||
.open("palettes").then(streams -> buildAll(new PaletteFactory(), paletteRegistry, abstractConfigLoader.load(streams, PaletteTemplate::new))).close()
|
||||
.open("ores").then(streams -> buildAll(new OreFactory(), oreRegistry, abstractConfigLoader.load(streams, OreTemplate::new))).close()
|
||||
.open("flora").then(streams -> buildAll(new FloraFactory(), floraRegistry, abstractConfigLoader.load(streams, FloraTemplate::new))).close()
|
||||
.open("carving").then(streams -> buildAll(new CarverFactory(this), carverRegistry, abstractConfigLoader.load(streams, CarverTemplate::new))).close()
|
||||
.open("carving").then(streams -> buildAll(new CarverFactory(this, main), carverRegistry, abstractConfigLoader.load(streams, CarverTemplate::new))).close()
|
||||
.open("structures/trees").then(streams -> buildAll(new TreeFactory(), treeRegistry, abstractConfigLoader.load(streams, TreeTemplate::new))).close()
|
||||
.open("structures/single").then(streams -> buildAll(new StructureFactory(), structureRegistry, abstractConfigLoader.load(streams, StructureTemplate::new))).close()
|
||||
.open("biomes").then(streams -> buildAll(new BiomeFactory(this), biomeRegistry, abstractConfigLoader.load(streams, () -> new BiomeTemplate(this)))).close()
|
||||
|
||||
@@ -6,6 +6,7 @@ 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;
|
||||
@@ -111,6 +112,25 @@ public class ConfigPackTemplate implements ValidatedConfigTemplate {
|
||||
@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;
|
||||
}
|
||||
@@ -211,10 +231,32 @@ public class ConfigPackTemplate implements ValidatedConfigTemplate {
|
||||
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,84 +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.ConfigException;
|
||||
import com.dfsek.tectonic.exception.ValidationException;
|
||||
import com.dfsek.tectonic.loading.ConfigLoader;
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.image.ImageLoader;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
|
||||
public class WorldConfig implements ValidatedConfigTemplate {
|
||||
private static final ConfigLoader LOADER = new ConfigLoader();
|
||||
|
||||
private final String worldID;
|
||||
private final String configID;
|
||||
@Value("image.enable")
|
||||
@Default
|
||||
public boolean fromImage = false;
|
||||
|
||||
@Value("image.channels.biome-x")
|
||||
@Default
|
||||
public ImageLoader.Channel biomeXChannel = ImageLoader.Channel.RED;
|
||||
@Value("image.channels.biome-z")
|
||||
@Default
|
||||
public ImageLoader.Channel biomeZChannel = ImageLoader.Channel.GREEN;
|
||||
@Value("image.channels.zone")
|
||||
@Default
|
||||
public ImageLoader.Channel zoneChannel = ImageLoader.Channel.BLUE;
|
||||
|
||||
@Value("image")
|
||||
@Default
|
||||
public ImageLoader imageLoader = null;
|
||||
private ConfigPack tConfig;
|
||||
|
||||
public WorldConfig(String w, String configID, Terra main) {
|
||||
main.registerAllLoaders(LOADER);
|
||||
this.worldID = w;
|
||||
this.configID = configID;
|
||||
load(main);
|
||||
}
|
||||
|
||||
public void load(Terra main) {
|
||||
tConfig = main.getRegistry().get(configID);
|
||||
|
||||
if(tConfig == null) throw new IllegalStateException("No such config pack \"" + configID + "\"");
|
||||
|
||||
File file = new File(main.getDataFolder() + File.separator + "worlds", worldID + ".yml");
|
||||
|
||||
try {
|
||||
if(!file.exists()) {
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
file.getParentFile().mkdirs();
|
||||
FileUtils.copyInputStreamToFile(Objects.requireNonNull(main.getResource("world.yml")), file);
|
||||
}
|
||||
LOADER.load(this, new FileInputStream(file));
|
||||
} catch(IOException e) {
|
||||
throw new IllegalStateException("Unable to load configuration.", e);
|
||||
} catch(ConfigException e) {
|
||||
throw new IllegalStateException("Unable to proceed due to fatal configuration error.", e);
|
||||
}
|
||||
}
|
||||
|
||||
public String getWorldID() {
|
||||
return worldID;
|
||||
}
|
||||
|
||||
public ConfigPack getConfig() {
|
||||
return tConfig;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean validate() throws ValidationException {
|
||||
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,9 +1,9 @@
|
||||
package com.dfsek.terra.config.builder.biomegrid;
|
||||
|
||||
import com.dfsek.terra.config.base.WorldConfig;
|
||||
import com.dfsek.terra.config.base.ConfigPack;
|
||||
import org.bukkit.World;
|
||||
import org.polydev.gaea.biome.BiomeGrid;
|
||||
|
||||
public interface BiomeGridBuilder {
|
||||
BiomeGrid build(World world, WorldConfig config);
|
||||
BiomeGrid build(World world, ConfigPack config);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.dfsek.terra.config.builder.biomegrid;
|
||||
|
||||
import com.dfsek.terra.biome.grid.SingleBiomeGrid;
|
||||
import com.dfsek.terra.config.base.WorldConfig;
|
||||
import com.dfsek.terra.config.base.ConfigPack;
|
||||
import org.bukkit.World;
|
||||
import org.polydev.gaea.biome.Biome;
|
||||
|
||||
@@ -13,7 +13,7 @@ public class SingleGridBuilder implements BiomeGridBuilder {
|
||||
}
|
||||
|
||||
@Override
|
||||
public SingleBiomeGrid build(World world, WorldConfig config) {
|
||||
public SingleBiomeGrid build(World world, ConfigPack config) {
|
||||
return new SingleBiomeGrid(world, biome);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.dfsek.terra.config.builder.biomegrid;
|
||||
|
||||
import com.dfsek.terra.biome.grid.UserDefinedGrid;
|
||||
import com.dfsek.terra.config.base.WorldConfig;
|
||||
import com.dfsek.terra.config.base.ConfigPack;
|
||||
import org.bukkit.World;
|
||||
import org.polydev.gaea.biome.Biome;
|
||||
|
||||
@@ -12,7 +12,7 @@ public class UserDefinedGridBuilder implements BiomeGridBuilder {
|
||||
private Biome[][] biomes;
|
||||
|
||||
@Override
|
||||
public UserDefinedGrid build(World world, WorldConfig config) {
|
||||
public UserDefinedGrid build(World world, ConfigPack config) {
|
||||
return new UserDefinedGrid(world, 1D / xFreq, 1D / zFreq, biomes, config);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
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;
|
||||
@@ -12,9 +13,11 @@ import java.util.List;
|
||||
|
||||
public class CarverFactory implements TerraFactory<CarverTemplate, UserDefinedCarver> {
|
||||
private final ConfigPack pack;
|
||||
private final Terra main;
|
||||
|
||||
public CarverFactory(ConfigPack pack) {
|
||||
public CarverFactory(ConfigPack pack, Terra main) {
|
||||
this.pack = pack;
|
||||
this.main = main;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -25,7 +28,7 @@ public class CarverFactory implements TerraFactory<CarverTemplate, UserDefinedCa
|
||||
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);
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.dfsek.terra.debug.gui;
|
||||
|
||||
import com.dfsek.terra.TerraWorld;
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.biome.UserDefinedBiome;
|
||||
import com.dfsek.terra.generation.TerraChunkGenerator;
|
||||
import com.dfsek.terra.image.ImageLoader;
|
||||
@@ -20,12 +20,14 @@ public class DebugFrame extends JFrame implements ActionListener {
|
||||
private final int x;
|
||||
private final int z;
|
||||
private final BufferedImage img;
|
||||
private final Terra main;
|
||||
|
||||
public DebugFrame(BufferedImage image, String s) {
|
||||
public DebugFrame(BufferedImage image, String s, Terra main) {
|
||||
super(s);
|
||||
this.x = image.getWidth();
|
||||
this.z = image.getHeight();
|
||||
this.img = image;
|
||||
this.main = main;
|
||||
new Timer(500, this).start();
|
||||
}
|
||||
|
||||
@@ -36,12 +38,12 @@ public class DebugFrame extends JFrame implements ActionListener {
|
||||
if(!(p.getWorld().getGenerator() instanceof TerraChunkGenerator)) break;
|
||||
int xp = (int) (((double) FastMath.floorMod(p.getLocation().getBlockX() - (img.getWidth() / 2), x) / x) * getWidth());
|
||||
int zp = (int) (((double) FastMath.floorMod(p.getLocation().getBlockZ() - (img.getHeight() / 2), z) / z) * getHeight());
|
||||
ImageLoader loader = TerraWorld.getWorld(p.getWorld()).getWorldConfig().imageLoader;
|
||||
ImageLoader loader = main.getWorld(p.getWorld()).getConfig().getTemplate().getImageLoader();
|
||||
if(loader != null && loader.getAlign().equals(ImageLoader.Align.NONE)) {
|
||||
xp = (int) (((double) FastMath.floorMod(p.getLocation().getBlockX(), x) / x) * getWidth());
|
||||
zp = (int) (((double) FastMath.floorMod(p.getLocation().getBlockZ(), z) / z) * getHeight());
|
||||
}
|
||||
String str = ((UserDefinedBiome) TerraWorld.getWorld(p.getWorld()).getGrid().getBiome(p.getLocation(), GenerationPhase.POPULATE)).getID();
|
||||
String str = ((UserDefinedBiome) main.getWorld(p.getWorld()).getGrid().getBiome(p.getLocation(), GenerationPhase.POPULATE)).getID();
|
||||
g.setColor(new Color(255, 255, 255, 128));
|
||||
g.fillRect(xp + 13, zp - 13, (int) (8 + 8.25 * str.length()), 33);
|
||||
g.setColor(Color.BLACK);
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.dfsek.terra.debug.gui;
|
||||
|
||||
import com.dfsek.terra.Terra;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
@@ -7,14 +9,16 @@ import java.awt.image.BufferedImage;
|
||||
public class DebugGUI extends Thread {
|
||||
|
||||
private final BufferedImage img;
|
||||
private final Terra main;
|
||||
|
||||
public DebugGUI(BufferedImage img) {
|
||||
public DebugGUI(BufferedImage img, Terra main) {
|
||||
this.img = img;
|
||||
this.main = main;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
DebugFrame frame = new DebugFrame(img, "Image2Map Debug GUI");
|
||||
DebugFrame frame = new DebugFrame(img, "Image2Map Debug GUI", main);
|
||||
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||
frame.setSize(1000, 1000);
|
||||
frame.setResizable(false);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.dfsek.terra.generation;
|
||||
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.TerraProfiler;
|
||||
import com.dfsek.terra.TerraWorld;
|
||||
import com.dfsek.terra.biome.UserDefinedBiome;
|
||||
@@ -20,7 +21,6 @@ import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.generator.BlockPopulator;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.polydev.gaea.GaeaPlugin;
|
||||
import org.polydev.gaea.biome.Biome;
|
||||
import org.polydev.gaea.generation.GaeaChunkGenerator;
|
||||
import org.polydev.gaea.generation.GenerationPhase;
|
||||
@@ -47,14 +47,16 @@ public class TerraChunkGenerator extends GaeaChunkGenerator {
|
||||
private final PopulationManager popMan;
|
||||
private final ConfigPack configPack;
|
||||
private boolean needsLoad = true;
|
||||
private final Terra main;
|
||||
|
||||
public TerraChunkGenerator(ConfigPack c, GaeaPlugin main) {
|
||||
public TerraChunkGenerator(ConfigPack c, Terra main) {
|
||||
super(ChunkInterpolator.InterpolationType.TRILINEAR);
|
||||
popMan = new PopulationManager(main);
|
||||
this.configPack = c;
|
||||
popMan.attach(new OrePopulator());
|
||||
popMan.attach(new TreePopulator());
|
||||
popMan.attach(new FloraPopulator());
|
||||
this.main = main;
|
||||
popMan.attach(new OrePopulator(main));
|
||||
popMan.attach(new TreePopulator(main));
|
||||
popMan.attach(new FloraPopulator(main));
|
||||
}
|
||||
|
||||
public static synchronized void saveAll() {
|
||||
@@ -84,7 +86,7 @@ public class TerraChunkGenerator extends GaeaChunkGenerator {
|
||||
public ChunkData generateBase(@NotNull World world, @NotNull Random random, int chunkX, int chunkZ, ChunkInterpolator interpolator) {
|
||||
if(needsLoad) load(world); // Load population data for world.
|
||||
ChunkData chunk = createChunkData(world);
|
||||
TerraWorld tw = TerraWorld.getWorld(world);
|
||||
TerraWorld tw = main.getWorld(world);
|
||||
if(!tw.isSafe()) return chunk;
|
||||
int xOrig = (chunkX << 4);
|
||||
int zOrig = (chunkZ << 4);
|
||||
@@ -169,15 +171,14 @@ public class TerraChunkGenerator extends GaeaChunkGenerator {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public org.polydev.gaea.biome.BiomeGrid getBiomeGrid(World world) {
|
||||
return TerraWorld.getWorld(world).getGrid();
|
||||
return main.getWorld(world).getGrid();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<BlockPopulator> getDefaultPopulators(@NotNull World world) {
|
||||
return Arrays.asList(new CavePopulator(), new StructurePopulator(), popMan);
|
||||
return Arrays.asList(new CavePopulator(main), new StructurePopulator(main), popMan);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.dfsek.terra.generation.items.tree;
|
||||
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.procgen.math.Vector2;
|
||||
import com.dfsek.terra.structure.Rotation;
|
||||
import com.dfsek.terra.structure.Structure;
|
||||
@@ -26,12 +27,12 @@ public class TerraTree implements Tree {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean plant(Location location, Random random, JavaPlugin javaPlugin) {
|
||||
public boolean plant(Location location, Random random, JavaPlugin main) {
|
||||
Location mut = location.clone().subtract(0, yOffset, 0);
|
||||
if(!spawnable.contains(location.getBlock().getType())) return false;
|
||||
Structure struc = structure.get(random);
|
||||
Rotation rotation = Rotation.fromDegrees(random.nextInt(4) * 90);
|
||||
if(!struc.checkSpawns(mut, rotation)) return false;
|
||||
if(!struc.checkSpawns(mut, rotation, (Terra) main)) return false;
|
||||
struc.paste(mut, rotation);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.dfsek.terra.image;
|
||||
|
||||
import com.dfsek.terra.TerraWorld;
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.biome.BiomeZone;
|
||||
import com.dfsek.terra.biome.grid.master.TerraBiomeGrid;
|
||||
import com.dfsek.terra.config.base.PluginConfig;
|
||||
@@ -25,18 +25,18 @@ public class ImageLoader {
|
||||
this.align = align;
|
||||
}
|
||||
|
||||
public static void debugWorld(boolean genStep, World w) {
|
||||
public static void debugWorld(boolean genStep, World w, Terra main) {
|
||||
if(!PluginConfig.isDebug()) return;
|
||||
BufferedImage newImg = new WorldImageGenerator(w, 1024, 1024).drawWorld(0, 0).getDraw();
|
||||
if(genStep) newImg = redrawStepped(newImg, w, Align.CENTER);
|
||||
DebugGUI debugGUI = new DebugGUI(newImg);
|
||||
BufferedImage newImg = new WorldImageGenerator(w, 1024, 1024, main).drawWorld(0, 0).getDraw();
|
||||
if(genStep) newImg = redrawStepped(newImg, w, Align.CENTER, main);
|
||||
DebugGUI debugGUI = new DebugGUI(newImg, main);
|
||||
debugGUI.start();
|
||||
}
|
||||
|
||||
private static BufferedImage redrawStepped(BufferedImage original, World w, Align align) {
|
||||
private static BufferedImage redrawStepped(BufferedImage original, World w, Align align, Terra main) {
|
||||
BufferedImage newImg = copyImage(original);
|
||||
TerraBiomeGrid tb = TerraWorld.getWorld(w).getGrid();
|
||||
BiomeZone z = TerraWorld.getWorld(w).getZone();
|
||||
TerraBiomeGrid tb = main.getWorld(w).getGrid();
|
||||
BiomeZone z = main.getWorld(w).getZone();
|
||||
for(int x = 0; x < newImg.getWidth(); x++) {
|
||||
for(int y = 0; y < newImg.getHeight(); y++) {
|
||||
double[] noise;
|
||||
@@ -60,13 +60,13 @@ public class ImageLoader {
|
||||
return b;
|
||||
}
|
||||
|
||||
public void debug(boolean genStep, World w) {
|
||||
public void debug(boolean genStep, World w, Terra main) {
|
||||
if(!PluginConfig.isDebug()) return;
|
||||
BufferedImage newImg = copyImage(image);
|
||||
if(genStep) {
|
||||
newImg = redrawStepped(image, w, align);
|
||||
newImg = redrawStepped(image, w, align, main);
|
||||
}
|
||||
DebugGUI debugGUI = new DebugGUI(newImg);
|
||||
DebugGUI debugGUI = new DebugGUI(newImg, main);
|
||||
debugGUI.start();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.dfsek.terra.image;
|
||||
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.TerraWorld;
|
||||
import com.dfsek.terra.biome.grid.master.TerraBiomeGrid;
|
||||
import org.bukkit.World;
|
||||
@@ -14,14 +15,16 @@ import java.io.IOException;
|
||||
public class WorldImageGenerator {
|
||||
private final World w;
|
||||
private final BufferedImage draw;
|
||||
private final Terra main;
|
||||
|
||||
public WorldImageGenerator(World w, int width, int height) {
|
||||
public WorldImageGenerator(World w, int width, int height, Terra main) {
|
||||
draw = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
|
||||
this.w = w;
|
||||
this.main = main;
|
||||
}
|
||||
|
||||
public WorldImageGenerator drawWorld(int centerX, int centerZ) {
|
||||
TerraWorld tw = TerraWorld.getWorld(w);
|
||||
TerraWorld tw = main.getWorld(w);
|
||||
TerraBiomeGrid tb = tw.getGrid();
|
||||
int imY = 0;
|
||||
for(int y = centerZ - (draw.getHeight() / 2); y < centerZ + (draw.getHeight() / 2); y++) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.dfsek.terra.listeners;
|
||||
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.TerraWorld;
|
||||
import com.dfsek.terra.config.base.ConfigPack;
|
||||
import com.dfsek.terra.debug.Debug;
|
||||
@@ -11,7 +12,6 @@ import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.world.StructureGrowEvent;
|
||||
import org.polydev.gaea.GaeaPlugin;
|
||||
import org.polydev.gaea.tree.Tree;
|
||||
import org.polydev.gaea.tree.TreeType;
|
||||
import org.polydev.gaea.util.FastRandom;
|
||||
@@ -20,16 +20,16 @@ import org.polydev.gaea.util.FastRandom;
|
||||
* Listener for events on all implementations.
|
||||
*/
|
||||
public class EventListener implements Listener {
|
||||
private final GaeaPlugin main;
|
||||
private final Terra main;
|
||||
|
||||
public EventListener(GaeaPlugin main) {
|
||||
public EventListener(Terra main) {
|
||||
this.main = main;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onSaplingGrow(StructureGrowEvent e) {
|
||||
if(!TerraWorld.isTerraWorld(e.getWorld())) return;
|
||||
TerraWorld tw = TerraWorld.getWorld(e.getWorld());
|
||||
TerraWorld tw = main.getWorld(e.getWorld());
|
||||
ConfigPack c = tw.getConfig();
|
||||
if(c.getTemplate().isDisableSaplings()) return;
|
||||
e.setCancelled(true);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.dfsek.terra.listeners;
|
||||
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.TerraWorld;
|
||||
import com.dfsek.terra.async.AsyncStructureFinder;
|
||||
import com.dfsek.terra.debug.Debug;
|
||||
@@ -15,7 +16,6 @@ import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntitySpawnEvent;
|
||||
import org.bukkit.event.entity.VillagerAcquireTradeEvent;
|
||||
import org.bukkit.event.entity.VillagerCareerChangeEvent;
|
||||
import org.polydev.gaea.GaeaPlugin;
|
||||
|
||||
/**
|
||||
* Listener to load on Spigot servers, contains Villager crash prevention and hacky ender eye redirection.
|
||||
@@ -24,9 +24,9 @@ import org.polydev.gaea.GaeaPlugin;
|
||||
* StructureLocateEvent).
|
||||
*/
|
||||
public class SpigotListener implements Listener {
|
||||
private final GaeaPlugin main;
|
||||
private final Terra main;
|
||||
|
||||
public SpigotListener(GaeaPlugin main) {
|
||||
public SpigotListener(Terra main) {
|
||||
this.main = main;
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ public class SpigotListener implements Listener {
|
||||
if(e.getEntityType().equals(EntityType.ENDER_SIGNAL)) {
|
||||
Debug.info("Detected Ender Signal...");
|
||||
if(!TerraWorld.isTerraWorld(e.getEntity().getWorld())) return;
|
||||
TerraWorld tw = TerraWorld.getWorld(e.getEntity().getWorld());
|
||||
TerraWorld tw = main.getWorld(e.getEntity().getWorld());
|
||||
EnderSignal signal = (EnderSignal) entity;
|
||||
TerraStructure config = tw.getConfig().getStructureLocatable(StructureTypeEnum.STRONGHOLD);
|
||||
if(config != null) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.dfsek.terra.population;
|
||||
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.TerraProfiler;
|
||||
import com.dfsek.terra.TerraWorld;
|
||||
import com.dfsek.terra.carving.UserDefinedCarver;
|
||||
@@ -24,15 +25,20 @@ import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
public class CavePopulator extends BlockPopulator {
|
||||
private final Terra main;
|
||||
private static final Map<Material, BlockData> shiftStorage = new HashMap<>(); // Persist BlockData created for shifts, to avoid re-calculating each time.
|
||||
private static final BlockData AIR = Material.AIR.createBlockData();
|
||||
|
||||
public CavePopulator(Terra main) {
|
||||
this.main = main;
|
||||
}
|
||||
|
||||
@SuppressWarnings("try")
|
||||
@Override
|
||||
public void populate(@NotNull World world, @NotNull Random r, @NotNull Chunk chunk) {
|
||||
try(ProfileFuture ignored = TerraProfiler.fromWorld(world).measure("CaveTime")) {
|
||||
Random random = PopulationUtil.getRandom(chunk);
|
||||
TerraWorld tw = TerraWorld.getWorld(world);
|
||||
TerraWorld tw = main.getWorld(world);
|
||||
if(!tw.isSafe()) return;
|
||||
ConfigPack config = tw.getConfig();
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.dfsek.terra.population;
|
||||
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.TerraProfiler;
|
||||
import com.dfsek.terra.TerraWorld;
|
||||
import com.dfsek.terra.biome.UserDefinedBiome;
|
||||
@@ -22,11 +23,17 @@ import java.util.Random;
|
||||
* Populates Flora and Trees
|
||||
*/
|
||||
public class FloraPopulator extends GaeaBlockPopulator {
|
||||
private final Terra main;
|
||||
|
||||
public FloraPopulator(Terra main) {
|
||||
this.main = main;
|
||||
}
|
||||
|
||||
@SuppressWarnings("try")
|
||||
@Override
|
||||
public void populate(@NotNull World world, @NotNull Random random, @NotNull Chunk chunk) {
|
||||
try(ProfileFuture ignored = TerraProfiler.fromWorld(world).measure("FloraTime")) {
|
||||
TerraWorld tw = TerraWorld.getWorld(world);
|
||||
TerraWorld tw = main.getWorld(world);
|
||||
if(!tw.isSafe()) return;
|
||||
TerraBiomeGrid grid = tw.getGrid();
|
||||
Map<Vector2, List<FloraLayer>> layers = new HashMap<>();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.dfsek.terra.population;
|
||||
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.TerraProfiler;
|
||||
import com.dfsek.terra.TerraWorld;
|
||||
import com.dfsek.terra.biome.UserDefinedBiome;
|
||||
@@ -18,18 +19,24 @@ import org.polydev.gaea.util.FastRandom;
|
||||
import java.util.Random;
|
||||
|
||||
public class OrePopulator extends GaeaBlockPopulator {
|
||||
private final Terra main;
|
||||
|
||||
public OrePopulator(Terra main) {
|
||||
this.main = main;
|
||||
}
|
||||
|
||||
@SuppressWarnings("try")
|
||||
@Override
|
||||
public void populate(@NotNull World world, @NotNull Random r, @NotNull Chunk chunk) {
|
||||
try(ProfileFuture ignored = TerraProfiler.fromWorld(world).measure("OreTime")) {
|
||||
TerraWorld tw = TerraWorld.getWorld(world);
|
||||
TerraWorld tw = main.getWorld(world);
|
||||
if(!tw.isSafe()) return;
|
||||
for(int cx = -1; cx <= 1; cx++) {
|
||||
for(int cz = -1; cz <= 1; cz++) {
|
||||
Random random = new FastRandom(MathUtil.getCarverChunkSeed(chunk.getX() + cx, chunk.getZ() + cz, world.getSeed()));
|
||||
int originX = ((chunk.getX() + cx) << 4);
|
||||
int originZ = ((chunk.getZ() + cz) << 4);
|
||||
Biome b = TerraWorld.getWorld(world).getGrid().getBiome(originX + 8, originZ + 8, GenerationPhase.POPULATE);
|
||||
Biome b = main.getWorld(world).getGrid().getBiome(originX + 8, originZ + 8, GenerationPhase.POPULATE);
|
||||
BiomeTemplate config = ((UserDefinedBiome) b).getConfig();
|
||||
int finalCx = cx;
|
||||
int finalCz = cz;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.dfsek.terra.population;
|
||||
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.TerraProfiler;
|
||||
import com.dfsek.terra.TerraWorld;
|
||||
import com.dfsek.terra.biome.UserDefinedBiome;
|
||||
@@ -28,6 +29,11 @@ import org.polydev.gaea.util.FastRandom;
|
||||
import java.util.Random;
|
||||
|
||||
public class StructurePopulator extends BlockPopulator {
|
||||
private final Terra main;
|
||||
|
||||
public StructurePopulator(Terra main) {
|
||||
this.main = main;
|
||||
}
|
||||
|
||||
@SuppressWarnings("try")
|
||||
@Override
|
||||
@@ -36,7 +42,7 @@ public class StructurePopulator extends BlockPopulator {
|
||||
Random random = PopulationUtil.getRandom(chunk);
|
||||
int cx = (chunk.getX() << 4);
|
||||
int cz = (chunk.getZ() << 4);
|
||||
TerraWorld tw = TerraWorld.getWorld(world);
|
||||
TerraWorld tw = main.getWorld(world);
|
||||
if(!tw.isSafe()) return;
|
||||
TerraBiomeGrid grid = tw.getGrid();
|
||||
ConfigPack config = tw.getConfig();
|
||||
@@ -50,7 +56,7 @@ public class StructurePopulator extends BlockPopulator {
|
||||
for(int y = conf.getSpawnStart().get(r2); y > 0; y--) {
|
||||
if(!conf.getBound().isInRange(y)) continue structure;
|
||||
spawn.setY(y);
|
||||
if(!struc.checkSpawns(spawn, rotation)) continue;
|
||||
if(!struc.checkSpawns(spawn, rotation, main)) continue;
|
||||
double horizontal = struc.getStructureInfo().getMaxHorizontal();
|
||||
if(FastMath.abs((cx + 8) - spawn.getBlockX()) <= horizontal && FastMath.abs((cz + 8) - spawn.getBlockZ()) <= horizontal) {
|
||||
struc.paste(spawn, chunk, rotation);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.dfsek.terra.population;
|
||||
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.TerraProfiler;
|
||||
import com.dfsek.terra.TerraWorld;
|
||||
import com.dfsek.terra.biome.UserDefinedBiome;
|
||||
@@ -18,6 +19,11 @@ import java.util.Random;
|
||||
|
||||
|
||||
public class TreePopulator extends GaeaBlockPopulator {
|
||||
private final Terra main;
|
||||
|
||||
public TreePopulator(Terra main) {
|
||||
this.main = main;
|
||||
}
|
||||
|
||||
private static int offset(Random r, int i) {
|
||||
return FastMath.min(FastMath.max(i + r.nextInt(3) - 1, 0), 15);
|
||||
@@ -27,7 +33,7 @@ public class TreePopulator extends GaeaBlockPopulator {
|
||||
@SuppressWarnings("try")
|
||||
public void populate(@NotNull World world, @NotNull Random random, @NotNull Chunk chunk) {
|
||||
try(ProfileFuture ignored = TerraProfiler.fromWorld(world).measure("TreeTime")) {
|
||||
TerraWorld tw = TerraWorld.getWorld(world);
|
||||
TerraWorld tw = main.getWorld(world);
|
||||
if(!tw.isSafe()) return;
|
||||
TerraBiomeGrid grid = tw.getGrid();
|
||||
for(int x = 0; x < 16; x += 2) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.dfsek.terra.structure;
|
||||
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.debug.Debug;
|
||||
import com.dfsek.terra.procgen.math.Vector2;
|
||||
import com.dfsek.terra.util.structure.RotationUtil;
|
||||
@@ -284,10 +285,10 @@ public class Structure implements Serializable {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean checkSpawns(Location origin, Rotation r) {
|
||||
public boolean checkSpawns(Location origin, Rotation r, Terra main) {
|
||||
for(StructureContainedBlock b : spawns) {
|
||||
Vector2 rot = getRotatedCoords(new Vector2(b.getX() - structureInfo.getCenterX(), b.getZ() - structureInfo.getCenterZ()), r);
|
||||
if(!b.getRequirement().getInstance(origin.getWorld()).matches((int) rot.getX() + origin.getBlockX(), origin.getBlockY() + b.getY(), (int) rot.getZ() + origin.getBlockZ()))
|
||||
if(!b.getRequirement().getInstance(origin.getWorld(), main).matches((int) rot.getX() + origin.getBlockX(), origin.getBlockY() + b.getY(), (int) rot.getZ() + origin.getBlockZ()))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.dfsek.terra.structure;
|
||||
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.structure.spawn.AirSpawn;
|
||||
import com.dfsek.terra.structure.spawn.BlankSpawn;
|
||||
import com.dfsek.terra.structure.spawn.LandSpawn;
|
||||
@@ -12,26 +13,26 @@ import java.io.Serializable;
|
||||
public enum StructureSpawnRequirement implements Serializable {
|
||||
AIR {
|
||||
@Override
|
||||
public Requirement getInstance(World world) {
|
||||
return new AirSpawn(world);
|
||||
public Requirement getInstance(World world, Terra main) {
|
||||
return new AirSpawn(world, main);
|
||||
}
|
||||
}, OCEAN {
|
||||
@Override
|
||||
public Requirement getInstance(World world) {
|
||||
return new OceanSpawn(world);
|
||||
public Requirement getInstance(World world, Terra main) {
|
||||
return new OceanSpawn(world, main);
|
||||
}
|
||||
}, LAND {
|
||||
@Override
|
||||
public Requirement getInstance(World world) {
|
||||
return new LandSpawn(world);
|
||||
public Requirement getInstance(World world, Terra main) {
|
||||
return new LandSpawn(world, main);
|
||||
}
|
||||
}, BLANK {
|
||||
@Override
|
||||
public Requirement getInstance(World world) {
|
||||
public Requirement getInstance(World world, Terra main) {
|
||||
return new BlankSpawn();
|
||||
}
|
||||
};
|
||||
private static final long serialVersionUID = -175639605885943679L;
|
||||
|
||||
public abstract Requirement getInstance(World world);
|
||||
public abstract Requirement getInstance(World world, Terra main);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.dfsek.terra.structure.spawn;
|
||||
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.TerraWorld;
|
||||
import com.dfsek.terra.biome.UserDefinedBiome;
|
||||
import com.dfsek.terra.config.templates.BiomeTemplate;
|
||||
@@ -8,17 +9,17 @@ import org.bukkit.World;
|
||||
import org.polydev.gaea.generation.GenerationPhase;
|
||||
|
||||
public class AirSpawn extends Requirement {
|
||||
public AirSpawn(World world) {
|
||||
super(world);
|
||||
public AirSpawn(World world, Terra main) {
|
||||
super(world, main);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(int x, int y, int z) {
|
||||
TerraWorld tw = TerraWorld.getWorld(getWorld());
|
||||
TerraWorld tw = main.getWorld(world);
|
||||
UserDefinedBiome b = (UserDefinedBiome) tw.getGrid().getBiome(x, z, GenerationPhase.POPULATE);
|
||||
BiomeTemplate c = b.getConfig();
|
||||
if(y <= c.getSeaLevel()) return false;
|
||||
double elevation = ((WorldGenerator) b.getGenerator()).getElevation(x, z);
|
||||
return b.getGenerator().getNoise(getNoise(), getWorld(), x, y, z) + elevation <= 0;
|
||||
return b.getGenerator().getNoise(getNoise(), world, x, y, z) + elevation <= 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.dfsek.terra.structure.spawn;
|
||||
|
||||
public class BlankSpawn extends Requirement {
|
||||
public BlankSpawn() {
|
||||
super(null);
|
||||
super(null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.dfsek.terra.structure.spawn;
|
||||
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.TerraWorld;
|
||||
import com.dfsek.terra.biome.UserDefinedBiome;
|
||||
import com.dfsek.terra.generation.config.WorldGenerator;
|
||||
@@ -7,15 +8,15 @@ import org.bukkit.World;
|
||||
import org.polydev.gaea.generation.GenerationPhase;
|
||||
|
||||
public class LandSpawn extends Requirement {
|
||||
public LandSpawn(World world) {
|
||||
super(world);
|
||||
public LandSpawn(World world, Terra main) {
|
||||
super(world, main);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(int x, int y, int z) {
|
||||
TerraWorld tw = TerraWorld.getWorld(getWorld());
|
||||
TerraWorld tw = main.getWorld(world);
|
||||
UserDefinedBiome b = (UserDefinedBiome) tw.getGrid().getBiome(x, z, GenerationPhase.POPULATE);
|
||||
double elevation = ((WorldGenerator) b.getGenerator()).getElevation(x, z);
|
||||
return b.getGenerator().getNoise(getNoise(), getWorld(), x, y, z) + elevation > 0;
|
||||
return b.getGenerator().getNoise(getNoise(), world, x, y, z) + elevation > 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.dfsek.terra.structure.spawn;
|
||||
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.TerraWorld;
|
||||
import com.dfsek.terra.biome.UserDefinedBiome;
|
||||
import com.dfsek.terra.config.templates.BiomeTemplate;
|
||||
@@ -8,17 +9,17 @@ import org.bukkit.World;
|
||||
import org.polydev.gaea.generation.GenerationPhase;
|
||||
|
||||
public class OceanSpawn extends Requirement {
|
||||
public OceanSpawn(World world) {
|
||||
super(world);
|
||||
public OceanSpawn(World world, Terra main) {
|
||||
super(world, main);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(int x, int y, int z) {
|
||||
TerraWorld tw = TerraWorld.getWorld(getWorld());
|
||||
TerraWorld tw = main.getWorld(world);
|
||||
UserDefinedBiome b = (UserDefinedBiome) tw.getGrid().getBiome(x, z, GenerationPhase.POPULATE);
|
||||
BiomeTemplate c = b.getConfig();
|
||||
if(y > c.getSeaLevel()) return false;
|
||||
double elevation = ((WorldGenerator) b.getGenerator()).getElevation(x, z);
|
||||
return b.getGenerator().getNoise(getNoise(), getWorld(), x, y, z) + elevation <= 0;
|
||||
return b.getGenerator().getNoise(getNoise(), world, x, y, z) + elevation <= 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.dfsek.terra.structure.spawn;
|
||||
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.generation.TerraChunkGenerator;
|
||||
import org.bukkit.World;
|
||||
import org.polydev.gaea.math.FastNoiseLite;
|
||||
@@ -7,10 +8,12 @@ import org.polydev.gaea.math.FastNoiseLite;
|
||||
import java.util.Objects;
|
||||
|
||||
public abstract class Requirement {
|
||||
private final World world;
|
||||
protected final World world;
|
||||
protected final Terra main;
|
||||
|
||||
public Requirement(World world) {
|
||||
public Requirement(World world, Terra main) {
|
||||
this.world = world;
|
||||
this.main = main;
|
||||
}
|
||||
|
||||
public abstract boolean matches(int x, int y, int z);
|
||||
|
||||
Reference in New Issue
Block a user