-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
59f1826
commit 863aa7d
Showing
67 changed files
with
403 additions
and
243 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
repositories { | ||
mavenCentral() | ||
flatDir { dirs "../libs" } | ||
} | ||
|
||
dependencies { | ||
implementation "com.google.code.gson:gson:+" | ||
implementation "it.unimi.dsi:fastutil:+" | ||
implementation "commons-io:commons-io:+" | ||
implementation "org.mtr:Minecraft-Mod-API-Tools:0.0.1" | ||
} | ||
|
||
java { | ||
toolchain { | ||
languageVersion.set(JavaLanguageVersion.of(8)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package org.mtr.mod; | ||
|
||
import com.google.gson.JsonElement; | ||
import com.google.gson.JsonObject; | ||
import com.google.gson.JsonParser; | ||
import com.jonafanho.apitools.ModId; | ||
import com.jonafanho.apitools.ModLoader; | ||
import com.jonafanho.apitools.ModProvider; | ||
import org.apache.commons.io.IOUtils; | ||
import org.apache.log4j.LogManager; | ||
import org.apache.log4j.Logger; | ||
import org.gradle.api.Project; | ||
|
||
import java.net.URL; | ||
import java.nio.charset.StandardCharsets; | ||
import java.nio.file.Path; | ||
|
||
public class BuildTools | ||
{ | ||
public final String minecraftVersion; | ||
public final String loader; | ||
public final int javaLanguageVersion; | ||
private final Path path; | ||
private final String version; | ||
private final String mtrVersion; | ||
|
||
public BuildTools(String minecraftVersion, String loader, String mtrVersion, Project project) { | ||
this.minecraftVersion = minecraftVersion; | ||
this.loader = loader; | ||
this.path = project.getProjectDir().toPath(); | ||
this.version = project.getVersion().toString(); | ||
this.mtrVersion = mtrVersion; | ||
int majorVersion = Integer.parseInt(minecraftVersion.split("\\.")[1]); | ||
javaLanguageVersion = majorVersion <= 16 ? 8 : majorVersion == 17 ? 16 : 17; | ||
} | ||
|
||
public String getFabricVersion() { | ||
String fabricVersion = getJson("https://meta.fabricmc.net/v2/versions/loader/" + minecraftVersion).getAsJsonArray().get(0).getAsJsonObject().getAsJsonObject("loader").get("version").getAsString(); | ||
System.out.println("Fabric loader version: " + fabricVersion); | ||
return fabricVersion; | ||
} | ||
|
||
public String getYarnVersion() { | ||
String yarnVersion = getJson("https://meta.fabricmc.net/v2/versions/yarn/" + minecraftVersion).getAsJsonArray().get(0).getAsJsonObject().get("version").getAsString(); | ||
System.out.println("Yarn version: " + yarnVersion); | ||
return yarnVersion; | ||
} | ||
|
||
public String getFabricApiVersion() { | ||
final String modIdString = "fabric-api"; | ||
String fabricApiVersion = new ModId(modIdString, ModProvider.MODRINTH).getModFiles(minecraftVersion, ModLoader.FABRIC, "").get(0).fileName.split(".jar")[0].replace(modIdString + "-", ""); | ||
System.out.println("Fabric API version: " + fabricApiVersion); | ||
return fabricApiVersion; | ||
} | ||
|
||
public String getModMenuVersion() { | ||
if (minecraftVersion.equals("1.20.4")) { | ||
return "9.0.0"; // TODO latest version not working | ||
} | ||
final String modIdString = "modmenu"; | ||
String modMenuVersion = new ModId(modIdString, ModProvider.MODRINTH).getModFiles(minecraftVersion, ModLoader.FABRIC, "").get(0).fileName.split(".jar")[0].replace(modIdString + "-", ""); | ||
System.out.println("ModMenu version: " + modMenuVersion); | ||
return modMenuVersion; | ||
} | ||
|
||
public String getForgeVersion() { | ||
String forgeVersion = getJson("https://files.minecraftforge.net/net/minecraftforge/forge/promotions_slim.json").getAsJsonObject().getAsJsonObject("promos").get(minecraftVersion + "-latest").getAsString(); | ||
System.out.println("Forge version: " + forgeVersion); | ||
return forgeVersion; | ||
} | ||
|
||
private static JsonElement getJson(String url) { | ||
for (int i = 0; i < 5; i++) { | ||
try { | ||
return JsonParser.parseString(IOUtils.toString(new URL(url), StandardCharsets.UTF_8)); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
try { | ||
Thread.sleep(1000); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
return new JsonObject(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,48 @@ | ||
import org.mtr.mod.BuildTools | ||
|
||
plugins { | ||
id 'fabric-loom' version '1.7-SNAPSHOT' | ||
id 'fabric-loom' version '+' | ||
} | ||
|
||
final BuildTools buildTools = new BuildTools(minecraft_version, "fabric", mtr_version, project) | ||
|
||
loom { | ||
runConfigs.configureEach { ideConfigGenerated = true } | ||
mixin { | ||
setDefaultRefmapName("tjmetro.refmap.json") | ||
} | ||
} | ||
|
||
repositories { | ||
maven { url = "https://maven.terraformersmc.com/" } | ||
} | ||
|
||
def yarn_version = project.properties["yarn_mappings_${rootProject.minecraft_version}"] | ||
def fabric_api_version = project.properties["fabric_api_version_${rootProject.minecraft_version}"] | ||
def mod_menu_version = project.properties["mod_menu_version_${rootProject.minecraft_version}"] | ||
def cloth_config_version = project.properties["cloth_config_version_${rootProject.minecraft_version}"] | ||
|
||
dependencies { | ||
// To change the versions see the gradle.properties file | ||
minecraft "com.mojang:minecraft:${rootProject.minecraft_version}" | ||
mappings "net.fabricmc:yarn:${yarn_version}:v2" | ||
modImplementation "org.mtr:MTR-fabric:${rootProject.mtr_version}+${rootProject.minecraft_version}-server" | ||
minecraft "com.mojang:minecraft:${minecraft_version}" | ||
mappings "net.fabricmc:yarn:${buildTools.getYarnVersion()}:v2" | ||
String FabricVersion = buildTools.getFabricVersion() | ||
modImplementation "net.fabricmc:fabric-loader:${FabricVersion}" | ||
modImplementation "net.fabricmc.fabric-api:fabric-api:${buildTools.getFabricApiVersion()}" | ||
//modImplementation(files("E:\\Tianjin-Metro\\libs\\MTR-fabric-4.0.0-beta-8+1.16.5-server.jar")) | ||
modImplementation "net.fabricmc:fabric-loader:${project.fabric_loader_version}" | ||
modImplementation "net.fabricmc.fabric-api:fabric-api:${fabric_api_version}" | ||
modApi "com.terraformersmc:modmenu:${mod_menu_version}" | ||
modApi ("ziyue.filters:filters-fabric:1.0.0+${rootProject.minecraft_version}") { | ||
modApi "com.terraformersmc:modmenu:${buildTools.getModMenuVersion()}" | ||
modApi("ziyue.filters:filters-fabric:1.0.0+${minecraft_version}") { | ||
exclude(group: "net.fabricmc") | ||
} | ||
annotationProcessor 'systems.manifold:manifold-preprocessor:2023.1.33' // Delibrate: Newer versions just throws an error *when displaying an compiling error* | ||
} | ||
|
||
tasks.withType(JavaCompile).configureEach { | ||
it.options.release = 16 | ||
} | ||
|
||
configurations.configureEach { | ||
// Force use our version of mod-loader even if dependency requires a lower mod-loader so the game can launch | ||
// May cause problems, but they're usually backward compatible | ||
resolutionStrategy { | ||
force("net.fabricmc:fabric-loader:$project.fabric_loader_version") | ||
// Uncomment this if you got "java.lang.IllegalStateException: duplicate fabric loader classes found on classpath". | ||
configurations.configureEach { | ||
resolutionStrategy { | ||
force("net.fabricmc:fabric-loader:${FabricVersion}") | ||
} | ||
} | ||
modImplementation "org.mtr:MTR-fabric:${mtr_version}+${minecraft_version}-server" | ||
annotationProcessor 'systems.manifold:manifold-preprocessor:+' | ||
// Delibrate: Newer versions just throws an error *when displaying an compiling error* | ||
} | ||
|
||
java { | ||
withSourcesJar() | ||
|
||
sourceCompatibility = JavaVersion.VERSION_16 | ||
targetCompatibility = JavaVersion.VERSION_16 | ||
repositories { | ||
maven { url = "https://maven.terraformersmc.com/" } | ||
} | ||
|
||
jar { | ||
from("LICENSE") { | ||
rename { "${it}_${base.archivesName.get()}"} | ||
java { | ||
toolchain { | ||
languageVersion.set(JavaLanguageVersion.of(buildTools.javaLanguageVersion)) | ||
} | ||
withSourcesJar() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.