diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index d6fbe2a8f..a246ea517 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -3,32 +3,20 @@ plugins { kotlin("jvm") version embeddedKotlinVersion } -buildscript { - configurations.all { - resolutionStrategy { - force("org.ow2.asm:asm:9.3") // TODO: remove when ShadowJar updates ASM version - force("org.ow2.asm:asm-commons:9.3") - } - } -} - repositories { mavenCentral() gradlePluginPortal() maven("https://repo.codemc.org/repository/maven-public") { name = "CodeMC" } - maven("https://papermc.io/repo/repository/maven-public/") { - name = "PaperMC" - } } dependencies { - implementation("gradle.plugin.com.github.jengelman.gradle.plugins:shadow:+") - implementation("io.papermc.paperweight.userdev:io.papermc.paperweight.userdev.gradle.plugin:1.3.5") + implementation(libs.libraries.internal.shadow) + - implementation("org.ow2.asm:asm:9.3") - implementation("org.ow2.asm:asm-tree:9.3") - implementation("com.dfsek.tectonic:common:4.2.0") - implementation("org.yaml:snakeyaml:1.27") + implementation(libs.libraries.internal.asm) + implementation(libs.libraries.internal.asm.tree) + implementation(libs.libraries.tectonic) + implementation(libs.libraries.snakeyaml) } \ No newline at end of file diff --git a/buildSrc/settings.gradle.kts b/buildSrc/settings.gradle.kts new file mode 100644 index 000000000..fa8bc7492 --- /dev/null +++ b/buildSrc/settings.gradle.kts @@ -0,0 +1,7 @@ +dependencyResolutionManagement { + versionCatalogs { + create("libs") { + from(files("../gradle/libs.versions.toml")) + } + } +} \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/DependencyConfig.kt b/buildSrc/src/main/kotlin/DependencyConfig.kt index b0e7d32c4..4fb94d820 100644 --- a/buildSrc/src/main/kotlin/DependencyConfig.kt +++ b/buildSrc/src/main/kotlin/DependencyConfig.kt @@ -5,6 +5,8 @@ import org.gradle.kotlin.dsl.getValue import org.gradle.kotlin.dsl.getting import org.gradle.kotlin.dsl.maven import org.gradle.kotlin.dsl.repositories +import org.gradle.api.artifacts.VersionCatalog +import org.gradle.kotlin.dsl.apply fun Project.configureDependencies() { val testImplementation by configurations.getting @@ -15,6 +17,8 @@ fun Project.configureDependencies() { val shaded by configurations.creating + val libs = rootProject.project.versionCatalogs.libs + @Suppress("UNUSED_VARIABLE") val shadedApi by configurations.creating { shaded.extendsFrom(this) @@ -48,14 +52,17 @@ fun Project.configureDependencies() { maven("https://jitpack.io") { name = "JitPack" } + maven("Modrinth") { + url = uri("https://api.modrinth.com/maven") + } } dependencies { - testImplementation("org.junit.jupiter:junit-jupiter-api:5.7.0") - testImplementation("org.junit.jupiter:junit-jupiter-engine:5.7.0") - compileOnly("org.jetbrains:annotations:23.0.0") - - compileOnly("com.google.guava:guava:30.0-jre") - testImplementation("com.google.guava:guava:30.0-jre") + testImplementation(libs.findLibrary("libraries.internal.junit.jupiter.api").get()) + testImplementation(libs.findLibrary("libraries.internal.junit.jupiter.engine").get()) + compileOnly(libs.findLibrary("libraries.internal.jetbrains.annotations").get()) + + compileOnly(libs.findLibrary("libraries.guava").get()) + testImplementation(libs.findLibrary("libraries.guava").get()) } } \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/Helper.kt b/buildSrc/src/main/kotlin/Helper.kt new file mode 100644 index 000000000..e77c7ff6e --- /dev/null +++ b/buildSrc/src/main/kotlin/Helper.kt @@ -0,0 +1,12 @@ +import org.gradle.api.artifacts.VersionCatalogsExtension +import org.gradle.api.artifacts.VersionCatalog +import org.gradle.api.Project +import org.gradle.kotlin.dsl.* + +internal +val Project.versionCatalogs: VersionCatalogsExtension + get() = the() + +internal +val VersionCatalogsExtension.libs: VersionCatalog + get() = named("libs") \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/Versions.kt b/buildSrc/src/main/kotlin/Versions.kt deleted file mode 100644 index c7f2e5ba3..000000000 --- a/buildSrc/src/main/kotlin/Versions.kt +++ /dev/null @@ -1,72 +0,0 @@ -object Versions { - object Libraries { - const val tectonic = "4.2.0" - const val paralithic = "0.7.0" - const val strata = "1.1.1" - - const val cloud = "1.7.0" - - const val slf4j = "1.7.36" - const val log4j_slf4j_impl = "2.14.1" - - const val caffeine = "3.1.0" - const val vavr = "0.10.4" - - object Internal { - const val apacheText = "1.9" - const val jafama = "2.3.2" - const val apacheIO = "2.6" - const val fastutil = "8.5.6" - } - } - - object Fabric { - const val fabricLoader = "0.14.8" - const val fabricAPI = "0.57.0+1.19" - } - - object Quilt { - const val quiltLoader = "0.17.0" - const val fabricApi = "2.0.0-beta.4+0.57.0-1.19" - } - - object Mod { - const val mixin = "0.11.2+mixin.0.8.5" - - const val minecraft = "1.19" - const val yarn = "$minecraft+build.1" - const val fabricLoader = "0.14.2" - - const val architecuryLoom = "0.12.0.290" - const val architecturyPlugin = "3.4-SNAPSHOT" - - const val loomQuiltflower = "1.7.1" - - const val lazyDfu = "0.1.2" - } - - object Forge { - const val forge = "${Mod.minecraft}-41.0.63" - const val burningwave = "12.53.0" - } - - object Bukkit { - const val paper = "1.18.2-R0.1-SNAPSHOT" - const val paperLib = "1.0.5" - const val minecraft = "1.19" - const val reflectionRemapper = "0.1.0-SNAPSHOT" - } - - object Sponge { - const val sponge = "9.0.0-SNAPSHOT" - const val mixin = "0.8.2" - const val minecraft = "1.17.1" - } - - object CLI { - const val nbt = "6.1" - const val logback = "1.2.9" - const val commonsIO = "2.7" - const val guava = "31.0.1-jre" - } -} \ No newline at end of file diff --git a/common/addons/biome-provider-image/build.gradle.kts b/common/addons/biome-provider-image/build.gradle.kts index 15145b578..d3eaff9fe 100644 --- a/common/addons/biome-provider-image/build.gradle.kts +++ b/common/addons/biome-provider-image/build.gradle.kts @@ -2,10 +2,4 @@ version = version("1.0.0") dependencies { compileOnlyApi(project(":common:addons:manifest-addon-loader")) - implementation("net.jafama", "jafama", Versions.Libraries.Internal.jafama) - testImplementation("net.jafama", "jafama", Versions.Libraries.Internal.jafama) -} - -tasks.named("shadowJar") { - relocate("net.jafama", "com.dfsek.terra.addons.biome.image.lib.jafama") } \ No newline at end of file diff --git a/common/addons/biome-provider-pipeline/build.gradle.kts b/common/addons/biome-provider-pipeline/build.gradle.kts index 2629ac476..f0b8af23a 100644 --- a/common/addons/biome-provider-pipeline/build.gradle.kts +++ b/common/addons/biome-provider-pipeline/build.gradle.kts @@ -2,11 +2,4 @@ version = version("1.0.1") dependencies { compileOnlyApi(project(":common:addons:manifest-addon-loader")) - - implementation("net.jafama", "jafama", Versions.Libraries.Internal.jafama) - testImplementation("net.jafama", "jafama", Versions.Libraries.Internal.jafama) -} - -tasks.named("shadowJar") { - relocate("net.jafama", "com.dfsek.terra.addons.biome.pipeline.lib.jafama") } \ No newline at end of file diff --git a/common/addons/chunk-generator-noise-3d/build.gradle.kts b/common/addons/chunk-generator-noise-3d/build.gradle.kts index 685cc848c..84c179738 100644 --- a/common/addons/chunk-generator-noise-3d/build.gradle.kts +++ b/common/addons/chunk-generator-noise-3d/build.gradle.kts @@ -2,11 +2,4 @@ version = version("1.1.0") dependencies { compileOnlyApi(project(":common:addons:manifest-addon-loader")) - - implementation("net.jafama", "jafama", Versions.Libraries.Internal.jafama) - testImplementation("net.jafama", "jafama", Versions.Libraries.Internal.jafama) -} - -tasks.named("shadowJar") { - relocate("net.jafama", "com.dfsek.terra.addons.chunkgenerator.lib.jafama") } diff --git a/common/addons/chunk-generator-noise-3d/src/main/java/com/dfsek/terra/addons/chunkgenerator/generation/math/interpolation/Interpolator.java b/common/addons/chunk-generator-noise-3d/src/main/java/com/dfsek/terra/addons/chunkgenerator/generation/math/interpolation/Interpolator.java index e96e15879..e30a70aae 100644 --- a/common/addons/chunk-generator-noise-3d/src/main/java/com/dfsek/terra/addons/chunkgenerator/generation/math/interpolation/Interpolator.java +++ b/common/addons/chunk-generator-noise-3d/src/main/java/com/dfsek/terra/addons/chunkgenerator/generation/math/interpolation/Interpolator.java @@ -7,6 +7,9 @@ package com.dfsek.terra.addons.chunkgenerator.generation.math.interpolation; +import com.dfsek.terra.api.util.MathUtil; + + /** * Class for bilinear interpolation of values arranged on a unit square. */ @@ -28,19 +31,6 @@ public class Interpolator { this.v3 = v3; } - /** - * 1D Linear interpolation between 2 points 1 unit apart. - * - * @param t - Distance from v0. Total distance between v0 and v1 is 1 unit. - * @param v0 - Value at v0. - * @param v1 - Value at v1. - * - * @return double - The interpolated value. - */ - public static double lerp(double t, double v0, double v1) { - return v0 + t * (v1 - v0); - } - /** * 2D Bilinear interpolation between 4 points on a unit square. * @@ -50,8 +40,8 @@ public class Interpolator { * @return double - The interpolated value. */ public double bilerp(double s, double t) { - double v01 = lerp(s, v0, v1); - double v23 = lerp(s, v2, v3); - return lerp(t, v01, v23); + double v01 = MathUtil.lerp(s, v0, v1); + double v23 = MathUtil.lerp(s, v2, v3); + return MathUtil.lerp(t, v01, v23); } } \ No newline at end of file diff --git a/common/addons/chunk-generator-noise-3d/src/main/java/com/dfsek/terra/addons/chunkgenerator/generation/math/interpolation/Interpolator3.java b/common/addons/chunk-generator-noise-3d/src/main/java/com/dfsek/terra/addons/chunkgenerator/generation/math/interpolation/Interpolator3.java index 804770b42..b313828d3 100644 --- a/common/addons/chunk-generator-noise-3d/src/main/java/com/dfsek/terra/addons/chunkgenerator/generation/math/interpolation/Interpolator3.java +++ b/common/addons/chunk-generator-noise-3d/src/main/java/com/dfsek/terra/addons/chunkgenerator/generation/math/interpolation/Interpolator3.java @@ -7,6 +7,9 @@ package com.dfsek.terra.addons.chunkgenerator.generation.math.interpolation; +import com.dfsek.terra.api.util.MathUtil; + + /** * Class for bilinear interpolation of values arranged on a unit square. */ @@ -34,6 +37,6 @@ public class Interpolator3 { } public double trilerp(double x, double y, double z) { - return Interpolator.lerp(x, top.bilerp(y, z), bottom.bilerp(y, z)); + return MathUtil.lerp(x, top.bilerp(y, z), bottom.bilerp(y, z)); } } \ No newline at end of file diff --git a/common/addons/chunk-generator-noise-3d/src/main/java/com/dfsek/terra/addons/chunkgenerator/generation/math/interpolation/LazilyEvaluatedInterpolator.java b/common/addons/chunk-generator-noise-3d/src/main/java/com/dfsek/terra/addons/chunkgenerator/generation/math/interpolation/LazilyEvaluatedInterpolator.java index f2a48c50a..ecc19d2f9 100644 --- a/common/addons/chunk-generator-noise-3d/src/main/java/com/dfsek/terra/addons/chunkgenerator/generation/math/interpolation/LazilyEvaluatedInterpolator.java +++ b/common/addons/chunk-generator-noise-3d/src/main/java/com/dfsek/terra/addons/chunkgenerator/generation/math/interpolation/LazilyEvaluatedInterpolator.java @@ -1,13 +1,13 @@ package com.dfsek.terra.addons.chunkgenerator.generation.math.interpolation; +import com.dfsek.terra.api.util.MathUtil; + import net.jafama.FastMath; import com.dfsek.terra.addons.chunkgenerator.config.noise.BiomeNoiseProperties; import com.dfsek.terra.api.properties.PropertyKey; import com.dfsek.terra.api.world.biome.generation.BiomeProvider; -import static com.dfsek.terra.addons.chunkgenerator.generation.math.interpolation.Interpolator.lerp; - public class LazilyEvaluatedInterpolator { private final Double[] samples; // @@ -84,10 +84,10 @@ public class LazilyEvaluatedInterpolator { double xFrac = (double) (x % horizontalRes) / horizontalRes; double zFrac = (double) (z % horizontalRes) / horizontalRes; - double lerp_bottom_0 = lerp(zFrac, sample_0_0_0, sample_0_0_1); - double lerp_bottom_1 = lerp(zFrac, sample_1_0_0, sample_1_0_1); + double lerp_bottom_0 = MathUtil.lerp(zFrac, sample_0_0_0, sample_0_0_1); + double lerp_bottom_1 = MathUtil.lerp(zFrac, sample_1_0_0, sample_1_0_1); - double lerp_bottom = lerp(xFrac, lerp_bottom_0, lerp_bottom_1); + double lerp_bottom = MathUtil.lerp(xFrac, lerp_bottom_0, lerp_bottom_1); if(yRange) { // we can do bilerp return lerp_bottom; @@ -103,11 +103,11 @@ public class LazilyEvaluatedInterpolator { double sample_1_1_0 = sample(xIndex + 1, yIndex + 1, zIndex, x + horizontalRes, y + verticalRes, z); double sample_1_1_1 = sample(xIndex + 1, yIndex + 1, zIndex + 1, x + horizontalRes, y + verticalRes, z + horizontalRes); - double lerp_top_0 = lerp(zFrac, sample_0_1_0, sample_0_1_1); - double lerp_top_1 = lerp(zFrac, sample_1_1_0, sample_1_1_1); + double lerp_top_0 = MathUtil.lerp(zFrac, sample_0_1_0, sample_0_1_1); + double lerp_top_1 = MathUtil.lerp(zFrac, sample_1_1_0, sample_1_1_1); - double lerp_top = lerp(xFrac, lerp_top_0, lerp_top_1); + double lerp_top = MathUtil.lerp(xFrac, lerp_top_0, lerp_top_1); - return lerp(yFrac, lerp_bottom, lerp_top); + return MathUtil.lerp(yFrac, lerp_bottom, lerp_top); } } diff --git a/common/addons/command-structures/src/main/java/com/dfsek/terra/addons/commands/structure/StructureCommandAddon.java b/common/addons/command-structures/src/main/java/com/dfsek/terra/addons/commands/structure/StructureCommandAddon.java index f1d8d552c..7f3bab096 100644 --- a/common/addons/command-structures/src/main/java/com/dfsek/terra/addons/commands/structure/StructureCommandAddon.java +++ b/common/addons/command-structures/src/main/java/com/dfsek/terra/addons/commands/structure/StructureCommandAddon.java @@ -6,21 +6,18 @@ import cloud.commandframework.arguments.standard.EnumArgument; import cloud.commandframework.arguments.standard.LongArgument; import cloud.commandframework.context.CommandContext; -import java.util.Random; +import java.util.random.RandomGenerator; +import java.util.random.RandomGeneratorFactory; import com.dfsek.terra.addons.manifest.api.MonadAddonInitializer; import com.dfsek.terra.addons.manifest.api.monad.Do; import com.dfsek.terra.addons.manifest.api.monad.Get; import com.dfsek.terra.addons.manifest.api.monad.Init; -import com.dfsek.terra.api.Platform; -import com.dfsek.terra.api.addon.BaseAddon; import com.dfsek.terra.api.command.CommandSender; import com.dfsek.terra.api.command.arguments.RegistryArgument; import com.dfsek.terra.api.entity.Entity; -import com.dfsek.terra.api.event.events.config.pack.ConfigPackPreLoadEvent; import com.dfsek.terra.api.event.events.platform.CommandRegistrationEvent; import com.dfsek.terra.api.event.functional.FunctionalEventHandler; -import com.dfsek.terra.api.inject.annotations.Inject; import com.dfsek.terra.api.registry.Registry; import com.dfsek.terra.api.structure.Structure; import com.dfsek.terra.api.util.Rotation; @@ -42,7 +39,7 @@ public class StructureCommandAddon implements MonadAddonInitializer { handler.register(base, CommandRegistrationEvent.class) .then(event -> { CommandManager manager = event.getCommandManager(); - + manager.command( manager.commandBuilder("structures", ArgumentDescription.of("Manage or generate structures")) .literal("generate") @@ -57,9 +54,7 @@ public class StructureCommandAddon implements MonadAddonInitializer { structure.generate( sender.position().toInt(), sender.world(), - ((Long) context.get("seed") == 0) ? new Random() : new Random(context.get("seed")), - context.get("rotation") - ); + context.get("rotation")); }) .permission("terra.structures.generate") ); diff --git a/common/addons/config-distributors/build.gradle.kts b/common/addons/config-distributors/build.gradle.kts index e38fb40ee..d3eaff9fe 100644 --- a/common/addons/config-distributors/build.gradle.kts +++ b/common/addons/config-distributors/build.gradle.kts @@ -2,11 +2,4 @@ version = version("1.0.0") dependencies { compileOnlyApi(project(":common:addons:manifest-addon-loader")) - - implementation("net.jafama", "jafama", Versions.Libraries.Internal.jafama) - testImplementation("net.jafama", "jafama", Versions.Libraries.Internal.jafama) -} - -tasks.named("shadowJar") { - relocate("net.jafama", "com.dfsek.terra.addons.feature.distributor.lib.jafama") } \ No newline at end of file diff --git a/common/addons/config-distributors/src/main/java/com/dfsek/terra/addons/feature/distributor/DistributorAddon.java b/common/addons/config-distributors/src/main/java/com/dfsek/terra/addons/feature/distributor/DistributorAddon.java index 1b30b78d3..15a6af263 100644 --- a/common/addons/config-distributors/src/main/java/com/dfsek/terra/addons/feature/distributor/DistributorAddon.java +++ b/common/addons/config-distributors/src/main/java/com/dfsek/terra/addons/feature/distributor/DistributorAddon.java @@ -14,7 +14,7 @@ import java.util.function.Supplier; import com.dfsek.terra.addons.feature.distributor.config.AndDistributorTemplate; import com.dfsek.terra.addons.feature.distributor.config.NoDistributorTemplate; import com.dfsek.terra.addons.feature.distributor.config.OrDistributorTemplate; -import com.dfsek.terra.addons.feature.distributor.config.PaddedGridDistributorTemplate; +import com.dfsek.terra.addons.feature.distributor.config.PaddedGridSamplerDistributorTemplate; import com.dfsek.terra.addons.feature.distributor.config.PointSetDistributorTemplate; import com.dfsek.terra.addons.feature.distributor.config.SamplerDistributorTemplate; import com.dfsek.terra.addons.feature.distributor.config.XorDistributorTemplate; @@ -25,11 +25,8 @@ import com.dfsek.terra.addons.manifest.api.MonadAddonInitializer; import com.dfsek.terra.addons.manifest.api.monad.Do; import com.dfsek.terra.addons.manifest.api.monad.Get; import com.dfsek.terra.addons.manifest.api.monad.Init; -import com.dfsek.terra.api.Platform; -import com.dfsek.terra.api.addon.BaseAddon; import com.dfsek.terra.api.event.events.config.pack.ConfigPackPreLoadEvent; import com.dfsek.terra.api.event.functional.FunctionalEventHandler; -import com.dfsek.terra.api.inject.annotations.Inject; import com.dfsek.terra.api.registry.CheckedRegistry; import com.dfsek.terra.api.structure.feature.Distributor; import com.dfsek.terra.api.util.function.monad.Monad; @@ -54,7 +51,7 @@ public class DistributorAddon implements MonadAddonInitializer { distributorRegistry.register(base.key("SAMPLER"), SamplerDistributorTemplate::new); distributorRegistry.register(base.key("POINTS"), PointSetDistributorTemplate::new); - distributorRegistry.register(base.key("PADDED_GRID"), PaddedGridDistributorTemplate::new); + distributorRegistry.register(base.key("PADDED_GRID_SAMPLER"), PaddedGridSamplerDistributorTemplate::new); distributorRegistry.register(base.key("AND"), AndDistributorTemplate::new); distributorRegistry.register(base.key("OR"), OrDistributorTemplate::new); distributorRegistry.register(base.key("XOR"), XorDistributorTemplate::new); diff --git a/common/addons/config-distributors/src/main/java/com/dfsek/terra/addons/feature/distributor/config/PaddedGridDistributorTemplate.java b/common/addons/config-distributors/src/main/java/com/dfsek/terra/addons/feature/distributor/config/PaddedGridSamplerDistributorTemplate.java similarity index 64% rename from common/addons/config-distributors/src/main/java/com/dfsek/terra/addons/feature/distributor/config/PaddedGridDistributorTemplate.java rename to common/addons/config-distributors/src/main/java/com/dfsek/terra/addons/feature/distributor/config/PaddedGridSamplerDistributorTemplate.java index ff77d18be..9af67d4b4 100644 --- a/common/addons/config-distributors/src/main/java/com/dfsek/terra/addons/feature/distributor/config/PaddedGridDistributorTemplate.java +++ b/common/addons/config-distributors/src/main/java/com/dfsek/terra/addons/feature/distributor/config/PaddedGridSamplerDistributorTemplate.java @@ -3,23 +3,24 @@ package com.dfsek.terra.addons.feature.distributor.config; import com.dfsek.tectonic.api.config.template.annotations.Value; import com.dfsek.tectonic.api.config.template.object.ObjectTemplate; -import com.dfsek.terra.addons.feature.distributor.distributors.PaddedGridDistributor; +import com.dfsek.terra.addons.feature.distributor.distributors.PaddedGridSamplerDistributor; import com.dfsek.terra.api.config.meta.Meta; +import com.dfsek.terra.api.noise.NoiseSampler; import com.dfsek.terra.api.structure.feature.Distributor; -public class PaddedGridDistributorTemplate implements ObjectTemplate { +public class PaddedGridSamplerDistributorTemplate implements ObjectTemplate { @Value("width") private @Meta int width; @Value("padding") private @Meta int padding; - @Value("salt") - private @Meta int salt; + @Value("sampler") + private @Meta NoiseSampler noise; @Override public Distributor get() { - return new PaddedGridDistributor(width, padding, salt); + return new PaddedGridSamplerDistributor(noise, width, padding); } } diff --git a/common/addons/config-distributors/src/main/java/com/dfsek/terra/addons/feature/distributor/distributors/PaddedGridDistributor.java b/common/addons/config-distributors/src/main/java/com/dfsek/terra/addons/feature/distributor/distributors/PaddedGridDistributor.java deleted file mode 100644 index bb380e034..000000000 --- a/common/addons/config-distributors/src/main/java/com/dfsek/terra/addons/feature/distributor/distributors/PaddedGridDistributor.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.dfsek.terra.addons.feature.distributor.distributors; - -import net.jafama.FastMath; - -import java.util.Random; - -import com.dfsek.terra.api.structure.feature.Distributor; -import com.dfsek.terra.api.util.MathUtil; - - -public class PaddedGridDistributor implements Distributor { - private final int width; - - private final int cellWidth; - - private final int salt; - - public PaddedGridDistributor(int width, int padding, int salt) { - this.width = width; - this.salt = salt; - this.cellWidth = width + padding; - } - - private static long murmur64(long h) { - h ^= h >>> 33; - h *= 0xff51afd7ed558ccdL; - h ^= h >>> 33; - h *= 0xc4ceb9fe1a85ec53L; - h ^= h >>> 33; - return h; - } - - @Override - public boolean matches(int x, int z, long seed) { - int cellX = FastMath.floorDiv(x, cellWidth); - int cellZ = FastMath.floorDiv(z, cellWidth); - - Random random = new Random((murmur64(MathUtil.squash(cellX, cellZ)) ^ seed) + salt); - - int pointX = random.nextInt(width) + cellX * cellWidth; - int pointZ = random.nextInt(width) + cellZ * cellWidth; - - return x == pointX && z == pointZ; - } -} diff --git a/common/addons/config-distributors/src/main/java/com/dfsek/terra/addons/feature/distributor/distributors/PaddedGridSamplerDistributor.java b/common/addons/config-distributors/src/main/java/com/dfsek/terra/addons/feature/distributor/distributors/PaddedGridSamplerDistributor.java new file mode 100644 index 000000000..00f1e38e2 --- /dev/null +++ b/common/addons/config-distributors/src/main/java/com/dfsek/terra/addons/feature/distributor/distributors/PaddedGridSamplerDistributor.java @@ -0,0 +1,36 @@ +package com.dfsek.terra.addons.feature.distributor.distributors; + +import com.dfsek.terra.api.noise.NoiseSampler; + +import net.jafama.FastMath; + +import java.util.random.RandomGenerator; +import java.util.random.RandomGeneratorFactory; + +import com.dfsek.terra.api.structure.feature.Distributor; +import com.dfsek.terra.api.util.MathUtil; + + +public class PaddedGridSamplerDistributor implements Distributor { + private final NoiseSampler sampler; + private final int width; + + private final int cellWidth; + + public PaddedGridSamplerDistributor(NoiseSampler sampler, int width, int padding) { + this.sampler = sampler; + this.width = width; + this.cellWidth = width + padding; + } + + @Override + public boolean matches(int x, int z, long seed) { + int cellX = FastMath.floorDiv(x, cellWidth); + int cellZ = FastMath.floorDiv(z, cellWidth); + + int pointX = (int) (FastMath.round(MathUtil.lerp(MathUtil.inverseLerp(sampler.noise(x, z, seed), -1, 1), 0, width)) + cellX * cellWidth); + int pointZ = (int) (FastMath.round(MathUtil.lerp(MathUtil.inverseLerp(sampler.noise(x, z, seed + 1), -1, 1), 0, width)) + cellZ * cellWidth); + + return x == pointX && z == pointZ; + } +} diff --git a/common/addons/config-flora/build.gradle.kts b/common/addons/config-flora/build.gradle.kts index 9e1e78d1f..9d0aac37f 100644 --- a/common/addons/config-flora/build.gradle.kts +++ b/common/addons/config-flora/build.gradle.kts @@ -2,10 +2,4 @@ version = version("1.0.0") dependencies { compileOnlyApi(project(":common:addons:manifest-addon-loader")) - implementation("net.jafama", "jafama", Versions.Libraries.Internal.jafama) - testImplementation("net.jafama", "jafama", Versions.Libraries.Internal.jafama) -} - -tasks.named("shadowJar") { - relocate("net.jafama", "com.dfsek.terra.addons.flora.lib.jafama") } diff --git a/common/addons/config-flora/src/main/java/com/dfsek/terra/addons/flora/flora/gen/TerraFlora.java b/common/addons/config-flora/src/main/java/com/dfsek/terra/addons/flora/flora/gen/TerraFlora.java index 31fbf1558..844b9681c 100644 --- a/common/addons/config-flora/src/main/java/com/dfsek/terra/addons/flora/flora/gen/TerraFlora.java +++ b/common/addons/config-flora/src/main/java/com/dfsek/terra/addons/flora/flora/gen/TerraFlora.java @@ -12,7 +12,8 @@ import net.jafama.FastMath; import java.util.ArrayList; import java.util.EnumSet; import java.util.List; -import java.util.Random; +import java.util.random.RandomGenerator; +import java.util.random.RandomGeneratorFactory; import com.dfsek.terra.api.block.state.BlockState; import com.dfsek.terra.api.block.state.properties.enums.Direction; @@ -73,7 +74,7 @@ public class TerraFlora implements Structure { } @Override - public boolean generate(Vector3Int location, WritableWorld world, Random random, Rotation rotation) { + public boolean generate(Vector3Int location, WritableWorld world, Rotation rotation) { boolean doRotation = testRotation.size() > 0; int size = layers.size(); int c = ceiling ? -1 : 1; @@ -86,10 +87,7 @@ public class TerraFlora implements Structure { int lvl = (FastMath.abs(i)); BlockState data = getStateCollection((ceiling ? lvl : size - lvl - 1)).get(distribution, location.getX(), location.getY(), location.getZ(), world.getSeed()); - if(doRotation) { - Direction oneFace = new ArrayList<>(faces).get( - new Random(location.getX() ^ location.getZ()).nextInt(faces.size())); // Get random face. - } + world.setBlockState(location.mutable().add(0, i + c, 0).immutable(), data, physics); } return true; diff --git a/common/addons/config-locators/build.gradle.kts b/common/addons/config-locators/build.gradle.kts index 50fc70400..84c179738 100644 --- a/common/addons/config-locators/build.gradle.kts +++ b/common/addons/config-locators/build.gradle.kts @@ -2,11 +2,4 @@ version = version("1.1.0") dependencies { compileOnlyApi(project(":common:addons:manifest-addon-loader")) - - implementation("net.jafama", "jafama", Versions.Libraries.Internal.jafama) - testImplementation("net.jafama", "jafama", Versions.Libraries.Internal.jafama) -} - -tasks.named("shadowJar") { - relocate("net.jafama", "com.dfsek.terra.addons.feature.locator.lib.jafama") } diff --git a/common/addons/config-locators/src/main/java/com/dfsek/terra/addons/feature/locator/LocatorAddon.java b/common/addons/config-locators/src/main/java/com/dfsek/terra/addons/feature/locator/LocatorAddon.java index 9cb6282e7..70018a038 100644 --- a/common/addons/config-locators/src/main/java/com/dfsek/terra/addons/feature/locator/LocatorAddon.java +++ b/common/addons/config-locators/src/main/java/com/dfsek/terra/addons/feature/locator/LocatorAddon.java @@ -13,10 +13,8 @@ import java.util.function.Supplier; import com.dfsek.terra.addons.feature.locator.config.AdjacentPatternLocatorTemplate; import com.dfsek.terra.addons.feature.locator.config.AndLocatorTemplate; -import com.dfsek.terra.addons.feature.locator.config.GaussianRandomLocatorTemplate; import com.dfsek.terra.addons.feature.locator.config.OrLocatorTemplate; import com.dfsek.terra.addons.feature.locator.config.PatternLocatorTemplate; -import com.dfsek.terra.addons.feature.locator.config.RandomLocatorTemplate; import com.dfsek.terra.addons.feature.locator.config.Sampler3DLocatorTemplate; import com.dfsek.terra.addons.feature.locator.config.SamplerLocatorTemplate; import com.dfsek.terra.addons.feature.locator.config.SurfaceLocatorTemplate; @@ -35,11 +33,8 @@ import com.dfsek.terra.addons.manifest.api.MonadAddonInitializer; import com.dfsek.terra.addons.manifest.api.monad.Do; import com.dfsek.terra.addons.manifest.api.monad.Get; import com.dfsek.terra.addons.manifest.api.monad.Init; -import com.dfsek.terra.api.Platform; -import com.dfsek.terra.api.addon.BaseAddon; import com.dfsek.terra.api.event.events.config.pack.ConfigPackPreLoadEvent; import com.dfsek.terra.api.event.functional.FunctionalEventHandler; -import com.dfsek.terra.api.inject.annotations.Inject; import com.dfsek.terra.api.registry.CheckedRegistry; import com.dfsek.terra.api.structure.feature.Locator; import com.dfsek.terra.api.util.function.monad.Monad; @@ -66,9 +61,6 @@ public class LocatorAddon implements MonadAddonInitializer { locatorRegistry.register(base.key("SURFACE"), SurfaceLocatorTemplate::new); locatorRegistry.register(base.key("TOP"), TopLocatorTemplate::new); - locatorRegistry.register(base.key("RANDOM"), RandomLocatorTemplate::new); - locatorRegistry.register(base.key("GAUSSIAN_RANDOM"), GaussianRandomLocatorTemplate::new); - locatorRegistry.register(base.key("PATTERN"), PatternLocatorTemplate::new); locatorRegistry.register(base.key("ADJACENT_PATTERN"), AdjacentPatternLocatorTemplate::new); diff --git a/common/addons/config-locators/src/main/java/com/dfsek/terra/addons/feature/locator/config/GaussianRandomLocatorTemplate.java b/common/addons/config-locators/src/main/java/com/dfsek/terra/addons/feature/locator/config/GaussianRandomLocatorTemplate.java deleted file mode 100644 index 80af89793..000000000 --- a/common/addons/config-locators/src/main/java/com/dfsek/terra/addons/feature/locator/config/GaussianRandomLocatorTemplate.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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.addons.feature.locator.config; - -import com.dfsek.tectonic.api.config.template.annotations.Default; -import com.dfsek.tectonic.api.config.template.annotations.Value; -import com.dfsek.tectonic.api.config.template.object.ObjectTemplate; - -import com.dfsek.terra.addons.feature.locator.locators.GaussianRandomLocator; -import com.dfsek.terra.api.config.meta.Meta; -import com.dfsek.terra.api.structure.feature.Locator; -import com.dfsek.terra.api.util.Range; - - -@SuppressWarnings("FieldMayBeFinal") -public class GaussianRandomLocatorTemplate implements ObjectTemplate { - @Value("height") - private @Meta Range height; - - @Value("amount") - private @Meta Range amount; - - @Value("standard-deviation") - private @Meta double standardDeviation; - - @Value("salt") - @Default - private @Meta int salt = 0; - - @Override - public Locator get() { - return new GaussianRandomLocator(height, amount, standardDeviation, salt); - } -} diff --git a/common/addons/config-locators/src/main/java/com/dfsek/terra/addons/feature/locator/config/RandomLocatorTemplate.java b/common/addons/config-locators/src/main/java/com/dfsek/terra/addons/feature/locator/config/RandomLocatorTemplate.java deleted file mode 100644 index 9bdb3f6db..000000000 --- a/common/addons/config-locators/src/main/java/com/dfsek/terra/addons/feature/locator/config/RandomLocatorTemplate.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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.addons.feature.locator.config; - -import com.dfsek.tectonic.api.config.template.annotations.Default; -import com.dfsek.tectonic.api.config.template.annotations.Value; -import com.dfsek.tectonic.api.config.template.object.ObjectTemplate; - -import com.dfsek.terra.addons.feature.locator.locators.RandomLocator; -import com.dfsek.terra.api.config.meta.Meta; -import com.dfsek.terra.api.structure.feature.Locator; -import com.dfsek.terra.api.util.Range; - - -@SuppressWarnings("FieldMayBeFinal") -public class RandomLocatorTemplate implements ObjectTemplate { - @Value("height") - private @Meta Range height; - - @Value("amount") - private @Meta Range amount; - - @Value("salt") - @Default - private @Meta int salt = 0; - - @Override - public Locator get() { - return new RandomLocator(height, amount, salt); - } -} diff --git a/common/addons/config-locators/src/main/java/com/dfsek/terra/addons/feature/locator/locators/GaussianRandomLocator.java b/common/addons/config-locators/src/main/java/com/dfsek/terra/addons/feature/locator/locators/GaussianRandomLocator.java deleted file mode 100644 index 16fb827e5..000000000 --- a/common/addons/config-locators/src/main/java/com/dfsek/terra/addons/feature/locator/locators/GaussianRandomLocator.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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.addons.feature.locator.locators; - -import java.util.Random; - -import com.dfsek.terra.api.structure.feature.BinaryColumn; -import com.dfsek.terra.api.structure.feature.Locator; -import com.dfsek.terra.api.util.Range; -import com.dfsek.terra.api.world.chunk.generation.util.Column; -import com.dfsek.terra.api.world.chunk.generation.util.Column.BinaryColumnBuilder; - - -public class GaussianRandomLocator implements Locator { - private final double mean; - - private final Range points; - - private final double standardDeviation; - - private final int salt; - - - public GaussianRandomLocator(Range height, Range points, double standardDeviation, int salt) { - this.mean = (height.getMax() + height.getMin()) / 2.0; - this.points = points; - this.standardDeviation = standardDeviation; - this.salt = salt; - } - - @Override - public BinaryColumn getSuitableCoordinates(Column column) { - long seed = column.getWorld().getSeed(); - seed = 31 * seed + column.getX(); - seed = 31 * seed + column.getZ(); - seed += salt; - - Random r = new Random(seed); - - int size = points.get(r); - - - BinaryColumnBuilder results = column.newBinaryColumn(); - for(int i = 0; i < size; i++) { - int h = (int) r.nextGaussian(mean, standardDeviation); - if(h >= column.getMaxY() || h < column.getMinY()) continue; - results.set(h); - } - - return results.build(); - } -} diff --git a/common/addons/config-locators/src/main/java/com/dfsek/terra/addons/feature/locator/locators/RandomLocator.java b/common/addons/config-locators/src/main/java/com/dfsek/terra/addons/feature/locator/locators/RandomLocator.java deleted file mode 100644 index fc86878ff..000000000 --- a/common/addons/config-locators/src/main/java/com/dfsek/terra/addons/feature/locator/locators/RandomLocator.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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.addons.feature.locator.locators; - -import java.util.Random; - -import com.dfsek.terra.api.structure.feature.BinaryColumn; -import com.dfsek.terra.api.structure.feature.Locator; -import com.dfsek.terra.api.util.Range; -import com.dfsek.terra.api.world.chunk.generation.util.Column; -import com.dfsek.terra.api.world.chunk.generation.util.Column.BinaryColumnBuilder; - - -public class RandomLocator implements Locator { - private final Range height; - - private final Range points; - - private final int salt; - - public RandomLocator(Range height, Range points, int salt) { - this.height = height; - this.points = points; - this.salt = salt; - } - - @Override - public BinaryColumn getSuitableCoordinates(Column column) { - long seed = column.getWorld().getSeed(); - seed = 31 * seed + column.getX(); - seed = 31 * seed + column.getZ(); - seed += salt; - - Random r = new Random(seed); - - int size = points.get(r); - - BinaryColumnBuilder results = column.newBinaryColumn(); - for(int i = 0; i < size; i++) { - int h = height.get(r); - if(h >= column.getMaxY() || h < column.getMinY()) continue; - results.set(h); - } - - return results.build(); - } -} diff --git a/common/addons/config-noise-function/build.gradle.kts b/common/addons/config-noise-function/build.gradle.kts index f51d5e878..1193d5cf5 100644 --- a/common/addons/config-noise-function/build.gradle.kts +++ b/common/addons/config-noise-function/build.gradle.kts @@ -4,13 +4,4 @@ version = version("1.0.0") dependencies { compileOnlyApi(project(":common:addons:manifest-addon-loader")) - api("com.dfsek", "paralithic", Versions.Libraries.paralithic) - implementation("net.jafama", "jafama", Versions.Libraries.Internal.jafama) - testImplementation("net.jafama", "jafama", Versions.Libraries.Internal.jafama) -} - - -tasks.named("shadowJar") { - relocate("com.dfsek.paralithic", "com.dfsek.terra.addons.noise.lib.paralithic") - relocate("net.jafama", "com.dfsek.terra.addons.noise.lib.jafama") } \ No newline at end of file diff --git a/common/addons/config-ore/build.gradle.kts b/common/addons/config-ore/build.gradle.kts index d575f43d3..4e7e1d975 100644 --- a/common/addons/config-ore/build.gradle.kts +++ b/common/addons/config-ore/build.gradle.kts @@ -2,10 +2,5 @@ version = version("1.0.0") dependencies { compileOnlyApi(project(":common:addons:manifest-addon-loader")) - implementation("net.jafama", "jafama", Versions.Libraries.Internal.jafama) - testImplementation("net.jafama", "jafama", Versions.Libraries.Internal.jafama) -} - -tasks.named("shadowJar") { - relocate("net.jafama", "com.dfsek.terra.addons.ore.lib.jafama") + compileOnlyApi(project(":common:addons:config-noise-function")) } diff --git a/common/addons/config-ore/src/main/java/com/dfsek/terra/addons/ore/OreFactory.java b/common/addons/config-ore/src/main/java/com/dfsek/terra/addons/ore/OreFactory.java index 9d8b1055a..1d824a00a 100644 --- a/common/addons/config-ore/src/main/java/com/dfsek/terra/addons/ore/OreFactory.java +++ b/common/addons/config-ore/src/main/java/com/dfsek/terra/addons/ore/OreFactory.java @@ -7,6 +7,7 @@ package com.dfsek.terra.addons.ore; +import com.dfsek.terra.addons.noise.samplers.noise.random.WhiteNoiseSampler; import com.dfsek.terra.addons.ore.ores.VanillaOre; import com.dfsek.terra.api.Platform; import com.dfsek.terra.api.block.state.BlockState; @@ -19,6 +20,6 @@ public class OreFactory implements ConfigFactory { public VanillaOre build(OreTemplate config, Platform platform) { BlockState m = config.getMaterial(); return new VanillaOre(m, config.getSize(), config.getReplaceable(), config.doPhysics(), config.isExposed(), - config.getMaterialOverrides()); + config.getMaterialOverrides(), new WhiteNoiseSampler()); } } diff --git a/common/addons/config-ore/src/main/java/com/dfsek/terra/addons/ore/ores/VanillaOre.java b/common/addons/config-ore/src/main/java/com/dfsek/terra/addons/ore/ores/VanillaOre.java index a1046aea9..2b3c333d7 100644 --- a/common/addons/config-ore/src/main/java/com/dfsek/terra/addons/ore/ores/VanillaOre.java +++ b/common/addons/config-ore/src/main/java/com/dfsek/terra/addons/ore/ores/VanillaOre.java @@ -7,10 +7,13 @@ package com.dfsek.terra.addons.ore.ores; +import com.dfsek.terra.api.noise.NoiseSampler; + +import com.dfsek.terra.api.util.MathUtil; + import net.jafama.FastMath; import java.util.Map; -import java.util.Random; import com.dfsek.terra.api.block.BlockType; import com.dfsek.terra.api.block.state.BlockState; @@ -30,38 +33,40 @@ public class VanillaOre implements Structure { private final boolean applyGravity; private final double exposed; private final Map materials; + private final NoiseSampler sampler; public VanillaOre(BlockState material, double size, MaterialSet replaceable, boolean applyGravity, - double exposed, Map materials) { + double exposed, Map materials, NoiseSampler sampler) { this.material = material; this.size = size; this.replaceable = replaceable; this.applyGravity = applyGravity; this.exposed = exposed; this.materials = materials; + this.sampler = sampler; } @Override - public boolean generate(Vector3Int location, WritableWorld world, Random random, Rotation rotation) { + public boolean generate(Vector3Int location, WritableWorld world, Rotation rotation){ int centerX = location.getX(); int centerZ = location.getZ(); int centerY = location.getY(); - float f = random.nextFloat() * (float) Math.PI; + double f = sampler.noise(centerX, centerY, centerZ, world.getSeed()) * (float) Math.PI; double d1 = centerX + 8 + FastMath.sin(f) * size / 8.0F; double d2 = centerX + 8 - FastMath.sin(f) * size / 8.0F; double d3 = centerZ + 8 + FastMath.cos(f) * size / 8.0F; double d4 = centerZ + 8 - FastMath.cos(f) * size / 8.0F; - double d5 = centerY + random.nextInt(3) - 2D; - double d6 = centerY + random.nextInt(3) - 2D; + double d5 = centerY + (Math.round(sampler.noise(centerX, centerY, centerZ, world.getSeed() + 1) + 1)) - 2D; + double d6 = centerY + (Math.round(sampler.noise(centerX, centerY, centerZ, world.getSeed() + 2) + 1)) - 2D; for(int i = 0; i < size; i++) { float iFactor = (float) i / (float) size; - double d10 = random.nextDouble() * size / 16.0D; + double d10 = MathUtil.inverseLerp(sampler.noise(centerX, centerY, centerZ, world.getSeed() + 2 + (i * 2 - 1)), -1, 1) * size / 16.0D; double d11 = (FastMath.sin(Math.PI * iFactor) + 1.0) * d10 + 1.0; double d12 = (FastMath.sin(Math.PI * iFactor) + 1.0) * d10 + 1.0; @@ -85,7 +90,7 @@ public class VanillaOre implements Structure { if(y >= world.getMaxHeight() || y < world.getMinHeight()) continue; BlockType block = world.getBlockState(x, y, z).getBlockType(); if((d13 * d13 + d14 * d14 + d15 * d15 < 1.0D) && getReplaceable().contains(block)) { - if(exposed > random.nextDouble() || !(world.getBlockState(x, y, z - 1).isAir() || + if(exposed > MathUtil.inverseLerp(sampler.noise(centerX, centerY, centerZ, world.getSeed() + 2 + (i * 2)), -1, 1) || !(world.getBlockState(x, y, z - 1).isAir() || world.getBlockState(x, y, z + 1).isAir() || world.getBlockState(x, y - 1, z).isAir() || world.getBlockState(x, y + 1, z).isAir() || diff --git a/common/addons/config-ore/src/main/resources/terra.addon.yml b/common/addons/config-ore/src/main/resources/terra.addon.yml index 60ea05e60..d83bcb3cc 100644 --- a/common/addons/config-ore/src/main/resources/terra.addon.yml +++ b/common/addons/config-ore/src/main/resources/terra.addon.yml @@ -9,4 +9,6 @@ website: issues: https://github.com/PolyhedralDev/Terra/issues source: https://github.com/PolyhedralDev/Terra docs: https://terra.polydev.org -license: MIT License \ No newline at end of file +license: MIT License +depends: + config-noise-function: "1.+" \ No newline at end of file diff --git a/common/addons/config-structure/build.gradle.kts b/common/addons/config-structure/build.gradle.kts index dad8fff7d..d3eaff9fe 100644 --- a/common/addons/config-structure/build.gradle.kts +++ b/common/addons/config-structure/build.gradle.kts @@ -1,13 +1,5 @@ version = version("1.0.0") dependencies { - api("com.googlecode.json-simple:json-simple:1.1.1") compileOnlyApi(project(":common:addons:manifest-addon-loader")) - - implementation("net.jafama", "jafama", Versions.Libraries.Internal.jafama) - testImplementation("net.jafama", "jafama", Versions.Libraries.Internal.jafama) -} - -tasks.named("shadowJar") { - relocate("net.jafama", "com.dfsek.terra.addons.structure.lib.jafama") -} +} \ No newline at end of file diff --git a/common/addons/config-structure/src/main/java/com/dfsek/terra/addons/structure/structures/loot/Entry.java b/common/addons/config-structure/src/main/java/com/dfsek/terra/addons/structure/structures/loot/Entry.java deleted file mode 100644 index ab8be10e2..000000000 --- a/common/addons/config-structure/src/main/java/com/dfsek/terra/addons/structure/structures/loot/Entry.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * 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.addons.structure.structures.loot; - -import net.jafama.FastMath; -import org.json.simple.JSONArray; -import org.json.simple.JSONObject; - -import java.util.ArrayList; -import java.util.List; -import java.util.Random; - -import com.dfsek.terra.addons.structure.structures.loot.functions.AmountFunction; -import com.dfsek.terra.addons.structure.structures.loot.functions.DamageFunction; -import com.dfsek.terra.addons.structure.structures.loot.functions.EnchantFunction; -import com.dfsek.terra.addons.structure.structures.loot.functions.LootFunction; -import com.dfsek.terra.api.Platform; -import com.dfsek.terra.api.inventory.Item; -import com.dfsek.terra.api.inventory.ItemStack; - - -/** - * Representation of a single item entry within a Loot Table pool. - */ -public class Entry { - private final Item item; - private final long weight; - private final List functions = new ArrayList<>(); - - /** - * Instantiates an Entry from a JSON representation. - * - * @param entry The JSON Object to instantiate from. - */ - public Entry(JSONObject entry, Platform platform) { - String id = entry.get("name").toString(); - this.item = platform.getItemHandle().createItem(id); - - long weight1; - try { - weight1 = (long) entry.get("weight"); - } catch(NullPointerException e) { - weight1 = 1; - } - - this.weight = weight1; - if(entry.containsKey("functions")) { - for(Object function : (JSONArray) entry.get("functions")) { - switch(((String) ((JSONObject) function).get("function"))) { - case "minecraft:set_count", "set_count" -> { - Object loot = ((JSONObject) function).get("count"); - long max, min; - if(loot instanceof Long) { - max = (Long) loot; - min = (Long) loot; - } else { - max = (long) ((JSONObject) loot).get("max"); - min = (long) ((JSONObject) loot).get("min"); - } - functions.add(new AmountFunction(FastMath.toIntExact(min), FastMath.toIntExact(max))); - } - case "minecraft:set_damage", "set_damage" -> { - long maxDamage = (long) ((JSONObject) ((JSONObject) function).get("damage")).get("max"); - long minDamage = (long) ((JSONObject) ((JSONObject) function).get("damage")).get("min"); - functions.add(new DamageFunction(FastMath.toIntExact(minDamage), FastMath.toIntExact(maxDamage))); - } - case "minecraft:enchant_with_levels", "enchant_with_levels" -> { - long maxEnchant = (long) ((JSONObject) ((JSONObject) function).get("levels")).get("max"); - long minEnchant = (long) ((JSONObject) ((JSONObject) function).get("levels")).get("min"); - JSONArray disabled = null; - if(((JSONObject) function).containsKey("disabled_enchants")) - disabled = (JSONArray) ((JSONObject) function).get("disabled_enchants"); - functions.add( - new EnchantFunction(FastMath.toIntExact(minEnchant), FastMath.toIntExact(maxEnchant), disabled, platform)); - } - } - } - } - } - - /** - * Fetches a single ItemStack from the Entry, applying all functions to it. - * - * @param r The Random instance to apply functions with - * - * @return ItemStack - The ItemStack with all functions applied. - */ - public ItemStack getItem(Random r) { - ItemStack item = this.item.newItemStack(1); - for(LootFunction f : functions) { - item = f.apply(item, r); - } - return item; - } - - /** - * Gets the weight attribute of the Entry. - * - * @return long - The weight of the Entry. - */ - public long getWeight() { - return this.weight; - } -} diff --git a/common/addons/config-structure/src/main/java/com/dfsek/terra/addons/structure/structures/loot/LootTableImpl.java b/common/addons/config-structure/src/main/java/com/dfsek/terra/addons/structure/structures/loot/LootTableImpl.java deleted file mode 100644 index c817c2d2d..000000000 --- a/common/addons/config-structure/src/main/java/com/dfsek/terra/addons/structure/structures/loot/LootTableImpl.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * 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.addons.structure.structures.loot; - -import org.json.simple.JSONArray; -import org.json.simple.JSONObject; -import org.json.simple.parser.JSONParser; -import org.json.simple.parser.ParseException; - -import java.util.ArrayList; -import java.util.List; -import java.util.Random; - -import com.dfsek.terra.api.Platform; -import com.dfsek.terra.api.inventory.Inventory; -import com.dfsek.terra.api.inventory.ItemStack; - - -/** - * Class representation of a Loot Table to populate chest loot. - */ -public class LootTableImpl implements com.dfsek.terra.api.structure.LootTable { - private final List pools = new ArrayList<>(); - - /** - * Instantiates a LootTable from a JSON String. - * - * @param json The JSON String representing the loot table. - * - * @throws ParseException if malformed JSON is passed. - */ - public LootTableImpl(String json, Platform platform) throws ParseException { - JSONParser jsonParser = new JSONParser(); - Object tableJSON = jsonParser.parse(json); - JSONArray poolArray = (JSONArray) ((JSONObject) tableJSON).get("pools"); - for(Object pool : poolArray) { - pools.add(new Pool((JSONObject) pool, platform)); - } - } - - @Override - public void fillInventory(Inventory i, Random r) { - List loot = getLoot(r); - for(ItemStack stack : loot) { - int attempts = 0; - while(stack.getAmount() != 0 && attempts < 10) { - ItemStack newStack = stack.getType().newItemStack(stack.getAmount()); - newStack.setItemMeta(stack.getItemMeta()); - newStack.setAmount(1); - int slot = r.nextInt(i.getSize()); - ItemStack slotItem = i.getItem(slot); - if(slotItem == null) { - i.setItem(slot, newStack); - stack.setAmount(stack.getAmount() - 1); - } else if(slotItem.getType().equals(newStack.getType())) { - ItemStack dep = newStack.getType().newItemStack(newStack.getAmount()); - dep.setItemMeta(newStack.getItemMeta()); - dep.setAmount(newStack.getAmount() + slotItem.getAmount()); - i.setItem(slot, dep); - stack.setAmount(stack.getAmount() - 1); - } - attempts++; - } - } - } - - @Override - public List getLoot(Random r) { - List itemList = new ArrayList<>(); - for(Pool pool : pools) { - itemList.addAll(pool.getItems(r)); - } - return itemList; - } -} diff --git a/common/addons/config-structure/src/main/java/com/dfsek/terra/addons/structure/structures/loot/Pool.java b/common/addons/config-structure/src/main/java/com/dfsek/terra/addons/structure/structures/loot/Pool.java deleted file mode 100644 index a807cb4a1..000000000 --- a/common/addons/config-structure/src/main/java/com/dfsek/terra/addons/structure/structures/loot/Pool.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * 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.addons.structure.structures.loot; - -import net.jafama.FastMath; -import org.json.simple.JSONArray; -import org.json.simple.JSONObject; - -import java.util.ArrayList; -import java.util.List; -import java.util.Random; - -import com.dfsek.terra.api.Platform; -import com.dfsek.terra.api.inventory.ItemStack; -import com.dfsek.terra.api.util.collection.ProbabilityCollection; - - -/** - * Representation of a Loot Table pool, or a set of items to be fetched independently. - */ -public class Pool { - private final int max; - private final int min; - private final ProbabilityCollection entries; - - /** - * Instantiates a Pool from a JSON representation. - * - * @param pool The JSON Object to instantiate from. - */ - public Pool(JSONObject pool, Platform platform) { - entries = new ProbabilityCollection<>(); - Object amount = pool.get("rolls"); - if(amount instanceof Long) { - max = FastMath.toIntExact((Long) amount); - min = FastMath.toIntExact((Long) amount); - } else { - max = FastMath.toIntExact((Long) ((JSONObject) amount).get("max")); - min = FastMath.toIntExact((Long) ((JSONObject) amount).get("min")); - } - - for(Object entryJSON : (JSONArray) pool.get("entries")) { - Entry entry = new Entry((JSONObject) entryJSON, platform); - entries.add(entry, FastMath.toIntExact(entry.getWeight())); - } - } - - /** - * Fetches a list of items from the pool using the provided Random instance. - * - * @param r The Random instance to use. - * - * @return List<ItemStack> - The list of items fetched. - */ - public List getItems(Random r) { - - int rolls = r.nextInt(max - min + 1) + min; - List items = new ArrayList<>(); - for(int i = 0; i < rolls; i++) { - items.add(entries.get(r).getItem(r)); - } - return items; - } -} diff --git a/common/addons/config-structure/src/main/java/com/dfsek/terra/addons/structure/structures/loot/functions/AmountFunction.java b/common/addons/config-structure/src/main/java/com/dfsek/terra/addons/structure/structures/loot/functions/AmountFunction.java deleted file mode 100644 index 8fd59a5ee..000000000 --- a/common/addons/config-structure/src/main/java/com/dfsek/terra/addons/structure/structures/loot/functions/AmountFunction.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * 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.addons.structure.structures.loot.functions; - - -import java.util.Random; - -import com.dfsek.terra.api.inventory.ItemStack; - - -/** - * Loot LootFunction fot setting the amount of an item. - */ -public class AmountFunction implements LootFunction { - private final int max; - private final int min; - - /** - * Instantiates an AmountFunction. - * - * @param min Minimum amount. - * @param max Maximum amount. - */ - public AmountFunction(int min, int max) { - this.min = min; - this.max = max; - } - - /** - * Applies the function to an ItemStack. - * - * @param original The ItemStack on which to apply the function. - * @param r The Random instance to use. - * - * @return - ItemStack - The mutated ItemStack. - */ - @Override - public ItemStack apply(ItemStack original, Random r) { - original.setAmount(r.nextInt(max - min + 1) + min); - return original; - } -} diff --git a/common/addons/config-structure/src/main/java/com/dfsek/terra/addons/structure/structures/loot/functions/DamageFunction.java b/common/addons/config-structure/src/main/java/com/dfsek/terra/addons/structure/structures/loot/functions/DamageFunction.java deleted file mode 100644 index 09eda7417..000000000 --- a/common/addons/config-structure/src/main/java/com/dfsek/terra/addons/structure/structures/loot/functions/DamageFunction.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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.addons.structure.structures.loot.functions; - -import java.util.Random; - -import com.dfsek.terra.api.inventory.ItemStack; -import com.dfsek.terra.api.inventory.item.Damageable; -import com.dfsek.terra.api.inventory.item.ItemMeta; - - -/** - * Loot LootFunction for setting the damage on items in Loot Tables - */ -public class DamageFunction implements LootFunction { - private final int max; - private final int min; - - /** - * Instantiates a DamageFunction. - * - * @param min Minimum amount of damage (percentage, out of 100) - * @param max Maximum amount of damage (percentage, out of 100) - */ - public DamageFunction(int min, int max) { - this.min = min; - this.max = max; - } - - /** - * Applies the function to an ItemStack. - * - * @param original The ItemStack on which to apply the function. - * @param r The Random instance to use. - * - * @return - ItemStack - The mutated ItemStack. - */ - @Override - public ItemStack apply(ItemStack original, Random r) { - if(original == null) return null; - if(!original.isDamageable()) return original; - ItemMeta meta = original.getItemMeta(); - double itemDurability = (r.nextDouble() * (max - min)) + min; - Damageable damage = (Damageable) meta; - damage.setDamage((int) (original.getType().getMaxDurability() - (itemDurability / 100) * original.getType().getMaxDurability())); - original.setItemMeta((ItemMeta) damage); - return original; - } -} diff --git a/common/addons/config-structure/src/main/java/com/dfsek/terra/addons/structure/structures/loot/functions/EnchantFunction.java b/common/addons/config-structure/src/main/java/com/dfsek/terra/addons/structure/structures/loot/functions/EnchantFunction.java deleted file mode 100644 index 6f5b4d62d..000000000 --- a/common/addons/config-structure/src/main/java/com/dfsek/terra/addons/structure/structures/loot/functions/EnchantFunction.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * 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.addons.structure.structures.loot.functions; - -import net.jafama.FastMath; -import org.json.simple.JSONArray; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Random; - -import com.dfsek.terra.api.Platform; -import com.dfsek.terra.api.inventory.ItemStack; -import com.dfsek.terra.api.inventory.item.Enchantment; -import com.dfsek.terra.api.inventory.item.ItemMeta; - - -public class EnchantFunction implements LootFunction { - private static final Logger LOGGER = LoggerFactory.getLogger(EnchantFunction.class); - private final int min; - private final int max; - private final JSONArray disabled; - private final Platform platform; - - - public EnchantFunction(int min, int max, JSONArray disabled, Platform platform) { - this.max = max; - this.min = min; - this.disabled = disabled; - this.platform = platform; - } - - /** - * Applies the function to an ItemStack. - * - * @param original The ItemStack on which to apply the function. - * @param r The Random instance to use. - * - * @return - ItemStack - The mutated ItemStack. - */ - @Override - public ItemStack apply(ItemStack original, Random r) { - if(original.getItemMeta() == null) return original; - - double enchant = (r.nextDouble() * (max - min)) + min; - List possible = new ArrayList<>(); - for(Enchantment ench : platform.getItemHandle().getEnchantments()) { - if(ench.canEnchantItem(original) && (disabled == null || !this.disabled.contains(ench.getID()))) { - possible.add(ench); - } - } - int numEnchant = (r.nextInt((int) FastMath.abs(enchant)) / 10 + 1); - Collections.shuffle(possible); - ItemMeta meta = original.getItemMeta(); - iter: - for(int i = 0; i < numEnchant && i < possible.size(); i++) { - Enchantment chosen = possible.get(i); - for(Enchantment ench : meta.getEnchantments().keySet()) { - if(chosen.conflictsWith(ench)) continue iter; - } - int lvl = r.nextInt(1 + (int) (((enchant / 40 > 1) ? 1 : enchant / 40) * (chosen.getMaxLevel()))); - try { - meta.addEnchantment(chosen, FastMath.max(lvl, 1)); - } catch(IllegalArgumentException e) { - LOGGER.warn( - "Attempted to enchant {} with {} at level {}, but an unexpected exception occurred! Usually this is caused by a " + - "misbehaving enchantment plugin.", - original.getType(), chosen, FastMath.max(lvl, 1)); - } - } - original.setItemMeta(meta); - return original; - } -} diff --git a/common/addons/config-structure/src/main/java/com/dfsek/terra/addons/structure/structures/loot/functions/LootFunction.java b/common/addons/config-structure/src/main/java/com/dfsek/terra/addons/structure/structures/loot/functions/LootFunction.java deleted file mode 100644 index ebe0fd550..000000000 --- a/common/addons/config-structure/src/main/java/com/dfsek/terra/addons/structure/structures/loot/functions/LootFunction.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * 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.addons.structure.structures.loot.functions; - - -import java.util.Random; - -import com.dfsek.terra.api.inventory.ItemStack; - - -/** - * Interface for mutating items in Loot Tables. - */ -public interface LootFunction { - /** - * Applies the function to an ItemStack. - * - * @param original The ItemStack on which to apply the function. - * @param r The Random instance to use. - * - * @return - ItemStack - The mutated ItemStack. - */ - ItemStack apply(ItemStack original, Random r); -} diff --git a/common/addons/generation-stage-feature/src/main/java/com/dfsek/terra/addons/generation/feature/FeatureGenerationStage.java b/common/addons/generation-stage-feature/src/main/java/com/dfsek/terra/addons/generation/feature/FeatureGenerationStage.java index 5408b26e4..527c15159 100644 --- a/common/addons/generation-stage-feature/src/main/java/com/dfsek/terra/addons/generation/feature/FeatureGenerationStage.java +++ b/common/addons/generation-stage-feature/src/main/java/com/dfsek/terra/addons/generation/feature/FeatureGenerationStage.java @@ -8,7 +8,8 @@ package com.dfsek.terra.addons.generation.feature; import java.util.Collections; -import java.util.Random; +import java.util.random.RandomGenerator; +import java.util.random.RandomGeneratorFactory; import com.dfsek.terra.addons.generation.feature.config.BiomeFeatures; import com.dfsek.terra.api.Platform; @@ -58,7 +59,6 @@ public class FeatureGenerationStage implements GenerationStage, StringIdentifiab for(int subChunkZ = 0; subChunkZ < resolution; subChunkZ++) { int x = subChunkX + tx; int z = subChunkZ + tz; - long coordinateSeed = (seed * 31 + x) * 31 + z; Column column = world.column(x, z); biome.getContext() .get(biomeFeaturesKey) @@ -72,7 +72,6 @@ public class FeatureGenerationStage implements GenerationStage, StringIdentifiab .forEach(y -> feature.getStructure(world, x, y, z) .generate(Vector3Int.of(x, y, z), world, - new Random(coordinateSeed * 31 + y), Rotation.NONE) ); } diff --git a/common/addons/language-yaml/build.gradle.kts b/common/addons/language-yaml/build.gradle.kts index bb180dae9..88b5ccfcf 100644 --- a/common/addons/language-yaml/build.gradle.kts +++ b/common/addons/language-yaml/build.gradle.kts @@ -1,6 +1,6 @@ version = version("1.0.0") dependencies { - implementation("com.dfsek.tectonic:yaml:${Versions.Libraries.tectonic}") + implementation(libs.libraries.tectonic.yaml) compileOnlyApi(project(":common:addons:manifest-addon-loader")) } diff --git a/common/addons/manifest-addon-loader/build.gradle.kts b/common/addons/manifest-addon-loader/build.gradle.kts index 6a5b6f54e..1964188ff 100644 --- a/common/addons/manifest-addon-loader/build.gradle.kts +++ b/common/addons/manifest-addon-loader/build.gradle.kts @@ -1,8 +1,8 @@ version = version("1.0.0") dependencies { - api("commons-io:commons-io:2.7") - implementation("com.dfsek.tectonic:yaml:${Versions.Libraries.tectonic}") + api(libs.libraries.internal.apache.io) + implementation(libs.libraries.tectonic.yaml) } tasks.withType { diff --git a/common/addons/structure-block-shortcut/src/main/java/com/dfsek/terra/addons/palette/shortcut/block/SingletonStructure.java b/common/addons/structure-block-shortcut/src/main/java/com/dfsek/terra/addons/palette/shortcut/block/SingletonStructure.java index 7d14c6ee7..83b37c652 100644 --- a/common/addons/structure-block-shortcut/src/main/java/com/dfsek/terra/addons/palette/shortcut/block/SingletonStructure.java +++ b/common/addons/structure-block-shortcut/src/main/java/com/dfsek/terra/addons/palette/shortcut/block/SingletonStructure.java @@ -1,6 +1,6 @@ package com.dfsek.terra.addons.palette.shortcut.block; -import java.util.Random; +import java.util.random.RandomGenerator; import com.dfsek.terra.api.block.state.BlockState; import com.dfsek.terra.api.structure.Structure; @@ -17,7 +17,7 @@ public class SingletonStructure implements Structure { } @Override - public boolean generate(Vector3Int location, WritableWorld world, Random random, Rotation rotation) { + public boolean generate(Vector3Int location, WritableWorld world, Rotation rotation) { world.setBlockState(location, blockState); return true; } diff --git a/common/addons/structure-mutator/src/main/java/com/dfsek/terra/addons/structure/mutator/MutatedStructure.java b/common/addons/structure-mutator/src/main/java/com/dfsek/terra/addons/structure/mutator/MutatedStructure.java index a5aafdd1e..c05d5a320 100644 --- a/common/addons/structure-mutator/src/main/java/com/dfsek/terra/addons/structure/mutator/MutatedStructure.java +++ b/common/addons/structure-mutator/src/main/java/com/dfsek/terra/addons/structure/mutator/MutatedStructure.java @@ -1,6 +1,6 @@ package com.dfsek.terra.addons.structure.mutator; -import java.util.Random; +import java.util.random.RandomGenerator; import com.dfsek.terra.api.registry.key.Keyed; import com.dfsek.terra.api.registry.key.RegistryKey; @@ -32,13 +32,12 @@ public class MutatedStructure implements Structure, Keyed { } @Override - public boolean generate(Vector3Int location, WritableWorld world, Random random, Rotation rotation) { + public boolean generate(Vector3Int location, WritableWorld world, Rotation rotation) { return base.generate(location, world .buffer() .read(readInterceptor) .write(writeInterceptor) - .build(), - random, rotation); + .build(), rotation); } } diff --git a/common/addons/structure-sponge-loader/src/main/java/com/dfsek/terra/addons/sponge/SpongeStructure.java b/common/addons/structure-sponge-loader/src/main/java/com/dfsek/terra/addons/sponge/SpongeStructure.java index e08c51146..cf8df81e5 100644 --- a/common/addons/structure-sponge-loader/src/main/java/com/dfsek/terra/addons/sponge/SpongeStructure.java +++ b/common/addons/structure-sponge-loader/src/main/java/com/dfsek/terra/addons/sponge/SpongeStructure.java @@ -7,7 +7,7 @@ package com.dfsek.terra.addons.sponge; -import java.util.Random; +import java.util.random.RandomGenerator; import com.dfsek.terra.api.block.state.BlockState; import com.dfsek.terra.api.registry.key.Keyed; @@ -31,7 +31,7 @@ public class SpongeStructure implements Structure, Keyed { } @Override - public boolean generate(Vector3Int location, WritableWorld world, Random random, Rotation rotation) { + public boolean generate(Vector3Int location, WritableWorld world, Rotation rotation) { int bX = location.getX(); int bY = location.getY(); int bZ = location.getZ(); diff --git a/common/addons/structure-terrascript-loader/build.gradle.kts b/common/addons/structure-terrascript-loader/build.gradle.kts index 18d4019b9..579b2c964 100644 --- a/common/addons/structure-terrascript-loader/build.gradle.kts +++ b/common/addons/structure-terrascript-loader/build.gradle.kts @@ -1,15 +1,6 @@ -import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar - version = version("1.1.0") dependencies { - api("commons-io:commons-io:2.7") compileOnlyApi(project(":common:addons:manifest-addon-loader")) - implementation("net.jafama", "jafama", Versions.Libraries.Internal.jafama) - testImplementation("net.jafama", "jafama", Versions.Libraries.Internal.jafama) -} - -tasks.named("shadowJar") { - relocate("org.apache.commons", "com.dfsek.terra.addons.terrascript.lib.commons") - relocate("net.jafama", "com.dfsek.terra.addons.terrascript.lib.jafama") + api(libs.libraries.internal.apache.io) } \ No newline at end of file diff --git a/common/addons/structure-terrascript-loader/src/main/java/com/dfsek/terra/addons/terrascript/script/StructureScript.java b/common/addons/structure-terrascript-loader/src/main/java/com/dfsek/terra/addons/terrascript/script/StructureScript.java index e865d0d6d..de0b7a39f 100644 --- a/common/addons/structure-terrascript-loader/src/main/java/com/dfsek/terra/addons/terrascript/script/StructureScript.java +++ b/common/addons/structure-terrascript-loader/src/main/java/com/dfsek/terra/addons/terrascript/script/StructureScript.java @@ -15,7 +15,7 @@ import org.slf4j.LoggerFactory; import java.io.IOException; import java.io.InputStream; import java.nio.charset.Charset; -import java.util.Random; +import java.util.random.RandomGenerator; import com.dfsek.terra.addons.terrascript.parser.Parser; import com.dfsek.terra.addons.terrascript.parser.lang.Executable; @@ -29,7 +29,6 @@ import com.dfsek.terra.addons.terrascript.script.builders.EntityFunctionBuilder; import com.dfsek.terra.addons.terrascript.script.builders.GetMarkFunctionBuilder; import com.dfsek.terra.addons.terrascript.script.builders.LootFunctionBuilder; import com.dfsek.terra.addons.terrascript.script.builders.PullFunctionBuilder; -import com.dfsek.terra.addons.terrascript.script.builders.RandomFunctionBuilder; import com.dfsek.terra.addons.terrascript.script.builders.RecursionsFunctionBuilder; import com.dfsek.terra.addons.terrascript.script.builders.SetMarkFunctionBuilder; import com.dfsek.terra.addons.terrascript.script.builders.StateFunctionBuilder; @@ -77,7 +76,6 @@ public class StructureScript implements Structure, Keyed { .registerFunction("block", new BlockFunctionBuilder(platform)) .registerFunction("debugBlock", new BlockFunctionBuilder(platform)) .registerFunction("structure", new StructureFunctionBuilder(registry, platform)) - .registerFunction("randomInt", new RandomFunctionBuilder()) .registerFunction("recursions", new RecursionsFunctionBuilder()) .registerFunction("setMark", new SetMarkFunctionBuilder()) .registerFunction("getMark", new GetMarkFunctionBuilder()) @@ -130,16 +128,16 @@ public class StructureScript implements Structure, Keyed { @Override @SuppressWarnings("try") - public boolean generate(Vector3Int location, WritableWorld world, Random random, Rotation rotation) { + public boolean generate(Vector3Int location, WritableWorld world, Rotation rotation) { platform.getProfiler().push(profile); - boolean result = applyBlock(new TerraImplementationArguments(location, rotation, random, world, 0)); + boolean result = applyBlock(new TerraImplementationArguments(location, rotation, world, 0)); platform.getProfiler().pop(profile); return result; } - public boolean generate(Vector3Int location, WritableWorld world, Random random, Rotation rotation, int recursions) { + public boolean generate(Vector3Int location, WritableWorld world, Rotation rotation, int recursions) { platform.getProfiler().push(profile); - boolean result = applyBlock(new TerraImplementationArguments(location, rotation, random, world, recursions)); + boolean result = applyBlock(new TerraImplementationArguments(location, rotation, world, recursions)); platform.getProfiler().pop(profile); return result; } diff --git a/common/addons/structure-terrascript-loader/src/main/java/com/dfsek/terra/addons/terrascript/script/TerraImplementationArguments.java b/common/addons/structure-terrascript-loader/src/main/java/com/dfsek/terra/addons/terrascript/script/TerraImplementationArguments.java index b9b9af058..4844b2d9e 100644 --- a/common/addons/structure-terrascript-loader/src/main/java/com/dfsek/terra/addons/terrascript/script/TerraImplementationArguments.java +++ b/common/addons/structure-terrascript-loader/src/main/java/com/dfsek/terra/addons/terrascript/script/TerraImplementationArguments.java @@ -9,7 +9,7 @@ package com.dfsek.terra.addons.terrascript.script; import java.util.HashMap; import java.util.Map; -import java.util.Random; +import java.util.random.RandomGenerator; import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments; import com.dfsek.terra.api.util.Rotation; @@ -20,16 +20,14 @@ import com.dfsek.terra.api.world.WritableWorld; public class TerraImplementationArguments implements ImplementationArguments { private final Rotation rotation; - private final Random random; private final WritableWorld world; private final Map marks = new HashMap<>(); private final int recursions; private final Vector3Int origin; private boolean waterlog = false; - public TerraImplementationArguments(Vector3Int origin, Rotation rotation, Random random, WritableWorld world, int recursions) { + public TerraImplementationArguments(Vector3Int origin, Rotation rotation, WritableWorld world, int recursions) { this.rotation = rotation; - this.random = random; this.world = world; this.recursions = recursions; this.origin = origin; @@ -39,10 +37,6 @@ public class TerraImplementationArguments implements ImplementationArguments { return recursions; } - public Random getRandom() { - return random; - } - public Rotation getRotation() { return rotation; } diff --git a/common/addons/structure-terrascript-loader/src/main/java/com/dfsek/terra/addons/terrascript/script/builders/RandomFunctionBuilder.java b/common/addons/structure-terrascript-loader/src/main/java/com/dfsek/terra/addons/terrascript/script/builders/RandomFunctionBuilder.java deleted file mode 100644 index 6cfeaa52d..000000000 --- a/common/addons/structure-terrascript-loader/src/main/java/com/dfsek/terra/addons/terrascript/script/builders/RandomFunctionBuilder.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * 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.addons.terrascript.script.builders; - -import java.util.List; - -import com.dfsek.terra.addons.terrascript.parser.lang.Returnable; -import com.dfsek.terra.addons.terrascript.parser.lang.functions.FunctionBuilder; -import com.dfsek.terra.addons.terrascript.script.functions.RandomFunction; -import com.dfsek.terra.addons.terrascript.tokenizer.Position; - - -public class RandomFunctionBuilder implements FunctionBuilder { - @SuppressWarnings("unchecked") - @Override - public RandomFunction build(List> argumentList, Position position) { - return new RandomFunction((Returnable) argumentList.get(0), position); - } - - @Override - public int argNumber() { - return 1; - } - - @Override - public Returnable.ReturnType getArgument(int position) { - if(position == 0) return Returnable.ReturnType.NUMBER; - return null; - } -} diff --git a/common/addons/structure-terrascript-loader/src/main/java/com/dfsek/terra/addons/terrascript/script/functions/LootFunction.java b/common/addons/structure-terrascript-loader/src/main/java/com/dfsek/terra/addons/terrascript/script/functions/LootFunction.java index ebadb9288..f785e17d3 100644 --- a/common/addons/structure-terrascript-loader/src/main/java/com/dfsek/terra/addons/terrascript/script/functions/LootFunction.java +++ b/common/addons/structure-terrascript-loader/src/main/java/com/dfsek/terra/addons/terrascript/script/functions/LootFunction.java @@ -11,8 +11,6 @@ import net.jafama.FastMath; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.Random; - import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments; import com.dfsek.terra.addons.terrascript.parser.lang.Returnable; import com.dfsek.terra.addons.terrascript.parser.lang.Scope; @@ -31,6 +29,9 @@ import com.dfsek.terra.api.util.RotationUtil; import com.dfsek.terra.api.util.vector.Vector2; import com.dfsek.terra.api.util.vector.Vector3; +import java.util.random.RandomGenerator; +import java.util.random.RandomGeneratorFactory; + public class LootFunction implements Function { private static final Logger LOGGER = LoggerFactory.getLogger(LootFunction.class); @@ -84,8 +85,7 @@ public class LootFunction implements Function { platform.getEventManager().callEvent(event); if(event.isCancelled()) return; - event.getTable().fillInventory(container.getInventory(), - new Random(apply.hashCode())); + event.getTable().fillInventory(container.getInventory()); data.update(false); } catch(Exception e) { LOGGER.error("Could not apply loot at {}", apply, e); diff --git a/common/addons/structure-terrascript-loader/src/main/java/com/dfsek/terra/addons/terrascript/script/functions/RandomFunction.java b/common/addons/structure-terrascript-loader/src/main/java/com/dfsek/terra/addons/terrascript/script/functions/RandomFunction.java deleted file mode 100644 index 3170d2645..000000000 --- a/common/addons/structure-terrascript-loader/src/main/java/com/dfsek/terra/addons/terrascript/script/functions/RandomFunction.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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.addons.terrascript.script.functions; - -import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments; -import com.dfsek.terra.addons.terrascript.parser.lang.Returnable; -import com.dfsek.terra.addons.terrascript.parser.lang.Scope; -import com.dfsek.terra.addons.terrascript.parser.lang.functions.Function; -import com.dfsek.terra.addons.terrascript.script.TerraImplementationArguments; -import com.dfsek.terra.addons.terrascript.tokenizer.Position; - - -public class RandomFunction implements Function { - private final Returnable numberReturnable; - private final Position position; - - public RandomFunction(Returnable numberReturnable, Position position) { - this.numberReturnable = numberReturnable; - this.position = position; - } - - - @Override - public ReturnType returnType() { - return ReturnType.NUMBER; - } - - @Override - public Integer apply(ImplementationArguments implementationArguments, Scope scope) { - return ((TerraImplementationArguments) implementationArguments).getRandom().nextInt( - numberReturnable.apply(implementationArguments, scope).intValue()); - } - - @Override - public Position getPosition() { - return position; - } -} diff --git a/common/addons/structure-terrascript-loader/src/main/java/com/dfsek/terra/addons/terrascript/script/functions/StructureFunction.java b/common/addons/structure-terrascript-loader/src/main/java/com/dfsek/terra/addons/terrascript/script/functions/StructureFunction.java index 51fb47054..84245a763 100644 --- a/common/addons/structure-terrascript-loader/src/main/java/com/dfsek/terra/addons/terrascript/script/functions/StructureFunction.java +++ b/common/addons/structure-terrascript-loader/src/main/java/com/dfsek/terra/addons/terrascript/script/functions/StructureFunction.java @@ -67,31 +67,20 @@ public class StructureFunction implements Function { String app = id.apply(implementationArguments, scope); return registry.getByID(app).map(script -> { - Rotation rotation1; - String rotString = rotations.get(arguments.getRandom().nextInt(rotations.size())).apply(implementationArguments, scope); - try { - rotation1 = Rotation.valueOf(rotString); - } catch(IllegalArgumentException e) { - LOGGER.warn("Invalid rotation {}", rotString); - return false; - } - if(script instanceof StructureScript structureScript) { return structureScript.generate(arguments.getOrigin(), arguments.getWorld() .buffer(FastMath.roundToInt(xz.getX()), y.apply(implementationArguments, scope).intValue(), FastMath.roundToInt(xz.getZ())), - arguments.getRandom(), - arguments.getRotation().rotate(rotation1), arguments.getRecursions() + 1); + arguments.getRotation(), arguments.getRecursions() + 1); } return script.generate(arguments.getOrigin(), arguments.getWorld() .buffer(FastMath.roundToInt(xz.getX()), y.apply(implementationArguments, scope).intValue(), FastMath.roundToInt(xz.getZ())), - arguments.getRandom(), - arguments.getRotation().rotate(rotation1)); + arguments.getRotation()); }).orElseGet(() -> { LOGGER.error("No such structure {}", app); return false; diff --git a/common/addons/terrascript-function-check-noise-3d/build.gradle.kts b/common/addons/terrascript-function-check-noise-3d/build.gradle.kts index 51bb33cf6..9b35e7ea0 100644 --- a/common/addons/terrascript-function-check-noise-3d/build.gradle.kts +++ b/common/addons/terrascript-function-check-noise-3d/build.gradle.kts @@ -4,11 +4,4 @@ dependencies { compileOnlyApi(project(":common:addons:manifest-addon-loader")) compileOnlyApi(project(":common:addons:chunk-generator-noise-3d")) compileOnlyApi(project(":common:addons:structure-terrascript-loader")) - - implementation("net.jafama", "jafama", Versions.Libraries.Internal.jafama) - testImplementation("net.jafama", "jafama", Versions.Libraries.Internal.jafama) -} - -tasks.named("shadowJar") { - relocate("net.jafama", "com.dfsek.terra.addon.terrascript.check.lib.jafama") } diff --git a/common/api/build.gradle.kts b/common/api/build.gradle.kts index b82c614ed..d6b54518a 100644 --- a/common/api/build.gradle.kts +++ b/common/api/build.gradle.kts @@ -1,14 +1,16 @@ dependencies { - api("ca.solo-studios", "strata", Versions.Libraries.strata) - compileOnlyApi("org.slf4j", "slf4j-api", Versions.Libraries.slf4j) - testImplementation("org.slf4j", "slf4j-api", Versions.Libraries.slf4j) - api("cloud.commandframework", "cloud-core", Versions.Libraries.cloud) + api(libs.libraries.strata) + compileOnlyApi(libs.libraries.slf4j.api) + testImplementation(libs.libraries.slf4j.api) + api(libs.libraries.cloud.core) - api("com.dfsek.tectonic", "common", Versions.Libraries.tectonic) + api(libs.libraries.tectonic) - api("com.github.ben-manes.caffeine", "caffeine", Versions.Libraries.caffeine) + api(libs.libraries.caffeine) - api("io.vavr", "vavr", Versions.Libraries.vavr) + api(libs.libraries.vavr) - implementation("net.jafama", "jafama", Versions.Libraries.Internal.jafama) + api(libs.libraries.jafama) + + api(libs.libraries.paralithic) } \ No newline at end of file diff --git a/common/api/src/main/java/com/dfsek/terra/api/structure/LootTable.java b/common/api/src/main/java/com/dfsek/terra/api/structure/LootTable.java index 162247c82..8995413e9 100644 --- a/common/api/src/main/java/com/dfsek/terra/api/structure/LootTable.java +++ b/common/api/src/main/java/com/dfsek/terra/api/structure/LootTable.java @@ -10,7 +10,7 @@ package com.dfsek.terra.api.structure; import org.jetbrains.annotations.ApiStatus.Experimental; import java.util.List; -import java.util.Random; +import java.util.random.RandomGenerator; import com.dfsek.terra.api.inventory.Inventory; import com.dfsek.terra.api.inventory.ItemStack; @@ -22,16 +22,15 @@ public interface LootTable { * Fills an Inventory with loot. * * @param i The Inventory to fill. - * @param r The The Random instance to use. */ - void fillInventory(Inventory i, Random r); + void fillInventory(Inventory i); /** - * Fetches a list of ItemStacks from the loot table using the given Random instance. + * Fetches a list of ItemStacks from the loot table using the given RandomGenerator instance. * - * @param r The Random instance to use. + * @param r The RandomGenerator instance to use. * * @return List<ItemStack> - The list of loot fetched. */ - List getLoot(Random r); + List getLoot(RandomGenerator r); } diff --git a/common/api/src/main/java/com/dfsek/terra/api/structure/Structure.java b/common/api/src/main/java/com/dfsek/terra/api/structure/Structure.java index 479c77e38..ddd2d77ed 100644 --- a/common/api/src/main/java/com/dfsek/terra/api/structure/Structure.java +++ b/common/api/src/main/java/com/dfsek/terra/api/structure/Structure.java @@ -7,13 +7,14 @@ package com.dfsek.terra.api.structure; -import java.util.Random; +import java.util.random.RandomGenerator; +import com.dfsek.terra.api.noise.NoiseSampler; import com.dfsek.terra.api.util.Rotation; import com.dfsek.terra.api.util.vector.Vector3Int; import com.dfsek.terra.api.world.WritableWorld; public interface Structure { - boolean generate(Vector3Int location, WritableWorld world, Random random, Rotation rotation); + boolean generate(Vector3Int location, WritableWorld world, Rotation rotation); } diff --git a/common/api/src/main/java/com/dfsek/terra/api/util/ConstantRange.java b/common/api/src/main/java/com/dfsek/terra/api/util/ConstantRange.java index 5849d09a6..cb8bc8278 100644 --- a/common/api/src/main/java/com/dfsek/terra/api/util/ConstantRange.java +++ b/common/api/src/main/java/com/dfsek/terra/api/util/ConstantRange.java @@ -11,7 +11,7 @@ import net.jafama.FastMath; import org.jetbrains.annotations.NotNull; import java.util.Iterator; -import java.util.Random; +import java.util.random.RandomGenerator; public class ConstantRange implements Range { @@ -37,7 +37,7 @@ public class ConstantRange implements Range { } @Override - public int get(Random r) { + public int get(RandomGenerator r) { return r.nextInt(min, max); } diff --git a/common/api/src/main/java/com/dfsek/terra/api/util/MathUtil.java b/common/api/src/main/java/com/dfsek/terra/api/util/MathUtil.java index 3c95df139..8e78f1f8b 100644 --- a/common/api/src/main/java/com/dfsek/terra/api/util/MathUtil.java +++ b/common/api/src/main/java/com/dfsek/terra/api/util/MathUtil.java @@ -173,4 +173,21 @@ public final class MathUtil { return mu + sigma * val; } + + /** + * 1D Linear interpolation between 2 points 1 unit apart. + * + * @param t - Distance from v0. Total distance between v0 and v1 is 1 unit. + * @param v0 - Value at v0. + * @param v1 - Value at v1. + * + * @return double - The interpolated value. + */ + public static double lerp(double t, double v0, double v1) { + return v0 + t * (v1 - v0); + } + + public static double inverseLerp(double t, double v0, double v1) { + return (t - v0) / (v1 - v0); + } } diff --git a/common/api/src/main/java/com/dfsek/terra/api/util/PopulationUtil.java b/common/api/src/main/java/com/dfsek/terra/api/util/PopulationUtil.java deleted file mode 100644 index d8949a0c2..000000000 --- a/common/api/src/main/java/com/dfsek/terra/api/util/PopulationUtil.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2020-2021 Polyhedral Development - * - * The Terra API is licensed under the terms of the MIT License. For more details, - * reference the LICENSE file in the common/api directory. - */ - -package com.dfsek.terra.api.util; - -import java.util.Random; - -import com.dfsek.terra.api.world.chunk.Chunk; - - -public final class PopulationUtil { - public static Random getRandom(Chunk c) { - return getRandom(c, 0); - } - - public static Random getRandom(Chunk c, long salt) { - return new Random(getCarverChunkSeed(c.getX(), c.getZ(), c.getWorld().getSeed() + salt)); - } - - /** - * Gets the carver seed for a chunk. - * - * @param chunkX Chunk's X coordinate - * @param chunkZ Chunk's Z coordinate - * @param seed World seed - * - * @return long - The carver seed. - */ - public static long getCarverChunkSeed(int chunkX, int chunkZ, long seed) { - Random r = new Random(seed); - return chunkX * r.nextLong() ^ chunkZ * r.nextLong() ^ seed; - } -} diff --git a/common/api/src/main/java/com/dfsek/terra/api/util/Range.java b/common/api/src/main/java/com/dfsek/terra/api/util/Range.java index c417b8183..df7c46d28 100644 --- a/common/api/src/main/java/com/dfsek/terra/api/util/Range.java +++ b/common/api/src/main/java/com/dfsek/terra/api/util/Range.java @@ -10,8 +10,8 @@ package com.dfsek.terra.api.util; import org.jetbrains.annotations.NotNull; import java.util.Iterator; -import java.util.Random; import java.util.function.Supplier; +import java.util.random.RandomGenerator; public interface Range extends Iterable { @@ -19,7 +19,7 @@ public interface Range extends Iterable { Range reflect(int pt); - int get(Random r); + int get(RandomGenerator r); Range intersects(Range other); diff --git a/common/api/src/main/java/com/dfsek/terra/api/util/collection/ProbabilityCollection.java b/common/api/src/main/java/com/dfsek/terra/api/util/collection/ProbabilityCollection.java index f5d5863c6..4302fa50f 100644 --- a/common/api/src/main/java/com/dfsek/terra/api/util/collection/ProbabilityCollection.java +++ b/common/api/src/main/java/com/dfsek/terra/api/util/collection/ProbabilityCollection.java @@ -15,9 +15,9 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.Map; -import java.util.Random; import java.util.Set; import java.util.function.Function; +import java.util.random.RandomGenerator; import com.dfsek.terra.api.noise.NoiseSampler; import com.dfsek.terra.api.util.MathUtil; @@ -43,7 +43,7 @@ public class ProbabilityCollection implements Collection { } @SuppressWarnings("unchecked") - public E get(Random r) { + public E get(RandomGenerator r) { if(array.length == 0) return null; return (E) array[r.nextInt(array.length)]; } @@ -195,7 +195,7 @@ public class ProbabilityCollection implements Collection { } @Override - public T get(Random r) { + public T get(RandomGenerator r) { return single; } diff --git a/common/implementation/base/build.gradle.kts b/common/implementation/base/build.gradle.kts index 1910484f0..a6d9bd1ac 100644 --- a/common/implementation/base/build.gradle.kts +++ b/common/implementation/base/build.gradle.kts @@ -2,14 +2,14 @@ dependencies { api(project(":common:api")) api(project(":common:implementation:bootstrap-addon-loader")) - testImplementation("org.slf4j", "slf4j-api", Versions.Libraries.slf4j) + testImplementation(libs.libraries.slf4j.api) - implementation("commons-io", "commons-io", Versions.Libraries.Internal.apacheIO) + implementation(libs.libraries.internal.apache.io) - implementation("org.apache.commons", "commons-text", Versions.Libraries.Internal.apacheText) - implementation("com.dfsek.tectonic", "yaml", Versions.Libraries.tectonic) + implementation(libs.libraries.internal.apache.text) + implementation(libs.libraries.tectonic.yaml) - implementation("net.jafama", "jafama", Versions.Libraries.Internal.jafama) + implementation(libs.libraries.jafama) - implementation("com.dfsek", "paralithic", Versions.Libraries.paralithic) + implementation(libs.libraries.paralithic) } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml new file mode 100644 index 000000000..03bcac999 --- /dev/null +++ b/gradle/libs.versions.toml @@ -0,0 +1,98 @@ +[versions] +libraries_tectonic = "4.2.0" +libraries_paralithic = "0.7.0" +libraries_strata = "1.3.1" +libraries_snakeyaml = "1.30" +libraries_cloud = "1.7.0" +libraries_slf4j = "1.7.36" +libraries_caffeine = "3.1.1" +libraries_vavr = "0.10.4" +libraries_jafama = "2.3.2" +libraries_guava = "31.1-jre" + +libraries_internal_apache-text = "1.9" +libraries_internal_apache-io = "2.11.0" +libraries_internal_fastutil = "8.5.8" +libraries_internal_shadow = "7.1.2" +libraries_internal_junit-jupiter = "5.9.0" +libraries_internal_jetbrains-annotations = "23.0.0" +libraries_internal_asm = "9.3" + +mod_mixin = "0.11.4+mixin.0.8.5" +mod_minecraft = "1.19.2" +mod_yarn = "1.19.2+build.4" +mod_architecury-loom = "0.12.0.299" +mod_architectury-plugin = "3.4.138" +mod_loom-quiltflower = "1.7.3" +mod_lazy-dfu = "0.1.3" + +mod_fabric_fabric-loader = "0.14.9" +mod_fabric_fabric-api = "0.60.0+1.19.2" + +mod_quilt_quilt-loader = "0.17.3" +mod_quilt_fabric-api = "4.0.0-beta.9+0.60.0-1.19.2" + +mod_forge_forge = "1.19.2-43.1.1" +mod_forge_burningwave = "12.59.0" + +bukkit_run-paper = "1.0.6" +bukkit_paperweight = "1.3.8" +bukkit_paper = "1.19-R0.1-20220725.172700-79" +bukkit_paper-lib = "1.0.7" +bukkit_minecraft = "1.19.2" +bukkit_reflection-remapper = "0.1.0-20220312.202611-7" + +cli_nbt = "6.1" +cli_logback = "1.2.11" + +[libraries] +libraries_tectonic = { module = "com.dfsek.tectonic:common", version.ref = "libraries_tectonic" } +libraries_tectonic_yaml = { module = "com.dfsek.tectonic:yaml", version.ref = "libraries_tectonic" } +libraries_paralithic = { module = "com.dfsek:paralithic", version.ref = "libraries_paralithic" } +libraries_strata = { module = "ca.solo-studios:strata", version.ref = "libraries_strata" } +libraries_snakeyaml = { module = "org.yaml:snakeyaml", version.ref = "libraries_snakeyaml" } +libraries_cloud-core = { module = "cloud.commandframework:cloud-core", version.ref = "libraries_cloud" } +libraries_slf4j-api = { module = "org.slf4j:slf4j-api", version.ref = "libraries_slf4j" } +libraries_caffeine = { module = "com.github.ben-manes.caffeine:caffeine", version.ref = "libraries_caffeine" } +libraries_vavr = { module = "io.vavr:vavr", version.ref = "libraries_vavr" } +libraries_guava = { module = "com.google.guava:guava", version.ref = "libraries_guava" } +libraries_jafama = { module = "net.jafama:jafama", version.ref = "libraries_jafama" } + +libraries_internal_apache-text = { module = "org.apache.commons:commons-text", version.ref = "libraries_internal_apache-text" } +libraries_internal_apache-io = { module = "commons-io:commons-io", version.ref = "libraries_internal_apache-io" } +libraries_internal_fastutil = { module = "it.unimi.dsi:fastutil ", version.ref = "libraries_internal_fastutil" } +libraries_internal_shadow = { module = "gradle.plugin.com.github.johnrengelman:shadow", version.ref = "libraries_internal_shadow" } +libraries_internal_junit-jupiter-api = { module = "org.junit.jupiter:junit-jupiter-api", version.ref = "libraries_internal_junit_jupiter" } +libraries_internal_junit-jupiter-engine = { module = "org.junit.jupiter:junit-jupiter-engine", version.ref = "libraries_internal_junit_jupiter" } +libraries_internal_jetbrains-annotations = { module = "org.jetbrains:annotations", version.ref = "libraries_internal_jetbrains_annotations" } +libraries_internal_asm = { module = "org.ow2.asm:asm", version.ref = "libraries_internal_asm" } +libraries_internal_asm-tree = { module = "org.ow2.asm:asm-tree", version.ref = "libraries_internal_asm" } + +mod_mixin = { module = "net.fabricmc:sponge-mixin", version.ref = "mod_mixin" } +mod_minecraft = { module = "com.mojang:minecraft", version.ref = "mod_minecraft" } +mod_lazy-dfu = { module = "maven.modrinth:lazydfu", version.ref = "mod_lazy-dfu" } +mod_cloud-fabric = { module = "cloud.commandframework:cloud-fabric", version.ref = "libraries_cloud" } + +mod_fabric_fabric-loader = { module = "net.fabricmc:fabric-loader", version.ref = "mod_fabric_fabric-loader" } + +mod_quilt_quilt-loader = { module = "org.quiltmc:quilt-loader", version.ref = "mod_quilt_quilt-loader" } +mod_quilt_fabric-api = { module = "org.quiltmc.quilted-fabric-api:quilted-fabric-api", version.ref = "mod_quilt_fabric-api" } + +mod_forge_forge = { module = "net.minecraftforge:forge", version.ref = "mod_forge_forge" } +mod_forge_burningwave = { module = "org.burningwave:core", version.ref = "mod_forge_burningwave" } + +bukkit_paper-api = { module = "io.papermc.paper:paper-api", version.ref = "bukkit_paper" } +bukkit_paper-lib = { module = "io.papermc:paperlib", version.ref = "bukkit_paper-lib" } +bukkit_reflection-remapper = { module = "xyz.jpenilla:reflection-remapper", version.ref = "bukkit_reflection-remapper" } +bukkit_cloud-paper = { module = "cloud.commandframework:cloud-paper", version.ref = "libraries_cloud" } + +cli_nbt = { module = "com.github.Querz:NBT", version.ref = "cli_nbt" } +cli_logback = { module = "ch.qos.logback:logback-classic", version.ref = "cli_logback" } + +[plugins] +mod_architectury-loom = { id = "dev.architectury.loom", version.ref = "mod_architecury-loom" } +mod_architectury-plugin = { id = "architectury-plugin", version.ref = "mod_architectury-plugin" } +mod_loom-quiltflower = { id = "io.github.juuxel.loom-quiltflower", version.ref = "mod_loom-quiltflower" } + +bukkit_run-paper = { id = "xyz.jpenilla.run-paper", version.ref = "bukkit_run-paper" } +bukkit_paperweight = { id = "io.papermc.paperweight.userdev", version.ref = "bukkit_paperweight" } \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index e708b1c02..41d9927a4 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 3e7c5fc21..ae04661ee 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -org.gradle.jvmargs=-Xmx4096m \ No newline at end of file diff --git a/gradlew b/gradlew index 4f906e0c8..1b6c78733 100755 --- a/gradlew +++ b/gradlew @@ -1,7 +1,7 @@ -#!/usr/bin/env sh +#!/bin/sh # -# Copyright 2015 the original author or authors. +# Copyright © 2015-2021 the original authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -17,67 +17,101 @@ # ############################################################################## -## -## Gradle start up script for UN*X -## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# ############################################################################## # Attempt to set APP_HOME + # Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` +APP_BASE_NAME=${0##*/} # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' # Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" +MAX_FD=maximum warn () { echo "$*" -} +} >&2 die () { echo echo "$*" echo exit 1 -} +} >&2 # OS specific support (must be 'true' or 'false'). cygwin=false msys=false darwin=false nonstop=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; - NONSTOP* ) - nonstop=true - ;; +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; esac CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar @@ -87,9 +121,9 @@ CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" + JAVACMD=$JAVA_HOME/jre/sh/java else - JAVACMD="$JAVA_HOME/bin/java" + JAVACMD=$JAVA_HOME/bin/java fi if [ ! -x "$JAVACMD" ] ; then die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME @@ -98,7 +132,7 @@ Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi else - JAVACMD="java" + JAVACMD=java which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the @@ -106,80 +140,95 @@ location of your Java installation." fi # Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi -fi - -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi - -# For Cygwin or MSYS, switch paths to Windows format before running java -if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - - JAVACMD=`cygpath --unix "$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi - # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" - fi - i=`expr $i + 1` - done - case $i in - 0) set -- ;; - 1) set -- "$args0" ;; - 2) set -- "$args0" "$args1" ;; - 3) set -- "$args0" "$args1" "$args2" ;; - 4) set -- "$args0" "$args1" "$args2" "$args3" ;; - 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" esac fi -# Escape application args -save () { - for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done - echo " " -} -APP_ARGS=`save "$@"` +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. -# Collect all arguments for the java command, following the shell quoting and substitution rules -eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' exec "$JAVACMD" "$@" diff --git a/platforms/bukkit/build.gradle.kts b/platforms/bukkit/build.gradle.kts index 8a00fd79d..d157f6a43 100644 --- a/platforms/bukkit/build.gradle.kts +++ b/platforms/bukkit/build.gradle.kts @@ -1,5 +1,5 @@ plugins { - id("xyz.jpenilla.run-paper") version "1.0.6" + alias(libs.plugins.bukkit.run.paper) } repositories { @@ -9,15 +9,12 @@ repositories { dependencies { shaded(project(":platforms:bukkit:common")) shaded(project(":platforms:bukkit:nms:v1_19_R1", configuration = "reobf")) - shaded("xyz.jpenilla", "reflection-remapper", Versions.Bukkit.reflectionRemapper) + shaded(libs.bukkit.reflection.remapper) } tasks { shadowJar { - relocate("org.bstats.bukkit", "com.dfsek.terra.lib.bstats") relocate("io.papermc.lib", "com.dfsek.terra.lib.paperlib") - relocate("com.google.common", "com.dfsek.terra.lib.google.common") - relocate("org.apache.logging.slf4j", "com.dfsek.terra.lib.slf4j-over-log4j") exclude("org/slf4j/**") exclude("org/checkerframework/**") exclude("org/jetbrains/annotations/**") @@ -28,7 +25,7 @@ tasks { } runServer { - minecraftVersion("1.19") + minecraftVersion(libs.versions.bukkit.minecraft.get()) dependsOn(shadowJar) pluginJars(shadowJar.get().archiveFile) } diff --git a/platforms/bukkit/common/build.gradle.kts b/platforms/bukkit/common/build.gradle.kts index a806ce672..7f25f1288 100644 --- a/platforms/bukkit/common/build.gradle.kts +++ b/platforms/bukkit/common/build.gradle.kts @@ -5,14 +5,9 @@ repositories { dependencies { shadedApi(project(":common:implementation:base")) - 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.") - } + compileOnly(libs.bukkit.paper.api) - compileOnly("io.papermc.paper:paper-api:${Versions.Bukkit.paper}") + shadedApi(libs.bukkit.paper.lib) - shadedApi("io.papermc", "paperlib", Versions.Bukkit.paperLib) - shadedApi("com.google.guava:guava:30.0-jre") - - shadedApi("cloud.commandframework", "cloud-paper", Versions.Libraries.cloud) + shadedApi(libs.bukkit.cloud.paper) } diff --git a/platforms/bukkit/common/src/main/java/com/dfsek/terra/bukkit/generator/BukkitChunkGeneratorWrapper.java b/platforms/bukkit/common/src/main/java/com/dfsek/terra/bukkit/generator/BukkitChunkGeneratorWrapper.java index 4cb9bfaef..9df6f7f15 100644 --- a/platforms/bukkit/common/src/main/java/com/dfsek/terra/bukkit/generator/BukkitChunkGeneratorWrapper.java +++ b/platforms/bukkit/common/src/main/java/com/dfsek/terra/bukkit/generator/BukkitChunkGeneratorWrapper.java @@ -28,7 +28,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.List; -import java.util.Random; +import java.util.random.RandomGenerator; import java.util.stream.Collectors; import com.dfsek.terra.api.block.state.BlockState; @@ -63,7 +63,7 @@ public class BukkitChunkGeneratorWrapper extends org.bukkit.generator.ChunkGener } @Override - public void generateNoise(@NotNull WorldInfo worldInfo, @NotNull Random random, int x, int z, @NotNull ChunkData chunkData) { + public void generateNoise(@NotNull WorldInfo worldInfo, @NotNull RandomGenerator random, int x, int z, @NotNull ChunkData chunkData) { BukkitWorldProperties properties = new BukkitWorldProperties(worldInfo); delegate.generateChunkData(new BukkitProtoChunk(chunkData), properties, pack.getBiomeProvider(), x, z); } @@ -74,7 +74,7 @@ public class BukkitChunkGeneratorWrapper extends org.bukkit.generator.ChunkGener .stream() .map(generationStage -> new BlockPopulator() { @Override - public void populate(@NotNull WorldInfo worldInfo, @NotNull Random random, int x, int z, + public void populate(@NotNull WorldInfo worldInfo, @NotNull RandomGenerator random, int x, int z, @NotNull LimitedRegion limitedRegion) { generationStage.populate(new BukkitProtoWorld(limitedRegion, air, pack.getBiomeProvider())); } diff --git a/platforms/bukkit/nms/v1_19_R1/build.gradle.kts b/platforms/bukkit/nms/v1_19_R1/build.gradle.kts index e40d548dc..cb17adc76 100644 --- a/platforms/bukkit/nms/v1_19_R1/build.gradle.kts +++ b/platforms/bukkit/nms/v1_19_R1/build.gradle.kts @@ -1,4 +1,6 @@ -apply(plugin = "io.papermc.paperweight.userdev") +plugins { + alias(libs.plugins.bukkit.paperweight) +} repositories { maven("https://s01.oss.sonatype.org/content/repositories/snapshots/") diff --git a/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/config/FertilizableConfig.java b/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/config/FertilizableConfig.java index 110f7d5ae..50641ad75 100644 --- a/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/config/FertilizableConfig.java +++ b/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/config/FertilizableConfig.java @@ -3,6 +3,9 @@ package com.dfsek.terra.bukkit.nms.v1_19_R1.config; import com.dfsek.tectonic.api.config.template.annotations.Default; import com.dfsek.tectonic.api.config.template.annotations.Value; import com.dfsek.tectonic.api.config.template.object.ObjectTemplate; + +import com.dfsek.terra.api.structure.Structure; + import net.minecraft.resources.ResourceLocation; import java.util.Map; @@ -14,7 +17,7 @@ import com.dfsek.terra.api.util.collection.ProbabilityCollection; public class FertilizableConfig implements ObjectTemplate { @Value("strucutres") @Default - private ProbabilityCollection structures = null; + private ProbabilityCollection structures = null; @Value("cooldowns") @Default @@ -28,7 +31,7 @@ public class FertilizableConfig implements ObjectTemplate { @Default private Boolean villagerFertilizable = null; - public ProbabilityCollection getStructures() { + public ProbabilityCollection getStructures() { return structures; } diff --git a/platforms/cli/build.gradle.kts b/platforms/cli/build.gradle.kts index e273422af..fc22547e9 100644 --- a/platforms/cli/build.gradle.kts +++ b/platforms/cli/build.gradle.kts @@ -7,14 +7,10 @@ val javaMainClass = "com.dfsek.terra.cli.TerraCLI" dependencies { shadedApi(project(":common:implementation:base")) - shadedApi("commons-io:commons-io:${Versions.CLI.commonsIO}") - shadedApi("com.github.Querz:NBT:${Versions.CLI.nbt}") + shadedApi(libs.libraries.internal.apache.io) + shadedApi(libs.cli.nbt) - shadedImplementation("com.google.guava:guava:${Versions.CLI.guava}") - - shadedImplementation("ch.qos.logback:logback-classic:${Versions.CLI.logback}") - - implementation("net.jafama", "jafama", Versions.Libraries.Internal.jafama) + shadedImplementation(libs.cli.logback) } tasks.withType { diff --git a/platforms/fabric/build.gradle.kts b/platforms/fabric/build.gradle.kts index 2a20545a2..380d65c2b 100644 --- a/platforms/fabric/build.gradle.kts +++ b/platforms/fabric/build.gradle.kts @@ -1,7 +1,7 @@ plugins { - id("dev.architectury.loom") version Versions.Mod.architecuryLoom - id("architectury-plugin") version Versions.Mod.architecturyPlugin - id("io.github.juuxel.loom-quiltflower") version Versions.Mod.loomQuiltflower + alias(libs.plugins.mod.architectury.loom) + alias(libs.plugins.mod.architectury.plugin) + alias(libs.plugins.mod.loom.quiltflower) } architectury { @@ -12,9 +12,6 @@ architectury { dependencies { shadedApi(project(":common:implementation:base")) - annotationProcessor("net.fabricmc:sponge-mixin:${Versions.Mod.mixin}") - annotationProcessor("dev.architectury:architectury-loom:${Versions.Mod.architecuryLoom}") - implementation(project(path = ":platforms:mixin-common", configuration = "namedElements")) { isTransitive = false } "developmentFabric"(project(path = ":platforms:mixin-common", configuration = "namedElements")) { isTransitive = false } shaded(project(path = ":platforms:mixin-common", configuration = "transformProductionFabric")) { isTransitive = false } @@ -22,28 +19,15 @@ dependencies { "developmentFabric"(project(path = ":platforms:mixin-lifecycle", configuration = "namedElements")) { isTransitive = false } shaded(project(path = ":platforms:mixin-lifecycle", configuration = "transformProductionFabric")) { isTransitive = false } + minecraft(libs.mod.minecraft) + mappings("net.fabricmc", "yarn", libs.versions.mod.yarn.get(), classifier = "v2") - minecraft("com.mojang:minecraft:${Versions.Mod.minecraft}") - mappings("net.fabricmc:yarn:${Versions.Mod.yarn}:v2") + modImplementation(libs.mod.fabric.fabric.loader) - modImplementation("net.fabricmc:fabric-loader:${Versions.Fabric.fabricLoader}") + modImplementation(libs.mod.cloud.fabric) + include(libs.mod.cloud.fabric) - setOf( - "fabric-lifecycle-events-v1", - "fabric-resource-loader-v0", - "fabric-api-base", - "fabric-command-api-v2", - "fabric-networking-api-v1" - ).forEach { apiModule -> - val module = fabricApi.module(apiModule, Versions.Fabric.fabricAPI) - modImplementation(module) - include(module) - } - - modImplementation("cloud.commandframework", "cloud-fabric", Versions.Libraries.cloud) - include("cloud.commandframework", "cloud-fabric", Versions.Libraries.cloud) - - modLocalRuntime("com.github.astei:lazydfu:${Versions.Mod.lazyDfu}") + modLocalRuntime(libs.mod.lazy.dfu) } loom { diff --git a/platforms/forge/build.gradle.kts b/platforms/forge/build.gradle.kts index 7cfddab1d..adf563834 100644 --- a/platforms/forge/build.gradle.kts +++ b/platforms/forge/build.gradle.kts @@ -1,7 +1,7 @@ plugins { - id("dev.architectury.loom") version Versions.Mod.architecuryLoom - id("architectury-plugin") version Versions.Mod.architecturyPlugin - id("io.github.juuxel.loom-quiltflower") version Versions.Mod.loomQuiltflower + alias(libs.plugins.mod.architectury.loom) + alias(libs.plugins.mod.architectury.plugin) + alias(libs.plugins.mod.loom.quiltflower) } architectury { @@ -10,9 +10,6 @@ architectury { } dependencies { - annotationProcessor("net.fabricmc:sponge-mixin:${Versions.Mod.mixin}") - annotationProcessor("dev.architectury:architectury-loom:${Versions.Mod.architecuryLoom}") - shadedApi(project(":common:implementation:base")) "forgeRuntimeLibrary"(project(":common:implementation:base")) @@ -20,14 +17,14 @@ dependencies { "developmentForge"(project(path = ":platforms:mixin-common", configuration = "namedElements")) { isTransitive = false } shaded(project(path = ":platforms:mixin-common", configuration = "transformProductionForge")) { isTransitive = false } - forge(group = "net.minecraftforge", name = "forge", version = Versions.Forge.forge) + forge(libs.mod.forge.forge) - minecraft("com.mojang:minecraft:${Versions.Mod.minecraft}") - mappings("net.fabricmc:yarn:${Versions.Mod.yarn}:v2") + minecraft(libs.mod.minecraft) + mappings("net.fabricmc", "yarn", libs.versions.mod.yarn.get(), classifier = "v2") //forge is not ok. - compileOnly("org.burningwave:core:${Versions.Forge.burningwave}") - "forgeRuntimeLibrary"("org.burningwave:core:${Versions.Forge.burningwave}") + compileOnly(libs.mod.forge.burningwave) + "forgeRuntimeLibrary"(libs.mod.forge.burningwave) } loom { diff --git a/platforms/mixin-common/build.gradle.kts b/platforms/mixin-common/build.gradle.kts index b293f3cfa..d57c4b00d 100644 --- a/platforms/mixin-common/build.gradle.kts +++ b/platforms/mixin-common/build.gradle.kts @@ -1,7 +1,7 @@ plugins { - id("dev.architectury.loom") version Versions.Mod.architecuryLoom - id("architectury-plugin") version Versions.Mod.architecturyPlugin - id("io.github.juuxel.loom-quiltflower") version Versions.Mod.loomQuiltflower + alias(libs.plugins.mod.architectury.loom) + alias(libs.plugins.mod.architectury.plugin) + alias(libs.plugins.mod.loom.quiltflower) } loom { @@ -15,16 +15,14 @@ loom { dependencies { shadedApi(project(":common:implementation:base")) - compileOnly("net.fabricmc:sponge-mixin:${Versions.Mod.mixin}") - annotationProcessor("net.fabricmc:sponge-mixin:${Versions.Mod.mixin}") - annotationProcessor("dev.architectury:architectury-loom:${Versions.Mod.architecuryLoom}") + modImplementation(libs.mod.fabric.fabric.loader) - minecraft("com.mojang:minecraft:${Versions.Mod.minecraft}") - mappings("net.fabricmc:yarn:${Versions.Mod.yarn}:v2") + minecraft(libs.mod.minecraft) + mappings("net.fabricmc", "yarn", libs.versions.mod.yarn.get(), classifier = "v2") } architectury { common("fabric", "forge", "quilt") - minecraft = Versions.Mod.minecraft + minecraft = libs.versions.mod.minecraft.get() } diff --git a/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/MinecraftAddon.java b/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/MinecraftAddon.java index fa1214389..e41141f1f 100644 --- a/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/MinecraftAddon.java +++ b/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/MinecraftAddon.java @@ -19,6 +19,13 @@ package com.dfsek.terra.mod; import ca.solostudios.strata.Versions; import ca.solostudios.strata.version.Version; + +import com.dfsek.terra.api.config.ConfigPack; + +import com.dfsek.terra.mod.config.VanillaWorldProperties; + +import com.dfsek.terra.mod.util.MinecraftUtil; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -44,6 +51,15 @@ public abstract class MinecraftAddon implements BaseAddon { @Override public void initialize() { + modPlatform.getEventManager() + .getHandler(FunctionalEventHandler.class) + .register(this, ConfigurationLoadEvent.class) + .then(event -> { + if(event.is(ConfigPack.class)) { + event.getLoadedObject(ConfigPack.class).getContext().put(event.load(new VanillaWorldProperties())); + } + }) + .global(); modPlatform.getEventManager() .getHandler(FunctionalEventHandler.class) .register(this, ConfigPackPreLoadEvent.class) diff --git a/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/ModPlatform.java b/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/ModPlatform.java index aae4a9aac..65feb9e63 100644 --- a/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/ModPlatform.java +++ b/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/ModPlatform.java @@ -77,14 +77,11 @@ public abstract class ModPlatform extends AbstractPlatform { throw new LoadException("Invalid identifier: " + o, depthTracker); return identifier; }) - .registerLoader(Precipitation.class, (type, o, loader, depthTracker) -> Precipitation.valueOf(((String) o).toUpperCase( - Locale.ROOT))) + .registerLoader(Precipitation.class, (type, o, loader, depthTracker) -> Precipitation.valueOf(((String) o).toUpperCase())) .registerLoader(GrassColorModifier.class, - (type, o, loader, depthTracker) -> GrassColorModifier.valueOf(((String) o).toUpperCase( - Locale.ROOT))) - .registerLoader(GrassColorModifier.class, - (type, o, loader, depthTracker) -> TemperatureModifier.valueOf(((String) o).toUpperCase( - Locale.ROOT))) + (type, o, loader, depthTracker) -> GrassColorModifier.valueOf(((String) o).toUpperCase())) + .registerLoader(TemperatureModifier.class, + (type, o, loader, depthTracker) -> TemperatureModifier.valueOf(((String) o).toUpperCase())) .registerLoader(SpawnGroup.class, (type, o, loader, depthTracker) -> SpawnGroup.valueOf((String) o)) .registerLoader(BiomeParticleConfig.class, BiomeParticleConfigTemplate::new) .registerLoader(SoundEvent.class, SoundEventTemplate::new) diff --git a/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/config/FertilizableConfig.java b/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/config/FertilizableConfig.java index d1fe3f92d..b16c39e93 100644 --- a/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/config/FertilizableConfig.java +++ b/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/config/FertilizableConfig.java @@ -7,14 +7,14 @@ import net.minecraft.util.Identifier; import java.util.Map; -import com.dfsek.terra.api.structure.configured.ConfiguredStructure; +import com.dfsek.terra.api.structure.Structure; import com.dfsek.terra.api.util.collection.ProbabilityCollection; public class FertilizableConfig implements ObjectTemplate { @Value("strucutres") @Default - private ProbabilityCollection structures = null; + private ProbabilityCollection structures = null; @Value("cooldowns") @Default @@ -22,13 +22,13 @@ public class FertilizableConfig implements ObjectTemplate { @Value("can-grow") @Default - private ConfiguredStructure canGrow = null; + private Structure canGrow = null; - @Value("villager-fertilizable") + @Value("villager-farmable") @Default - private Boolean villagerFertilizable = null; + private Boolean villagerFarmable = null; - public ProbabilityCollection getStructures() { + public ProbabilityCollection getStructures() { return structures; } @@ -36,12 +36,12 @@ public class FertilizableConfig implements ObjectTemplate { return cooldowns; } - public ConfiguredStructure getCanGrow() { + public Structure getCanGrow() { return canGrow; } - public Boolean isVillagerFertilizable() { - return villagerFertilizable; + public Boolean isVillagerFarmable() { + return villagerFarmable; } @Override diff --git a/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/config/MonsterSettingsTemplate.java b/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/config/MonsterSettingsTemplate.java new file mode 100644 index 000000000..e585fe43a --- /dev/null +++ b/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/config/MonsterSettingsTemplate.java @@ -0,0 +1,38 @@ +package com.dfsek.terra.mod.config; + +import com.dfsek.tectonic.api.config.template.annotations.Default; +import com.dfsek.tectonic.api.config.template.annotations.Value; + +import com.dfsek.tectonic.api.config.template.object.ObjectTemplate; + +import com.dfsek.terra.api.util.ConstantRange; +import com.dfsek.terra.api.util.Range; + +import com.dfsek.terra.mod.implmentation.TerraIntProvider; + +import net.minecraft.world.dimension.DimensionType.MonsterSettings; + + +public class MonsterSettingsTemplate implements ObjectTemplate { + @Value("piglin-safe") + @Default + private Boolean piglinSafe = false; + + @Value("has-raids") + @Default + private Boolean hasRaids = false; + + @Value("monster-spawn-light") + @Default + private Range monsterSpawnLight = new ConstantRange(0, 1); + + @Value("monster-spawn-block-light-limit") + @Default + private int monsterSpawnBlockLightLimit = 0; + + + @Override + public MonsterSettings get() { + return new MonsterSettings(piglinSafe, hasRaids, new TerraIntProvider(monsterSpawnLight), monsterSpawnBlockLightLimit); + } +} diff --git a/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/config/VanillaWorldProperties.java b/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/config/VanillaWorldProperties.java new file mode 100644 index 000000000..8ee95432b --- /dev/null +++ b/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/config/VanillaWorldProperties.java @@ -0,0 +1,141 @@ +package com.dfsek.terra.mod.config; + +import com.dfsek.tectonic.api.config.template.ConfigTemplate; +import com.dfsek.tectonic.api.config.template.annotations.Default; +import com.dfsek.tectonic.api.config.template.annotations.Value; + +import com.dfsek.terra.mod.implmentation.TerraIntProvider; + +import net.minecraft.client.gl.Uniform; +import net.minecraft.util.Identifier; +import net.minecraft.util.math.intprovider.IntProvider; +import net.minecraft.util.math.intprovider.IntProviderType; +import net.minecraft.util.math.random.Random; +import net.minecraft.world.dimension.DimensionType.MonsterSettings; + +import com.dfsek.terra.api.properties.Properties; +import com.dfsek.terra.api.util.ConstantRange; +import com.dfsek.terra.api.util.Range; + + +public class VanillaWorldProperties implements ConfigTemplate, Properties { + @Value("minecraft.fixed-time") + @Default + private Long fixedTime = null; + + @Value("minecraft.has-sky-light") + @Default + private Boolean hasSkyLight = false; + + @Value("minecraft.has-ceiling") + @Default + private Boolean hasCeiling = false; + + @Value("minecraft.ultra-warm") + @Default + private Boolean ultraWarm = false; + + @Value("minecraft.natural") + @Default + private Boolean natural = false; + + @Value("minecraft.coordinate-scale") + @Default + private Double coordinateScale = 1.0E-5d; + + @Value("minecraft.bed-works") + @Default + private Boolean bedWorks = false; + + @Value("minecraft.respawn-anchor-works") + @Default + private Boolean respawnAnchorWorks = false; + + @Value("minecraft.height") + @Default + private Range height = new ConstantRange(0, 16); + + @Value("minecraft.height.logical") + @Default + private Integer logicalHeight = 0; + + @Value("minecraft.infiniburn") + @Default + private Identifier infiniburn = new Identifier(""); + + @Value("minecraft.effects") + @Default + private Identifier effects = new Identifier(""); + + @Value("minecraft.ambient-light") + @Default + private Float ambientLight = Float.MAX_VALUE; + + @Value("minecraft.monster-settings") + @Default + private MonsterSettings monsterSettings = new MonsterSettings(false, false, new TerraIntProvider(new ConstantRange(0, 1)), 0); + + @Value("minecraft.sealevel") + @Default + private Integer sealevel = 0; + + public Long getFixedTime() { + return fixedTime; + } + + public Boolean getHasSkyLight() { + return hasSkyLight; + } + + public Boolean getHasCeiling() { + return hasCeiling; + } + + public Boolean getUltraWarm() { + return ultraWarm; + } + + public Boolean getNatural() { + return natural; + } + + public Double getCoordinateScale() { + return coordinateScale; + } + + public Boolean getBedWorks() { + return bedWorks; + } + + public Boolean getRespawnAnchorWorks() { + return respawnAnchorWorks; + } + + public Range getHeight() { + return height; + } + + public Integer getLogicalHeight() { + return logicalHeight; + } + + public Identifier getInfiniburn() { + return infiniburn; + } + + public Identifier getEffects() { + return effects; + } + + public Float getAmbientLight() { + return ambientLight; + } + + public MonsterSettings getMonsterSettings() { + return monsterSettings; + } + + public Integer getSealevel() { + return sealevel; + } +} diff --git a/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/data/Codecs.java b/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/data/Codecs.java index 5f5dd615a..66e668cbf 100644 --- a/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/data/Codecs.java +++ b/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/data/Codecs.java @@ -1,5 +1,10 @@ package com.dfsek.terra.mod.data; +import com.dfsek.terra.api.util.ConstantRange; +import com.dfsek.terra.api.util.Range; + +import com.dfsek.terra.mod.implmentation.TerraIntProvider; + import com.mojang.serialization.Codec; import com.mojang.serialization.codecs.RecordCodecBuilder; import net.minecraft.util.dynamic.RegistryOps; @@ -62,4 +67,9 @@ public final class Codecs { .forGetter(MinecraftChunkGeneratorWrapper::getSettings) ).apply(instance, instance.stable(MinecraftChunkGeneratorWrapper::new)) ); + + public static final Codec TERRA_CONSTANT_RANGE_INT_PROVIDER_TYPE = RecordCodecBuilder.create(range -> range.group( + Codec.INT.fieldOf("min").stable().forGetter(TerraIntProvider::getMin), + Codec.INT.fieldOf("max").stable().forGetter(TerraIntProvider::getMax)).apply(range, range.stable((min, max) -> new TerraIntProvider(new ConstantRange( + min, max))))); } diff --git a/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/generation/MinecraftChunkGeneratorWrapper.java b/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/generation/MinecraftChunkGeneratorWrapper.java index 5742120d6..0130d8112 100644 --- a/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/generation/MinecraftChunkGeneratorWrapper.java +++ b/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/generation/MinecraftChunkGeneratorWrapper.java @@ -17,6 +17,9 @@ package com.dfsek.terra.mod.generation; +import com.dfsek.terra.mod.config.VanillaBiomeProperties; +import com.dfsek.terra.mod.config.VanillaWorldProperties; + import com.mojang.serialization.Codec; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; @@ -76,6 +79,8 @@ public class MinecraftChunkGeneratorWrapper extends net.minecraft.world.gen.chun private ChunkGenerator delegate; private ConfigPack pack; + private VanillaWorldProperties vanillaWorldProperties; + public MinecraftChunkGeneratorWrapper(Registry noiseRegistry, TerraBiomeSource biomeSource, ConfigPack configPack, RegistryEntry settingsSupplier) { super(noiseRegistry, Optional.empty(), biomeSource); @@ -86,6 +91,11 @@ public class MinecraftChunkGeneratorWrapper extends net.minecraft.world.gen.chun this.delegate = pack.getGeneratorProvider().newInstance(pack); logger.info("Loading world with config pack {}", pack.getID()); this.biomeSource = biomeSource; + if (pack.getContext().has(VanillaBiomeProperties.class)) { + vanillaWorldProperties = pack.getContext().get(VanillaWorldProperties.class); + } else { + vanillaWorldProperties = new VanillaWorldProperties(); + } } public Registry getNoiseRegistry() { @@ -115,7 +125,7 @@ public class MinecraftChunkGeneratorWrapper extends net.minecraft.world.gen.chun @Override public int getWorldHeight() { - return settings.value().generationShapeConfig().height(); + return vanillaWorldProperties.getHeight().getMax(); } @@ -137,7 +147,7 @@ public class MinecraftChunkGeneratorWrapper extends net.minecraft.world.gen.chun private void beard(StructureAccessor structureAccessor, Chunk chunk, WorldProperties world, BiomeProvider biomeProvider, PreLoadCompatibilityOptions compatibilityOptions) { - StructureWeightSampler structureWeightSampler = StructureWeightSampler.method_42695(structureAccessor, chunk.getPos()); + StructureWeightSampler structureWeightSampler = StructureWeightSampler.createStructureWeightSampler(structureAccessor, chunk.getPos()); double threshold = compatibilityOptions.getBeardThreshold(); double airThreshold = compatibilityOptions.getAirThreshold(); int xi = chunk.getPos().x << 4; @@ -174,12 +184,12 @@ public class MinecraftChunkGeneratorWrapper extends net.minecraft.world.gen.chun @Override public int getSeaLevel() { - return settings.value().seaLevel(); + return vanillaWorldProperties.getSealevel(); } @Override public int getMinimumY() { - return settings.value().generationShapeConfig().minimumY(); + return vanillaWorldProperties.getHeight().getMin(); } @@ -209,7 +219,7 @@ public class MinecraftChunkGeneratorWrapper extends net.minecraft.world.gen.chun @Override public void getDebugHudText(List text, NoiseConfig noiseConfig, BlockPos pos) { - + // no op } public ConfigPack getPack() { @@ -220,6 +230,12 @@ public class MinecraftChunkGeneratorWrapper extends net.minecraft.world.gen.chun this.pack = pack; this.delegate = pack.getGeneratorProvider().newInstance(pack); biomeSource.setPack(pack); + + if (pack.getContext().has(VanillaBiomeProperties.class)) { + vanillaWorldProperties = pack.getContext().get(VanillaWorldProperties.class); + } else { + vanillaWorldProperties = new VanillaWorldProperties(); + } logger.debug("Loading world with config pack {}", pack.getID()); } diff --git a/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/implmentation/TerraIntProvider.java b/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/implmentation/TerraIntProvider.java new file mode 100644 index 000000000..dd5d51687 --- /dev/null +++ b/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/implmentation/TerraIntProvider.java @@ -0,0 +1,43 @@ +package com.dfsek.terra.mod.implmentation; + +import com.dfsek.terra.api.util.Range; + +import com.dfsek.terra.mod.util.MinecraftAdapter; + +import net.minecraft.util.math.intprovider.IntProvider; +import net.minecraft.util.math.intprovider.IntProviderType; +import net.minecraft.util.math.random.Random; + +import java.util.HashMap; +import java.util.Map; + + +public class TerraIntProvider extends IntProvider { + public static final Map TERRA_RANGE_TYPE_TO_INT_PROVIDER_TYPE = new HashMap<>(); + + public Range delegate; + + public TerraIntProvider(Range delegate) { + this.delegate = delegate; + } + + @Override + public int get(Random random) { + return delegate.get(MinecraftAdapter.adapt(random)); + } + + @Override + public int getMin() { + return delegate.getMin(); + } + + @Override + public int getMax() { + return delegate.getMax(); + } + + @Override + public IntProviderType getType() { + return TERRA_RANGE_TYPE_TO_INT_PROVIDER_TYPE.get(delegate.getClass()); + } +} diff --git a/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/mixin/access/BiomeAccessor.java b/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/mixin/access/BiomeAccessor.java deleted file mode 100644 index c51029682..000000000 --- a/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/mixin/access/BiomeAccessor.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.dfsek.terra.mod.mixin.access; - -import net.minecraft.world.biome.Biome; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Accessor; - - -@Mixin(Biome.class) -public interface BiomeAccessor { - @Accessor("weather") - Biome.Weather getWeather(); -} diff --git a/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/mixin/gameplay/BoneMealItemMixin.java b/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/mixin/gameplay/BoneMealItemMixin.java index 22fac5a71..96c69f8a8 100644 --- a/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/mixin/gameplay/BoneMealItemMixin.java +++ b/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/mixin/gameplay/BoneMealItemMixin.java @@ -1,6 +1,8 @@ package com.dfsek.terra.mod.mixin.gameplay; +import com.dfsek.terra.mod.util.MinecraftAdapter; + import net.minecraft.item.BoneMealItem; import net.minecraft.item.ItemStack; import net.minecraft.server.world.ServerWorld; @@ -14,6 +16,8 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import com.dfsek.terra.mod.util.FertilizableUtil; +import java.util.random.RandomGenerator; + @Mixin(BoneMealItem.class) public class BoneMealItemMixin { @@ -22,7 +26,7 @@ public class BoneMealItemMixin { @Inject(method = "useOnFertilizable", at = @At("HEAD"), cancellable = true) private static void injectUseOnFertilizable(ItemStack stack, World world, BlockPos pos, CallbackInfoReturnable cir) { if(world instanceof ServerWorld) { - Boolean value = FertilizableUtil.grow((ServerWorld) world, pos, world.getBlockState(pos), cooldownId); + Boolean value = FertilizableUtil.grow((ServerWorld) world, MinecraftAdapter.adapt(world.getRandom()), pos, world.getBlockState(pos), cooldownId); stack.decrement(1); if(value != null) { cir.setReturnValue(value); diff --git a/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/mixin/gameplay/BoneMealTaskMixin.java b/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/mixin/gameplay/BoneMealTaskMixin.java index 90e93b656..52d95d33d 100644 --- a/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/mixin/gameplay/BoneMealTaskMixin.java +++ b/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/mixin/gameplay/BoneMealTaskMixin.java @@ -1,6 +1,10 @@ package com.dfsek.terra.mod.mixin.gameplay; +import com.dfsek.terra.api.world.World; + +import com.dfsek.terra.mod.util.WritableWorldSeedRedirecter; + import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.entity.ai.brain.task.BoneMealTask; @@ -14,14 +18,15 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import java.util.Map; -import java.util.Random; +import java.util.random.RandomGenerator; -import com.dfsek.terra.api.structure.configured.ConfiguredStructure; +import com.dfsek.terra.api.structure.Structure; import com.dfsek.terra.api.util.Rotation; import com.dfsek.terra.api.util.vector.Vector3Int; import com.dfsek.terra.api.world.WritableWorld; import com.dfsek.terra.mod.config.FertilizableConfig; import com.dfsek.terra.mod.util.BiomeUtil; +import com.dfsek.terra.mod.util.MinecraftAdapter; @Mixin(BoneMealTask.class) @@ -35,21 +40,20 @@ public class BoneMealTaskMixin { Block block = blockState.getBlock(); FertilizableConfig config = map.get(Registry.BLOCK.getId(block)); if(config != null) { - Boolean villagerFertilizable = config.isVillagerFertilizable(); - if(villagerFertilizable != null) { - if(villagerFertilizable) { - ConfiguredStructure canGrow = config.getCanGrow(); + Boolean villagerFarmable = config.isVillagerFarmable(); + if(villagerFarmable != null) { + if(villagerFarmable) { + Structure canGrow = config.getCanGrow(); if(canGrow != null) { - Random random = (Random) world.getRandom(); - cir.setReturnValue(canGrow.getStructure().get(random).generate( - Vector3Int.of(pos.getX(), pos.getY(), pos.getZ()), (WritableWorld) world, random, Rotation.NONE)); + RandomGenerator random = MinecraftAdapter.adapt(world.getRandom()); + cir.setReturnValue(canGrow.generate( + Vector3Int.of(pos.getX(), pos.getY(), pos.getZ()), new WritableWorldSeedRedirecter((WritableWorld) world, world.getSeed() + random.nextLong(Long.MAX_VALUE)), Rotation.NONE)); return; } cir.setReturnValue(true); return; } cir.setReturnValue(false); - return; } } } diff --git a/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/mixin/gameplay/ServerWorldMixin.java b/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/mixin/gameplay/ServerWorldMixin.java index 0081db33d..b64726b36 100644 --- a/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/mixin/gameplay/ServerWorldMixin.java +++ b/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/mixin/gameplay/ServerWorldMixin.java @@ -1,6 +1,8 @@ package com.dfsek.terra.mod.mixin.gameplay; +import com.dfsek.terra.mod.util.MinecraftAdapter; + import net.minecraft.block.BlockState; import net.minecraft.server.world.ServerWorld; import net.minecraft.util.Identifier; @@ -12,6 +14,8 @@ import org.spongepowered.asm.mixin.injection.Redirect; import com.dfsek.terra.mod.util.FertilizableUtil; +import java.util.random.RandomGenerator; + @Mixin(ServerWorld.class) public class ServerWorldMixin { @@ -22,7 +26,7 @@ public class ServerWorldMixin { target = "Lnet/minecraft/block/BlockState;randomTick(Lnet/minecraft/server/world/ServerWorld;" + "Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/util/math/random/Random;)V")) public void injectTickChunk(BlockState instance, ServerWorld serverWorld, BlockPos blockPos, Random random) { - Boolean value = FertilizableUtil.grow(serverWorld, blockPos, instance, cooldownId); + Boolean value = FertilizableUtil.grow(serverWorld, MinecraftAdapter.adapt(random), blockPos, instance, cooldownId); if(value != null) { if(!value) { instance.randomTick(serverWorld, blockPos, random); diff --git a/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/mixin/lifecycle/DataPackContentsMixin.java b/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/mixin/lifecycle/DataPackContentsMixin.java index d1c470076..237a9e550 100644 --- a/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/mixin/lifecycle/DataPackContentsMixin.java +++ b/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/mixin/lifecycle/DataPackContentsMixin.java @@ -1,5 +1,7 @@ package com.dfsek.terra.mod.mixin.lifecycle; +import com.dfsek.terra.mod.util.MinecraftUtil; + import net.minecraft.server.DataPackContents; import net.minecraft.util.registry.DynamicRegistryManager; import net.minecraft.util.registry.Registry; diff --git a/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/util/BiomeUtil.java b/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/util/BiomeUtil.java index 4e13d6eec..ebc59e7cb 100644 --- a/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/util/BiomeUtil.java +++ b/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/util/BiomeUtil.java @@ -62,7 +62,13 @@ public class BiomeUtil { */ protected static void registerBiome(Biome biome, ConfigPack pack, com.dfsek.terra.api.registry.key.RegistryKey id) { - VanillaBiomeProperties vanillaBiomeProperties = biome.getContext().get(VanillaBiomeProperties.class); + VanillaBiomeProperties vanillaBiomeProperties; + if (biome.getContext().has(VanillaBiomeProperties.class)) { + vanillaBiomeProperties = biome.getContext().get(VanillaBiomeProperties.class); + } else { + vanillaBiomeProperties = new VanillaBiomeProperties(); + } + net.minecraft.world.biome.Biome minecraftBiome = MinecraftUtil.createBiome(vanillaBiomeProperties); diff --git a/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/util/DimensionUtil.java b/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/util/DimensionUtil.java new file mode 100644 index 000000000..234ea2940 --- /dev/null +++ b/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/util/DimensionUtil.java @@ -0,0 +1,62 @@ +package com.dfsek.terra.mod.util; + +import com.dfsek.terra.api.config.ConfigPack; +import com.dfsek.terra.mod.config.VanillaBiomeProperties; +import com.dfsek.terra.mod.config.VanillaWorldProperties; + +import net.minecraft.tag.TagKey; +import net.minecraft.util.Identifier; +import net.minecraft.util.registry.BuiltinRegistries; +import net.minecraft.util.registry.Registry; +import net.minecraft.util.registry.RegistryKey; +import net.minecraft.world.dimension.DimensionOptions; +import net.minecraft.world.dimension.DimensionType; + +import java.util.OptionalLong; + + +public class DimensionUtil { + protected static RegistryKey registerDimension(Identifier identifier, + DimensionType dimension) { + BuiltinRegistries.add(BuiltinRegistries.DIMENSION_TYPE, + registerKey(identifier) + .getValue(), + dimension); + return getDimensionKey(identifier); + } + + public static RegistryKey registerKey(Identifier identifier) { + return RegistryKey.of(Registry.DIMENSION_KEY, identifier); + } + public static RegistryKey getDimensionKey(Identifier identifier) { + return BuiltinRegistries.DIMENSION_TYPE.getKey(BuiltinRegistries.DIMENSION_TYPE.get(identifier)).orElseThrow(); + } + + protected static RegistryKey registerDimension(ConfigPack pack) { + VanillaWorldProperties vanillaWorldProperties; + if (pack.getContext().has(VanillaBiomeProperties.class)) { + vanillaWorldProperties = pack.getContext().get(VanillaWorldProperties.class); + } else { + vanillaWorldProperties = new VanillaWorldProperties(); + } + + DimensionType overworldDimensionType = new DimensionType( + vanillaWorldProperties.getFixedTime() == null ? OptionalLong.empty() : OptionalLong.of(vanillaWorldProperties.getFixedTime()), + vanillaWorldProperties.getHasSkyLight(), + vanillaWorldProperties.getHasCeiling(), + vanillaWorldProperties.getUltraWarm(), + vanillaWorldProperties.getNatural(), + vanillaWorldProperties.getCoordinateScale(), + vanillaWorldProperties.getBedWorks(), + vanillaWorldProperties.getRespawnAnchorWorks(), + vanillaWorldProperties.getHeight().getMin(), + vanillaWorldProperties.getHeight().getMax(), + vanillaWorldProperties.getLogicalHeight(), + TagKey.of(Registry.BLOCK_KEY, vanillaWorldProperties.getInfiniburn()), + vanillaWorldProperties.getEffects(), + vanillaWorldProperties.getAmbientLight(), + vanillaWorldProperties.getMonsterSettings()); + + return registerDimension(new Identifier("terra", pack.getID().toLowerCase()), overworldDimensionType); + } +} diff --git a/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/util/FertilizableUtil.java b/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/util/FertilizableUtil.java index 7ee320b75..588df823b 100644 --- a/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/util/FertilizableUtil.java +++ b/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/util/FertilizableUtil.java @@ -8,9 +8,9 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.registry.Registry; import java.util.Map; -import java.util.Random; +import java.util.random.RandomGenerator; -import com.dfsek.terra.api.structure.configured.ConfiguredStructure; +import com.dfsek.terra.api.structure.Structure; import com.dfsek.terra.api.util.Rotation; import com.dfsek.terra.api.util.vector.Vector3Int; import com.dfsek.terra.api.world.WritableWorld; @@ -18,23 +18,16 @@ import com.dfsek.terra.mod.config.FertilizableConfig; public class FertilizableUtil { - - private static final Random mojankRandom = new Random(); - - public static Boolean grow(ServerWorld world, BlockPos pos, BlockState state, Identifier cooldownId) { - return grow(world, mojankRandom, pos, state, cooldownId); - } - - public static Boolean grow(ServerWorld world, Random random, BlockPos pos, BlockState state, Identifier cooldownId) { + public static Boolean grow(ServerWorld world, RandomGenerator random, BlockPos pos, BlockState state, Identifier cooldownId) { Map map = BiomeUtil.TERRA_BIOME_FERTILIZABLE_MAP.get(world.getBiome(pos)); if(map != null) { Block block = state.getBlock(); FertilizableConfig config = map.get(Registry.BLOCK.getId(block)); if(config != null) { - ConfiguredStructure canGrow = config.getCanGrow(); + Structure canGrow = config.getCanGrow(); if(canGrow != null) { - if(!canGrow.getStructure().get(random).generate( - Vector3Int.of(pos.getX(), pos.getY(), pos.getZ()), (WritableWorld) world, random, Rotation.NONE)) { + if(!canGrow.generate( + Vector3Int.of(pos.getX(), pos.getY(), pos.getZ()), new WritableWorldSeedRedirecter((WritableWorld) world, world.getSeed() + random.nextLong(Long.MAX_VALUE)), Rotation.NONE)) { return false; } } @@ -44,8 +37,8 @@ public class FertilizableUtil { return true; } } - config.getStructures().get(random).getStructure().get(random).generate( - Vector3Int.of(pos.getX(), pos.getY(), pos.getZ()), (WritableWorld) world, random, Rotation.NONE); + config.getStructures().get(random).generate( + Vector3Int.of(pos.getX(), pos.getY(), pos.getZ()), new WritableWorldSeedRedirecter((WritableWorld) world, world.getSeed() + random.nextLong(Long.MAX_VALUE)), Rotation.NONE); return true; } } diff --git a/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/util/MinecraftAdapter.java b/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/util/MinecraftAdapter.java index 2f43913e2..f21f40505 100644 --- a/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/util/MinecraftAdapter.java +++ b/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/util/MinecraftAdapter.java @@ -18,11 +18,14 @@ package com.dfsek.terra.mod.util; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.random.Random; import net.minecraft.world.HeightLimitView; import com.dfsek.terra.api.util.vector.Vector3; import com.dfsek.terra.api.world.info.WorldProperties; +import java.util.random.RandomGenerator; + public final class MinecraftAdapter { @@ -53,4 +56,48 @@ public final class MinecraftAdapter { } }; } + + public static RandomGenerator adapt(Random random) { + return new RandomGenerator() { + @Override + public boolean nextBoolean() { + return random.nextBoolean(); + } + + @Override + public float nextFloat() { + return random.nextFloat(); + } + + @Override + public double nextDouble() { + return random.nextDouble(); + } + + @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 double nextGaussian() { + return random.nextGaussian(); + } + + @Override + public int nextInt(int origin, int bound) { + return random.nextBetween(origin, bound); + } + }; + } } diff --git a/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/util/MinecraftUtil.java b/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/util/MinecraftUtil.java index 941f85b2c..fc623fa6c 100644 --- a/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/util/MinecraftUtil.java +++ b/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/util/MinecraftUtil.java @@ -1,10 +1,17 @@ package com.dfsek.terra.mod.util; +import com.dfsek.terra.api.util.ConstantRange; +import com.dfsek.terra.mod.data.Codecs; + +import com.dfsek.terra.mod.implmentation.TerraIntProvider; + import net.minecraft.block.entity.LootableContainerBlockEntity; import net.minecraft.block.entity.MobSpawnerBlockEntity; import net.minecraft.block.entity.SignBlockEntity; import net.minecraft.util.Identifier; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.intprovider.ConstantIntProvider; +import net.minecraft.util.math.intprovider.IntProviderType; import net.minecraft.util.registry.Registry; import net.minecraft.util.registry.RegistryEntry; import net.minecraft.util.registry.RegistryKey; @@ -12,6 +19,7 @@ import net.minecraft.world.WorldAccess; import net.minecraft.world.biome.Biome; import net.minecraft.world.biome.Biome.Builder; import net.minecraft.world.biome.BiomeEffects; +import net.minecraft.world.biome.BiomeEffects.GrassColorModifier; import net.minecraft.world.biome.GenerationSettings; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -54,6 +62,13 @@ public final class MinecraftUtil { return null; } + public static void registerIntProviderTypes() { + IntProviderType CONSTANT = IntProviderType.register("terra:constant_range", + Codecs.TERRA_CONSTANT_RANGE_INT_PROVIDER_TYPE); + + TerraIntProvider.TERRA_RANGE_TYPE_TO_INT_PROVIDER_TYPE.put(ConstantRange.class, CONSTANT); + } + public static RegistryKey registerKey(Identifier identifier) { return RegistryKey.of(Registry.BIOME_KEY, identifier); } diff --git a/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/util/PresetUtil.java b/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/util/PresetUtil.java index f4fd942c8..fe44e4f80 100644 --- a/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/util/PresetUtil.java +++ b/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/util/PresetUtil.java @@ -1,11 +1,16 @@ package com.dfsek.terra.mod.util; +import net.minecraft.client.gui.screen.CustomizeBuffetLevelScreen; +import net.minecraft.client.gui.screen.CustomizeFlatLevelScreen; +import net.minecraft.client.gui.screen.world.LevelScreenProvider; import net.minecraft.structure.StructureSet; import net.minecraft.util.Identifier; import net.minecraft.util.math.noise.DoublePerlinNoiseSampler.NoiseParameters; import net.minecraft.util.registry.BuiltinRegistries; +import net.minecraft.util.registry.DynamicRegistryManager; import net.minecraft.util.registry.Registry; import net.minecraft.util.registry.RegistryEntry; +import net.minecraft.util.registry.RegistryKey; import net.minecraft.world.biome.Biome; import net.minecraft.world.biome.source.MultiNoiseBiomeSource; import net.minecraft.world.biome.source.TheEndBiomeSource; @@ -13,8 +18,11 @@ import net.minecraft.world.dimension.DimensionOptions; import net.minecraft.world.dimension.DimensionType; import net.minecraft.world.dimension.DimensionTypes; import net.minecraft.world.gen.WorldPreset; +import net.minecraft.world.gen.WorldPresets; import net.minecraft.world.gen.chunk.ChunkGenerator; import net.minecraft.world.gen.chunk.ChunkGeneratorSettings; +import net.minecraft.world.gen.chunk.FlatChunkGenerator; +import net.minecraft.world.gen.chunk.FlatChunkGeneratorConfig; import net.minecraft.world.gen.chunk.NoiseChunkGenerator; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -23,6 +31,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.Optional; import com.dfsek.terra.api.config.ConfigPack; import com.dfsek.terra.api.util.generic.pair.Pair; @@ -34,6 +43,9 @@ public class PresetUtil { private static final Logger LOGGER = LoggerFactory.getLogger(PresetUtil.class); private static final List PRESETS = new ArrayList<>(); + public static RegistryKey getPresetKey(Identifier identifier) { + return RegistryKey.of(Registry.WORLD_PRESET_KEY, identifier); + } public static Pair createDefault(ConfigPack pack) { Registry dimensionTypeRegistry = BuiltinRegistries.DIMENSION_TYPE; Registry chunkGeneratorSettingsRegistry = BuiltinRegistries.CHUNK_GENERATOR_SETTINGS; @@ -58,7 +70,7 @@ public class PresetUtil { new TheEndBiomeSource(biomeRegistry), endChunkGeneratorSettings)); - RegistryEntry overworldDimensionType = dimensionTypeRegistry.getOrCreateEntry(DimensionTypes.OVERWORLD); + RegistryEntry overworldDimensionType = dimensionTypeRegistry.getOrCreateEntry(DimensionUtil.registerDimension(pack)); RegistryEntry overworld = chunkGeneratorSettingsRegistry.getOrCreateEntry(ChunkGeneratorSettings.OVERWORLD); diff --git a/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/util/WritableWorldSeedRedirecter.java b/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/util/WritableWorldSeedRedirecter.java new file mode 100644 index 000000000..ba453eff6 --- /dev/null +++ b/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/util/WritableWorldSeedRedirecter.java @@ -0,0 +1,168 @@ +package com.dfsek.terra.mod.util; + +import com.dfsek.terra.api.block.entity.BlockEntity; +import com.dfsek.terra.api.block.state.BlockState; +import com.dfsek.terra.api.config.ConfigPack; +import com.dfsek.terra.api.entity.Entity; +import com.dfsek.terra.api.entity.EntityType; +import com.dfsek.terra.api.util.vector.Vector3; +import com.dfsek.terra.api.util.vector.Vector3.Mutable; +import com.dfsek.terra.api.util.vector.Vector3Int; +import com.dfsek.terra.api.world.BufferedWorld; +import com.dfsek.terra.api.world.BufferedWorld.Builder; +import com.dfsek.terra.api.world.WritableWorld; +import com.dfsek.terra.api.world.biome.generation.BiomeProvider; +import com.dfsek.terra.api.world.chunk.generation.ChunkGenerator; +import com.dfsek.terra.api.world.chunk.generation.util.Column; + + +public class WritableWorldSeedRedirecter implements WritableWorld { + private final WritableWorld delegate; + private final long seed; + + + public WritableWorldSeedRedirecter(WritableWorld delegate, long seed) { + this.delegate = delegate; + this.seed = seed; + } + + @Override + public Object getHandle() { + return delegate.getHandle(); + } + + @Override + public BlockState getBlockState(int x, int y, int z) { + return delegate.getBlockState(x, y, z); + } + + @Override + public BlockState getBlockState(Vector3 position) { + return delegate.getBlockState(position); + } + + @Override + public BlockState getBlockState(Vector3Int position) { + return delegate.getBlockState(position); + } + + @Override + public BlockEntity getBlockEntity(int x, int y, int z) { + return delegate.getBlockEntity(x, y, z); + } + + @Override + public BlockEntity getBlockEntity(Vector3 position) { + return delegate.getBlockEntity(position); + } + + @Override + public BlockEntity getBlockEntity(Vector3Int position) { + return delegate.getBlockEntity(position); + } + + @Override + public ChunkGenerator getGenerator() { + return delegate.getGenerator(); + } + + @Override + public BiomeProvider getBiomeProvider() { + return delegate.getBiomeProvider(); + } + + @Override + public ConfigPack getPack() { + return delegate.getPack(); + } + + @Override + public void setBlockState(Vector3 position, BlockState data, boolean physics) { + delegate.setBlockState(position, data, physics); + } + + @Override + public void setBlockState(Mutable position, BlockState data, boolean physics) { + delegate.setBlockState(position, data, physics); + } + + @Override + public void setBlockState(Vector3Int position, BlockState data, boolean physics) { + delegate.setBlockState(position, data, physics); + } + + @Override + public void setBlockState(Vector3Int.Mutable position, BlockState data, boolean physics) { + delegate.setBlockState(position, data, physics); + } + + @Override + public void setBlockState(Vector3 position, BlockState data) { + delegate.setBlockState(position, data); + } + + @Override + public void setBlockState(Mutable position, BlockState data) { + delegate.setBlockState(position, data); + } + + @Override + public void setBlockState(Vector3Int position, BlockState data) { + delegate.setBlockState(position, data); + } + + @Override + public void setBlockState(Vector3Int.Mutable position, BlockState data) { + delegate.setBlockState(position, data); + } + + @Override + public void setBlockState(int x, int y, int z, BlockState data) { + delegate.setBlockState(x, y, z, data); + } + + @Override + public void setBlockState(int x, int y, int z, BlockState data, boolean physics) { + delegate.setBlockState(x, y, z, data, physics); + } + + @Override + public Entity spawnEntity(Vector3 location, EntityType entityType) { + return delegate.spawnEntity(location, entityType); + } + + @Override + public Entity spawnEntity(double x, double y, double z, EntityType entityType) { + return delegate.spawnEntity(x, y, z, entityType); + } + + @Override + public BufferedWorld buffer(int offsetX, int offsetY, int offsetZ) { + return delegate.buffer(offsetX, offsetY, offsetZ); + } + + @Override + public Builder buffer() { + return delegate.buffer(); + } + + @Override + public Column column(int x, int z) { + return delegate.column(x, z); + } + + @Override + public long getSeed() { + return seed; + } + + @Override + public int getMaxHeight() { + return delegate.getMaxHeight(); + } + + @Override + public int getMinHeight() { + return delegate.getMinHeight(); + } +} diff --git a/platforms/mixin-common/src/main/resources/terra.accesswidener b/platforms/mixin-common/src/main/resources/terra.accesswidener index 4f59bb962..dfde67a12 100644 --- a/platforms/mixin-common/src/main/resources/terra.accesswidener +++ b/platforms/mixin-common/src/main/resources/terra.accesswidener @@ -1,2 +1 @@ -accessWidener v1 named -accessible class net/minecraft/world/biome/Biome$Weather \ No newline at end of file +accessWidener v1 named \ No newline at end of file diff --git a/platforms/mixin-lifecycle/build.gradle.kts b/platforms/mixin-lifecycle/build.gradle.kts index e8b852dc5..a645777fc 100644 --- a/platforms/mixin-lifecycle/build.gradle.kts +++ b/platforms/mixin-lifecycle/build.gradle.kts @@ -1,22 +1,22 @@ plugins { - id("dev.architectury.loom") version Versions.Mod.architecuryLoom - id("architectury-plugin") version Versions.Mod.architecturyPlugin - id("io.github.juuxel.loom-quiltflower") version Versions.Mod.loomQuiltflower + alias(libs.plugins.mod.architectury.loom) + alias(libs.plugins.mod.architectury.plugin) + alias(libs.plugins.mod.loom.quiltflower) } dependencies { shadedApi(project(":common:implementation:base")) - compileOnly("net.fabricmc:sponge-mixin:${Versions.Mod.mixin}") - annotationProcessor("net.fabricmc:sponge-mixin:${Versions.Mod.mixin}") - annotationProcessor("dev.architectury:architectury-loom:${Versions.Mod.architecuryLoom}") - implementation(project(path = ":platforms:mixin-common", configuration = "namedElements")) { isTransitive = false } - minecraft("com.mojang:minecraft:${Versions.Mod.minecraft}") - mappings("net.fabricmc:yarn:${Versions.Mod.yarn}:v2") + shadedApi(project(":common:implementation:base")) - modImplementation("cloud.commandframework", "cloud-fabric", Versions.Libraries.cloud) { + modImplementation(libs.mod.fabric.fabric.loader) + + minecraft(libs.mod.minecraft) + mappings("net.fabricmc", "yarn", libs.versions.mod.yarn.get(), classifier = "v2") + + modImplementation(libs.mod.cloud.fabric) { exclude("net.fabricmc") exclude("net.fabricmc.fabric-api") } @@ -42,5 +42,5 @@ tasks { architectury { common("fabric", "quilt") - minecraft = Versions.Mod.minecraft + minecraft = libs.versions.mod.minecraft.get() } \ No newline at end of file diff --git a/platforms/mixin-lifecycle/src/main/java/com/dfsek/terra/lifecycle/LifecycleEntryPoint.java b/platforms/mixin-lifecycle/src/main/java/com/dfsek/terra/lifecycle/LifecycleEntryPoint.java index 3f53bfdfb..ed16b4da9 100644 --- a/platforms/mixin-lifecycle/src/main/java/com/dfsek/terra/lifecycle/LifecycleEntryPoint.java +++ b/platforms/mixin-lifecycle/src/main/java/com/dfsek/terra/lifecycle/LifecycleEntryPoint.java @@ -16,15 +16,19 @@ public class LifecycleEntryPoint { protected static void initialize(String modName, LifecyclePlatform platform) { logger.info("Initializing Terra {} mod...", modName); - FabricServerCommandManager manager = new FabricServerCommandManager<>( - CommandExecutionCoordinator.simpleCoordinator(), - serverCommandSource -> (CommandSender) serverCommandSource, - commandSender -> (ServerCommandSource) commandSender - ); - - - manager.brigadierManager().setNativeNumberSuggestions(false); - - platform.getEventManager().callEvent(new CommandRegistrationEvent(manager)); + try { + FabricServerCommandManager manager = new FabricServerCommandManager<>( + CommandExecutionCoordinator.simpleCoordinator(), + serverCommandSource -> (CommandSender) serverCommandSource, + commandSender -> (ServerCommandSource) commandSender + ); + + + manager.brigadierManager().setNativeNumberSuggestions(false); + + platform.getEventManager().callEvent(new CommandRegistrationEvent(manager)); + } catch (Exception e) { + logger.warn("Fabric API not found, Terra commands will not work."); + } } } diff --git a/platforms/mixin-lifecycle/src/main/java/com/dfsek/terra/lifecycle/util/RegistryUtil.java b/platforms/mixin-lifecycle/src/main/java/com/dfsek/terra/lifecycle/util/RegistryUtil.java index 9f17b89e3..aeb57b484 100644 --- a/platforms/mixin-lifecycle/src/main/java/com/dfsek/terra/lifecycle/util/RegistryUtil.java +++ b/platforms/mixin-lifecycle/src/main/java/com/dfsek/terra/lifecycle/util/RegistryUtil.java @@ -1,5 +1,7 @@ package com.dfsek.terra.lifecycle.util; +import com.dfsek.terra.mod.util.MinecraftUtil; + import net.minecraft.util.Identifier; import net.minecraft.util.registry.Registry; @@ -12,6 +14,7 @@ public final class RegistryUtil { } public static void register() { + MinecraftUtil.registerIntProviderTypes(); Registry.register(Registry.CHUNK_GENERATOR, new Identifier("terra:terra"), Codecs.MINECRAFT_CHUNK_GENERATOR_WRAPPER); Registry.register(Registry.BIOME_SOURCE, new Identifier("terra:terra"), Codecs.TERRA_BIOME_SOURCE); } diff --git a/platforms/quilt/build.gradle.kts b/platforms/quilt/build.gradle.kts index 38ddaaae6..c8a2dbefb 100644 --- a/platforms/quilt/build.gradle.kts +++ b/platforms/quilt/build.gradle.kts @@ -1,7 +1,7 @@ plugins { - id("dev.architectury.loom") version Versions.Mod.architecuryLoom - id("architectury-plugin") version Versions.Mod.architecturyPlugin - id("io.github.juuxel.loom-quiltflower") version Versions.Mod.loomQuiltflower + alias(libs.plugins.mod.architectury.loom) + alias(libs.plugins.mod.architectury.plugin) + alias(libs.plugins.mod.loom.quiltflower) } architectury { @@ -12,9 +12,6 @@ architectury { dependencies { shadedApi(project(":common:implementation:base")) - annotationProcessor("net.fabricmc:sponge-mixin:${Versions.Mod.mixin}") - annotationProcessor("dev.architectury:architectury-loom:${Versions.Mod.architecuryLoom}") - implementation(project(path = ":platforms:mixin-common", configuration = "namedElements")) { isTransitive = false } "developmentQuilt"(project(path = ":platforms:mixin-common", configuration = "namedElements")) { isTransitive = false } shaded(project(path = ":platforms:mixin-common", configuration = "transformProductionQuilt")) { isTransitive = false } @@ -23,23 +20,22 @@ dependencies { "developmentQuilt"(project(path = ":platforms:mixin-lifecycle", configuration = "namedElements")) { isTransitive = false } shaded(project(path = ":platforms:mixin-lifecycle", configuration = "transformProductionQuilt")) { isTransitive = false } - minecraft("com.mojang:minecraft:${Versions.Mod.minecraft}") - mappings("net.fabricmc:yarn:${Versions.Mod.yarn}:v2") + minecraft(libs.mod.minecraft) + mappings("net.fabricmc", "yarn", libs.versions.mod.yarn.get(), classifier = "v2") - modImplementation("org.quiltmc:quilt-loader:${Versions.Quilt.quiltLoader}") + modImplementation(libs.mod.quilt.quilt.loader) + modImplementation(libs.mod.quilt.fabric.api) - modImplementation("org.quiltmc.quilted-fabric-api:quilted-fabric-api:${Versions.Quilt.fabricApi}") - - modImplementation("cloud.commandframework", "cloud-fabric", Versions.Libraries.cloud) { + modImplementation(libs.mod.cloud.fabric) { exclude("net.fabricmc") exclude("net.fabricmc.fabric-api") } - include("cloud.commandframework", "cloud-fabric", Versions.Libraries.cloud) { + include(libs.mod.cloud.fabric) { exclude("net.fabricmc") exclude("net.fabricmc.fabric-api") } - modLocalRuntime("com.github.astei:lazydfu:${Versions.Mod.lazyDfu}") { + modLocalRuntime(libs.mod.lazy.dfu) { exclude("net.fabricmc") exclude("net.fabricmc.fabric-api") } diff --git a/settings.gradle.kts b/settings.gradle.kts index 7a1cdc8a0..231cc5007 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -24,6 +24,7 @@ include(":platforms:bukkit:common") pluginManagement { repositories { + mavenCentral() gradlePluginPortal() maven("https://maven.fabricmc.net") { name = "Fabric Maven" @@ -37,5 +38,8 @@ pluginManagement { maven("https://maven.quiltmc.org/repository/release/") { name = "Quilt" } + maven("https://papermc.io/repo/repository/maven-public/") { + name = "PaperMC" + } } }