Merge pull request #101 from PolyhedralDev/ver/5.1.1

API to add populators, Buildscript improvements
This commit is contained in:
dfsek
2021-03-29 16:26:59 -07:00
committed by GitHub
29 changed files with 335 additions and 187 deletions

View File

@@ -30,7 +30,7 @@ fun Project.configureCommon() {
}
fun Project.getGitHash(): String {
val stdout = java.io.ByteArrayOutputStream()
val stdout = ByteArrayOutputStream()
exec {
commandLine = mutableListOf("git", "rev-parse", "--short", "HEAD")
standardOutput = stdout

View File

@@ -14,13 +14,9 @@ fun Project.configureDistribution() {
apply(plugin = "java-library")
apply(plugin = "com.github.johnrengelman.shadow")
// configurations.create("shaded")
configurations {
val shaded = create("shaded")
getByName("compile").extendsFrom(shaded)
// shaded.extendsFrom(getByName("compile"))
val shadedApi = create("shadedApi")
shaded.extendsFrom(shadedApi)
getByName("api").extendsFrom(shadedApi)
@@ -29,11 +25,8 @@ fun Project.configureDistribution() {
getByName("implementation").extendsFrom(shadedImplementation)
}
// tasks.withType<JavaCompile> {
// classpath +=
// }
val downloadDefaultPacks = tasks.create("downloadDefaultPacks") {
group = "terra"
doFirst {
file("${buildDir}/resources/main/packs/").deleteRecursively()

View File

@@ -160,7 +160,6 @@ public class TerraCommandManager implements CommandManager {
if(field.isAnnotationPresent(SwitchTarget.class)) {
SwitchTarget switchTarget = field.getAnnotation(SwitchTarget.class);
if(!holder.switches.containsValue(switchTarget.value())) {
System.out.println(holder.switches);
throw new MalformedCommandException("Switch Target specifies nonexistent switch \"" + switchTarget.value() + "\"");
}

View File

@@ -0,0 +1,7 @@
package com.dfsek.terra.api.world.generation;
/**
* Marker interface that marks a feature as "chunkified" (only modifying one chunk at a time)
*/
public interface Chunkified {
}

View File

@@ -1,8 +0,0 @@
package com.dfsek.terra.api.world.generation;
/**
* The phase of terrain generation. Used for modifying values based on the phase of generation.
*/
public enum GenerationPhase {
BASE, POPULATE, GENERATION_POPULATE, PALETTE_APPLY, POST_GEN
}

View File

@@ -6,10 +6,10 @@ import com.dfsek.terra.api.platform.world.World;
import com.dfsek.terra.api.platform.world.generator.ChunkData;
import com.dfsek.terra.api.world.biome.provider.BiomeProvider;
import com.dfsek.terra.config.pack.ConfigPack;
import com.dfsek.terra.world.generation.math.SamplerCache;
import com.dfsek.terra.world.generation.math.samplers.Sampler;
import org.jetbrains.annotations.NotNull;
import java.util.List;
import java.util.Random;
public interface TerraChunkGenerator {
@@ -32,4 +32,6 @@ public interface TerraChunkGenerator {
TerraPlugin getMain();
Sampler createSampler(int chunkX, int chunkZ, BiomeProvider provider, World world, int elevationSmooth);
List<TerraBlockPopulator> getPopulators();
}

View File

@@ -63,8 +63,6 @@ public class StructureLoadCommand implements CommandTemplate {
@Override
public void execute(CommandSender sender) {
System.out.println(rotation);
Player player = (Player) sender;
long t = System.nanoTime();

View File

@@ -4,7 +4,10 @@ import com.dfsek.terra.api.platform.world.Biome;
import com.dfsek.terra.api.util.collections.ProbabilityCollection;
import com.dfsek.terra.api.util.seeded.SeededBuilder;
import com.dfsek.terra.api.world.biome.TerraBiome;
import com.dfsek.terra.config.templates.BiomeTemplate;
public interface BiomeBuilder extends SeededBuilder<TerraBiome> {
ProbabilityCollection<Biome> getVanillaBiomes();
BiomeTemplate getTemplate();
}

View File

@@ -66,4 +66,9 @@ public class UserDefinedBiomeBuilder implements BiomeBuilder {
public ProbabilityCollection<Biome> getVanillaBiomes() {
return template.getVanilla();
}
@Override
public BiomeTemplate getTemplate() {
return template;
}
}

View File

@@ -65,7 +65,6 @@ public class ExpressionFunctionTemplate extends SamplerTemplate<ExpressionFuncti
Map<String, Function> noiseFunctionMap = new HashMap<>();
for(Map.Entry<String, FunctionTemplate> entry : expressions.entrySet()) {
System.out.println(entry);
noiseFunctionMap.put(entry.getKey(), UserDefinedFunction.newInstance(entry.getValue(), new Parser(), new Scope()));
}

View File

@@ -73,6 +73,46 @@ public class ConfigPackTemplate implements ConfigTemplate {
@Default
private String version = "0.1.0";
@Value("disable.carvers")
@Default
private boolean disableCarvers = false;
@Value("disable.structures")
@Default
private boolean disableStructures = false;
@Value("disable.ores")
@Default
private boolean disableOres = false;
@Value("disable.trees")
@Default
private boolean disableTrees = false;
@Value("disable.flora")
@Default
private boolean disableFlora = false;
public boolean disableCarvers() {
return disableCarvers;
}
public boolean disableFlora() {
return disableFlora;
}
public boolean disableOres() {
return disableOres;
}
public boolean disableStructures() {
return disableStructures;
}
public boolean disableTrees() {
return disableTrees;
}
public LinkedHashMap<String, FunctionTemplate> getFunctions() {
return functions;
}

View File

@@ -190,10 +190,19 @@ public class BiomeTemplate extends AbstractableTemplate implements ValidatedConf
@Default
private Map<UserDefinedCarver, Integer> carvers = new HashMap<>();
@Value("colors")
@Abstractable
@Default
private Map<String, Integer> colors = new HashMap<>(); // Plain ol' map, so platforms can decide what to do with colors (if anything).
public Set<String> getTags() {
return tags;
}
public Map<String, Integer> getColors() {
return colors;
}
public Map<UserDefinedCarver, Integer> getCarvers() {
return carvers;
}

View File

@@ -10,6 +10,7 @@ import com.dfsek.terra.api.util.world.PaletteUtil;
import com.dfsek.terra.api.world.biome.TerraBiome;
import com.dfsek.terra.api.world.biome.UserDefinedBiome;
import com.dfsek.terra.api.world.biome.provider.BiomeProvider;
import com.dfsek.terra.api.world.generation.TerraBlockPopulator;
import com.dfsek.terra.api.world.generation.TerraChunkGenerator;
import com.dfsek.terra.api.world.palette.Palette;
import com.dfsek.terra.config.pack.ConfigPack;
@@ -21,9 +22,15 @@ import com.dfsek.terra.world.carving.NoiseCarver;
import com.dfsek.terra.world.generation.math.SamplerCache;
import com.dfsek.terra.world.generation.math.samplers.Sampler;
import com.dfsek.terra.world.generation.math.samplers.Sampler2D;
import com.dfsek.terra.world.population.CavePopulator;
import com.dfsek.terra.world.population.OrePopulator;
import com.dfsek.terra.world.population.StructurePopulator;
import com.dfsek.terra.world.population.TreePopulator;
import net.jafama.FastMath;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
public class DefaultChunkGenerator2D implements TerraChunkGenerator {
@@ -31,12 +38,18 @@ public class DefaultChunkGenerator2D implements TerraChunkGenerator {
private final TerraPlugin main;
private final Carver carver;
private final List<TerraBlockPopulator> blockPopulators = new ArrayList<>();
private final SamplerCache cache;
public DefaultChunkGenerator2D(ConfigPack c, TerraPlugin main, SamplerCache cache) {
this.configPack = c;
this.main = main;
blockPopulators.add(new CavePopulator(main));
blockPopulators.add(new StructurePopulator(main));
blockPopulators.add(new OrePopulator(main));
blockPopulators.add(new TreePopulator(main));
blockPopulators.add(new TreePopulator(main));
carver = new NoiseCarver(new Range(0, 255), main.getWorldHandle().createBlockData("minecraft:air"), main);
this.cache = cache;
}
@@ -125,4 +138,9 @@ public class DefaultChunkGenerator2D implements TerraChunkGenerator {
public Sampler createSampler(int chunkX, int chunkZ, BiomeProvider provider, World world, int elevationSmooth) {
return new Sampler2D(chunkX, chunkZ, provider, world, elevationSmooth);
}
@Override
public List<TerraBlockPopulator> getPopulators() {
return blockPopulators;
}
}

View File

@@ -17,6 +17,7 @@ import com.dfsek.terra.api.util.world.PaletteUtil;
import com.dfsek.terra.api.world.biome.TerraBiome;
import com.dfsek.terra.api.world.biome.UserDefinedBiome;
import com.dfsek.terra.api.world.biome.provider.BiomeProvider;
import com.dfsek.terra.api.world.generation.TerraBlockPopulator;
import com.dfsek.terra.api.world.generation.TerraChunkGenerator;
import com.dfsek.terra.api.world.palette.Palette;
import com.dfsek.terra.api.world.palette.SinglePalette;
@@ -28,8 +29,15 @@ import com.dfsek.terra.world.TerraWorld;
import com.dfsek.terra.world.carving.NoiseCarver;
import com.dfsek.terra.world.generation.math.samplers.Sampler;
import com.dfsek.terra.world.generation.math.samplers.Sampler3D;
import com.dfsek.terra.world.population.CavePopulator;
import com.dfsek.terra.world.population.FloraPopulator;
import com.dfsek.terra.world.population.OrePopulator;
import com.dfsek.terra.world.population.StructurePopulator;
import com.dfsek.terra.world.population.TreePopulator;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Random;
@@ -38,14 +46,21 @@ public class DefaultChunkGenerator3D implements TerraChunkGenerator {
private final TerraPlugin main;
private final BlockType water;
private final SinglePalette<BlockData> blank;
private final List<TerraBlockPopulator> blockPopulators = new ArrayList<>();
private final Carver carver;
public DefaultChunkGenerator3D(ConfigPack c, TerraPlugin main) {
this.configPack = c;
this.main = main;
blockPopulators.add(new CavePopulator(main));
blockPopulators.add(new StructurePopulator(main));
blockPopulators.add(new OrePopulator(main));
blockPopulators.add(new TreePopulator(main));
blockPopulators.add(new FloraPopulator(main));
carver = new NoiseCarver(new Range(0, 255), main.getWorldHandle().createBlockData("minecraft:air"), main);
water = main.getWorldHandle().createBlockData("minecraft:water").getBlockType();
blank = new SinglePalette<>(main.getWorldHandle().createBlockData("minecraft:air"));
@@ -236,4 +251,9 @@ public class DefaultChunkGenerator3D implements TerraChunkGenerator {
public Sampler createSampler(int chunkX, int chunkZ, BiomeProvider provider, World world, int elevationSmooth) {
return new Sampler3D(chunkX, chunkZ, provider, world, elevationSmooth);
}
@Override
public List<TerraBlockPopulator> getPopulators() {
return blockPopulators;
}
}

View File

@@ -9,6 +9,7 @@ import com.dfsek.terra.api.platform.handle.WorldHandle;
import com.dfsek.terra.api.platform.world.Chunk;
import com.dfsek.terra.api.platform.world.World;
import com.dfsek.terra.api.util.world.PopulationUtil;
import com.dfsek.terra.api.world.generation.Chunkified;
import com.dfsek.terra.api.world.generation.TerraBlockPopulator;
import com.dfsek.terra.carving.UserDefinedCarver;
import com.dfsek.terra.config.pack.WorldConfig;
@@ -23,7 +24,7 @@ import java.util.Map;
import java.util.Random;
import java.util.Set;
public class CavePopulator implements TerraBlockPopulator {
public class CavePopulator implements TerraBlockPopulator, Chunkified {
private static final Map<BlockType, BlockData> shiftStorage = new HashMap<>(); // Persist BlockData created for shifts, to avoid re-calculating each time.
private final TerraPlugin main;
@@ -41,6 +42,7 @@ public class CavePopulator implements TerraBlockPopulator {
Random random = PopulationUtil.getRandom(chunk);
if(!tw.isSafe()) return;
WorldConfig config = tw.getConfig();
if(config.getTemplate().disableCarvers()) return;
for(UserDefinedCarver c : config.getCarvers()) {
CarverTemplate template = c.getConfig();

View File

@@ -33,6 +33,8 @@ public class FloraPopulator implements TerraBlockPopulator {
public void populate(@NotNull World world, @NotNull Chunk chunk) {
TerraWorld tw = main.getWorld(world);
try(ProfileFuture ignored = tw.getProfiler().measure("FloraTime")) {
if(tw.getConfig().getTemplate().disableCarvers()) return;
if(!tw.isSafe()) return;
BiomeProvider provider = tw.getBiomeProvider();
Map<Vector2, List<FloraLayer>> layers = new HashMap<>();

View File

@@ -28,6 +28,8 @@ public class OrePopulator implements TerraBlockPopulator {
public void populate(@NotNull World world, @NotNull Chunk chunk) {
TerraWorld tw = main.getWorld(world);
try(ProfileFuture ignored = tw.getProfiler().measure("OreTime")) {
if(tw.getConfig().getTemplate().disableCarvers()) return;
if(!tw.isSafe()) return;
for(int cx = -1; cx <= 1; cx++) {
for(int cz = -1; cz <= 1; cz++) {

View File

@@ -9,6 +9,7 @@ import com.dfsek.terra.api.structures.structure.Rotation;
import com.dfsek.terra.api.util.FastRandom;
import com.dfsek.terra.api.world.biome.UserDefinedBiome;
import com.dfsek.terra.api.world.biome.provider.BiomeProvider;
import com.dfsek.terra.api.world.generation.Chunkified;
import com.dfsek.terra.api.world.generation.TerraBlockPopulator;
import com.dfsek.terra.config.pack.ConfigPack;
import com.dfsek.terra.config.pack.WorldConfig;
@@ -20,7 +21,7 @@ import org.jetbrains.annotations.NotNull;
import java.util.Random;
public class StructurePopulator implements TerraBlockPopulator {
public class StructurePopulator implements TerraBlockPopulator, Chunkified {
private final TerraPlugin main;
public StructurePopulator(TerraPlugin main) {
@@ -32,6 +33,8 @@ public class StructurePopulator implements TerraBlockPopulator {
public void populate(@NotNull World world, @NotNull Chunk chunk) {
TerraWorld tw = main.getWorld(world);
try(ProfileFuture ignored = tw.getProfiler().measure("StructureTime")) {
if(tw.getConfig().getTemplate().disableCarvers()) return;
int cx = (chunk.getX() << 4);
int cz = (chunk.getZ() << 4);
if(!tw.isSafe()) return;

View File

@@ -33,6 +33,8 @@ public class TreePopulator implements TerraBlockPopulator {
public void populate(@NotNull World world, @NotNull Chunk chunk) {
TerraWorld tw = main.getWorld(world);
try(ProfileFuture ignored = tw.getProfiler().measure("TreeTime")) {
if(tw.getConfig().getTemplate().disableCarvers()) return;
if(!tw.isSafe()) return;
BiomeProvider provider = tw.getBiomeProvider();
Random random = PopulationUtil.getRandom(chunk);

View File

@@ -39,6 +39,7 @@ import com.dfsek.terra.config.loaders.config.biome.templates.provider.SingleBiom
import com.dfsek.terra.config.loaders.config.sampler.NoiseSamplerBuilderLoader;
import com.dfsek.terra.config.pack.ConfigPack;
import com.dfsek.terra.config.templates.AbstractableTemplate;
import com.dfsek.terra.config.templates.BiomeTemplate;
import com.dfsek.terra.registry.config.BiomeRegistry;
import com.dfsek.terra.registry.config.NoiseRegistry;
import com.dfsek.terra.world.TerraWorld;
@@ -306,6 +307,11 @@ public class DistributionTest {
return null;
}
@Override
public BiomeTemplate getTemplate() {
return null;
}
@Override
public Generator getGenerator(World w) {
return null;

View File

@@ -15,6 +15,13 @@ configureCommon()
group = "com.dfsek.terra.bukkit"
val mcVersion = "1.16.5"
val testDir = "target/server/"
val testMem = "3G"
val paperURL = "https://papermc.io/api/v1/paper/%version%/latest/download/"
val purpurURL = "https://ci.pl3x.net/job/Purpur/lastSuccessfulBuild/artifact/final/purpurclip.jar"
repositories {
mavenCentral()
maven { url = uri("http://maven.enginehub.org/repo/") }
@@ -35,73 +42,155 @@ dependencies {
"shadedImplementation"("com.google.guava:guava:30.0-jre")
}
val testDir = "target/server/"
val aikarsFlags = 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", "-DIReallyKnowWhatIAmDoingISwear")
val setupServer = tasks.create("setupServer") {
dependsOn("shadowJar")
doFirst {
// clean
file("${testDir}/").deleteRecursively()
file("${testDir}/plugins").mkdirs()
fun downloadPaperclip(url: String, dir: String) {
val clip = URL(url.replace("%version%", mcVersion))
val clipReadableByteChannel = Channels.newChannel(clip.openStream())
val clipFile = file("$testDir/$dir/paperclip.jar")
val clipOutputStream = clipFile.outputStream()
val clipFileChannel = clipOutputStream.channel
clipFileChannel.transferFrom(clipReadableByteChannel, 0, Long.MAX_VALUE)
}
// Downloading latest paper jar.
val paperUrl = URL("https://papermc.io/api/v1/paper/1.16.4/latest/download")
val paperReadableByteChannel = Channels.newChannel(paperUrl.openStream())
val paperFile = file("${testDir}/paper.jar")
val paperFileOutputStream = paperFile.outputStream()
val paperFileChannel = paperFileOutputStream.channel
paperFileChannel.transferFrom(paperReadableByteChannel, 0, Long.MAX_VALUE)
// Cloning test setup.
gitClone("https://github.com/PolyhedralDev/WorldGenTestServer")
// Copying plugins
Files.move(Paths.get("WorldGenTestServer/plugins"),
Paths.get("$testDir/plugins"),
StandardCopyOption.REPLACE_EXISTING)
// Copying config
val serverText = URL("https://raw.githubusercontent.com/PolyhedralDev/WorldGenTestServer/master/server.properties").readText()
file("${testDir}/server.properties").writeText(serverText)
val bukkitText = URL("https://raw.githubusercontent.com/PolyhedralDev/WorldGenTestServer/master/bukkit.yml").readText()
file("${testDir}/bukkit.yml").writeText(bukkitText.replace("\${world}", "world").replace("\${gen}", "Terra:DEFAULT"))
File("${testDir}/eula.txt").writeText("eula=true")
// clean up
file("WorldGenTestServer").deleteRecursively()
fun copyTerra(dir: String) {
file("$testDir/$dir").walk().forEach {
if(it.name.startsWith("Terra-") && it.name.endsWith(".jar")) it.delete() // Delete old Terra jar(s)
}
copy {
from("$buildDir/libs/Terra-bukkit-$version-shaded.jar")
into("$testDir/$dir/plugins/")
}
}
val testWithPaper = task<JavaExec>(name = "testWithPaper") {
fun installServer(dir: String) {
// clean
file("$testDir/$dir").deleteRecursively()
file("$testDir/$dir/plugins").mkdirs()
// Cloning test setup.
gitClone("https://github.com/PolyhedralDev/WorldGenTestServer")
// Copying plugins
Files.move(Paths.get("WorldGenTestServer/plugins"),
Paths.get("$testDir/$dir/plugins"),
StandardCopyOption.REPLACE_EXISTING)
// Copying config
val serverText = URL("https://raw.githubusercontent.com/PolyhedralDev/WorldGenTestServer/master/server.properties").readText()
file("$testDir/$dir/server.properties").writeText(serverText)
val bukkitText = URL("https://raw.githubusercontent.com/PolyhedralDev/WorldGenTestServer/master/bukkit.yml").readText()
file("$testDir/$dir/bukkit.yml").writeText(bukkitText.replace("\${world}", "world").replace("\${gen}", "Terra:DEFAULT"))
println("By proceeding, you are agreeing to the Minecraft EULA: https://account.mojang.com/documents/minecraft_eula")
file("$testDir/$dir/eula.txt").writeText("eula=true")
// clean up
file("WorldGenTestServer").deleteRecursively()
}
fun deleteFolder(folder: File) {
if(folder.exists()) folder.deleteRecursively()
}
fun deleteFile(file: File) {
if(file.exists()) file.delete()
}
tasks.create("cleanWorlds") {
group = "bukkit"
doFirst {
deleteFolder(file("$testDir/paper/world"))
deleteFolder(file("$testDir/paper/world_nether"))
deleteFolder(file("$testDir/paper/world_the_end"))
deleteFolder(file("$testDir/purpur/world"))
deleteFolder(file("$testDir/purpur/world_nether"))
deleteFolder(file("$testDir/purpur/world_the_end"))
}
}
tasks.create("updatePaper") {
group = "bukkit"
doFirst {
deleteFile(file("$testDir/paper/paperclip.jar"))
downloadPaperclip(paperURL, "paper")
}
}
tasks.create("updatePurpur") {
group = "bukkit"
doFirst {
deleteFile(file("$testDir/paper/paperclip.jar"))
downloadPaperclip(purpurURL, "purpur")
}
}
tasks.create("installPaper") {
group = "bukkit"
dependsOn("shadowJar")
doFirst {
installServer("paper")
// Downloading latest paper jar.
downloadPaperclip(paperURL, "paper")
}
}
tasks.create("installPurpur") {
group = "bukkit"
dependsOn("shadowJar")
doFirst {
installServer("purpur")
// Downloading latest paper jar.
downloadPaperclip(purpurURL, "purpur")
}
}
task<JavaExec>(name = "runPaper") {
group = "bukkit"
standardInput = System.`in`
dependsOn("shadowJar")
// Copy Terra into dir
doFirst {
copy {
from("${buildDir}/libs/Terra-bukkit-${version}-shaded.jar")
into("${testDir}/plugins/")
}
copyTerra("paper")
}
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", "-DIReallyKnowWhatIAmDoingISwear")
maxHeapSize = "4G"
minHeapSize = "4G"
jvmArgs = aikarsFlags
maxHeapSize = testMem
minHeapSize = testMem
//args = listOf("nogui")
workingDir = file("${testDir}/")
classpath = files("${testDir}/paper.jar")
workingDir = file("$testDir/paper")
classpath = files("$testDir/paper/paperclip.jar")
}
task<JavaExec>(name = "runPurpur") {
group = "bukkit"
standardInput = System.`in`
dependsOn("shadowJar")
// Copy Terra into dir
doFirst {
copyTerra("purpur")
}
main = "io.papermc.paperclip.Paperclip"
jvmArgs = aikarsFlags
maxHeapSize = testMem
minHeapSize = testMem
//args = listOf("nogui")
workingDir = file("$testDir/purpur")
classpath = files("$testDir/purpur/paperclip.jar")
}
tasks.named<ShadowJar>("shadowJar") {
relocate("org.bstats.bukkit", "com.dfsek.terra.lib.bstats")
relocate("io.papermc.lib", "com.dfsek.terra.lib.paperlib")
}
publishing {
publications {
create<MavenPublication>("mavenJava") {
@@ -112,7 +201,6 @@ publishing {
repositories {
val mavenUrl = "https://repo.codemc.io/repository/maven-releases/"
val mavenSnapshotUrl = "https://repo.codemc.io/repository/maven-snapshots/"
maven(mavenUrl) {
val mavenUsername: String? by project

View File

@@ -23,6 +23,8 @@ import org.jetbrains.annotations.NotNull;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
@@ -40,20 +42,13 @@ public class BukkitChunkGeneratorWrapper extends ChunkGenerator implements Gener
private final TerraPlugin main;
private final List<TerraBlockPopulator> populators = new LinkedList<>();
private boolean needsLoad = true;
public BukkitChunkGeneratorWrapper(TerraChunkGenerator delegate) {
this.delegate = delegate;
this.main = delegate.getMain();
popMan = new PopulationManager(main);
popMan.attach(new OrePopulator(main));
popMan.attach(new TreePopulator(main));
popMan.attach(new FloraPopulator(main));
populators.add(new CavePopulator(main));
populators.add(new StructurePopulator(main));
populators.add(popMan);
this.popMan = new PopulationManager(delegate, main);
}
@@ -96,7 +91,7 @@ public class BukkitChunkGeneratorWrapper extends ChunkGenerator implements Gener
@Override
public @NotNull List<BlockPopulator> getDefaultPopulators(@NotNull World world) {
return populators.stream().map(BukkitPopulatorWrapper::new).collect(Collectors.toList());
return Arrays.asList(popMan, new BukkitPopulatorWrapper(delegate));
}
@Override

View File

@@ -1,27 +0,0 @@
package com.dfsek.terra.bukkit.generator;
import com.dfsek.terra.api.platform.world.Chunk;
import com.dfsek.terra.api.platform.world.World;
import com.dfsek.terra.api.platform.world.generator.BlockPopulator;
import com.dfsek.terra.bukkit.world.BukkitChunk;
import com.dfsek.terra.bukkit.world.BukkitWorld;
import java.util.Random;
public class BukkitPopulator implements BlockPopulator {
private final org.bukkit.generator.BlockPopulator handle;
public BukkitPopulator(org.bukkit.generator.BlockPopulator handle) {
this.handle = handle;
}
@Override
public void populate(World world, Random random, Chunk chunk) {
handle.populate(((BukkitWorld) world).getHandle(), random, ((BukkitChunk) chunk).getHandle());
}
@Override
public org.bukkit.generator.BlockPopulator getHandle() {
return handle;
}
}

View File

@@ -1,6 +1,8 @@
package com.dfsek.terra.bukkit.generator;
import com.dfsek.terra.api.world.generation.Chunkified;
import com.dfsek.terra.api.world.generation.TerraBlockPopulator;
import com.dfsek.terra.api.world.generation.TerraChunkGenerator;
import com.dfsek.terra.bukkit.world.BukkitAdapter;
import org.bukkit.Chunk;
import org.bukkit.World;
@@ -10,14 +12,18 @@ import org.jetbrains.annotations.NotNull;
import java.util.Random;
public class BukkitPopulatorWrapper extends BlockPopulator {
private final TerraBlockPopulator delegate;
private final TerraChunkGenerator delegate;
public BukkitPopulatorWrapper(TerraBlockPopulator delegate) {
public BukkitPopulatorWrapper(TerraChunkGenerator delegate) {
this.delegate = delegate;
}
@Override
public void populate(@NotNull World world, @NotNull Random random, @NotNull Chunk source) {
delegate.populate(BukkitAdapter.adapt(world), BukkitAdapter.adapt(source));
delegate.getPopulators().forEach(populator -> {
if(populator instanceof Chunkified) {
populator.populate(BukkitAdapter.adapt(world), BukkitAdapter.adapt(source));
}
});
}
}

View File

@@ -4,54 +4,35 @@ import com.dfsek.terra.api.TerraPlugin;
import com.dfsek.terra.api.platform.world.Chunk;
import com.dfsek.terra.api.platform.world.World;
import com.dfsek.terra.api.util.FastRandom;
import com.dfsek.terra.api.util.GlueList;
import com.dfsek.terra.api.world.generation.Chunkified;
import com.dfsek.terra.api.world.generation.TerraBlockPopulator;
import com.dfsek.terra.api.world.generation.TerraChunkGenerator;
import com.dfsek.terra.bukkit.TerraBukkitPlugin;
import com.dfsek.terra.bukkit.world.BukkitAdapter;
import com.dfsek.terra.profiler.ProfileFuture;
import com.dfsek.terra.profiler.WorldProfiler;
import org.bukkit.generator.BlockPopulator;
import org.jetbrains.annotations.NotNull;
import java.io.File;
import java.io.IOException;
import java.util.HashSet;
import java.util.List;
import java.util.Random;
/**
* Cursed management class for the horrors of Bukkit population
*/
public class PopulationManager implements TerraBlockPopulator {
private final List<TerraBlockPopulator> attachedPopulators = new GlueList<>();
public class PopulationManager extends BlockPopulator {
private final TerraChunkGenerator generator;
private final HashSet<ChunkCoordinate> needsPop = new HashSet<>();
private final TerraPlugin main;
private WorldProfiler profiler;
public PopulationManager(TerraPlugin main) {
public PopulationManager(TerraChunkGenerator generator, TerraPlugin main) {
this.generator = generator;
this.main = main;
}
public void attach(TerraBlockPopulator populator) {
this.attachedPopulators.add(populator);
}
@Override
@SuppressWarnings("try")
public void populate(@NotNull World world, @NotNull Chunk chunk) {
try(ProfileFuture ignored = measure()) {
needsPop.add(new ChunkCoordinate(chunk));
int x = chunk.getX();
int z = chunk.getZ();
if(((TerraBukkitPlugin) main).isEnabled()) {
for(int xi = -1; xi <= 1; xi++) {
for(int zi = -1; zi <= 1; zi++) {
if(xi == 0 && zi == 0) continue;
if(world.isChunkGenerated(xi + x, zi + z)) checkNeighbors(xi + x, zi + z, world);
}
}
}
}
}
private ProfileFuture measure() {
if(profiler != null) return profiler.measure("PopulationManagerTime");
return null;
@@ -87,10 +68,30 @@ public class PopulationManager implements TerraBlockPopulator {
long zRand = (random.nextLong() / 2L << 1L) + 1L;
random.setSeed((long) x * xRand + (long) z * zRand ^ w.getSeed());
Chunk currentChunk = w.getChunkAt(x, z);
for(TerraBlockPopulator r : attachedPopulators) {
r.populate(w, currentChunk);
}
generator.getPopulators().forEach(populator -> {
if(!(populator instanceof Chunkified)) {
populator.populate(w, currentChunk);
}
});
needsPop.remove(c);
}
}
@Override
public void populate(org.bukkit.@NotNull World world, @NotNull Random random, org.bukkit.@NotNull Chunk source) {
try(ProfileFuture ignored = measure()) {
Chunk chunk = BukkitAdapter.adapt(source);
needsPop.add(new ChunkCoordinate(chunk));
int x = chunk.getX();
int z = chunk.getZ();
if(((TerraBukkitPlugin) main).isEnabled()) {
for(int xi = -1; xi <= 1; xi++) {
for(int zi = -1; zi <= 1; zi++) {
if(xi == 0 && zi == 0) continue;
if(world.isChunkGenerated(xi + x, zi + z)) checkNeighbors(xi + x, zi + z, BukkitAdapter.adapt(world));
}
}
}
}
}
}

View File

@@ -40,6 +40,7 @@ configure<LoomGradleExtension> {
}
tasks.register<RemapJarTask>("remapShadedJar") {
group = "fabric"
val shadowJar = tasks.getByName<ShadowJar>("shadowJar")
dependsOn(shadowJar)
input.set(shadowJar.archiveFile)

View File

@@ -35,6 +35,7 @@ import com.dfsek.terra.config.builder.BiomeBuilder;
import com.dfsek.terra.config.lang.LangUtil;
import com.dfsek.terra.config.lang.Language;
import com.dfsek.terra.config.pack.ConfigPack;
import com.dfsek.terra.config.templates.BiomeTemplate;
import com.dfsek.terra.fabric.inventory.FabricItemHandle;
import com.dfsek.terra.fabric.mixin.GeneratorTypeAccessor;
import com.dfsek.terra.fabric.world.FabricAdapter;
@@ -150,7 +151,6 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
@Override
public TerraWorld getWorld(World world) {
if(worldMap.size() > 1) System.out.println(worldMap.size());
return worldMap.computeIfAbsent(world.getSeed(), w -> {
logger.info("Loading world " + w);
return new TerraWorld(world, ((FabricChunkGeneratorWrapper) ((FabricChunkGenerator) world.getGenerator()).getHandle()).getPack(), this);
@@ -246,6 +246,9 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
DefaultBiomeFeatures.addFarmAnimals(spawnSettings);
DefaultBiomeFeatures.addMonsters(spawnSettings, 95, 5, 100);
BiomeTemplate template = biome.getTemplate();
Map<String, Integer> colors = template.getColors();
Biome vanilla = ((FabricBiome) new ArrayList<>(biome.getVanillaBiomes().getContents()).get(0)).getHandle();
GenerationSettings.Builder generationSettings = new GenerationSettings.Builder();
@@ -254,28 +257,37 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
BiomeEffects.Builder effects = new BiomeEffects.Builder()
.waterColor(vanilla.getEffects().waterColor)
.waterFogColor(vanilla.getEffects().waterFogColor)
.fogColor(vanilla.getEffects().fogColor)
.skyColor(vanilla.getEffects().skyColor)
.waterColor(colors.getOrDefault("water", vanilla.getEffects().waterColor))
.waterFogColor(colors.getOrDefault("water-fog", vanilla.getEffects().waterFogColor))
.fogColor(colors.getOrDefault("fog", vanilla.getEffects().fogColor))
.skyColor(colors.getOrDefault("sky", vanilla.getEffects().skyColor))
.grassColorModifier(vanilla.getEffects().grassColorModifier);
vanilla.getEffects().grassColor.ifPresent(effects::grassColor);
vanilla.getEffects().foliageColor.ifPresent(effects::foliageColor);
return (new Biome.Builder())
if(colors.containsKey("grass")) {
effects.grassColor(colors.get("grass"));
} else {
vanilla.getEffects().grassColor.ifPresent(effects::grassColor);
}
vanilla.getEffects().foliageColor.ifPresent(effects::foliageColor);
if(colors.containsKey("foliage")) {
effects.foliageColor(colors.get("foliage"));
} else {
vanilla.getEffects().foliageColor.ifPresent(effects::foliageColor);
}
return new Biome.Builder()
.precipitation(vanilla.getPrecipitation())
.category(vanilla.getCategory())
.depth(vanilla.getDepth())
.scale(vanilla.getScale())
.temperature(vanilla.getTemperature())
.downfall(vanilla.getDownfall())
.effects(vanilla.getEffects()) // TODO: configurable
.effects(effects.build())
.spawnSettings(spawnSettings.build())
.generationSettings(generationSettings.build())
.build();
}
@SuppressWarnings("unchecked")
@Override
public void onInitialize() {
instance = this;
@@ -327,10 +339,8 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> {
int max = manager.getMaxArgumentDepth();
System.out.println("MAX:" + max);
RequiredArgumentBuilder<ServerCommandSource, String> arg = argument("arg" + (max - 1), StringArgumentType.word());
for(int i = 0; i < max; i++) {
System.out.println("arg " + i);
RequiredArgumentBuilder<ServerCommandSource, String> next = argument("arg" + (max - i - 1), StringArgumentType.word());
arg = next.then(assemble(arg, manager));

View File

@@ -27,11 +27,7 @@ public class PopulatorFeature extends Feature<DefaultFeatureConfig> {
FabricChunkGeneratorWrapper gen = (FabricChunkGeneratorWrapper) chunkGenerator;
FabricChunkWorldAccess chunk = new FabricChunkWorldAccess(world, pos.getX() >> 4, pos.getZ() >> 4);
FabricWorld world1 = new FabricWorld(world.toServerWorld(), new FabricChunkGenerator(chunkGenerator));
gen.getCavePopulator().populate(new FabricWorldAccess(world), chunk);
gen.getStructurePopulator().populate(new FabricWorldAccess(world), chunk);
gen.getOrePopulator().populate(world1, chunk);
gen.getTreePopulator().populate(world1, chunk);
gen.getFloraPopulator().populate(world1, chunk);
gen.getHandle().getPopulators().forEach(populator -> populator.populate(world1, chunk));
return true;
}
}

View File

@@ -50,32 +50,6 @@ public class FabricChunkGeneratorWrapper extends ChunkGenerator implements Gener
return pack;
}
private final FloraPopulator floraPopulator = new FloraPopulator(TerraFabricPlugin.getInstance());
private final OrePopulator orePopulator = new OrePopulator(TerraFabricPlugin.getInstance());
private final TreePopulator treePopulator = new TreePopulator(TerraFabricPlugin.getInstance());
private final StructurePopulator structurePopulator = new StructurePopulator(TerraFabricPlugin.getInstance());
private final CavePopulator cavePopulator = new CavePopulator(TerraFabricPlugin.getInstance());
public TreePopulator getTreePopulator() {
return treePopulator;
}
public OrePopulator getOrePopulator() {
return orePopulator;
}
public FloraPopulator getFloraPopulator() {
return floraPopulator;
}
public StructurePopulator getStructurePopulator() {
return structurePopulator;
}
public CavePopulator getCavePopulator() {
return cavePopulator;
}
public FabricChunkGeneratorWrapper(TerraBiomeSource biomeSource, long seed, ConfigPack configPack) {
super(biomeSource, new StructuresConfig(false));
this.pack = configPack;
@@ -124,6 +98,8 @@ public class FabricChunkGeneratorWrapper extends ChunkGenerator implements Gener
}
@Override
public boolean isStrongholdStartingChunk(ChunkPos chunkPos) {
return false;