From b1e5aecc1e5fc5f416f74f36d6a063a04e2843ad Mon Sep 17 00:00:00 2001 From: Harley Date: Fri, 2 Aug 2024 16:38:51 +0100 Subject: [PATCH] Port to NeoForge 1.21 --- README.md | 5 +- build.gradle.kts | 103 ++++++------------ buildSrc/build.gradle.kts | 18 --- gradle.properties | 12 +- gradle/wrapper/gradle-wrapper.properties | 2 +- settings.gradle.kts | 11 ++ .../lumien/chunkanimator/ChunkAnimator.java | 30 ++--- .../lumien/chunkanimator/MixinConnector.java | 29 ----- .../chunkanimator/config/AnimationMode.java | 2 +- .../config/ChunkAnimatorConfig.java | 16 ++- .../handler/AnimationContext.java | 8 +- .../handler/AnimationHandler.java | 22 ++-- .../chunkanimator/handler/AsmHandler.java | 63 ----------- .../handler/LevelEventHandler.java | 8 +- .../handler/PreRenderContext.java | 8 +- .../mixin/LevelRendererMixin.java | 35 +++--- .../mixin/OptiFineLevelRendererMixin.java | 100 ----------------- ...hunkMixin.java => RenderSectionMixin.java} | 10 +- .../util/OptiFineUniform3fWrapper.java | 34 ------ .../chunkanimator/util/UniformWrapper.java | 7 -- .../util/VanillaUniformWrapper.java | 18 --- .../resources/META-INF/accesstransformer.cfg | 2 - .../{mods.toml => neoforge.mods.toml} | 21 ++-- src/main/resources/chunkanimator.mixins.json | 4 +- .../chunkanimator.optifine.mixins.json | 11 -- version_info.json | 5 + 26 files changed, 139 insertions(+), 445 deletions(-) delete mode 100644 buildSrc/build.gradle.kts create mode 100644 settings.gradle.kts delete mode 100644 src/main/java/lumien/chunkanimator/MixinConnector.java delete mode 100644 src/main/java/lumien/chunkanimator/handler/AsmHandler.java delete mode 100644 src/main/java/lumien/chunkanimator/mixin/OptiFineLevelRendererMixin.java rename src/main/java/lumien/chunkanimator/mixin/{RenderChunkMixin.java => RenderSectionMixin.java} (65%) delete mode 100644 src/main/java/lumien/chunkanimator/util/OptiFineUniform3fWrapper.java delete mode 100644 src/main/java/lumien/chunkanimator/util/UniformWrapper.java delete mode 100644 src/main/java/lumien/chunkanimator/util/VanillaUniformWrapper.java delete mode 100644 src/main/resources/META-INF/accesstransformer.cfg rename src/main/resources/META-INF/{mods.toml => neoforge.mods.toml} (66%) delete mode 100644 src/main/resources/chunkanimator.optifine.mixins.json diff --git a/README.md b/README.md index a08251d..58fa594 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,9 @@ This can be downloaded from the [the CurseForge](https://www.curseforge.com/mine When new chunks are loaded in vanilla minecraft they simply "appear instantly", with this mod they can be animated to appear from below, above, or the side. This mod shouldn't impact FPS considerably because all it does is render chunks "somewhere else". +## NeoForge +As of 1.21, this project is only on NeoForge. Unfortunately this is the only mod loader I have the time to support for the time being. + ## Usage Once you install this mod it will be in mode 0, that means that all chunks will appear from below. In the config file you can switch between 5 modes and also change the duration of the animation. In addition you can also enable an option that makes chunks that are close to the player not animate. @@ -22,7 +25,7 @@ You can also change the easing function that is used in the animation, [this](ht To learn more about how the animations can be configured, visit [this page](https://github.com/Harleyoc1/ChunkAnimator/wiki/Config) on the config. ## OptiFine -OptiFine is supported, however for the chunks to be animated you will need to make sure the `render regions` option is disabled (set to `false`). This can be found under the `Performance` screen in `Video Settings`, or as `ofRenderRegions` in the `optionsof.txt` in your Minecraft directory. +OptiFine is supported for versions **below** 1.21, however for the chunks to be animated you will need to make sure the `render regions` option is disabled (set to `false`). This can be found under the `Performance` screen in `Video Settings`, or as `ofRenderRegions` in the `optionsof.txt` in your Minecraft directory. ## Bugs and Feature Requests If you find any bugs or have an idea for a new feature, please [open a new issue](https://github.com/Harleyoc1/ChunkAnimator/issues/new/choose) using the relevant template. For any other discussion or support, please use the [Discussions tab](https://github.com/Harleyoc1/ChunkAnimator/discussions). diff --git a/build.gradle.kts b/build.gradle.kts index f429c12..5a04b18 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,8 +1,4 @@ -import com.google.gson.Gson -import com.google.gson.JsonObject import com.matthewprenger.cursegradle.CurseProject -import net.minecraftforge.gradle.common.util.RunConfig -import java.io.InputStreamReader import java.time.Instant import java.time.format.DateTimeFormatter @@ -13,15 +9,17 @@ apply(from = "https://gist.githubusercontent.com/Harleyoc1/4d23d4e991e868d98d548 plugins { id("java") - id("net.minecraftforge.gradle") - id("org.parchmentmc.librarian.forgegradle") - id("org.spongepowered.mixin") + id("net.neoforged.gradle.userdev") version "7.0.145" id("idea") id("maven-publish") id("com.matthewprenger.cursegradle") version "1.4.0" id("com.modrinth.minotaur") version "2.+" } +tasks.named("wrapper", Wrapper::class).configure { + distributionType = Wrapper.DistributionType.BIN +} + val modName = property("modName") val modId = property("modId") val modVersion = property("modVersion") @@ -31,50 +29,42 @@ val mcVersion = property("mcVersion") version = "$mcVersion-$modVersion" group = property("group") -minecraft { - mappings("parchment", "${property("mappingsVersion")}-$mcVersion") - accessTransformer(file("src/main/resources/META-INF/accesstransformer.cfg")) - - runs { - create("client") { - workingDirectory = file("run").absolutePath - - this.applyDefaultConfiguration() - - if (project.hasProperty("mcUuid")) { - args("--uuid", property("mcUuid")) - } - if (project.hasProperty("mcUsername")) { - args("--username", property("mcUsername")) - } - if (project.hasProperty("mcAccessToken")) { - args("--accessToken", property("mcAccessToken")) - } - } +base { + archivesName.set(modName) +} - create("server") { - workingDirectory = file("run-server").absolutePath +runs { + configureEach { + systemProperty("forge.logging.markers", "SCAN,REGISTRIES,REGISTRYDUMP") + systemProperty("forge.logging.console.level", "debug") - this.applyDefaultConfiguration() - } + modSource(project.sourceSets["main"]) } } -mixin { - add(sourceSets.main.get(), "$modId.refmap.json") -} - dependencies { - minecraft("net.minecraftforge:forge:$mcVersion-${property("forgeVersion")}") - - annotationProcessor("org.spongepowered:mixin:${property("mixinVersion")}:processor") + implementation("net.neoforged:neoforge:${property("forgeVersion")}") } java { withSourcesJar() toolchain { - languageVersion.set(JavaLanguageVersion.of(17)) + languageVersion.set(JavaLanguageVersion.of(21)) + } +} + +tasks.withType(ProcessResources::class).configureEach { + val replaceProperties = mapOf( + "mcVersionRange" to project.findProperty("mcVersionRange"), + "forgeVersionRange" to project.findProperty("forgeVersionRange"), + "loaderVersionRange" to project.findProperty("loaderVersionRange"), + "modId" to project.findProperty("modId"), + "modVersion" to project.findProperty("modVersion") + ) + inputs.properties(replaceProperties) + filesMatching("META-INF/neoforge.mods.toml") { + expand(replaceProperties) } } @@ -86,12 +76,10 @@ tasks.jar { "Implementation-Title" to project.name, "Implementation-Version" to project.version, "Implementation-Vendor" to "Harley O'Connor", // I am the author of this port. - "Implementation-Timestamp" to DateTimeFormatter.ISO_INSTANT.format(Instant.now()), - "MixinConnector" to "lumien.chunkanimator.MixinConnector" + "Implementation-Timestamp" to DateTimeFormatter.ISO_INSTANT.format(Instant.now()) ) archiveBaseName.set(modName) - finalizedBy("reobfJar") } tasks.withType { @@ -146,16 +134,6 @@ publishing { } } -fun readRawChangelog(): String? { - val versionInfoFile = file("version_info.json") - val jsonObject = Gson().fromJson(InputStreamReader(versionInfoFile.inputStream()), JsonObject::class.java) - return jsonObject - ?.get(mcVersion)?.asJsonObject - ?.get(project.version.toString())?.asString -} - -val rawChangelog = readRawChangelog()!! - curseforge { if (!project.hasProperty("curseApiKey")) { project.logger.warn("API Key for CurseForge not detected; uploading will be disabled.") @@ -169,7 +147,7 @@ curseforge { addGameVersion(mcVersion) - changelog = rawChangelog + changelog = "Changelog pending." changelogType = "markdown" releaseType = optionalProperty("versionType") ?: "release" @@ -189,22 +167,5 @@ modrinth { versionType.set(optionalProperty("versionType") ?: "release") uploadFile.set(tasks.jar.get()) gameVersions.add(mcVersion) - changelog.set(rawChangelog) + changelog.set("Changelog pending.") } - -fun RunConfig.applyDefaultConfiguration() { - property("forge.logging.markers", "SCAN,REGISTRIES,REGISTRYDUMP") - property("forge.logging.console.level", "debug") - - property("mixin.debug.export", "true") - property("mixin.env.remapRefMap", "true") - property("mixin.env.refMapRemappingFile", "${buildDir}/createSrgToMcp/output.srg") - - args("-mixin.config=$modId.mixins.json") - - mods { - create(modId) { - source(sourceSets.main.get()) - } - } -} \ No newline at end of file diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts deleted file mode 100644 index e252e78..0000000 --- a/buildSrc/build.gradle.kts +++ /dev/null @@ -1,18 +0,0 @@ -plugins { - `kotlin-dsl` - `java-library` -} - -repositories { - mavenCentral() - maven("https://files.minecraftforge.net/maven") - maven("https://maven.parchmentmc.org") - maven("https://repo.spongepowered.org/repository/maven-public/") -} - -dependencies { - implementation("com.google.code.gson:gson:2.8.8") - implementation("net.minecraftforge.gradle:ForgeGradle:5.1.+") - implementation("org.parchmentmc:librarian:1.+") - implementation("org.spongepowered:mixingradle:0.7-SNAPSHOT") -} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 421b9fc..175fb7c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,11 +1,17 @@ +neogradle.subsystems.parchment.minecraftVersion=1.21 +neogradle.subsystems.parchment.mappingsVersion=2024.07.07 + modName=ChunkAnimator modId=chunkanimator modVersion=1.3.7 group=lumien.chunkanimator -mcVersion=1.20.1 -forgeVersion=47.0.1 -mappingsVersion=1.19.3-2023.03.12 +mcVersion=1.21 +mcVersionRange=[1.21,1.22) + +forgeVersion=21.0.148 +forgeVersionRange=[21.0.148,) +loaderVersionRange=[4,) mixinVersion=0.8.5 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index ceccc3a..19cfad9 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-all.zip diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 0000000..6c6d6d8 --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1,11 @@ +pluginManagement { + repositories { + mavenLocal() + gradlePluginPortal() + maven("https://maven.neoforged.net/releases") + } +} + +plugins { + id("org.gradle.toolchains.foojay-resolver-convention") version "0.8.0" +} \ No newline at end of file diff --git a/src/main/java/lumien/chunkanimator/ChunkAnimator.java b/src/main/java/lumien/chunkanimator/ChunkAnimator.java index fad27dd..0b5e2a9 100644 --- a/src/main/java/lumien/chunkanimator/ChunkAnimator.java +++ b/src/main/java/lumien/chunkanimator/ChunkAnimator.java @@ -3,15 +3,12 @@ import lumien.chunkanimator.config.ChunkAnimatorConfig; import lumien.chunkanimator.handler.AnimationHandler; import lumien.chunkanimator.handler.LevelEventHandler; -import net.minecraft.client.renderer.chunk.ChunkRenderDispatcher; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.fml.IExtensionPoint; -import net.minecraftforge.fml.ModLoadingContext; -import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.fml.config.ModConfig; -import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; -import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; -import net.minecraftforge.network.NetworkConstants; +import net.neoforged.bus.api.IEventBus; +import net.neoforged.fml.ModContainer; +import net.neoforged.fml.common.Mod; +import net.neoforged.fml.config.ModConfig; +import net.neoforged.fml.event.lifecycle.FMLClientSetupEvent; +import net.neoforged.neoforge.common.NeoForge; /** * @author lumien231 @@ -25,28 +22,23 @@ public final class ChunkAnimator { public AnimationHandler animationHandler; - public ChunkAnimator() { + public ChunkAnimator(IEventBus modBus, ModContainer modContainer) { instance = this; - final var loadingContext = ModLoadingContext.get(); - loadingContext.registerExtensionPoint( - IExtensionPoint.DisplayTest.class, - () -> new IExtensionPoint.DisplayTest(() -> NetworkConstants.IGNORESERVERONLY, (a, b) -> true) - ); - loadingContext.registerConfig(ModConfig.Type.CLIENT, ChunkAnimatorConfig.SPEC); + modContainer.registerConfig(ModConfig.Type.CLIENT, ChunkAnimatorConfig.SPEC); - FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setupClient); + modBus.addListener(this::setupClient); } /** - * Performs setup tasks that should only be run on the client. {@link ChunkRenderDispatcher.RenderChunk#setOrigin(int, int, int)} + * Performs setup tasks that should only be run on the client. {@link net.minecraft.client.renderer.chunk.SectionRenderDispatcher.RenderSection#setOrigin(int, int, int)} * * @param event The {@link FMLClientSetupEvent} instance. */ private void setupClient(final FMLClientSetupEvent event) { this.animationHandler = new AnimationHandler(); - MinecraftForge.EVENT_BUS.register(new LevelEventHandler()); + NeoForge.EVENT_BUS.register(new LevelEventHandler()); } } diff --git a/src/main/java/lumien/chunkanimator/MixinConnector.java b/src/main/java/lumien/chunkanimator/MixinConnector.java deleted file mode 100644 index 9b584e8..0000000 --- a/src/main/java/lumien/chunkanimator/MixinConnector.java +++ /dev/null @@ -1,29 +0,0 @@ -package lumien.chunkanimator; - -import org.spongepowered.asm.mixin.Mixins; -import org.spongepowered.asm.mixin.connect.IMixinConnector; - -/** - * @author Harley O'Connor - */ -public final class MixinConnector implements IMixinConnector { - - @Override - public void connect() { - if (this.isOptiFinePresent()) { - Mixins.addConfiguration("chunkanimator.optifine.mixins.json"); - } else { - Mixins.addConfiguration("chunkanimator.mixins.json"); - } - } - - private boolean isOptiFinePresent() { - try { - Class.forName("optifine.OptiFineTransformationService"); - return true; - } catch (ClassNotFoundException e) { - return false; - } - } - -} diff --git a/src/main/java/lumien/chunkanimator/config/AnimationMode.java b/src/main/java/lumien/chunkanimator/config/AnimationMode.java index 1e843de..571e070 100644 --- a/src/main/java/lumien/chunkanimator/config/AnimationMode.java +++ b/src/main/java/lumien/chunkanimator/config/AnimationMode.java @@ -54,7 +54,7 @@ public enum AnimationMode { HORIZONTAL_SLIDE_ALTERNATE( (context, data) -> data.chunkFacing = getChunkFacing(getZeroedPlayerPos(Objects.requireNonNull(Minecraft.getInstance().player)) - .subtract(getZeroedCenteredChunkPos(context.renderChunk().getOrigin())) + .subtract(getZeroedCenteredChunkPos(context.renderSection().getOrigin())) ), HORIZONTAL_SLIDE.contextConsumer ); diff --git a/src/main/java/lumien/chunkanimator/config/ChunkAnimatorConfig.java b/src/main/java/lumien/chunkanimator/config/ChunkAnimatorConfig.java index 16e9fb2..aa8431f 100644 --- a/src/main/java/lumien/chunkanimator/config/ChunkAnimatorConfig.java +++ b/src/main/java/lumien/chunkanimator/config/ChunkAnimatorConfig.java @@ -1,8 +1,6 @@ package lumien.chunkanimator.config; -import net.minecraftforge.common.ForgeConfigSpec; -import net.minecraftforge.common.ForgeConfigSpec.BooleanValue; -import net.minecraftforge.common.ForgeConfigSpec.IntValue; +import net.neoforged.neoforge.common.ModConfigSpec; /** * @author lumien231 @@ -10,21 +8,21 @@ public final class ChunkAnimatorConfig { /** The animation mode - controls how the chunks should be animated. */ - public static final ForgeConfigSpec.EnumValue MODE; + public static final ModConfigSpec.EnumValue MODE; /** The easing function - controls which easing function should be used. */ - public static final ForgeConfigSpec.EnumValue EASING_FUNCTION; + public static final ModConfigSpec.EnumValue EASING_FUNCTION; /** The animation duration - controls how long the animation should last (in milliseconds). */ - public static final IntValue ANIMATION_DURATION; + public static final ModConfigSpec.IntValue ANIMATION_DURATION; /** Disable around player - disables animation of chunks near the player. */ - public static final BooleanValue DISABLE_AROUND_PLAYER; + public static final ModConfigSpec.BooleanValue DISABLE_AROUND_PLAYER; - public static final ForgeConfigSpec SPEC; + public static final ModConfigSpec SPEC; static { - final ForgeConfigSpec.Builder builder = new ForgeConfigSpec.Builder(); + final ModConfigSpec.Builder builder = new ModConfigSpec.Builder(); MODE = builder.comment(""" Defines how the chunks should be animated. diff --git a/src/main/java/lumien/chunkanimator/handler/AnimationContext.java b/src/main/java/lumien/chunkanimator/handler/AnimationContext.java index 8a7b75b..a1c6dd6 100644 --- a/src/main/java/lumien/chunkanimator/handler/AnimationContext.java +++ b/src/main/java/lumien/chunkanimator/handler/AnimationContext.java @@ -1,8 +1,8 @@ package lumien.chunkanimator.handler; -import lumien.chunkanimator.util.UniformWrapper; +import com.mojang.blaze3d.shaders.Uniform; import net.minecraft.client.multiplayer.ClientLevel; -import net.minecraft.client.renderer.chunk.ChunkRenderDispatcher; +import net.minecraft.client.renderer.chunk.SectionRenderDispatcher; import net.minecraft.core.BlockPos; /** @@ -11,8 +11,8 @@ * @author Harley O'Connor */ public record AnimationContext( - ChunkRenderDispatcher.RenderChunk renderChunk, - UniformWrapper uniform, + SectionRenderDispatcher.RenderSection renderSection, + Uniform uniform, float x, float y, float z, diff --git a/src/main/java/lumien/chunkanimator/handler/AnimationHandler.java b/src/main/java/lumien/chunkanimator/handler/AnimationHandler.java index e93c2a5..cc6348b 100644 --- a/src/main/java/lumien/chunkanimator/handler/AnimationHandler.java +++ b/src/main/java/lumien/chunkanimator/handler/AnimationHandler.java @@ -4,12 +4,12 @@ import lumien.chunkanimator.config.ChunkAnimatorConfig; import net.minecraft.client.Minecraft; import net.minecraft.client.player.LocalPlayer; -import net.minecraft.client.renderer.chunk.ChunkRenderDispatcher; +import net.minecraft.client.renderer.chunk.SectionRenderDispatcher; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.core.Vec3i; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; import java.util.Objects; import java.util.WeakHashMap; @@ -23,10 +23,10 @@ public final class AnimationHandler { private final Minecraft mc = Minecraft.getInstance(); - private final WeakHashMap timeStamps = new WeakHashMap<>(); + private final WeakHashMap timeStamps = new WeakHashMap<>(); public void preRender(PreRenderContext context) { - final var animationData = timeStamps.get(context.renderChunk()); + final var animationData = timeStamps.get(context.renderSection()); if (animationData == null) { context.uniform().set(context.x(), context.y(), context.z()); @@ -49,23 +49,23 @@ public void preRender(PreRenderContext context) { if (timeDif < animationDuration) { ChunkAnimatorConfig.MODE.get().contextConsumer().accept(new AnimationContext( - context.renderChunk(), + context.renderSection(), context.uniform(), context.x(), context.y(), context.z(), animationData, - context.renderChunk().getOrigin(), + context.renderSection().getOrigin(), timeDif, AnimationContext.LevelContext.from(Objects.requireNonNull(this.mc.level)) )); } else { context.uniform().set(context.x(), context.y(), context.z()); - this.timeStamps.remove(context.renderChunk()); + this.timeStamps.remove(context.renderSection()); } } - public void setOrigin(final ChunkRenderDispatcher.RenderChunk renderChunk, final BlockPos pos) { + public void setOrigin(final SectionRenderDispatcher.RenderSection renderSection, final BlockPos pos) { if (this.mc.player == null) return; @@ -73,10 +73,10 @@ public void setOrigin(final ChunkRenderDispatcher.RenderChunk renderChunk, final final BlockPos zeroedCenteredChunkPos = getZeroedCenteredChunkPos(pos); if (!ChunkAnimatorConfig.DISABLE_AROUND_PLAYER.get() || zeroedPlayerPos.distSqr(zeroedCenteredChunkPos) > (64 * 64)) { - timeStamps.put(renderChunk, new AnimationData(-1L, ChunkAnimatorConfig.MODE.get() == AnimationMode.HORIZONTAL_SLIDE ? + timeStamps.put(renderSection, new AnimationData(-1L, ChunkAnimatorConfig.MODE.get() == AnimationMode.HORIZONTAL_SLIDE ? getChunkFacing(zeroedPlayerPos.subtract(zeroedCenteredChunkPos)) : null)); } else { - timeStamps.remove(renderChunk); + timeStamps.remove(renderSection); } } diff --git a/src/main/java/lumien/chunkanimator/handler/AsmHandler.java b/src/main/java/lumien/chunkanimator/handler/AsmHandler.java deleted file mode 100644 index e9b1a85..0000000 --- a/src/main/java/lumien/chunkanimator/handler/AsmHandler.java +++ /dev/null @@ -1,63 +0,0 @@ -package lumien.chunkanimator.handler; - -import com.mojang.blaze3d.shaders.Uniform; -import com.mojang.blaze3d.vertex.PoseStack; -import lumien.chunkanimator.ChunkAnimator; -import lumien.chunkanimator.util.VanillaUniformWrapper; -import net.minecraft.client.renderer.LevelRenderer; -import net.minecraft.client.renderer.RenderType; -import net.minecraft.client.renderer.chunk.ChunkRenderDispatcher; -import net.minecraft.core.BlockPos; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; -import org.joml.Matrix4f; - -/** - * This class acts as a "middle man" between Minecraft's transformed classes and - * the {@link AnimationHandler}. - * - * @author lumien231 - */ -@OnlyIn(Dist.CLIENT) -public final class AsmHandler { - - private AsmHandler() {} - - private static final AnimationHandler HANDLER = ChunkAnimator.instance.animationHandler; - - /** - * Calls {@link AnimationHandler#setOrigin(ChunkRenderDispatcher.RenderChunk, BlockPos)} with - * the given parameters. - * - *

The {@link ChunkRenderDispatcher.RenderChunk} transformer invokes this method, inserting - * the call in {@link ChunkRenderDispatcher.RenderChunk#setOrigin(int, int, int)}.

- * - * @param renderChunk The {@link ChunkRenderDispatcher.RenderChunk} instance. - * @param x The {@code x-coordinate} for the origin. - * @param y The {@code y-coordinate} for the origin. - * @param z The {@code z-coordinate} for the origin. - */ - public static void setOrigin(ChunkRenderDispatcher.RenderChunk renderChunk, int x, int y, int z) { - HANDLER.setOrigin(renderChunk, new BlockPos(x, y, z)); - } - - /** - * Calls {@link AnimationHandler#preRender(PreRenderContext)} - * with the given parameters. - * - *

The {@link LevelRenderer} transformer invokes this method, replacing the default - * {@link Uniform#set(float, float, float)} call in - * {@link LevelRenderer#renderChunkLayer(RenderType, PoseStack, double, double, double, Matrix4f)}. - * - * @param uniform The chunk offset {@link Uniform} object. - * @param x The final x-coordinate for the chunk (where it should end up). - * @param y The final y-coordinate for the chunk (where it should end up). - * @param z The final z-coordinate for the chunk (where it should end up). - * @param renderChunk The {@link ChunkRenderDispatcher.RenderChunk} instance. - */ - public static void preRenderChunk(final Uniform uniform, final float x, final float y, final float z, - final ChunkRenderDispatcher.RenderChunk renderChunk) { - HANDLER.preRender(new PreRenderContext(renderChunk, new VanillaUniformWrapper(uniform), x, y, z)); - } - -} diff --git a/src/main/java/lumien/chunkanimator/handler/LevelEventHandler.java b/src/main/java/lumien/chunkanimator/handler/LevelEventHandler.java index 01e17eb..ea88464 100644 --- a/src/main/java/lumien/chunkanimator/handler/LevelEventHandler.java +++ b/src/main/java/lumien/chunkanimator/handler/LevelEventHandler.java @@ -2,10 +2,10 @@ import lumien.chunkanimator.ChunkAnimator; import net.minecraft.client.multiplayer.ClientLevel; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; -import net.minecraftforge.event.level.LevelEvent; -import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; +import net.neoforged.bus.api.SubscribeEvent; +import net.neoforged.neoforge.event.level.LevelEvent; /** * Handles {@link LevelEvent}s, updating {@link AnimationHandler} properties when the world diff --git a/src/main/java/lumien/chunkanimator/handler/PreRenderContext.java b/src/main/java/lumien/chunkanimator/handler/PreRenderContext.java index 89cfc38..cb7d90f 100644 --- a/src/main/java/lumien/chunkanimator/handler/PreRenderContext.java +++ b/src/main/java/lumien/chunkanimator/handler/PreRenderContext.java @@ -1,8 +1,8 @@ package lumien.chunkanimator.handler; -import lumien.chunkanimator.util.UniformWrapper; +import com.mojang.blaze3d.shaders.Uniform; import net.minecraft.client.renderer.LevelRenderer; -import net.minecraft.client.renderer.chunk.ChunkRenderDispatcher; +import net.minecraft.client.renderer.chunk.SectionRenderDispatcher; /** * Holds context gathered from the {@link LevelRenderer} required for pre-rendering @@ -11,8 +11,8 @@ * @author Harley O'Connor */ public record PreRenderContext( - ChunkRenderDispatcher.RenderChunk renderChunk, - UniformWrapper uniform, + SectionRenderDispatcher.RenderSection renderSection, + Uniform uniform, float x, float y, float z diff --git a/src/main/java/lumien/chunkanimator/mixin/LevelRendererMixin.java b/src/main/java/lumien/chunkanimator/mixin/LevelRendererMixin.java index 34433ff..2420e57 100644 --- a/src/main/java/lumien/chunkanimator/mixin/LevelRendererMixin.java +++ b/src/main/java/lumien/chunkanimator/mixin/LevelRendererMixin.java @@ -1,16 +1,14 @@ package lumien.chunkanimator.mixin; import com.mojang.blaze3d.shaders.Uniform; -import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.VertexBuffer; import it.unimi.dsi.fastutil.objects.ObjectListIterator; import lumien.chunkanimator.ChunkAnimator; import lumien.chunkanimator.handler.PreRenderContext; -import lumien.chunkanimator.util.VanillaUniformWrapper; import net.minecraft.client.renderer.LevelRenderer; import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.ShaderInstance; -import net.minecraft.client.renderer.chunk.ChunkRenderDispatcher; +import net.minecraft.client.renderer.chunk.SectionRenderDispatcher; import net.minecraft.core.BlockPos; import org.joml.Matrix4f; import org.spongepowered.asm.mixin.Mixin; @@ -26,34 +24,33 @@ @Mixin(LevelRenderer.class) public final class LevelRendererMixin { - @Redirect(method = "renderChunkLayer", at = @At( + @Redirect(method = "renderSectionLayer", at = @At( value = "INVOKE", target = "Lcom/mojang/blaze3d/shaders/Uniform;set(FFF)V" )) private void preventDefaultOffset(Uniform chunkOffset, float x, float y, float z) { - // Since this doesn't allow local capture and we need access to the renderChunk we simply do nothing here - // and replace this with our own logic in #preRenderChunk. + // Since this doesn't allow local capture and we need access to the renderSection we simply do nothing here + // and replace this with our own logic in #preRenderSection. } - @Inject(method = "renderChunkLayer", at = @At( + @Inject(method = "renderSectionLayer", at = @At( value = "INVOKE", shift = At.Shift.BEFORE, target = "Lcom/mojang/blaze3d/shaders/Uniform;upload()V" ), locals = LocalCapture.CAPTURE_FAILHARD) - private void preRenderChunk(RenderType renderType, PoseStack poseStack, double camX, double camY, double camZ, - Matrix4f projectionMatrix, CallbackInfo ci, boolean notTranslucent, - ObjectListIterator renderChunkIterator, - ShaderInstance shaderInstance, Uniform chunkOffset, - LevelRenderer.RenderChunkInfo renderChunkInfo, - ChunkRenderDispatcher.RenderChunk renderChunk, VertexBuffer chunkVertexBuffer, - BlockPos chunkOrigin) { + private void preRenderSection(RenderType renderType, double camX, double camY, double camZ, + Matrix4f frustrumMatrix, Matrix4f projectionMatrix, CallbackInfo ci, boolean notTranslucent, + ObjectListIterator renderSectionIterator, + ShaderInstance shaderInstance, Uniform chunkOffset, + SectionRenderDispatcher.RenderSection renderSection, + VertexBuffer sectionVertexBuffer, BlockPos sectionOrigin) { ChunkAnimator.instance.animationHandler.preRender( new PreRenderContext( - renderChunk, - new VanillaUniformWrapper(chunkOffset), - (float) (chunkOrigin.getX() - camX), - (float) (chunkOrigin.getY() - camY), - (float) (chunkOrigin.getZ() - camZ) + renderSection, + chunkOffset, + (float) (sectionOrigin.getX() - camX), + (float) (sectionOrigin.getY() - camY), + (float) (sectionOrigin.getZ() - camZ) ) ); } diff --git a/src/main/java/lumien/chunkanimator/mixin/OptiFineLevelRendererMixin.java b/src/main/java/lumien/chunkanimator/mixin/OptiFineLevelRendererMixin.java deleted file mode 100644 index dd7ceda..0000000 --- a/src/main/java/lumien/chunkanimator/mixin/OptiFineLevelRendererMixin.java +++ /dev/null @@ -1,100 +0,0 @@ -package lumien.chunkanimator.mixin; - -import com.mojang.blaze3d.shaders.Uniform; -import org.objectweb.asm.Opcodes; -import lumien.chunkanimator.ChunkAnimator; -import lumien.chunkanimator.handler.PreRenderContext; -import lumien.chunkanimator.util.OptiFineUniform3fWrapper; -import lumien.chunkanimator.util.VanillaUniformWrapper; -import net.minecraft.client.renderer.LevelRenderer; -import net.minecraft.client.renderer.chunk.ChunkRenderDispatcher; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Coerce; -import org.spongepowered.asm.mixin.injection.Redirect; - -import java.lang.reflect.Field; - -/** - * {@link lumien.chunkanimator.mixin.LevelRendererMixin} equivalent for OptiFine. - * - * @author Harley O'Connor - */ -@Mixin(LevelRenderer.class) -public final class OptiFineLevelRendererMixin { - - private static final Field CHUNK_OFFSET_UNIFORM_FIELD; - - static { - try { - Class shadersClass = Class.forName("net.optifine.shaders.Shaders"); - CHUNK_OFFSET_UNIFORM_FIELD = shadersClass.getField("uniform_chunkOffset"); - } catch (ClassNotFoundException | NoSuchFieldException e) { - throw new RuntimeException(e); - } - } - - private ChunkRenderDispatcher.RenderChunk currentRenderChunk; - - /** - * Gets the current render chunk, saving it in {@link #currentRenderChunk} for use by the offset overrides. - * This is done because {@link Redirect} cannot capture locals. - */ - @Redirect(method = "renderChunkLayer", at = @At( - value = "FIELD", - target = "Lnet/minecraft/client/renderer/LevelRenderer$RenderChunkInfo;chunk:Lnet/minecraft/client/renderer/chunk/ChunkRenderDispatcher$RenderChunk;", - opcode = Opcodes.GETFIELD, - ordinal = 3 - )) - private ChunkRenderDispatcher.RenderChunk getRenderChunk(LevelRenderer.RenderChunkInfo owner) { - currentRenderChunk = owner.chunk; - return owner.chunk; - } - - /** - * Sets the chunk offset uniform with a modified x/y/z values, creating the animation. - */ - @Redirect(method = "renderChunkLayer", at = @At( - value = "INVOKE", - target = "Lcom/mojang/blaze3d/shaders/Uniform;set(FFF)V" - )) - private void preRender(Uniform chunkOffset, float x, float y, float z) { - ChunkAnimator.instance.animationHandler.preRender( - new PreRenderContext( - currentRenderChunk, - new VanillaUniformWrapper(chunkOffset), - x, - y, - z - ) - ); - } - - /** - * Matches behaviour of {@link #preRender(Uniform, float, float, float)}, except sets OptiFine's shaders - * chunk offset uniform instead. This makes the animation work when shaders are enabled. - */ - @Redirect(method = "renderChunkLayer", at = @At( - value = "INVOKE", - target = "Lnet/optifine/shaders/uniform/ShaderUniform3f;setValue(FFF)V", - ordinal = 0 - )) - private void preRender(@Coerce Object chunkOffset, float x, float y, float z) { - Object chunkOffsetUniform; - try { - chunkOffsetUniform = CHUNK_OFFSET_UNIFORM_FIELD.get(null); - } catch (IllegalAccessException e) { - throw new RuntimeException(e); - } - ChunkAnimator.instance.animationHandler.preRender( - new PreRenderContext( - currentRenderChunk, - new OptiFineUniform3fWrapper(chunkOffsetUniform), - x, - y, - z - ) - ); - } - -} diff --git a/src/main/java/lumien/chunkanimator/mixin/RenderChunkMixin.java b/src/main/java/lumien/chunkanimator/mixin/RenderSectionMixin.java similarity index 65% rename from src/main/java/lumien/chunkanimator/mixin/RenderChunkMixin.java rename to src/main/java/lumien/chunkanimator/mixin/RenderSectionMixin.java index ddd6a02..e288563 100644 --- a/src/main/java/lumien/chunkanimator/mixin/RenderChunkMixin.java +++ b/src/main/java/lumien/chunkanimator/mixin/RenderSectionMixin.java @@ -1,7 +1,7 @@ package lumien.chunkanimator.mixin; import lumien.chunkanimator.ChunkAnimator; -import net.minecraft.client.renderer.chunk.ChunkRenderDispatcher; +import net.minecraft.client.renderer.chunk.SectionRenderDispatcher; import net.minecraft.core.BlockPos; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -11,16 +11,16 @@ /** * @author Harley O'Connor */ -@Mixin(ChunkRenderDispatcher.RenderChunk.class) -public final class RenderChunkMixin { +@Mixin(SectionRenderDispatcher.RenderSection.class) +public final class RenderSectionMixin { @Inject(method = "setOrigin", at = @At( value = "INVOKE", - target = "Lnet/minecraft/client/renderer/chunk/ChunkRenderDispatcher$RenderChunk;reset()V" + target = "Lnet/minecraft/client/renderer/chunk/SectionRenderDispatcher$RenderSection;reset()V" )) public void setOrigin(int x, int y, int z, CallbackInfo ci) { ChunkAnimator.instance.animationHandler.setOrigin( - (ChunkRenderDispatcher.RenderChunk) (Object) this, + (SectionRenderDispatcher.RenderSection) (Object) this, new BlockPos(x, y, z) ); } diff --git a/src/main/java/lumien/chunkanimator/util/OptiFineUniform3fWrapper.java b/src/main/java/lumien/chunkanimator/util/OptiFineUniform3fWrapper.java deleted file mode 100644 index 6a0af18..0000000 --- a/src/main/java/lumien/chunkanimator/util/OptiFineUniform3fWrapper.java +++ /dev/null @@ -1,34 +0,0 @@ -package lumien.chunkanimator.util; - -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; - -public class OptiFineUniform3fWrapper implements UniformWrapper { - - private static final Method SET_VALUE_METHOD; - - static { - try { - Class uniform3fClass = Class.forName("net.optifine.shaders.uniform.ShaderUniform3f"); - SET_VALUE_METHOD = uniform3fClass.getMethod("setValue", float.class, float.class, float.class); - } catch (ClassNotFoundException | NoSuchMethodException e) { - throw new RuntimeException(e); - } - } - - private final Object uniform; - - public OptiFineUniform3fWrapper(Object uniform) { - this.uniform = uniform; - } - - @Override - public void set(float x, float y, float z) { - try { - SET_VALUE_METHOD.invoke(uniform, x, y, z); - } catch (IllegalAccessException | InvocationTargetException e) { - throw new RuntimeException(e); - } - } - -} diff --git a/src/main/java/lumien/chunkanimator/util/UniformWrapper.java b/src/main/java/lumien/chunkanimator/util/UniformWrapper.java deleted file mode 100644 index ec5c440..0000000 --- a/src/main/java/lumien/chunkanimator/util/UniformWrapper.java +++ /dev/null @@ -1,7 +0,0 @@ -package lumien.chunkanimator.util; - -public interface UniformWrapper { - - void set(float x, float y, float z); - -} diff --git a/src/main/java/lumien/chunkanimator/util/VanillaUniformWrapper.java b/src/main/java/lumien/chunkanimator/util/VanillaUniformWrapper.java deleted file mode 100644 index 37537cd..0000000 --- a/src/main/java/lumien/chunkanimator/util/VanillaUniformWrapper.java +++ /dev/null @@ -1,18 +0,0 @@ -package lumien.chunkanimator.util; - -import com.mojang.blaze3d.shaders.Uniform; - -public class VanillaUniformWrapper implements UniformWrapper { - - private final Uniform uniform; - - public VanillaUniformWrapper(Uniform uniform) { - this.uniform = uniform; - } - - @Override - public void set(float x, float y, float z) { - uniform.set(x, y, z); - } - -} diff --git a/src/main/resources/META-INF/accesstransformer.cfg b/src/main/resources/META-INF/accesstransformer.cfg deleted file mode 100644 index afb7d74..0000000 --- a/src/main/resources/META-INF/accesstransformer.cfg +++ /dev/null @@ -1,2 +0,0 @@ -public net.minecraft.client.renderer.LevelRenderer$RenderChunkInfo -public net.minecraft.client.renderer.LevelRenderer$RenderChunkInfo f_109839_ # chunk \ No newline at end of file diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/neoforge.mods.toml similarity index 66% rename from src/main/resources/META-INF/mods.toml rename to src/main/resources/META-INF/neoforge.mods.toml index 2ff7948..d918aad 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/neoforge.mods.toml @@ -1,5 +1,5 @@ modLoader="javafml" -loaderVersion="[47,)" +loaderVersion="${loaderVersionRange}" issueTrackerURL="https://github.com/Harleyoc1/ChunkAnimator/issues" @@ -8,8 +8,8 @@ license="MIT" [[mods]] displayName="Chunk Animator" -modId="chunkanimator" -version="${file.jarVersion}" +modId="${modId}" +version="${modVersion}" authors="Lumien" credits="Harley O'Connor for this port" @@ -18,19 +18,22 @@ description=''' A small client side mod that animates the appeareance of chunks so that they don't just instantly appear. ''' +[[mixins]] +config="${modId}.mixins.json" + displayURL="https://www.curseforge.com/minecraft/mc-mods/chunk-animator" -updateJSONURL="https://github.com/Harleyoc1/ChunkAnimator/blob/1.20/version_info.json?raw=true" +updateJSONURL="https://github.com/Harleyoc1/ChunkAnimator/blob/1.21/version_info.json?raw=true" -[[dependencies.chunkanimator]] - modId="forge" +[[dependencies.${modId}]] + modId="neoforge" mandatory=true - versionRange="[47.0.1,)" + versionRange="${forgeVersionRange}" ordering="NONE" side="BOTH" -[[dependencies.chunkanimator]] +[[dependencies.${modId}]] modId="minecraft" mandatory=true - versionRange="[1.20.1,1.21)" + versionRange="${mcVersionRange}" ordering="NONE" side="BOTH" \ No newline at end of file diff --git a/src/main/resources/chunkanimator.mixins.json b/src/main/resources/chunkanimator.mixins.json index 082b715..ed3bfe3 100644 --- a/src/main/resources/chunkanimator.mixins.json +++ b/src/main/resources/chunkanimator.mixins.json @@ -1,11 +1,11 @@ { "required": true, "package": "lumien.chunkanimator.mixin", - "compatibilityLevel": "JAVA_17", + "compatibilityLevel": "JAVA_21", "refmap": "chunkanimator.refmap.json", "mixins": [ "LevelRendererMixin", - "RenderChunkMixin" + "RenderSectionMixin" ], "minVersion": "0.8.5" } \ No newline at end of file diff --git a/src/main/resources/chunkanimator.optifine.mixins.json b/src/main/resources/chunkanimator.optifine.mixins.json deleted file mode 100644 index e31d4c2..0000000 --- a/src/main/resources/chunkanimator.optifine.mixins.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "required": true, - "package": "lumien.chunkanimator.mixin", - "compatibilityLevel": "JAVA_17", - "refmap": "chunkanimator.refmap.json", - "mixins": [ - "OptiFineLevelRendererMixin", - "RenderChunkMixin" - ], - "minVersion": "0.8.5" -} \ No newline at end of file diff --git a/version_info.json b/version_info.json index 97a6325..d7230ca 100644 --- a/version_info.json +++ b/version_info.json @@ -1,9 +1,14 @@ { "homepage": "https://www.curseforge.com/minecraft/mc-mods/chunk-animator", + "1.21": { + "1.21-1.3.7": "Update to 1.21" + }, "1.20.1": { "1.20.1-1.3.7": "Update to 1.20.1" }, "promos": { + "1.21-latest": "1.21-1.3.7", + "1.21-recommended": "1.21-1.3.7", "1.20.1-latest": "1.20.1-1.3.7", "1.20.1-recommended": "1.20.1-1.3.7" }