diff --git a/.gitignore b/.gitignore index 63dda43600..8a964f70b2 100644 --- a/.gitignore +++ b/.gitignore @@ -249,3 +249,5 @@ nbdist/ platforms/**/run/** +#Vale Config File +**/.vale.ini diff --git a/build.gradle.kts b/build.gradle.kts index f1156e2f75..0088d805e2 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,8 +1,8 @@ preRelease(true) -versionProjects(":common:api", version("6.4.1")) -versionProjects(":common:implementation", version("6.4.1")) -versionProjects(":platforms", version("6.4.1")) +versionProjects(":common:api", version("6.4.2")) +versionProjects(":common:implementation", version("6.4.2")) +versionProjects(":platforms", version("6.4.2")) allprojects { diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index eaec594a48..3bdfddef0f 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -17,10 +17,10 @@ repositories { dependencies { //TODO Allow pulling from Versions.kt implementation("com.github.johnrengelman", "shadow", "8.1.1") - implementation("io.papermc.paperweight.userdev", "io.papermc.paperweight.userdev.gradle.plugin", "1.5.6") + implementation("io.papermc.paperweight.userdev", "io.papermc.paperweight.userdev.gradle.plugin", "1.5.11") - implementation("org.ow2.asm", "asm", "9.5") - implementation("org.ow2.asm", "asm-tree", "9.5") - implementation("com.dfsek.tectonic", "common", "4.2.0") + implementation("org.ow2.asm", "asm", "9.6") + implementation("org.ow2.asm", "asm-tree", "9.6") + implementation("com.dfsek.tectonic", "common", "4.2.1") implementation("org.yaml", "snakeyaml", "2.2") } \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/DependencyConfig.kt b/buildSrc/src/main/kotlin/DependencyConfig.kt index 82b3b206b1..58bde514ce 100644 --- a/buildSrc/src/main/kotlin/DependencyConfig.kt +++ b/buildSrc/src/main/kotlin/DependencyConfig.kt @@ -48,17 +48,14 @@ fun Project.configureDependencies() { maven("https://jitpack.io") { name = "JitPack" } - maven("https://nexuslite.gcnt.net/repos/other/") { - name = "GCNT" - } } 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") + testImplementation("org.junit.jupiter", "junit-jupiter-api", Versions.Libraries.Internal.junit) + testImplementation("org.junit.jupiter", "junit-jupiter-engine", Versions.Libraries.Internal.junit) + compileOnly("org.jetbrains", "annotations", Versions.Libraries.Internal.jetBrainsAnnotations) - compileOnly("com.google.guava:guava:30.0-jre") - testImplementation("com.google.guava:guava:30.0-jre") + compileOnly("com.google.guava", "guava", Versions.Libraries.Internal.guava) + testImplementation("com.google.guava", "guava", Versions.Libraries.Internal.guava) } } diff --git a/buildSrc/src/main/kotlin/DistributionConfig.kt b/buildSrc/src/main/kotlin/DistributionConfig.kt index df003b078d..80e59104e9 100644 --- a/buildSrc/src/main/kotlin/DistributionConfig.kt +++ b/buildSrc/src/main/kotlin/DistributionConfig.kt @@ -27,7 +27,7 @@ fun Project.configureDistribution() { group = "terra" doFirst { file("${buildDir}/resources/main/packs/").deleteRecursively() - val defaultPackUrl = URL("https://github.com/PolyhedralDev/TerraOverworldConfig/releases/download/latest/default.zip") + val defaultPackUrl = URL("https://github.com/PolyhedralDev/TerraOverworldConfig/releases/download/" + Versions.Terra.overworldConfig + "/default.zip") downloadPack(defaultPackUrl, project) } } diff --git a/buildSrc/src/main/kotlin/Versions.kt b/buildSrc/src/main/kotlin/Versions.kt index 18dbd85fef..a150ac3b26 100644 --- a/buildSrc/src/main/kotlin/Versions.kt +++ b/buildSrc/src/main/kotlin/Versions.kt @@ -1,4 +1,8 @@ object Versions { + object Terra { + const val overworldConfig = "v1.3.4" + } + object Libraries { const val tectonic = "4.2.1" const val paralithic = "0.7.1" @@ -6,21 +10,25 @@ object Versions { const val cloud = "1.8.4" + const val caffeine = "3.1.8" + const val slf4j = "2.0.9" const val log4j_slf4j_impl = "2.20.0" object Internal { const val shadow = "8.1.1" - const val apacheText = "1.10.0" - const val apacheIO = "2.14.0" + const val apacheText = "1.11.0" + const val apacheIO = "2.15.1" const val guava = "32.1.3-jre" - const val asm = "9.5" + const val asm = "9.6" const val snakeYml = "2.2" + const val jetBrainsAnnotations = "24.1.0" + const val junit = "5.10.1" } } object Fabric { - const val fabricAPI = "0.90.0+${Mod.minecraft}" + const val fabricAPI = "0.91.2+${Mod.minecraft}" } // // object Quilt { @@ -31,30 +39,28 @@ object Versions { object Mod { const val mixin = "0.12.5+mixin.0.8.5" - const val minecraft = "1.20.2" - const val yarn = "$minecraft+build.4" - const val fabricLoader = "0.14.23" - - const val architecuryLoom = "1.3.357" - const val architecturyPlugin = "3.4.146" + const val minecraft = "1.20.4" + const val yarn = "$minecraft+build.1" + const val fabricLoader = "0.15.1" - const val loomVineflower = "1.11.0" - } - - object Forge { - const val forge = "${Mod.minecraft}-48.0.13" - const val burningwave = "12.63.0" + const val architecuryLoom = "1.4.369" + const val architecturyPlugin = "3.4.151" } +// +// object Forge { +// const val forge = "${Mod.minecraft}-48.0.13" +// const val burningwave = "12.63.0" +// } object Bukkit { - const val paper = "1.18.2-R0.1-SNAPSHOT" - const val paperLib = "1.0.5" - const val foliaLib = "0.2.5" - const val minecraft = "1.20.2" - const val reflectionRemapper = "0.1.0-SNAPSHOT" - const val paperDevBundle = "1.20.2-R0.1-SNAPSHOT" - const val runPaper = "2.2.0" - const val paperWeight = "1.5.6" + const val minecraft = "1.20.4" + const val paperBuild = "$minecraft-R0.1-20231209.173338-2" + const val paper = paperBuild + const val paperLib = "1.0.8" + const val reflectionRemapper = "0.1.0" + const val paperDevBundle = paperBuild + const val runPaper = "2.2.2" + const val paperWeight = "1.5.11" } // @@ -66,6 +72,6 @@ object Versions { // object CLI { const val nbt = "6.1" - const val logback = "1.4.11" + const val logback = "1.4.14" } } \ No newline at end of file diff --git a/common/addons/biome-provider-extrusion/src/main/java/com/dfsek/terra/addons/biome/extrusion/extrusions/ReplaceExtrusion.java b/common/addons/biome-provider-extrusion/src/main/java/com/dfsek/terra/addons/biome/extrusion/extrusions/ReplaceExtrusion.java index daa1b12d92..26b1ec4bb8 100644 --- a/common/addons/biome-provider-extrusion/src/main/java/com/dfsek/terra/addons/biome/extrusion/extrusions/ReplaceExtrusion.java +++ b/common/addons/biome-provider-extrusion/src/main/java/com/dfsek/terra/addons/biome/extrusion/extrusions/ReplaceExtrusion.java @@ -1,5 +1,9 @@ package com.dfsek.terra.addons.biome.extrusion.extrusions; +import java.util.Collection; +import java.util.function.Predicate; +import java.util.stream.Collectors; + import com.dfsek.terra.addons.biome.extrusion.api.Extrusion; import com.dfsek.terra.addons.biome.extrusion.api.ReplaceableBiome; import com.dfsek.terra.addons.biome.query.api.BiomeQueries; @@ -8,10 +12,6 @@ import com.dfsek.terra.api.util.collection.ProbabilityCollection; import com.dfsek.terra.api.world.biome.Biome; -import java.util.Collection; -import java.util.function.Predicate; -import java.util.stream.Collectors; - /** * Sets biomes at locations based on a sampler. diff --git a/common/addons/biome-provider-image-v2/src/main/java/com/dfsek/terra/addons/biome/image/v2/ImageBiomeProvider.java b/common/addons/biome-provider-image-v2/src/main/java/com/dfsek/terra/addons/biome/image/v2/ImageBiomeProvider.java index 8809410c53..073bea70e2 100644 --- a/common/addons/biome-provider-image-v2/src/main/java/com/dfsek/terra/addons/biome/image/v2/ImageBiomeProvider.java +++ b/common/addons/biome-provider-image-v2/src/main/java/com/dfsek/terra/addons/biome/image/v2/ImageBiomeProvider.java @@ -7,13 +7,13 @@ package com.dfsek.terra.addons.biome.image.v2; +import java.util.Optional; + import com.dfsek.terra.addons.image.colorsampler.ColorSampler; import com.dfsek.terra.addons.image.converter.ColorConverter; import com.dfsek.terra.api.world.biome.Biome; import com.dfsek.terra.api.world.biome.generation.BiomeProvider; -import java.util.Optional; - public class ImageBiomeProvider implements BiomeProvider { private final int resolution; diff --git a/common/addons/biome-provider-pipeline-v2/src/main/java/com/dfsek/terra/addons/biome/pipeline/v2/pipeline/BiomeChunkImpl.java b/common/addons/biome-provider-pipeline-v2/src/main/java/com/dfsek/terra/addons/biome/pipeline/v2/pipeline/BiomeChunkImpl.java index e9fe9dbb22..78b0fe806f 100644 --- a/common/addons/biome-provider-pipeline-v2/src/main/java/com/dfsek/terra/addons/biome/pipeline/v2/pipeline/BiomeChunkImpl.java +++ b/common/addons/biome-provider-pipeline-v2/src/main/java/com/dfsek/terra/addons/biome/pipeline/v2/pipeline/BiomeChunkImpl.java @@ -14,7 +14,8 @@ public class BiomeChunkImpl implements BiomeChunk { private final SeededVector worldOrigin; private final int chunkOriginArrayIndex; private final int worldCoordinateScale; - private PipelineBiome[][] biomes; + private final int size; + private PipelineBiome[] biomes; public BiomeChunkImpl(SeededVector worldOrigin, PipelineImpl pipeline) { @@ -22,14 +23,14 @@ public BiomeChunkImpl(SeededVector worldOrigin, PipelineImpl pipeline) { this.chunkOriginArrayIndex = pipeline.getChunkOriginArrayIndex(); this.worldCoordinateScale = pipeline.getResolution(); - int size = pipeline.getArraySize(); + this.size = pipeline.getArraySize(); int expanderCount = pipeline.getExpanderCount(); int expansionsApplied = 0; // Allocate working arrays - this.biomes = new PipelineBiome[size][size]; - PipelineBiome[][] lookupArray = new PipelineBiome[size][size]; + this.biomes = new PipelineBiome[size * size]; + PipelineBiome[] lookupArray = new PipelineBiome[size * size]; // A second lookup array is required such that stage application doesn't affect lookups, otherwise application may cascade // Construct working grid @@ -43,7 +44,7 @@ public BiomeChunkImpl(SeededVector worldOrigin, PipelineImpl pipeline) { for(int gridZ = 0; gridZ < gridSize; gridZ++) { int xIndex = gridOrigin + gridX * gridInterval; int zIndex = gridOrigin + gridZ * gridInterval; - biomes[xIndex][zIndex] = pipeline.getSource().get(worldOrigin.seed(), xIndexToWorldCoordinate(xIndex), + biomes[(xIndex * size) + zIndex] = pipeline.getSource().get(worldOrigin.seed(), xIndexToWorldCoordinate(xIndex), zIndexToWorldCoordinate(zIndex)); } } @@ -65,7 +66,7 @@ public BiomeChunkImpl(SeededVector worldOrigin, PipelineImpl pipeline) { // Cycle arrays, the previously populated array is swapped to be used for lookups, and the result of the stage application // overwrites the previous lookup array. This saves having to allocate a new array copy each time - PipelineBiome[][] tempArray = biomes; + PipelineBiome[] tempArray = biomes; biomes = lookupArray; lookupArray = tempArray; @@ -74,7 +75,8 @@ public BiomeChunkImpl(SeededVector worldOrigin, PipelineImpl pipeline) { for(int gridX = 0; gridX < gridSize; gridX = gridX + 1) { int xIndex = gridOrigin + gridX * gridInterval; int zIndex = gridOrigin + gridZ * gridInterval; - biomes[xIndex][zIndex] = stage.apply(new ViewPoint(this, gridInterval, gridX, gridZ, xIndex, zIndex, lookupArray)); + biomes[(xIndex * size) + zIndex] = stage.apply( + new ViewPoint(this, gridInterval, gridX, gridZ, xIndex, zIndex, lookupArray, size)); } } } @@ -133,7 +135,7 @@ private static int calculateGridInterval(int totalExpansions, int expansionsAppl public PipelineBiome get(int xInChunk, int zInChunk) { int xIndex = xInChunk + chunkOriginArrayIndex; int zIndex = zInChunk + chunkOriginArrayIndex; - return biomes[xIndex][zIndex]; + return biomes[(xIndex * size) + zIndex]; } private int xIndexToWorldCoordinate(int xIndex) { @@ -159,10 +161,11 @@ public static class ViewPoint { private final int gridZ; private final int xIndex; private final int zIndex; - private final PipelineBiome[][] lookupArray; + private final PipelineBiome[] lookupArray; + private final int size; private ViewPoint(BiomeChunkImpl chunk, int gridInterval, int gridX, int gridZ, int xIndex, int zIndex, - PipelineBiome[][] lookupArray) { + PipelineBiome[] lookupArray, int size) { this.chunk = chunk; this.gridInterval = gridInterval; this.gridX = gridX; @@ -170,13 +173,14 @@ private ViewPoint(BiomeChunkImpl chunk, int gridInterval, int gridX, int gridZ, this.xIndex = xIndex; this.zIndex = zIndex; this.lookupArray = lookupArray; - this.biome = lookupArray[xIndex][zIndex]; + this.size = size; + this.biome = lookupArray[(this.xIndex * this.size) + this.zIndex]; } public PipelineBiome getRelativeBiome(int x, int z) { int lookupXIndex = this.xIndex + x * gridInterval; int lookupZIndex = this.zIndex + z * gridInterval; - return lookupArray[lookupXIndex][lookupZIndex]; + return lookupArray[(lookupXIndex * this.size) + lookupZIndex]; } public PipelineBiome getBiome() { diff --git a/common/addons/structure-terrascript-loader/src/main/java/com/dfsek/terra/addons/terrascript/script/functions/BlockFunction.java b/common/addons/structure-terrascript-loader/src/main/java/com/dfsek/terra/addons/terrascript/script/functions/BlockFunction.java index c4518b47c3..28de644816 100644 --- a/common/addons/structure-terrascript-loader/src/main/java/com/dfsek/terra/addons/terrascript/script/functions/BlockFunction.java +++ b/common/addons/structure-terrascript-loader/src/main/java/com/dfsek/terra/addons/terrascript/script/functions/BlockFunction.java @@ -10,8 +10,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.HashMap; import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments; import com.dfsek.terra.addons.terrascript.parser.lang.Returnable; @@ -32,7 +32,7 @@ public class BlockFunction implements Function { protected final Returnable x, y, z; protected final Returnable blockData; protected final Platform platform; - private final Map data = new HashMap<>(); + private final Map data = new ConcurrentHashMap<>(); private final Returnable overwrite; private final Returnable physics; private final Position position; diff --git a/common/api/build.gradle.kts b/common/api/build.gradle.kts index 68a2f0d757..4f88c83e39 100644 --- a/common/api/build.gradle.kts +++ b/common/api/build.gradle.kts @@ -6,6 +6,6 @@ dependencies { api("com.dfsek.tectonic", "common", Versions.Libraries.tectonic) - api("com.github.ben-manes.caffeine:caffeine:3.1.0") + api("com.github.ben-manes.caffeine", "caffeine", Versions.Libraries.caffeine) } \ No newline at end of file diff --git a/common/implementation/base/src/main/java/com/dfsek/terra/config/pack/ConfigPackImpl.java b/common/implementation/base/src/main/java/com/dfsek/terra/config/pack/ConfigPackImpl.java index 06b617cd80..82ec7d95b5 100644 --- a/common/implementation/base/src/main/java/com/dfsek/terra/config/pack/ConfigPackImpl.java +++ b/common/implementation/base/src/main/java/com/dfsek/terra/config/pack/ConfigPackImpl.java @@ -26,6 +26,33 @@ import com.dfsek.tectonic.api.loader.ConfigLoader; import com.dfsek.tectonic.api.loader.type.TypeLoader; import com.dfsek.tectonic.yaml.YamlConfiguration; +import com.google.common.collect.ListMultimap; +import com.google.common.collect.Multimaps; +import org.jetbrains.annotations.NotNull; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.UncheckedIOException; +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TreeMap; +import java.util.concurrent.ConcurrentHashMap; +import java.util.function.Supplier; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; import com.dfsek.terra.api.Platform; import com.dfsek.terra.api.addon.BaseAddon; @@ -56,28 +83,16 @@ import com.dfsek.terra.config.fileloaders.ZIPLoader; import com.dfsek.terra.config.loaders.GenericTemplateSupplierLoader; import com.dfsek.terra.config.loaders.config.BufferedImageLoader; -import com.dfsek.terra.config.preprocessor.*; +import com.dfsek.terra.config.preprocessor.MetaListLikePreprocessor; +import com.dfsek.terra.config.preprocessor.MetaMapPreprocessor; +import com.dfsek.terra.config.preprocessor.MetaNumberPreprocessor; +import com.dfsek.terra.config.preprocessor.MetaStringPreprocessor; +import com.dfsek.terra.config.preprocessor.MetaValuePreprocessor; import com.dfsek.terra.config.prototype.ProtoConfig; import com.dfsek.terra.registry.CheckedRegistryImpl; import com.dfsek.terra.registry.OpenRegistryImpl; import com.dfsek.terra.registry.ShortcutHolder; -import com.google.common.collect.ListMultimap; -import com.google.common.collect.Multimaps; -import org.jetbrains.annotations.NotNull; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.awt.image.BufferedImage; -import java.io.*; -import java.lang.reflect.ParameterizedType; -import java.lang.reflect.Type; -import java.util.*; -import java.util.concurrent.ConcurrentHashMap; -import java.util.function.Supplier; -import java.util.zip.ZipEntry; -import java.util.zip.ZipFile; - /** * Represents a Terra configuration pack. diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 7f93135c49..d64cd49177 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 ac72c34e8a..db8c3baafe 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,7 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip +distributionSha256Sum=9d926787066a081739e8200858338b4a69e837c3a821a33aca9db09dd4a41026 +distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/gradlew b/gradlew index 0adc8e1a53..1aa94a4269 100755 --- a/gradlew +++ b/gradlew @@ -145,7 +145,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then case $MAX_FD in #( max*) # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC3045 + # shellcheck disable=SC2039,SC3045 MAX_FD=$( ulimit -H -n ) || warn "Could not query maximum file descriptor limit" esac @@ -153,7 +153,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then '' | soft) :;; #( *) # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC3045 + # shellcheck disable=SC2039,SC3045 ulimit -n "$MAX_FD" || warn "Could not set maximum file descriptor limit to $MAX_FD" esac @@ -202,11 +202,11 @@ fi # 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"' -# 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. +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. set -- \ "-Dorg.gradle.appname=$APP_BASE_NAME" \ diff --git a/platforms/bukkit/build.gradle.kts b/platforms/bukkit/build.gradle.kts index 89df67efcf..6f75b01330 100644 --- a/platforms/bukkit/build.gradle.kts +++ b/platforms/bukkit/build.gradle.kts @@ -10,19 +10,13 @@ repositories { dependencies { shaded(project(":platforms:bukkit:common")) - shaded(project(":platforms:bukkit:nms:v1_18_R2", configuration = "reobf")) - shaded(project(":platforms:bukkit:nms:v1_19_R1", configuration = "reobf")) - shaded(project(":platforms:bukkit:nms:v1_19_R2", configuration = "reobf")) - shaded(project(":platforms:bukkit:nms:v1_19_R3", configuration = "reobf")) - shaded(project(":platforms:bukkit:nms:v1_20_R1", configuration = "reobf")) - shaded(project(":platforms:bukkit:nms:v1_20_R2", configuration = "reobf")) + shaded(project(":platforms:bukkit:nms:v1_20_R3", configuration = "reobf")) shaded("xyz.jpenilla", "reflection-remapper", Versions.Bukkit.reflectionRemapper) } tasks { shadowJar { relocate("io.papermc.lib", "com.dfsek.terra.lib.paperlib") - relocate("com.tcoded.folialib", "com.dfsek.terra.lib.folialib") 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/**") diff --git a/platforms/bukkit/common/build.gradle.kts b/platforms/bukkit/common/build.gradle.kts index 1324e038d6..f47415da4c 100644 --- a/platforms/bukkit/common/build.gradle.kts +++ b/platforms/bukkit/common/build.gradle.kts @@ -8,9 +8,7 @@ dependencies { compileOnly("io.papermc.paper", "paper-api", Versions.Bukkit.paper) shadedApi("io.papermc", "paperlib", Versions.Bukkit.paperLib) - // TODO: 2023-11-08 When we drop support for 1.18 and 1.19, we can remove FoliaLib and instead use `RegionScheduler`, - // AsyncScheduler, or GlobalRegionScheduler. - shadedApi("com.tcoded", "FoliaLib", Versions.Bukkit.foliaLib) + shadedApi("com.google.guava", "guava", Versions.Libraries.Internal.guava) shadedApi("cloud.commandframework", "cloud-paper", Versions.Libraries.cloud) diff --git a/platforms/bukkit/common/src/main/java/com/dfsek/terra/bukkit/PlatformImpl.java b/platforms/bukkit/common/src/main/java/com/dfsek/terra/bukkit/PlatformImpl.java index 0ef6164d81..45a82c5cbb 100644 --- a/platforms/bukkit/common/src/main/java/com/dfsek/terra/bukkit/PlatformImpl.java +++ b/platforms/bukkit/common/src/main/java/com/dfsek/terra/bukkit/PlatformImpl.java @@ -84,8 +84,8 @@ public boolean reload() { } @Override - public void runPossiblyUnsafeTask(@NotNull Runnable task) { - plugin.getFoliaLib().getImpl().runAsync(task); + public void runPossiblyUnsafeTask(@NotNull Runnable runnable) { + plugin.getGlobalRegionScheduler().run(plugin, task -> runnable.run()); } @Override diff --git a/platforms/bukkit/common/src/main/java/com/dfsek/terra/bukkit/TerraBukkitPlugin.java b/platforms/bukkit/common/src/main/java/com/dfsek/terra/bukkit/TerraBukkitPlugin.java index dd910d48cd..a8701da17e 100644 --- a/platforms/bukkit/common/src/main/java/com/dfsek/terra/bukkit/TerraBukkitPlugin.java +++ b/platforms/bukkit/common/src/main/java/com/dfsek/terra/bukkit/TerraBukkitPlugin.java @@ -21,7 +21,8 @@ import cloud.commandframework.bukkit.CloudBukkitCapabilities; import cloud.commandframework.execution.CommandExecutionCoordinator; import cloud.commandframework.paper.PaperCommandManager; -import com.tcoded.folialib.FoliaLib; +import io.papermc.paper.threadedregions.scheduler.AsyncScheduler; +import io.papermc.paper.threadedregions.scheduler.GlobalRegionScheduler; import org.bukkit.Bukkit; import org.bukkit.generator.ChunkGenerator; import org.bukkit.plugin.java.JavaPlugin; @@ -32,6 +33,7 @@ import java.util.HashMap; import java.util.Map; +import java.util.concurrent.TimeUnit; import com.dfsek.terra.api.command.CommandSender; import com.dfsek.terra.api.config.ConfigPack; @@ -51,7 +53,9 @@ public class TerraBukkitPlugin extends JavaPlugin { private final PlatformImpl platform = new PlatformImpl(this); private final Map generatorMap = new HashMap<>(); - private final FoliaLib foliaLib = new FoliaLib(this); + private AsyncScheduler asyncScheduler = this.getServer().getAsyncScheduler(); + + private GlobalRegionScheduler globalRegionScheduler = this.getServer().getGlobalRegionScheduler(); @Override public void onEnable() { @@ -61,6 +65,10 @@ public void onEnable() { platform.getEventManager().callEvent(new PlatformInitializationEvent()); + if(!Initializer.init(platform)) { + Bukkit.getPluginManager().disablePlugin(this); + return; + } try { PaperCommandManager commandManager = getCommandSenderPaperCommandManager(); @@ -80,8 +88,6 @@ public void onEnable() { Bukkit.getPluginManager().registerEvents(new CommonListener(), this); // Register master event listener PaperUtil.checkPaper(this); - - Initializer.init(platform); } @NotNull @@ -116,6 +122,9 @@ private boolean doVersionCheck() { if(!VersionUtil.getSpigotVersionInfo().isSpigot()) logger.error("YOU ARE RUNNING A CRAFTBUKKIT OR BUKKIT SERVER. PLEASE UPGRADE TO PAPER."); + if(!VersionUtil.getSpigotVersionInfo().isPaper()) + logger.error("YOU ARE RUNNING A SPIGOT SERVER. PLEASE UPGRADE TO PAPER."); + if(VersionUtil.getSpigotVersionInfo().isMohist()) { if(System.getProperty("IKnowMohistCausesLotsOfIssuesButIWillUseItAnyways") == null) { Runnable runnable = () -> { // scary big block of text @@ -159,7 +168,7 @@ private boolean doVersionCheck() { """.strip()); }; runnable.run(); - foliaLib.getImpl().runLaterAsync(runnable, 200L); + asyncScheduler.runDelayed(this, task -> runnable.run(), 200L, TimeUnit.SECONDS); // Bukkit.shutdown(); // we're not *that* evil Bukkit.getPluginManager().disablePlugin(this); return false; @@ -187,7 +196,11 @@ ChunkGenerator getDefaultWorldGenerator(@NotNull String worldName, String id) { }), platform.getRawConfigRegistry().getByID(id).orElseThrow(), platform.getWorldHandle().air()); } - public FoliaLib getFoliaLib() { - return foliaLib; + public AsyncScheduler getAsyncScheduler() { + return asyncScheduler; + } + + public GlobalRegionScheduler getGlobalRegionScheduler() { + return globalRegionScheduler; } } diff --git a/platforms/bukkit/common/src/main/java/com/dfsek/terra/bukkit/handles/BukkitWorldHandle.java b/platforms/bukkit/common/src/main/java/com/dfsek/terra/bukkit/handles/BukkitWorldHandle.java index d28798518e..e3b92b069d 100644 --- a/platforms/bukkit/common/src/main/java/com/dfsek/terra/bukkit/handles/BukkitWorldHandle.java +++ b/platforms/bukkit/common/src/main/java/com/dfsek/terra/bukkit/handles/BukkitWorldHandle.java @@ -20,6 +20,8 @@ import org.bukkit.Bukkit; import org.bukkit.Material; import org.jetbrains.annotations.NotNull; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.Locale; @@ -31,6 +33,7 @@ public class BukkitWorldHandle implements WorldHandle { + private static final Logger logger = LoggerFactory.getLogger(BukkitWorldHandle.class); private final BlockState air; public BukkitWorldHandle() { @@ -39,6 +42,13 @@ public BukkitWorldHandle() { @Override public synchronized @NotNull BlockState createBlockState(@NotNull String data) { + if(data.equals("minecraft:grass")) { //TODO: remove in 7.0 + data = "minecraft:short_grass"; + logger.warn( + "Translating minecraft:grass to minecraft:short_grass. In 1.20.3 minecraft:grass was renamed to minecraft:short_grass" + + ". You are advised to perform this rename in your config backs as this translation will be removed in the next major " + + "version of Terra."); + } org.bukkit.block.data.BlockData bukkitData = Bukkit.createBlockData( data); // somehow bukkit managed to make this not thread safe! :) return BukkitBlockState.newInstance(bukkitData); @@ -51,6 +61,13 @@ public BukkitWorldHandle() { @Override public @NotNull EntityType getEntity(@NotNull String id) { + if (!id.contains(":")) { //TODO: remove in 7.0 + String newid = "minecraft:" + id.toLowerCase();; + logger.warn( + "Translating " + id + " to " + newid + ". In 1.20.3 entity parsing was reworked" + + ". You are advised to perform this rename in your config backs as this translation will be removed in the next major " + + "version of Terra."); + } if(!id.startsWith("minecraft:")) throw new IllegalArgumentException("Invalid entity identifier " + id); String entityID = id.toUpperCase(Locale.ROOT).substring(10); diff --git a/platforms/bukkit/common/src/main/java/com/dfsek/terra/bukkit/nms/Initializer.java b/platforms/bukkit/common/src/main/java/com/dfsek/terra/bukkit/nms/Initializer.java index d2ae2f04b8..413250d57b 100644 --- a/platforms/bukkit/common/src/main/java/com/dfsek/terra/bukkit/nms/Initializer.java +++ b/platforms/bukkit/common/src/main/java/com/dfsek/terra/bukkit/nms/Initializer.java @@ -11,7 +11,7 @@ public interface Initializer { String NMS = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3]; String TERRA_PACKAGE = Initializer.class.getPackageName(); - static void init(PlatformImpl platform) { + static boolean init(PlatformImpl platform) { Logger logger = LoggerFactory.getLogger(Initializer.class); try { Class initializerClass = Class.forName(TERRA_PACKAGE + "." + NMS + ".NMSInitializer"); @@ -24,16 +24,27 @@ static void init(PlatformImpl platform) { } catch(ClassNotFoundException e) { logger.error("NMS bindings for version {} do not exist. Support for this version is limited.", NMS); logger.error("This is usually due to running Terra on an unsupported Minecraft version."); - logger.error(""); - logger.error(""); - for(int i = 0; i < 20; i++) { - logger.error("PROCEEDING WITH AN EXISTING TERRA WORLD WILL RESULT IN CORRUPTION!!!"); + String bypassKey = "IKnowThereAreNoNMSBindingsFor" + NMS + "ButIWillProceedAnyway"; + if(System.getProperty(bypassKey) == null) { + logger.error("Because of this **TERRA HAS BEEN DISABLED**."); + logger.error("Do not come ask us why it is not working."); + logger.error("If you wish to proceed anyways, you can add the JVM System Property \"{}\" to enable the plugin.", bypassKey); + return false; + } else { + logger.error(""); + logger.error(""); + for(int i = 0; i < 20; i++) { + logger.error("PROCEEDING WITH AN EXISTING TERRA WORLD WILL RESULT IN CORRUPTION!!!"); + } + logger.error(""); + logger.error(""); + logger.error("NMS bindings for version {} do not exist. Support for this version is limited.", NMS); + logger.error("This is usually due to running Terra on an unsupported Minecraft version."); + logger.error("We will not give you any support for issues that may arise."); + logger.error("Since you enabled the \"{}\" flag, we won't disable Terra. But be warned.", bypassKey); } - logger.error(""); - logger.error(""); - logger.error("NMS bindings for version {} do not exist. Support for this version is limited.", NMS); - logger.error("This is usually due to running Terra on an unsupported Minecraft version."); } + return true; } void initialize(PlatformImpl plugin); diff --git a/platforms/bukkit/common/src/main/java/com/dfsek/terra/bukkit/util/PaperUtil.java b/platforms/bukkit/common/src/main/java/com/dfsek/terra/bukkit/util/PaperUtil.java index 2cde19b1f5..c687fb0002 100644 --- a/platforms/bukkit/common/src/main/java/com/dfsek/terra/bukkit/util/PaperUtil.java +++ b/platforms/bukkit/common/src/main/java/com/dfsek/terra/bukkit/util/PaperUtil.java @@ -19,6 +19,8 @@ import io.papermc.lib.PaperLib; +import java.util.concurrent.TimeUnit; + import com.dfsek.terra.bukkit.TerraBukkitPlugin; import static io.papermc.lib.PaperLib.suggestPaper; @@ -26,10 +28,10 @@ public final class PaperUtil { public static void checkPaper(TerraBukkitPlugin plugin) { - plugin.getFoliaLib().getImpl().runLaterAsync(() -> { + plugin.getAsyncScheduler().runDelayed(plugin, task -> { if(!PaperLib.isPaper()) { suggestPaper(plugin); } - }, 100L); + }, 100L, TimeUnit.SECONDS); } } diff --git a/platforms/bukkit/common/src/main/resources/plugin.yml b/platforms/bukkit/common/src/main/resources/plugin.yml index d4bfd55340..e965d7deed 100644 --- a/platforms/bukkit/common/src/main/resources/plugin.yml +++ b/platforms/bukkit/common/src/main/resources/plugin.yml @@ -4,6 +4,6 @@ version: "@VERSION@" load: "STARTUP" author: dfsek website: "@WIKI@" -api-version: "1.13" +api-version: "1.20" description: "@DESCRIPTION@" folia-supported: true diff --git a/platforms/bukkit/nms/v1_18_R2/build.gradle.kts b/platforms/bukkit/nms/v1_18_R2/build.gradle.kts deleted file mode 100644 index e3fc99195a..0000000000 --- a/platforms/bukkit/nms/v1_18_R2/build.gradle.kts +++ /dev/null @@ -1,17 +0,0 @@ -apply(plugin = "io.papermc.paperweight.userdev") - -repositories { - maven("https://s01.oss.sonatype.org/content/repositories/snapshots/") -} - -dependencies { - api(project(":platforms:bukkit:common")) - paperDevBundle("1.18.2-R0.1-SNAPSHOT") - implementation("xyz.jpenilla", "reflection-remapper", Versions.Bukkit.reflectionRemapper) -} - -tasks { - assemble { - dependsOn("reobfJar") - } -} \ No newline at end of file diff --git a/platforms/bukkit/nms/v1_18_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_18_R2/AwfulBukkitHacks.java b/platforms/bukkit/nms/v1_18_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_18_R2/AwfulBukkitHacks.java deleted file mode 100644 index bbfae8b2c6..0000000000 --- a/platforms/bukkit/nms/v1_18_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_18_R2/AwfulBukkitHacks.java +++ /dev/null @@ -1,115 +0,0 @@ -package com.dfsek.terra.bukkit.nms.v1_18_R2; - -import com.google.common.collect.ImmutableMap; -import com.mojang.serialization.Lifecycle; -import net.minecraft.core.Holder; -import net.minecraft.core.MappedRegistry; -import net.minecraft.core.Registry; -import net.minecraft.core.WritableRegistry; -import net.minecraft.data.BuiltinRegistries; -import net.minecraft.resources.ResourceKey; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.tags.TagKey; -import net.minecraft.world.level.biome.Biome; -import org.bukkit.NamespacedKey; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import com.dfsek.terra.bukkit.world.BukkitPlatformBiome; -import com.dfsek.terra.registry.master.ConfigRegistry; - - -public class AwfulBukkitHacks { - private static final Logger LOGGER = LoggerFactory.getLogger(NMSBiomeInjector.class); - private static final Map> terraBiomeMap = new HashMap<>(); - - - public static void registerBiomes(ConfigRegistry configRegistry) { - try { - LOGGER.info("Hacking biome registry..."); - WritableRegistry biomeRegistry = (WritableRegistry) Registries.biomeRegistry(); - - Reflection.MAPPED_REGISTRY.setFrozen((MappedRegistry) biomeRegistry, false); - - configRegistry.forEach(pack -> pack.getRegistry(com.dfsek.terra.api.world.biome.Biome.class).forEach((key, biome) -> { - try { - BukkitPlatformBiome platformBiome = (BukkitPlatformBiome) biome.getPlatformBiome(); - NamespacedKey vanillaBukkitKey = platformBiome.getHandle().getKey(); - ResourceLocation vanillaMinecraftKey = new ResourceLocation(vanillaBukkitKey.getNamespace(), vanillaBukkitKey.getKey()); - Biome platform = NMSBiomeInjector.createBiome( - biome, - biomeRegistry.get(vanillaMinecraftKey) // get - ); - - ResourceKey delegateKey = ResourceKey.create(Registry.BIOME_REGISTRY, new ResourceLocation("terra", - NMSBiomeInjector.createBiomeID( - pack, key))); - - BuiltinRegistries.register(BuiltinRegistries.BIOME, delegateKey, platform); - biomeRegistry.register(delegateKey, platform, Lifecycle.stable()); - platformBiome.getContext().put(new NMSBiomeInfo(delegateKey)); - - terraBiomeMap.computeIfAbsent(vanillaMinecraftKey, i -> new ArrayList<>()).add(delegateKey.location()); - - LOGGER.debug("Registered biome: " + delegateKey); - } catch(NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) { - throw new RuntimeException(e); - } - })); - - Reflection.MAPPED_REGISTRY.setFrozen((MappedRegistry) biomeRegistry, true); // freeze registry again :) - - LOGGER.info("Doing tag garbage...."); - Map, List>> collect = biomeRegistry - .getTags() // streamKeysAndEntries - .collect(HashMap::new, - (map, pair) -> - map.put(pair.getFirst(), new ArrayList<>(pair.getSecond().stream().toList())), - HashMap::putAll); - - terraBiomeMap - .forEach((vb, terraBiomes) -> - NMSBiomeInjector.getEntry(biomeRegistry, vb) - .ifPresentOrElse( - vanilla -> terraBiomes - .forEach(tb -> NMSBiomeInjector.getEntry(biomeRegistry, tb) - .ifPresentOrElse( - terra -> { - LOGGER.debug( - vanilla.unwrapKey() - .orElseThrow() - .location() + - " (vanilla for " + - terra.unwrapKey() - .orElseThrow() - .location() + - ": " + - vanilla.tags() - .toList()); - - vanilla.tags() - .forEach( - tag -> collect - .computeIfAbsent( - tag, - t -> new ArrayList<>()) - .add(terra)); - }, - () -> LOGGER.error( - "No such biome: {}", - tb))), - () -> LOGGER.error("No vanilla biome: {}", vb))); - - biomeRegistry.resetTags(); // clearTags - biomeRegistry.bindTags(ImmutableMap.copyOf(collect)); // populateTags - - } catch(SecurityException | IllegalArgumentException exception) { - throw new RuntimeException(exception); - } - } -} diff --git a/platforms/bukkit/nms/v1_18_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_18_R2/NMSBiomeInfo.java b/platforms/bukkit/nms/v1_18_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_18_R2/NMSBiomeInfo.java deleted file mode 100644 index 7e04ef1783..0000000000 --- a/platforms/bukkit/nms/v1_18_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_18_R2/NMSBiomeInfo.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.dfsek.terra.bukkit.nms.v1_18_R2; - -import net.minecraft.resources.ResourceKey; -import net.minecraft.world.level.biome.Biome; - -import com.dfsek.terra.api.properties.Properties; - - -public record NMSBiomeInfo(ResourceKey biomeKey) implements Properties { -} diff --git a/platforms/bukkit/nms/v1_18_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_18_R2/NMSBiomeInjector.java b/platforms/bukkit/nms/v1_18_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_18_R2/NMSBiomeInjector.java deleted file mode 100644 index f56c32b5bb..0000000000 --- a/platforms/bukkit/nms/v1_18_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_18_R2/NMSBiomeInjector.java +++ /dev/null @@ -1,79 +0,0 @@ -package com.dfsek.terra.bukkit.nms.v1_18_R2; - -import net.minecraft.core.Holder; -import net.minecraft.core.Registry; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.level.biome.Biome; -import net.minecraft.world.level.biome.BiomeSpecialEffects; - -import java.util.Locale; -import java.util.Objects; -import java.util.Optional; - -import com.dfsek.terra.api.config.ConfigPack; -import com.dfsek.terra.bukkit.config.VanillaBiomeProperties; - - -public class NMSBiomeInjector { - - public static Optional> getEntry(Registry registry, ResourceLocation identifier) { - return registry.getOptional(identifier) - .flatMap(registry::getResourceKey) - .map(registry::getOrCreateHolder); - } - - public static Biome createBiome(com.dfsek.terra.api.world.biome.Biome biome, Biome vanilla) - throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { - Biome.BiomeBuilder builder = new Biome.BiomeBuilder(); // Builder - - - builder.biomeCategory(Reflection.BIOME.getBiomeCategory(vanilla)) - .precipitation(vanilla.getPrecipitation()) // getPrecipitation - .mobSpawnSettings(vanilla.getMobSettings()) - .generationSettings(vanilla.getGenerationSettings()) - .temperature(vanilla.getBaseTemperature()) - .downfall(vanilla.getDownfall()); - - - BiomeSpecialEffects.Builder effects = new BiomeSpecialEffects.Builder(); - - effects.grassColorModifier(vanilla.getSpecialEffects().getGrassColorModifier()); - - VanillaBiomeProperties vanillaBiomeProperties = biome.getContext().get(VanillaBiomeProperties.class); - - effects.fogColor(Objects.requireNonNullElse(vanillaBiomeProperties.getFogColor(), vanilla.getFogColor())) - - .waterColor(Objects.requireNonNullElse(vanillaBiomeProperties.getWaterColor(), vanilla.getWaterColor())) - - .waterFogColor(Objects.requireNonNullElse(vanillaBiomeProperties.getWaterFogColor(), vanilla.getWaterFogColor())) - - .skyColor(Objects.requireNonNullElse(vanillaBiomeProperties.getSkyColor(), vanilla.getSkyColor())); - - if(vanillaBiomeProperties.getFoliageColor() == null) { - vanilla.getSpecialEffects().getFoliageColorOverride().ifPresent(effects::foliageColorOverride); - } else { - effects.foliageColorOverride(vanillaBiomeProperties.getFoliageColor()); - } - - if(vanillaBiomeProperties.getGrassColor() == null) { - vanilla.getSpecialEffects().getGrassColorOverride().ifPresent(effects::grassColorOverride); - } else { - effects.grassColorOverride(vanillaBiomeProperties.getGrassColor()); - } - - vanilla.getAmbientLoop().ifPresent(effects::ambientLoopSound); - vanilla.getAmbientAdditions().ifPresent(effects::ambientAdditionsSound); - vanilla.getAmbientMood().ifPresent(effects::ambientMoodSound); - vanilla.getBackgroundMusic().ifPresent(effects::backgroundMusic); - vanilla.getAmbientParticle().ifPresent(effects::ambientParticle); - - builder.specialEffects(effects.build()); - - return builder.build(); // build() - } - - public static String createBiomeID(ConfigPack pack, com.dfsek.terra.api.registry.key.RegistryKey biomeID) { - return pack.getID() - .toLowerCase() + "/" + biomeID.getNamespace().toLowerCase(Locale.ROOT) + "/" + biomeID.getID().toLowerCase(Locale.ROOT); - } -} diff --git a/platforms/bukkit/nms/v1_18_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_18_R2/NMSBiomeProvider.java b/platforms/bukkit/nms/v1_18_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_18_R2/NMSBiomeProvider.java deleted file mode 100644 index 9fb99f13fb..0000000000 --- a/platforms/bukkit/nms/v1_18_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_18_R2/NMSBiomeProvider.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.dfsek.terra.bukkit.nms.v1_18_R2; - -import com.mojang.serialization.Codec; -import net.minecraft.core.Holder; -import net.minecraft.core.Registry; -import net.minecraft.world.level.biome.Biome; -import net.minecraft.world.level.biome.BiomeSource; -import net.minecraft.world.level.biome.Climate.Sampler; -import org.jetbrains.annotations.NotNull; - -import com.dfsek.terra.api.world.biome.generation.BiomeProvider; -import com.dfsek.terra.bukkit.world.BukkitPlatformBiome; - - -public class NMSBiomeProvider extends BiomeSource { - private final BiomeProvider delegate; - private final BiomeSource vanilla; - private final long seed; - private final Registry biomeRegistry = Registries.biomeRegistry(); - - public NMSBiomeProvider(BiomeProvider delegate, BiomeSource vanilla, long seed) { - super(delegate.stream() - .map(biome -> Registries.biomeRegistry() - .getOrCreateHolder(((BukkitPlatformBiome) biome.getPlatformBiome()).getContext() - .get(NMSBiomeInfo.class) - .biomeKey()))); - this.delegate = delegate; - this.vanilla = vanilla; - this.seed = seed; - } - - @Override - protected Codec codec() { - return BiomeSource.CODEC; - } - - @Override - public @NotNull BiomeSource withSeed(long seed) { - return new NMSBiomeProvider(delegate, vanilla, seed); - } - - @Override - public @NotNull Holder getNoiseBiome(int x, int y, int z, @NotNull Sampler sampler) { - return biomeRegistry.getOrCreateHolder(((BukkitPlatformBiome) delegate.getBiome(x << 2, y << 2, z << 2, seed).getPlatformBiome()) - .getContext() - .get(NMSBiomeInfo.class) - .biomeKey()); - } -} diff --git a/platforms/bukkit/nms/v1_18_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_18_R2/NMSChunkGeneratorDelegate.java b/platforms/bukkit/nms/v1_18_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_18_R2/NMSChunkGeneratorDelegate.java deleted file mode 100644 index 905867b62b..0000000000 --- a/platforms/bukkit/nms/v1_18_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_18_R2/NMSChunkGeneratorDelegate.java +++ /dev/null @@ -1,254 +0,0 @@ -package com.dfsek.terra.bukkit.nms.v1_18_R2; - -import com.mojang.datafixers.util.Pair; -import com.mojang.serialization.Codec; -import it.unimi.dsi.fastutil.objects.Object2ObjectArrayMap; -import net.minecraft.core.BlockPos; -import net.minecraft.core.Holder; -import net.minecraft.core.SectionPos; -import net.minecraft.server.level.WorldGenRegion; -import net.minecraft.world.level.ChunkPos; -import net.minecraft.world.level.LevelHeightAccessor; -import net.minecraft.world.level.NoiseColumn; -import net.minecraft.world.level.StructureFeatureManager; -import net.minecraft.world.level.WorldGenLevel; -import net.minecraft.world.level.biome.Biome; -import net.minecraft.world.level.biome.BiomeManager; -import net.minecraft.world.level.biome.Climate; -import net.minecraft.world.level.biome.Climate.Sampler; -import net.minecraft.world.level.chunk.ChunkAccess; -import net.minecraft.world.level.chunk.ChunkGenerator; -import net.minecraft.world.level.levelgen.GenerationStep; -import net.minecraft.world.level.levelgen.Heightmap; -import net.minecraft.world.level.levelgen.blending.Blender; -import net.minecraft.world.level.levelgen.structure.StructureSet; -import net.minecraft.world.level.levelgen.structure.placement.ConcentricRingsStructurePlacement; -import net.minecraft.world.level.levelgen.structure.placement.StructurePlacement; -import org.bukkit.craftbukkit.v1_18_R2.block.data.CraftBlockData; -import org.jetbrains.annotations.NotNull; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.annotation.Nullable; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; -import java.util.Random; -import java.util.Set; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.Executor; -import java.util.stream.Collectors; - -import com.dfsek.terra.api.config.ConfigPack; -import com.dfsek.terra.api.util.MathUtil; -import com.dfsek.terra.api.util.generic.Lazy; -import com.dfsek.terra.api.world.biome.generation.BiomeProvider; -import com.dfsek.terra.api.world.info.WorldProperties; - - -public class NMSChunkGeneratorDelegate extends ChunkGenerator { - private static final Logger LOGGER = LoggerFactory.getLogger(NMSChunkGeneratorDelegate.class); - private static final Lazy> EMPTY = Lazy.lazy(List::of); - private final NMSBiomeProvider biomeSource; - private final com.dfsek.terra.api.world.chunk.generation.ChunkGenerator delegate; - private final ChunkGenerator vanilla; - private final ConfigPack pack; - private final long seed; - private final Map>> ringPositions = new Object2ObjectArrayMap<>(); - private volatile boolean rings = false; - - public NMSChunkGeneratorDelegate(ChunkGenerator vanilla, ConfigPack pack, NMSBiomeProvider biomeProvider, long seed) { - super(Registries.structureSet(), Optional.empty(), biomeProvider, biomeProvider, seed); - this.delegate = pack.getGeneratorProvider().newInstance(pack); - this.vanilla = vanilla; - this.biomeSource = biomeProvider; - this.pack = pack; - this.seed = seed; - } - - @Override - public void applyCarvers(@NotNull WorldGenRegion chunkRegion, long seed, @NotNull BiomeManager biomeAccess, - @NotNull StructureFeatureManager structureAccessor, - @NotNull ChunkAccess chunk, GenerationStep.@NotNull Carving generationStep) { - // no-op - } - - @Override - public void applyBiomeDecoration(@NotNull WorldGenLevel world, @NotNull ChunkAccess chunk, - @NotNull StructureFeatureManager structureAccessor) { - vanilla.applyBiomeDecoration(world, chunk, structureAccessor); - } - - @Override - public int getSeaLevel() { - return vanilla.getSeaLevel(); - } - - @Override - public @NotNull CompletableFuture fillFromNoise(@NotNull Executor executor, @NotNull Blender blender, - @NotNull StructureFeatureManager structureAccessor, - @NotNull ChunkAccess chunk) { - return vanilla.fillFromNoise(executor, blender, structureAccessor, chunk); - } - - @Override - public void buildSurface(@NotNull WorldGenRegion region, @NotNull StructureFeatureManager structures, @NotNull ChunkAccess chunk) { - // no-op - } - - @Override - protected @NotNull Codec codec() { - return ChunkGenerator.CODEC; - } - - @Override - public @NotNull NoiseColumn getBaseColumn(int x, int z, LevelHeightAccessor height) { - /* - BlockState[] array = new BlockState[height.getHeight()]; - WorldProperties properties = new NMSWorldProperties(seed, height); - BiomeProvider biomeProvider = pack.getBiomeProvider().caching(properties); - for(int y = properties.getMaxHeight() - 1; y >= properties.getMinHeight(); y--) { - array[y - properties.getMinHeight()] = ((CraftBlockData) delegate.getBlock(properties, x, y, z, biomeProvider) - .getHandle()).getState(); - } - return new NoiseColumn(getMinY(), array); - */ - return vanilla.getBaseColumn(x, z, height); - } - - @Override // withSeed - public @NotNull ChunkGenerator withSeed(long seed) { - return new NMSChunkGeneratorDelegate(vanilla, pack, biomeSource, seed); - } - - @Override - public void spawnOriginalMobs(@NotNull WorldGenRegion regionlimitedworldaccess) { - vanilla.spawnOriginalMobs(regionlimitedworldaccess); - } - - @Override - public int getGenDepth() { - return vanilla.getGenDepth(); - } - - @Override - public @NotNull Sampler climateSampler() { - return Climate.empty(); - } - - @Override - public int getMinY() { - return vanilla.getMinY(); - } - - @Override - public int getBaseHeight(int x, int z, Heightmap.@NotNull Types heightmap, @NotNull LevelHeightAccessor world) { - WorldProperties properties = new NMSWorldProperties(seed, world); - int y = properties.getMaxHeight(); - BiomeProvider biomeProvider = pack.getBiomeProvider(); - while(y >= getMinY() && !heightmap.isOpaque().test( - ((CraftBlockData) delegate.getBlock(properties, x, y - 1, z, biomeProvider).getHandle()).getState())) { - y--; - } - return y; - } - - @Nullable - @Override - public List getRingPositionsFor(@NotNull ConcentricRingsStructurePlacement concentricringsstructureplacement) { - ensureStructuresGenerated(); - return ringPositions.getOrDefault(concentricringsstructureplacement, EMPTY).value(); - } - - @Override - public synchronized void ensureStructuresGenerated() { - if(!this.rings) { - super.ensureStructuresGenerated(); - this.populateStrongholdData(); - this.rings = true; - } - } - - private void populateStrongholdData() { - LOGGER.info("Generating safe stronghold data. This may take up to a minute."); - Set> set = this.runtimeBiomeSource.possibleBiomes(); - possibleStructureSets().map(Holder::value).forEach((holder) -> { // we dont need the spigot crap because it doesnt touch concentric. - StructurePlacement structureplacement = holder.placement(); - if(structureplacement instanceof ConcentricRingsStructurePlacement concentricringsstructureplacement) { - if(holder.structures().stream().anyMatch((structureset_a1) -> structureset_a1.generatesInMatchingBiome(set::contains))) { - this.ringPositions.put(concentricringsstructureplacement, - Lazy.lazy(() -> this.generateRingPositions(holder, concentricringsstructureplacement))); - } - } - }); - } - - private List generateRingPositions(StructureSet holder, - ConcentricRingsStructurePlacement concentricringsstructureplacement) { // Spigot - if(concentricringsstructureplacement.count() == 0) { - return List.of(); - } - - List list = new ArrayList<>(); - Set> set = holder - .structures() - .stream() - .flatMap((structureset_a) -> structureset_a.structure().value().biomes().stream()) - .collect(Collectors.toSet()); - int i = concentricringsstructureplacement.distance(); - int j = concentricringsstructureplacement.count(); - int k = concentricringsstructureplacement.spread(); - Random random = new Random(); - - // Paper start - if(this.conf.strongholdSeed != null && this.structureSets.getResourceKey(holder).orElse(null) == - net.minecraft.world.level.levelgen.structure.BuiltinStructureSets.STRONGHOLDS) { - random.setSeed(this.conf.strongholdSeed); - } else { - // Paper end - random.setSeed(this.ringPlacementSeed); - } // Paper - double d0 = random.nextDouble() * 3.141592653589793D * 2.0D; - int l = 0; - int i1 = 0; - - for(int j1 = 0; j1 < j; ++j1) { - double d1 = (double) (4 * i + i * i1 * 6) + (random.nextDouble() - 0.5D) * (double) i * 2.5D; - int k1 = (int) Math.round(MathUtil.cos(d0) * d1); - int l1 = (int) Math.round(MathUtil.sin(d0) * d1); - int i2 = SectionPos.sectionToBlockCoord(k1, 8); - int j2 = SectionPos.sectionToBlockCoord(l1, 8); - - Objects.requireNonNull(set); - Pair> pair = this.biomeSource.findBiomeHorizontal(i2, 0, j2, 112, set::contains, random, - this.climateSampler()); - - if(pair != null) { - BlockPos blockposition = pair.getFirst(); - - k1 = SectionPos.blockToSectionCoord(blockposition.getX()); - l1 = SectionPos.blockToSectionCoord(blockposition.getZ()); - } - - list.add(new ChunkPos(k1, l1)); - d0 += 6.283185307179586D / (double) k; - ++l; - if(l == k) { - ++i1; - l = 0; - k += 2 * k / (i1 + 1); - k = Math.min(k, j - j1); - d0 += random.nextDouble() * 3.141592653589793D * 2.0D; - } - } - - return list; - } - - @Override - public void addDebugScreenInfo(@NotNull List arg0, @NotNull BlockPos arg1) { - - } -} diff --git a/platforms/bukkit/nms/v1_18_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_18_R2/NMSInitializer.java b/platforms/bukkit/nms/v1_18_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_18_R2/NMSInitializer.java deleted file mode 100644 index f724b89f0f..0000000000 --- a/platforms/bukkit/nms/v1_18_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_18_R2/NMSInitializer.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.dfsek.terra.bukkit.nms.v1_18_R2; - -import org.bukkit.Bukkit; - -import com.dfsek.terra.bukkit.PlatformImpl; -import com.dfsek.terra.bukkit.nms.Initializer; - - -public class NMSInitializer implements Initializer { - @Override - public void initialize(PlatformImpl platform) { - AwfulBukkitHacks.registerBiomes(platform.getRawConfigRegistry()); - Bukkit.getPluginManager().registerEvents(new NMSInjectListener(), platform.getPlugin()); - } -} diff --git a/platforms/bukkit/nms/v1_18_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_18_R2/NMSInjectListener.java b/platforms/bukkit/nms/v1_18_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_18_R2/NMSInjectListener.java deleted file mode 100644 index 9e055524a3..0000000000 --- a/platforms/bukkit/nms/v1_18_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_18_R2/NMSInjectListener.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.dfsek.terra.bukkit.nms.v1_18_R2; - -import net.minecraft.server.level.ServerLevel; -import net.minecraft.world.level.chunk.ChunkGenerator; -import org.bukkit.World; -import org.bukkit.craftbukkit.v1_18_R2.CraftWorld; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.world.WorldInitEvent; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.HashSet; -import java.util.Set; -import java.util.concurrent.locks.ReentrantLock; - -import com.dfsek.terra.api.config.ConfigPack; -import com.dfsek.terra.bukkit.generator.BukkitChunkGeneratorWrapper; - - -public class NMSInjectListener implements Listener { - private static final Logger LOGGER = LoggerFactory.getLogger(NMSInjectListener.class); - private static final Set INJECTED = new HashSet<>(); - private static final ReentrantLock INJECT_LOCK = new ReentrantLock(); - - @EventHandler - public void onWorldInit(WorldInitEvent event) { - if(!INJECTED.contains(event.getWorld()) && - event.getWorld().getGenerator() instanceof BukkitChunkGeneratorWrapper bukkitChunkGeneratorWrapper) { - INJECT_LOCK.lock(); - INJECTED.add(event.getWorld()); - LOGGER.info("Preparing to take over the world: {}", event.getWorld().getName()); - CraftWorld craftWorld = (CraftWorld) event.getWorld(); - ServerLevel serverWorld = craftWorld.getHandle(); - - ConfigPack pack = bukkitChunkGeneratorWrapper.getPack(); - - ChunkGenerator vanilla = serverWorld.getChunkSource().getGenerator(); - NMSBiomeProvider provider = new NMSBiomeProvider(pack.getBiomeProvider(), vanilla.getBiomeSource(), craftWorld.getSeed()); - NMSChunkGeneratorDelegate custom = new NMSChunkGeneratorDelegate(vanilla, pack, provider, craftWorld.getSeed()); - - custom.conf = vanilla.conf; // world config from Spigot - - serverWorld.getChunkSource().chunkMap.generator = custom; - - LOGGER.info("Successfully injected into world."); - - serverWorld.getChunkSource().chunkMap.generator.ensureStructuresGenerated(); // generate stronghold data now - - INJECT_LOCK.unlock(); - } - } -} diff --git a/platforms/bukkit/nms/v1_18_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_18_R2/NMSWorldProperties.java b/platforms/bukkit/nms/v1_18_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_18_R2/NMSWorldProperties.java deleted file mode 100644 index 875dc03307..0000000000 --- a/platforms/bukkit/nms/v1_18_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_18_R2/NMSWorldProperties.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.dfsek.terra.bukkit.nms.v1_18_R2; - -import net.minecraft.world.level.LevelHeightAccessor; - -import com.dfsek.terra.api.world.info.WorldProperties; - - -public class NMSWorldProperties implements WorldProperties { - private final long seed; - private final LevelHeightAccessor height; - - public NMSWorldProperties(long seed, LevelHeightAccessor height) { - this.seed = seed; - this.height = height; - } - - @Override - public Object getHandle() { - return height; - } - - @Override - public long getSeed() { - return seed; - } - - @Override - public int getMaxHeight() { - return height.getMaxBuildHeight(); - } - - @Override - public int getMinHeight() { - return height.getMinBuildHeight(); - } -} diff --git a/platforms/bukkit/nms/v1_18_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_18_R2/Reflection.java b/platforms/bukkit/nms/v1_18_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_18_R2/Reflection.java deleted file mode 100644 index c6e3351a12..0000000000 --- a/platforms/bukkit/nms/v1_18_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_18_R2/Reflection.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.dfsek.terra.bukkit.nms.v1_18_R2; - -import net.minecraft.core.MappedRegistry; -import net.minecraft.world.level.biome.Biome; -import xyz.jpenilla.reflectionremapper.ReflectionRemapper; -import xyz.jpenilla.reflectionremapper.proxy.ReflectionProxyFactory; -import xyz.jpenilla.reflectionremapper.proxy.annotation.FieldGetter; -import xyz.jpenilla.reflectionremapper.proxy.annotation.FieldSetter; -import xyz.jpenilla.reflectionremapper.proxy.annotation.Proxies; - - -public class Reflection { - public static final MappedRegistryProxy MAPPED_REGISTRY; - public static final BiomeProxy BIOME; - - static { - ReflectionRemapper reflectionRemapper = ReflectionRemapper.forReobfMappingsInPaperJar(); - ReflectionProxyFactory reflectionProxyFactory = ReflectionProxyFactory.create(reflectionRemapper, - Reflection.class.getClassLoader()); - - MAPPED_REGISTRY = reflectionProxyFactory.reflectionProxy(MappedRegistryProxy.class); - BIOME = reflectionProxyFactory.reflectionProxy(BiomeProxy.class); - } - - - @Proxies(MappedRegistry.class) - public interface MappedRegistryProxy { - @FieldSetter("frozen") - void setFrozen(MappedRegistry instance, boolean frozen); - } - - - @Proxies(Biome.class) - public interface BiomeProxy { - @FieldGetter("biomeCategory") - Biome.BiomeCategory getBiomeCategory(Biome instance); - } -} diff --git a/platforms/bukkit/nms/v1_18_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_18_R2/Registries.java b/platforms/bukkit/nms/v1_18_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_18_R2/Registries.java deleted file mode 100644 index 652d77cab3..0000000000 --- a/platforms/bukkit/nms/v1_18_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_18_R2/Registries.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.dfsek.terra.bukkit.nms.v1_18_R2; - -import net.minecraft.core.Registry; -import net.minecraft.resources.ResourceKey; -import net.minecraft.server.dedicated.DedicatedServer; -import net.minecraft.world.level.biome.Biome; -import net.minecraft.world.level.levelgen.structure.StructureSet; -import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_18_R2.CraftServer; - - -public class Registries { - private static Registry getRegistry(ResourceKey> key) { - CraftServer craftserver = (CraftServer) Bukkit.getServer(); - DedicatedServer dedicatedserver = craftserver.getServer(); - return dedicatedserver - .registryAccess() - .registryOrThrow( // getRegistry - key - ); - } - - public static Registry biomeRegistry() { - return getRegistry(Registry.BIOME_REGISTRY); - } - - public static Registry structureSet() { - return getRegistry(Registry.STRUCTURE_SET_REGISTRY); - } -} diff --git a/platforms/bukkit/nms/v1_19_R1/build.gradle.kts b/platforms/bukkit/nms/v1_19_R1/build.gradle.kts deleted file mode 100644 index 9b301aa706..0000000000 --- a/platforms/bukkit/nms/v1_19_R1/build.gradle.kts +++ /dev/null @@ -1,17 +0,0 @@ -apply(plugin = "io.papermc.paperweight.userdev") - -repositories { - maven("https://s01.oss.sonatype.org/content/repositories/snapshots/") -} - -dependencies { - api(project(":platforms:bukkit:common")) - paperDevBundle("1.19-R0.1-SNAPSHOT") - implementation("xyz.jpenilla", "reflection-remapper", Versions.Bukkit.reflectionRemapper) -} - -tasks { - assemble { - dependsOn("reobfJar") - } -} diff --git a/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/AwfulBukkitHacks.java b/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/AwfulBukkitHacks.java deleted file mode 100644 index 92506d834d..0000000000 --- a/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/AwfulBukkitHacks.java +++ /dev/null @@ -1,116 +0,0 @@ -package com.dfsek.terra.bukkit.nms.v1_19_R1; - -import com.google.common.collect.ImmutableMap; -import com.mojang.serialization.Lifecycle; -import net.minecraft.core.Holder; -import net.minecraft.core.MappedRegistry; -import net.minecraft.core.Registry; -import net.minecraft.core.WritableRegistry; -import net.minecraft.data.BuiltinRegistries; -import net.minecraft.resources.ResourceKey; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.tags.TagKey; -import net.minecraft.world.level.biome.Biome; -import org.bukkit.NamespacedKey; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -import com.dfsek.terra.bukkit.world.BukkitPlatformBiome; -import com.dfsek.terra.registry.master.ConfigRegistry; - - -public class AwfulBukkitHacks { - private static final Logger LOGGER = LoggerFactory.getLogger(AwfulBukkitHacks.class); - - private static final Map> terraBiomeMap = new HashMap<>(); - - public static void registerBiomes(ConfigRegistry configRegistry) { - try { - LOGGER.info("Hacking biome registry..."); - WritableRegistry biomeRegistry = (WritableRegistry) Registries.biomeRegistry(); - - Reflection.MAPPED_REGISTRY.setFrozen((MappedRegistry) biomeRegistry, false); - - configRegistry.forEach(pack -> pack.getRegistry(com.dfsek.terra.api.world.biome.Biome.class).forEach((key, biome) -> { - try { - BukkitPlatformBiome platformBiome = (BukkitPlatformBiome) biome.getPlatformBiome(); - NamespacedKey vanillaBukkitKey = platformBiome.getHandle().getKey(); - ResourceLocation vanillaMinecraftKey = new ResourceLocation(vanillaBukkitKey.getNamespace(), vanillaBukkitKey.getKey()); - Biome platform = NMSBiomeInjector.createBiome( - biome, - Objects.requireNonNull(biomeRegistry.get(vanillaMinecraftKey)) // get - ); - - ResourceKey delegateKey = ResourceKey.create(Registry.BIOME_REGISTRY, - new ResourceLocation("terra", - NMSBiomeInjector.createBiomeID(pack, key))); - - BuiltinRegistries.register(BuiltinRegistries.BIOME, delegateKey, platform); - biomeRegistry.register(delegateKey, platform, Lifecycle.stable()); - platformBiome.getContext().put(new NMSBiomeInfo(delegateKey)); - - terraBiomeMap.computeIfAbsent(vanillaMinecraftKey, i -> new ArrayList<>()).add(delegateKey.location()); - - LOGGER.debug("Registered biome: " + delegateKey); - } catch(NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) { - throw new RuntimeException(e); - } - })); - - Reflection.MAPPED_REGISTRY.setFrozen((MappedRegistry) biomeRegistry, true); // freeze registry again :) - - LOGGER.info("Doing tag garbage...."); - Map, List>> collect = biomeRegistry - .getTags() // streamKeysAndEntries - .collect(HashMap::new, - (map, pair) -> - map.put(pair.getFirst(), new ArrayList<>(pair.getSecond().stream().toList())), - HashMap::putAll); - - terraBiomeMap - .forEach((vb, terraBiomes) -> - NMSBiomeInjector.getEntry(biomeRegistry, vb) - .ifPresentOrElse( - vanilla -> terraBiomes - .forEach(tb -> NMSBiomeInjector.getEntry(biomeRegistry, tb) - .ifPresentOrElse( - terra -> { - LOGGER.debug( - vanilla.unwrapKey() - .orElseThrow() - .location() + - " (vanilla for " + - terra.unwrapKey() - .orElseThrow() - .location() + - ": " + - vanilla.tags() - .toList()); - - vanilla.tags() - .forEach( - tag -> collect - .computeIfAbsent( - tag, - t -> new ArrayList<>()) - .add(terra)); - }, - () -> LOGGER.error( - "No such biome: {}", - tb))), - () -> LOGGER.error("No vanilla biome: {}", vb))); - - biomeRegistry.resetTags(); - biomeRegistry.bindTags(ImmutableMap.copyOf(collect)); - - } catch(SecurityException | IllegalArgumentException exception) { - throw new RuntimeException(exception); - } - } -} diff --git a/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSBiomeInjector.java b/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSBiomeInjector.java deleted file mode 100644 index 39a66e468e..0000000000 --- a/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSBiomeInjector.java +++ /dev/null @@ -1,79 +0,0 @@ -package com.dfsek.terra.bukkit.nms.v1_19_R1; - -import net.minecraft.core.Holder; -import net.minecraft.core.Registry; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.level.biome.Biome; -import net.minecraft.world.level.biome.BiomeSpecialEffects; - -import java.util.Locale; -import java.util.Objects; -import java.util.Optional; - -import com.dfsek.terra.api.config.ConfigPack; -import com.dfsek.terra.bukkit.config.VanillaBiomeProperties; - - -public class NMSBiomeInjector { - - public static Optional> getEntry(Registry registry, ResourceLocation identifier) { - return registry.getOptional(identifier) - .flatMap(registry::getResourceKey) - .map(registry::getOrCreateHolderOrThrow); - } - - public static Biome createBiome(com.dfsek.terra.api.world.biome.Biome biome, Biome vanilla) - throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { - Biome.BiomeBuilder builder = new Biome.BiomeBuilder(); - - builder - .precipitation(vanilla.getPrecipitation()) - .downfall(vanilla.getDownfall()) - .temperature(vanilla.getBaseTemperature()) - .mobSpawnSettings(vanilla.getMobSettings()) - .generationSettings(vanilla.getGenerationSettings()); - - - BiomeSpecialEffects.Builder effects = new BiomeSpecialEffects.Builder(); - - effects.grassColorModifier(vanilla.getSpecialEffects().getGrassColorModifier()); - - VanillaBiomeProperties vanillaBiomeProperties = biome.getContext().get(VanillaBiomeProperties.class); - - effects.fogColor(Objects.requireNonNullElse(vanillaBiomeProperties.getFogColor(), vanilla.getFogColor())) - - .waterColor(Objects.requireNonNullElse(vanillaBiomeProperties.getWaterColor(), vanilla.getWaterColor())) - - .waterFogColor(Objects.requireNonNullElse(vanillaBiomeProperties.getWaterFogColor(), vanilla.getWaterFogColor())) - - .skyColor(Objects.requireNonNullElse(vanillaBiomeProperties.getSkyColor(), vanilla.getSkyColor())); - - if(vanillaBiomeProperties.getFoliageColor() == null) { - vanilla.getSpecialEffects().getFoliageColorOverride().ifPresent(effects::foliageColorOverride); - } else { - effects.foliageColorOverride(vanillaBiomeProperties.getFoliageColor()); - } - - if(vanillaBiomeProperties.getGrassColor() == null) { - vanilla.getSpecialEffects().getGrassColorOverride().ifPresent(effects::grassColorOverride); - } else { - // grass - effects.grassColorOverride(vanillaBiomeProperties.getGrassColor()); - } - - vanilla.getAmbientLoop().ifPresent(effects::ambientLoopSound); - vanilla.getAmbientAdditions().ifPresent(effects::ambientAdditionsSound); - vanilla.getAmbientMood().ifPresent(effects::ambientMoodSound); - vanilla.getBackgroundMusic().ifPresent(effects::backgroundMusic); - vanilla.getAmbientParticle().ifPresent(effects::ambientParticle); - - builder.specialEffects(effects.build()); - - return builder.build(); - } - - public static String createBiomeID(ConfigPack pack, com.dfsek.terra.api.registry.key.RegistryKey biomeID) { - return pack.getID() - .toLowerCase() + "/" + biomeID.getNamespace().toLowerCase(Locale.ROOT) + "/" + biomeID.getID().toLowerCase(Locale.ROOT); - } -} diff --git a/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSBiomeProvider.java b/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSBiomeProvider.java deleted file mode 100644 index ee7a054434..0000000000 --- a/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSBiomeProvider.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.dfsek.terra.bukkit.nms.v1_19_R1; - -import com.mojang.serialization.Codec; -import net.minecraft.core.Holder; -import net.minecraft.core.Registry; -import net.minecraft.world.level.biome.Biome; -import net.minecraft.world.level.biome.BiomeSource; -import net.minecraft.world.level.biome.Climate.Sampler; -import org.jetbrains.annotations.NotNull; - -import com.dfsek.terra.api.world.biome.generation.BiomeProvider; -import com.dfsek.terra.bukkit.world.BukkitPlatformBiome; - - -public class NMSBiomeProvider extends BiomeSource { - private final BiomeProvider delegate; - private final long seed; - private final Registry biomeRegistry = Registries.biomeRegistry(); - - public NMSBiomeProvider(BiomeProvider delegate, long seed) { - super(delegate.stream() - .map(biome -> Registries.biomeRegistry() - .getHolderOrThrow(((BukkitPlatformBiome) biome.getPlatformBiome()).getContext() - .get(NMSBiomeInfo.class) - .biomeKey()))); - this.delegate = delegate; - this.seed = seed; - } - - @Override - protected @NotNull Codec codec() { - return BiomeSource.CODEC; - } - - @Override - public @NotNull Holder getNoiseBiome(int x, int y, int z, @NotNull Sampler sampler) { - return biomeRegistry.getHolderOrThrow(((BukkitPlatformBiome) delegate.getBiome(x << 2, y << 2, z << 2, seed) - .getPlatformBiome()).getContext() - .get(NMSBiomeInfo.class) - .biomeKey()); - } -} diff --git a/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSChunkGeneratorDelegate.java b/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSChunkGeneratorDelegate.java deleted file mode 100644 index 6e374ff8b4..0000000000 --- a/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSChunkGeneratorDelegate.java +++ /dev/null @@ -1,291 +0,0 @@ -package com.dfsek.terra.bukkit.nms.v1_19_R1; - -import com.mojang.datafixers.util.Pair; -import com.mojang.serialization.Codec; -import it.unimi.dsi.fastutil.objects.Object2ObjectArrayMap; -import net.minecraft.core.BlockPos; -import net.minecraft.core.Holder; -import net.minecraft.core.HolderSet; -import net.minecraft.core.SectionPos; -import net.minecraft.server.level.WorldGenRegion; -import net.minecraft.util.RandomSource; -import net.minecraft.world.level.ChunkPos; -import net.minecraft.world.level.LevelAccessor; -import net.minecraft.world.level.LevelHeightAccessor; -import net.minecraft.world.level.NoiseColumn; -import net.minecraft.world.level.StructureManager; -import net.minecraft.world.level.WorldGenLevel; -import net.minecraft.world.level.biome.Biome; -import net.minecraft.world.level.biome.BiomeManager; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.chunk.ChunkAccess; -import net.minecraft.world.level.chunk.ChunkGenerator; -import net.minecraft.world.level.levelgen.Beardifier; -import net.minecraft.world.level.levelgen.DensityFunction.SinglePointContext; -import net.minecraft.world.level.levelgen.GenerationStep.Carving; -import net.minecraft.world.level.levelgen.Heightmap.Types; -import net.minecraft.world.level.levelgen.RandomState; -import net.minecraft.world.level.levelgen.blending.Blender; -import net.minecraft.world.level.levelgen.structure.Structure; -import net.minecraft.world.level.levelgen.structure.StructureSet; -import net.minecraft.world.level.levelgen.structure.StructureSet.StructureSelectionEntry; -import net.minecraft.world.level.levelgen.structure.placement.ConcentricRingsStructurePlacement; -import org.bukkit.craftbukkit.v1_19_R1.block.data.CraftBlockData; -import org.jetbrains.annotations.NotNull; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.Executor; -import java.util.stream.Stream; - -import com.dfsek.terra.api.config.ConfigPack; -import com.dfsek.terra.api.util.MathUtil; -import com.dfsek.terra.api.util.generic.Lazy; -import com.dfsek.terra.api.world.biome.generation.BiomeProvider; -import com.dfsek.terra.api.world.info.WorldProperties; -import com.dfsek.terra.bukkit.config.PreLoadCompatibilityOptions; -import com.dfsek.terra.bukkit.world.BukkitWorldProperties; -import com.dfsek.terra.bukkit.world.block.data.BukkitBlockState; - - -public class NMSChunkGeneratorDelegate extends ChunkGenerator { - private static final Logger LOGGER = LoggerFactory.getLogger(NMSChunkGeneratorDelegate.class); - private final com.dfsek.terra.api.world.chunk.generation.ChunkGenerator delegate; - - private final ChunkGenerator vanilla; - private final ConfigPack pack; - - private final long seed; - private final Map>> ringPositions = new Object2ObjectArrayMap<>(); - private volatile boolean rings = false; - - public NMSChunkGeneratorDelegate(ChunkGenerator vanilla, ConfigPack pack, NMSBiomeProvider biomeProvider, long seed) { - super(Registries.structureSet(), Optional.empty(), biomeProvider); - this.delegate = pack.getGeneratorProvider().newInstance(pack); - this.vanilla = vanilla; - this.pack = pack; - this.seed = seed; - } - - @Override - protected @NotNull Codec codec() { - return ChunkGenerator.CODEC; - } - - @Override - public void applyCarvers(@NotNull WorldGenRegion chunkRegion, long seed, @NotNull RandomState noiseConfig, @NotNull BiomeManager world, - @NotNull StructureManager structureAccessor, @NotNull ChunkAccess chunk, @NotNull Carving carverStep) { - // no-op - } - - @Override - public void buildSurface(@NotNull WorldGenRegion region, @NotNull StructureManager structures, @NotNull RandomState noiseConfig, - @NotNull ChunkAccess chunk) { - // no-op - } - - @Override - public void applyBiomeDecoration(@NotNull WorldGenLevel world, @NotNull ChunkAccess chunk, - @NotNull StructureManager structureAccessor) { - vanilla.applyBiomeDecoration(world, chunk, structureAccessor); - } - - @Override - public void spawnOriginalMobs(@NotNull WorldGenRegion region) { - vanilla.spawnOriginalMobs(region); - } - - @Override - public int getGenDepth() { - return vanilla.getGenDepth(); - } - - @Override - public @NotNull CompletableFuture fillFromNoise(@NotNull Executor executor, @NotNull Blender blender, - @NotNull RandomState noiseConfig, - @NotNull StructureManager structureAccessor, @NotNull ChunkAccess chunk) { - return vanilla.fillFromNoise(executor, blender, noiseConfig, structureAccessor, chunk) - .thenApply(c -> { - LevelAccessor level = Reflection.STRUCTURE_MANAGER.getLevel(structureAccessor); - BiomeProvider biomeProvider = pack.getBiomeProvider(); - PreLoadCompatibilityOptions compatibilityOptions = pack.getContext().get(PreLoadCompatibilityOptions.class); - if(compatibilityOptions.isBeard()) { - beard(structureAccessor, chunk, new BukkitWorldProperties(level.getMinecraftWorld().getWorld()), - biomeProvider, compatibilityOptions); - } - return c; - }); - } - - private void beard(StructureManager structureAccessor, ChunkAccess chunk, WorldProperties world, BiomeProvider biomeProvider, - PreLoadCompatibilityOptions compatibilityOptions) { - Beardifier structureWeightSampler = Beardifier.forStructuresInChunk(structureAccessor, chunk.getPos()); - double threshold = compatibilityOptions.getBeardThreshold(); - double airThreshold = compatibilityOptions.getAirThreshold(); - int xi = chunk.getPos().x << 4; - int zi = chunk.getPos().z << 4; - for(int x = 0; x < 16; x++) { - for(int z = 0; z < 16; z++) { - int depth = 0; - for(int y = world.getMaxHeight(); y >= world.getMinHeight(); y--) { - double noise = structureWeightSampler.compute(new SinglePointContext(x + xi, y, z + zi)); - if(noise > threshold) { - chunk.setBlockState(new BlockPos(x, y, z), ((CraftBlockData) ((BukkitBlockState) delegate - .getPalette(x + xi, y, z + zi, world, biomeProvider) - .get(depth, x + xi, y, z + zi, world.getSeed())).getHandle()).getState(), false); - depth++; - } else if(noise < airThreshold) { - chunk.setBlockState(new BlockPos(x, y, z), Blocks.AIR.defaultBlockState(), false); - } else { - depth = 0; - } - } - } - } - } - - @Override - public int getSeaLevel() { - return vanilla.getSeaLevel(); - } - - @Override - public int getMinY() { - return vanilla.getMinY(); - } - - @Override - public int getBaseHeight(int x, int z, @NotNull Types heightmap, @NotNull LevelHeightAccessor world, @NotNull RandomState noiseConfig) { - WorldProperties properties = new NMSWorldProperties(seed, world); - int y = properties.getMaxHeight(); - BiomeProvider biomeProvider = pack.getBiomeProvider(); - while(y >= getMinY() && !heightmap.isOpaque().test( - ((CraftBlockData) delegate.getBlock(properties, x, y - 1, z, biomeProvider).getHandle()).getState())) { - y--; - } - return y; - } - - @Override - public @NotNull NoiseColumn getBaseColumn(int x, int z, @NotNull LevelHeightAccessor world, @NotNull RandomState noiseConfig) { - /* - BlockState[] array = new BlockState[world.getHeight()]; - WorldProperties properties = new NMSWorldProperties(seed, world); - BiomeProvider biomeProvider = pack.getBiomeProvider().caching(properties); - for(int y = properties.getMaxHeight() - 1; y >= properties.getMinHeight(); y--) { - array[y - properties.getMinHeight()] = ((CraftBlockData) delegate.getBlock(properties, x, y, z, biomeProvider) - .getHandle()).getState(); - } - return new NoiseColumn(getMinY(), array); - - */ - return vanilla.getBaseColumn(x, z, world, noiseConfig); - } - - @Override - public void addDebugScreenInfo(@NotNull List text, @NotNull RandomState noiseConfig, @NotNull BlockPos pos) { - - } - - @Override - public void ensureStructuresGenerated(@NotNull RandomState noiseConfig) { - if(!this.rings) { - super.ensureStructuresGenerated(noiseConfig); - this.populateStrongholdData(noiseConfig); - this.rings = true; - } - - } - - @Override - public List getRingPositionsFor(@NotNull ConcentricRingsStructurePlacement structurePlacement, - @NotNull RandomState noiseConfig) { - ensureStructuresGenerated(noiseConfig); - return ringPositions.get(structurePlacement).value(); - } - - private void populateStrongholdData(RandomState noiseConfig) { - LOGGER.info("Generating safe stronghold data. This may take up to a minute."); - Set> set = this.biomeSource.possibleBiomes(); - possibleStructureSets().map(Holder::value).forEach((holder) -> { - boolean match = false; - for(StructureSelectionEntry structureset_a : holder.structures()) { - Structure structure = structureset_a.structure().value(); - Stream> stream = structure.biomes().stream(); - if(stream.anyMatch(set::contains)) { - match = true; - } - } - - if(match) { - if(holder.placement() instanceof ConcentricRingsStructurePlacement concentricringsstructureplacement) { - this.ringPositions.put(concentricringsstructureplacement, Lazy.lazy( - () -> this.generateRingPositions(holder, noiseConfig, concentricringsstructureplacement))); - } - } - }); - } - - private List generateRingPositions(StructureSet holder, RandomState randomstate, - ConcentricRingsStructurePlacement concentricringsstructureplacement) { // Spigot - if(concentricringsstructureplacement.count() == 0) { - return List.of(); - } - - List list = new ArrayList<>(); - int i = concentricringsstructureplacement.distance(); - int j = concentricringsstructureplacement.count(); - int k = concentricringsstructureplacement.spread(); - HolderSet holderset = concentricringsstructureplacement.preferredBiomes(); - RandomSource randomsource = RandomSource.create(); - - if(this.conf.strongholdSeed != null && this.structureSets.getResourceKey(holder).orElse(null) == - net.minecraft.world.level.levelgen.structure.BuiltinStructureSets.STRONGHOLDS) { - randomsource.setSeed(this.conf.strongholdSeed); - } else { - randomsource.setSeed(randomstate.legacyLevelSeed()); - } - double d0 = randomsource.nextDouble() * 3.141592653589793D * 2.0D; - int l = 0; - int i1 = 0; - - for(int j1 = 0; j1 < j; ++j1) { - double d1 = (double) (4 * i + i * i1 * 6) + (randomsource.nextDouble() - 0.5D) * (double) i * 2.5D; - int k1 = (int) Math.round(MathUtil.cos(d0) * d1); - int l1 = (int) Math.round(MathUtil.sin(d0) * d1); - int i2 = SectionPos.sectionToBlockCoord(k1, 8); - int j2 = SectionPos.sectionToBlockCoord(l1, 8); - - Objects.requireNonNull(holderset); - Pair> pair = this.biomeSource.findBiomeHorizontal(i2, 0, j2, 112, holderset::contains, randomsource, - randomstate.sampler()); - - if(pair != null) { - BlockPos blockposition = pair.getFirst(); - - k1 = SectionPos.blockToSectionCoord(blockposition.getX()); - l1 = SectionPos.blockToSectionCoord(blockposition.getZ()); - } - - list.add(new ChunkPos(k1, l1)); - d0 += 6.283185307179586D / (double) k; - ++l; - if(l == k) { - ++i1; - l = 0; - k += 2 * k / (i1 + 1); - k = Math.min(k, j - j1); - d0 += randomsource.nextDouble() * 3.141592653589793D * 2.0D; - } - } - - return list; - } -} diff --git a/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSInjectListener.java b/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSInjectListener.java deleted file mode 100644 index 0f11f700d2..0000000000 --- a/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSInjectListener.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.dfsek.terra.bukkit.nms.v1_19_R1; - -import net.minecraft.server.level.ServerLevel; -import net.minecraft.world.level.chunk.ChunkGenerator; -import org.bukkit.World; -import org.bukkit.craftbukkit.v1_19_R1.CraftWorld; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.world.WorldInitEvent; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.HashSet; -import java.util.Set; -import java.util.concurrent.locks.ReentrantLock; - -import com.dfsek.terra.api.config.ConfigPack; -import com.dfsek.terra.bukkit.generator.BukkitChunkGeneratorWrapper; - - -public class NMSInjectListener implements Listener { - private static final Logger LOGGER = LoggerFactory.getLogger(NMSInjectListener.class); - private static final Set INJECTED = new HashSet<>(); - private static final ReentrantLock INJECT_LOCK = new ReentrantLock(); - - @EventHandler - public void onWorldInit(WorldInitEvent event) { - if(!INJECTED.contains(event.getWorld()) && - event.getWorld().getGenerator() instanceof BukkitChunkGeneratorWrapper bukkitChunkGeneratorWrapper) { - INJECT_LOCK.lock(); - INJECTED.add(event.getWorld()); - LOGGER.info("Preparing to take over the world: {}", event.getWorld().getName()); - CraftWorld craftWorld = (CraftWorld) event.getWorld(); - ServerLevel serverWorld = craftWorld.getHandle(); - - ConfigPack pack = bukkitChunkGeneratorWrapper.getPack(); - - ChunkGenerator vanilla = serverWorld.getChunkSource().getGenerator(); - NMSBiomeProvider provider = new NMSBiomeProvider(pack.getBiomeProvider(), craftWorld.getSeed()); - NMSChunkGeneratorDelegate custom = new NMSChunkGeneratorDelegate(vanilla, pack, provider, craftWorld.getSeed()); - - custom.conf = vanilla.conf; // world config from Spigot - - serverWorld.getChunkSource().chunkMap.generator = custom; - - LOGGER.info("Successfully injected into world."); - - INJECT_LOCK.unlock(); - } - } -} diff --git a/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/Reflection.java b/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/Reflection.java deleted file mode 100644 index 84263a6677..0000000000 --- a/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/Reflection.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.dfsek.terra.bukkit.nms.v1_19_R1; - -import net.minecraft.core.MappedRegistry; -import net.minecraft.world.level.LevelAccessor; -import net.minecraft.world.level.StructureManager; -import xyz.jpenilla.reflectionremapper.ReflectionRemapper; -import xyz.jpenilla.reflectionremapper.proxy.ReflectionProxyFactory; -import xyz.jpenilla.reflectionremapper.proxy.annotation.FieldGetter; -import xyz.jpenilla.reflectionremapper.proxy.annotation.FieldSetter; -import xyz.jpenilla.reflectionremapper.proxy.annotation.Proxies; - - -public class Reflection { - public static final MappedRegistryProxy MAPPED_REGISTRY; - public static final StructureManagerProxy STRUCTURE_MANAGER; - - static { - ReflectionRemapper reflectionRemapper = ReflectionRemapper.forReobfMappingsInPaperJar(); - ReflectionProxyFactory reflectionProxyFactory = ReflectionProxyFactory.create(reflectionRemapper, - Reflection.class.getClassLoader()); - - MAPPED_REGISTRY = reflectionProxyFactory.reflectionProxy(MappedRegistryProxy.class); - STRUCTURE_MANAGER = reflectionProxyFactory.reflectionProxy(StructureManagerProxy.class); - } - - - @Proxies(MappedRegistry.class) - public interface MappedRegistryProxy { - @FieldSetter("frozen") - void setFrozen(MappedRegistry instance, boolean frozen); - } - - - @Proxies(StructureManager.class) - public interface StructureManagerProxy { - @FieldGetter("level") - LevelAccessor getLevel(StructureManager instance); - } -} diff --git a/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/Registries.java b/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/Registries.java deleted file mode 100644 index 1ff9641062..0000000000 --- a/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/Registries.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.dfsek.terra.bukkit.nms.v1_19_R1; - -import net.minecraft.core.Registry; -import net.minecraft.resources.ResourceKey; -import net.minecraft.server.dedicated.DedicatedServer; -import net.minecraft.world.level.biome.Biome; -import net.minecraft.world.level.levelgen.structure.StructureSet; -import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_19_R1.CraftServer; - - -public class Registries { - private static Registry getRegistry(ResourceKey> key) { - CraftServer craftserver = (CraftServer) Bukkit.getServer(); - DedicatedServer dedicatedserver = craftserver.getServer(); - return dedicatedserver - .registryAccess() - .registryOrThrow( // getRegistry - key - ); - } - - public static Registry biomeRegistry() { - return getRegistry(Registry.BIOME_REGISTRY); - } - - public static Registry structureSet() { - return getRegistry(Registry.STRUCTURE_SET_REGISTRY); - } -} diff --git a/platforms/bukkit/nms/v1_19_R2/build.gradle.kts b/platforms/bukkit/nms/v1_19_R2/build.gradle.kts deleted file mode 100644 index c6f6d82059..0000000000 --- a/platforms/bukkit/nms/v1_19_R2/build.gradle.kts +++ /dev/null @@ -1,17 +0,0 @@ -apply(plugin = "io.papermc.paperweight.userdev") - -repositories { - maven("https://s01.oss.sonatype.org/content/repositories/snapshots/") -} - -dependencies { - api(project(":platforms:bukkit:common")) - paperDevBundle("1.19.3-R0.1-SNAPSHOT") - implementation("xyz.jpenilla", "reflection-remapper", Versions.Bukkit.reflectionRemapper) -} - -tasks { - assemble { - dependsOn("reobfJar") - } -} \ No newline at end of file diff --git a/platforms/bukkit/nms/v1_19_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R2/AwfulBukkitHacks.java b/platforms/bukkit/nms/v1_19_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R2/AwfulBukkitHacks.java deleted file mode 100644 index 725f2fb1a1..0000000000 --- a/platforms/bukkit/nms/v1_19_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R2/AwfulBukkitHacks.java +++ /dev/null @@ -1,100 +0,0 @@ -package com.dfsek.terra.bukkit.nms.v1_19_R2; - -import com.google.common.collect.ImmutableMap; -import com.mojang.serialization.Lifecycle; -import net.minecraft.core.Holder; -import net.minecraft.core.Holder.Reference; -import net.minecraft.core.MappedRegistry; -import net.minecraft.core.WritableRegistry; -import net.minecraft.core.registries.Registries; -import net.minecraft.resources.ResourceKey; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.tags.TagKey; -import net.minecraft.world.level.biome.Biome; -import org.bukkit.NamespacedKey; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -import com.dfsek.terra.bukkit.world.BukkitPlatformBiome; -import com.dfsek.terra.registry.master.ConfigRegistry; - - -public class AwfulBukkitHacks { - private static final Logger LOGGER = LoggerFactory.getLogger(AwfulBukkitHacks.class); - - private static final Map> terraBiomeMap = new HashMap<>(); - - public static void registerBiomes(ConfigRegistry configRegistry) { - try { - LOGGER.info("Hacking biome registry..."); - WritableRegistry biomeRegistry = (WritableRegistry) RegistryFetcher.biomeRegistry(); - - Reflection.MAPPED_REGISTRY.setFrozen((MappedRegistry) biomeRegistry, false); - - configRegistry.forEach(pack -> pack.getRegistry(com.dfsek.terra.api.world.biome.Biome.class).forEach((key, biome) -> { - try { - BukkitPlatformBiome platformBiome = (BukkitPlatformBiome) biome.getPlatformBiome(); - NamespacedKey vanillaBukkitKey = platformBiome.getHandle().getKey(); - ResourceLocation vanillaMinecraftKey = new ResourceLocation(vanillaBukkitKey.getNamespace(), vanillaBukkitKey.getKey()); - Biome platform = NMSBiomeInjector.createBiome(biome, Objects.requireNonNull(biomeRegistry.get(vanillaMinecraftKey))); - - ResourceKey delegateKey = ResourceKey.create( - Registries.BIOME, - new ResourceLocation("terra", NMSBiomeInjector.createBiomeID(pack, key)) - ); - - Reference holder = biomeRegistry.register(delegateKey, platform, Lifecycle.stable()); - Reflection.REFERENCE.invokeBindValue(holder, platform); // IMPORTANT: bind holder. - - platformBiome.getContext().put(new NMSBiomeInfo(delegateKey)); - - terraBiomeMap.computeIfAbsent(vanillaMinecraftKey, i -> new ArrayList<>()).add(delegateKey.location()); - - LOGGER.debug("Registered biome: " + delegateKey); - } catch(NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) { - throw new RuntimeException(e); - } - })); - - Reflection.MAPPED_REGISTRY.setFrozen((MappedRegistry) biomeRegistry, true); // freeze registry again :) - - LOGGER.info("Doing tag garbage...."); - Map, List>> collect = biomeRegistry - .getTags() // streamKeysAndEntries - .collect(HashMap::new, - (map, pair) -> - map.put(pair.getFirst(), new ArrayList<>(pair.getSecond().stream().toList())), - HashMap::putAll); - - terraBiomeMap - .forEach((vb, terraBiomes) -> - NMSBiomeInjector.getEntry(biomeRegistry, vb).ifPresentOrElse( - vanilla -> terraBiomes.forEach( - tb -> NMSBiomeInjector.getEntry(biomeRegistry, tb).ifPresentOrElse( - terra -> { - LOGGER.debug("{} (vanilla for {}): {}", - vanilla.unwrapKey().orElseThrow().location(), - terra.unwrapKey().orElseThrow().location(), - vanilla.tags().toList()); - vanilla.tags() - .forEach(tag -> collect - .computeIfAbsent(tag, t -> new ArrayList<>()) - .add(terra)); - }, - () -> LOGGER.error("No such biome: {}", tb))), - () -> LOGGER.error("No vanilla biome: {}", vb))); - - biomeRegistry.resetTags(); - biomeRegistry.bindTags(ImmutableMap.copyOf(collect)); - - } catch(SecurityException | IllegalArgumentException exception) { - throw new RuntimeException(exception); - } - } -} diff --git a/platforms/bukkit/nms/v1_19_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R2/NMSBiomeInfo.java b/platforms/bukkit/nms/v1_19_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R2/NMSBiomeInfo.java deleted file mode 100644 index 639c9eaedd..0000000000 --- a/platforms/bukkit/nms/v1_19_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R2/NMSBiomeInfo.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.dfsek.terra.bukkit.nms.v1_19_R2; - -import net.minecraft.resources.ResourceKey; -import net.minecraft.world.level.biome.Biome; - -import com.dfsek.terra.api.properties.Properties; - - -public record NMSBiomeInfo(ResourceKey biomeKey) implements Properties { -} diff --git a/platforms/bukkit/nms/v1_19_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R2/NMSBiomeInjector.java b/platforms/bukkit/nms/v1_19_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R2/NMSBiomeInjector.java deleted file mode 100644 index 0b8c36a502..0000000000 --- a/platforms/bukkit/nms/v1_19_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R2/NMSBiomeInjector.java +++ /dev/null @@ -1,79 +0,0 @@ -package com.dfsek.terra.bukkit.nms.v1_19_R2; - -import net.minecraft.core.Holder; -import net.minecraft.core.Registry; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.level.biome.Biome; -import net.minecraft.world.level.biome.BiomeSpecialEffects; - -import java.util.Locale; -import java.util.Objects; -import java.util.Optional; - -import com.dfsek.terra.api.config.ConfigPack; -import com.dfsek.terra.bukkit.config.VanillaBiomeProperties; - - -public class NMSBiomeInjector { - - public static Optional> getEntry(Registry registry, ResourceLocation identifier) { - return registry.getOptional(identifier) - .flatMap(registry::getResourceKey) - .flatMap(registry::getHolder); - } - - public static Biome createBiome(com.dfsek.terra.api.world.biome.Biome biome, Biome vanilla) - throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { - Biome.BiomeBuilder builder = new Biome.BiomeBuilder(); - - builder - .precipitation(vanilla.getPrecipitation()) - .downfall(vanilla.getDownfall()) - .temperature(vanilla.getBaseTemperature()) - .mobSpawnSettings(vanilla.getMobSettings()) - .generationSettings(vanilla.getGenerationSettings()); - - - BiomeSpecialEffects.Builder effects = new BiomeSpecialEffects.Builder(); - - effects.grassColorModifier(vanilla.getSpecialEffects().getGrassColorModifier()); - - VanillaBiomeProperties vanillaBiomeProperties = biome.getContext().get(VanillaBiomeProperties.class); - - effects.fogColor(Objects.requireNonNullElse(vanillaBiomeProperties.getFogColor(), vanilla.getFogColor())) - - .waterColor(Objects.requireNonNullElse(vanillaBiomeProperties.getWaterColor(), vanilla.getWaterColor())) - - .waterFogColor(Objects.requireNonNullElse(vanillaBiomeProperties.getWaterFogColor(), vanilla.getWaterFogColor())) - - .skyColor(Objects.requireNonNullElse(vanillaBiomeProperties.getSkyColor(), vanilla.getSkyColor())); - - if(vanillaBiomeProperties.getFoliageColor() == null) { - vanilla.getSpecialEffects().getFoliageColorOverride().ifPresent(effects::foliageColorOverride); - } else { - effects.foliageColorOverride(vanillaBiomeProperties.getFoliageColor()); - } - - if(vanillaBiomeProperties.getGrassColor() == null) { - vanilla.getSpecialEffects().getGrassColorOverride().ifPresent(effects::grassColorOverride); - } else { - // grass - effects.grassColorOverride(vanillaBiomeProperties.getGrassColor()); - } - - vanilla.getAmbientLoop().ifPresent(effects::ambientLoopSound); - vanilla.getAmbientAdditions().ifPresent(effects::ambientAdditionsSound); - vanilla.getAmbientMood().ifPresent(effects::ambientMoodSound); - vanilla.getBackgroundMusic().ifPresent(effects::backgroundMusic); - vanilla.getAmbientParticle().ifPresent(effects::ambientParticle); - - builder.specialEffects(effects.build()); - - return builder.build(); - } - - public static String createBiomeID(ConfigPack pack, com.dfsek.terra.api.registry.key.RegistryKey biomeID) { - return pack.getID() - .toLowerCase() + "/" + biomeID.getNamespace().toLowerCase(Locale.ROOT) + "/" + biomeID.getID().toLowerCase(Locale.ROOT); - } -} diff --git a/platforms/bukkit/nms/v1_19_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R2/NMSBiomeProvider.java b/platforms/bukkit/nms/v1_19_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R2/NMSBiomeProvider.java deleted file mode 100644 index 4e4b9f1c5d..0000000000 --- a/platforms/bukkit/nms/v1_19_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R2/NMSBiomeProvider.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.dfsek.terra.bukkit.nms.v1_19_R2; - -import com.mojang.serialization.Codec; -import net.minecraft.core.Holder; -import net.minecraft.core.Registry; -import net.minecraft.world.level.biome.Biome; -import net.minecraft.world.level.biome.BiomeSource; -import net.minecraft.world.level.biome.Climate.Sampler; -import org.jetbrains.annotations.NotNull; - -import com.dfsek.terra.api.world.biome.generation.BiomeProvider; -import com.dfsek.terra.bukkit.world.BukkitPlatformBiome; - - -public class NMSBiomeProvider extends BiomeSource { - private final BiomeProvider delegate; - private final long seed; - private final Registry biomeRegistry = RegistryFetcher.biomeRegistry(); - - public NMSBiomeProvider(BiomeProvider delegate, long seed) { - super(delegate.stream() - .map(biome -> RegistryFetcher.biomeRegistry() - .getHolderOrThrow(((BukkitPlatformBiome) biome.getPlatformBiome()).getContext() - .get(NMSBiomeInfo.class) - .biomeKey()))); - this.delegate = delegate; - this.seed = seed; - } - - @Override - protected @NotNull Codec codec() { - return BiomeSource.CODEC; - } - - @Override - public @NotNull Holder getNoiseBiome(int x, int y, int z, @NotNull Sampler sampler) { - return biomeRegistry.getHolderOrThrow(((BukkitPlatformBiome) delegate.getBiome(x << 2, y << 2, z << 2, seed) - .getPlatformBiome()).getContext() - .get(NMSBiomeInfo.class) - .biomeKey()); - } -} diff --git a/platforms/bukkit/nms/v1_19_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R2/NMSChunkGeneratorDelegate.java b/platforms/bukkit/nms/v1_19_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R2/NMSChunkGeneratorDelegate.java deleted file mode 100644 index 9059326cae..0000000000 --- a/platforms/bukkit/nms/v1_19_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R2/NMSChunkGeneratorDelegate.java +++ /dev/null @@ -1,174 +0,0 @@ -package com.dfsek.terra.bukkit.nms.v1_19_R2; - -import com.mojang.serialization.Codec; -import net.minecraft.core.BlockPos; -import net.minecraft.server.level.WorldGenRegion; -import net.minecraft.world.level.LevelAccessor; -import net.minecraft.world.level.LevelHeightAccessor; -import net.minecraft.world.level.NoiseColumn; -import net.minecraft.world.level.StructureManager; -import net.minecraft.world.level.WorldGenLevel; -import net.minecraft.world.level.biome.BiomeManager; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.chunk.ChunkAccess; -import net.minecraft.world.level.chunk.ChunkGenerator; -import net.minecraft.world.level.levelgen.Beardifier; -import net.minecraft.world.level.levelgen.DensityFunction.SinglePointContext; -import net.minecraft.world.level.levelgen.GenerationStep.Carving; -import net.minecraft.world.level.levelgen.Heightmap.Types; -import net.minecraft.world.level.levelgen.RandomState; -import net.minecraft.world.level.levelgen.blending.Blender; -import org.bukkit.craftbukkit.v1_19_R2.block.data.CraftBlockData; -import org.jetbrains.annotations.NotNull; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.List; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.Executor; - -import com.dfsek.terra.api.config.ConfigPack; -import com.dfsek.terra.api.world.biome.generation.BiomeProvider; -import com.dfsek.terra.api.world.info.WorldProperties; -import com.dfsek.terra.bukkit.config.PreLoadCompatibilityOptions; -import com.dfsek.terra.bukkit.world.BukkitWorldProperties; -import com.dfsek.terra.bukkit.world.block.data.BukkitBlockState; - - -public class NMSChunkGeneratorDelegate extends ChunkGenerator { - private static final Logger LOGGER = LoggerFactory.getLogger(NMSChunkGeneratorDelegate.class); - private final com.dfsek.terra.api.world.chunk.generation.ChunkGenerator delegate; - - private final ChunkGenerator vanilla; - private final ConfigPack pack; - - private final long seed; - - public NMSChunkGeneratorDelegate(ChunkGenerator vanilla, ConfigPack pack, NMSBiomeProvider biomeProvider, long seed) { - super(biomeProvider); - this.delegate = pack.getGeneratorProvider().newInstance(pack); - this.vanilla = vanilla; - this.pack = pack; - this.seed = seed; - } - - @Override - protected @NotNull Codec codec() { - return ChunkGenerator.CODEC; - } - - @Override - public void applyCarvers(@NotNull WorldGenRegion chunkRegion, long seed, @NotNull RandomState noiseConfig, @NotNull BiomeManager world, - @NotNull StructureManager structureAccessor, @NotNull ChunkAccess chunk, @NotNull Carving carverStep) { - // no-op - } - - @Override - public void buildSurface(@NotNull WorldGenRegion region, @NotNull StructureManager structures, @NotNull RandomState noiseConfig, - @NotNull ChunkAccess chunk) { - // no-op - } - - @Override - public void applyBiomeDecoration(@NotNull WorldGenLevel world, @NotNull ChunkAccess chunk, - @NotNull StructureManager structureAccessor) { - vanilla.applyBiomeDecoration(world, chunk, structureAccessor); - } - - @Override - public void spawnOriginalMobs(@NotNull WorldGenRegion region) { - vanilla.spawnOriginalMobs(region); - } - - @Override - public int getGenDepth() { - return vanilla.getGenDepth(); - } - - @Override - public @NotNull CompletableFuture fillFromNoise(@NotNull Executor executor, @NotNull Blender blender, - @NotNull RandomState noiseConfig, - @NotNull StructureManager structureAccessor, @NotNull ChunkAccess chunk) { - return vanilla.fillFromNoise(executor, blender, noiseConfig, structureAccessor, chunk) - .thenApply(c -> { - LevelAccessor level = Reflection.STRUCTURE_MANAGER.getLevel(structureAccessor); - BiomeProvider biomeProvider = pack.getBiomeProvider(); - PreLoadCompatibilityOptions compatibilityOptions = pack.getContext().get(PreLoadCompatibilityOptions.class); - if(compatibilityOptions.isBeard()) { - beard(structureAccessor, chunk, new BukkitWorldProperties(level.getMinecraftWorld().getWorld()), - biomeProvider, compatibilityOptions); - } - return c; - }); - } - - private void beard(StructureManager structureAccessor, ChunkAccess chunk, WorldProperties world, BiomeProvider biomeProvider, - PreLoadCompatibilityOptions compatibilityOptions) { - Beardifier structureWeightSampler = Beardifier.forStructuresInChunk(structureAccessor, chunk.getPos()); - double threshold = compatibilityOptions.getBeardThreshold(); - double airThreshold = compatibilityOptions.getAirThreshold(); - int xi = chunk.getPos().x << 4; - int zi = chunk.getPos().z << 4; - for(int x = 0; x < 16; x++) { - for(int z = 0; z < 16; z++) { - int depth = 0; - for(int y = world.getMaxHeight(); y >= world.getMinHeight(); y--) { - double noise = structureWeightSampler.compute(new SinglePointContext(x + xi, y, z + zi)); - if(noise > threshold) { - chunk.setBlockState(new BlockPos(x, y, z), ((CraftBlockData) ((BukkitBlockState) delegate - .getPalette(x + xi, y, z + zi, world, biomeProvider) - .get(depth, x + xi, y, z + zi, world.getSeed())).getHandle()).getState(), false); - depth++; - } else if(noise < airThreshold) { - chunk.setBlockState(new BlockPos(x, y, z), Blocks.AIR.defaultBlockState(), false); - } else { - depth = 0; - } - } - } - } - } - - @Override - public int getSeaLevel() { - return vanilla.getSeaLevel(); - } - - @Override - public int getMinY() { - return vanilla.getMinY(); - } - - @Override - public int getBaseHeight(int x, int z, @NotNull Types heightmap, @NotNull LevelHeightAccessor world, @NotNull RandomState noiseConfig) { - WorldProperties properties = new NMSWorldProperties(seed, world); - int y = properties.getMaxHeight(); - BiomeProvider biomeProvider = pack.getBiomeProvider(); - while(y >= getMinY() && !heightmap.isOpaque().test( - ((CraftBlockData) delegate.getBlock(properties, x, y - 1, z, biomeProvider).getHandle()).getState())) { - y--; - } - return y; - } - - @Override - public @NotNull NoiseColumn getBaseColumn(int x, int z, @NotNull LevelHeightAccessor world, @NotNull RandomState noiseConfig) { - /* - BlockState[] array = new BlockState[world.getHeight()]; - WorldProperties properties = new NMSWorldProperties(seed, world); - BiomeProvider biomeProvider = pack.getBiomeProvider().caching(properties); - for(int y = properties.getMaxHeight() - 1; y >= properties.getMinHeight(); y--) { - array[y - properties.getMinHeight()] = ((CraftBlockData) delegate.getBlock(properties, x, y, z, biomeProvider) - .getHandle()).getState(); - } - return new NoiseColumn(getMinY(), array); - - */ - return vanilla.getBaseColumn(x, z, world, noiseConfig); - } - - @Override - public void addDebugScreenInfo(@NotNull List text, @NotNull RandomState noiseConfig, @NotNull BlockPos pos) { - - } -} diff --git a/platforms/bukkit/nms/v1_19_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R2/NMSInitializer.java b/platforms/bukkit/nms/v1_19_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R2/NMSInitializer.java deleted file mode 100644 index 05814cfd4d..0000000000 --- a/platforms/bukkit/nms/v1_19_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R2/NMSInitializer.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.dfsek.terra.bukkit.nms.v1_19_R2; - -import org.bukkit.Bukkit; - -import com.dfsek.terra.bukkit.PlatformImpl; -import com.dfsek.terra.bukkit.nms.Initializer; - - -public class NMSInitializer implements Initializer { - @Override - public void initialize(PlatformImpl platform) { - AwfulBukkitHacks.registerBiomes(platform.getRawConfigRegistry()); - Bukkit.getPluginManager().registerEvents(new NMSInjectListener(), platform.getPlugin()); - } -} diff --git a/platforms/bukkit/nms/v1_19_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R2/NMSWorldProperties.java b/platforms/bukkit/nms/v1_19_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R2/NMSWorldProperties.java deleted file mode 100644 index 9e1989451a..0000000000 --- a/platforms/bukkit/nms/v1_19_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R2/NMSWorldProperties.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.dfsek.terra.bukkit.nms.v1_19_R2; - -import net.minecraft.world.level.LevelHeightAccessor; - -import com.dfsek.terra.api.world.info.WorldProperties; - - -public class NMSWorldProperties implements WorldProperties { - private final long seed; - private final LevelHeightAccessor height; - - public NMSWorldProperties(long seed, LevelHeightAccessor height) { - this.seed = seed; - this.height = height; - } - - @Override - public Object getHandle() { - return height; - } - - @Override - public long getSeed() { - return seed; - } - - @Override - public int getMaxHeight() { - return height.getMaxBuildHeight(); - } - - @Override - public int getMinHeight() { - return height.getMinBuildHeight(); - } -} diff --git a/platforms/bukkit/nms/v1_19_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R2/Reflection.java b/platforms/bukkit/nms/v1_19_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R2/Reflection.java deleted file mode 100644 index d0f9332583..0000000000 --- a/platforms/bukkit/nms/v1_19_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R2/Reflection.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.dfsek.terra.bukkit.nms.v1_19_R2; - -import net.minecraft.core.Holder; -import net.minecraft.core.Holder.Reference; -import net.minecraft.core.MappedRegistry; -import net.minecraft.world.level.LevelAccessor; -import net.minecraft.world.level.StructureManager; -import xyz.jpenilla.reflectionremapper.ReflectionRemapper; -import xyz.jpenilla.reflectionremapper.proxy.ReflectionProxyFactory; -import xyz.jpenilla.reflectionremapper.proxy.annotation.FieldGetter; -import xyz.jpenilla.reflectionremapper.proxy.annotation.FieldSetter; -import xyz.jpenilla.reflectionremapper.proxy.annotation.MethodName; -import xyz.jpenilla.reflectionremapper.proxy.annotation.Proxies; - - -public class Reflection { - public static final MappedRegistryProxy MAPPED_REGISTRY; - public static final StructureManagerProxy STRUCTURE_MANAGER; - - public static final ReferenceProxy REFERENCE; - - static { - ReflectionRemapper reflectionRemapper = ReflectionRemapper.forReobfMappingsInPaperJar(); - ReflectionProxyFactory reflectionProxyFactory = ReflectionProxyFactory.create(reflectionRemapper, - Reflection.class.getClassLoader()); - - MAPPED_REGISTRY = reflectionProxyFactory.reflectionProxy(MappedRegistryProxy.class); - STRUCTURE_MANAGER = reflectionProxyFactory.reflectionProxy(StructureManagerProxy.class); - REFERENCE = reflectionProxyFactory.reflectionProxy(ReferenceProxy.class); - } - - - @Proxies(MappedRegistry.class) - public interface MappedRegistryProxy { - @FieldSetter("frozen") - void setFrozen(MappedRegistry instance, boolean frozen); - } - - - @Proxies(StructureManager.class) - public interface StructureManagerProxy { - @FieldGetter("level") - LevelAccessor getLevel(StructureManager instance); - } - - - @Proxies(Holder.Reference.class) - public interface ReferenceProxy { - @MethodName("bindValue") - void invokeBindValue(Reference instance, T value); - } -} diff --git a/platforms/bukkit/nms/v1_19_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R2/RegistryFetcher.java b/platforms/bukkit/nms/v1_19_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R2/RegistryFetcher.java deleted file mode 100644 index ed353eafc1..0000000000 --- a/platforms/bukkit/nms/v1_19_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R2/RegistryFetcher.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.dfsek.terra.bukkit.nms.v1_19_R2; - -import net.minecraft.core.Registry; -import net.minecraft.core.registries.Registries; -import net.minecraft.resources.ResourceKey; -import net.minecraft.server.dedicated.DedicatedServer; -import net.minecraft.world.level.biome.Biome; -import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_19_R2.CraftServer; - - -public class RegistryFetcher { - private static Registry getRegistry(ResourceKey> key) { - CraftServer craftserver = (CraftServer) Bukkit.getServer(); - DedicatedServer dedicatedserver = craftserver.getServer(); - return dedicatedserver - .registryAccess() - .registryOrThrow(key); - } - - public static Registry biomeRegistry() { - return getRegistry(Registries.BIOME); - } -} diff --git a/platforms/bukkit/nms/v1_19_R3/build.gradle.kts b/platforms/bukkit/nms/v1_19_R3/build.gradle.kts deleted file mode 100644 index 4b2ad7d637..0000000000 --- a/platforms/bukkit/nms/v1_19_R3/build.gradle.kts +++ /dev/null @@ -1,17 +0,0 @@ -apply(plugin = "io.papermc.paperweight.userdev") - -repositories { - maven("https://s01.oss.sonatype.org/content/repositories/snapshots/") -} - -dependencies { - api(project(":platforms:bukkit:common")) - paperDevBundle("1.19.4-R0.1-SNAPSHOT") - implementation("xyz.jpenilla", "reflection-remapper", Versions.Bukkit.reflectionRemapper) -} - -tasks { - assemble { - dependsOn("reobfJar") - } -} \ No newline at end of file diff --git a/platforms/bukkit/nms/v1_19_R3/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R3/AwfulBukkitHacks.java b/platforms/bukkit/nms/v1_19_R3/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R3/AwfulBukkitHacks.java deleted file mode 100644 index b2ac9d28b2..0000000000 --- a/platforms/bukkit/nms/v1_19_R3/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R3/AwfulBukkitHacks.java +++ /dev/null @@ -1,101 +0,0 @@ -package com.dfsek.terra.bukkit.nms.v1_19_R3; - -import com.google.common.collect.ImmutableMap; -import com.mojang.serialization.Lifecycle; -import net.minecraft.core.Holder; -import net.minecraft.core.Holder.Reference; -import net.minecraft.core.MappedRegistry; -import net.minecraft.core.WritableRegistry; -import net.minecraft.core.registries.Registries; -import net.minecraft.resources.ResourceKey; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.tags.TagKey; -import net.minecraft.world.level.biome.Biome; -import org.bukkit.NamespacedKey; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -import com.dfsek.terra.bukkit.world.BukkitPlatformBiome; -import com.dfsek.terra.registry.master.ConfigRegistry; - - -public class AwfulBukkitHacks { - private static final Logger LOGGER = LoggerFactory.getLogger(AwfulBukkitHacks.class); - - private static final Map> terraBiomeMap = new HashMap<>(); - - public static void registerBiomes(ConfigRegistry configRegistry) { - try { - LOGGER.info("Hacking biome registry..."); - WritableRegistry biomeRegistry = (WritableRegistry) RegistryFetcher.biomeRegistry(); - - Reflection.MAPPED_REGISTRY.setFrozen((MappedRegistry) biomeRegistry, false); - - configRegistry.forEach(pack -> pack.getRegistry(com.dfsek.terra.api.world.biome.Biome.class).forEach((key, biome) -> { - try { - BukkitPlatformBiome platformBiome = (BukkitPlatformBiome) biome.getPlatformBiome(); - NamespacedKey vanillaBukkitKey = platformBiome.getHandle().getKey(); - ResourceLocation vanillaMinecraftKey = new ResourceLocation(vanillaBukkitKey.getNamespace(), vanillaBukkitKey.getKey()); - Biome platform = NMSBiomeInjector.createBiome(biome, Objects.requireNonNull(biomeRegistry.get(vanillaMinecraftKey))); - - ResourceKey delegateKey = ResourceKey.create( - Registries.BIOME, - new ResourceLocation("terra", NMSBiomeInjector.createBiomeID(pack, key)) - ); - - Reference holder = biomeRegistry.register(delegateKey, platform, Lifecycle.stable()); - Reflection.REFERENCE.invokeBindValue(holder, platform); // IMPORTANT: bind holder. - - platformBiome.getContext().put(new NMSBiomeInfo(delegateKey)); - - terraBiomeMap.computeIfAbsent(vanillaMinecraftKey, i -> new ArrayList<>()).add(delegateKey.location()); - - LOGGER.debug("Registered biome: " + delegateKey); - } catch(NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) { - throw new RuntimeException(e); - } - })); - - Reflection.MAPPED_REGISTRY.setFrozen((MappedRegistry) biomeRegistry, true); // freeze registry again :) - - LOGGER.info("Doing tag garbage...."); - Map, List>> collect = biomeRegistry - .getTags() // streamKeysAndEntries - .collect(HashMap::new, - (map, pair) -> - map.put(pair.getFirst(), new ArrayList<>(pair.getSecond().stream().toList())), - HashMap::putAll); - - terraBiomeMap - .forEach((vb, terraBiomes) -> - NMSBiomeInjector.getEntry(biomeRegistry, vb).ifPresentOrElse( - vanilla -> terraBiomes.forEach( - tb -> NMSBiomeInjector.getEntry(biomeRegistry, tb).ifPresentOrElse( - terra -> { - LOGGER.debug("{} (vanilla for {}): {}", - vanilla.unwrapKey().orElseThrow().location(), - terra.unwrapKey().orElseThrow().location(), - vanilla.tags().toList()); - vanilla.tags() - .forEach(tag -> collect - .computeIfAbsent(tag, t -> new ArrayList<>()) - .add(terra)); - }, - () -> LOGGER.error("No such biome: {}", tb))), - () -> LOGGER.error("No vanilla biome: {}", vb))); - - biomeRegistry.resetTags(); - biomeRegistry.bindTags(ImmutableMap.copyOf(collect)); - - } catch(SecurityException | IllegalArgumentException exception) { - throw new RuntimeException(exception); - } - } -} - diff --git a/platforms/bukkit/nms/v1_19_R3/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R3/NMSBiomeInfo.java b/platforms/bukkit/nms/v1_19_R3/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R3/NMSBiomeInfo.java deleted file mode 100644 index 816d96068d..0000000000 --- a/platforms/bukkit/nms/v1_19_R3/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R3/NMSBiomeInfo.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.dfsek.terra.bukkit.nms.v1_19_R3; - -import net.minecraft.resources.ResourceKey; -import net.minecraft.world.level.biome.Biome; - -import com.dfsek.terra.api.properties.Properties; - - -public record NMSBiomeInfo(ResourceKey biomeKey) implements Properties { -} diff --git a/platforms/bukkit/nms/v1_19_R3/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R3/NMSBiomeProvider.java b/platforms/bukkit/nms/v1_19_R3/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R3/NMSBiomeProvider.java deleted file mode 100644 index ed5ea15893..0000000000 --- a/platforms/bukkit/nms/v1_19_R3/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R3/NMSBiomeProvider.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.dfsek.terra.bukkit.nms.v1_19_R3; - -import com.mojang.serialization.Codec; -import net.minecraft.core.Holder; -import net.minecraft.core.Registry; -import net.minecraft.world.level.biome.Biome; -import net.minecraft.world.level.biome.BiomeSource; -import net.minecraft.world.level.biome.Climate.Sampler; -import org.jetbrains.annotations.NotNull; - -import java.util.stream.Stream; - -import com.dfsek.terra.api.world.biome.generation.BiomeProvider; -import com.dfsek.terra.bukkit.world.BukkitPlatformBiome; - - -public class NMSBiomeProvider extends BiomeSource { - private final BiomeProvider delegate; - private final long seed; - private final Registry biomeRegistry = RegistryFetcher.biomeRegistry(); - - public NMSBiomeProvider(BiomeProvider delegate, long seed) { - super(); - this.delegate = delegate; - this.seed = seed; - } - - @Override - protected Stream> collectPossibleBiomes() { - return delegate.stream() - .map(biome -> RegistryFetcher.biomeRegistry() - .getHolderOrThrow(((BukkitPlatformBiome) biome.getPlatformBiome()).getContext() - .get(NMSBiomeInfo.class) - .biomeKey())); - } - - @Override - protected @NotNull Codec codec() { - return BiomeSource.CODEC; - } - - @Override - public @NotNull Holder getNoiseBiome(int x, int y, int z, @NotNull Sampler sampler) { - return biomeRegistry.getHolderOrThrow(((BukkitPlatformBiome) delegate.getBiome(x << 2, y << 2, z << 2, seed) - .getPlatformBiome()).getContext() - .get(NMSBiomeInfo.class) - .biomeKey()); - } -} diff --git a/platforms/bukkit/nms/v1_19_R3/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R3/NMSChunkGeneratorDelegate.java b/platforms/bukkit/nms/v1_19_R3/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R3/NMSChunkGeneratorDelegate.java deleted file mode 100644 index c697bd0c19..0000000000 --- a/platforms/bukkit/nms/v1_19_R3/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R3/NMSChunkGeneratorDelegate.java +++ /dev/null @@ -1,171 +0,0 @@ -package com.dfsek.terra.bukkit.nms.v1_19_R3; - -import com.mojang.serialization.Codec; -import net.minecraft.core.BlockPos; -import net.minecraft.server.level.WorldGenRegion; -import net.minecraft.world.level.LevelAccessor; -import net.minecraft.world.level.LevelHeightAccessor; -import net.minecraft.world.level.NoiseColumn; -import net.minecraft.world.level.StructureManager; -import net.minecraft.world.level.WorldGenLevel; -import net.minecraft.world.level.biome.BiomeManager; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.chunk.ChunkAccess; -import net.minecraft.world.level.chunk.ChunkGenerator; -import net.minecraft.world.level.levelgen.Beardifier; -import net.minecraft.world.level.levelgen.DensityFunction.SinglePointContext; -import net.minecraft.world.level.levelgen.GenerationStep.Carving; -import net.minecraft.world.level.levelgen.Heightmap.Types; -import net.minecraft.world.level.levelgen.RandomState; -import net.minecraft.world.level.levelgen.blending.Blender; -import org.bukkit.craftbukkit.v1_19_R3.block.data.CraftBlockData; -import org.jetbrains.annotations.NotNull; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.List; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.Executor; - -import com.dfsek.terra.api.config.ConfigPack; -import com.dfsek.terra.api.world.biome.generation.BiomeProvider; -import com.dfsek.terra.api.world.info.WorldProperties; -import com.dfsek.terra.bukkit.config.PreLoadCompatibilityOptions; -import com.dfsek.terra.bukkit.world.BukkitWorldProperties; -import com.dfsek.terra.bukkit.world.block.data.BukkitBlockState; - - -public class NMSChunkGeneratorDelegate extends ChunkGenerator { - private static final Logger LOGGER = LoggerFactory.getLogger(NMSChunkGeneratorDelegate.class); - private final com.dfsek.terra.api.world.chunk.generation.ChunkGenerator delegate; - - private final ChunkGenerator vanilla; - private final ConfigPack pack; - - private final long seed; - - public NMSChunkGeneratorDelegate(ChunkGenerator vanilla, ConfigPack pack, NMSBiomeProvider biomeProvider, long seed) { - super(biomeProvider); - this.delegate = pack.getGeneratorProvider().newInstance(pack); - this.vanilla = vanilla; - this.pack = pack; - this.seed = seed; - } - - @Override - protected @NotNull Codec codec() { - return ChunkGenerator.CODEC; - } - - @Override - public void applyCarvers(@NotNull WorldGenRegion chunkRegion, long seed, @NotNull RandomState noiseConfig, @NotNull BiomeManager world, - @NotNull StructureManager structureAccessor, @NotNull ChunkAccess chunk, @NotNull Carving carverStep) { - // no-op - } - - @Override - public void buildSurface(@NotNull WorldGenRegion region, @NotNull StructureManager structures, @NotNull RandomState noiseConfig, - @NotNull ChunkAccess chunk) { - // no-op - } - - @Override - public void applyBiomeDecoration(@NotNull WorldGenLevel world, @NotNull ChunkAccess chunk, - @NotNull StructureManager structureAccessor) { - vanilla.applyBiomeDecoration(world, chunk, structureAccessor); - } - - @Override - public void spawnOriginalMobs(@NotNull WorldGenRegion region) { - vanilla.spawnOriginalMobs(region); - } - - @Override - public int getGenDepth() { - return vanilla.getGenDepth(); - } - - @Override - public @NotNull CompletableFuture fillFromNoise(@NotNull Executor executor, @NotNull Blender blender, - @NotNull RandomState noiseConfig, - @NotNull StructureManager structureAccessor, @NotNull ChunkAccess chunk) { - return vanilla.fillFromNoise(executor, blender, noiseConfig, structureAccessor, chunk) - .thenApply(c -> { - LevelAccessor level = Reflection.STRUCTURE_MANAGER.getLevel(structureAccessor); - BiomeProvider biomeProvider = pack.getBiomeProvider(); - PreLoadCompatibilityOptions compatibilityOptions = pack.getContext().get(PreLoadCompatibilityOptions.class); - if(compatibilityOptions.isBeard()) { - beard(structureAccessor, chunk, new BukkitWorldProperties(level.getMinecraftWorld().getWorld()), - biomeProvider, compatibilityOptions); - } - return c; - }); - } - - private void beard(StructureManager structureAccessor, ChunkAccess chunk, WorldProperties world, BiomeProvider biomeProvider, - PreLoadCompatibilityOptions compatibilityOptions) { - Beardifier structureWeightSampler = Beardifier.forStructuresInChunk(structureAccessor, chunk.getPos()); - double threshold = compatibilityOptions.getBeardThreshold(); - double airThreshold = compatibilityOptions.getAirThreshold(); - int xi = chunk.getPos().x << 4; - int zi = chunk.getPos().z << 4; - for(int x = 0; x < 16; x++) { - for(int z = 0; z < 16; z++) { - int depth = 0; - for(int y = world.getMaxHeight(); y >= world.getMinHeight(); y--) { - double noise = structureWeightSampler.compute(new SinglePointContext(x + xi, y, z + zi)); - if(noise > threshold) { - chunk.setBlockState(new BlockPos(x, y, z), ((CraftBlockData) ((BukkitBlockState) delegate - .getPalette(x + xi, y, z + zi, world, biomeProvider) - .get(depth, x + xi, y, z + zi, world.getSeed())).getHandle()).getState(), false); - depth++; - } else if(noise < airThreshold) { - chunk.setBlockState(new BlockPos(x, y, z), Blocks.AIR.defaultBlockState(), false); - } else { - depth = 0; - } - } - } - } - } - - @Override - public int getSeaLevel() { - return vanilla.getSeaLevel(); - } - - @Override - public int getMinY() { - return vanilla.getMinY(); - } - - @Override - public int getBaseHeight(int x, int z, @NotNull Types heightmap, @NotNull LevelHeightAccessor world, @NotNull RandomState noiseConfig) { - WorldProperties properties = new NMSWorldProperties(seed, world); - int y = properties.getMaxHeight(); - BiomeProvider biomeProvider = pack.getBiomeProvider(); - while(y >= getMinY() && !heightmap.isOpaque().test( - ((CraftBlockData) delegate.getBlock(properties, x, y - 1, z, biomeProvider).getHandle()).getState())) { - y--; - } - return y; - } - - @Override - public @NotNull NoiseColumn getBaseColumn(int x, int z, @NotNull LevelHeightAccessor world, @NotNull RandomState noiseConfig) { - BlockState[] array = new BlockState[world.getHeight()]; - WorldProperties properties = new NMSWorldProperties(seed, world); - BiomeProvider biomeProvider = pack.getBiomeProvider(); - for(int y = properties.getMaxHeight() - 1; y >= properties.getMinHeight(); y--) { - array[y - properties.getMinHeight()] = ((CraftBlockData) delegate.getBlock(properties, x, y, z, biomeProvider) - .getHandle()).getState(); - } - return new NoiseColumn(getMinY(), array); - } - - @Override - public void addDebugScreenInfo(@NotNull List text, @NotNull RandomState noiseConfig, @NotNull BlockPos pos) { - - } -} diff --git a/platforms/bukkit/nms/v1_19_R3/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R3/NMSInitializer.java b/platforms/bukkit/nms/v1_19_R3/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R3/NMSInitializer.java deleted file mode 100644 index 99797e8ab3..0000000000 --- a/platforms/bukkit/nms/v1_19_R3/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R3/NMSInitializer.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.dfsek.terra.bukkit.nms.v1_19_R3; - -import org.bukkit.Bukkit; - -import com.dfsek.terra.bukkit.PlatformImpl; -import com.dfsek.terra.bukkit.nms.Initializer; - - -public class NMSInitializer implements Initializer { - @Override - public void initialize(PlatformImpl platform) { - AwfulBukkitHacks.registerBiomes(platform.getRawConfigRegistry()); - Bukkit.getPluginManager().registerEvents(new NMSInjectListener(), platform.getPlugin()); - } -} diff --git a/platforms/bukkit/nms/v1_19_R3/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R3/NMSInjectListener.java b/platforms/bukkit/nms/v1_19_R3/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R3/NMSInjectListener.java deleted file mode 100644 index 78da74f655..0000000000 --- a/platforms/bukkit/nms/v1_19_R3/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R3/NMSInjectListener.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.dfsek.terra.bukkit.nms.v1_19_R3; - -import net.minecraft.server.level.ServerLevel; -import net.minecraft.world.level.chunk.ChunkGenerator; -import org.bukkit.World; -import org.bukkit.craftbukkit.v1_19_R3.CraftWorld; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.world.WorldInitEvent; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.HashSet; -import java.util.Set; -import java.util.concurrent.locks.ReentrantLock; - -import com.dfsek.terra.api.config.ConfigPack; -import com.dfsek.terra.bukkit.generator.BukkitChunkGeneratorWrapper; - - -public class NMSInjectListener implements Listener { - private static final Logger LOGGER = LoggerFactory.getLogger(NMSInjectListener.class); - private static final Set INJECTED = new HashSet<>(); - private static final ReentrantLock INJECT_LOCK = new ReentrantLock(); - - @EventHandler - public void onWorldInit(WorldInitEvent event) { - if(!INJECTED.contains(event.getWorld()) && - event.getWorld().getGenerator() instanceof BukkitChunkGeneratorWrapper bukkitChunkGeneratorWrapper) { - INJECT_LOCK.lock(); - INJECTED.add(event.getWorld()); - LOGGER.info("Preparing to take over the world: {}", event.getWorld().getName()); - CraftWorld craftWorld = (CraftWorld) event.getWorld(); - ServerLevel serverWorld = craftWorld.getHandle(); - - ConfigPack pack = bukkitChunkGeneratorWrapper.getPack(); - - ChunkGenerator vanilla = serverWorld.getChunkSource().getGenerator(); - NMSBiomeProvider provider = new NMSBiomeProvider(pack.getBiomeProvider(), craftWorld.getSeed()); - - serverWorld.getChunkSource().chunkMap.generator = new NMSChunkGeneratorDelegate(vanilla, pack, provider, craftWorld.getSeed()); - - LOGGER.info("Successfully injected into world."); - - INJECT_LOCK.unlock(); - } - } -} diff --git a/platforms/bukkit/nms/v1_19_R3/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R3/NMSWorldProperties.java b/platforms/bukkit/nms/v1_19_R3/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R3/NMSWorldProperties.java deleted file mode 100644 index 2cda90452f..0000000000 --- a/platforms/bukkit/nms/v1_19_R3/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R3/NMSWorldProperties.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.dfsek.terra.bukkit.nms.v1_19_R3; - -import net.minecraft.world.level.LevelHeightAccessor; - -import com.dfsek.terra.api.world.info.WorldProperties; - - -public class NMSWorldProperties implements WorldProperties { - private final long seed; - private final LevelHeightAccessor height; - - public NMSWorldProperties(long seed, LevelHeightAccessor height) { - this.seed = seed; - this.height = height; - } - - @Override - public Object getHandle() { - return height; - } - - @Override - public long getSeed() { - return seed; - } - - @Override - public int getMaxHeight() { - return height.getMaxBuildHeight(); - } - - @Override - public int getMinHeight() { - return height.getMinBuildHeight(); - } -} diff --git a/platforms/bukkit/nms/v1_19_R3/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R3/RegistryFetcher.java b/platforms/bukkit/nms/v1_19_R3/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R3/RegistryFetcher.java deleted file mode 100644 index e033491bba..0000000000 --- a/platforms/bukkit/nms/v1_19_R3/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R3/RegistryFetcher.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.dfsek.terra.bukkit.nms.v1_19_R3; - -import net.minecraft.core.Registry; -import net.minecraft.core.registries.Registries; -import net.minecraft.resources.ResourceKey; -import net.minecraft.server.dedicated.DedicatedServer; -import net.minecraft.world.level.biome.Biome; -import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_19_R3.CraftServer; - - -public class RegistryFetcher { - private static Registry getRegistry(ResourceKey> key) { - CraftServer craftserver = (CraftServer) Bukkit.getServer(); - DedicatedServer dedicatedserver = craftserver.getServer(); - return dedicatedserver - .registryAccess() - .registryOrThrow(key); - } - - public static Registry biomeRegistry() { - return getRegistry(Registries.BIOME); - } -} diff --git a/platforms/bukkit/nms/v1_20_R1/build.gradle.kts b/platforms/bukkit/nms/v1_20_R1/build.gradle.kts deleted file mode 100644 index c3c0d9809b..0000000000 --- a/platforms/bukkit/nms/v1_20_R1/build.gradle.kts +++ /dev/null @@ -1,17 +0,0 @@ -apply(plugin = "io.papermc.paperweight.userdev") - -repositories { - maven("https://s01.oss.sonatype.org/content/repositories/snapshots/") -} - -dependencies { - api(project(":platforms:bukkit:common")) - paperDevBundle("1.20.1-R0.1-SNAPSHOT") - implementation("xyz.jpenilla", "reflection-remapper", Versions.Bukkit.reflectionRemapper) -} - -tasks { - assemble { - dependsOn("reobfJar") - } -} \ No newline at end of file diff --git a/platforms/bukkit/nms/v1_20_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R1/AwfulBukkitHacks.java b/platforms/bukkit/nms/v1_20_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R1/AwfulBukkitHacks.java deleted file mode 100644 index 7994a0074d..0000000000 --- a/platforms/bukkit/nms/v1_20_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R1/AwfulBukkitHacks.java +++ /dev/null @@ -1,101 +0,0 @@ -package com.dfsek.terra.bukkit.nms.v1_20_R1; - -import com.google.common.collect.ImmutableMap; -import com.mojang.serialization.Lifecycle; -import net.minecraft.core.Holder; -import net.minecraft.core.Holder.Reference; -import net.minecraft.core.MappedRegistry; -import net.minecraft.core.WritableRegistry; -import net.minecraft.core.registries.Registries; -import net.minecraft.resources.ResourceKey; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.tags.TagKey; -import net.minecraft.world.level.biome.Biome; -import org.bukkit.NamespacedKey; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -import com.dfsek.terra.bukkit.world.BukkitPlatformBiome; -import com.dfsek.terra.registry.master.ConfigRegistry; - - -public class AwfulBukkitHacks { - private static final Logger LOGGER = LoggerFactory.getLogger(AwfulBukkitHacks.class); - - private static final Map> terraBiomeMap = new HashMap<>(); - - public static void registerBiomes(ConfigRegistry configRegistry) { - try { - LOGGER.info("Hacking biome registry..."); - WritableRegistry biomeRegistry = (WritableRegistry) RegistryFetcher.biomeRegistry(); - - Reflection.MAPPED_REGISTRY.setFrozen((MappedRegistry) biomeRegistry, false); - - configRegistry.forEach(pack -> pack.getRegistry(com.dfsek.terra.api.world.biome.Biome.class).forEach((key, biome) -> { - try { - BukkitPlatformBiome platformBiome = (BukkitPlatformBiome) biome.getPlatformBiome(); - NamespacedKey vanillaBukkitKey = platformBiome.getHandle().getKey(); - ResourceLocation vanillaMinecraftKey = new ResourceLocation(vanillaBukkitKey.getNamespace(), vanillaBukkitKey.getKey()); - Biome platform = NMSBiomeInjector.createBiome(biome, Objects.requireNonNull(biomeRegistry.get(vanillaMinecraftKey))); - - ResourceKey delegateKey = ResourceKey.create( - Registries.BIOME, - new ResourceLocation("terra", NMSBiomeInjector.createBiomeID(pack, key)) - ); - - Reference holder = biomeRegistry.register(delegateKey, platform, Lifecycle.stable()); - Reflection.REFERENCE.invokeBindValue(holder, platform); // IMPORTANT: bind holder. - - platformBiome.getContext().put(new NMSBiomeInfo(delegateKey)); - - terraBiomeMap.computeIfAbsent(vanillaMinecraftKey, i -> new ArrayList<>()).add(delegateKey.location()); - - LOGGER.debug("Registered biome: " + delegateKey); - } catch(NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) { - throw new RuntimeException(e); - } - })); - - Reflection.MAPPED_REGISTRY.setFrozen((MappedRegistry) biomeRegistry, true); // freeze registry again :) - - LOGGER.info("Doing tag garbage...."); - Map, List>> collect = biomeRegistry - .getTags() // streamKeysAndEntries - .collect(HashMap::new, - (map, pair) -> - map.put(pair.getFirst(), new ArrayList<>(pair.getSecond().stream().toList())), - HashMap::putAll); - - terraBiomeMap - .forEach((vb, terraBiomes) -> - NMSBiomeInjector.getEntry(biomeRegistry, vb).ifPresentOrElse( - vanilla -> terraBiomes.forEach( - tb -> NMSBiomeInjector.getEntry(biomeRegistry, tb).ifPresentOrElse( - terra -> { - LOGGER.debug("{} (vanilla for {}): {}", - vanilla.unwrapKey().orElseThrow().location(), - terra.unwrapKey().orElseThrow().location(), - vanilla.tags().toList()); - vanilla.tags() - .forEach(tag -> collect - .computeIfAbsent(tag, t -> new ArrayList<>()) - .add(terra)); - }, - () -> LOGGER.error("No such biome: {}", tb))), - () -> LOGGER.error("No vanilla biome: {}", vb))); - - biomeRegistry.resetTags(); - biomeRegistry.bindTags(ImmutableMap.copyOf(collect)); - - } catch(SecurityException | IllegalArgumentException exception) { - throw new RuntimeException(exception); - } - } -} - diff --git a/platforms/bukkit/nms/v1_20_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R1/NMSBiomeInfo.java b/platforms/bukkit/nms/v1_20_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R1/NMSBiomeInfo.java deleted file mode 100644 index 7d8203ce31..0000000000 --- a/platforms/bukkit/nms/v1_20_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R1/NMSBiomeInfo.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.dfsek.terra.bukkit.nms.v1_20_R1; - -import net.minecraft.resources.ResourceKey; -import net.minecraft.world.level.biome.Biome; - -import com.dfsek.terra.api.properties.Properties; - - -public record NMSBiomeInfo(ResourceKey biomeKey) implements Properties { -} diff --git a/platforms/bukkit/nms/v1_20_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R1/NMSBiomeInjector.java b/platforms/bukkit/nms/v1_20_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R1/NMSBiomeInjector.java deleted file mode 100644 index 8c13d05b14..0000000000 --- a/platforms/bukkit/nms/v1_20_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R1/NMSBiomeInjector.java +++ /dev/null @@ -1,78 +0,0 @@ -package com.dfsek.terra.bukkit.nms.v1_20_R1; - -import net.minecraft.core.Holder; -import net.minecraft.core.Registry; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.level.biome.Biome; -import net.minecraft.world.level.biome.BiomeSpecialEffects; - -import java.util.Locale; -import java.util.Objects; -import java.util.Optional; - -import com.dfsek.terra.api.config.ConfigPack; -import com.dfsek.terra.bukkit.config.VanillaBiomeProperties; - - -public class NMSBiomeInjector { - - public static Optional> getEntry(Registry registry, ResourceLocation identifier) { - return registry.getOptional(identifier) - .flatMap(registry::getResourceKey) - .flatMap(registry::getHolder); - } - - public static Biome createBiome(com.dfsek.terra.api.world.biome.Biome biome, Biome vanilla) - throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { - Biome.BiomeBuilder builder = new Biome.BiomeBuilder(); - - builder - .downfall(vanilla.climateSettings.downfall()) - .temperature(vanilla.getBaseTemperature()) - .mobSpawnSettings(vanilla.getMobSettings()) - .generationSettings(vanilla.getGenerationSettings()); - - - BiomeSpecialEffects.Builder effects = new BiomeSpecialEffects.Builder(); - - effects.grassColorModifier(vanilla.getSpecialEffects().getGrassColorModifier()); - - VanillaBiomeProperties vanillaBiomeProperties = biome.getContext().get(VanillaBiomeProperties.class); - - effects.fogColor(Objects.requireNonNullElse(vanillaBiomeProperties.getFogColor(), vanilla.getFogColor())) - - .waterColor(Objects.requireNonNullElse(vanillaBiomeProperties.getWaterColor(), vanilla.getWaterColor())) - - .waterFogColor(Objects.requireNonNullElse(vanillaBiomeProperties.getWaterFogColor(), vanilla.getWaterFogColor())) - - .skyColor(Objects.requireNonNullElse(vanillaBiomeProperties.getSkyColor(), vanilla.getSkyColor())); - - if(vanillaBiomeProperties.getFoliageColor() == null) { - vanilla.getSpecialEffects().getFoliageColorOverride().ifPresent(effects::foliageColorOverride); - } else { - effects.foliageColorOverride(vanillaBiomeProperties.getFoliageColor()); - } - - if(vanillaBiomeProperties.getGrassColor() == null) { - vanilla.getSpecialEffects().getGrassColorOverride().ifPresent(effects::grassColorOverride); - } else { - // grass - effects.grassColorOverride(vanillaBiomeProperties.getGrassColor()); - } - - vanilla.getAmbientLoop().ifPresent(effects::ambientLoopSound); - vanilla.getAmbientAdditions().ifPresent(effects::ambientAdditionsSound); - vanilla.getAmbientMood().ifPresent(effects::ambientMoodSound); - vanilla.getBackgroundMusic().ifPresent(effects::backgroundMusic); - vanilla.getAmbientParticle().ifPresent(effects::ambientParticle); - - builder.specialEffects(effects.build()); - - return builder.build(); - } - - public static String createBiomeID(ConfigPack pack, com.dfsek.terra.api.registry.key.RegistryKey biomeID) { - return pack.getID() - .toLowerCase() + "/" + biomeID.getNamespace().toLowerCase(Locale.ROOT) + "/" + biomeID.getID().toLowerCase(Locale.ROOT); - } -} diff --git a/platforms/bukkit/nms/v1_20_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R1/NMSInitializer.java b/platforms/bukkit/nms/v1_20_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R1/NMSInitializer.java deleted file mode 100644 index 6fb689ee78..0000000000 --- a/platforms/bukkit/nms/v1_20_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R1/NMSInitializer.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.dfsek.terra.bukkit.nms.v1_20_R1; - -import org.bukkit.Bukkit; - -import com.dfsek.terra.bukkit.PlatformImpl; -import com.dfsek.terra.bukkit.nms.Initializer; - - -public class NMSInitializer implements Initializer { - @Override - public void initialize(PlatformImpl platform) { - AwfulBukkitHacks.registerBiomes(platform.getRawConfigRegistry()); - Bukkit.getPluginManager().registerEvents(new NMSInjectListener(), platform.getPlugin()); - } -} diff --git a/platforms/bukkit/nms/v1_20_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R1/NMSInjectListener.java b/platforms/bukkit/nms/v1_20_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R1/NMSInjectListener.java deleted file mode 100644 index 3f7c9e060b..0000000000 --- a/platforms/bukkit/nms/v1_20_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R1/NMSInjectListener.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.dfsek.terra.bukkit.nms.v1_20_R1; - -import net.minecraft.server.level.ServerLevel; -import net.minecraft.world.level.chunk.ChunkGenerator; -import org.bukkit.World; -import org.bukkit.craftbukkit.v1_20_R1.CraftWorld; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.world.WorldInitEvent; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.HashSet; -import java.util.Set; -import java.util.concurrent.locks.ReentrantLock; - -import com.dfsek.terra.api.config.ConfigPack; -import com.dfsek.terra.bukkit.generator.BukkitChunkGeneratorWrapper; - - -public class NMSInjectListener implements Listener { - private static final Logger LOGGER = LoggerFactory.getLogger(NMSInjectListener.class); - private static final Set INJECTED = new HashSet<>(); - private static final ReentrantLock INJECT_LOCK = new ReentrantLock(); - - @EventHandler - public void onWorldInit(WorldInitEvent event) { - if(!INJECTED.contains(event.getWorld()) && - event.getWorld().getGenerator() instanceof BukkitChunkGeneratorWrapper bukkitChunkGeneratorWrapper) { - INJECT_LOCK.lock(); - INJECTED.add(event.getWorld()); - LOGGER.info("Preparing to take over the world: {}", event.getWorld().getName()); - CraftWorld craftWorld = (CraftWorld) event.getWorld(); - ServerLevel serverWorld = craftWorld.getHandle(); - - ConfigPack pack = bukkitChunkGeneratorWrapper.getPack(); - - ChunkGenerator vanilla = serverWorld.getChunkSource().getGenerator(); - NMSBiomeProvider provider = new NMSBiomeProvider(pack.getBiomeProvider(), craftWorld.getSeed()); - - serverWorld.getChunkSource().chunkMap.generator = new NMSChunkGeneratorDelegate(vanilla, pack, provider, craftWorld.getSeed()); - - LOGGER.info("Successfully injected into world."); - - INJECT_LOCK.unlock(); - } - } -} diff --git a/platforms/bukkit/nms/v1_20_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R1/NMSWorldProperties.java b/platforms/bukkit/nms/v1_20_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R1/NMSWorldProperties.java deleted file mode 100644 index 48effeb5fc..0000000000 --- a/platforms/bukkit/nms/v1_20_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R1/NMSWorldProperties.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.dfsek.terra.bukkit.nms.v1_20_R1; - -import net.minecraft.world.level.LevelHeightAccessor; - -import com.dfsek.terra.api.world.info.WorldProperties; - - -public class NMSWorldProperties implements WorldProperties { - private final long seed; - private final LevelHeightAccessor height; - - public NMSWorldProperties(long seed, LevelHeightAccessor height) { - this.seed = seed; - this.height = height; - } - - @Override - public Object getHandle() { - return height; - } - - @Override - public long getSeed() { - return seed; - } - - @Override - public int getMaxHeight() { - return height.getMaxBuildHeight(); - } - - @Override - public int getMinHeight() { - return height.getMinBuildHeight(); - } -} diff --git a/platforms/bukkit/nms/v1_20_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R1/Reflection.java b/platforms/bukkit/nms/v1_20_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R1/Reflection.java deleted file mode 100644 index a11dd1b15c..0000000000 --- a/platforms/bukkit/nms/v1_20_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R1/Reflection.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.dfsek.terra.bukkit.nms.v1_20_R1; - -import net.minecraft.core.Holder; -import net.minecraft.core.Holder.Reference; -import net.minecraft.core.MappedRegistry; -import net.minecraft.world.level.LevelAccessor; -import net.minecraft.world.level.StructureManager; -import xyz.jpenilla.reflectionremapper.ReflectionRemapper; -import xyz.jpenilla.reflectionremapper.proxy.ReflectionProxyFactory; -import xyz.jpenilla.reflectionremapper.proxy.annotation.FieldGetter; -import xyz.jpenilla.reflectionremapper.proxy.annotation.FieldSetter; -import xyz.jpenilla.reflectionremapper.proxy.annotation.MethodName; -import xyz.jpenilla.reflectionremapper.proxy.annotation.Proxies; - - -public class Reflection { - public static final MappedRegistryProxy MAPPED_REGISTRY; - public static final StructureManagerProxy STRUCTURE_MANAGER; - - public static final ReferenceProxy REFERENCE; - - static { - ReflectionRemapper reflectionRemapper = ReflectionRemapper.forReobfMappingsInPaperJar(); - ReflectionProxyFactory reflectionProxyFactory = ReflectionProxyFactory.create(reflectionRemapper, - Reflection.class.getClassLoader()); - - MAPPED_REGISTRY = reflectionProxyFactory.reflectionProxy(MappedRegistryProxy.class); - STRUCTURE_MANAGER = reflectionProxyFactory.reflectionProxy(StructureManagerProxy.class); - REFERENCE = reflectionProxyFactory.reflectionProxy(ReferenceProxy.class); - } - - - @Proxies(MappedRegistry.class) - public interface MappedRegistryProxy { - @FieldSetter("frozen") - void setFrozen(MappedRegistry instance, boolean frozen); - } - - - @Proxies(StructureManager.class) - public interface StructureManagerProxy { - @FieldGetter("level") - LevelAccessor getLevel(StructureManager instance); - } - - - @Proxies(Holder.Reference.class) - public interface ReferenceProxy { - @MethodName("bindValue") - void invokeBindValue(Reference instance, T value); - } -} diff --git a/platforms/bukkit/nms/v1_20_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R2/NMSBiomeInfo.java b/platforms/bukkit/nms/v1_20_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R2/NMSBiomeInfo.java deleted file mode 100644 index fd415fb208..0000000000 --- a/platforms/bukkit/nms/v1_20_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R2/NMSBiomeInfo.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.dfsek.terra.bukkit.nms.v1_20_R2; - -import net.minecraft.resources.ResourceKey; -import net.minecraft.world.level.biome.Biome; - -import com.dfsek.terra.api.properties.Properties; - - -public record NMSBiomeInfo(ResourceKey biomeKey) implements Properties { -} diff --git a/platforms/bukkit/nms/v1_20_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R2/NMSBiomeInjector.java b/platforms/bukkit/nms/v1_20_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R2/NMSBiomeInjector.java deleted file mode 100644 index b798ba4b8c..0000000000 --- a/platforms/bukkit/nms/v1_20_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R2/NMSBiomeInjector.java +++ /dev/null @@ -1,78 +0,0 @@ -package com.dfsek.terra.bukkit.nms.v1_20_R2; - -import net.minecraft.core.Holder; -import net.minecraft.core.Registry; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.level.biome.Biome; -import net.minecraft.world.level.biome.BiomeSpecialEffects; - -import java.util.Locale; -import java.util.Objects; -import java.util.Optional; - -import com.dfsek.terra.api.config.ConfigPack; -import com.dfsek.terra.bukkit.config.VanillaBiomeProperties; - - -public class NMSBiomeInjector { - - public static Optional> getEntry(Registry registry, ResourceLocation identifier) { - return registry.getOptional(identifier) - .flatMap(registry::getResourceKey) - .flatMap(registry::getHolder); - } - - public static Biome createBiome(com.dfsek.terra.api.world.biome.Biome biome, Biome vanilla) - throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { - Biome.BiomeBuilder builder = new Biome.BiomeBuilder(); - - builder - .downfall(vanilla.climateSettings.downfall()) - .temperature(vanilla.getBaseTemperature()) - .mobSpawnSettings(vanilla.getMobSettings()) - .generationSettings(vanilla.getGenerationSettings()); - - - BiomeSpecialEffects.Builder effects = new BiomeSpecialEffects.Builder(); - - effects.grassColorModifier(vanilla.getSpecialEffects().getGrassColorModifier()); - - VanillaBiomeProperties vanillaBiomeProperties = biome.getContext().get(VanillaBiomeProperties.class); - - effects.fogColor(Objects.requireNonNullElse(vanillaBiomeProperties.getFogColor(), vanilla.getFogColor())) - - .waterColor(Objects.requireNonNullElse(vanillaBiomeProperties.getWaterColor(), vanilla.getWaterColor())) - - .waterFogColor(Objects.requireNonNullElse(vanillaBiomeProperties.getWaterFogColor(), vanilla.getWaterFogColor())) - - .skyColor(Objects.requireNonNullElse(vanillaBiomeProperties.getSkyColor(), vanilla.getSkyColor())); - - if(vanillaBiomeProperties.getFoliageColor() == null) { - vanilla.getSpecialEffects().getFoliageColorOverride().ifPresent(effects::foliageColorOverride); - } else { - effects.foliageColorOverride(vanillaBiomeProperties.getFoliageColor()); - } - - if(vanillaBiomeProperties.getGrassColor() == null) { - vanilla.getSpecialEffects().getGrassColorOverride().ifPresent(effects::grassColorOverride); - } else { - // grass - effects.grassColorOverride(vanillaBiomeProperties.getGrassColor()); - } - - vanilla.getAmbientLoop().ifPresent(effects::ambientLoopSound); - vanilla.getAmbientAdditions().ifPresent(effects::ambientAdditionsSound); - vanilla.getAmbientMood().ifPresent(effects::ambientMoodSound); - vanilla.getBackgroundMusic().ifPresent(effects::backgroundMusic); - vanilla.getAmbientParticle().ifPresent(effects::ambientParticle); - - builder.specialEffects(effects.build()); - - return builder.build(); - } - - public static String createBiomeID(ConfigPack pack, com.dfsek.terra.api.registry.key.RegistryKey biomeID) { - return pack.getID() - .toLowerCase() + "/" + biomeID.getNamespace().toLowerCase(Locale.ROOT) + "/" + biomeID.getID().toLowerCase(Locale.ROOT); - } -} diff --git a/platforms/bukkit/nms/v1_20_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R2/NMSBiomeProvider.java b/platforms/bukkit/nms/v1_20_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R2/NMSBiomeProvider.java deleted file mode 100644 index 1521a3582e..0000000000 --- a/platforms/bukkit/nms/v1_20_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R2/NMSBiomeProvider.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.dfsek.terra.bukkit.nms.v1_20_R2; - -import com.mojang.serialization.Codec; -import net.minecraft.core.Holder; -import net.minecraft.core.Registry; -import net.minecraft.world.level.biome.Biome; -import net.minecraft.world.level.biome.BiomeSource; -import net.minecraft.world.level.biome.Climate.Sampler; -import org.jetbrains.annotations.NotNull; - -import java.util.stream.Stream; - -import com.dfsek.terra.api.world.biome.generation.BiomeProvider; -import com.dfsek.terra.bukkit.world.BukkitPlatformBiome; - - -public class NMSBiomeProvider extends BiomeSource { - private final BiomeProvider delegate; - private final long seed; - private final Registry biomeRegistry = RegistryFetcher.biomeRegistry(); - - public NMSBiomeProvider(BiomeProvider delegate, long seed) { - super(); - this.delegate = delegate; - this.seed = seed; - } - - @Override - protected Stream> collectPossibleBiomes() { - return delegate.stream() - .map(biome -> RegistryFetcher.biomeRegistry() - .getHolderOrThrow(((BukkitPlatformBiome) biome.getPlatformBiome()).getContext() - .get(NMSBiomeInfo.class) - .biomeKey())); - } - - @Override - protected @NotNull Codec codec() { - return BiomeSource.CODEC; - } - - @Override - public @NotNull Holder getNoiseBiome(int x, int y, int z, @NotNull Sampler sampler) { - return biomeRegistry.getHolderOrThrow(((BukkitPlatformBiome) delegate.getBiome(x << 2, y << 2, z << 2, seed) - .getPlatformBiome()).getContext() - .get(NMSBiomeInfo.class) - .biomeKey()); - } -} diff --git a/platforms/bukkit/nms/v1_20_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R2/NMSChunkGeneratorDelegate.java b/platforms/bukkit/nms/v1_20_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R2/NMSChunkGeneratorDelegate.java deleted file mode 100644 index 8ecc904acc..0000000000 --- a/platforms/bukkit/nms/v1_20_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R2/NMSChunkGeneratorDelegate.java +++ /dev/null @@ -1,171 +0,0 @@ -package com.dfsek.terra.bukkit.nms.v1_20_R2; - -import com.mojang.serialization.Codec; -import net.minecraft.core.BlockPos; -import net.minecraft.server.level.WorldGenRegion; -import net.minecraft.world.level.LevelAccessor; -import net.minecraft.world.level.LevelHeightAccessor; -import net.minecraft.world.level.NoiseColumn; -import net.minecraft.world.level.StructureManager; -import net.minecraft.world.level.WorldGenLevel; -import net.minecraft.world.level.biome.BiomeManager; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.chunk.ChunkAccess; -import net.minecraft.world.level.chunk.ChunkGenerator; -import net.minecraft.world.level.levelgen.Beardifier; -import net.minecraft.world.level.levelgen.DensityFunction.SinglePointContext; -import net.minecraft.world.level.levelgen.GenerationStep.Carving; -import net.minecraft.world.level.levelgen.Heightmap.Types; -import net.minecraft.world.level.levelgen.RandomState; -import net.minecraft.world.level.levelgen.blending.Blender; -import org.bukkit.craftbukkit.v1_20_R2.block.data.CraftBlockData; -import org.jetbrains.annotations.NotNull; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.List; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.Executor; - -import com.dfsek.terra.api.config.ConfigPack; -import com.dfsek.terra.api.world.biome.generation.BiomeProvider; -import com.dfsek.terra.api.world.info.WorldProperties; -import com.dfsek.terra.bukkit.config.PreLoadCompatibilityOptions; -import com.dfsek.terra.bukkit.world.BukkitWorldProperties; -import com.dfsek.terra.bukkit.world.block.data.BukkitBlockState; - - -public class NMSChunkGeneratorDelegate extends ChunkGenerator { - private static final Logger LOGGER = LoggerFactory.getLogger(NMSChunkGeneratorDelegate.class); - private final com.dfsek.terra.api.world.chunk.generation.ChunkGenerator delegate; - - private final ChunkGenerator vanilla; - private final ConfigPack pack; - - private final long seed; - - public NMSChunkGeneratorDelegate(ChunkGenerator vanilla, ConfigPack pack, NMSBiomeProvider biomeProvider, long seed) { - super(biomeProvider); - this.delegate = pack.getGeneratorProvider().newInstance(pack); - this.vanilla = vanilla; - this.pack = pack; - this.seed = seed; - } - - @Override - protected @NotNull Codec codec() { - return ChunkGenerator.CODEC; - } - - @Override - public void applyCarvers(@NotNull WorldGenRegion chunkRegion, long seed, @NotNull RandomState noiseConfig, @NotNull BiomeManager world, - @NotNull StructureManager structureAccessor, @NotNull ChunkAccess chunk, @NotNull Carving carverStep) { - // no-op - } - - @Override - public void buildSurface(@NotNull WorldGenRegion region, @NotNull StructureManager structures, @NotNull RandomState noiseConfig, - @NotNull ChunkAccess chunk) { - // no-op - } - - @Override - public void applyBiomeDecoration(@NotNull WorldGenLevel world, @NotNull ChunkAccess chunk, - @NotNull StructureManager structureAccessor) { - vanilla.applyBiomeDecoration(world, chunk, structureAccessor); - } - - @Override - public void spawnOriginalMobs(@NotNull WorldGenRegion region) { - vanilla.spawnOriginalMobs(region); - } - - @Override - public int getGenDepth() { - return vanilla.getGenDepth(); - } - - @Override - public @NotNull CompletableFuture fillFromNoise(@NotNull Executor executor, @NotNull Blender blender, - @NotNull RandomState noiseConfig, - @NotNull StructureManager structureAccessor, @NotNull ChunkAccess chunk) { - return vanilla.fillFromNoise(executor, blender, noiseConfig, structureAccessor, chunk) - .thenApply(c -> { - LevelAccessor level = Reflection.STRUCTURE_MANAGER.getLevel(structureAccessor); - BiomeProvider biomeProvider = pack.getBiomeProvider(); - PreLoadCompatibilityOptions compatibilityOptions = pack.getContext().get(PreLoadCompatibilityOptions.class); - if(compatibilityOptions.isBeard()) { - beard(structureAccessor, chunk, new BukkitWorldProperties(level.getMinecraftWorld().getWorld()), - biomeProvider, compatibilityOptions); - } - return c; - }); - } - - private void beard(StructureManager structureAccessor, ChunkAccess chunk, WorldProperties world, BiomeProvider biomeProvider, - PreLoadCompatibilityOptions compatibilityOptions) { - Beardifier structureWeightSampler = Beardifier.forStructuresInChunk(structureAccessor, chunk.getPos()); - double threshold = compatibilityOptions.getBeardThreshold(); - double airThreshold = compatibilityOptions.getAirThreshold(); - int xi = chunk.getPos().x << 4; - int zi = chunk.getPos().z << 4; - for(int x = 0; x < 16; x++) { - for(int z = 0; z < 16; z++) { - int depth = 0; - for(int y = world.getMaxHeight(); y >= world.getMinHeight(); y--) { - double noise = structureWeightSampler.compute(new SinglePointContext(x + xi, y, z + zi)); - if(noise > threshold) { - chunk.setBlockState(new BlockPos(x, y, z), ((CraftBlockData) ((BukkitBlockState) delegate - .getPalette(x + xi, y, z + zi, world, biomeProvider) - .get(depth, x + xi, y, z + zi, world.getSeed())).getHandle()).getState(), false); - depth++; - } else if(noise < airThreshold) { - chunk.setBlockState(new BlockPos(x, y, z), Blocks.AIR.defaultBlockState(), false); - } else { - depth = 0; - } - } - } - } - } - - @Override - public int getSeaLevel() { - return vanilla.getSeaLevel(); - } - - @Override - public int getMinY() { - return vanilla.getMinY(); - } - - @Override - public int getBaseHeight(int x, int z, @NotNull Types heightmap, @NotNull LevelHeightAccessor world, @NotNull RandomState noiseConfig) { - WorldProperties properties = new NMSWorldProperties(seed, world); - int y = properties.getMaxHeight(); - BiomeProvider biomeProvider = pack.getBiomeProvider(); - while(y >= getMinY() && !heightmap.isOpaque().test( - ((CraftBlockData) delegate.getBlock(properties, x, y - 1, z, biomeProvider).getHandle()).getState())) { - y--; - } - return y; - } - - @Override - public @NotNull NoiseColumn getBaseColumn(int x, int z, @NotNull LevelHeightAccessor world, @NotNull RandomState noiseConfig) { - BlockState[] array = new BlockState[world.getHeight()]; - WorldProperties properties = new NMSWorldProperties(seed, world); - BiomeProvider biomeProvider = pack.getBiomeProvider(); - for(int y = properties.getMaxHeight() - 1; y >= properties.getMinHeight(); y--) { - array[y - properties.getMinHeight()] = ((CraftBlockData) delegate.getBlock(properties, x, y, z, biomeProvider) - .getHandle()).getState(); - } - return new NoiseColumn(getMinY(), array); - } - - @Override - public void addDebugScreenInfo(@NotNull List text, @NotNull RandomState noiseConfig, @NotNull BlockPos pos) { - - } -} diff --git a/platforms/bukkit/nms/v1_20_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R2/NMSInitializer.java b/platforms/bukkit/nms/v1_20_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R2/NMSInitializer.java deleted file mode 100644 index 89cf3b8786..0000000000 --- a/platforms/bukkit/nms/v1_20_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R2/NMSInitializer.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.dfsek.terra.bukkit.nms.v1_20_R2; - -import org.bukkit.Bukkit; - -import com.dfsek.terra.bukkit.PlatformImpl; -import com.dfsek.terra.bukkit.nms.Initializer; - - -public class NMSInitializer implements Initializer { - @Override - public void initialize(PlatformImpl platform) { - AwfulBukkitHacks.registerBiomes(platform.getRawConfigRegistry()); - Bukkit.getPluginManager().registerEvents(new NMSInjectListener(), platform.getPlugin()); - } -} diff --git a/platforms/bukkit/nms/v1_20_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R2/NMSInjectListener.java b/platforms/bukkit/nms/v1_20_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R2/NMSInjectListener.java deleted file mode 100644 index ace83ddc7d..0000000000 --- a/platforms/bukkit/nms/v1_20_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R2/NMSInjectListener.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.dfsek.terra.bukkit.nms.v1_20_R2; - -import net.minecraft.server.level.ServerLevel; -import net.minecraft.world.level.chunk.ChunkGenerator; -import org.bukkit.World; -import org.bukkit.craftbukkit.v1_20_R2.CraftWorld; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.world.WorldInitEvent; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.HashSet; -import java.util.Set; -import java.util.concurrent.locks.ReentrantLock; - -import com.dfsek.terra.api.config.ConfigPack; -import com.dfsek.terra.bukkit.generator.BukkitChunkGeneratorWrapper; - - -public class NMSInjectListener implements Listener { - private static final Logger LOGGER = LoggerFactory.getLogger(NMSInjectListener.class); - private static final Set INJECTED = new HashSet<>(); - private static final ReentrantLock INJECT_LOCK = new ReentrantLock(); - - @EventHandler - public void onWorldInit(WorldInitEvent event) { - if(!INJECTED.contains(event.getWorld()) && - event.getWorld().getGenerator() instanceof BukkitChunkGeneratorWrapper bukkitChunkGeneratorWrapper) { - INJECT_LOCK.lock(); - INJECTED.add(event.getWorld()); - LOGGER.info("Preparing to take over the world: {}", event.getWorld().getName()); - CraftWorld craftWorld = (CraftWorld) event.getWorld(); - ServerLevel serverWorld = craftWorld.getHandle(); - - ConfigPack pack = bukkitChunkGeneratorWrapper.getPack(); - - ChunkGenerator vanilla = serverWorld.getChunkSource().getGenerator(); - NMSBiomeProvider provider = new NMSBiomeProvider(pack.getBiomeProvider(), craftWorld.getSeed()); - - serverWorld.getChunkSource().chunkMap.generator = new NMSChunkGeneratorDelegate(vanilla, pack, provider, craftWorld.getSeed()); - - LOGGER.info("Successfully injected into world."); - - INJECT_LOCK.unlock(); - } - } -} diff --git a/platforms/bukkit/nms/v1_20_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R2/NMSWorldProperties.java b/platforms/bukkit/nms/v1_20_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R2/NMSWorldProperties.java deleted file mode 100644 index 441a1847d0..0000000000 --- a/platforms/bukkit/nms/v1_20_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R2/NMSWorldProperties.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.dfsek.terra.bukkit.nms.v1_20_R2; - -import net.minecraft.world.level.LevelHeightAccessor; - -import com.dfsek.terra.api.world.info.WorldProperties; - - -public class NMSWorldProperties implements WorldProperties { - private final long seed; - private final LevelHeightAccessor height; - - public NMSWorldProperties(long seed, LevelHeightAccessor height) { - this.seed = seed; - this.height = height; - } - - @Override - public Object getHandle() { - return height; - } - - @Override - public long getSeed() { - return seed; - } - - @Override - public int getMaxHeight() { - return height.getMaxBuildHeight(); - } - - @Override - public int getMinHeight() { - return height.getMinBuildHeight(); - } -} diff --git a/platforms/bukkit/nms/v1_20_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R2/Reflection.java b/platforms/bukkit/nms/v1_20_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R2/Reflection.java deleted file mode 100644 index da7b5c01d9..0000000000 --- a/platforms/bukkit/nms/v1_20_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R2/Reflection.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.dfsek.terra.bukkit.nms.v1_20_R2; - -import net.minecraft.core.Holder; -import net.minecraft.core.Holder.Reference; -import net.minecraft.core.MappedRegistry; -import net.minecraft.world.level.LevelAccessor; -import net.minecraft.world.level.StructureManager; -import xyz.jpenilla.reflectionremapper.ReflectionRemapper; -import xyz.jpenilla.reflectionremapper.proxy.ReflectionProxyFactory; -import xyz.jpenilla.reflectionremapper.proxy.annotation.FieldGetter; -import xyz.jpenilla.reflectionremapper.proxy.annotation.FieldSetter; -import xyz.jpenilla.reflectionremapper.proxy.annotation.MethodName; -import xyz.jpenilla.reflectionremapper.proxy.annotation.Proxies; - - -public class Reflection { - public static final MappedRegistryProxy MAPPED_REGISTRY; - public static final StructureManagerProxy STRUCTURE_MANAGER; - - public static final ReferenceProxy REFERENCE; - - static { - ReflectionRemapper reflectionRemapper = ReflectionRemapper.forReobfMappingsInPaperJar(); - ReflectionProxyFactory reflectionProxyFactory = ReflectionProxyFactory.create(reflectionRemapper, - Reflection.class.getClassLoader()); - - MAPPED_REGISTRY = reflectionProxyFactory.reflectionProxy(MappedRegistryProxy.class); - STRUCTURE_MANAGER = reflectionProxyFactory.reflectionProxy(StructureManagerProxy.class); - REFERENCE = reflectionProxyFactory.reflectionProxy(ReferenceProxy.class); - } - - - @Proxies(MappedRegistry.class) - public interface MappedRegistryProxy { - @FieldSetter("frozen") - void setFrozen(MappedRegistry instance, boolean frozen); - } - - - @Proxies(StructureManager.class) - public interface StructureManagerProxy { - @FieldGetter("level") - LevelAccessor getLevel(StructureManager instance); - } - - - @Proxies(Holder.Reference.class) - public interface ReferenceProxy { - @MethodName("bindValue") - void invokeBindValue(Reference instance, T value); - } -} diff --git a/platforms/bukkit/nms/v1_20_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R2/RegistryFetcher.java b/platforms/bukkit/nms/v1_20_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R2/RegistryFetcher.java deleted file mode 100644 index 52bec1b1b2..0000000000 --- a/platforms/bukkit/nms/v1_20_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R2/RegistryFetcher.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.dfsek.terra.bukkit.nms.v1_20_R2; - -import net.minecraft.core.Registry; -import net.minecraft.core.registries.Registries; -import net.minecraft.resources.ResourceKey; -import net.minecraft.server.dedicated.DedicatedServer; -import net.minecraft.world.level.biome.Biome; -import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_20_R2.CraftServer; - - -public class RegistryFetcher { - private static Registry getRegistry(ResourceKey> key) { - CraftServer craftserver = (CraftServer) Bukkit.getServer(); - DedicatedServer dedicatedserver = craftserver.getServer(); - return dedicatedserver - .registryAccess() - .registryOrThrow(key); - } - - public static Registry biomeRegistry() { - return getRegistry(Registries.BIOME); - } -} diff --git a/platforms/bukkit/nms/v1_20_R2/build.gradle.kts b/platforms/bukkit/nms/v1_20_R3/build.gradle.kts similarity index 100% rename from platforms/bukkit/nms/v1_20_R2/build.gradle.kts rename to platforms/bukkit/nms/v1_20_R3/build.gradle.kts diff --git a/platforms/bukkit/nms/v1_20_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R2/AwfulBukkitHacks.java b/platforms/bukkit/nms/v1_20_R3/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R3/AwfulBukkitHacks.java similarity index 99% rename from platforms/bukkit/nms/v1_20_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R2/AwfulBukkitHacks.java rename to platforms/bukkit/nms/v1_20_R3/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R3/AwfulBukkitHacks.java index 8023ae4522..fa2cc9907b 100644 --- a/platforms/bukkit/nms/v1_20_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R2/AwfulBukkitHacks.java +++ b/platforms/bukkit/nms/v1_20_R3/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R3/AwfulBukkitHacks.java @@ -1,4 +1,4 @@ -package com.dfsek.terra.bukkit.nms.v1_20_R2; +package com.dfsek.terra.bukkit.nms.v1_20_R3; import com.google.common.collect.ImmutableMap; import com.mojang.serialization.Lifecycle; diff --git a/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSBiomeInfo.java b/platforms/bukkit/nms/v1_20_R3/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R3/NMSBiomeInfo.java similarity index 83% rename from platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSBiomeInfo.java rename to platforms/bukkit/nms/v1_20_R3/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R3/NMSBiomeInfo.java index 02e67dc8d1..f47d21c56e 100644 --- a/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSBiomeInfo.java +++ b/platforms/bukkit/nms/v1_20_R3/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R3/NMSBiomeInfo.java @@ -1,10 +1,10 @@ -package com.dfsek.terra.bukkit.nms.v1_19_R1; - -import com.dfsek.terra.api.properties.Properties; +package com.dfsek.terra.bukkit.nms.v1_20_R3; import net.minecraft.resources.ResourceKey; import net.minecraft.world.level.biome.Biome; +import com.dfsek.terra.api.properties.Properties; + public record NMSBiomeInfo(ResourceKey biomeKey) implements Properties { } diff --git a/platforms/bukkit/nms/v1_19_R3/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R3/NMSBiomeInjector.java b/platforms/bukkit/nms/v1_20_R3/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R3/NMSBiomeInjector.java similarity index 98% rename from platforms/bukkit/nms/v1_19_R3/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R3/NMSBiomeInjector.java rename to platforms/bukkit/nms/v1_20_R3/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R3/NMSBiomeInjector.java index 733fd38f4f..e75b6fc0a6 100644 --- a/platforms/bukkit/nms/v1_19_R3/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R3/NMSBiomeInjector.java +++ b/platforms/bukkit/nms/v1_20_R3/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R3/NMSBiomeInjector.java @@ -1,4 +1,4 @@ -package com.dfsek.terra.bukkit.nms.v1_19_R3; +package com.dfsek.terra.bukkit.nms.v1_20_R3; import net.minecraft.core.Holder; import net.minecraft.core.Registry; diff --git a/platforms/bukkit/nms/v1_20_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R1/NMSBiomeProvider.java b/platforms/bukkit/nms/v1_20_R3/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R3/NMSBiomeProvider.java similarity index 97% rename from platforms/bukkit/nms/v1_20_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R1/NMSBiomeProvider.java rename to platforms/bukkit/nms/v1_20_R3/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R3/NMSBiomeProvider.java index 48f0483180..875a77fb52 100644 --- a/platforms/bukkit/nms/v1_20_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R1/NMSBiomeProvider.java +++ b/platforms/bukkit/nms/v1_20_R3/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R3/NMSBiomeProvider.java @@ -1,4 +1,4 @@ -package com.dfsek.terra.bukkit.nms.v1_20_R1; +package com.dfsek.terra.bukkit.nms.v1_20_R3; import com.mojang.serialization.Codec; import net.minecraft.core.Holder; diff --git a/platforms/bukkit/nms/v1_20_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R1/NMSChunkGeneratorDelegate.java b/platforms/bukkit/nms/v1_20_R3/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R3/NMSChunkGeneratorDelegate.java similarity index 98% rename from platforms/bukkit/nms/v1_20_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R1/NMSChunkGeneratorDelegate.java rename to platforms/bukkit/nms/v1_20_R3/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R3/NMSChunkGeneratorDelegate.java index 565d0cbc4d..4338dc140c 100644 --- a/platforms/bukkit/nms/v1_20_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R1/NMSChunkGeneratorDelegate.java +++ b/platforms/bukkit/nms/v1_20_R3/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R3/NMSChunkGeneratorDelegate.java @@ -1,4 +1,4 @@ -package com.dfsek.terra.bukkit.nms.v1_20_R1; +package com.dfsek.terra.bukkit.nms.v1_20_R3; import com.mojang.serialization.Codec; import net.minecraft.core.BlockPos; @@ -19,7 +19,7 @@ import net.minecraft.world.level.levelgen.Heightmap.Types; import net.minecraft.world.level.levelgen.RandomState; import net.minecraft.world.level.levelgen.blending.Blender; -import org.bukkit.craftbukkit.v1_20_R1.block.data.CraftBlockData; +import org.bukkit.craftbukkit.v1_20_R3.block.data.CraftBlockData; import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSInitializer.java b/platforms/bukkit/nms/v1_20_R3/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R3/NMSInitializer.java similarity index 90% rename from platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSInitializer.java rename to platforms/bukkit/nms/v1_20_R3/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R3/NMSInitializer.java index 82a293cd19..084c5c30a0 100644 --- a/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSInitializer.java +++ b/platforms/bukkit/nms/v1_20_R3/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R3/NMSInitializer.java @@ -1,4 +1,4 @@ -package com.dfsek.terra.bukkit.nms.v1_19_R1; +package com.dfsek.terra.bukkit.nms.v1_20_R3; import org.bukkit.Bukkit; diff --git a/platforms/bukkit/nms/v1_19_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R2/NMSInjectListener.java b/platforms/bukkit/nms/v1_20_R3/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R3/NMSInjectListener.java similarity index 95% rename from platforms/bukkit/nms/v1_19_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R2/NMSInjectListener.java rename to platforms/bukkit/nms/v1_20_R3/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R3/NMSInjectListener.java index 6ce184da05..a81e93a3f3 100644 --- a/platforms/bukkit/nms/v1_19_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R2/NMSInjectListener.java +++ b/platforms/bukkit/nms/v1_20_R3/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R3/NMSInjectListener.java @@ -1,9 +1,9 @@ -package com.dfsek.terra.bukkit.nms.v1_19_R2; +package com.dfsek.terra.bukkit.nms.v1_20_R3; import net.minecraft.server.level.ServerLevel; import net.minecraft.world.level.chunk.ChunkGenerator; import org.bukkit.World; -import org.bukkit.craftbukkit.v1_19_R2.CraftWorld; +import org.bukkit.craftbukkit.v1_20_R3.CraftWorld; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.world.WorldInitEvent; diff --git a/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSWorldProperties.java b/platforms/bukkit/nms/v1_20_R3/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R3/NMSWorldProperties.java similarity index 94% rename from platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSWorldProperties.java rename to platforms/bukkit/nms/v1_20_R3/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R3/NMSWorldProperties.java index 9348ca0478..60f6cee46c 100644 --- a/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSWorldProperties.java +++ b/platforms/bukkit/nms/v1_20_R3/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R3/NMSWorldProperties.java @@ -1,4 +1,4 @@ -package com.dfsek.terra.bukkit.nms.v1_19_R1; +package com.dfsek.terra.bukkit.nms.v1_20_R3; import net.minecraft.world.level.LevelHeightAccessor; diff --git a/platforms/bukkit/nms/v1_19_R3/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R3/Reflection.java b/platforms/bukkit/nms/v1_20_R3/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R3/Reflection.java similarity index 97% rename from platforms/bukkit/nms/v1_19_R3/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R3/Reflection.java rename to platforms/bukkit/nms/v1_20_R3/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R3/Reflection.java index 43d362ee66..32243da54d 100644 --- a/platforms/bukkit/nms/v1_19_R3/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R3/Reflection.java +++ b/platforms/bukkit/nms/v1_20_R3/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R3/Reflection.java @@ -1,4 +1,4 @@ -package com.dfsek.terra.bukkit.nms.v1_19_R3; +package com.dfsek.terra.bukkit.nms.v1_20_R3; import net.minecraft.core.Holder; import net.minecraft.core.Holder.Reference; diff --git a/platforms/bukkit/nms/v1_20_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R1/RegistryFetcher.java b/platforms/bukkit/nms/v1_20_R3/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R3/RegistryFetcher.java similarity index 88% rename from platforms/bukkit/nms/v1_20_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R1/RegistryFetcher.java rename to platforms/bukkit/nms/v1_20_R3/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R3/RegistryFetcher.java index c7d77462d3..6dbbecbc77 100644 --- a/platforms/bukkit/nms/v1_20_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R1/RegistryFetcher.java +++ b/platforms/bukkit/nms/v1_20_R3/src/main/java/com/dfsek/terra/bukkit/nms/v1_20_R3/RegistryFetcher.java @@ -1,4 +1,4 @@ -package com.dfsek.terra.bukkit.nms.v1_20_R1; +package com.dfsek.terra.bukkit.nms.v1_20_R3; import net.minecraft.core.Registry; import net.minecraft.core.registries.Registries; @@ -6,7 +6,7 @@ import net.minecraft.server.dedicated.DedicatedServer; import net.minecraft.world.level.biome.Biome; import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_20_R1.CraftServer; +import org.bukkit.craftbukkit.v1_20_R3.CraftServer; public class RegistryFetcher { diff --git a/platforms/fabric/build.gradle.kts b/platforms/fabric/build.gradle.kts index 3598ae92c5..dba2687289 100644 --- a/platforms/fabric/build.gradle.kts +++ b/platforms/fabric/build.gradle.kts @@ -3,7 +3,6 @@ import java.util.* plugins { id("dev.architectury.loom") version Versions.Mod.architecuryLoom id("architectury-plugin") version Versions.Mod.architecturyPlugin - id("io.github.juuxel.loom-vineflower") version Versions.Mod.loomVineflower } architectury { diff --git a/platforms/fabric/src/main/resources/fabric.mod.json b/platforms/fabric/src/main/resources/fabric.mod.json index bfb5727101..8b67c7b547 100644 --- a/platforms/fabric/src/main/resources/fabric.mod.json +++ b/platforms/fabric/src/main/resources/fabric.mod.json @@ -26,9 +26,9 @@ "terra.common.mixins.json" ], "depends": { - "fabricloader": ">=0.14.2", + "fabricloader": ">=0.15.1", "java": ">=17", - "minecraft": "1.20.x", + "minecraft": ">=1.20.4", "fabric": "*" } } \ No newline at end of file diff --git a/platforms/forge/build.gradle.kts b/platforms/forge/build.gradle.kts.disabled similarity index 100% rename from platforms/forge/build.gradle.kts rename to platforms/forge/build.gradle.kts.disabled diff --git a/platforms/mixin-common/build.gradle.kts b/platforms/mixin-common/build.gradle.kts index a6b4e72311..2fb92233c6 100644 --- a/platforms/mixin-common/build.gradle.kts +++ b/platforms/mixin-common/build.gradle.kts @@ -1,7 +1,6 @@ plugins { id("dev.architectury.loom") version Versions.Mod.architecuryLoom id("architectury-plugin") version Versions.Mod.architecturyPlugin - id("io.github.juuxel.loom-vineflower") version Versions.Mod.loomVineflower } loom { @@ -24,7 +23,7 @@ dependencies { } architectury { - common("fabric", "forge") + common("fabric") minecraft = Versions.Mod.minecraft } diff --git a/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/handle/MinecraftWorldHandle.java b/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/handle/MinecraftWorldHandle.java index 52ea52dfa8..3b5e1fe49b 100644 --- a/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/handle/MinecraftWorldHandle.java +++ b/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/handle/MinecraftWorldHandle.java @@ -23,6 +23,8 @@ import net.minecraft.registry.Registries; import net.minecraft.util.Identifier; import org.jetbrains.annotations.NotNull; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import com.dfsek.terra.api.block.state.BlockState; import com.dfsek.terra.api.entity.EntityType; @@ -31,11 +33,21 @@ public class MinecraftWorldHandle implements WorldHandle { + private static final BlockState AIR = (BlockState) Blocks.AIR.getDefaultState(); + private static final Logger logger = LoggerFactory.getLogger(MinecraftWorldHandle.class); + @Override public @NotNull BlockState createBlockState(@NotNull String data) { try { + if(data.equals("minecraft:grass")) { //TODO: remove in 7.0 + data = "minecraft:short_grass"; + logger.warn( + "Translating minecraft:grass to minecraft:short_grass. In 1.20.3 minecraft:grass was renamed to minecraft:short_grass" + + ". You are advised to perform this rename in your config packs as this translation will be removed in the next major " + + "version of Terra."); + } net.minecraft.block.BlockState state = BlockArgumentParser.block(Registries.BLOCK.getReadOnlyWrapper(), data, true) .blockState(); if(state == null) throw new IllegalArgumentException("Invalid data: " + data); @@ -52,6 +64,15 @@ public class MinecraftWorldHandle implements WorldHandle { @Override public @NotNull EntityType getEntity(@NotNull String id) { + if (!id.contains(":")) { //TODO: remove in 7.0 + String newid = "minecraft:" + id.toLowerCase();; + logger.warn( + "Translating " + id + " to " + newid + ". In 1.20.3 entity parsing was reworked" + + ". You are advised to perform this rename in your config packs as this translation will be removed in the next major " + + "version of Terra."); + id = newid; + } + if(!id.contains(":")) throw new IllegalArgumentException("Invalid entity identifier " + id); Identifier identifier = Identifier.tryParse(id); if(identifier == null) identifier = Identifier.tryParse(id); return (EntityType) Registries.ENTITY_TYPE.get(identifier); diff --git a/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/mixin/access/MobSpawnerLogicAccessor.java b/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/mixin/access/MobSpawnerLogicAccessor.java index 5289cd4274..002b5c25ba 100644 --- a/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/mixin/access/MobSpawnerLogicAccessor.java +++ b/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/mixin/access/MobSpawnerLogicAccessor.java @@ -17,8 +17,8 @@ package com.dfsek.terra.mod.mixin.access; -import net.minecraft.world.MobSpawnerEntry; -import net.minecraft.world.MobSpawnerLogic; +import net.minecraft.block.spawner.MobSpawnerEntry; +import net.minecraft.block.spawner.MobSpawnerLogic; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Accessor; diff --git a/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/mixin/implementations/terra/block/entity/MobSpawnerBlockEntityMixin.java b/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/mixin/implementations/terra/block/entity/MobSpawnerBlockEntityMixin.java index 1b882e5fd5..ccc8b738a5 100644 --- a/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/mixin/implementations/terra/block/entity/MobSpawnerBlockEntityMixin.java +++ b/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/mixin/implementations/terra/block/entity/MobSpawnerBlockEntityMixin.java @@ -21,11 +21,11 @@ import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.entity.BlockEntityType; import net.minecraft.block.entity.MobSpawnerBlockEntity; +import net.minecraft.block.spawner.MobSpawnerLogic; import net.minecraft.registry.Registries; import net.minecraft.util.Identifier; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.random.Random; -import net.minecraft.world.MobSpawnerLogic; import org.jetbrains.annotations.NotNull; import org.spongepowered.asm.mixin.Implements; import org.spongepowered.asm.mixin.Interface; @@ -50,7 +50,7 @@ private MobSpawnerBlockEntityMixin(BlockEntityType type, BlockPos pos, BlockS public abstract MobSpawnerLogic getLogic(); @Shadow - public abstract void setEntityType(net.minecraft.entity.EntityType entityType, Random random); + public abstract void method_46408(net.minecraft.entity.EntityType entityType, Random random); public EntityType terra$getSpawnedType() { return (EntityType) Registries.ENTITY_TYPE.get( @@ -58,7 +58,13 @@ private MobSpawnerBlockEntityMixin(BlockEntityType type, BlockPos pos, BlockS } public void terra$setSpawnedType(@NotNull EntityType creatureType) { - setEntityType((net.minecraft.entity.EntityType) creatureType, world.getRandom()); + Random rand; + if (hasWorld()) { + rand = world.getRandom(); + } else { + rand = Random.create(); + } + method_46408((net.minecraft.entity.EntityType) creatureType, rand); } public int terra$getDelay() { diff --git a/platforms/mixin-lifecycle/build.gradle.kts b/platforms/mixin-lifecycle/build.gradle.kts index 490cdf687a..a4e7004121 100644 --- a/platforms/mixin-lifecycle/build.gradle.kts +++ b/platforms/mixin-lifecycle/build.gradle.kts @@ -1,7 +1,6 @@ plugins { id("dev.architectury.loom") version Versions.Mod.architecuryLoom id("architectury-plugin") version Versions.Mod.architecturyPlugin - id("io.github.juuxel.loom-vineflower") version Versions.Mod.loomVineflower } dependencies {