Merge remote-tracking branch 'origin/ver/6.0.0' into ver/6.0.0

# Conflicts:
#	build.gradle.kts
#	buildSrc/src/main/kotlin/DependencyConfig.kt
#	buildSrc/src/main/kotlin/DistributionConfig.kt
#	common/addons/biome-provider-image/build.gradle.kts
#	common/addons/biome-provider-pipeline/build.gradle.kts
#	common/addons/biome-provider-single/build.gradle.kts
#	common/addons/chunk-generator-noise-3d/build.gradle.kts
#	common/addons/command-addons/build.gradle.kts
#	common/addons/command-packs/build.gradle.kts
#	common/addons/command-profiler/build.gradle.kts
#	common/addons/command-structures/build.gradle.kts
#	common/addons/config-biome/build.gradle.kts
#	common/addons/config-distributors/build.gradle.kts
#	common/addons/config-feature/build.gradle.kts
#	common/addons/config-flora/build.gradle.kts
#	common/addons/config-locators/build.gradle.kts
#	common/addons/config-noise-function/build.gradle.kts
#	common/addons/config-ore/build.gradle.kts
#	common/addons/config-palette/build.gradle.kts
#	common/addons/config-structure/build.gradle.kts
#	common/addons/generation-stage-feature/build.gradle.kts
#	common/addons/generation-stage-structure/build.gradle.kts
#	common/addons/language-yaml/build.gradle.kts
#	common/addons/manifest-addon-loader/build.gradle.kts
#	common/addons/palette-block-shortcut/build.gradle.kts
#	common/addons/structure-block-shortcut/build.gradle.kts
#	common/addons/structure-mutator/build.gradle.kts
#	common/addons/structure-sponge-loader/build.gradle.kts
#	common/addons/structure-terrascript-loader/build.gradle.kts
#	common/addons/terrascript-function-check-noise-3d/build.gradle.kts
#	common/addons/terrascript-function-sampler/build.gradle.kts
#	common/api/build.gradle.kts
#	common/implementation/base/build.gradle.kts
#	common/implementation/bootstrap-addon-loader/build.gradle.kts
#	platforms/bukkit/build.gradle.kts
#	platforms/cli/build.gradle.kts
#	platforms/merged/build.gradle.kts
This commit is contained in:
dfsek
2022-05-14 12:03:56 -07:00
52 changed files with 255 additions and 153 deletions

View File

@@ -1,5 +1,3 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
preRelease(true) preRelease(true)
versionProjects(":common:api", version("6.0.0")) versionProjects(":common:api", version("6.0.0"))
@@ -46,18 +44,16 @@ afterEvaluate {
} }
forSubProjects(":common:addons") { forSubProjects(":common:addons") {
apply(plugin = "com.github.johnrengelman.shadow") apply(plugin = "com.github.johnrengelman.shadow")
tasks.named("build") {
finalizedBy(tasks.named("shadowJar"))
}
dependencies { dependencies {
"compileOnly"(project(":common:api")) "compileOnly"(project(":common:api"))
"implementation"("net.jafama", "jafama", Versions.Libraries.Internal.jafama) "implementation"("net.jafama", "jafama", Versions.Libraries.Internal.jafama)
"testImplementation"("net.jafama", "jafama", Versions.Libraries.Internal.jafama) "testImplementation"("net.jafama", "jafama", Versions.Libraries.Internal.jafama)
"testImplementation"(project(":common:api")) "testImplementation"(project(":common:api"))
} }
val libPackage = "com.dfsek.terra.addons.${this.name.replace('-', '_')}.lib"
tasks.named<ShadowJar>("shadowJar") {
relocate("net.jafama", "$libPackage.jafama")
}
tasks.named("build") {
finalizedBy(tasks.named("shadowJar"))
}
} }
} }

View File

@@ -9,6 +9,23 @@ fun Project.configureDependencies() {
val testImplementation by configurations.getting val testImplementation by configurations.getting
val compileOnly by configurations.getting val compileOnly by configurations.getting
val api by configurations.getting
val implementation by configurations.getting
val shaded by configurations.creating
@Suppress("UNUSED_VARIABLE")
val shadedApi by configurations.creating {
shaded.extendsFrom(this)
api.extendsFrom(this)
}
@Suppress("UNUSED_VARIABLE")
val shadedImplementation by configurations.creating {
shaded.extendsFrom(this)
implementation.extendsFrom(this)
}
repositories { repositories {
mavenCentral() mavenCentral()
gradlePluginPortal() gradlePluginPortal()

View File

@@ -121,14 +121,14 @@ fun Project.configureDistribution() {
tasks.named<ShadowJar>("shadowJar") { tasks.named<ShadowJar>("shadowJar") {
// Tell shadow to download the packs // Tell shadow to download the packs
dependsOn(downloadDefaultPacks) dependsOn(downloadDefaultPacks)
configurations = listOf(project.configurations["shaded"])
archiveClassifier.set("shaded") archiveClassifier.set("shaded")
setVersion(project.version) setVersion(project.version)
relocate("org.apache.commons", "com.dfsek.terra.lib.commons") relocate("org.apache.commons", "com.dfsek.terra.lib.commons")
relocate("org.objectweb.asm", "com.dfsek.terra.lib.asm") relocate("org.objectweb.asm", "com.dfsek.terra.lib.asm")
relocate("com.dfsek.paralithic", "com.dfsek.terra.lib.paralithic")
relocate("org.json", "com.dfsek.terra.lib.json") relocate("org.json", "com.dfsek.terra.lib.json")
relocate("org.yaml", "com.dfsek.terra.lib.yaml") relocate("org.yaml", "com.dfsek.terra.lib.yaml")
relocate("com.dfsek.paralithic", "com.dfsek.terra.lib.paralithic")
} }
configure<BasePluginExtension> { configure<BasePluginExtension> {
@@ -147,10 +147,4 @@ fun downloadPack(packUrl: URL, project: Project) {
file.outputStream().write(packUrl.readBytes()) file.outputStream().write(packUrl.readBytes())
} }
fun Project.getJarTask(): Jar { fun Project.getJarTask() = tasks.named("shadowJar").get() as ShadowJar
return if (tasks.findByName("shadowJar") != null) {
(tasks.named("shadowJar").get() as ShadowJar)
} else {
(tasks.named("jar").get() as Jar)
}
}

View File

@@ -1,7 +1,7 @@
object Versions { object Versions {
object Libraries { object Libraries {
const val tectonic = "4.2.0" const val tectonic = "4.2.0"
const val paralithic = "0.6.0" const val paralithic = "0.6.1"
const val strata = "1.1.1" const val strata = "1.1.1"
const val cloud = "1.6.2" const val cloud = "1.6.2"
@@ -13,7 +13,6 @@ object Versions {
const val apacheText = "1.9" const val apacheText = "1.9"
const val jafama = "2.3.2" const val jafama = "2.3.2"
const val apacheIO = "2.6" const val apacheIO = "2.6"
const val asm = "9.2"
const val fastutil = "8.5.6" const val fastutil = "8.5.6"
} }
} }

View File

@@ -0,0 +1,26 @@
package com.dfsek.terra.addon.loader;
import ca.solostudios.strata.version.Version;
import com.dfsek.terra.api.addon.BaseAddon;
public class ApiAddon implements BaseAddon {
private final Version version;
private final String id;
public ApiAddon(Version version, String id) {
this.version = version;
this.id = id;
}
@Override
public Version getVersion() {
return version;
}
@Override
public String getID() {
return id;
}
}

View File

@@ -0,0 +1,22 @@
/*
* Copyright (c) 2020-2021 Polyhedral Development
*
* The Terra Core Addons are licensed under the terms of the MIT License. For more details,
* reference the LICENSE file in this module's root directory.
*/
package com.dfsek.terra.addon.loader;
import java.net.URL;
import java.net.URLClassLoader;
public class ApiAddonClassLoader extends URLClassLoader {
static {
ClassLoader.registerAsParallelCapable();
}
public ApiAddonClassLoader(URL[] urls, ClassLoader parent) {
super(urls, parent);
}
}

View File

@@ -14,6 +14,7 @@ import java.nio.file.Path;
import java.util.Collections; import java.util.Collections;
import com.dfsek.terra.api.addon.BaseAddon; import com.dfsek.terra.api.addon.BaseAddon;
import com.dfsek.terra.api.addon.bootstrap.BootstrapAddonClassLoader;
import com.dfsek.terra.api.addon.bootstrap.BootstrapBaseAddon; import com.dfsek.terra.api.addon.bootstrap.BootstrapBaseAddon;
@@ -21,7 +22,8 @@ public class ApiAddonLoader implements BootstrapBaseAddon<BaseAddon> {
private static final Version VERSION = Versions.getVersion(1, 0, 0); private static final Version VERSION = Versions.getVersion(1, 0, 0);
@Override @Override
public Iterable<BaseAddon> loadAddons(Path addonsFolder, ClassLoader parent) { public Iterable<BaseAddon> loadAddons(Path addonsFolder, BootstrapAddonClassLoader parent) {
return Collections.emptySet(); return Collections.emptySet();
} }

View File

@@ -1,5 +1,5 @@
version = version("0.1.0") version = version("0.1.0")
dependencies { dependencies {
compileOnly(project(":common:addons:manifest-addon-loader")) compileOnlyApi(project(":common:addons:manifest-addon-loader"))
} }

View File

@@ -1,5 +1,5 @@
version = version("0.1.0") version = version("0.1.0")
dependencies { dependencies {
compileOnly(project(":common:addons:manifest-addon-loader")) compileOnlyApi(project(":common:addons:manifest-addon-loader"))
} }

View File

@@ -1,5 +1,5 @@
version = version("0.1.0") version = version("0.1.0")
dependencies { dependencies {
compileOnly(project(":common:addons:manifest-addon-loader")) compileOnlyApi(project(":common:addons:manifest-addon-loader"))
} }

View File

@@ -1,5 +1,5 @@
version = version("0.1.0") version = version("0.1.0")
dependencies { dependencies {
compileOnly(project(":common:addons:manifest-addon-loader")) compileOnlyApi(project(":common:addons:manifest-addon-loader"))
} }

View File

@@ -1,5 +1,5 @@
version = version("0.1.0") version = version("0.1.0")
dependencies { dependencies {
compileOnly(project(":common:addons:manifest-addon-loader")) compileOnlyApi(project(":common:addons:manifest-addon-loader"))
} }

View File

@@ -1,5 +1,5 @@
version = version("0.1.0") version = version("0.1.0")
dependencies { dependencies {
compileOnly(project(":common:addons:manifest-addon-loader")) compileOnlyApi(project(":common:addons:manifest-addon-loader"))
} }

View File

@@ -1,5 +1,5 @@
version = version("0.1.0") version = version("0.1.0")
dependencies { dependencies {
compileOnly(project(":common:addons:manifest-addon-loader")) compileOnlyApi(project(":common:addons:manifest-addon-loader"))
} }

View File

@@ -1,5 +1,5 @@
version = version("0.1.0") version = version("0.1.0")
dependencies { dependencies {
compileOnly(project(":common:addons:manifest-addon-loader")) compileOnlyApi(project(":common:addons:manifest-addon-loader"))
} }

View File

@@ -1,5 +1,5 @@
version = version("0.1.0") version = version("0.1.0")
dependencies { dependencies {
compileOnly(project(":common:addons:manifest-addon-loader")) compileOnlyApi(project(":common:addons:manifest-addon-loader"))
} }

View File

@@ -1,5 +1,5 @@
version = version("0.1.0") version = version("0.1.0")
dependencies { dependencies {
compileOnly(project(":common:addons:manifest-addon-loader")) compileOnlyApi(project(":common:addons:manifest-addon-loader"))
} }

View File

@@ -1,5 +1,5 @@
version = version("0.1.0") version = version("0.1.0")
dependencies { dependencies {
compileOnly(project(":common:addons:manifest-addon-loader")) compileOnlyApi(project(":common:addons:manifest-addon-loader"))
} }

View File

@@ -1,5 +1,5 @@
version = version("0.1.0") version = version("0.1.0")
dependencies { dependencies {
compileOnly(project(":common:addons:manifest-addon-loader")) compileOnlyApi(project(":common:addons:manifest-addon-loader"))
} }

View File

@@ -1,5 +1,5 @@
version = version("0.1.0") version = version("0.1.0")
dependencies { dependencies {
compileOnly(project(":common:addons:manifest-addon-loader")) compileOnlyApi(project(":common:addons:manifest-addon-loader"))
} }

View File

@@ -2,16 +2,12 @@ import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
version = version("0.1.0") version = version("0.1.0")
plugins {
id("com.github.johnrengelman.shadow")
}
dependencies { dependencies {
compileOnly(project(":common:addons:manifest-addon-loader")) compileOnlyApi(project(":common:addons:manifest-addon-loader"))
implementation("com.dfsek", "paralithic", Versions.Libraries.paralithic) api("com.dfsek", "paralithic", Versions.Libraries.paralithic)
} }
tasks.named<ShadowJar>("shadowJar") { tasks.named<ShadowJar>("shadowJar") {
relocate("com.dfsek.paralithic", "com.dfsek.terra.addons.noise.lib.paralithic") relocate("com.dfsek.paralithic", "com.dfsek.terra.addons.noise.lib.paralithic")
} }

View File

@@ -32,6 +32,7 @@ import com.dfsek.terra.addons.noise.config.templates.noise.fractal.RidgedFractal
import com.dfsek.terra.addons.noise.config.templates.normalizer.ClampNormalizerTemplate; import com.dfsek.terra.addons.noise.config.templates.normalizer.ClampNormalizerTemplate;
import com.dfsek.terra.addons.noise.config.templates.normalizer.LinearNormalizerTemplate; import com.dfsek.terra.addons.noise.config.templates.normalizer.LinearNormalizerTemplate;
import com.dfsek.terra.addons.noise.config.templates.normalizer.NormalNormalizerTemplate; import com.dfsek.terra.addons.noise.config.templates.normalizer.NormalNormalizerTemplate;
import com.dfsek.terra.addons.noise.config.templates.normalizer.PosterizationNormalizerTemplate;
import com.dfsek.terra.addons.noise.config.templates.normalizer.ProbabilityNormalizerTemplate; import com.dfsek.terra.addons.noise.config.templates.normalizer.ProbabilityNormalizerTemplate;
import com.dfsek.terra.addons.noise.config.templates.normalizer.ScaleNormalizerTemplate; import com.dfsek.terra.addons.noise.config.templates.normalizer.ScaleNormalizerTemplate;
import com.dfsek.terra.addons.noise.samplers.arithmetic.AdditionSampler; import com.dfsek.terra.addons.noise.samplers.arithmetic.AdditionSampler;
@@ -90,6 +91,7 @@ public class NoiseAddon implements AddonInitializer {
noiseRegistry.register(addon.key("CLAMP"), ClampNormalizerTemplate::new); noiseRegistry.register(addon.key("CLAMP"), ClampNormalizerTemplate::new);
noiseRegistry.register(addon.key("PROBABILITY"), ProbabilityNormalizerTemplate::new); noiseRegistry.register(addon.key("PROBABILITY"), ProbabilityNormalizerTemplate::new);
noiseRegistry.register(addon.key("SCALE"), ScaleNormalizerTemplate::new); noiseRegistry.register(addon.key("SCALE"), ScaleNormalizerTemplate::new);
noiseRegistry.register(addon.key("POSTERIZATION"), PosterizationNormalizerTemplate::new);
noiseRegistry.register(addon.key("IMAGE"), ImageSamplerTemplate::new); noiseRegistry.register(addon.key("IMAGE"), ImageSamplerTemplate::new);
@@ -121,7 +123,6 @@ public class NoiseAddon implements AddonInitializer {
noiseRegistry.register(addon.key("LINEAR_HEIGHTMAP"), LinearHeightmapSamplerTemplate::new); noiseRegistry.register(addon.key("LINEAR_HEIGHTMAP"), LinearHeightmapSamplerTemplate::new);
noiseRegistry.register(addon.key("ADD"), () -> new BinaryArithmeticTemplate<>(AdditionSampler::new)); noiseRegistry.register(addon.key("ADD"), () -> new BinaryArithmeticTemplate<>(AdditionSampler::new));
noiseRegistry.register(addon.key("SUB"), () -> new BinaryArithmeticTemplate<>(SubtractionSampler::new)); noiseRegistry.register(addon.key("SUB"), () -> new BinaryArithmeticTemplate<>(SubtractionSampler::new));
noiseRegistry.register(addon.key("MUL"), () -> new BinaryArithmeticTemplate<>(MultiplicationSampler::new)); noiseRegistry.register(addon.key("MUL"), () -> new BinaryArithmeticTemplate<>(MultiplicationSampler::new));

View File

@@ -0,0 +1,26 @@
/*
* Copyright (c) 2022 Polyhedral Development
*
* The Terra Core Addons are licensed under the terms of the MIT License. For more details,
* reference the LICENSE file in this module's root directory.
*/
package com.dfsek.terra.addons.noise.config.templates.normalizer;
import com.dfsek.tectonic.api.config.template.annotations.Value;
import com.dfsek.terra.addons.noise.normalizer.PosterizationNormalizer;
import com.dfsek.terra.api.config.meta.Meta;
import com.dfsek.terra.api.noise.NoiseSampler;
@SuppressWarnings({ "unused", "FieldMayBeFinal" })
public class PosterizationNormalizerTemplate extends NormalizerTemplate<PosterizationNormalizer> {
@Value("steps")
private @Meta int steps;
@Override
public NoiseSampler get() {
return new PosterizationNormalizer(function, steps);
}
}

View File

@@ -0,0 +1,26 @@
/*
* Copyright (c) 2022 Polyhedral Development
*
* The Terra Core Addons are licensed under the terms of the MIT License. For more details,
* reference the LICENSE file in this module's root directory.
*/
package com.dfsek.terra.addons.noise.normalizer;
import com.dfsek.terra.api.noise.NoiseSampler;
import net.jafama.FastMath;
public class PosterizationNormalizer extends Normalizer {
private final double stepSize;
public PosterizationNormalizer(NoiseSampler sampler, int steps) {
super(sampler);
this.stepSize = 2.0 / (steps - 1);
}
@Override
public double normalize(double in) {
return FastMath.roundToInt((in + 1) / stepSize) * stepSize - 1;
}
}

View File

@@ -1,5 +1,5 @@
version = version("0.1.0") version = version("0.1.0")
dependencies { dependencies {
compileOnly(project(":common:addons:manifest-addon-loader")) compileOnlyApi(project(":common:addons:manifest-addon-loader"))
} }

View File

@@ -1,5 +1,5 @@
version = version("0.1.0") version = version("0.1.0")
dependencies { dependencies {
compileOnly(project(":common:addons:manifest-addon-loader")) compileOnlyApi(project(":common:addons:manifest-addon-loader"))
} }

View File

@@ -2,5 +2,5 @@ version = version("0.1.0")
dependencies { dependencies {
api("com.googlecode.json-simple:json-simple:1.1.1") api("com.googlecode.json-simple:json-simple:1.1.1")
compileOnly(project(":common:addons:manifest-addon-loader")) compileOnlyApi(project(":common:addons:manifest-addon-loader"))
} }

View File

@@ -1,5 +1,5 @@
version = version("0.1.0") version = version("0.1.0")
dependencies { dependencies {
compileOnly(project(":common:addons:manifest-addon-loader")) compileOnlyApi(project(":common:addons:manifest-addon-loader"))
} }

View File

@@ -1,5 +1,5 @@
version = version("0.1.0") version = version("0.1.0")
dependencies { dependencies {
compileOnly(project(":common:addons:manifest-addon-loader")) compileOnlyApi(project(":common:addons:manifest-addon-loader"))
} }

View File

@@ -2,5 +2,5 @@ version = version("0.1.0")
dependencies { dependencies {
implementation("com.dfsek.tectonic:yaml:${Versions.Libraries.tectonic}") implementation("com.dfsek.tectonic:yaml:${Versions.Libraries.tectonic}")
compileOnly(project(":common:addons:manifest-addon-loader")) compileOnlyApi(project(":common:addons:manifest-addon-loader"))
} }

View File

@@ -1,7 +1,7 @@
version = version("0.1.0") version = version("0.1.0")
dependencies { dependencies {
api("commons-io:commons-io:2.6") api("commons-io:commons-io:2.7")
implementation("com.dfsek.tectonic:yaml:${Versions.Libraries.tectonic}") implementation("com.dfsek.tectonic:yaml:${Versions.Libraries.tectonic}")
} }

View File

@@ -13,6 +13,9 @@ import ca.solostudios.strata.version.VersionRange;
import com.dfsek.tectonic.api.exception.LoadException; import com.dfsek.tectonic.api.exception.LoadException;
import com.dfsek.tectonic.api.loader.ConfigLoader; import com.dfsek.tectonic.api.loader.ConfigLoader;
import com.dfsek.tectonic.yaml.YamlConfiguration; import com.dfsek.tectonic.yaml.YamlConfiguration;
import com.dfsek.terra.api.addon.bootstrap.BootstrapAddonClassLoader;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@@ -72,13 +75,9 @@ public class ManifestAddonLoader implements BootstrapBaseAddon<ManifestAddon> {
throw new AddonException("Addon " + manifest.getID() + " has unknown schema version: " + manifest.getSchemaVersion()); throw new AddonException("Addon " + manifest.getID() + " has unknown schema version: " + manifest.getSchemaVersion());
} }
@SuppressWarnings({ "IOResourceOpenedButNotSafelyClosed", "resource" })
ManifestAddonClassLoader childLoader = new ManifestAddonClassLoader(new URL[]{ addonPath.toUri().toURL() },
loader);
List<AddonInitializer> initializers = manifest.getEntryPoints().stream().map(entryPoint -> { List<AddonInitializer> initializers = manifest.getEntryPoints().stream().map(entryPoint -> {
try { try {
Object in = childLoader.loadClass(entryPoint).getConstructor().newInstance(); Object in = loader.loadClass(entryPoint).getConstructor().newInstance();
if(!(in instanceof AddonInitializer)) { if(!(in instanceof AddonInitializer)) {
throw new AddonException(in.getClass() + " does not extend " + AddonInitializer.class); throw new AddonException(in.getClass() + " does not extend " + AddonInitializer.class);
} }
@@ -103,7 +102,7 @@ public class ManifestAddonLoader implements BootstrapBaseAddon<ManifestAddon> {
} }
@Override @Override
public Iterable<ManifestAddon> loadAddons(Path addonsFolder, ClassLoader parent) { public Iterable<ManifestAddon> loadAddons(Path addonsFolder, BootstrapAddonClassLoader parent) {
logger.debug("Loading addons..."); logger.debug("Loading addons...");
try(Stream<Path> files = Files.walk(addonsFolder, 1, FileVisitOption.FOLLOW_LINKS)) { try(Stream<Path> files = Files.walk(addonsFolder, 1, FileVisitOption.FOLLOW_LINKS)) {
@@ -114,16 +113,16 @@ public class ManifestAddonLoader implements BootstrapBaseAddon<ManifestAddon> {
.filter(path -> path.toString().endsWith(".jar")) .filter(path -> path.toString().endsWith(".jar"))
.toList(); .toList();
ManifestAddonClassLoader loader = new ManifestAddonClassLoader(addons.stream().map(path -> { addons.stream().map(path -> {
try { try {
return path.toUri().toURL(); return path.toUri().toURL();
} catch(MalformedURLException e) { } catch(MalformedURLException e) {
throw new UncheckedIOException(e); throw new UncheckedIOException(e);
} }
}).toArray(URL[]::new), getClass().getClassLoader()); }).forEach(parent::addURL);
return addons.stream() return addons.stream()
.map(jar -> loadAddon(jar, loader)) .map(jar -> loadAddon(jar, parent))
.collect(Collectors.toList()); .collect(Collectors.toList());
} catch(IOException e) { } catch(IOException e) {
throw new UncheckedIOException(e); throw new UncheckedIOException(e);

View File

@@ -1,5 +1,5 @@
version = version("0.1.0") version = version("0.1.0")
dependencies { dependencies {
compileOnly(project(":common:addons:manifest-addon-loader")) compileOnlyApi(project(":common:addons:manifest-addon-loader"))
} }

View File

@@ -1,5 +1,5 @@
version = version("0.1.0") version = version("0.1.0")
dependencies { dependencies {
compileOnly(project(":common:addons:manifest-addon-loader")) compileOnlyApi(project(":common:addons:manifest-addon-loader"))
} }

View File

@@ -1,5 +1,5 @@
version = version("0.1.0") version = version("0.1.0")
dependencies { dependencies {
compileOnly(project(":common:addons:manifest-addon-loader")) compileOnlyApi(project(":common:addons:manifest-addon-loader"))
} }

View File

@@ -2,10 +2,6 @@ import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
version = version("0.1.0") version = version("0.1.0")
plugins {
id("com.github.johnrengelman.shadow")
}
repositories { repositories {
maven { url = uri("https://jitpack.io/") } maven { url = uri("https://jitpack.io/") }
} }
@@ -13,9 +9,9 @@ repositories {
dependencies { dependencies {
api("commons-io:commons-io:2.7") api("commons-io:commons-io:2.7")
api("com.github.Querz:NBT:6.1") api("com.github.Querz:NBT:6.1")
compileOnly(project(":common:addons:manifest-addon-loader")) compileOnlyApi(project(":common:addons:manifest-addon-loader"))
} }
tasks.named<ShadowJar>("shadowJar") { tasks.named<ShadowJar>("shadowJar") {
relocate("org.apache.commons", "com.dfsek.terra.addons.sponge.lib.commons") relocate("org.apache.commons", "com.dfsek.terra.addons.sponge.lib.commons")
} }

View File

@@ -2,14 +2,9 @@ import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
version = version("0.1.0") version = version("0.1.0")
plugins {
id("com.github.johnrengelman.shadow")
}
dependencies { dependencies {
api("commons-io:commons-io:2.7") api("commons-io:commons-io:2.7")
compileOnly(project(":common:addons:manifest-addon-loader")) compileOnlyApi(project(":common:addons:manifest-addon-loader"))
} }
tasks.named<ShadowJar>("shadowJar") { tasks.named<ShadowJar>("shadowJar") {

View File

@@ -1,7 +1,7 @@
version = version("0.1.0") version = version("0.1.0")
dependencies { dependencies {
compileOnly(project(":common:addons:manifest-addon-loader")) compileOnlyApi(project(":common:addons:manifest-addon-loader"))
api(project(":common:addons:chunk-generator-noise-3d")) compileOnlyApi(project(":common:addons:chunk-generator-noise-3d"))
api(project(":common:addons:structure-terrascript-loader")) compileOnlyApi(project(":common:addons:structure-terrascript-loader"))
} }

View File

@@ -1,7 +1,7 @@
version = version("0.1.0") version = version("0.1.0")
dependencies { dependencies {
compileOnly(project(":common:addons:manifest-addon-loader")) compileOnlyApi(project(":common:addons:manifest-addon-loader"))
api(project(":common:addons:config-noise-function")) compileOnlyApi(project(":common:addons:config-noise-function"))
api(project(":common:addons:structure-terrascript-loader")) compileOnlyApi(project(":common:addons:structure-terrascript-loader"))
} }

View File

@@ -1,9 +1,10 @@
dependencies { dependencies {
compileOnlyApi("ca.solo-studios", "strata", Versions.Libraries.strata) api("ca.solo-studios", "strata", Versions.Libraries.strata)
compileOnlyApi("org.slf4j", "slf4j-api", Versions.Libraries.slf4j) api("org.slf4j", "slf4j-api", Versions.Libraries.slf4j)
compileOnlyApi("cloud.commandframework", "cloud-core", Versions.Libraries.cloud) api("cloud.commandframework", "cloud-core", Versions.Libraries.cloud)
compileOnlyApi("com.dfsek.tectonic", "common", Versions.Libraries.tectonic) api("com.dfsek.tectonic", "common", Versions.Libraries.tectonic)
compileOnlyApi("net.jafama", "jafama", Versions.Libraries.Internal.jafama)
implementation("net.jafama", "jafama", Versions.Libraries.Internal.jafama)
} }

View File

@@ -0,0 +1,33 @@
package com.dfsek.terra.api.addon.bootstrap;
import java.net.URL;
import java.net.URLClassLoader;
import java.net.URLStreamHandlerFactory;
public class BootstrapAddonClassLoader extends URLClassLoader {
public BootstrapAddonClassLoader(URL[] urls, ClassLoader parent) {
super(urls, parent);
}
public BootstrapAddonClassLoader(URL[] urls) {
super(urls);
}
public BootstrapAddonClassLoader(URL[] urls, ClassLoader parent, URLStreamHandlerFactory factory) {
super(urls, parent, factory);
}
public BootstrapAddonClassLoader(String name, URL[] urls, ClassLoader parent) {
super(name, urls, parent);
}
public BootstrapAddonClassLoader(String name, URL[] urls, ClassLoader parent, URLStreamHandlerFactory factory) {
super(name, urls, parent, factory);
}
@Override
public void addURL(URL url) {
super.addURL(url);
}
}

View File

@@ -32,5 +32,5 @@ public interface BootstrapBaseAddon<T extends BaseAddon> extends BaseAddon {
* *
* @return Loaded addons * @return Loaded addons
*/ */
Iterable<T> loadAddons(Path addonsFolder, ClassLoader parent); Iterable<T> loadAddons(Path addonsFolder, BootstrapAddonClassLoader parent);
} }

View File

@@ -3,22 +3,11 @@ dependencies {
api(project(":common:implementation:bootstrap-addon-loader")) api(project(":common:implementation:bootstrap-addon-loader"))
implementation("commons-io", "commons-io", Versions.Libraries.Internal.apacheIO) implementation("commons-io", "commons-io", Versions.Libraries.Internal.apacheIO)
implementation("org.apache.commons", "commons-text", Versions.Libraries.Internal.apacheText) implementation("org.apache.commons", "commons-text", Versions.Libraries.Internal.apacheText)
implementation("com.dfsek.tectonic", "yaml", Versions.Libraries.tectonic) implementation("com.dfsek.tectonic", "yaml", Versions.Libraries.tectonic)
implementation("com.dfsek.tectonic", "common", Versions.Libraries.tectonic)
implementation("com.dfsek", "paralithic", Versions.Libraries.paralithic)
implementation("ca.solo-studios", "strata", Versions.Libraries.strata)
implementation("cloud.commandframework", "cloud-core", Versions.Libraries.cloud)
implementation("net.jafama", "jafama", Versions.Libraries.Internal.jafama) implementation("net.jafama", "jafama", Versions.Libraries.Internal.jafama)
implementation("org.ow2.asm", "asm", Versions.Libraries.Internal.asm) implementation("com.dfsek", "paralithic", Versions.Libraries.paralithic)
testImplementation("org.slf4j", "slf4j-api", Versions.Libraries.slf4j)
} }

View File

@@ -18,6 +18,9 @@
package com.dfsek.terra; package com.dfsek.terra;
import com.dfsek.tectonic.api.TypeRegistry; import com.dfsek.tectonic.api.TypeRegistry;
import com.dfsek.terra.api.addon.bootstrap.BootstrapAddonClassLoader;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@@ -31,6 +34,7 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.UncheckedIOException; import java.io.UncheckedIOException;
import java.net.URL;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.ArrayList; import java.util.ArrayList;
@@ -162,12 +166,14 @@ public abstract class AbstractPlatform implements Platform {
Injector<Platform> platformInjector = new InjectorImpl<>(this); Injector<Platform> platformInjector = new InjectorImpl<>(this);
platformInjector.addExplicitTarget(Platform.class); platformInjector.addExplicitTarget(Platform.class);
BootstrapAddonClassLoader bootstrapAddonClassLoader = new BootstrapAddonClassLoader(new URL[] {}, getClass().getClassLoader());
bootstrapAddonLoader.loadAddons(addonsFolder, getClass().getClassLoader()) bootstrapAddonLoader.loadAddons(addonsFolder, bootstrapAddonClassLoader)
.forEach(bootstrapAddon -> { .forEach(bootstrapAddon -> {
platformInjector.inject(bootstrapAddon); platformInjector.inject(bootstrapAddon);
bootstrapAddon.loadAddons(addonsFolder, getClass().getClassLoader()) bootstrapAddon.loadAddons(addonsFolder, bootstrapAddonClassLoader)
.forEach(addonList::add); .forEach(addonList::add);
}); });

View File

@@ -1,3 +1,3 @@
dependencies { dependencies {
"api"(project(":common:api")) compileOnlyApi(project(":common:api"))
} }

View File

@@ -1,32 +0,0 @@
/*
* This file is part of Terra.
*
* Terra is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Terra is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
*/
package com.dfsek.terra.addon;
import java.net.URL;
import java.net.URLClassLoader;
public class AddonClassLoader extends URLClassLoader {
static {
ClassLoader.registerAsParallelCapable();
}
public AddonClassLoader(URL[] urls, ClassLoader parent) {
super(urls, parent);
}
}

View File

@@ -19,6 +19,7 @@ package com.dfsek.terra.addon;
import ca.solostudios.strata.Versions; import ca.solostudios.strata.Versions;
import ca.solostudios.strata.version.Version; import ca.solostudios.strata.version.Version;
import com.dfsek.terra.api.addon.bootstrap.BootstrapAddonClassLoader;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@@ -43,7 +44,7 @@ public class BootstrapAddonLoader implements BootstrapBaseAddon<BootstrapBaseAdd
public BootstrapAddonLoader() { } public BootstrapAddonLoader() { }
private BootstrapBaseAddon<?> loadAddon(Path addonPath, ClassLoader parent) { private BootstrapBaseAddon<?> loadAddon(Path addonPath, BootstrapAddonClassLoader parent) {
logger.debug("Loading bootstrap addon from JAR {}", addonPath); logger.debug("Loading bootstrap addon from JAR {}", addonPath);
try(JarFile jar = new JarFile(addonPath.toFile())) { try(JarFile jar = new JarFile(addonPath.toFile())) {
String entry = jar.getManifest().getMainAttributes().getValue("Terra-Bootstrap-Addon-Entry-Point"); String entry = jar.getManifest().getMainAttributes().getValue("Terra-Bootstrap-Addon-Entry-Point");
@@ -54,10 +55,8 @@ public class BootstrapAddonLoader implements BootstrapBaseAddon<BootstrapBaseAdd
//noinspection NestedTryStatement //noinspection NestedTryStatement
try { try {
@SuppressWarnings({ "resource", "IOResourceOpenedButNotSafelyClosed" }) parent.addURL(addonPath.toUri().toURL());
AddonClassLoader loader = new AddonClassLoader(new URL[]{ addonPath.toUri().toURL() }, parent); Object addonObject = parent.loadClass(entry).getConstructor().newInstance();
Object addonObject = loader.loadClass(entry).getConstructor().newInstance();
if(!(addonObject instanceof BootstrapBaseAddon<?> addon)) { if(!(addonObject instanceof BootstrapBaseAddon<?> addon)) {
throw new AddonLoadException( throw new AddonLoadException(
@@ -81,7 +80,7 @@ public class BootstrapAddonLoader implements BootstrapBaseAddon<BootstrapBaseAdd
} }
@Override @Override
public Iterable<BootstrapBaseAddon<?>> loadAddons(Path addonsFolder, ClassLoader parent) { public Iterable<BootstrapBaseAddon<?>> loadAddons(Path addonsFolder, BootstrapAddonClassLoader parent) {
Path bootstrapFolder = addonsFolder.resolve("bootstrap"); Path bootstrapFolder = addonsFolder.resolve("bootstrap");
logger.debug("Loading bootstrap addons from {}", bootstrapFolder); logger.debug("Loading bootstrap addons from {}", bootstrapFolder);

View File

@@ -14,7 +14,7 @@ val paperURL = "https://papermc.io/api/v2/projects/paper/versions/%version%/buil
val purpurURL = "https://api.pl3x.net/v2/purpur/%version%/latest/download" val purpurURL = "https://api.pl3x.net/v2/purpur/%version%/latest/download"
dependencies { dependencies {
api(project(":common:implementation:base")) shadedApi(project(":common:implementation:base"))
api("org.slf4j:slf4j-api:1.8.0-beta4") { api("org.slf4j:slf4j-api:1.8.0-beta4") {
because("Minecraft 1.17+ includes slf4j 1.8.0-beta4, so we need to shade it for other versions.") because("Minecraft 1.17+ includes slf4j 1.8.0-beta4, so we need to shade it for other versions.")
@@ -24,11 +24,11 @@ dependencies {
} }
compileOnly("io.papermc.paper", "paper-api", Versions.Bukkit.paper) compileOnly("io.papermc.paper", "paper-api", Versions.Bukkit.paper)
implementation("io.papermc", "paperlib", Versions.Bukkit.paperLib) shadedApi("io.papermc", "paperlib", Versions.Bukkit.paperLib)
api("com.google.guava:guava:30.0-jre") shadedApi("com.google.guava:guava:30.0-jre")
api("cloud.commandframework", "cloud-paper", Versions.Libraries.cloud) shadedApi("cloud.commandframework", "cloud-paper", Versions.Libraries.cloud)
} }
val jvmFlags = listOf( val jvmFlags = listOf(

View File

@@ -6,6 +6,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.Optional; import java.util.Optional;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Supplier; import java.util.function.Supplier;
import com.dfsek.terra.api.block.entity.BlockEntity; import com.dfsek.terra.api.block.entity.BlockEntity;
@@ -29,6 +30,8 @@ public class BukkitProtoWorld implements ProtoWorld {
private final LimitedRegion delegate; private final LimitedRegion delegate;
private final BlockState air; private final BlockState air;
private static final AtomicBoolean warn = new AtomicBoolean(true);
public BukkitProtoWorld(LimitedRegion delegate, BlockState air) { public BukkitProtoWorld(LimitedRegion delegate, BlockState air) {
this.delegate = delegate; this.delegate = delegate;
this.air = air; this.air = air;
@@ -114,19 +117,25 @@ public class BukkitProtoWorld implements ProtoWorld {
private <T> Optional<T> access(int x, int y, int z, Supplier<T> action) { private <T> Optional<T> access(int x, int y, int z, Supplier<T> action) {
if(delegate.isInRegion(x, y, z)) { if(delegate.isInRegion(x, y, z)) {
return Optional.of(action.get()); return Optional.of(action.get());
} else { } else if(warn.getAndSet(false)) {
LOGGER.warn("Detected world access at coordinates out of bounds: ({}, {}, {}) accessed for region [{}, {}]", x, y, z, LOGGER.warn("Detected world access at coordinates out of bounds: ({}, {}, {}) accessed for region [{}, {}]", x, y, z,
delegate.getCenterChunkX(), delegate.getCenterChunkZ()); delegate.getCenterChunkX(), delegate.getCenterChunkZ());
return Optional.empty(); } else {
LOGGER.debug("Detected world access at coordinates out of bounds: ({}, {}, {}) accessed for region [{}, {}]", x, y, z,
delegate.getCenterChunkX(), delegate.getCenterChunkZ());
} }
return Optional.empty();
} }
private void access(int x, int y, int z, Runnable action) { private void access(int x, int y, int z, Runnable action) {
if(delegate.isInRegion(x, y, z)) { if(delegate.isInRegion(x, y, z)) {
action.run(); action.run();
} else { } else if(warn.getAndSet(false)) {
LOGGER.warn("Detected world access at coordinates out of bounds: ({}, {}, {}) accessed for region [{}, {}]", x, y, z, LOGGER.warn("Detected world access at coordinates out of bounds: ({}, {}, {}) accessed for region [{}, {}]", x, y, z,
delegate.getCenterChunkX(), delegate.getCenterChunkZ()); delegate.getCenterChunkX(), delegate.getCenterChunkZ());
} else {
LOGGER.debug("Detected world access at coordinates out of bounds: ({}, {}, {}) accessed for region [{}, {}]", x, y, z,
delegate.getCenterChunkX(), delegate.getCenterChunkZ());
} }
} }
} }

View File

@@ -3,13 +3,13 @@ repositories {
} }
dependencies { dependencies {
api("commons-io:commons-io:2.6") shadedApi("commons-io:commons-io:2.7")
api("com.github.Querz:NBT:6.1") shadedApi("com.github.Querz:NBT:6.1")
api(project(":common:implementation:base")) shadedApi(project(":common:implementation:base"))
implementation("com.google.guava:guava:31.0.1-jre") shadedImplementation("com.google.guava:guava:31.0.1-jre")
implementation("ch.qos.logback:logback-classic:1.2.7") shadedImplementation("ch.qos.logback:logback-classic:1.2.9")
implementation("net.jafama", "jafama", Versions.Libraries.Internal.jafama) implementation("net.jafama", "jafama", Versions.Libraries.Internal.jafama)
} }

View File

@@ -13,7 +13,9 @@ import com.dfsek.terra.fabric.util.FabricUtil;
@Mixin(DataPackContents.class) @Mixin(DataPackContents.class)
public class DataPackContentsMixin { public class DataPackContentsMixin {
/*
* #refresh populates all tags in the registries
*/
@Inject(method = "refresh(Lnet/minecraft/util/registry/DynamicRegistryManager;)V", at = @At("RETURN")) @Inject(method = "refresh(Lnet/minecraft/util/registry/DynamicRegistryManager;)V", at = @At("RETURN"))
private void injectReload(DynamicRegistryManager dynamicRegistryManager, CallbackInfo ci) { private void injectReload(DynamicRegistryManager dynamicRegistryManager, CallbackInfo ci) {
FabricUtil.registerTags(dynamicRegistryManager.get(Registry.BIOME_KEY)); FabricUtil.registerTags(dynamicRegistryManager.get(Registry.BIOME_KEY));

View File

@@ -3,7 +3,7 @@ val platformOverrides = mapOf(
) )
dependencies { dependencies {
api(project(":common:implementation")) api(project(":common:implementation:base"))
} }
val taskSet = HashSet<AbstractArchiveTask>() val taskSet = HashSet<AbstractArchiveTask>()