mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2025-07-18 10:32:30 +00:00
commit
b1a954b433
@ -340,7 +340,7 @@ ij_json_wrap_long_lines = false
|
||||
|
||||
[{*.yaml,*.yml}]
|
||||
indent_size = 2
|
||||
ij_yaml_keep_indents_on_empty_lines = false
|
||||
ij_yaml_keep_indents_on_empty_lines = true
|
||||
ij_yaml_keep_line_breaks = true
|
||||
ij_yaml_space_before_colon = true
|
||||
ij_yaml_spaces_within_braces = true
|
||||
|
2
.gitignore
vendored
2
.gitignore
vendored
@ -134,3 +134,5 @@ build
|
||||
.idea/codeStyles/**
|
||||
.idea/**.xml
|
||||
.idea/modules/**.iml
|
||||
|
||||
!lib/*.jar
|
13
.idea/inspectionProfiles/Project_Default.xml
generated
13
.idea/inspectionProfiles/Project_Default.xml
generated
@ -6,5 +6,18 @@
|
||||
<language minSize="54" name="Java" />
|
||||
</Languages>
|
||||
</inspection_tool>
|
||||
<inspection_tool class="NonSerializableObjectPassedToObjectStream" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="SerialVersionUIDNotStaticFinal" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="SerializableHasSerialVersionUIDField" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<option name="ignoreAnonymousInnerClasses" value="false" />
|
||||
<option name="superClassString" value="java.awt.Component" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="SerializableInnerClassHasSerialVersionUIDField" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<option name="ignoreAnonymousInnerClasses" value="false" />
|
||||
<option name="superClassString" value="java.awt.Component" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="SerializableStoresNonSerializable" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="TransientFieldInNonSerializableClass" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="TransientFieldNotInitialized" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
</profile>
|
||||
</component>
|
3
.idea/misc.xml
generated
3
.idea/misc.xml
generated
@ -1,6 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="EntryPointsManager">
|
||||
<entry_points version="2.0">
|
||||
<entry_point TYPE="field" FQNAME="com.dfsek.terra.util.StructureTypeEnum NETHER_FORTRESS" />
|
||||
</entry_points>
|
||||
<list size="1">
|
||||
<item index="0" class="java.lang.String" itemvalue="org.bukkit.event.EventHandler" />
|
||||
</list>
|
||||
|
17
Terra.iml
Normal file
17
Terra.iml
Normal file
@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module version="4">
|
||||
<component name="CheckStyle-IDEA-Module">
|
||||
<option name="configuration">
|
||||
<map />
|
||||
</option>
|
||||
</component>
|
||||
<component name="FacetManager">
|
||||
<facet type="minecraft" name="Minecraft">
|
||||
<configuration>
|
||||
<autoDetectTypes>
|
||||
<platformType>SPIGOT</platformType>
|
||||
</autoDetectTypes>
|
||||
</configuration>
|
||||
</facet>
|
||||
</component>
|
||||
</module>
|
@ -44,6 +44,16 @@ 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 = "")
|
||||
}
|
||||
|
||||
val compileJava: JavaCompile by tasks
|
||||
compileJava.apply {
|
||||
options.encoding = "UTF-8"
|
||||
doFirst {
|
||||
options.compilerArgs = mutableListOf("-Xlint:all", "-Xlint:-processing")
|
||||
}
|
||||
}
|
||||
|
||||
tasks.test {
|
||||
@ -92,6 +102,7 @@ val setupServer = tasks.create("setupServer") {
|
||||
}
|
||||
|
||||
val testWithPaper = task<JavaExec>(name = "testWithPaper") {
|
||||
standardInput = System.`in`
|
||||
dependsOn(tasks.shadowJar)
|
||||
// Copy Terra into dir
|
||||
doFirst {
|
||||
@ -103,13 +114,13 @@ val testWithPaper = task<JavaExec>(name = "testWithPaper") {
|
||||
|
||||
main = "io.papermc.paperclip.Paperclip"
|
||||
jvmArgs = listOf("-XX:+UseG1GC", "-XX:+ParallelRefProcEnabled", "-XX:MaxGCPauseMillis=200",
|
||||
"-XX:+UnlockExperimentalVMOptions", "-XX:+DisableExplicitGC", "-XX:+AlwaysPreTouch",
|
||||
"-XX:G1NewSizePercent=30", "-XX:G1MaxNewSizePercent=40", "-XX:G1HeapRegionSize=8M",
|
||||
"-XX:G1ReservePercent=20", "-XX:G1HeapWastePercent=5", "-XX:G1MixedGCCountTarget=4",
|
||||
"-XX:InitiatingHeapOccupancyPercent=15", "-XX:G1MixedGCLiveThresholdPercent=90",
|
||||
"-XX:G1RSetUpdatingPauseTimePercent=5", "-XX:SurvivorRatio=32", "-XX:+PerfDisableSharedMem",
|
||||
"-XX:MaxTenuringThreshold=1", "-Dusing.aikars.flags=https://mcflags.emc.gs",
|
||||
"-Daikars.new.flags=true")
|
||||
"-XX:+UnlockExperimentalVMOptions", "-XX:+DisableExplicitGC", "-XX:+AlwaysPreTouch",
|
||||
"-XX:G1NewSizePercent=30", "-XX:G1MaxNewSizePercent=40", "-XX:G1HeapRegionSize=8M",
|
||||
"-XX:G1ReservePercent=20", "-XX:G1HeapWastePercent=5", "-XX:G1MixedGCCountTarget=4",
|
||||
"-XX:InitiatingHeapOccupancyPercent=15", "-XX:G1MixedGCLiveThresholdPercent=90",
|
||||
"-XX:G1RSetUpdatingPauseTimePercent=5", "-XX:SurvivorRatio=32", "-XX:+PerfDisableSharedMem",
|
||||
"-XX:MaxTenuringThreshold=1", "-Dusing.aikars.flags=https://mcflags.emc.gs",
|
||||
"-Daikars.new.flags=true")
|
||||
maxHeapSize = "2G"
|
||||
workingDir = file("${testDir}/")
|
||||
classpath = files("${testDir}/paper.jar")
|
||||
@ -137,6 +148,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<>();
|
||||
@ -34,6 +35,7 @@ public class Terra extends GaeaPlugin {
|
||||
TerraChunkGenerator.saveAll();
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public void onEnable() {
|
||||
instance = 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));
|
||||
|
@ -158,9 +158,26 @@ public class ConfigPack extends YamlConfiguration {
|
||||
LangUtil.log("config-pack.loaded", Level.INFO, getID(), String.valueOf((System.nanoTime() - l) / 1000000D));
|
||||
}
|
||||
|
||||
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 void loadAll(JavaPlugin main) {
|
||||
configs.clear();
|
||||
File file = new File(main.getDataFolder(), "packs");
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
file.mkdirs();
|
||||
List<Path> subfolder;
|
||||
try {
|
||||
@ -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);
|
||||
|
@ -6,6 +6,7 @@ import org.bukkit.configuration.InvalidConfigurationException;
|
||||
* Thrown when a config item is not valid.
|
||||
*/
|
||||
public class ConfigException extends InvalidConfigurationException {
|
||||
private static final long serialVersionUID = -4342864317005935979L;
|
||||
private final String message;
|
||||
private final String id;
|
||||
|
||||
|
@ -4,6 +4,8 @@ package com.dfsek.terra.config.exception;
|
||||
* Thrown when a required config item is not found.
|
||||
*/
|
||||
public class NotFoundException extends ConfigException {
|
||||
private static final long serialVersionUID = -3763471113262357426L;
|
||||
|
||||
public NotFoundException(String item, String itemName, String id) {
|
||||
super(item + " \"" + itemName + "\" cannot be found!", id);
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -61,8 +61,8 @@ public class OreConfig extends TerraConfig {
|
||||
}
|
||||
}
|
||||
|
||||
private int randomInRange(Random r) {
|
||||
return r.nextInt(max - min + 1) + min;
|
||||
public String getID() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void doVein(Vector l, Chunk chunk, Random r) {
|
||||
@ -91,6 +91,10 @@ public class OreConfig extends TerraConfig {
|
||||
}
|
||||
}
|
||||
|
||||
private int randomInRange(Random r) {
|
||||
return r.nextInt(max - min + 1) + min;
|
||||
}
|
||||
|
||||
public void doVeinSingle(Vector l, Chunk chunk, Random r) {
|
||||
FastNoiseLite ore = new FastNoiseLite(r.nextInt());
|
||||
ore.setNoiseType(FastNoiseLite.NoiseType.OpenSimplex2);
|
||||
@ -117,10 +121,6 @@ public class OreConfig extends TerraConfig {
|
||||
return "Ore with ID " + getID();
|
||||
}
|
||||
|
||||
public String getID() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public boolean crossChunks() {
|
||||
return crossChunks;
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ import java.awt.event.ActionListener;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
public class DebugFrame extends JFrame implements ActionListener {
|
||||
private static final long serialVersionUID = 9133084939622854303L;
|
||||
private final int x;
|
||||
private final int z;
|
||||
private final BufferedImage img;
|
||||
|
@ -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();
|
||||
@ -25,20 +25,21 @@ public class UserDefinedGenerator extends Generator {
|
||||
private final Variable xVar = s.getVariable("x");
|
||||
private final Variable yVar = s.getVariable("y");
|
||||
private final Variable zVar = s.getVariable("z");
|
||||
@SuppressWarnings("unchecked")
|
||||
@SuppressWarnings({"unchecked", "rawtypes", "RedundantSuppression"})
|
||||
private final Palette<BlockData>[] palettes = new Palette[256];
|
||||
private final NoiseFunction2 n2 = new NoiseFunction2();
|
||||
private final NoiseFunction3 n3 = new NoiseFunction3();
|
||||
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;
|
||||
|
@ -15,9 +15,9 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public class ImageLoader {
|
||||
private static final double INVERSE_ROOT_2 = 0.7071067811865475;
|
||||
private final BufferedImage image;
|
||||
private final Align align;
|
||||
double inverseRoot2 = 0.7071067811865475;
|
||||
|
||||
public ImageLoader(File file, Align align) throws IOException {
|
||||
image = ImageIO.read(file);
|
||||
@ -59,23 +59,6 @@ public class ImageLoader {
|
||||
return b;
|
||||
}
|
||||
|
||||
public int getChannel(int x, int y, Channel channel) {
|
||||
int rgb;
|
||||
rgb = align.getRGB(image, x, y);
|
||||
switch(channel) {
|
||||
case RED:
|
||||
return rgb >> 16 & 0xff;
|
||||
case GREEN:
|
||||
return rgb >> 8 & 0xff;
|
||||
case BLUE:
|
||||
return rgb & 0xff;
|
||||
case ALPHA:
|
||||
return rgb >> 32 & 0xff;
|
||||
default:
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
}
|
||||
|
||||
public void debug(boolean genStep, World w) {
|
||||
if(!ConfigUtil.debug) return;
|
||||
BufferedImage newImg = copyImage(image);
|
||||
@ -87,7 +70,24 @@ public class ImageLoader {
|
||||
}
|
||||
|
||||
public double getNoiseVal(int x, int y, Channel channel) {
|
||||
return ((double) (getChannel(x, y, channel) - 128) / 128) * inverseRoot2;
|
||||
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);
|
||||
switch(channel) {
|
||||
case RED:
|
||||
return rgb >> 16 & 0xff;
|
||||
case GREEN:
|
||||
return rgb >> 8 & 0xff;
|
||||
case BLUE:
|
||||
return rgb & 0xff;
|
||||
case ALPHA:
|
||||
return rgb >> 24 & 0xff;
|
||||
default:
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
}
|
||||
|
||||
public Align getAlign() {
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -28,6 +28,7 @@ public class CavePopulator extends BlockPopulator {
|
||||
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();
|
||||
|
||||
@SuppressWarnings("try")
|
||||
@Override
|
||||
public void populate(@NotNull World world, @NotNull Random random, @NotNull Chunk chunk) {
|
||||
if(ConfigUtil.masterDisableCaves) return;
|
||||
|
@ -30,36 +30,7 @@ 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;
|
||||
}
|
||||
|
||||
@SuppressWarnings("try")
|
||||
@Override
|
||||
public void populate(@NotNull World world, @NotNull Random random, @NotNull Chunk chunk) {
|
||||
try(ProfileFuture ignored = TerraProfiler.fromWorld(world).measure("FloraTime")) {
|
||||
@ -100,4 +71,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);
|
||||
}
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
public class OrePopulator extends GaeaBlockPopulator {
|
||||
@SuppressWarnings("try")
|
||||
@Override
|
||||
public void populate(@NotNull World world, @NotNull Random random, @NotNull Chunk chunk) {
|
||||
try(ProfileFuture ignored = TerraProfiler.fromWorld(world).measure("OreTime")) {
|
||||
|
@ -44,6 +44,7 @@ public class SnowPopulator extends GaeaBlockPopulator {
|
||||
Bukkit.getLogger().info("Added " + blacklistSpawn.size() + " materials to snow blacklist");
|
||||
}
|
||||
|
||||
@SuppressWarnings("try")
|
||||
@Override
|
||||
public void populate(@NotNull World world, @NotNull Random random, @NotNull Chunk chunk) {
|
||||
try(ProfileFuture ignored = TerraProfiler.fromWorld(world).measure("SnowTime")) {
|
||||
|
@ -25,6 +25,7 @@ import java.util.Random;
|
||||
|
||||
public class StructurePopulator extends BlockPopulator {
|
||||
|
||||
@SuppressWarnings("try")
|
||||
@Override
|
||||
public void populate(@NotNull World world, @NotNull Random random, @NotNull Chunk chunk) {
|
||||
try(ProfileFuture ignored = TerraProfiler.fromWorld(world).measure("StructureTime")) {
|
||||
@ -76,8 +77,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.
|
||||
*
|
||||
@ -144,15 +145,6 @@ public class Vector2 implements Cloneable {
|
||||
return dx * dx + dz * dz;
|
||||
}
|
||||
|
||||
@Override
|
||||
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
|
||||
public int hashCode() {
|
||||
int hash = 17;
|
||||
@ -162,8 +154,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 +170,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,7 +3,9 @@ package com.dfsek.terra.structure;
|
||||
import org.bukkit.Location;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class InitializationException extends Exception {
|
||||
private static final long serialVersionUID = -3817726044758088486L;
|
||||
private final Location worldLoc;
|
||||
|
||||
public InitializationException(String message, @Nullable 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.
|
||||
*
|
||||
@ -178,36 +163,6 @@ public class Structure implements Serializable {
|
||||
this.executeForBlocksInRange(xRange, getRange(Axis.Y, r), zRange, block -> pasteBlock(block, origin, r), r);
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
/**
|
||||
* Paste a single StructureDefinedBlock at an origin location, offset by its coordinates.
|
||||
*
|
||||
@ -303,6 +258,16 @@ public class Structure implements Serializable {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get GaeaStructureInfo object
|
||||
*
|
||||
* @return Structure Info
|
||||
*/
|
||||
@NotNull
|
||||
public StructureInfo getStructureInfo() {
|
||||
return structureInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test whether a set of coordinates is within the current structure
|
||||
*
|
||||
@ -315,36 +280,6 @@ public class Structure implements Serializable {
|
||||
return x < structureInfo.getSizeX() && y < structureInfo.getSizeY() && z < structureInfo.getSizeZ() && x >= 0 && y >= 0 && z >= 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* From an origin location (First bound) fetch the second bound.
|
||||
*
|
||||
* @param origin Origin location
|
||||
* @return Other bound location
|
||||
*/
|
||||
public Location getOtherBound(Location origin) {
|
||||
return origin.clone().add(structureInfo.getSizeX(), structureInfo.getSizeY(), structureInfo.getSizeZ());
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the structure to a file
|
||||
*
|
||||
* @param f File to save to
|
||||
* @throws IOException If file access error occurs
|
||||
*/
|
||||
public void save(@NotNull File f) throws IOException {
|
||||
toFile(this, f);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public UUID getUuid() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Range getRange(@NotNull Axis a, @NotNull Rotation r) {
|
||||
if(a.equals(Axis.Y)) return getRawRange(a);
|
||||
@ -374,6 +309,72 @@ public class Structure implements Serializable {
|
||||
}
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
/**
|
||||
* From an origin location (First bound) fetch the second bound.
|
||||
*
|
||||
* @param origin Origin location
|
||||
* @return Other bound location
|
||||
*/
|
||||
public Location getOtherBound(Location origin) {
|
||||
return origin.clone().add(structureInfo.getSizeX(), structureInfo.getSizeY(), structureInfo.getSizeZ());
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the structure to a file
|
||||
*
|
||||
* @param f File to save to
|
||||
* @throws IOException If file access error occurs
|
||||
*/
|
||||
public void save(@NotNull File f) throws IOException {
|
||||
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;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public UUID getUuid() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
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<>();
|
||||
|
||||
@ -32,6 +32,7 @@ public class SerializableBanner implements SerializableBlockState {
|
||||
}
|
||||
|
||||
private static final class Pattern implements Serializable {
|
||||
private static final long serialVersionUID = -7802163816361757171L;
|
||||
private final DyeColor color;
|
||||
private final PatternType type;
|
||||
|
||||
|
@ -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,103 +46,6 @@ public final class RotationUtil {
|
||||
return n;
|
||||
}
|
||||
|
||||
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);
|
||||
switch(orig) {
|
||||
case X:
|
||||
if(shouldSwitch) other = org.bukkit.Axis.Z;
|
||||
break;
|
||||
case Z:
|
||||
if(shouldSwitch) other = org.bukkit.Axis.X;
|
||||
break;
|
||||
}
|
||||
return other;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Method to rotate the incredibly obnoxious Rail.Shape enum
|
||||
*
|
||||
* @param orig Original shape
|
||||
* @param r Rotate
|
||||
* @return Rotated/mirrored shape
|
||||
*/
|
||||
public static Rail.Shape getRotatedRail(Rail.Shape orig, Structure.Rotation r) {
|
||||
switch(r) {
|
||||
case CCW_90:
|
||||
switch(orig) {
|
||||
case NORTH_WEST:
|
||||
return Rail.Shape.SOUTH_WEST;
|
||||
case NORTH_SOUTH:
|
||||
return Rail.Shape.EAST_WEST;
|
||||
case SOUTH_WEST:
|
||||
return Rail.Shape.SOUTH_EAST;
|
||||
case SOUTH_EAST:
|
||||
return Rail.Shape.NORTH_EAST;
|
||||
case EAST_WEST:
|
||||
return Rail.Shape.NORTH_SOUTH;
|
||||
case NORTH_EAST:
|
||||
return Rail.Shape.NORTH_WEST;
|
||||
case ASCENDING_EAST:
|
||||
return Rail.Shape.ASCENDING_NORTH;
|
||||
case ASCENDING_WEST:
|
||||
return Rail.Shape.ASCENDING_SOUTH;
|
||||
case ASCENDING_NORTH:
|
||||
return Rail.Shape.ASCENDING_WEST;
|
||||
case ASCENDING_SOUTH:
|
||||
return Rail.Shape.ASCENDING_EAST;
|
||||
}
|
||||
case CW_90:
|
||||
switch(orig) {
|
||||
case NORTH_WEST:
|
||||
return Rail.Shape.NORTH_EAST;
|
||||
case NORTH_SOUTH:
|
||||
return Rail.Shape.EAST_WEST;
|
||||
case SOUTH_WEST:
|
||||
return Rail.Shape.NORTH_WEST;
|
||||
case SOUTH_EAST:
|
||||
return Rail.Shape.SOUTH_WEST;
|
||||
case EAST_WEST:
|
||||
return Rail.Shape.NORTH_SOUTH;
|
||||
case NORTH_EAST:
|
||||
return Rail.Shape.SOUTH_EAST;
|
||||
case ASCENDING_EAST:
|
||||
return Rail.Shape.ASCENDING_SOUTH;
|
||||
case ASCENDING_WEST:
|
||||
return Rail.Shape.ASCENDING_NORTH;
|
||||
case ASCENDING_NORTH:
|
||||
return Rail.Shape.ASCENDING_EAST;
|
||||
case ASCENDING_SOUTH:
|
||||
return Rail.Shape.ASCENDING_WEST;
|
||||
}
|
||||
case CW_180:
|
||||
switch(orig) {
|
||||
case NORTH_WEST:
|
||||
return Rail.Shape.SOUTH_EAST;
|
||||
case NORTH_SOUTH:
|
||||
return Rail.Shape.NORTH_SOUTH;
|
||||
case SOUTH_WEST:
|
||||
return Rail.Shape.NORTH_EAST;
|
||||
case SOUTH_EAST:
|
||||
return Rail.Shape.NORTH_WEST;
|
||||
case EAST_WEST:
|
||||
return Rail.Shape.EAST_WEST;
|
||||
case NORTH_EAST:
|
||||
return Rail.Shape.SOUTH_WEST;
|
||||
case ASCENDING_EAST:
|
||||
return Rail.Shape.ASCENDING_WEST;
|
||||
case ASCENDING_WEST:
|
||||
return Rail.Shape.ASCENDING_EAST;
|
||||
case ASCENDING_NORTH:
|
||||
return Rail.Shape.ASCENDING_SOUTH;
|
||||
case ASCENDING_SOUTH:
|
||||
return Rail.Shape.ASCENDING_NORTH;
|
||||
}
|
||||
}
|
||||
return orig;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an integer representation of a BlockFace, to perform math on.
|
||||
*
|
||||
@ -232,4 +135,101 @@ public final class RotationUtil {
|
||||
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);
|
||||
switch(orig) {
|
||||
case X:
|
||||
if(shouldSwitch) other = org.bukkit.Axis.Z;
|
||||
break;
|
||||
case Z:
|
||||
if(shouldSwitch) other = org.bukkit.Axis.X;
|
||||
break;
|
||||
}
|
||||
return other;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to rotate the incredibly obnoxious Rail.Shape enum
|
||||
*
|
||||
* @param orig Original shape
|
||||
* @param r Rotate
|
||||
* @return Rotated/mirrored shape
|
||||
*/
|
||||
@SuppressWarnings("fallthrough")
|
||||
public static Rail.Shape getRotatedRail(Rail.Shape orig, Structure.Rotation r) {
|
||||
switch(r) {
|
||||
case CCW_90:
|
||||
switch(orig) {
|
||||
case NORTH_WEST:
|
||||
return Rail.Shape.SOUTH_WEST;
|
||||
case NORTH_SOUTH:
|
||||
return Rail.Shape.EAST_WEST;
|
||||
case SOUTH_WEST:
|
||||
return Rail.Shape.SOUTH_EAST;
|
||||
case SOUTH_EAST:
|
||||
return Rail.Shape.NORTH_EAST;
|
||||
case EAST_WEST:
|
||||
return Rail.Shape.NORTH_SOUTH;
|
||||
case NORTH_EAST:
|
||||
return Rail.Shape.NORTH_WEST;
|
||||
case ASCENDING_EAST:
|
||||
return Rail.Shape.ASCENDING_NORTH;
|
||||
case ASCENDING_WEST:
|
||||
return Rail.Shape.ASCENDING_SOUTH;
|
||||
case ASCENDING_NORTH:
|
||||
return Rail.Shape.ASCENDING_WEST;
|
||||
case ASCENDING_SOUTH:
|
||||
return Rail.Shape.ASCENDING_EAST;
|
||||
}
|
||||
case CW_90:
|
||||
switch(orig) {
|
||||
case NORTH_WEST:
|
||||
return Rail.Shape.NORTH_EAST;
|
||||
case NORTH_SOUTH:
|
||||
return Rail.Shape.EAST_WEST;
|
||||
case SOUTH_WEST:
|
||||
return Rail.Shape.NORTH_WEST;
|
||||
case SOUTH_EAST:
|
||||
return Rail.Shape.SOUTH_WEST;
|
||||
case EAST_WEST:
|
||||
return Rail.Shape.NORTH_SOUTH;
|
||||
case NORTH_EAST:
|
||||
return Rail.Shape.SOUTH_EAST;
|
||||
case ASCENDING_EAST:
|
||||
return Rail.Shape.ASCENDING_SOUTH;
|
||||
case ASCENDING_WEST:
|
||||
return Rail.Shape.ASCENDING_NORTH;
|
||||
case ASCENDING_NORTH:
|
||||
return Rail.Shape.ASCENDING_EAST;
|
||||
case ASCENDING_SOUTH:
|
||||
return Rail.Shape.ASCENDING_WEST;
|
||||
}
|
||||
case CW_180:
|
||||
switch(orig) {
|
||||
case NORTH_WEST:
|
||||
return Rail.Shape.SOUTH_EAST;
|
||||
case NORTH_SOUTH:
|
||||
return Rail.Shape.NORTH_SOUTH;
|
||||
case SOUTH_WEST:
|
||||
return Rail.Shape.NORTH_EAST;
|
||||
case SOUTH_EAST:
|
||||
return Rail.Shape.NORTH_WEST;
|
||||
case EAST_WEST:
|
||||
return Rail.Shape.EAST_WEST;
|
||||
case NORTH_EAST:
|
||||
return Rail.Shape.SOUTH_WEST;
|
||||
case ASCENDING_EAST:
|
||||
return Rail.Shape.ASCENDING_WEST;
|
||||
case ASCENDING_WEST:
|
||||
return Rail.Shape.ASCENDING_EAST;
|
||||
case ASCENDING_NORTH:
|
||||
return Rail.Shape.ASCENDING_SOUTH;
|
||||
case ASCENDING_SOUTH:
|
||||
return Rail.Shape.ASCENDING_NORTH;
|
||||
}
|
||||
}
|
||||
return orig;
|
||||
}
|
||||
}
|
||||
|
@ -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,19 +91,19 @@ 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;
|
||||
}
|
||||
|
||||
private static class Worker extends Thread {
|
||||
private final List<Double> l;
|
||||
private final int searches;
|
||||
|
Loading…
x
Reference in New Issue
Block a user