diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 068aa8b..c37f047 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,4 +1,4 @@ -name: Build 1.20.x +name: Build 1.21.x on: push: @@ -14,10 +14,10 @@ jobs: steps: - name: Checkout uses: actions/checkout@v3 - - name: Set up JDK 17 + - name: Set up JDK 21 uses: actions/setup-java@v3 with: - java-version: '17' + java-version: '21' distribution: 'adopt' - name: Get Version id: version @@ -69,7 +69,6 @@ jobs: version-type: ${{ steps.version_type.outputs.result }} java: 17 loaders: | - forge neoforge changelog-file: CHANGELOG.md diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a067e02..9cf4460 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,11 +1,11 @@ -name: Test 1.20.x +name: Test 1.21.x on: push: branches: - - 1.20.x + - 1.21.x pull_request: - branches: [ 1.20.x ] + branches: [ 1.21.x ] jobs: main: @@ -16,10 +16,10 @@ jobs: steps: - name: Checkout uses: actions/checkout@v2 - - name: Set up JDK 17 + - name: Set up JDK 21 uses: actions/setup-java@v2 with: - java-version: '17' + java-version: '21' distribution: 'adopt' - name: Build uses: gradle/gradle-build-action@v2 diff --git a/build.gradle b/build.gradle deleted file mode 100644 index b23b933..0000000 --- a/build.gradle +++ /dev/null @@ -1,72 +0,0 @@ -plugins { - id 'idea' - id 'net.minecraftforge.gradle' version '[6.0,6.2)' -} - -def envVersion = System.getenv('VERSION') -version = envVersion == null ? '0.0.0-indev' : envVersion -group = 'com.eerussianguy.betterfoliage' // http://maven.apache.org/guides/mini/guide-naming-conventions.html -archivesBaseName = 'betterfoliage' - -def tfcVersion = 4915584 -def patchouliVersion = "1.20.1-81-FORGE" - -java.toolchain.languageVersion = JavaLanguageVersion.of(17) - -println "Java: ${System.getProperty 'java.version'}, JVM: ${System.getProperty 'java.vm.version'} (${System.getProperty 'java.vendor'}), Arch: ${System.getProperty 'os.arch'}" -minecraft { - mappings channel: 'official', version: '1.20.1' - runs { - client { - workingDirectory project.file('run') - - property 'mixin.env.remapRefMap', 'true' - property 'mixin.env.refMapRemappingFile', "${projectDir}/build/createSrgToMcp/output.srg" - property 'forge.logging.markers', 'REGISTRIES' - property 'forge.logging.console.level', 'debug' - - mods { - betterfoliage { - source sourceSets.main - } - } - } - - } -} - -// Include resources generated by data generators. -sourceSets.main.resources { srcDir 'src/generated/resources' } - -dependencies { - minecraft 'net.minecraftforge:forge:1.20.1-47.1.3' - - compileOnly(fg.deobf("curse.maven:tfc-302973:${tfcVersion}")) - //runtimeOnly(fg.deobf("curse.maven:tfc-302973:${tfcVersion}")) - //runtimeOnly(fg.deobf("vazkii.patchouli:Patchouli:$patchouliVersion")) - - //runtimeOnly fg.deobf('bop:BiomesOPlenty-1.18.2:16.0.0.109-universal') - //runtimeOnly fg.deobf('tb:TerraBlender-forge-1.18.2:1.1.0.102') -} - -repositories { - flatDir { - dir 'libs' - } - maven { - url "https://www.cursemaven.com" - content { - includeGroup("curse.maven") - } - } - maven { url "https://maven.blamejared.com" } -} - -jar { - manifest { - attributes([ - "Implementation-Version": project.version, - ]) - } -} - diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 0000000..bf608ae --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,131 @@ +import groovy.json.JsonOutput +import groovy.json.JsonSlurper + +plugins { + id("net.neoforged.moddev") version "2.0.1-beta" +} + + +// Toolchain versions +val minecraftVersion: String = "1.21" +val neoForgeVersion: String = "21.0.167" +val parchmentVersion: String = "2024.07.07" +val parchmentMinecraftVersion: String = "1.21" + +val modId: String = "betterfoliage" +val modVersion: String = System.getenv("VERSION") ?: "0.0.0-indev" +val modJavaVersion: String = "21" +val modIsInCI: Boolean = !modVersion.contains("-indev") + + +val generateModMetadata = tasks.register("generateModMetadata") { + val modReplacementProperties = mapOf( + "modId" to modId, + "modVersion" to modVersion, + "minecraftVersionRange" to "[$minecraftVersion,)", + "neoForgeVersionRange" to "[$neoForgeVersion,)" + ) + inputs.properties(modReplacementProperties) + expand(modReplacementProperties) + from("src/main/templates") + into(layout.buildDirectory.dir("generated/sources/modMetadata")) +} + + +base { + archivesName.set("BetterFoliageRenewed-NeoForge-$minecraftVersion") + group = "com.eerussianguy.betterfoliage" + version = modVersion +} + +java { + toolchain.languageVersion.set(JavaLanguageVersion.of(modJavaVersion)) +} + +repositories { + mavenLocal() + exclusiveContent { + forRepository { maven("https://www.cursemaven.com") } + filter { includeGroup("curse.maven") } + } +} + +sourceSets { + main { + resources { + srcDir(generateModMetadata) + } + } +} + +dependencies { +} + +neoForge { + version.set(neoForgeVersion) + validateAccessTransformers = true + + parchment { + minecraftVersion.set(parchmentMinecraftVersion) + mappingsVersion.set(parchmentVersion) + } + + runs { + configureEach { + // Only JBR allows enhanced class redefinition, so ignore the option for any other JDKs + jvmArguments.addAll("-XX:+IgnoreUnrecognizedVMOptions", "-XX:+AllowEnhancedClassRedefinition", "-ea") + systemProperty("betterfoliage.enableDebugSelfTests", "true") + } + register("client") { + client() + gameDirectory = file("run/client") + } + } + + mods { + create(modId) { + sourceSet(sourceSets.main.get()) + } + } + + ideSyncTask(generateModMetadata) +} + +tasks { + processResources { + if (modIsInCI) { + doLast { + val jsonMinifyStart: Long = System.currentTimeMillis() + var jsonMinified: Long = 0 + var jsonBytesBefore: Long = 0 + var jsonBytesAfter: Long = 0 + + fileTree(mapOf("dir" to outputs.files.asPath, "include" to "**/*.json")).forEach { + jsonMinified++ + jsonBytesBefore += it.length() + try { + it.writeText(JsonOutput.toJson(JsonSlurper().parse(it)).replace("\"__comment__\":\"This file was automatically created by mcresources\",", "")) + } catch (e: Exception) { + println("JSON Error in ${it.path}") + throw e + } + + jsonBytesAfter += it.length() + } + println("Minified $jsonMinified json files. Reduced ${jsonBytesBefore / 1024} kB to ${(jsonBytesAfter / 1024)} kB. Took ${System.currentTimeMillis() - jsonMinifyStart} ms") + } + } + } + + + jar { + manifest { + attributes["Implementation-Version"] = project.version + } + } + + named("neoForgeIdeSync") { + dependsOn(generateModMetadata) + } +} + diff --git a/gradle.properties b/gradle.properties index 51a7d8c..0b59935 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ -# Sets default memory used for gradle commands. Can be overridden by user or command line properties. -# This is required to provide enough memory for the Minecraft decompilation process. -org.gradle.jvmargs=-Xmx4G -org.gradle.daemon=false -org.gradle.console=plain \ No newline at end of file +org.gradle.jvmargs=-Xmx2G +org.gradle.daemon=true +org.gradle.parallel=true +org.gradle.caching=true +org.gradle.configuration-cache=true \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 943f0cb..2c35211 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 37aef8d..09523c0 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.1.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip networkTimeout=10000 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index 65dcd68..f5feea6 100755 --- a/gradlew +++ b/gradlew @@ -15,6 +15,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # +# SPDX-License-Identifier: Apache-2.0 +# ############################################################################## # @@ -55,7 +57,7 @@ # Darwin, MinGW, and NonStop. # # (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt # within the Gradle project. # # You can find Gradle at https://github.com/gradle/gradle/. @@ -83,10 +85,9 @@ done # This is normally unused # shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} -APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit - -# 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"' +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s +' "$PWD" ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum @@ -133,10 +134,13 @@ location of your Java installation." fi else JAVACMD=java - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." + fi fi # Increase the maximum file descriptors if we can. @@ -144,7 +148,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 @@ -152,7 +156,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 @@ -197,11 +201,15 @@ if "$cygwin" || "$msys" ; then done fi -# Collect all arguments for the java command; -# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of -# shell script including quotes and variable substitutions, so put them in -# double quotes to make sure that they get re-expanded; and -# * put everything else in single quotes, so that it's not re-expanded. + +# 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, 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/gradlew.bat b/gradlew.bat index 93e3f59..9d21a21 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -13,6 +13,8 @@ @rem See the License for the specific language governing permissions and @rem limitations under the License. @rem +@rem SPDX-License-Identifier: Apache-2.0 +@rem @if "%DEBUG%"=="" @echo off @rem ########################################################################## @@ -43,11 +45,11 @@ set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -57,11 +59,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 0000000..70dba09 --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1,14 @@ +pluginManagement { + repositories { + gradlePluginPortal() + mavenCentral() + exclusiveContent { + forRepository { maven("https://maven.neoforged.net/releases") } + filter { includeGroupAndSubgroups("net.neoforged") } + } + } +} + +plugins { + id("org.gradle.toolchains.foojay-resolver-convention") version "0.8.0" +} \ No newline at end of file diff --git a/src/main/java/com/eerussianguy/betterfoliage/BFConfig.java b/src/main/java/com/eerussianguy/betterfoliage/BFConfig.java index 0335f87..e708177 100644 --- a/src/main/java/com/eerussianguy/betterfoliage/BFConfig.java +++ b/src/main/java/com/eerussianguy/betterfoliage/BFConfig.java @@ -1,22 +1,17 @@ package com.eerussianguy.betterfoliage; -import java.util.function.Function; - +import net.neoforged.neoforge.common.ModConfigSpec; import org.apache.commons.lang3.tuple.Pair; -import net.minecraftforge.common.ForgeConfigSpec; -import net.minecraftforge.fml.ModLoadingContext; -import net.minecraftforge.fml.config.ModConfig; public class BFConfig { - public static final ClientConfig CLIENT = register(ClientConfig::new); - - public static void init() {} + public static final ClientConfig CLIENT; + public static final ModConfigSpec SPEC; - private static C register(Function factory) + static { - Pair specPair = new ForgeConfigSpec.Builder().configure(factory); - ModLoadingContext.get().registerConfig(ModConfig.Type.CLIENT, specPair.getRight()); - return specPair.getLeft(); + final Pair specPair = new ModConfigSpec.Builder().configure(ClientConfig::new); + CLIENT = specPair.getLeft(); + SPEC = specPair.getRight(); } } diff --git a/src/main/java/com/eerussianguy/betterfoliage/BetterFoliage.java b/src/main/java/com/eerussianguy/betterfoliage/BetterFoliage.java index 378cb9d..c91db50 100644 --- a/src/main/java/com/eerussianguy/betterfoliage/BetterFoliage.java +++ b/src/main/java/com/eerussianguy/betterfoliage/BetterFoliage.java @@ -1,31 +1,30 @@ package com.eerussianguy.betterfoliage; -import com.mojang.logging.LogUtils; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.fml.loading.FMLEnvironment; -import org.slf4j.Logger; +import net.neoforged.api.distmarker.Dist; +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.loading.FMLEnvironment; import static com.eerussianguy.betterfoliage.BetterFoliage.MOD_ID; @Mod(MOD_ID) public class BetterFoliage { - private static final Logger LOGGER = LogUtils.getLogger(); - public static final String MOD_ID = "betterfoliage"; public static boolean LEAVES_DISABLED_BY_MOD = false; - public BetterFoliage() + public BetterFoliage(ModContainer mod, IEventBus bus) { if (FMLEnvironment.dist == Dist.CLIENT) { - EventHandler.init(); + EventHandler.init(bus); ForgeEventHandler.init(); } - BFConfig.init(); + mod.registerConfig(ModConfig.Type.CLIENT, BFConfig.SPEC); } diff --git a/src/main/java/com/eerussianguy/betterfoliage/ClientConfig.java b/src/main/java/com/eerussianguy/betterfoliage/ClientConfig.java index ed5dd5d..f4db31e 100644 --- a/src/main/java/com/eerussianguy/betterfoliage/ClientConfig.java +++ b/src/main/java/com/eerussianguy/betterfoliage/ClientConfig.java @@ -2,31 +2,28 @@ import java.util.function.Function; -import net.minecraftforge.common.ForgeConfigSpec.BooleanValue; -import net.minecraftforge.common.ForgeConfigSpec.Builder; -import net.minecraftforge.common.ForgeConfigSpec.IntValue; -import net.minecraftforge.common.ForgeConfigSpec.DoubleValue; +import net.neoforged.neoforge.common.ModConfigSpec; import static com.eerussianguy.betterfoliage.BetterFoliage.MOD_ID; public class ClientConfig { - public final IntValue particleAttempts; - public final IntValue particleDistance; + public final ModConfigSpec.IntValue particleAttempts; + public final ModConfigSpec.IntValue particleDistance; - public final BooleanValue souls; - public final BooleanValue leaves; - public final BooleanValue snowballs; + public final ModConfigSpec.BooleanValue souls; + public final ModConfigSpec.BooleanValue leaves; + public final ModConfigSpec.BooleanValue snowballs; - public final IntValue leavesCacheSize; - public final DoubleValue leavesVariationDistance; - public final IntValue extraGrassRarity; + public final ModConfigSpec.IntValue leavesCacheSize; + public final ModConfigSpec.DoubleValue leavesVariationDistance; + public final ModConfigSpec.IntValue extraGrassRarity; - public final BooleanValue forceForgeLighting; + public final ModConfigSpec.BooleanValue forceForgeLighting; - ClientConfig(Builder innerBuilder) + ClientConfig(ModConfigSpec.Builder innerBuilder) { - Function builder = name -> innerBuilder.translation(MOD_ID + ".config.server." + name); + Function builder = name -> innerBuilder.translation(MOD_ID + ".config.server." + name); innerBuilder.push("general"); diff --git a/src/main/java/com/eerussianguy/betterfoliage/EventHandler.java b/src/main/java/com/eerussianguy/betterfoliage/EventHandler.java index 7cd4fbc..eea3af3 100644 --- a/src/main/java/com/eerussianguy/betterfoliage/EventHandler.java +++ b/src/main/java/com/eerussianguy/betterfoliage/EventHandler.java @@ -3,18 +3,17 @@ import java.util.function.Supplier; import com.google.common.base.Suppliers; -import net.minecraftforge.client.event.ModelEvent; -import net.minecraftforge.client.event.TextureStitchEvent; -import net.minecraftforge.common.ForgeConfig; -import net.minecraftforge.eventbus.api.IEventBus; -import net.minecraftforge.fml.ModList; -import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; -import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; import com.eerussianguy.betterfoliage.model.GrassBakedModel; import com.eerussianguy.betterfoliage.model.GrassLoader; import com.eerussianguy.betterfoliage.model.LeavesBakedModel; import com.eerussianguy.betterfoliage.model.LeavesLoader; +import net.neoforged.bus.api.IEventBus; +import net.neoforged.fml.ModList; +import net.neoforged.fml.event.lifecycle.FMLClientSetupEvent; +import net.neoforged.neoforge.client.event.ModelEvent; +import net.neoforged.neoforge.client.event.TextureAtlasStitchedEvent; +import net.neoforged.neoforge.common.NeoForgeConfig; public class EventHandler { @@ -31,10 +30,8 @@ public class EventHandler } }); - public static void init() + public static void init(IEventBus bus) { - final IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus(); - bus.addListener(EventHandler::clientSetup); bus.addListener(EventHandler::onModelBake); bus.addListener(EventHandler::onModelRegister); @@ -46,7 +43,7 @@ private static void clientSetup(final FMLClientSetupEvent event) { if (BFConfig.CLIENT.forceForgeLighting.get() && !OPTIFINE_LOADED.get() && !ModList.get().isLoaded("oculus")) { - ForgeConfig.CLIENT.experimentalForgeLightPipelineEnabled.set(true); + NeoForgeConfig.CLIENT.experimentalForgeLightPipelineEnabled.set(true); } if (ModList.get().isLoaded("tfc")) @@ -61,21 +58,21 @@ private static void onModelBake(final ModelEvent.BakingCompleted event) GrassBakedModel.INSTANCES.forEach(GrassBakedModel::init); } - private static void afterTextureStitch(final TextureStitchEvent.Post event) + private static void afterTextureStitch(final TextureAtlasStitchedEvent event) { ForgeEventHandler.clearCache(); } private static void onLoaderRegister(final ModelEvent.RegisterGeometryLoaders event) { - event.register("leaves", new LeavesLoader()); - event.register("grass", new GrassLoader()); + event.register(Helpers.identifier("leaves"), new LeavesLoader()); + event.register(Helpers.identifier("grass"), new GrassLoader()); } private static void onModelRegister(final ModelEvent.RegisterAdditional event) { - event.register(Helpers.identifier("block/better_grass")); - event.register(Helpers.identifier("block/better_grass_snowed")); - event.register(Helpers.identifier("block/better_mycelium")); + event.register(Helpers.standalone("block/better_grass")); + event.register(Helpers.standalone("block/better_grass_snowed")); + event.register(Helpers.standalone("block/better_mycelium")); } } diff --git a/src/main/java/com/eerussianguy/betterfoliage/ForgeEventHandler.java b/src/main/java/com/eerussianguy/betterfoliage/ForgeEventHandler.java index 8ffc9c9..ee57262 100644 --- a/src/main/java/com/eerussianguy/betterfoliage/ForgeEventHandler.java +++ b/src/main/java/com/eerussianguy/betterfoliage/ForgeEventHandler.java @@ -20,12 +20,11 @@ import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.Vec3; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.event.TickEvent; -import net.minecraftforge.eventbus.api.IEventBus; import com.eerussianguy.betterfoliage.particle.LeafParticle; import com.eerussianguy.betterfoliage.particle.SoulParticle; +import net.neoforged.neoforge.client.event.ClientTickEvent; +import net.neoforged.neoforge.common.NeoForge; public class ForgeEventHandler { @@ -33,7 +32,7 @@ public class ForgeEventHandler public static void init() { - final IEventBus bus = MinecraftForge.EVENT_BUS; + final var bus = NeoForge.EVENT_BUS; bus.addListener(ForgeEventHandler::onClientTick); } @@ -43,7 +42,7 @@ public static void clearCache() SPRITE_CACHE.clear(); } - private static void onClientTick(TickEvent.ClientTickEvent event) + private static void onClientTick(ClientTickEvent.Post event) { Minecraft mc = Minecraft.getInstance(); if (mc.isPaused()) return; @@ -61,7 +60,7 @@ private static void onClientTick(TickEvent.ClientTickEvent event) // stupid hack // noinspection deprecation - final AbstractTexture particleTexture = Minecraft.getInstance().textureManager.getTexture(TextureAtlas.LOCATION_PARTICLES); + final AbstractTexture particleTexture = Minecraft.getInstance().getTextureManager().getTexture(TextureAtlas.LOCATION_PARTICLES); particleTexture.setFilter(false, false); if (particleTexture instanceof TextureAtlas atlas) { diff --git a/src/main/java/com/eerussianguy/betterfoliage/Helpers.java b/src/main/java/com/eerussianguy/betterfoliage/Helpers.java index 2de4c32..c330530 100644 --- a/src/main/java/com/eerussianguy/betterfoliage/Helpers.java +++ b/src/main/java/com/eerussianguy/betterfoliage/Helpers.java @@ -1,7 +1,5 @@ package com.eerussianguy.betterfoliage; -import java.util.Arrays; -import java.util.Collection; import java.util.List; import java.util.Map; import java.util.function.Function; @@ -14,7 +12,6 @@ import net.minecraft.client.renderer.texture.TextureAtlas; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.client.resources.model.BlockModelRotation; -import net.minecraft.client.resources.model.Material; import net.minecraft.client.resources.model.ModelResourceLocation; import net.minecraft.client.resources.model.SimpleBakedModel; import net.minecraft.core.BlockPos; @@ -27,34 +24,40 @@ import com.eerussianguy.betterfoliage.particle.SpritePicker; import com.mojang.blaze3d.vertex.PoseStack; -import net.minecraftforge.client.model.ForgeFaceData; +import net.neoforged.neoforge.client.model.ExtraFaceData; +import org.apache.commons.lang3.mutable.MutableObject; import static com.eerussianguy.betterfoliage.BetterFoliage.MOD_ID; public class Helpers { public static final Direction[] DIRECTIONS = Direction.values(); - public static final ModelResourceLocation BACKING_DIRT_MODEL = new ModelResourceLocation("minecraft", "dirt", "inventory"); + public static final ModelResourceLocation BACKING_DIRT_MODEL = ModelResourceLocation.inventory(ResourceLocation.fromNamespaceAndPath("minecraft", "dirt")); public static ResourceLocation identifier(String name) { - return new ResourceLocation(MOD_ID, name); + return ResourceLocation.fromNamespaceAndPath(MOD_ID, name); + } + + public static ModelResourceLocation standalone(String name) + { + return ModelResourceLocation.standalone(identifier(name)); } public static final ResourceLocation EMPTY = identifier("empty"); public static final BlockFaceUV UV_DEFAULT = new BlockFaceUV(new float[] {0f, 0f, 16f, 16f}, 0); - public static ForgeFaceData forgeFace(boolean ao) + public static ExtraFaceData forgeFace(boolean ao) { return ao ? - new ForgeFaceData(0xFFFFFFFF, 0, 0, true) - : new ForgeFaceData(0xFFFFFFFF, 0, 0, false); + new ExtraFaceData(0xFFFFFFFF, 0, 0, true) + : new ExtraFaceData(0xFFFFFFFF, 0, 0, false); } public static BlockElementFace makeTintedFace(BlockFaceUV uv, boolean ao) { - return new BlockElementFace(null, 0, "", uv, forgeFace(ao)); + return new BlockElementFace(null, 0, "", uv, forgeFace(ao), new MutableObject<>()); } public static BlockElementFace makeTintedFace(BlockFaceUV uv) @@ -64,7 +67,7 @@ public static BlockElementFace makeTintedFace(BlockFaceUV uv) public static BlockElementFace makeFace(BlockFaceUV uv, boolean ao) { - return new BlockElementFace(null, -1, "", uv, forgeFace(ao)); + return new BlockElementFace(null, -1, "", uv, forgeFace(ao), new MutableObject<>()); } public static BlockElementFace makeFace(BlockFaceUV uv) @@ -74,41 +77,35 @@ public static BlockElementFace makeFace(BlockFaceUV uv) public static ResourceLocation requireID(JsonObject json, String member) { - return new ResourceLocation(GsonHelper.getAsString(json, member, EMPTY.toString())); + return ResourceLocation.parse(GsonHelper.getAsString(json, member, EMPTY.toString())); } public static ResourceLocation identifierOrEmpty(JsonObject json, String member) { if (!json.has(member)) return EMPTY; - return new ResourceLocation(json.get(member).getAsString()); - } - - public static Collection makeMaterials(ResourceLocation... textures) - { - //noinspection deprecation - return Arrays.stream(textures).map(texture -> new Material(TextureAtlas.LOCATION_BLOCKS, texture)).toList(); + return ResourceLocation.parse(json.get(member).getAsString()); } - public static BakedQuad makeBakedQuad(BlockElement BlockElement, BlockElementFace partFace, TextureAtlasSprite atlasSprite, Direction dir, BlockModelRotation modelRotation, ResourceLocation modelResLoc) + public static BakedQuad makeBakedQuad(BlockElement BlockElement, BlockElementFace partFace, TextureAtlasSprite atlasSprite, Direction dir, BlockModelRotation modelRotation) { - return new FaceBakery().bakeQuad(BlockElement.from, BlockElement.to, partFace, atlasSprite, dir, modelRotation, BlockElement.rotation, true, modelResLoc); + return new FaceBakery().bakeQuad(BlockElement.from, BlockElement.to, partFace, atlasSprite, dir, modelRotation, BlockElement.rotation, true); } - public static void assembleFaces(SimpleBakedModel.Builder builder, BlockElement part, TextureAtlasSprite sprite, ResourceLocation modelLocation) + public static void assembleFaces(SimpleBakedModel.Builder builder, BlockElement part, TextureAtlasSprite sprite) { for (Map.Entry e : part.faces.entrySet()) { Direction d = e.getKey(); - builder.addCulledFace(d, Helpers.makeBakedQuad(part, e.getValue(), sprite, d, BlockModelRotation.X0_Y0, modelLocation)); + builder.addCulledFace(d, Helpers.makeBakedQuad(part, e.getValue(), sprite, d, BlockModelRotation.X0_Y0)); } } - public static void assembleFacesConditional(SimpleBakedModel.Builder builder, BlockElement part, Function getter, ResourceLocation modelLocation) + public static void assembleFacesConditional(SimpleBakedModel.Builder builder, BlockElement part, Function getter) { for (Map.Entry e : part.faces.entrySet()) { Direction d = e.getKey(); - builder.addCulledFace(d, Helpers.makeBakedQuad(part, e.getValue(), getter.apply(d), d, BlockModelRotation.X0_Y0, modelLocation)); + builder.addCulledFace(d, Helpers.makeBakedQuad(part, e.getValue(), getter.apply(d), d, BlockModelRotation.X0_Y0)); } } diff --git a/src/main/java/com/eerussianguy/betterfoliage/model/BFBakedModel.java b/src/main/java/com/eerussianguy/betterfoliage/model/BFBakedModel.java index 57f09ff..b9320ab 100644 --- a/src/main/java/com/eerussianguy/betterfoliage/model/BFBakedModel.java +++ b/src/main/java/com/eerussianguy/betterfoliage/model/BFBakedModel.java @@ -1,7 +1,7 @@ package com.eerussianguy.betterfoliage.model; import net.minecraft.client.renderer.block.model.ItemOverrides; -import net.minecraftforge.client.model.IDynamicBakedModel; +import net.neoforged.neoforge.client.model.IDynamicBakedModel; public abstract class BFBakedModel implements IDynamicBakedModel { diff --git a/src/main/java/com/eerussianguy/betterfoliage/model/GrassBakedModel.java b/src/main/java/com/eerussianguy/betterfoliage/model/GrassBakedModel.java index d6e9674..69caf7f 100644 --- a/src/main/java/com/eerussianguy/betterfoliage/model/GrassBakedModel.java +++ b/src/main/java/com/eerussianguy/betterfoliage/model/GrassBakedModel.java @@ -8,6 +8,7 @@ import net.minecraft.client.renderer.block.model.*; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.client.resources.model.BakedModel; +import net.minecraft.client.resources.model.ModelResourceLocation; import net.minecraft.client.resources.model.SimpleBakedModel; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; @@ -17,12 +18,12 @@ import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.properties.BlockStateProperties; -import net.minecraftforge.client.ChunkRenderTypeSet; -import net.minecraftforge.client.NamedRenderTypeManager; -import net.minecraftforge.client.model.data.ModelData; import com.eerussianguy.betterfoliage.BFConfig; import com.eerussianguy.betterfoliage.Helpers; +import net.neoforged.neoforge.client.ChunkRenderTypeSet; +import net.neoforged.neoforge.client.NamedRenderTypeManager; +import net.neoforged.neoforge.client.model.data.ModelData; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.joml.Vector3f; @@ -34,11 +35,10 @@ public class GrassBakedModel extends BFBakedModel private final BlockModel blockModel; - private final ResourceLocation modelLocation; private final ResourceLocation dirt; private final ResourceLocation top; private final ResourceLocation overlay; - private final ResourceLocation grass; + private final ModelResourceLocation grass; private final boolean tint; @Nullable private TextureAtlasSprite dirtTex; @@ -47,16 +47,15 @@ public class GrassBakedModel extends BFBakedModel private final BakedModel[] models = new BakedModel[16]; - public GrassBakedModel(ResourceLocation modelLocation, ResourceLocation dirt, ResourceLocation top, ResourceLocation overlay, boolean tint, ResourceLocation grass) + public GrassBakedModel(ResourceLocation dirt, ResourceLocation top, ResourceLocation overlay, boolean tint, ResourceLocation grass) { this.blockModel = new BlockModel(null, new ArrayList<>(), new HashMap<>(), false, BlockModel.GuiLight.FRONT, ItemTransforms.NO_TRANSFORMS, new ArrayList<>()); - this.modelLocation = modelLocation; this.dirt = dirt; this.top = top; this.overlay = overlay; this.tint = tint; - this.grass = grass; + this.grass = ModelResourceLocation.standalone(grass); INSTANCES.add(this); } @@ -97,9 +96,9 @@ public void generateModels() SimpleBakedModel.Builder builder = new SimpleBakedModel.Builder(blockModel, ItemOverrides.EMPTY, false).particle(topTex); final int fMeta = meta; - Helpers.assembleFacesConditional(builder, core, direction -> direction == Direction.UP ? topTex : dirtTex, modelLocation); - Helpers.assembleFacesConditional(builder, part, direction -> resolveTexture(direction, stateFromMeta(fMeta)), modelLocation); - models[meta] = builder.build(NamedRenderTypeManager.get(new ResourceLocation("cutout_mipped"))); + Helpers.assembleFacesConditional(builder, core, direction -> direction == Direction.UP ? topTex : dirtTex); + Helpers.assembleFacesConditional(builder, part, direction -> resolveTexture(direction, stateFromMeta(fMeta))); + models[meta] = builder.build(NamedRenderTypeManager.get(ResourceLocation.parse("cutout_mipped"))); } } @@ -109,11 +108,11 @@ private TextureAtlasSprite resolveTexture(Direction d, boolean[] booleans) return switch (d) { case UP -> topTex; - default -> dirtTex; case NORTH -> booleans[0] ? topTex : overlayTex; case EAST -> booleans[1] ? topTex : overlayTex; case SOUTH -> booleans[2] ? topTex : overlayTex; case WEST -> booleans[3] ? topTex : overlayTex; + default -> dirtTex; }; } @@ -138,7 +137,7 @@ public List getQuads(@Nullable BlockState state, @Nullable Direction { final int meta = grassData.get(); List quads = new ArrayList<>(models[meta].getQuads(state, side, rand, extraData, renderType)); - if (grassData.hasUp() && !grass.equals(Helpers.EMPTY) && rand.nextInt(BFConfig.CLIENT.extraGrassRarity.get()) == 0) + if (grassData.hasUp() && !grass.id().equals(Helpers.EMPTY) && rand.nextInt(BFConfig.CLIENT.extraGrassRarity.get()) == 0) { final BakedModel grassModel = Minecraft.getInstance().getModelManager().getModel(grass); quads.addAll(grassModel.getQuads(state, side, rand, extraData, renderType)); diff --git a/src/main/java/com/eerussianguy/betterfoliage/model/GrassConnectionData.java b/src/main/java/com/eerussianguy/betterfoliage/model/GrassConnectionData.java index 56aecbc..8e141e6 100644 --- a/src/main/java/com/eerussianguy/betterfoliage/model/GrassConnectionData.java +++ b/src/main/java/com/eerussianguy/betterfoliage/model/GrassConnectionData.java @@ -1,6 +1,7 @@ package com.eerussianguy.betterfoliage.model; -import net.minecraftforge.client.model.data.ModelProperty; + +import net.neoforged.neoforge.client.model.data.ModelProperty; public class GrassConnectionData { diff --git a/src/main/java/com/eerussianguy/betterfoliage/model/GrassLoader.java b/src/main/java/com/eerussianguy/betterfoliage/model/GrassLoader.java index 03a140f..b73200c 100644 --- a/src/main/java/com/eerussianguy/betterfoliage/model/GrassLoader.java +++ b/src/main/java/com/eerussianguy/betterfoliage/model/GrassLoader.java @@ -7,9 +7,9 @@ import net.minecraft.MethodsReturnNonnullByDefault; import net.minecraft.resources.ResourceLocation; import net.minecraft.util.GsonHelper; -import net.minecraftforge.client.model.geometry.IGeometryLoader; import com.eerussianguy.betterfoliage.Helpers; +import net.neoforged.neoforge.client.model.geometry.IGeometryLoader; @ParametersAreNonnullByDefault diff --git a/src/main/java/com/eerussianguy/betterfoliage/model/GrassModel.java b/src/main/java/com/eerussianguy/betterfoliage/model/GrassModel.java index c676241..f207d25 100644 --- a/src/main/java/com/eerussianguy/betterfoliage/model/GrassModel.java +++ b/src/main/java/com/eerussianguy/betterfoliage/model/GrassModel.java @@ -7,14 +7,14 @@ import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.client.resources.model.*; import net.minecraft.resources.ResourceLocation; -import net.minecraftforge.client.model.geometry.IGeometryBakingContext; -import net.minecraftforge.client.model.geometry.IUnbakedGeometry; +import net.neoforged.neoforge.client.model.geometry.IGeometryBakingContext; +import net.neoforged.neoforge.client.model.geometry.IUnbakedGeometry; public record GrassModel(ResourceLocation dirt, ResourceLocation top, ResourceLocation overlay, boolean tint, ResourceLocation grassLocation) implements IUnbakedGeometry { @Override - public BakedModel bake(IGeometryBakingContext owner, ModelBaker bakery, Function spriteGetter, ModelState modelTransform, ItemOverrides overrides, ResourceLocation modelLocation) + public BakedModel bake(IGeometryBakingContext owner, ModelBaker bakery, Function spriteGetter, ModelState modelTransform, ItemOverrides overrides) { - return new GrassBakedModel(modelLocation, dirt, top, overlay, tint, grassLocation); + return new GrassBakedModel(dirt, top, overlay, tint, grassLocation); } } diff --git a/src/main/java/com/eerussianguy/betterfoliage/model/LeavesBakedModel.java b/src/main/java/com/eerussianguy/betterfoliage/model/LeavesBakedModel.java index defdbfa..aafa297 100644 --- a/src/main/java/com/eerussianguy/betterfoliage/model/LeavesBakedModel.java +++ b/src/main/java/com/eerussianguy/betterfoliage/model/LeavesBakedModel.java @@ -14,12 +14,12 @@ import net.minecraft.world.item.ItemDisplayContext; import net.minecraft.world.level.BlockAndTintGetter; import net.minecraft.world.level.block.state.BlockState; -import net.minecraftforge.client.NamedRenderTypeManager; -import net.minecraftforge.client.model.data.ModelData; import com.eerussianguy.betterfoliage.BFConfig; import com.eerussianguy.betterfoliage.Helpers; import com.mojang.blaze3d.vertex.PoseStack; +import net.neoforged.neoforge.client.NamedRenderTypeManager; +import net.neoforged.neoforge.client.model.data.ModelData; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.joml.Vector3f; @@ -31,7 +31,6 @@ public class LeavesBakedModel extends BFBakedModel private final ResourceLocation leaves; private final ResourceLocation fluff; private final ResourceLocation overlay; - private final ResourceLocation modelLocation; private final boolean isOverlay; private final boolean tintOverlay; private final boolean tintLeaves; @@ -45,11 +44,10 @@ public class LeavesBakedModel extends BFBakedModel @Nullable private BakedModel core; @Nullable private BakedModel outerCore; - public LeavesBakedModel(ResourceLocation modelLocation, ResourceLocation leaves, ResourceLocation fluff, ResourceLocation overlay, boolean tintLeaves, boolean tintOverlay) + public LeavesBakedModel(ResourceLocation leaves, ResourceLocation fluff, ResourceLocation overlay, boolean tintLeaves, boolean tintOverlay) { this.blockModel = new BlockModel(null, new ArrayList<>(), new HashMap<>(), false, BlockModel.GuiLight.FRONT, ItemTransforms.NO_TRANSFORMS, new ArrayList<>()); - this.modelLocation = modelLocation; this.leaves = leaves; this.fluff = fluff; this.overlay = overlay; @@ -112,10 +110,10 @@ private void buildCross(int ordinal, float x, float y, float z) assert leavesTex != null; SimpleBakedModel.Builder builder = new SimpleBakedModel.Builder(blockModel, ItemOverrides.EMPTY, false).particle(leavesTex); - Helpers.assembleFaces(builder, part, fluffTex, modelLocation); - Helpers.assembleFaces(builder, partR, fluffTex, modelLocation); + Helpers.assembleFaces(builder, part, fluffTex); + Helpers.assembleFaces(builder, partR, fluffTex); - crosses[ordinal] = builder.build(NamedRenderTypeManager.get(new ResourceLocation("cutout_mipped"))); + crosses[ordinal] = builder.build(NamedRenderTypeManager.get(ResourceLocation.parse("cutout_mipped"))); } private BlockElementRotation makeRotation(float degrees) @@ -136,10 +134,10 @@ private BakedModel buildBlock(TextureAtlasSprite tex, boolean tint) for (Map.Entry e : part.faces.entrySet()) { Direction d = e.getKey(); - builder.addCulledFace(d, Helpers.makeBakedQuad(part, e.getValue(), tex, d, BlockModelRotation.X0_Y0, modelLocation)); + builder.addCulledFace(d, Helpers.makeBakedQuad(part, e.getValue(), tex, d, BlockModelRotation.X0_Y0)); } - return builder.build(NamedRenderTypeManager.get(new ResourceLocation("cutout_mipped"))); + return builder.build(NamedRenderTypeManager.get(ResourceLocation.parse("cutout_mipped"))); } @Override diff --git a/src/main/java/com/eerussianguy/betterfoliage/model/LeavesLoader.java b/src/main/java/com/eerussianguy/betterfoliage/model/LeavesLoader.java index 544891f..4cc269e 100644 --- a/src/main/java/com/eerussianguy/betterfoliage/model/LeavesLoader.java +++ b/src/main/java/com/eerussianguy/betterfoliage/model/LeavesLoader.java @@ -7,9 +7,9 @@ import net.minecraft.MethodsReturnNonnullByDefault; import net.minecraft.resources.ResourceLocation; import net.minecraft.util.GsonHelper; -import net.minecraftforge.client.model.geometry.IGeometryLoader; import com.eerussianguy.betterfoliage.Helpers; +import net.neoforged.neoforge.client.model.geometry.IGeometryLoader; @ParametersAreNonnullByDefault @MethodsReturnNonnullByDefault diff --git a/src/main/java/com/eerussianguy/betterfoliage/model/LeavesModel.java b/src/main/java/com/eerussianguy/betterfoliage/model/LeavesModel.java index fe78a5d..64f873e 100644 --- a/src/main/java/com/eerussianguy/betterfoliage/model/LeavesModel.java +++ b/src/main/java/com/eerussianguy/betterfoliage/model/LeavesModel.java @@ -6,15 +6,15 @@ import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.client.resources.model.*; import net.minecraft.resources.ResourceLocation; -import net.minecraftforge.client.model.geometry.IGeometryBakingContext; -import net.minecraftforge.client.model.geometry.IUnbakedGeometry; +import net.neoforged.neoforge.client.model.geometry.IGeometryBakingContext; +import net.neoforged.neoforge.client.model.geometry.IUnbakedGeometry; public record LeavesModel(ResourceLocation leaves, ResourceLocation fluff, ResourceLocation overlay, boolean tintLeaves, boolean tintOverlay) implements IUnbakedGeometry { @Override - public BakedModel bake(IGeometryBakingContext owner, ModelBaker bakery, Function spriteGetter, ModelState modelTransform, ItemOverrides overrides, ResourceLocation modelLocation) + public BakedModel bake(IGeometryBakingContext owner, ModelBaker bakery, Function spriteGetter, ModelState modelTransform, ItemOverrides overrides) { - return new LeavesBakedModel(modelLocation, leaves, fluff, overlay, tintLeaves, tintOverlay); + return new LeavesBakedModel(leaves, fluff, overlay, tintLeaves, tintOverlay); } } diff --git a/src/main/java/com/eerussianguy/betterfoliage/model/LeavesOrdinalData.java b/src/main/java/com/eerussianguy/betterfoliage/model/LeavesOrdinalData.java index fb6600d..567f3d8 100644 --- a/src/main/java/com/eerussianguy/betterfoliage/model/LeavesOrdinalData.java +++ b/src/main/java/com/eerussianguy/betterfoliage/model/LeavesOrdinalData.java @@ -4,9 +4,8 @@ import net.minecraft.core.BlockPos; -import net.minecraftforge.client.model.data.ModelProperty; - import com.eerussianguy.betterfoliage.BFConfig; +import net.neoforged.neoforge.client.model.data.ModelProperty; public class LeavesOrdinalData { diff --git a/src/main/resources/META-INF/mods.toml b/src/main/templates/META-INF/neoforge.mods.toml similarity index 85% rename from src/main/resources/META-INF/mods.toml rename to src/main/templates/META-INF/neoforge.mods.toml index 1b1d856..36ad263 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/templates/META-INF/neoforge.mods.toml @@ -1,11 +1,10 @@ modLoader="javafml" #mandatory -loaderVersion="[47,)" +loaderVersion="[4,)" license="MIT License" issueTrackerURL="https://github.com/eerussianguy/Better-Foliage/issues" #optional [[mods]] #mandatory modId="betterfoliage" #mandatory -version="${file.jarVersion}" #mandatory displayName="Better Foliage" #mandatory displayURL="https://github.com/eerussianguy/Better-Foliage" #optional logoFile="examplemod.png" #optional @@ -19,31 +18,31 @@ Most changes are configurable via resource pack. ''' [[dependencies.betterfoliage]] modId="minecraft" - mandatory=true - versionRange="[1.20.1, 1.21)" + type = "optional" + versionRange="[1.21, 1.22)" ordering="NONE" side="BOTH" [[dependencies.betterfoliage]] modId="biomesoplenty" - mandatory=false + type = "optional" versionRange="[0,)" ordering="AFTER" side="BOTH" [[dependencies.betterfoliage]] modId="quark" - mandatory=false + type = "optional" versionRange="[0,)" ordering="AFTER" side="BOTH" [[dependencies.betterfoliage]] modId="atmospheric" - mandatory=false + type = "optional" versionRange="[0,)" ordering="AFTER" side="BOTH" [[dependencies.betterfoliage]] modId="tfc" - mandatory=false + type = "optional" versionRange="[0,)" ordering="AFTER" side="BOTH"