Skip to content

Commit

Permalink
Port to NeoForge 1.21
Browse files Browse the repository at this point in the history
  • Loading branch information
Harleyoc1 committed Aug 2, 2024
1 parent d8c722a commit b1e5aec
Show file tree
Hide file tree
Showing 26 changed files with 139 additions and 445 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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).
103 changes: 32 additions & 71 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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")
Expand All @@ -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)
}
}

Expand All @@ -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<GenerateModuleMetadata> {
Expand Down Expand Up @@ -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.")
Expand All @@ -169,7 +147,7 @@ curseforge {

addGameVersion(mcVersion)

changelog = rawChangelog
changelog = "Changelog pending."
changelogType = "markdown"
releaseType = optionalProperty("versionType") ?: "release"

Expand All @@ -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())
}
}
}
18 changes: 0 additions & 18 deletions buildSrc/build.gradle.kts

This file was deleted.

12 changes: 9 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -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"
}
30 changes: 11 additions & 19 deletions src/main/java/lumien/chunkanimator/ChunkAnimator.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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());
}

}
29 changes: 0 additions & 29 deletions src/main/java/lumien/chunkanimator/MixinConnector.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,28 @@
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
*/
public final class ChunkAnimatorConfig {

/** The animation mode - controls how the chunks should be animated. */
public static final ForgeConfigSpec.EnumValue<AnimationMode> MODE;
public static final ModConfigSpec.EnumValue<AnimationMode> MODE;

/** The easing function - controls which easing function should be used. */
public static final ForgeConfigSpec.EnumValue<EasingFunction> EASING_FUNCTION;
public static final ModConfigSpec.EnumValue<EasingFunction> 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.
Expand Down
Loading

0 comments on commit b1e5aec

Please sign in to comment.