Skip to content

Commit

Permalink
neoforge support for mc 1.20.6 and 1.21
Browse files Browse the repository at this point in the history
  • Loading branch information
Fallen-Breath committed Jul 1, 2024
1 parent 5ff5a69 commit 2662eef
Show file tree
Hide file tree
Showing 9 changed files with 124 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/scripts/matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def main():
matrix_entries = []
for subproject in subprojects:
mod_brand = subproject.split('-')[-1]
assert mod_brand in ['fabric', 'forge']
assert mod_brand in ['fabric', 'forge', 'neoforge']
matrix_entries.append({
'subproject': subproject,
'mod_brand': mod_brand,
Expand Down
7 changes: 7 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ preprocess {
def mc119_forge = createNode('1.19.4-forge' , 1_19_04, '')
def mc1204_forge = createNode('1.20.4-forge' , 1_20_04, '')
// Architectury Loom does not support mc1.20.5+ forge at all
// see also: https://github.com/architectury/architectury-loom/pull/219

def mc1206_neoforge = createNode('1.20.6-neoforge', 1_20_06, '')
def mc121_neoforge = createNode('1.21-neoforge' , 1_21_00, '')

mc114_fabric.link(mc115_fabric, null)
mc115_fabric.link(mc116_fabric, null)
Expand All @@ -45,6 +49,9 @@ preprocess {
mc118_fabric.link(mc118_forge, null)
mc119_fabric.link(mc119_forge, null)
mc1204_fabric.link(mc1204_forge, null)

mc1206_fabric.link(mc1206_neoforge, null)
mc121_fabric.link(mc121_neoforge, null)
}

tasks.register('buildAndGather') {
Expand Down
67 changes: 45 additions & 22 deletions common.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ apply plugin: 'com.replaymod.preprocess'
apply plugin: 'me.fallenbreath.yamlang'

def mod_brand = (loom.platform.get() as String).toLowerCase()
assert mod_brand in ['fabric', 'forge']
assert mod_brand in ['fabric', 'forge', 'neoforge']
assert project.name.endsWith('-' + mod_brand) // optional check

int mcVersion = 1
Expand All @@ -16,6 +16,8 @@ preprocess {
vars.put("MC", mcVersion)
vars.put("FABRIC", mod_brand == 'fabric' ? 1 : 0)
vars.put("FORGE", mod_brand == 'forge' ? 1 : 0)
vars.put("NEOFORGE", mod_brand == 'neoforge' ? 1 : 0)
vars.put("FORGE_LIKE", mod_brand in ['forge', 'neoforge'] ? 1 : 0)
}

repositories {
Expand All @@ -25,6 +27,9 @@ repositories {
maven {
url 'https://maven.fallenbreath.me/releases'
}
maven {
url 'https://maven.neoforged.net/releases'
}
}

// https://github.com/FabricMC/fabric-loader/issues/783
Expand All @@ -35,12 +40,22 @@ configurations {
dependencies {
// loom
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
if (mod_brand == 'fabric' || mod_brand == 'forge') {
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
} else {
// https://github.com/architectury/architectury-loom/issues/214
mappings loom.layered {
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
it.mappings("dev.architectury:yarn-mappings-patch-neoforge:${project.yarn_mappings_patch}")
}
}

if (mod_brand == 'fabric') {
modImplementation "net.fabricmc:fabric-loader:${project.fabric_loader_version}"
} else {
} else if (mod_brand == 'forge') {
forge "net.minecraftforge:forge:${project.minecraft_version}-${project.forge_version}"
} else if (mod_brand == 'neoforge') {
neoForge "net.neoforged:neoforge:${project.neoforge_version}"
}

// runtime mods
Expand Down Expand Up @@ -100,10 +115,10 @@ String finalModVersion = project.mod_version + modVersionSuffix
String fullProjectVersion, fullArtifactVersion

// Example version values:
// project.mod_version 1.0.3 (the base mod version)
// finalModVersion 1.0.3+build.88 (the actual mod version to use)
// fullProjectVersion mc1.15.2-v1.0.3+build.88 (in build output jar name)
// fullArtifactVersion mc1.15.2-v1.0.3-SNAPSHOT (maven artifact version)
// project.mod_version 1.0.3 (the base mod version)
// finalModVersion 1.0.3+build.88 (the actual mod version to use)
// fullProjectVersion mc1.15.2-fabric-v1.0.3+build.88 (in build output jar name)
// fullArtifactVersion mc1.15.2-fabric-v1.0.3-SNAPSHOT (maven artifact version)

group = project.maven_group
if (System.getenv("JITPACK") == "true") {
Expand All @@ -126,32 +141,40 @@ processResources {
inputs.property "version", finalModVersion
inputs.property "minecraft_dependency", project.minecraft_dependency

def good_files = [] as Set
def all_files = [] as Set
[
'fabric': ['fabric.mod.json'],
'forge': ['META-INF', 'META-INF/mods.toml', 'pack.mcmeta'],
].forEach { brand, files ->
files.forEach { name ->
if (brand == mod_brand) {
filesMatching(name) {
def valueMap = [
"id": project.mod_id,
"name": project.mod_name,
"version": finalModVersion,
"minecraft_dependency": project.minecraft_dependency,
]
expand valueMap
}
} else {
exclude name
'neoforge': ['META-INF', 'META-INF/neoforge.mods.toml', 'pack.mcmeta'],
].forEach { brand, paths ->
all_files.addAll(paths)
if (brand == mod_brand) {
good_files.addAll(paths)
}
}
all_files.forEach { it2 ->
def path = it2 as String
if (good_files.contains(path)) {
filesMatching(path) {
def valueMap = [
"id": project.mod_id,
"name": project.mod_name,
"version": finalModVersion,
"minecraft_dependency": project.minecraft_dependency,
]
expand valueMap
}
} else {
exclude path
}
}

filesMatching(MIXIN_CONFIG_PATH) {
filter { s -> s.replace('{{COMPATIBILITY_LEVEL}}', "JAVA_${MIXIN_COMPATIBILITY_LEVEL.ordinal() + 1}") }
}

if (mod_brand == 'forge') {
if (mod_brand == 'forge' || mod_brand == 'neoforge') {
// forge requires the mod icon file to be at the resource root
filesMatching(MOD_ICON_PATH) { f -> f.path = new File(f.path).getName() }
}
Expand Down
5 changes: 4 additions & 1 deletion settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
"1.17.1-forge",
"1.18.2-forge",
"1.19.4-forge",
"1.20.4-forge"
"1.20.4-forge",

"1.20.6-neoforge",
"1.21-neoforge"
]
}
13 changes: 9 additions & 4 deletions src/main/java/me/fallenbreath/template_mod/TemplateMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,17 @@
import net.fabricmc.api.ModInitializer;
import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.api.metadata.ModMetadata;

//#elseif FORGE
//$$ import net.minecraftforge.fml.ModList;
//$$ import net.minecraftforge.fml.common.Mod;
//$$ import net.minecraftforge.forgespi.language.IModInfo;
//$$
//#elseif NEOFORGE
//$$ import net.neoforged.fml.ModList;
//$$ import net.neoforged.fml.common.Mod;
//$$ import net.neoforged.neoforgespi.language.IModInfo;
//#endif

//#if FORGE_LIKE
//$$ @Mod(TemplateMod.MOD_ID)
//#endif
public class TemplateMod
Expand Down Expand Up @@ -66,13 +71,13 @@ public void onInitialize()
LOGGER.info("Hello {} v{} from fabric!", MOD_NAME, MOD_VERSION);
this.init();
}
//#elseif FORGE
//#elseif FORGE_LIKE
//$$ public TemplateMod()
//$$ {
//$$ IModInfo modInfo = ModList.get().getModContainerById(MOD_ID).orElseThrow(RuntimeException::new).getModInfo();
//$$ MOD_NAME = modInfo.getDisplayName();
//$$ MOD_VERSION = modInfo.getVersion().toString();
//$$ LOGGER.info("Hello {} v{} from forge!", MOD_NAME, MOD_VERSION);
//$$ LOGGER.info("Hello {} v{} from forge-like!", MOD_NAME, MOD_VERSION);
//$$ this.init();
//$$ }
//#endif
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/META-INF/mods.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
modLoader = "javafml"
loaderVersion = "[31,)"
license = "LGPLv3"
issueTrackerURL = "https://github.com/Fallen-Breath/fabric-mod-template/issues"

[[mods]]
modId = "${id}"
Expand Down
25 changes: 25 additions & 0 deletions src/main/resources/META-INF/neoforge.mods.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
modLoader="javafml"
loaderVersion="[1,)"
license = "LGPLv3"
issueTrackerURL = "https://github.com/Fallen-Breath/fabric-mod-template/issues"

[[mods]]
modId = "${id}"
version = "${version}"
displayName = "${name}"
displayURL = "https://github.com/Fallen-Breath/fabric-mod-template"
authors = "Fallen_Breath"
description = '''
Template for my fabric mods
'''
logoFile = "icon.png"

[[mixins]]
config = "${id}.mixins.json"

[[dependencies."${id}"]]
modId = "minecraft"
mandatory = true
versionRange = "${minecraft_dependency}"
ordering = "NONE"
side = "BOTH"
16 changes: 16 additions & 0 deletions versions/1.20.6-neoforge/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Loom Properties
# check these on https://fallen-breath.github.io/fabric-versions/?&version=1.20.6
minecraft_version=1.20.6
yarn_mappings=1.20.6+build.3
loom.platform=neoforge
# https://maven.architectury.dev/dev/architectury/yarn-mappings-patch-neoforge/
yarn_mappings_patch=1.20.6+build.4

# Mod Metadata
# https://projects.neoforged.net/neoforged/neoforge
neoforge_version=20.6.119
minecraft_dependency=[1.20.6]

# Build Information
# The target mc versions for the mod during mod publishing, separated with \n
game_versions=1.20.6
16 changes: 16 additions & 0 deletions versions/1.21-neoforge/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Loom Properties
# check these on https://fallen-breath.github.io/fabric-versions/?&version=1.21
minecraft_version=1.21
yarn_mappings=1.21+build.2
loom.platform=neoforge
# https://maven.architectury.dev/dev/architectury/yarn-mappings-patch-neoforge/
yarn_mappings_patch=1.21+build.4

# Mod Metadata
# https://projects.neoforged.net/neoforged/neoforge
neoforge_version=21.0.43-beta
minecraft_dependency=[1.21]

# Build Information
# The target mc versions for the mod during mod publishing, separated with \n
game_versions=1.21

0 comments on commit 2662eef

Please sign in to comment.