From abd8116cfe6a7151b5f1532bb5280e6f512af22d Mon Sep 17 00:00:00 2001 From: Steveplays28 Date: Thu, 20 Jun 2024 17:02:25 +0200 Subject: [PATCH] feat: Update to 1.21 --- build.gradle | 2 +- .../mixin/NoiseChunkGeneratorMixin.java | 40 +++++++++------- .../LithiumNoiseChunkGeneratorMixin.java | 48 +++++++++++-------- .../main/resources/noisium-common.mixins.json | 2 +- gradle.properties | 16 +++---- neoforge/build.gradle | 3 -- 6 files changed, 63 insertions(+), 48 deletions(-) diff --git a/build.gradle b/build.gradle index 07cf23d..f2e28b4 100644 --- a/build.gradle +++ b/build.gradle @@ -17,7 +17,7 @@ subprojects { minecraft "com.mojang:minecraft:${rootProject.minecraft_version}" mappings loom.layered { it.mappings("net.fabricmc:yarn:${project.yarn_mappings}:v2") - it.mappings("dev.architectury:yarn-mappings-patch-neoforge:1.20.5+build.3") + it.mappings("dev.architectury:yarn-mappings-patch-neoforge:1.21+build.4") } } } diff --git a/common/src/main/java/io/github/steveplays28/noisium/mixin/NoiseChunkGeneratorMixin.java b/common/src/main/java/io/github/steveplays28/noisium/mixin/NoiseChunkGeneratorMixin.java index 338ae84..fb727a9 100644 --- a/common/src/main/java/io/github/steveplays28/noisium/mixin/NoiseChunkGeneratorMixin.java +++ b/common/src/main/java/io/github/steveplays28/noisium/mixin/NoiseChunkGeneratorMixin.java @@ -16,7 +16,6 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import java.util.concurrent.CompletableFuture; -import java.util.concurrent.Executor; @Mixin(NoiseChunkGenerator.class) public abstract class NoiseChunkGeneratorMixin extends ChunkGenerator { @@ -51,24 +50,33 @@ public NoiseChunkGeneratorMixin(BiomeSource biomeSource) { return blockState; } - @Inject(method = "populateNoise(Ljava/util/concurrent/Executor;Lnet/minecraft/world/gen/chunk/Blender;Lnet/minecraft/world/gen/noise/NoiseConfig;Lnet/minecraft/world/gen/StructureAccessor;Lnet/minecraft/world/chunk/Chunk;)Ljava/util/concurrent/CompletableFuture;", at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/world/chunk/Chunk;getSectionIndex(I)I", ordinal = 1), cancellable = true) - private void noisium$populateNoiseInject(Executor executor, Blender blender, NoiseConfig noiseConfig, StructureAccessor structureAccessor, Chunk chunk, CallbackInfoReturnable> cir, @Local(ordinal = 1) int minimumYFloorDiv, @Local(ordinal = 2) int generationShapeHeightFloorDiv, @Local(ordinal = 3) int startingChunkSectionIndex, @Local(ordinal = 4) int minimumYChunkSectionIndex) { - var chunkSections = chunk.getSectionArray(); - for (int chunkSectionIndex = startingChunkSectionIndex; chunkSectionIndex >= minimumYChunkSectionIndex; --chunkSectionIndex) { - chunkSections[chunkSectionIndex].lock(); + @Inject(method = "populateNoise(Lnet/minecraft/world/gen/chunk/Blender;Lnet/minecraft/world/gen/noise/NoiseConfig;Lnet/minecraft/world/gen/StructureAccessor;Lnet/minecraft/world/chunk/Chunk;)Ljava/util/concurrent/CompletableFuture;", at = @At(value = "RETURN", shift = At.Shift.BEFORE), cancellable = true) + private void noisium$populateNoiseInject(Blender blender, NoiseConfig noiseConfig, StructureAccessor structureAccessor, Chunk chunk, CallbackInfoReturnable> cir, @Local GenerationShapeConfig generationShapeConfig, @Local(ordinal = 0) int minimumY, @Local(ordinal = 1) int minimumYFloorDiv, @Local(ordinal = 2) int generationShapeHeightFloorDiv) { + if (generationShapeHeightFloorDiv <= 0) { + cir.setReturnValue(CompletableFuture.completedFuture(chunk)); + return; } - cir.setReturnValue(CompletableFuture.supplyAsync( - Util.debugSupplier( - "wgen_fill_noise", - () -> this.populateNoise(blender, structureAccessor, noiseConfig, chunk, minimumYFloorDiv, - generationShapeHeightFloorDiv - ) - ), Util.getMainWorkerExecutor()).whenCompleteAsync((chunk2, throwable) -> { - // Replace an enhanced for loop with a fori loop + cir.setReturnValue(CompletableFuture.supplyAsync(Util.debugSupplier("wgen_fill_noise", () -> { + int startingChunkSectionIndex = chunk.getSectionIndex( + generationShapeHeightFloorDiv * generationShapeConfig.verticalCellBlockCount() - 1 + minimumY); + int minimumYChunkSectionIndex = chunk.getSectionIndex(minimumY); + var chunkSections = chunk.getSectionArray(); for (int chunkSectionIndex = startingChunkSectionIndex; chunkSectionIndex >= minimumYChunkSectionIndex; --chunkSectionIndex) { - chunkSections[chunkSectionIndex].unlock(); + chunkSections[chunkSectionIndex].lock(); } - }, executor)); + + Chunk chunkWithNoise; + try { + chunkWithNoise = this.populateNoise( + blender, structureAccessor, noiseConfig, chunk, minimumYFloorDiv, generationShapeHeightFloorDiv); + } finally { + for (int chunkSectionIndex = startingChunkSectionIndex; chunkSectionIndex >= minimumYChunkSectionIndex; --chunkSectionIndex) { + chunkSections[chunkSectionIndex].unlock(); + } + } + + return chunkWithNoise; + }), Util.getMainWorkerExecutor())); } } diff --git a/common/src/main/java/io/github/steveplays28/noisium/mixin/compat/lithium/LithiumNoiseChunkGeneratorMixin.java b/common/src/main/java/io/github/steveplays28/noisium/mixin/compat/lithium/LithiumNoiseChunkGeneratorMixin.java index 4ffa20e..f5ca34d 100644 --- a/common/src/main/java/io/github/steveplays28/noisium/mixin/compat/lithium/LithiumNoiseChunkGeneratorMixin.java +++ b/common/src/main/java/io/github/steveplays28/noisium/mixin/compat/lithium/LithiumNoiseChunkGeneratorMixin.java @@ -9,6 +9,7 @@ import net.minecraft.world.gen.StructureAccessor; import net.minecraft.world.gen.chunk.Blender; import net.minecraft.world.gen.chunk.ChunkGenerator; +import net.minecraft.world.gen.chunk.GenerationShapeConfig; import net.minecraft.world.gen.chunk.NoiseChunkGenerator; import net.minecraft.world.gen.noise.NoiseConfig; import org.spongepowered.asm.mixin.Mixin; @@ -19,7 +20,6 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import java.util.concurrent.CompletableFuture; -import java.util.concurrent.Executor; @Mixin(NoiseChunkGenerator.class) public abstract class LithiumNoiseChunkGeneratorMixin extends ChunkGenerator { @@ -42,28 +42,38 @@ public LithiumNoiseChunkGeneratorMixin(BiomeSource biomeSource) { return blockState; } - @Inject(method = "populateNoise(Ljava/util/concurrent/Executor;Lnet/minecraft/world/gen/chunk/Blender;Lnet/minecraft/world/gen/noise/NoiseConfig;Lnet/minecraft/world/gen/StructureAccessor;Lnet/minecraft/world/chunk/Chunk;)Ljava/util/concurrent/CompletableFuture;", at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/world/chunk/Chunk;getSectionIndex(I)I", ordinal = 1), cancellable = true) - private void noisium$populateNoiseInject(Executor executor, Blender blender, NoiseConfig noiseConfig, StructureAccessor structureAccessor, Chunk chunk, CallbackInfoReturnable> cir, @Local(ordinal = 1) int minimumYFloorDiv, @Local(ordinal = 2) int generationShapeHeightFloorDiv, @Local(ordinal = 3) int startingChunkSectionIndex, @Local(ordinal = 4) int minimumYChunkSectionIndex) { - var chunkSections = chunk.getSectionArray(); - for (int chunkSectionIndex = startingChunkSectionIndex; chunkSectionIndex >= minimumYChunkSectionIndex; --chunkSectionIndex) { - chunkSections[chunkSectionIndex].lock(); + @Inject(method = "populateNoise(Lnet/minecraft/world/gen/chunk/Blender;Lnet/minecraft/world/gen/noise/NoiseConfig;Lnet/minecraft/world/gen/StructureAccessor;Lnet/minecraft/world/chunk/Chunk;)Ljava/util/concurrent/CompletableFuture;", at = @At(value = "RETURN", shift = At.Shift.BEFORE), cancellable = true) + private void noisium$populateNoiseInject(Blender blender, NoiseConfig noiseConfig, StructureAccessor structureAccessor, Chunk chunk, CallbackInfoReturnable> cir, @Local GenerationShapeConfig generationShapeConfig, @Local(ordinal = 0) int minimumY, @Local(ordinal = 1) int minimumYFloorDiv, @Local(ordinal = 2) int generationShapeHeightFloorDiv) { + if (generationShapeHeightFloorDiv <= 0) { + cir.setReturnValue(CompletableFuture.completedFuture(chunk)); + return; } - cir.setReturnValue(CompletableFuture.supplyAsync( - Util.debugSupplier( - "wgen_fill_noise", - () -> this.populateNoise(blender, structureAccessor, noiseConfig, chunk, minimumYFloorDiv, - generationShapeHeightFloorDiv - ) - ), Util.getMainWorkerExecutor()).whenCompleteAsync((chunk2, throwable) -> { - // Replace an enhanced for loop with a fori loop - // Also run calculateCounts() on every chunk section to add Lithium compatibility + cir.setReturnValue(CompletableFuture.supplyAsync(Util.debugSupplier("wgen_fill_noise", () -> { + int startingChunkSectionIndex = chunk.getSectionIndex( + generationShapeHeightFloorDiv * generationShapeConfig.verticalCellBlockCount() - 1 + minimumY); + int minimumYChunkSectionIndex = chunk.getSectionIndex(minimumY); + var chunkSections = chunk.getSectionArray(); for (int chunkSectionIndex = startingChunkSectionIndex; chunkSectionIndex >= minimumYChunkSectionIndex; --chunkSectionIndex) { - var chunkSection = chunkSections[chunkSectionIndex]; + chunkSections[chunkSectionIndex].lock(); + } + + Chunk chunkWithNoise; + try { + chunkWithNoise = this.populateNoise( + blender, structureAccessor, noiseConfig, chunk, minimumYFloorDiv, generationShapeHeightFloorDiv); + } finally { + // Replace an enhanced for loop with a fori loop + // Also run calculateCounts() on every chunk section to add Lithium compatibility + for (int chunkSectionIndex = startingChunkSectionIndex; chunkSectionIndex >= minimumYChunkSectionIndex; --chunkSectionIndex) { + var chunkSection = chunkSections[chunkSectionIndex]; - chunkSection.calculateCounts(); - chunkSection.unlock(); + chunkSection.calculateCounts(); + chunkSection.unlock(); + } } - }, executor)); + + return chunkWithNoise; + }), Util.getMainWorkerExecutor())); } } diff --git a/common/src/main/resources/noisium-common.mixins.json b/common/src/main/resources/noisium-common.mixins.json index de7adc6..44cce3b 100644 --- a/common/src/main/resources/noisium-common.mixins.json +++ b/common/src/main/resources/noisium-common.mixins.json @@ -2,7 +2,7 @@ "required": true, "minVersion": "0.8", "package": "io.github.steveplays28.noisium.mixin", - "compatibilityLevel": "JAVA_17", + "compatibilityLevel": "JAVA_21", "plugin": "io.github.steveplays28.noisium.mixin.NoisiumMixinPlugin", "mixins": [ "ChainedBlockSourceMixin", diff --git a/gradle.properties b/gradle.properties index a2d4c76..b990480 100644 --- a/gradle.properties +++ b/gradle.properties @@ -13,15 +13,15 @@ mod_name=Noisium mod_description=Optimises worldgen performance for a better gameplay experience. mod_license=LGPL-3.0 mod_version=2.1.0 -supported_minecraft_version=>=1.20.5 <=1.20.6 -supported_minecraft_version_name=1.20.5-1.20.6 +supported_minecraft_version=1.21 +supported_minecraft_version_name=1.21 # Multiloader properties architectury_plugin_version=3.4-SNAPSHOT architectury_loom_version=1.6-SNAPSHOT shadow_plugin_version=7.1.2 forgix_plugin_version=1.2.6 -minecraft_version=1.20.5 +minecraft_version=1.21 java_version=21 enabled_platforms=fabric,neoforge @@ -31,13 +31,13 @@ modrinth_project_id=KuNKN7d2 # Fabric properties # Check these on https://modmuss50.me/fabric.html -yarn_mappings=1.20.5+build.1 -fabric_loader_version=0.15.6 +yarn_mappings=1.21+build.2 +fabric_loader_version=0.15.11 # NeoForge properties -neoforge_version=20.5.21-beta +neoforge_version=21.0.20-beta # Dependencies mixin_extras_version=0.3.5 -fabric_api_version=0.97.8+1.20.5 -mod_menu_version=10.0.0-beta.1 +fabric_api_version=0.100.1+1.21 +mod_menu_version=11.0.0-beta.2 diff --git a/neoforge/build.gradle b/neoforge/build.gradle index 52c46a1..f308298 100644 --- a/neoforge/build.gradle +++ b/neoforge/build.gradle @@ -31,9 +31,6 @@ configurations { dependencies { neoForge "net.neoforged:neoforge:${rootProject.neoforge_version}" - // Mixin Extras - implementation(annotationProcessor("io.github.llamalad7:mixinextras-forge:${project.mixin_extras_version}")) - common(project(path: ":common", configuration: "namedElements")) { transitive false } shadowCommon(project(path: ":common", configuration: "transformProductionNeoForge")) { transitive = false } }