From aeb0372d594b89ef9c7faa63009dd8254e63eb28 Mon Sep 17 00:00:00 2001 From: dfsek Date: Sun, 19 Dec 2021 15:30:50 -0700 Subject: [PATCH] pull versions out to Versions config --- build.gradle.kts | 2 + buildSrc/src/main/kotlin/Versions.kt | 15 ++++ common/api/addons/build.gradle.kts | 2 +- common/api/core/build.gradle.kts | 6 +- common/api/inject/build.gradle.kts | 2 - common/api/noise/build.gradle.kts | 4 +- common/api/util/build.gradle.kts | 4 +- common/implementation/base/build.gradle.kts | 11 ++- .../loaders/config/GridSpawnLoader.java | 37 -------- .../java/com/dfsek/terra/math/GridSpawn.java | 86 ------------------- .../java/com/dfsek/terra/util/FastRandom.java | 86 ------------------- platforms/bukkit/build.gradle.kts | 2 +- platforms/sponge/build.gradle.kts | 10 +-- 13 files changed, 36 insertions(+), 231 deletions(-) delete mode 100644 common/implementation/base/src/main/java/com/dfsek/terra/config/loaders/config/GridSpawnLoader.java delete mode 100644 common/implementation/base/src/main/java/com/dfsek/terra/math/GridSpawn.java delete mode 100644 common/implementation/base/src/main/java/com/dfsek/terra/util/FastRandom.java diff --git a/build.gradle.kts b/build.gradle.kts index b159900df..49abd6a90 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -46,6 +46,8 @@ afterEvaluate { forSubProjects(":common:addons") { dependencies { "compileOnly"(project(":common:api")) + "shadedImplementation"("net.jafama", "jafama", Versions.Libraries.Internal.jafama) + "testImplementation"("net.jafama", "jafama", Versions.Libraries.Internal.jafama) "testImplementation"(project(":common:api")) } } diff --git a/buildSrc/src/main/kotlin/Versions.kt b/buildSrc/src/main/kotlin/Versions.kt index 225ac7e4d..0a369395e 100644 --- a/buildSrc/src/main/kotlin/Versions.kt +++ b/buildSrc/src/main/kotlin/Versions.kt @@ -1,11 +1,20 @@ object Versions { object Libraries { const val tectonic = "3.1.0" + const val paralithic = "0.6.0" + const val strata = "1.1.1" const val cloud = "1.6.1" const val slf4j = "1.7.32" const val log4j_slf4j_impl = "2.14.1" + + object Internal { + const val apacheText = "1.9" + const val jafama = "2.3.2" + const val apacheIO = "2.6" + const val asm = "9.2" + } } object Fabric { @@ -18,4 +27,10 @@ object Versions { const val paper = "1.18-R0.1-SNAPSHOT" const val paperLib = "1.0.5" } + + object Sponge { + const val sponge = "9.0.0-SNAPSHOT" + const val mixin = "0.8.2" + const val minecraft = "1.17.1" + } } \ No newline at end of file diff --git a/common/api/addons/build.gradle.kts b/common/api/addons/build.gradle.kts index 87ca3b8ec..9ca59c852 100644 --- a/common/api/addons/build.gradle.kts +++ b/common/api/addons/build.gradle.kts @@ -1,4 +1,4 @@ dependencies { shadedApi(project(":common:api:util")) - shadedApi("ca.solo-studios:strata:1.1.1") + shadedApi("ca.solo-studios", "strata", Versions.Libraries.strata) } diff --git a/common/api/core/build.gradle.kts b/common/api/core/build.gradle.kts index fd78cef39..6478aaddf 100644 --- a/common/api/core/build.gradle.kts +++ b/common/api/core/build.gradle.kts @@ -4,10 +4,10 @@ dependencies { shadedApi(project(":common:api:registry")) shadedApi(project(":common:api:addons")) - shadedApi("net.jafama:jafama:2.3.2") - shadedApi("org.slf4j", "slf4j-api", Versions.Libraries.slf4j) + shadedApi("cloud.commandframework", "cloud-core", Versions.Libraries.cloud) - shadedApi("cloud.commandframework", "cloud-core", "1.6.1") + + shadedImplementation("net.jafama", "jafama", Versions.Libraries.Internal.jafama) } diff --git a/common/api/inject/build.gradle.kts b/common/api/inject/build.gradle.kts index 8519b7689..db0506f53 100644 --- a/common/api/inject/build.gradle.kts +++ b/common/api/inject/build.gradle.kts @@ -1,6 +1,4 @@ dependencies { shadedApi(project(":common:api:util")) - - shadedApi("net.jafama:jafama:2.3.2") } diff --git a/common/api/noise/build.gradle.kts b/common/api/noise/build.gradle.kts index 997e02bcc..69cc69cef 100644 --- a/common/api/noise/build.gradle.kts +++ b/common/api/noise/build.gradle.kts @@ -1,8 +1,8 @@ dependencies { shadedApi(project(":common:api:util")) - shadedApi("com.dfsek:paralithic:0.6.0") + shadedApi("com.dfsek", "paralithic", Versions.Libraries.paralithic) - shadedApi("net.jafama:jafama:2.3.2") + shadedImplementation("net.jafama", "jafama", Versions.Libraries.Internal.jafama) } diff --git a/common/api/util/build.gradle.kts b/common/api/util/build.gradle.kts index b6159649f..65ed8775a 100644 --- a/common/api/util/build.gradle.kts +++ b/common/api/util/build.gradle.kts @@ -1,6 +1,6 @@ dependencies { - shadedApi("com.dfsek.tectonic:common:${Versions.Libraries.tectonic}") + shadedApi("com.dfsek.tectonic", "common", Versions.Libraries.tectonic) - shadedApi("net.jafama:jafama:2.3.2") + shadedImplementation("net.jafama", "jafama", Versions.Libraries.Internal.jafama) } diff --git a/common/implementation/base/build.gradle.kts b/common/implementation/base/build.gradle.kts index 8b78e4d86..d776dc618 100644 --- a/common/implementation/base/build.gradle.kts +++ b/common/implementation/base/build.gradle.kts @@ -2,12 +2,11 @@ dependencies { shadedApi(project(":common:api")) shadedApi(project(":common:implementation:bootstrap-addon-loader")) - shadedApi("org.apache.commons:commons-rng-core:1.3") - shadedApi("commons-io:commons-io:2.6") - shadedImplementation("org.apache.commons:commons-text:1.9") + shadedImplementation("commons-io", "commons-io", Versions.Libraries.Internal.apacheIO) - shadedImplementation("com.dfsek.tectonic:yaml:${Versions.Libraries.tectonic}") + shadedImplementation("org.apache.commons", "commons-text", Versions.Libraries.Internal.apacheText) + shadedImplementation("com.dfsek.tectonic", "yaml", Versions.Libraries.tectonic) - shadedImplementation("org.yaml:snakeyaml:1.27") - shadedImplementation("org.ow2.asm:asm:9.2") + shadedImplementation("net.jafama", "jafama", Versions.Libraries.Internal.jafama) + shadedImplementation("org.ow2.asm", "asm", Versions.Libraries.Internal.asm) } diff --git a/common/implementation/base/src/main/java/com/dfsek/terra/config/loaders/config/GridSpawnLoader.java b/common/implementation/base/src/main/java/com/dfsek/terra/config/loaders/config/GridSpawnLoader.java deleted file mode 100644 index 3d496fb4f..000000000 --- a/common/implementation/base/src/main/java/com/dfsek/terra/config/loaders/config/GridSpawnLoader.java +++ /dev/null @@ -1,37 +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 . - */ - -package com.dfsek.terra.config.loaders.config; - -import com.dfsek.tectonic.api.loader.ConfigLoader; -import com.dfsek.tectonic.api.loader.type.TypeLoader; - -import java.lang.reflect.AnnotatedType; -import java.util.Map; - -import com.dfsek.terra.api.structure.StructureSpawn; -import com.dfsek.terra.math.GridSpawn; - - -@SuppressWarnings("unchecked") -public class GridSpawnLoader implements TypeLoader { - @Override - public StructureSpawn load(AnnotatedType type, Object o, ConfigLoader configLoader) { - Map map = (Map) o; - return new GridSpawn(map.get("width"), map.get("padding"), map.getOrDefault("salt", 0)); - } -} diff --git a/common/implementation/base/src/main/java/com/dfsek/terra/math/GridSpawn.java b/common/implementation/base/src/main/java/com/dfsek/terra/math/GridSpawn.java deleted file mode 100644 index 2a197d29f..000000000 --- a/common/implementation/base/src/main/java/com/dfsek/terra/math/GridSpawn.java +++ /dev/null @@ -1,86 +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 . - */ - -package com.dfsek.terra.math; - -import java.util.ArrayList; -import java.util.List; -import java.util.Random; - -import com.dfsek.terra.api.util.PopulationUtil; -import com.dfsek.terra.api.util.vector.Vector3; -import com.dfsek.terra.util.FastRandom; - - -/** - * Class to procedurally determine the spawn point of an object based on a grid with padding between cells. - */ -public class GridSpawn implements com.dfsek.terra.api.structure.StructureSpawn { - private final int separation; - private final int width; - private final int salt; - - public GridSpawn(int width, int separation, int salt) { - this.separation = separation; - this.width = width; - this.salt = salt; - } - - @Override - public Vector3 getNearestSpawn(int x, int z, long seed) { - int structureChunkX = x / (width + 2 * separation); - int structureChunkZ = z / (width + 2 * separation); - List zones = new ArrayList<>(9); - for(int xi = structureChunkX - 1; xi <= structureChunkX + 1; xi++) { - for(int zi = structureChunkZ - 1; zi <= structureChunkZ + 1; zi++) { - zones.add(getChunkSpawn(xi, zi, seed)); - } - } - Vector3 shortest = zones.get(0); - Vector3 compare = new Vector3(x, 0, z); - for(Vector3 v : zones) { - if(compare.distanceSquared(shortest) > compare.distanceSquared(v)) shortest = v.clone(); - } - return shortest; - } - - /** - * Get the X/Z coordinates of the spawn point in the nearest Chunk (not Minecraft chunk) - * - * @param structureChunkX Chunk X coordinate - * @param structureChunkZ Chunk Z coordinate - * @param seed Seed for RNG - * - * @return Vector representing spawnpoint - */ - public Vector3 getChunkSpawn(int structureChunkX, int structureChunkZ, long seed) { - Random r = new FastRandom(PopulationUtil.getCarverChunkSeed(structureChunkX, structureChunkZ, seed + salt)); - int offsetX = r.nextInt(width); - int offsetZ = r.nextInt(width); - int sx = structureChunkX * (width + 2 * separation) + offsetX; - int sz = structureChunkZ * (width + 2 * separation) + offsetZ; - return new Vector3(sx, 0, sz); - } - - public int getWidth() { - return width; - } - - public int getSeparation() { - return separation; - } -} diff --git a/common/implementation/base/src/main/java/com/dfsek/terra/util/FastRandom.java b/common/implementation/base/src/main/java/com/dfsek/terra/util/FastRandom.java deleted file mode 100644 index ff0776d2a..000000000 --- a/common/implementation/base/src/main/java/com/dfsek/terra/util/FastRandom.java +++ /dev/null @@ -1,86 +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 . - */ - -package com.dfsek.terra.util; - - -import org.apache.commons.rng.core.source64.XoRoShiRo128PlusPlus; - -import java.io.Serial; -import java.util.Random; -import java.util.SplittableRandom; - - -public class FastRandom extends Random { - - @Serial - private static final long serialVersionUID = 4571946470190183260L; - private XoRoShiRo128PlusPlus random; - - public FastRandom() { - super(); - SplittableRandom randomseed = new SplittableRandom(); - this.random = new XoRoShiRo128PlusPlus(randomseed.nextLong(), randomseed.nextLong()); - } - - public FastRandom(long seed) { - super(seed); - SplittableRandom randomseed = new SplittableRandom(seed); - this.random = new XoRoShiRo128PlusPlus(randomseed.nextLong(), randomseed.nextLong()); - } - - @Override - public synchronized void setSeed(long seed) { - SplittableRandom randomseed = new SplittableRandom(seed); - this.random = new XoRoShiRo128PlusPlus(randomseed.nextLong(), randomseed.nextLong()); - } - - @Override - public void nextBytes(byte[] bytes) { - random.nextBytes(bytes); - } - - @Override - public int nextInt() { - return random.nextInt(); - } - - @Override - public int nextInt(int bound) { - return random.nextInt(bound); - } - - @Override - public long nextLong() { - return random.nextLong(); - } - - @Override - public boolean nextBoolean() { - return random.nextBoolean(); - } - - @Override - public float nextFloat() { - return (float) random.nextDouble(); - } - - @Override - public double nextDouble() { - return random.nextDouble(); - } -} \ No newline at end of file diff --git a/platforms/bukkit/build.gradle.kts b/platforms/bukkit/build.gradle.kts index 7db9cf4ad..c9fcaa27d 100644 --- a/platforms/bukkit/build.gradle.kts +++ b/platforms/bukkit/build.gradle.kts @@ -19,7 +19,7 @@ dependencies { shadedApi("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.") } - shadedImplementation("org.apache.logging.log4j:log4j-slf4j18-impl:2.14.1") { + shadedImplementation("org.apache.logging.log4j", "log4j-slf4j18-impl", Versions.Libraries.log4j_slf4j_impl) { because("Minecraft 1.17+ includes slf4j 1.8.0-beta4, so we need to shade it for other versions.") } diff --git a/platforms/sponge/build.gradle.kts b/platforms/sponge/build.gradle.kts index fdd0954a1..472f6c3cb 100644 --- a/platforms/sponge/build.gradle.kts +++ b/platforms/sponge/build.gradle.kts @@ -14,17 +14,17 @@ dependencies { shadedApi("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.") } - shadedImplementation("org.apache.logging.log4j:log4j-slf4j18-impl:2.14.1") { + shadedImplementation("org.apache.logging.log4j", "log4j-slf4j18-impl", Versions.Libraries.log4j_slf4j_impl) { because("Minecraft 1.17+ includes slf4j 1.8.0-beta4, so we need to shade it for other versions.") } - annotationProcessor("org.spongepowered:spongeapi:9.0.0-SNAPSHOT") - implementation("org.spongepowered:spongeapi:9.0.0-SNAPSHOT") - annotationProcessor("org.spongepowered:mixin:0.8.2:processor") + annotationProcessor("org.spongepowered", "spongeapi", Versions.Sponge.sponge) + implementation("org.spongepowered", "spongeapi", Versions.Sponge.sponge) + annotationProcessor("org.spongepowered:mixin:${Versions.Sponge.mixin}:processor") } minecraft { - version("1.17.1") + version(Versions.Sponge.minecraft) runs { server() client()