From 6c732f2cac03d8dceca79a445b4504b1d1175b07 Mon Sep 17 00:00:00 2001 From: Wulian233 <71213467+Wulian233@users.noreply.github.com> Date: Sun, 4 Feb 2024 19:26:04 +0800 Subject: [PATCH] clean + fix --- .github/workflows/release.yml | 38 ++++++++++++++++ CHANGELOG.md | 7 +++ build.gradle | 45 ++++++++++++++++--- .../VMTranslationUpdate.java | 4 +- .../config/ModConfigs.java | 2 +- .../forge/VMTranslationUpdateClientForge.java | 6 ++- gradle.properties | 7 ++- gradle/wrapper/gradle-wrapper.properties | 2 +- 8 files changed, 98 insertions(+), 13 deletions(-) create mode 100644 .github/workflows/release.yml create mode 100644 CHANGELOG.md diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..4aa9117 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,38 @@ +name: Publish Release + +on: + workflow_dispatch: + release: + types: + - published + +permissions: + contents: write + +jobs: + Build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Set up JDK 20 + uses: actions/setup-java@v3 + with: + distribution: 'adopt' + java-version: 20 + - name: Cache + uses: actions/cache@v3 + with: + path: | + ~/.gradle/caches + ~/.gradle/wrapper + .gradle + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties', 'build.gradle') }} + - uses: gradle/wrapper-validation-action@v1 + - run: | + chmod +x gradlew + ./gradlew mergeJars publishMods --stacktrace -Porg.gradle.parallel.threads=4 + env: + CURSEFORGE_TOKEN: ${{ secrets.CURSEFORGE_TOKEN }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + MODRINTH_TOKEN: ${{ secrets.MODRINTH_TOKEN }} \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..5f3af9d --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,7 @@ +## 更新日志 +- Add mod release workflow +- clean code + +## Changelog +- 添加 mod release workflow +- 代码清理 \ No newline at end of file diff --git a/build.gradle b/build.gradle index ca6f0be..502082e 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,8 @@ plugins { id "architectury-plugin" version "3.4-SNAPSHOT" id "io.github.pacifistmc.forgix" version "1.2.6" - id "dev.architectury.loom" version "1.3-SNAPSHOT" apply false + id "dev.architectury.loom" version "1.4-SNAPSHOT" apply false + id "me.modmuss50.mod-publish-plugin" version "0.4.5" } architectury { @@ -23,7 +24,7 @@ allprojects { apply plugin: "maven-publish" archivesBaseName = rootProject.archives_base_name - version = "${rootProject.mod_version}-${rootProject.minecraft_version}" + version = "${rootProject.mod_version}+mc${rootProject.minecraft_version}" group = rootProject.maven_group repositories { @@ -46,16 +47,50 @@ allprojects { forgix { group = rootProject.maven_group - mergedJarName = "${rootProject.archives_base_name}-${project.version}.jar" + mergedJarName = "${rootProject.archives_base_name}-${rootProject.version}.jar" outputDir = "build/libs/forgix" forge { projectName = "forge" - jarLocation = "build/libs/${rootProject.archives_base_name}-forge-${ rootProject.version }.jar" + jarLocation = "build/libs/${rootProject.archives_base_name}-forge-${rootProject.version}.jar" } fabric { projectName = "fabric" - jarLocation = "build/libs/${rootProject.archives_base_name}-fabric-${ rootProject.version }.jar" + jarLocation = "build/libs/${rootProject.archives_base_name}-fabric-${rootProject.version}.jar" } } + +publishMods { + file = file(forgix.getOutputDir() + "/" + forgix.getMergedJarName()) + changelog = file("CHANGELOG.md").getText('UTF-8') + type = STABLE + modLoaders = ["fabric", "forge"] + + var CURSEFORGE_TOKEN = project.findProperty("CURSEFORGE_TOKEN") ?: System.getenv("CURSEFORGE_TOKEN") + if (CURSEFORGE_TOKEN != null) { + curseforge { + projectId = rootProject.curseforge_id + accessToken = providers.environmentVariable(CURSEFORGE_TOKEN as Provider) + minecraftVersions = ["1.19.3", "1.19.4"] + + requires { + slug = ["architectury-api", "cloth-config"] + } + } + } + + + var MODRINTH_TOKEN = project.findProperty("MODRINTH_TOKEN") ?: System.getenv("MODRINTH_TOKEN") + if (MODRINTH_TOKEN != null) { + modrinth { + projectId = rootProject.modrinth_id + accessToken = providers.environmentVariable(MODRINTH_TOKEN as Provider) + minecraftVersions = ["1.19.3", "1.19.4"] + } + + requires { + slug = ["architectury-api", "cloth-config"] + } + } +} \ No newline at end of file diff --git a/common/src/main/java/top/vmctcn/vmtranslationupdate/VMTranslationUpdate.java b/common/src/main/java/top/vmctcn/vmtranslationupdate/VMTranslationUpdate.java index 03fada1..460f33a 100644 --- a/common/src/main/java/top/vmctcn/vmtranslationupdate/VMTranslationUpdate.java +++ b/common/src/main/java/top/vmctcn/vmtranslationupdate/VMTranslationUpdate.java @@ -18,13 +18,13 @@ import java.util.concurrent.CompletableFuture; public class VMTranslationUpdate { - public static final Random random = new Random(); + public static Random random = new Random(); public static int tickCounter; public static final String MODNAME = "VMTranslationUpdate"; public static final String MOD_ID = "vmtranslationupdate"; static MinecraftClient client = MinecraftClient.getInstance(); - private static final boolean isStenographerLoaded = Platform.isModLoaded("stenographer"); // Stenographer 兼容 public static final Logger LOGGER = LoggerFactory.getLogger(MODNAME); + private static final boolean isStenographerLoaded = Platform.isModLoaded("stenographer"); // Stenographer 兼容 public static void init() { if (ModConfigUtil.getConfig().autoSwitchLanguage && !isStenographerLoaded) { diff --git a/common/src/main/java/top/vmctcn/vmtranslationupdate/config/ModConfigs.java b/common/src/main/java/top/vmctcn/vmtranslationupdate/config/ModConfigs.java index d28f8ce..2d18482 100644 --- a/common/src/main/java/top/vmctcn/vmtranslationupdate/config/ModConfigs.java +++ b/common/src/main/java/top/vmctcn/vmtranslationupdate/config/ModConfigs.java @@ -19,6 +19,6 @@ public class ModConfigs implements ConfigData { public String modPackTranslationVersion = "1.0.0"; public int tipsMinutes = 25; public String traslationPackName = "VM汉化组模组汉化包1.19"; - public String traslationPackUrl= "https://cdn.modrinth.com/data/IDWIdXwS/versions/acZy8zAY/VM汉化组模组汉化包1.19"; + public String traslationPackUrl= "https://cdn.modrinth.com/data/IDWIdXwS/versions/acZy8zAY/"; public String nameUrl = "https://vmct-cn.top/name.json"; } diff --git a/forge/src/main/java/top/vmctcn/vmtranslationupdate/forge/VMTranslationUpdateClientForge.java b/forge/src/main/java/top/vmctcn/vmtranslationupdate/forge/VMTranslationUpdateClientForge.java index 763c0ed..925daf6 100644 --- a/forge/src/main/java/top/vmctcn/vmtranslationupdate/forge/VMTranslationUpdateClientForge.java +++ b/forge/src/main/java/top/vmctcn/vmtranslationupdate/forge/VMTranslationUpdateClientForge.java @@ -1,12 +1,12 @@ package top.vmctcn.vmtranslationupdate.forge; import dev.architectury.platform.forge.EventBuses; -import dev.architectury.utils.EnvExecutor; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.fml.IExtensionPoint; import net.minecraftforge.fml.ModLoadingContext; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; +import net.minecraftforge.fml.loading.FMLLoader; import net.minecraftforge.network.NetworkConstants; import top.vmctcn.vmtranslationupdate.VMTranslationUpdate; import top.vmctcn.vmtranslationupdate.util.ModConfigUtil; @@ -17,7 +17,9 @@ public VMTranslationUpdateClientForge() { ModLoadingContext.get().registerExtensionPoint(IExtensionPoint.DisplayTest.class, () -> new IExtensionPoint.DisplayTest(() -> NetworkConstants.IGNORESERVERONLY, (a, b) -> true)); EventBuses.registerModEventBus(VMTranslationUpdate.MOD_ID, FMLJavaModLoadingContext.get().getModEventBus()); - EnvExecutor.runInEnv(Dist.CLIENT, () -> this::onInitializeClient); + if (FMLLoader.getDist() == Dist.CLIENT) { + onInitializeClient(); + } } public void onInitializeClient() { diff --git a/gradle.properties b/gradle.properties index 4590289..0be961c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,8 +6,8 @@ enabled_platforms=fabric,forge yarn_mappings=1.19.4+build.2 archives_base_name=VMTranslationUpdate -mod_version=2.3 -maven_group=top.vmctcn +mod_version=2.3.1 +maven_group=top.vmctcn.vmtranslationupdate architectury_version=8.2.89 clothconfig_version=10.1.117 @@ -16,3 +16,6 @@ fabric_loader_version=0.14.22 fabric_api_version=0.87.2+1.19.4 forge_version=1.19.4-45.2.8 + +curseforge_id=890229 +modrinth_id=wvCSIW08 \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index fae0804..e411586 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ 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.4-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists