Skip to content

Commit

Permalink
Renamed version, Fixed bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
ZiYueCommentary committed Jul 27, 2024
1 parent 59f1826 commit 863aa7d
Show file tree
Hide file tree
Showing 67 changed files with 403 additions and 243 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# Tianjin Metro

<img alt="Requires Java 16" height="50px" src="icons/requires_java16.svg"/>

A small mod for [Minecraft Transit Railway](https://github.com/jonafanho/Minecraft-Transit-Railway), in developing stage.

## How to build
Expand Down
37 changes: 14 additions & 23 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,33 +1,20 @@
plugins {
id "java"
id "io.github.pacifistmc.forgix" version "1.+"
}

group "ziyue.tjmetro"
version mod_version + "+" + minecraft_version

forgix {
group = "ziyue.tjmetro"
mergedJarName = "${project.archives_base_name}-${project.mod_version}+${project.minecraft_version}.jar"
outputDir = "build/"

fabric {
projectName = "fabric"
jarLocation = "build/libs/${project.archives_base_name}-fabric-${project.mod_version}+${project.minecraft_version}.jar"
}

forge {
projectName = "forge"
jarLocation = "build/libs/${project.archives_base_name}-forge-${project.mod_version}+${project.minecraft_version}.jar"
}
mergedJarName = "Tianjin-Metro-" + version + ".jar"
outputDir = "build"
}

subprojects {
apply plugin: "java"

group project.maven_group
version "${rootProject.properties.mod_version}+${rootProject.properties.minecraft_version}"

base {
archivesName = "${rootProject.archives_base_name}-${project.properties.loader_name}"
}

dependencies {
implementation 'com.google.code.findbugs:jsr305:+'
}
Expand All @@ -36,7 +23,6 @@ subprojects {
flatDir { dirs "../libs" }
maven { url "https://jitpack.io" }
maven { url "https://maven.ziyuesinicization.site/releases/" }
maven { url "https://maven.shedaniel.me/" }
}

def mc_ver = rootProject.properties.minecraft_version
Expand All @@ -46,8 +32,11 @@ subprojects {
def merged_mc_version = "$mc_major$mc_main$mc_minor"

ext { // Expose to subproject
java_version = 17

java_version =
(merged_mc_version as int) <= 11605 ? 8 :
(merged_mc_version as int) <= 11701 ? 16 :
(merged_mc_version as int) <= 12004 ? 17 :
21
full_mod_version = version
}

Expand Down Expand Up @@ -82,7 +71,9 @@ subprojects {
)
}
}
}

subprojects {
build.finalizedBy(mergeJars)
assemble.finalizedBy(mergeJars)
}
}
17 changes: 17 additions & 0 deletions buildSrc/build.gradle
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))
}
}
88 changes: 88 additions & 0 deletions buildSrc/src/main/java/org/mtr/mod/BuildTools.java
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();
}
}
66 changes: 29 additions & 37 deletions fabric/build.gradle
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()
}
2 changes: 1 addition & 1 deletion fabric/src/main/java/ziyue/tjmetro/mod/EntityTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import ziyue.tjmetro.mod.entity.EntitySeat;

/**
* @since beta-1
* @since 1.0.0-beta-1
*/

public interface EntityTypes
Expand Down
5 changes: 3 additions & 2 deletions fabric/src/main/java/ziyue/tjmetro/mod/Reference.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@
/**
* References for <b>Tianjin Metro Mod</b>.
*
* @since beta-1
* @since 1.0.0-beta-1
*/

public interface Reference
{
String MOD_ID = "tjmetro";
String NAME = "Tianjin Metro";
String VERSION = "beta-1";
String VERSION = "1.0.0-beta-1";

String GITHUB_REPO = "https://github.com/ZiYueCommentary/Tianjin-Metro";
String CONTRIBUTORS = "https://github.com/ZiYueCommentary/Tianjin-Metro/graphs/contributors";
String FORUM = "https://forum.ziyuesinicization.site/t/tianjin-metro";
String WEBLATE = "https://weblate.ziyuesinicization.site/engage/tianjin-metro/";
String DISCORD = "https://discord.gg/mEvEjPnVXe";
}
5 changes: 3 additions & 2 deletions fabric/src/main/java/ziyue/tjmetro/mod/Registry.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,18 @@
/**
* Register for some methods that have different implement ways.
*
* @since beta-1
* @since 1.0.0-beta-1
*/

public final class Registry
{
public static final org.mtr.mapping.registry.Registry REGISTRY = new org.mtr.mapping.registry.Registry();
public static final org.mtr.mapping.registry.Registry REGISTRY_TABS = new org.mtr.mapping.registry.Registry();
public static final List<Pair<Filter, ItemRegistryObject>> FILTERS_REGISTRY_ITEM = new ArrayList<>();
public static final List<Pair<Filter, BlockRegistryObject>> FILTERS_REGISTRY_BLOCK = new ArrayList<>();

public static CreativeModeTabHolder createCreativeModeTabHolder(String id, Supplier<ItemStack> icon) {
return REGISTRY.createCreativeModeTabHolder(new Identifier(Reference.MOD_ID, id), icon);
return REGISTRY_TABS.createCreativeModeTabHolder(new Identifier(Reference.MOD_ID, id), icon);
}

public static BlockRegistryObject registerBlock(String id, Supplier<Block> supplier) {
Expand Down
2 changes: 2 additions & 0 deletions fabric/src/main/java/ziyue/tjmetro/mod/TianjinMetro.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public static void init() {
LOGGER.info("Mod ID: " + Reference.MOD_ID);
LOGGER.info("Version: " + Reference.VERSION);

Registry.REGISTRY_TABS.init();

BlockList.registerBlocks();
ItemList.registerItems();
BlockEntityTypes.registerBlockEntities();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*
* @author ZiYueCommentary
* @see org.mtr.mod.block.BlockAPGGlass
* @since beta-1
* @since 1.0.0-beta-1
*/

public class BlockAPGCorner extends BlockExtension implements DirectionHelper
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
/**
* @author ZiYueCommentary
* @see EntitySeat
* @since beta-1
* @since 1.0.0-beta-1
*/

public class BlockBench extends BlockExtension implements DirectionHelper, IBlock
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/**
* @author ZiYueCommentary
* @see BlockCustomColorBase
* @since beta-1
* @since 1.0.0-beta-1
*/

public class BlockCustomColorConcrete extends BlockCustomColorBase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
/**
* @author ZiYueCommentary
* @see BlockCustomColorBase
* @since beta-1
* @since 1.0.0-beta-1
*/

public class BlockCustomColorConcreteSlab extends SlabBlockExtension implements BlockWithEntity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
/**
* @author ZiYueCommentary
* @see BlockCustomColorBase
* @since beta-1
* @since 1.0.0-beta-1
*/

public class BlockCustomColorConcreteStairs extends StairBlock implements BlockWithEntity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
/**
* @author ZiYueCommentary
* @see BlockEmergencyExitSignStyle
* @since beta-1
* @since 1.0.0-beta-1
*/

public class BlockEmergencyExitSign extends BlockExtension implements DirectionHelper
Expand Down Expand Up @@ -58,7 +58,7 @@ public void addBlockProperties(List<HolderBase<?>> properties) {
*
* @author ZiYueCommentary
* @see BlockEmergencyExitSign
* @since beta-1
* @since 1.0.0-beta-1
*/
public enum BlockEmergencyExitSignStyle implements StringIdentifiable
{
Expand Down
Loading

0 comments on commit 863aa7d

Please sign in to comment.