mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-06-19 07:11:14 +00:00
Fix up issues with code
Signed-off-by: solonovamax <solonovamax@12oclockpoint.com>
This commit is contained in:
+1
-1
@@ -179,7 +179,7 @@ ij_java_space_before_for_left_brace = true
|
||||
ij_java_space_before_for_parentheses = false
|
||||
ij_java_space_before_for_semicolon = false
|
||||
ij_java_space_before_if_left_brace = true
|
||||
ij_java_space_before_if_parentheses = false
|
||||
ij_java_space_before_if_parentheses = true
|
||||
ij_java_space_before_method_call_parentheses = false
|
||||
ij_java_space_before_method_left_brace = true
|
||||
ij_java_space_before_method_parentheses = false
|
||||
|
||||
@@ -134,3 +134,5 @@ build
|
||||
.idea/codeStyles/**
|
||||
.idea/**.xml
|
||||
.idea/modules/**.iml
|
||||
|
||||
!lib/*.jar
|
||||
@@ -44,6 +44,8 @@ dependencies {
|
||||
// JUnit.
|
||||
testImplementation("org.junit.jupiter:junit-jupiter-api:5.7.0")
|
||||
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.7.0")
|
||||
|
||||
testImplementation(name = "Gaea-1.14.0", group = "")
|
||||
}
|
||||
|
||||
tasks.test {
|
||||
@@ -92,6 +94,7 @@ val setupServer = tasks.create("setupServer") {
|
||||
}
|
||||
|
||||
val testWithPaper = task<JavaExec>(name = "testWithPaper") {
|
||||
standardInput = System.`in`
|
||||
dependsOn(setupServer)
|
||||
//dependsOn(tasks.shadowJar)
|
||||
// Copy Terra into dir
|
||||
@@ -138,6 +141,7 @@ tasks.build {
|
||||
/**
|
||||
* Version class that does version stuff.
|
||||
*/
|
||||
@Suppress("MemberVisibilityCanBePrivate")
|
||||
class Version(val major: String, val minor: String, val revision: String, val preReleaseData: String? = null) {
|
||||
|
||||
override fun toString(): String {
|
||||
|
||||
@@ -21,6 +21,7 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
|
||||
public class Terra extends GaeaPlugin {
|
||||
private static Terra instance;
|
||||
private final Map<String, TerraChunkGenerator> generatorMap = new HashMap<>();
|
||||
@@ -53,6 +54,7 @@ public class Terra extends GaeaPlugin {
|
||||
locatePl.setTabCompleter(locate);
|
||||
|
||||
saveDefaultConfig();
|
||||
//noinspection deprecation
|
||||
Bukkit.getScheduler().scheduleAsyncRepeatingTask(this, TerraChunkGenerator::saveAll, ConfigUtil.dataSave, ConfigUtil.dataSave);
|
||||
Bukkit.getPluginManager().registerEvents(new EventListener(this), this);
|
||||
PaperUtil.checkPaper(this);
|
||||
|
||||
@@ -23,6 +23,14 @@ public class TerraWorld {
|
||||
private final WorldConfig worldConfig;
|
||||
private boolean safe;
|
||||
|
||||
public static void loadWorld(WorldConfig w) {
|
||||
loaded.put(w.getWorldID(), w);
|
||||
}
|
||||
|
||||
public static synchronized TerraWorld getWorld(World w) {
|
||||
return map.computeIfAbsent(w, TerraWorld::new);
|
||||
}
|
||||
|
||||
private TerraWorld(World w) {
|
||||
safe = true;
|
||||
worldConfig = loaded.get(w.getName());
|
||||
@@ -78,14 +86,6 @@ public class TerraWorld {
|
||||
grid = new TerraBiomeGrid(w, config.freq1, config.freq2, zone, config, erosion);
|
||||
}
|
||||
|
||||
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();
|
||||
for(WorldConfig config : loaded.values()) {
|
||||
|
||||
@@ -10,6 +10,7 @@ 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.Random;
|
||||
import java.util.function.Consumer;
|
||||
@@ -28,7 +29,7 @@ public class AsyncStructureFinder implements Runnable {
|
||||
private final World world;
|
||||
private final Consumer<Vector> callback;
|
||||
|
||||
public AsyncStructureFinder(TerraBiomeGrid grid, StructureConfig target, Location origin, int startRadius, int maxRadius, Consumer<Vector> callback) {
|
||||
public AsyncStructureFinder(TerraBiomeGrid grid, StructureConfig target, @NotNull Location origin, int startRadius, int maxRadius, Consumer<Vector> callback) {
|
||||
this.grid = grid;
|
||||
this.target = target;
|
||||
this.startRadius = startRadius;
|
||||
@@ -36,6 +37,7 @@ public class AsyncStructureFinder implements Runnable {
|
||||
this.centerX = origin.getBlockX();
|
||||
this.centerZ = origin.getBlockZ();
|
||||
this.world = origin.getWorld();
|
||||
assert world != null;
|
||||
this.seed = world.getSeed();
|
||||
this.callback = callback;
|
||||
}
|
||||
|
||||
@@ -31,6 +31,10 @@ public class TerraBiomeGrid extends BiomeGrid {
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
@@ -62,7 +66,5 @@ public class TerraBiomeGrid extends BiomeGrid {
|
||||
return getBiome(l.getBlockX(), l.getBlockZ(), phase);
|
||||
}
|
||||
|
||||
public UserDefinedGrid getGrid(int x, int z) {
|
||||
return (UserDefinedGrid) zone.getGrid(x, z);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import parsii.tokenizer.ParseException;
|
||||
/**
|
||||
* What happens if terrain generation is attempted with an unrecoverable config error.
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public enum FailType {
|
||||
/**
|
||||
* Return failover biome, then shut down server to minimize damage.
|
||||
|
||||
@@ -9,6 +9,7 @@ import org.polydev.gaea.world.carving.Worm;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class SimplexCarver extends Carver {
|
||||
private final FastNoiseLite noise;
|
||||
private final FastNoiseLite height;
|
||||
@@ -39,20 +40,6 @@ public class SimplexCarver extends Carver {
|
||||
hasCaves.setFrequency(0.005f);
|
||||
}
|
||||
|
||||
private static double acot(double x) {
|
||||
return Math.PI / 2 - Math.atan(x);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Worm getWorm(long l, Vector vector) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isChunkCarved(World world, int i, int i1, Random random) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CarvingData carve(int chunkX, int chunkZ, World w) {
|
||||
CarvingData c = new CarvingData(chunkX, chunkZ);
|
||||
@@ -80,4 +67,18 @@ public class SimplexCarver extends Carver {
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
private static double acot(double x) {
|
||||
return Math.PI / 2 - Math.atan(x);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Worm getWorm(long l, Vector vector) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isChunkCarved(World world, int i, int i1, Random random) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,6 +42,11 @@ public class OreCommand extends WorldCommand {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "ore";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<org.polydev.gaea.command.Command> getSubCommands() {
|
||||
return Collections.emptyList();
|
||||
@@ -52,11 +57,6 @@ public class OreCommand extends WorldCommand {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "ore";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) {
|
||||
return Collections.emptyList();
|
||||
|
||||
@@ -23,10 +23,8 @@ public class SaveDataCommand extends WorldCommand {
|
||||
}
|
||||
|
||||
@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;
|
||||
public List<Command> getSubCommands() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -35,12 +33,14 @@ public class SaveDataCommand extends WorldCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Command> getSubCommands() {
|
||||
public List<String> getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) {
|
||||
return Collections.emptyList();
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,11 @@ public class ImageCommand extends WorldCommand {
|
||||
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));
|
||||
@@ -34,11 +39,6 @@ public class ImageCommand extends WorldCommand {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "image";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) {
|
||||
return Collections.emptyList();
|
||||
|
||||
@@ -25,7 +25,9 @@ public class RenderCommand extends WorldCommand {
|
||||
WorldImageGenerator g = new WorldImageGenerator(world, Integer.parseInt(args[0]), Integer.parseInt(args[1]));
|
||||
g.drawWorld(sender.getLocation().getBlockX(), sender.getLocation().getBlockZ());
|
||||
File file = new File(Terra.getInstance().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());
|
||||
|
||||
@@ -37,7 +37,9 @@ public class ExportCommand extends PlayerCommand {
|
||||
}
|
||||
try {
|
||||
File file = new File(Terra.getInstance().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());
|
||||
@@ -47,11 +49,6 @@ public class ExportCommand extends PlayerCommand {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "export";
|
||||
@@ -66,4 +63,9 @@ public class ExportCommand extends PlayerCommand {
|
||||
public int arguments() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,11 +46,6 @@ public class LoadCommand extends PlayerCommand implements DebugCommand {
|
||||
return "load";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<org.polydev.gaea.command.Command> getSubCommands() {
|
||||
return Collections.emptyList();
|
||||
@@ -60,4 +55,9 @@ public class LoadCommand extends PlayerCommand implements DebugCommand {
|
||||
public int arguments() {
|
||||
return 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,13 +23,13 @@ public class StructureCommand extends PlayerCommand {
|
||||
}
|
||||
|
||||
@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));
|
||||
public String getName() {
|
||||
return "structure";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) {
|
||||
return Collections.emptyList();
|
||||
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
|
||||
@@ -38,7 +38,7 @@ public class StructureCommand extends PlayerCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "structure";
|
||||
public List<String> getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ public class ConfigLoader {
|
||||
public static <T extends TerraConfig> Map<String, T> load(Path file, ConfigPack config, Class<T> clazz) {
|
||||
long l = System.nanoTime();
|
||||
Map<String, T> configs = new HashMap<>();
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
file.toFile().mkdirs();
|
||||
List<String> ids = new ArrayList<>();
|
||||
try(Stream<Path> paths = Files.walk(file)) {
|
||||
@@ -40,7 +41,7 @@ public class ConfigLoader {
|
||||
LangUtil.log("config.error.generic", Level.SEVERE, path.toString());
|
||||
} catch(IllegalArgumentException | InvocationTargetException e) {
|
||||
if(ConfigUtil.debug) e.printStackTrace();
|
||||
LangUtil.log("config.error.file", Level.SEVERE, path.toString(), ((e instanceof InvocationTargetException) ? "INVOCATION: " + e.getCause().getMessage() : e.getMessage()));
|
||||
LangUtil.log("config.error.file", Level.SEVERE, path.toString(), e.getMessage());
|
||||
}
|
||||
});
|
||||
LangUtil.log("config.loaded-all", Level.INFO, String.valueOf(configs.size()), clazz.getSimpleName(), String.valueOf((System.nanoTime() - l) / 1000000D));
|
||||
|
||||
@@ -161,6 +161,7 @@ public class ConfigPack extends YamlConfiguration {
|
||||
public static synchronized void loadAll(JavaPlugin main) {
|
||||
configs.clear();
|
||||
File file = new File(main.getDataFolder(), "packs");
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
file.mkdirs();
|
||||
List<Path> subfolder;
|
||||
try {
|
||||
@@ -187,6 +188,22 @@ public class ConfigPack extends YamlConfiguration {
|
||||
}
|
||||
}
|
||||
|
||||
public String getID() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public Map<String, BiomeConfig> getBiomes() {
|
||||
return biomes;
|
||||
}
|
||||
|
||||
public StructureConfig getStructure(String id) {
|
||||
return structures.get(id);
|
||||
}
|
||||
|
||||
public BiomeGridConfig getBiomeGrid(String id) {
|
||||
return grids.get(id);
|
||||
}
|
||||
|
||||
public static synchronized ConfigPack fromID(String id) {
|
||||
return configs.get(id);
|
||||
}
|
||||
@@ -199,10 +216,6 @@ public class ConfigPack extends YamlConfiguration {
|
||||
return abstractBiomes;
|
||||
}
|
||||
|
||||
public Map<String, BiomeConfig> getBiomes() {
|
||||
return biomes;
|
||||
}
|
||||
|
||||
public Map<String, CarverConfig> getCarvers() {
|
||||
return carvers;
|
||||
}
|
||||
@@ -215,10 +228,6 @@ public class ConfigPack extends YamlConfiguration {
|
||||
return dataFolder;
|
||||
}
|
||||
|
||||
public String getID() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public BiomeConfig getBiome(UserDefinedBiome b) {
|
||||
for(BiomeConfig biome : biomes.values()) {
|
||||
if(biome.getBiome().equals(b)) return biome;
|
||||
@@ -241,10 +250,6 @@ public class ConfigPack extends YamlConfiguration {
|
||||
throw new IllegalArgumentException("Unable to find carver!");
|
||||
}
|
||||
|
||||
public StructureConfig getStructure(String id) {
|
||||
return structures.get(id);
|
||||
}
|
||||
|
||||
public PaletteConfig getPalette(String id) {
|
||||
return palettes.get(id);
|
||||
}
|
||||
@@ -273,10 +278,6 @@ public class ConfigPack extends YamlConfiguration {
|
||||
return flora.get(id);
|
||||
}
|
||||
|
||||
public BiomeGridConfig getBiomeGrid(String id) {
|
||||
return grids.get(id);
|
||||
}
|
||||
|
||||
public TreeConfig getTree(String id) {
|
||||
return trees.get(id);
|
||||
}
|
||||
|
||||
@@ -17,8 +17,6 @@ import java.util.Objects;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class WorldConfig {
|
||||
|
||||
|
||||
private final String worldID;
|
||||
private final String configID;
|
||||
private final GaeaPlugin main;
|
||||
@@ -48,6 +46,7 @@ public class WorldConfig {
|
||||
throw new ConfigException("Config pack unspecified in bukkit.yml!", worldID);
|
||||
File configFile = new File(main.getDataFolder() + File.separator + "worlds", worldID + ".yml");
|
||||
if(!configFile.exists()) {
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
configFile.getParentFile().mkdirs();
|
||||
LangUtil.log("world-config.not-found", Level.WARNING, worldID);
|
||||
FileUtils.copyInputStreamToFile(Objects.requireNonNull(main.getResource("world.yml")), configFile);
|
||||
@@ -73,7 +72,9 @@ public class WorldConfig {
|
||||
throw new InvalidConfigurationException("2 objects share the same image channels: zone and biome-x/z");
|
||||
if (fromImage) {
|
||||
try {
|
||||
imageLoader = new ImageLoader(new File(Objects.requireNonNull(config.getString("image.file"))), ImageLoader.Align.valueOf(config.getString("image.align", "center").toUpperCase()));
|
||||
//noinspection ConstantConditions
|
||||
imageLoader = new ImageLoader(new File(config.getString("image.file")),
|
||||
ImageLoader.Align.valueOf(config.getString("image.align", "center").toUpperCase()));
|
||||
LangUtil.log("world-config.using-image", Level.INFO, worldID);
|
||||
} catch(IOException | NullPointerException e) {
|
||||
e.printStackTrace();
|
||||
@@ -83,7 +84,7 @@ public class WorldConfig {
|
||||
} catch(IllegalArgumentException | NullPointerException e) {
|
||||
throw new InvalidConfigurationException(e.getCause());
|
||||
}
|
||||
Bukkit.getLogger().info("Loaded " + tConfig.biomeList.size() + " BiomeGrids from list.");
|
||||
Bukkit.getLogger().log(Level.INFO, "Loaded {0} BiomeGrids from list.", tConfig.biomeList.size());
|
||||
} catch(IOException | InvalidConfigurationException e) {
|
||||
e.printStackTrace();
|
||||
LangUtil.log("world-config.error", Level.SEVERE, worldID);
|
||||
|
||||
@@ -46,30 +46,29 @@ public class BiomeGridConfig extends TerraConfig {
|
||||
}
|
||||
}
|
||||
|
||||
public int getSizeX() {
|
||||
return sizeX;
|
||||
}
|
||||
|
||||
public int getSizeZ() {
|
||||
return sizeZ;
|
||||
public String getID() {
|
||||
return gridID;
|
||||
}
|
||||
|
||||
public UserDefinedBiome[][] getBiomeGrid() {
|
||||
return gridRaw;
|
||||
}
|
||||
|
||||
public String getID() {
|
||||
return gridID;
|
||||
}
|
||||
|
||||
public UserDefinedGrid getGrid(World w, WorldConfig wc) {
|
||||
ConfigPack c = wc.getConfig();
|
||||
return new UserDefinedGrid(w, c.freq1, c.freq2, gridRaw, wc);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "BiomeGrid with ID " + getID() + ", dimensions " + getSizeX() + ":" + getSizeZ();
|
||||
}
|
||||
|
||||
public int getSizeX() {
|
||||
return sizeX;
|
||||
}
|
||||
|
||||
public int getSizeZ() {
|
||||
return sizeZ;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ public class CarverConfig extends TerraConfig {
|
||||
super(file, config);
|
||||
load(file);
|
||||
if(!contains("id")) throw new ConfigException("No ID specified for Carver!", "null");
|
||||
id = getString("id");
|
||||
id = Objects.requireNonNull(getString("id"));
|
||||
|
||||
inner = getBlocks("palette.inner.layers");
|
||||
|
||||
@@ -95,14 +95,6 @@ public class CarverConfig extends TerraConfig {
|
||||
carver = new UserDefinedCarver(height, radius, length, start, mutate, radiusMultiplier, id.hashCode(), getInt("cut.top", 0), getInt("cut.bottom", 0));
|
||||
}
|
||||
|
||||
public String getID() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public UserDefinedCarver getCarver() {
|
||||
return carver;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Map<Integer, ProbabilityCollection<BlockData>> getBlocks(String key) throws InvalidConfigurationException {
|
||||
if(!contains(key)) throw new ConfigException("Missing Carver Palette!", getID());
|
||||
@@ -123,6 +115,14 @@ public class CarverConfig extends TerraConfig {
|
||||
return result;
|
||||
}
|
||||
|
||||
public String getID() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public UserDefinedCarver getCarver() {
|
||||
return carver;
|
||||
}
|
||||
|
||||
public Map<Material, Set<Material>> getShiftedBlocks() {
|
||||
return shift;
|
||||
}
|
||||
|
||||
@@ -68,6 +68,11 @@ public class PaletteConfig extends TerraConfig {
|
||||
return p;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Palette with ID " + getID() + " with " + getPalette().getSize() + " layers, using Simplex: " + useNoise;
|
||||
}
|
||||
|
||||
public Palette<BlockData> getPalette() {
|
||||
return palette;
|
||||
}
|
||||
@@ -75,9 +80,4 @@ public class PaletteConfig extends TerraConfig {
|
||||
public String getID() {
|
||||
return paletteID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Palette with ID " + getID() + " with " + getPalette().getSize() + " layers, using Simplex: " + useNoise;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,14 +159,14 @@ public class BiomeConfig extends TerraConfig {
|
||||
}
|
||||
}
|
||||
|
||||
public UserDefinedBiome getBiome() {
|
||||
return biome;
|
||||
}
|
||||
|
||||
public String getID() {
|
||||
return biomeID;
|
||||
}
|
||||
|
||||
public UserDefinedBiome getBiome() {
|
||||
return biome;
|
||||
}
|
||||
|
||||
public BiomeOreConfig getOres() {
|
||||
return ore;
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ import com.dfsek.terra.config.base.ConfigPack;
|
||||
import com.dfsek.terra.config.base.ConfigUtil;
|
||||
import com.dfsek.terra.config.exception.ConfigException;
|
||||
import com.dfsek.terra.config.exception.NotFoundException;
|
||||
import com.dfsek.terra.population.StructurePopulator;
|
||||
import com.dfsek.terra.procgen.GridSpawn;
|
||||
import com.dfsek.terra.structure.Structure;
|
||||
import com.dfsek.terra.structure.features.Feature;
|
||||
@@ -36,8 +35,6 @@ public class StructureConfig extends TerraConfig {
|
||||
private final Map<Integer, LootTable> loot = new HashMap<>();
|
||||
private final List<Feature> features;
|
||||
|
||||
StructurePopulator.SearchType type;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public StructureConfig(File file, ConfigPack config) throws IOException, InvalidConfigurationException {
|
||||
super(file, config);
|
||||
@@ -95,15 +92,6 @@ public class StructureConfig extends TerraConfig {
|
||||
spawn = new GridSpawn(getInt("spawn.width", 500), getInt("spawn.padding", 100));
|
||||
searchStart = new Range(getInt("spawn.start.min", 72), getInt("spawn.start.max", 72));
|
||||
bound = new Range(getInt("spawn.bound.min", 48), getInt("spawn.bound.max", 72));
|
||||
try {
|
||||
type = StructurePopulator.SearchType.valueOf(getString("spawn.search", "DOWN"));
|
||||
} catch(IllegalArgumentException e) {
|
||||
throw new ConfigException("Invalid search type, " + getString("spawn.search"), getID());
|
||||
}
|
||||
}
|
||||
|
||||
public List<Feature> getFeatures() {
|
||||
return features;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -111,6 +99,10 @@ public class StructureConfig extends TerraConfig {
|
||||
return id;
|
||||
}
|
||||
|
||||
public List<Feature> getFeatures() {
|
||||
return features;
|
||||
}
|
||||
|
||||
public Structure getStructure(Random r) {
|
||||
return structure.get(r);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public abstract class TerraWorldEvent extends Event {
|
||||
private static final HandlerList HANDLERS = new HandlerList();
|
||||
private final TerraWorld world;
|
||||
|
||||
@@ -43,6 +43,7 @@ import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.logging.Level;
|
||||
|
||||
|
||||
public class TerraChunkGenerator extends GaeaChunkGenerator {
|
||||
private static final Map<World, PopulationManager> popMap = new HashMap<>();
|
||||
private final PopulationManager popMan = new PopulationManager(Terra.getInstance());
|
||||
@@ -73,6 +74,12 @@ public class TerraChunkGenerator extends GaeaChunkGenerator {
|
||||
popMap.get(c.getWorld()).checkNeighbors(c.getX(), c.getZ(), c.getWorld());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void attachProfiler(WorldProfiler p) {
|
||||
super.attachProfiler(p);
|
||||
popMan.attachProfiler(p);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChunkData generateBase(@NotNull World world, @NotNull Random random, int chunkX, int chunkZ, ChunkInterpolator interpolator) {
|
||||
if (needsLoad) load(world); // Load population data for world.
|
||||
@@ -98,7 +105,8 @@ public class TerraChunkGenerator extends GaeaChunkGenerator {
|
||||
BlockData data = b.getGenerator().getPalette(y).get(paletteLevel, cx, cz);
|
||||
chunk.setBlock(x, y, z, data);
|
||||
if(paletteLevel == 0 && slab != null && y < 255) {
|
||||
prepareBlockPart(data, chunk.getBlockData(x, y + 1, z), chunk, new Vector(x, y + 1, z), slab.getSlabs(), slab.getStairs(), slab.getSlabThreshold(), interpolator);
|
||||
prepareBlockPart(data, chunk.getBlockData(x, y + 1, z), chunk, new Vector(x, y + 1, z), slab.getSlabs(),
|
||||
slab.getStairs(), slab.getSlabThreshold(), interpolator);
|
||||
}
|
||||
paletteLevel++;
|
||||
} else if (y <= sea) {
|
||||
@@ -111,7 +119,8 @@ public class TerraChunkGenerator extends GaeaChunkGenerator {
|
||||
return chunk;
|
||||
}
|
||||
|
||||
private void prepareBlockPart(BlockData down, BlockData orig, ChunkData chunk, Vector block, Map<Material, Palette<BlockData>> slabs, Map<Material, Palette<BlockData>> stairs, double thresh, ChunkInterpolator interpolator) {
|
||||
private void prepareBlockPart(BlockData down, BlockData orig, ChunkData chunk, Vector block, Map<Material, Palette<BlockData>> slabs,
|
||||
Map<Material, Palette<BlockData>> stairs, double thresh, ChunkInterpolator interpolator) {
|
||||
if (interpolator.getNoise(block.getBlockX(), block.getBlockY() - 0.4, block.getBlockZ()) > thresh) {
|
||||
if (stairs != null) {
|
||||
Palette<BlockData> stairPalette = stairs.get(down.getMaterial());
|
||||
@@ -154,12 +163,6 @@ public class TerraChunkGenerator extends GaeaChunkGenerator {
|
||||
needsLoad = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void attachProfiler(WorldProfiler p) {
|
||||
super.attachProfiler(p);
|
||||
popMan.attachProfiler(p);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNoiseOctaves(World world) {
|
||||
return configPack.octaves;
|
||||
@@ -186,6 +189,11 @@ public class TerraChunkGenerator extends GaeaChunkGenerator {
|
||||
return Arrays.asList(new CavePopulator(), new StructurePopulator(), popMan);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isParallelCapable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldGenerateCaves() {
|
||||
return configPack.vanillaCaves;
|
||||
@@ -206,9 +214,4 @@ public class TerraChunkGenerator extends GaeaChunkGenerator {
|
||||
return configPack.vanillaStructures;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isParallelCapable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ import parsii.tokenizer.ParseException;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
|
||||
public class UserDefinedGenerator extends Generator {
|
||||
private static final Object noiseLock = new Object();
|
||||
@@ -32,13 +32,14 @@ public class UserDefinedGenerator extends Generator {
|
||||
private final boolean preventSmooth;
|
||||
|
||||
|
||||
public UserDefinedGenerator(String equation, List<Variable> v, TreeMap<Integer, Palette<BlockData>> pa, boolean preventSmooth) throws ParseException {
|
||||
public UserDefinedGenerator(String equation, List<Variable> userVariables, Map<Integer, Palette<BlockData>> paletteMap, boolean preventSmooth)
|
||||
throws ParseException {
|
||||
Parser p = new Parser();
|
||||
p.registerFunction("noise2", n2);
|
||||
p.registerFunction("noise3", n3);
|
||||
for(int y = 0; y < 256; y++) {
|
||||
Palette<BlockData> d = DataUtil.BLANK_PALETTE;
|
||||
for(Map.Entry<Integer, Palette<BlockData>> e : pa.entrySet()) {
|
||||
for(Map.Entry<Integer, Palette<BlockData>> e : paletteMap.entrySet()) {
|
||||
if (e.getKey() >= y) {
|
||||
d = e.getValue();
|
||||
break;
|
||||
|
||||
@@ -17,7 +17,7 @@ import java.io.IOException;
|
||||
public class ImageLoader {
|
||||
private final BufferedImage image;
|
||||
private final Align align;
|
||||
double inverseRoot2 = 0.7071067811865475;
|
||||
private static final double INVERSE_ROOT_2 = 0.7071067811865475;
|
||||
|
||||
public ImageLoader(File file, Align align) throws IOException {
|
||||
image = ImageIO.read(file);
|
||||
@@ -59,6 +59,20 @@ public class ImageLoader {
|
||||
return b;
|
||||
}
|
||||
|
||||
public void debug(boolean genStep, World w) {
|
||||
if (!ConfigUtil.debug) return;
|
||||
BufferedImage newImg = copyImage(image);
|
||||
if (genStep) {
|
||||
newImg = redrawStepped(image, w, align);
|
||||
}
|
||||
DebugGUI debugGUI = new DebugGUI(newImg);
|
||||
debugGUI.start();
|
||||
}
|
||||
|
||||
public double getNoiseVal(int x, int y, Channel channel) {
|
||||
return ((double) (getChannel(x, y, channel) - 128) / 128) * INVERSE_ROOT_2;
|
||||
}
|
||||
|
||||
public int getChannel(int x, int y, Channel channel) {
|
||||
int rgb;
|
||||
rgb = align.getRGB(image, x, y);
|
||||
@@ -70,7 +84,7 @@ public class ImageLoader {
|
||||
case BLUE:
|
||||
return rgb & 0xff;
|
||||
case ALPHA:
|
||||
return rgb >> 32 & 0xff;
|
||||
return rgb >> 24 & 0xff;
|
||||
default:
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
@@ -21,15 +21,15 @@ public class NoiseFunction2 implements Function {
|
||||
return cache.get(list.get(0).evaluate(), list.get(1).evaluate());
|
||||
}
|
||||
|
||||
public void setNoise(FastNoiseLite gen) {
|
||||
this.gen = gen;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNaturalFunction() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void setNoise(FastNoiseLite gen) {
|
||||
this.gen = gen;
|
||||
}
|
||||
|
||||
private final class Cache {
|
||||
private final double[] cacheX = new double[ConfigUtil.cacheSize];
|
||||
private final double[] cacheZ = new double[ConfigUtil.cacheSize];
|
||||
|
||||
@@ -19,12 +19,12 @@ public class NoiseFunction3 implements Function {
|
||||
return gen.getNoise(list.get(0).evaluate(), list.get(1).evaluate(), list.get(2).evaluate());
|
||||
}
|
||||
|
||||
public void setNoise(FastNoiseLite gen) {
|
||||
this.gen = gen;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNaturalFunction() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void setNoise(FastNoiseLite gen) {
|
||||
this.gen = gen;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,36 +30,6 @@ import java.util.Random;
|
||||
* Populates Flora and Trees
|
||||
*/
|
||||
public class FloraPopulator extends GaeaBlockPopulator {
|
||||
private static boolean doTrees(@NotNull UserDefinedBiome biome, TerraWorld world, @NotNull Random random, @NotNull Chunk chunk, int x, int z) {
|
||||
for(Block block : getValidTreeSpawnsAt(chunk, x, z, new Range(0, 254))) {
|
||||
Tree tree = biome.getDecorator().getTrees().get(random);
|
||||
Range range = world.getConfig().getBiome(biome).getTreeRange(tree);
|
||||
if(!range.isInRange(block.getY())) continue;
|
||||
try {
|
||||
Location l = block.getLocation();
|
||||
TreeGenerateEvent event = new TreeGenerateEvent(world, l, tree);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if(!event.isCancelled()) tree.plant(l, random, Terra.getInstance());
|
||||
} catch(NullPointerException ignore) {
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static int offset(Random r, int i) {
|
||||
return Math.min(Math.max(i + r.nextInt(3) - 1, 0), 15);
|
||||
}
|
||||
|
||||
public static List<Block> getValidTreeSpawnsAt(Chunk chunk, int x, int z, Range check) {
|
||||
List<Block> blocks = new ArrayList<>();
|
||||
for(int y : check) {
|
||||
if(chunk.getBlock(x, y, z).getType().isSolid() && chunk.getBlock(x, y + 1, z).getType().isAir()) {
|
||||
blocks.add(chunk.getBlock(x, y + 1, z));
|
||||
}
|
||||
}
|
||||
return blocks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void populate(@NotNull World world, @NotNull Random random, @NotNull Chunk chunk) {
|
||||
try(ProfileFuture ignored = TerraProfiler.fromWorld(world).measure("FloraTime")) {
|
||||
@@ -100,4 +70,34 @@ public class FloraPopulator extends GaeaBlockPopulator {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean doTrees(@NotNull UserDefinedBiome biome, TerraWorld world, @NotNull Random random, @NotNull Chunk chunk, int x, int z) {
|
||||
for(Block block : getValidTreeSpawnsAt(chunk, x, z, new Range(0, 254))) {
|
||||
Tree tree = biome.getDecorator().getTrees().get(random);
|
||||
Range range = world.getConfig().getBiome(biome).getTreeRange(tree);
|
||||
if (!range.isInRange(block.getY())) continue;
|
||||
try {
|
||||
Location l = block.getLocation();
|
||||
TreeGenerateEvent event = new TreeGenerateEvent(world, l, tree);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if (!event.isCancelled()) tree.plant(l, random, Terra.getInstance());
|
||||
} catch(NullPointerException ignore) {
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static List<Block> getValidTreeSpawnsAt(Chunk chunk, int x, int z, Range check) {
|
||||
List<Block> blocks = new ArrayList<>();
|
||||
for(int y : check) {
|
||||
if (chunk.getBlock(x, y, z).getType().isSolid() && chunk.getBlock(x, y + 1, z).getType().isAir()) {
|
||||
blocks.add(chunk.getBlock(x, y + 1, z));
|
||||
}
|
||||
}
|
||||
return blocks;
|
||||
}
|
||||
|
||||
private static int offset(Random r, int i) {
|
||||
return Math.min(Math.max(i + r.nextInt(3) - 1, 0), 15);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,8 +76,4 @@ public class StructurePopulator extends BlockPopulator {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum SearchType {
|
||||
UP, DOWN
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.dfsek.terra.procgen.math;
|
||||
/**
|
||||
* oh yeah
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public class Vector2 implements Cloneable {
|
||||
private double x;
|
||||
private double z;
|
||||
@@ -58,36 +59,6 @@ public class Vector2 implements Cloneable {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Divide X and Z components by a value.
|
||||
*
|
||||
* @param d Divisor
|
||||
* @return Mutated vector, for chaining.
|
||||
*/
|
||||
public Vector2 divide(double d) {
|
||||
x /= d;
|
||||
z /= d;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the squared length of this Vector
|
||||
*
|
||||
* @return squared length
|
||||
*/
|
||||
public double lengthSquared() {
|
||||
return x * x + z * z;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the length of this Vector
|
||||
*
|
||||
* @return length
|
||||
*/
|
||||
public double length() {
|
||||
return Math.sqrt(lengthSquared());
|
||||
}
|
||||
|
||||
/**
|
||||
* Add this vector to another.
|
||||
*
|
||||
@@ -122,6 +93,36 @@ public class Vector2 implements Cloneable {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Divide X and Z components by a value.
|
||||
*
|
||||
* @param d Divisor
|
||||
* @return Mutated vector, for chaining.
|
||||
*/
|
||||
public Vector2 divide(double d) {
|
||||
x /= d;
|
||||
z /= d;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the length of this Vector
|
||||
*
|
||||
* @return length
|
||||
*/
|
||||
public double length() {
|
||||
return Math.sqrt(lengthSquared());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the squared length of this Vector
|
||||
*
|
||||
* @return squared length
|
||||
*/
|
||||
public double lengthSquared() {
|
||||
return x * x + z * z;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the distance from this vector to another.
|
||||
*
|
||||
@@ -162,8 +163,12 @@ public class Vector2 implements Cloneable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "(" + x + ", " + z + ")";
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof Vector2)) {
|
||||
return false;
|
||||
}
|
||||
Vector2 other = (Vector2) obj;
|
||||
return other.x == this.x && other.z == this.z;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -174,4 +179,9 @@ public class Vector2 implements Cloneable {
|
||||
throw new Error(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "(" + x + ", " + z + ")";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.dfsek.terra.procgen.math.Vector2;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public abstract class Polygon {
|
||||
public abstract Set<Vector2> getContainedPixels();
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.dfsek.terra.procgen.math.Vector2;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class Rectangle extends Polygon {
|
||||
private final Vector2 min;
|
||||
private final Vector2 max;
|
||||
|
||||
@@ -6,7 +6,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class VoxelGeometry {
|
||||
public List<Vector> geometry = new ArrayList<>();
|
||||
private final List<Vector> geometry = new ArrayList<>();
|
||||
|
||||
public static VoxelGeometry getBlank() {
|
||||
return new VoxelGeometry() {
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.dfsek.terra.structure;
|
||||
import org.bukkit.Location;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class InitializationException extends Exception {
|
||||
private final Location worldLoc;
|
||||
|
||||
|
||||
@@ -38,8 +38,9 @@ import java.util.function.Consumer;
|
||||
|
||||
import static com.dfsek.terra.util.structure.RotationUtil.*;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class Structure implements Serializable {
|
||||
public static final long serialVersionUID = -6664585217063842035L;
|
||||
private static final long serialVersionUID = -6664585217063842035L;
|
||||
private final StructureContainedBlock[][][] structure;
|
||||
private final StructureInfo structureInfo;
|
||||
private final String id;
|
||||
@@ -150,22 +151,6 @@ public class Structure implements Serializable {
|
||||
return (Structure) o;
|
||||
}
|
||||
|
||||
private static void toFile(@NotNull Serializable o, @NotNull File f) throws IOException {
|
||||
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(f));
|
||||
oos.writeObject(o);
|
||||
oos.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get GaeaStructureInfo object
|
||||
*
|
||||
* @return Structure Info
|
||||
*/
|
||||
@NotNull
|
||||
public StructureInfo getStructureInfo() {
|
||||
return structureInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Paste the structure at a Location, ignoring chunk boundaries.
|
||||
*
|
||||
@@ -208,6 +193,48 @@ public class Structure implements Serializable {
|
||||
Debug.info(intersectX.toString() + " : " + intersectZ.toString());
|
||||
}
|
||||
|
||||
public boolean checkSpawns(Location origin, Rotation r) {
|
||||
for(StructureContainedBlock b : spawns) {
|
||||
Vector2 rot = getRotatedCoords(new Vector2(b.getX() - structureInfo.getCenterX(), b.getZ() - structureInfo.getCenterZ()), r);
|
||||
if (!b.getRequirement().matches(origin.getWorld(), (int) rot.getX() + origin.getBlockX(), origin.getBlockY() + b.getY(), (int) rot.getZ() + origin.getBlockZ()))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public HashSet<StructureContainedInventory> getInventories() {
|
||||
return inventories;
|
||||
}
|
||||
|
||||
/**
|
||||
* Paste structure at an origin location, confined to a single chunk.
|
||||
*
|
||||
* @param origin Origin location
|
||||
* @param chunk Chunk to confine pasting to
|
||||
* @param r Rotation
|
||||
*/
|
||||
public void paste(Location origin, Chunk chunk, Rotation r) {
|
||||
int xOr = (chunk.getX() << 4);
|
||||
int zOr = (chunk.getZ() << 4);
|
||||
Range intersectX = new Range(xOr, xOr + 16).sub(origin.getBlockX() - structureInfo.getCenterX());
|
||||
Range intersectZ = new Range(zOr, zOr + 16).sub(origin.getBlockZ() - structureInfo.getCenterZ());
|
||||
if (intersectX == null || intersectZ == null) return;
|
||||
executeForBlocksInRange(intersectX, getRange(Axis.Y, r), intersectZ, block -> pasteBlock(block, origin, r), r);
|
||||
Debug.info(intersectX.toString() + " : " + intersectZ.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test whether a set of coordinates is within the current structure
|
||||
*
|
||||
* @param x X coordinate
|
||||
* @param y Y coordinate
|
||||
* @param z Z coordinate
|
||||
* @return True if coordinate set is in structure, false if it is not.
|
||||
*/
|
||||
private boolean isInStructure(int x, int y, int z) {
|
||||
return x < structureInfo.getSizeX() && y < structureInfo.getSizeY() && z < structureInfo.getSizeZ() && x >= 0 && y >= 0 && z >= 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Paste a single StructureDefinedBlock at an origin location, offset by its coordinates.
|
||||
*
|
||||
@@ -279,6 +306,20 @@ public class Structure implements Serializable {
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Range getRawRange(@NotNull Axis a) {
|
||||
switch(a) {
|
||||
case X:
|
||||
return new Range(0, structureInfo.getSizeX());
|
||||
case Y:
|
||||
return new Range(0, structureInfo.getSizeY());
|
||||
case Z:
|
||||
return new Range(0, structureInfo.getSizeZ());
|
||||
default:
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute a Consumer for all blocks in a cuboid region defined by 3 Ranges, accounting for rotation.
|
||||
*
|
||||
@@ -304,15 +345,28 @@ public class Structure implements Serializable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Test whether a set of coordinates is within the current structure
|
||||
* Get GaeaStructureInfo object
|
||||
*
|
||||
* @param x X coordinate
|
||||
* @param y Y coordinate
|
||||
* @param z Z coordinate
|
||||
* @return True if coordinate set is in structure, false if it is not.
|
||||
* @return Structure Info
|
||||
*/
|
||||
private boolean isInStructure(int x, int y, int z) {
|
||||
return x < structureInfo.getSizeX() && y < structureInfo.getSizeY() && z < structureInfo.getSizeZ() && x >= 0 && y >= 0 && z >= 0;
|
||||
@NotNull
|
||||
public StructureInfo getStructureInfo() {
|
||||
return structureInfo;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Range getRange(@NotNull Axis a, @NotNull Rotation r) {
|
||||
if (a.equals(Axis.Y)) return getRawRange(a);
|
||||
Vector2 center = new Vector2(structureInfo.getCenterX(), structureInfo.getCenterZ());
|
||||
Range x = getRawRange(Axis.X);
|
||||
Range z = getRawRange(Axis.Z);
|
||||
Vector2 min = getRotatedCoords(new Vector2(x.getMin(), z.getMin()).subtract(center), r.inverse()).add(center);
|
||||
Vector2 max = getRotatedCoords(new Vector2(x.getMax(), z.getMax()).subtract(center), r.inverse()).add(center);
|
||||
|
||||
if (a.equals(Axis.X))
|
||||
return new Range((int) Math.floor(Math.min(min.getX(), max.getX())), (int) Math.ceil(Math.max(min.getX(), max.getX())) + 1);
|
||||
else
|
||||
return new Range((int) Math.floor(Math.min(min.getZ(), max.getZ())), (int) Math.ceil(Math.max(min.getZ(), max.getZ())) + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -335,6 +389,12 @@ public class Structure implements Serializable {
|
||||
toFile(this, f);
|
||||
}
|
||||
|
||||
private static void toFile(@NotNull Serializable o, @NotNull File f) throws IOException {
|
||||
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(f));
|
||||
oos.writeObject(o);
|
||||
oos.close();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getId() {
|
||||
return id;
|
||||
@@ -345,35 +405,6 @@ public class Structure implements Serializable {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Range getRange(@NotNull Axis a, @NotNull Rotation r) {
|
||||
if(a.equals(Axis.Y)) return getRawRange(a);
|
||||
Vector2 center = new Vector2(structureInfo.getCenterX(), structureInfo.getCenterZ());
|
||||
Range x = getRawRange(Axis.X);
|
||||
Range z = getRawRange(Axis.Z);
|
||||
Vector2 min = getRotatedCoords(new Vector2(x.getMin(), z.getMin()).subtract(center), r.inverse()).add(center);
|
||||
Vector2 max = getRotatedCoords(new Vector2(x.getMax(), z.getMax()).subtract(center), r.inverse()).add(center);
|
||||
|
||||
if(a.equals(Axis.X))
|
||||
return new Range((int) Math.floor(Math.min(min.getX(), max.getX())), (int) Math.ceil(Math.max(min.getX(), max.getX())) + 1);
|
||||
else
|
||||
return new Range((int) Math.floor(Math.min(min.getZ(), max.getZ())), (int) Math.ceil(Math.max(min.getZ(), max.getZ())) + 1);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Range getRawRange(@NotNull Axis a) {
|
||||
switch(a) {
|
||||
case X:
|
||||
return new Range(0, structureInfo.getSizeX());
|
||||
case Y:
|
||||
return new Range(0, structureInfo.getSizeY());
|
||||
case Z:
|
||||
return new Range(0, structureInfo.getSizeZ());
|
||||
default:
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
}
|
||||
|
||||
public enum Axis {
|
||||
X, Y, Z
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ import org.bukkit.block.data.BlockData;
|
||||
import java.io.Serializable;
|
||||
|
||||
public class StructureContainedBlock implements Serializable {
|
||||
public static final long serialVersionUID = 6143969483382710947L;
|
||||
private static final long serialVersionUID = 6143969483382710947L;
|
||||
private final SerializableBlockData bl;
|
||||
private final Pull pull;
|
||||
private final int pullOffset;
|
||||
|
||||
@@ -6,7 +6,7 @@ import org.bukkit.inventory.ItemStack;
|
||||
import java.io.Serializable;
|
||||
|
||||
public class StructureContainedInventory implements Serializable {
|
||||
public static final long serialVersionUID = -175339605585943678L;
|
||||
private static final long serialVersionUID = -175339605585943678L;
|
||||
private final int uid;
|
||||
private final int x, y, z;
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import com.dfsek.terra.procgen.math.Vector2;
|
||||
import java.io.Serializable;
|
||||
|
||||
public class StructureInfo implements Serializable {
|
||||
public static final long serialVersionUID = -175639605885943678L;
|
||||
private static final long serialVersionUID = -175639605885943678L;
|
||||
private final int sizeX;
|
||||
private final int sizeY;
|
||||
private final int sizeZ;
|
||||
|
||||
@@ -49,14 +49,6 @@ public enum StructureSpawnRequirement implements Serializable {
|
||||
private static final long serialVersionUID = -175639605885943679L;
|
||||
private static final transient Map<World, FastNoiseLite> noiseMap = new HashMap<>();
|
||||
|
||||
public static void putNoise(World w, FastNoiseLite noise) {
|
||||
noiseMap.putIfAbsent(w, noise);
|
||||
}
|
||||
|
||||
private static FastNoiseLite getNoise(World w) {
|
||||
return noiseMap.get(w);
|
||||
}
|
||||
|
||||
private static void setNoise(World w, int x, int y, int z) {
|
||||
TerraWorld tw = TerraWorld.getWorld(w);
|
||||
ConfigPack wc = tw.getConfig();
|
||||
@@ -70,5 +62,13 @@ public enum StructureSpawnRequirement implements Serializable {
|
||||
}
|
||||
}
|
||||
|
||||
public static void putNoise(World w, FastNoiseLite noise) {
|
||||
noiseMap.putIfAbsent(w, noise);
|
||||
}
|
||||
|
||||
private static FastNoiseLite getNoise(World w) {
|
||||
return noiseMap.get(w);
|
||||
}
|
||||
|
||||
public abstract boolean matches(World w, int x, int y, int z);
|
||||
}
|
||||
|
||||
@@ -32,10 +32,6 @@ public class EntityFeature implements Feature {
|
||||
this.inSize = inSize;
|
||||
}
|
||||
|
||||
private static boolean isInChunk(Chunk c, Location l) {
|
||||
return Math.floorDiv(l.getBlockX(), 16) == c.getX() && Math.floorDiv(l.getBlockZ(), 16) == c.getZ();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(Structure structure, Location l, Chunk chunk) {
|
||||
Random random = new Random(MathUtil.getCarverChunkSeed(chunk.getX(), chunk.getZ(), chunk.getWorld().getSeed()));
|
||||
@@ -76,6 +72,10 @@ public class EntityFeature implements Feature {
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isInChunk(Chunk c, Location l) {
|
||||
return Math.floorDiv(l.getBlockX(), 16) == c.getX() && Math.floorDiv(l.getBlockZ(), 16) == c.getZ();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(Structure structure, Location l, Random random) {
|
||||
int amountSpawn = amount.get(random);
|
||||
@@ -112,8 +112,4 @@ public class EntityFeature implements Feature {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class SpawnRule {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import org.bukkit.block.data.BlockData;
|
||||
import java.io.Serializable;
|
||||
|
||||
public class SerializableBlockData implements Serializable {
|
||||
public static final long serialVersionUID = 5298928608478640008L;
|
||||
private static final long serialVersionUID = 5298928608478640008L;
|
||||
private final String data;
|
||||
|
||||
public SerializableBlockData(BlockData d) {
|
||||
|
||||
@@ -9,7 +9,7 @@ import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class SerializableBanner implements SerializableBlockState {
|
||||
public static final long serialVersionUID = 5298928608478640004L;
|
||||
private static final long serialVersionUID = 5298928608478640004L;
|
||||
private final DyeColor base;
|
||||
private final ArrayList<Pattern> patterns = new ArrayList<>();
|
||||
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ import org.bukkit.block.CreatureSpawner;
|
||||
import org.bukkit.entity.EntityType;
|
||||
|
||||
public class SerializableMonsterCage implements SerializableBlockState {
|
||||
public static final long serialVersionUID = 529892860847864007L;
|
||||
private static final long serialVersionUID = 529892860847864007L;
|
||||
private final EntityType type;
|
||||
private final int minDelay;
|
||||
private final int maxDelay;
|
||||
|
||||
@@ -4,7 +4,7 @@ import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.Sign;
|
||||
|
||||
public class SerializableSign implements SerializableBlockState {
|
||||
public static final long serialVersionUID = 5298928608478640001L;
|
||||
private static final long serialVersionUID = 5298928608478640001L;
|
||||
private final String[] text;
|
||||
private final boolean isEditable;
|
||||
|
||||
|
||||
@@ -5,10 +5,14 @@ import org.bukkit.StructureType;
|
||||
/**
|
||||
* Enum to represent StructureType, which is a class for some reason.
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public enum StructureTypeEnum {
|
||||
MINESHAFT(StructureType.MINESHAFT),
|
||||
VILLAGE(StructureType.VILLAGE),
|
||||
NETHER_FORTRESS(StructureType.NETHER_FORTRESS),
|
||||
/**
|
||||
* Currently the only one used.
|
||||
*/
|
||||
STRONGHOLD(StructureType.STRONGHOLD),
|
||||
JUNGLE_PYRAMID(StructureType.JUNGLE_PYRAMID),
|
||||
OCEAN_RUIN(StructureType.OCEAN_RUIN),
|
||||
|
||||
@@ -46,6 +46,96 @@ public final class RotationUtil {
|
||||
return n;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an integer representation of a BlockFace, to perform math on.
|
||||
*
|
||||
* @param f BlockFace to get integer for
|
||||
* @return integer representation of BlockFace
|
||||
*/
|
||||
public static int faceRotation(BlockFace f) {
|
||||
switch(f) {
|
||||
case NORTH:
|
||||
return 0;
|
||||
case NORTH_NORTH_EAST:
|
||||
return 1;
|
||||
case NORTH_EAST:
|
||||
return 2;
|
||||
case EAST_NORTH_EAST:
|
||||
return 3;
|
||||
case EAST:
|
||||
return 4;
|
||||
case EAST_SOUTH_EAST:
|
||||
return 5;
|
||||
case SOUTH_EAST:
|
||||
return 6;
|
||||
case SOUTH_SOUTH_EAST:
|
||||
return 7;
|
||||
case SOUTH:
|
||||
return 8;
|
||||
case SOUTH_SOUTH_WEST:
|
||||
return 9;
|
||||
case SOUTH_WEST:
|
||||
return 10;
|
||||
case WEST_SOUTH_WEST:
|
||||
return 11;
|
||||
case WEST:
|
||||
return 12;
|
||||
case WEST_NORTH_WEST:
|
||||
return 13;
|
||||
case NORTH_WEST:
|
||||
return 14;
|
||||
case NORTH_NORTH_WEST:
|
||||
return 15;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert integer to BlockFace representation
|
||||
*
|
||||
* @param r integer to get BlockFace for
|
||||
* @return BlockFace represented by integer.
|
||||
*/
|
||||
public static BlockFace fromRotation(int r) {
|
||||
switch(Math.floorMod(r, 16)) {
|
||||
case 0:
|
||||
return BlockFace.NORTH;
|
||||
case 1:
|
||||
return BlockFace.NORTH_NORTH_EAST;
|
||||
case 2:
|
||||
return BlockFace.NORTH_EAST;
|
||||
case 3:
|
||||
return BlockFace.EAST_NORTH_EAST;
|
||||
case 4:
|
||||
return BlockFace.EAST;
|
||||
case 5:
|
||||
return BlockFace.EAST_SOUTH_EAST;
|
||||
case 6:
|
||||
return BlockFace.SOUTH_EAST;
|
||||
case 7:
|
||||
return BlockFace.SOUTH_SOUTH_EAST;
|
||||
case 8:
|
||||
return BlockFace.SOUTH;
|
||||
case 9:
|
||||
return BlockFace.SOUTH_SOUTH_WEST;
|
||||
case 10:
|
||||
return BlockFace.SOUTH_WEST;
|
||||
case 11:
|
||||
return BlockFace.WEST_SOUTH_WEST;
|
||||
case 12:
|
||||
return BlockFace.WEST;
|
||||
case 13:
|
||||
return BlockFace.WEST_NORTH_WEST;
|
||||
case 14:
|
||||
return BlockFace.NORTH_WEST;
|
||||
case 15:
|
||||
return BlockFace.NORTH_NORTH_WEST;
|
||||
default:
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
}
|
||||
|
||||
public static org.bukkit.Axis getRotatedAxis(org.bukkit.Axis orig, Structure.Rotation r) {
|
||||
org.bukkit.Axis other = orig;
|
||||
final boolean shouldSwitch = r.equals(Structure.Rotation.CW_90) || r.equals(Structure.Rotation.CCW_90);
|
||||
@@ -60,7 +150,6 @@ public final class RotationUtil {
|
||||
return other;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Method to rotate the incredibly obnoxious Rail.Shape enum
|
||||
*
|
||||
|
||||
@@ -12,13 +12,6 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public final class WorldEditUtil {
|
||||
public static WorldEditPlugin getWorldEdit() {
|
||||
Plugin p = Bukkit.getServer().getPluginManager().getPlugin("WorldEdit");
|
||||
if(p instanceof WorldEditPlugin) return (WorldEditPlugin) p;
|
||||
Bukkit.getLogger().severe("[Terra] a command requiring WorldEdit was executed, but WorldEdit was not detected!");
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Location[] getSelectionLocations(Player sender) {
|
||||
WorldEditPlugin we = WorldEditUtil.getWorldEdit();
|
||||
if(we == null) {
|
||||
@@ -43,6 +36,13 @@ public final class WorldEditUtil {
|
||||
return new Location[] {l1, l2};
|
||||
}
|
||||
|
||||
public static WorldEditPlugin getWorldEdit() {
|
||||
Plugin p = Bukkit.getServer().getPluginManager().getPlugin("WorldEdit");
|
||||
if (p instanceof WorldEditPlugin) return (WorldEditPlugin) p;
|
||||
Bukkit.getLogger().severe("[Terra] a command requiring WorldEdit was executed, but WorldEdit was not detected!");
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Location[] getSelectionPositions(Player sender) {
|
||||
WorldEditPlugin we = WorldEditUtil.getWorldEdit();
|
||||
if (we == null) {
|
||||
|
||||
@@ -16,7 +16,7 @@ command:
|
||||
- "--------------------Terra--------------------"
|
||||
- "Herlaai - Herlaai konfigurasiedata"
|
||||
- "bioom - Kry huidige bioom"
|
||||
- "erts - Genereer 'n ertsader op die plek waar u te staan kom (vir foutopsporing)"
|
||||
- "erts - Genereer 'n ertsader op die plek waar u te staan kom (vir foutopsporing)"
|
||||
- "stoor-data - Stoor bevolkingsdata"
|
||||
- "struktuur - Laai en stoor strukture"
|
||||
- "profiel - Profielopsies"
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -1,13 +1,15 @@
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.polydev.gaea.math.FastNoiseLite;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class LookupGenerator {
|
||||
class LookupGenerator {
|
||||
private static double[] lookup;
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
@Test
|
||||
static void main(String[] args) throws InterruptedException {
|
||||
int dist = 4096;
|
||||
|
||||
List<Double> vals = new ArrayList<>();
|
||||
@@ -63,7 +65,7 @@ public class LookupGenerator {
|
||||
int current = vals.size() / dist;
|
||||
System.out.println(i + ", max: " + vals.get(current * (i + 1) - 1));
|
||||
lookup[i] = vals.get(current * (i + 1) - 1);
|
||||
s.append(vals.get(current * (i + 1) - 1) + "D, ");
|
||||
s.append(vals.get(current * (i + 1) - 1)).append("D, ");
|
||||
}
|
||||
s.delete(s.length() - 2, s.length());
|
||||
s.append("}");
|
||||
@@ -89,17 +91,23 @@ public class LookupGenerator {
|
||||
|
||||
}
|
||||
|
||||
public static int normalizeNew(double d) {
|
||||
for(int i = 0; i < lookup.length; i++) {
|
||||
if (d < lookup[i]) return i;
|
||||
}
|
||||
return lookup.length - 1;
|
||||
}
|
||||
|
||||
public static int normalize(double i, int n) {
|
||||
i *= 1.42; // Magic simplex value (sqrt(2) plus a little)
|
||||
i = Math.min(Math.max(i, -1), 1);
|
||||
return Math.min((int) Math.floor((i + 1) * ((double) n / 2)), n - 1);
|
||||
}
|
||||
|
||||
public static int normalizeNew(double d) {
|
||||
for(int i = 0; i < lookup.length; i++) {
|
||||
if(d < lookup[i]) return i;
|
||||
}
|
||||
return lookup.length - 1;
|
||||
public static int normalize(double i, int n) {
|
||||
i *= 1.42; // Magic simplex value (sqrt(2) plus a little)
|
||||
i = Math.min(Math.max(i, -1), 1);
|
||||
return Math.min((int) Math.floor((i + 1) * ((double) n / 2)), n - 1);
|
||||
}
|
||||
|
||||
private static class Worker extends Thread {
|
||||
|
||||
Reference in New Issue
Block a user