diff options
31 files changed, 1076 insertions, 0 deletions
diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..5c372e2 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,7 @@ +root = true + +[*.kt] +charset = utf-8 +end_of_line = lf +indent_style = tab +insert_final_newline = true diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d4f1e7a --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +.idea +.gradle +build/ +*/build/ +versions/*/build/ +versions/*/run/ +.env +.properties diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 0000000..5e92d93 --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,147 @@ +import com.replaymod.gradle.preprocess.PreprocessExtension +import moe.nea.sharedbuild.Versions +import moe.nea.sharedbuild.parseEnvFile +import net.fabricmc.loom.api.LoomGradleExtensionAPI +import net.fabricmc.loom.task.RemapJarTask +import net.fabricmc.loom.task.RunGameTask +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +plugins { + id("java") + kotlin("jvm") + id("com.github.johnrengelman.shadow") +} + +val version = Versions.values().find { it.projectPath == project.path }!! +if (version.forgeDep != null) + extra.set("loom.platform", "forge") +apply(plugin = "gg.essential.loom") +apply(plugin = "com.replaymod.preprocess") + +val loom = the<LoomGradleExtensionAPI>() +val preprocess = the<PreprocessExtension>() + +if (version.needsPack200) { + loom.forge.pack200Provider.set(dev.architectury.pack200.java.Pack200Adapter()) +} +if (version.forgeDep != null) { + loom.forge.mixinConfig("mixins.ultranotifier.json") +} +val mcJavaVersion = JavaLanguageVersion.of( + when { + version.numericMinecraftVersion >= 12005 -> 21 + version.numericMinecraftVersion >= 11800 -> 17 + version.numericMinecraftVersion >= 11700 -> 16 + else -> 8 + } +) +loom.mixin.defaultRefmapName.set("mixins.ultranotifier.refmap.json") +java.toolchain.languageVersion.set(mcJavaVersion) +preprocess.run { + vars.put("MC", version.numericMinecraftVersion) + vars.put("FORGE", if ((version.forgeDep != null)) 1 else 0) +} + +repositories { + mavenCentral() + maven("https://maven.minecraftforge.net") { + metadataSources { + artifact() + } + } + maven("https://repo.spongepowered.org/maven/") + maven("https://pkgs.dev.azure.com/djtheredstoner/DevAuth/_packaging/public/maven/v1") + maven("https://jitpack.io") { + content { + includeGroupByRegex("(io|com)\\.github\\..+") + } + } +} + +loom.run { + this.runs { + this.removeIf { it.name != "client" } + this.named("client") { + parseEnvFile(file(".env")).forEach { (t, u) -> + this.environmentVariable(t, u) + } + parseEnvFile(file(".properties")).forEach { (t, u) -> + this.property(t, u) + } + this.property("mixin.debug", "true") + if (version == Versions.MC189) { + this.programArgs("--tweakClass", "org.spongepowered.asm.launch.MixinTweaker") + } + } + } +} +val modImplementation by configurations.getting +val shadowImpl by configurations.creating { + configurations.implementation.get().extendsFrom(this) +} +val shadowModImpl by configurations.creating { + modImplementation.extendsFrom(this) +} +val include = if (version.forgeDep != null) configurations.getByName("include") else shadowModImpl +val devauthVersion = "1.1.2" +dependencies { + "minecraft"("com.mojang:minecraft:" + version.minecraftVersion) + "mappings"(version.mappingDependency) + if (version.forgeDep != null) { + "forge"(version.forgeDep!!) + runtimeOnly("me.djtheredstoner:DevAuth-forge-legacy:$devauthVersion") + } else { + modImplementation("net.fabricmc:fabric-loader:0.15.10") + runtimeOnly("me.djtheredstoner:DevAuth-fabric:$devauthVersion") + } + shadowImpl("com.github.therealbush:eventbus:1.0.2") + if (version <= Versions.MC11404F) { + shadowImpl("org.spongepowered:mixin:0.7.11-SNAPSHOT") { + isTransitive = false + } + annotationProcessor("org.spongepowered:mixin:0.8.5-SNAPSHOT") + annotationProcessor("com.google.code.gson:gson:2.10.1") + annotationProcessor("com.google.guava:guava:17.0") + } +} + +tasks.withType<Jar> { + this.destinationDirectory.set(layout.buildDirectory.dir("badjars")) + if (version == Versions.MC189) { + manifest.attributes( + "FMLCorePluginContainsFMLMod" to "true", + "ForceLoadAsMod" to "true", + "TweakClass" to "org.spongepowered.asm.launch.MixinTweaker", + "MixinConfigs" to "mixins.ultranotifier.json" + ) + } +} + +tasks.jar { + archiveClassifier.set("without-dep") +} + +tasks.shadowJar { + archiveClassifier.set("all-dev") + configurations = listOf(shadowImpl, shadowModImpl) +} + +tasks.named("remapJar", RemapJarTask::class) { + this.destinationDirectory.set(layout.buildDirectory.dir("libs")) + from(tasks.shadowJar) + archiveClassifier.set("") + inputFile.set(tasks.shadowJar.flatMap { it.archiveFile }) +} +tasks.named("runClient", RunGameTask::class) { + this.javaLauncher.set(javaToolchains.launcherFor { + this.languageVersion.set(mcJavaVersion) + }) +} +if (version.isBridge) { + tasks.withType<JavaCompile> { + onlyIf { false } + } + tasks.withType<KotlinCompile> { + onlyIf { false } + } +} diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts new file mode 100644 index 0000000..d54cae9 --- /dev/null +++ b/buildSrc/build.gradle.kts @@ -0,0 +1,10 @@ +plugins { + java +} + +repositories { + mavenCentral() +} +dependencies { + implementation("com.google.code.gson:gson:2.10.1") +}
\ No newline at end of file diff --git a/check-correct-subproject.sh b/check-correct-subproject.sh new file mode 100755 index 0000000..023e5d4 --- /dev/null +++ b/check-correct-subproject.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash +# git hook to make sure you check out the current core version before committing +# to install, place it into your git hook folder with the appropriate name: +# +# cp check-correct-subproject.sh .git/hooks/pre-commit +# +# OR (to check a bit earlier) +# +# cp check-correct-subproject.sh .git/hooks/prepare-commit-msg +# + +currentMainProject="$(git show :versions/mainProject|tr -d '\n')" +currentMainVersion="$(git show :mainProject|tr -d '\n')" +if [ "x$currentMainVersion" != "x$currentMainProject" ]; then + echo "Currently checked out version is $currentMainProject, but $currentMainVersion should be committed." + echo "Run ./gradlew :${currentMainVersion}:setCoreVersion to fix" + echo + exit 1 +else + echo "Correct core version $currentMainVersion checked out" +fi + diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..d7a34a5 --- /dev/null +++ b/gradle.properties @@ -0,0 +1 @@ +org.gradle.jvmargs=-Xmx2g diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar Binary files differnew file mode 100644 index 0000000..249e583 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.jar diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..48c0a02 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists @@ -0,0 +1,234 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +APP_NAME="Gradle" +APP_BASE_NAME=${0##*/} + +# 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"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +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. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + 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. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..107acd3 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "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. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +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. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/mainProject b/mainProject new file mode 100644 index 0000000..e63679c --- /dev/null +++ b/mainProject @@ -0,0 +1 @@ +1.20.6 diff --git a/root.gradle.kts b/root.gradle.kts new file mode 100644 index 0000000..d7f638d --- /dev/null +++ b/root.gradle.kts @@ -0,0 +1,27 @@ +import com.replaymod.gradle.preprocess.Node +import moe.nea.sharedbuild.Versions + +plugins { + id("com.replaymod.preprocess") version "b09f534" +// id("fabric-loom") version "1.6-SNAPSHOT" apply false + kotlin("jvm") version "1.9.23" apply false + id("gg.essential.loom") version "1.6.+" apply false + id("dev.architectury.architectury-pack200") version "0.1.3" + id("com.github.johnrengelman.shadow") version "8.1.1" apply false +} + +allprojects { + version = "1.0.0" + group = "moe.nea.rxcraft" +} + +preprocess { + val nodes = mutableMapOf<Versions, Node>() + Versions.values().forEach { version -> + nodes[version] = createNode(version.projectName, version.numericMinecraftVersion, version.mappingStyle) + } + Versions.values().forEach { child -> + val parent = child.parent ?: return@forEach + nodes[parent]!!.link(nodes[child]!!, file("versions/mapping-${parent.projectName}-${child.projectName}.txt")) + } +}
\ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 0000000..3f927a5 --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1,39 @@ +import moe.nea.sharedbuild.Versions + +pluginManagement { + includeBuild("sharedVariables") + repositories { + maven("https://maven.fabricmc.net") + maven("https://jitpack.io") + mavenCentral() + google() + mavenCentral() + gradlePluginPortal() + maven("https://oss.sonatype.org/content/repositories/snapshots") + maven("https://maven.architectury.dev/") + maven("https://maven.minecraftforge.net/") + maven("https://repo.spongepowered.org/maven/") + maven("https://repo.sk1er.club/repository/maven-releases/") + } + resolutionStrategy { + eachPlugin { + when (requested.id.id) { + "com.replaymod.preprocess" -> useModule("com.github.replaymod:preprocessor:${requested.version}") + "gg.essential.loom" -> useModule("gg.essential:architectury-loom:${requested.version}") + } + } + } +} +plugins { + id("moe.nea.shared-variables") +} + +rootProject.name = "ultra-notifier" +rootProject.buildFileName = "root.gradle.kts" + +Versions.values().forEach { version -> + include(version.projectPath) + val p = project(version.projectPath) + p.projectDir = file("versions/${version.projectName}") + p.buildFileName = "../../build.gradle.kts" +} diff --git a/sharedVariables/build.gradle.kts b/sharedVariables/build.gradle.kts new file mode 100644 index 0000000..43c1182 --- /dev/null +++ b/sharedVariables/build.gradle.kts @@ -0,0 +1,31 @@ +plugins { + `kotlin-dsl` + kotlin("plugin.serialization") version "1.4.0" + `java-gradle-plugin` +} + +repositories { + mavenCentral() + maven("https://maven.fabricmc.net/") +} + +sourceSets { + main.configure { + this.kotlin.srcDir(file("src")) + } +} + +dependencies { +// implementation("net.fabricmc:tiny-remapper:0.8.6") +// implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.0.0") + + +} +gradlePlugin { + plugins { + create("simplePlugin") { + id = "moe.nea.shared-variables" + implementationClass = "moe.nea.sharedbuild.NoOp" + } + } +} diff --git a/sharedVariables/settings.gradle.kts b/sharedVariables/settings.gradle.kts new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/sharedVariables/settings.gradle.kts diff --git a/sharedVariables/src/EnvFileReader.kt b/sharedVariables/src/EnvFileReader.kt new file mode 100644 index 0000000..95cbe39 --- /dev/null +++ b/sharedVariables/src/EnvFileReader.kt @@ -0,0 +1,15 @@ +package moe.nea.sharedbuild + + +import java.io.File + +fun parseEnvFile(file: File): Map<String, String> { + if (!file.exists()) return mapOf() + val map = mutableMapOf<String, String>() + for (line in file.readText().lines()) { + if (line.isEmpty() || line.startsWith("#")) continue + val parts = line.split("=", limit = 2) + map[parts[0]] = parts.getOrNull(1) ?: "" + } + return map +}
\ No newline at end of file diff --git a/sharedVariables/src/NoOp.kt b/sharedVariables/src/NoOp.kt new file mode 100644 index 0000000..e8cd76e --- /dev/null +++ b/sharedVariables/src/NoOp.kt @@ -0,0 +1,9 @@ +package moe.nea.sharedbuild + +import org.gradle.api.Plugin + +class NoOp : Plugin<Any> { + override fun apply(target: Any) { + + } +}
\ No newline at end of file diff --git a/sharedVariables/src/Versions.kt b/sharedVariables/src/Versions.kt new file mode 100644 index 0000000..f559d03 --- /dev/null +++ b/sharedVariables/src/Versions.kt @@ -0,0 +1,39 @@ +package moe.nea.sharedbuild + +private fun yarn(version: String): String = + "net.fabricmc:yarn:${version}:v2" + +enum class Versions( + val projectName: String, + val mappingStyle: String, + val minecraftVersion: String, + val mappingDependency: String, + parentName: String?, + val forgeDep: String?, + val needsPack200: Boolean, + val isBridge: Boolean, +) { + MC189("1.8.9", "srg", "1.8.9", "de.oceanlabs.mcp:mcp_stable:22-1.8.9@zip", "MC11404F", "net.minecraftforge:forge:1.8.9-11.15.1.2318-1.8.9", true, false), + MC11404F("1.14.4-forge", "srg", "1.14.4", "de.oceanlabs.mcp:mcp_stable:58-1.14.4@zip", "MC11404", "net.minecraftforge:forge:1.14.4-28.1.113", false, true), + MC11404("1.14.4", "yarn", "1.14.4", yarn("1.14.4+build.1"), "MC12006", null, false, true), + MC12006("1.20.6", "yarn", "1.20.6", yarn("1.20.6+build.1"), null, null, false, false), + ; + + val parent: Versions? by lazy { + if (parentName == null) null + else Versions.values().find { it.name == parentName }!! + } + + val numericMinecraftVersion = run { + require(minecraftVersion.count { it == '.' } == 2) + val (a, b, c) = minecraftVersion.split(".").map { it.toInt() } + a * 10000 + b * 100 + c + } + val projectPath get() = ":$projectName" + + companion object { + init { + values().forEach { it.parent } + } + } +} diff --git a/src/main/java/moe/nea/ultranotifier/init/NeaMixinConfig.java b/src/main/java/moe/nea/ultranotifier/init/NeaMixinConfig.java new file mode 100644 index 0000000..a3fc4fc --- /dev/null +++ b/src/main/java/moe/nea/ultranotifier/init/NeaMixinConfig.java @@ -0,0 +1,185 @@ +package moe.nea.ultranotifier.init; + +//#if MC < 11404 +//$$import org.spongepowered.asm.lib.tree.ClassNode; +//#else +import org.objectweb.asm.tree.ClassNode; +//#endif +import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; +import org.spongepowered.asm.mixin.extensibility.IMixinInfo; + +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URISyntaxException; +import java.net.URL; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; +import java.util.stream.Stream; +import java.util.zip.ZipEntry; +import java.util.zip.ZipInputStream; + +public class NeaMixinConfig implements IMixinConfigPlugin { + + private static final List<NeaMixinConfig> mixinPlugins = new ArrayList<>(); + + public static List<NeaMixinConfig> getMixinPlugins() { + return mixinPlugins; + } + + private String mixinPackage; + + @Override + public void onLoad(String mixinPackage) { + this.mixinPackage = mixinPackage; + mixinPlugins.add(this); + } + + /** + * Resolves the base class root for a given class URL. This resolves either the JAR root, or the class file root. + * In either case the return value of this + the class name will resolve back to the original class url, or to other + * class urls for other classes. + */ + public URL getBaseUrlForClassUrl(URL classUrl) { + String string = classUrl.toString(); + if (classUrl.getProtocol().equals("jar")) { + try { + return new URL(string.substring(4).split("!")[0]); + } catch (MalformedURLException e) { + throw new RuntimeException(e); + } + } + if (string.endsWith(".class")) { + try { + return new URL(string.replace("\\", "/") + .replace(getClass().getCanonicalName() + .replace(".", "/") + ".class", "")); + } catch (MalformedURLException e) { + throw new RuntimeException(e); + } + } + return classUrl; + } + + /** + * Get the package that contains all the mixins. This value is set by mixin itself using {@link #onLoad}. + */ + public String getMixinPackage() { + return mixinPackage; + } + + /** + * Get the path inside the class root to the mixin package + */ + public String getMixinBaseDir() { + return mixinPackage.replace(".", "/"); + } + + /** + * A list of all discovered mixins. + */ + private List<String> mixins = null; + + /** + * Try to add mixin class ot the mixins based on the filepath inside of the class root. + * Removes the {@code .class} file suffix, as well as the base mixin package. + * <p><b>This method cannot be called after mixin initialization.</p> + * + * @param className the name or path of a class to be registered as a mixin. + */ + public void tryAddMixinClass(String className) { + String norm = (className.endsWith(".class") ? className.substring(0, className.length() - ".class".length()) : className) + .replace("\\", "/") + .replace("/", "."); + if (norm.startsWith(getMixinPackage() + ".") && !norm.endsWith(".")) { + mixins.add(norm.substring(getMixinPackage().length() + 1)); + } + } + + /** + * Search through the JAR or class directory to find mixins contained in {@link #getMixinPackage()} + */ + @Override + public List<String> getMixins() { + if (mixins != null) return mixins; + System.out.println("Trying to discover mixins"); + mixins = new ArrayList<>(); + URL classUrl = getClass().getProtectionDomain().getCodeSource().getLocation(); + System.out.println("Found classes at " + classUrl); + Path file; + try { + file = Paths.get(getBaseUrlForClassUrl(classUrl).toURI()); + } catch (URISyntaxException e) { + throw new RuntimeException(e); + } + System.out.println("Base directory found at " + file); + if (Files.isDirectory(file)) { + walkDir(file); + } else { + walkJar(file); + } + System.out.println("Found mixins: " + mixins); + + return mixins; + } + + /** + * Search through directory for mixin classes based on {@link #getMixinBaseDir}. + * + * @param classRoot The root directory in which classes are stored for the default package. + */ + private void walkDir(Path classRoot) { + System.out.println("Trying to find mixins from directory"); + try (Stream<Path> classes = Files.walk(classRoot.resolve(getMixinBaseDir()))) { + classes.map(it -> classRoot.relativize(it).toString()) + .forEach(this::tryAddMixinClass); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + /** + * Read through a JAR file, trying to find all mixins inside. + */ + private void walkJar(Path file) { + System.out.println("Trying to find mixins from jar file"); + try (ZipInputStream zis = new ZipInputStream(Files.newInputStream(file))) { + ZipEntry next; + while ((next = zis.getNextEntry()) != null) { + tryAddMixinClass(next.getName()); + zis.closeEntry(); + } + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + + @Override + public String getRefMapperConfig() { + return null; + } + + @Override + public boolean shouldApplyMixin(String targetClassName, String mixinClassName) { + return true; + } + + @Override + public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) { + + } + + @Override + public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { + + } + + @Override + public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { + + } +} diff --git a/src/main/java/moe/nea/ultranotifier/mixin/ChatHudMessageAdded.java b/src/main/java/moe/nea/ultranotifier/mixin/ChatHudMessageAdded.java new file mode 100644 index 0000000..b8239d3 --- /dev/null +++ b/src/main/java/moe/nea/ultranotifier/mixin/ChatHudMessageAdded.java @@ -0,0 +1,41 @@ +package moe.nea.ultranotifier.mixin; + +import moe.nea.ultranotifier.ChatLineAddedEvent; +import moe.nea.ultranotifier.UltraNotifierEvents; +import net.minecraft.client.gui.hud.ChatHud; +//#if MC > 11404 +import net.minecraft.client.gui.hud.MessageIndicator; +import net.minecraft.network.message.MessageSignatureData; +//#endif +import net.minecraft.text.Text; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin( + ChatHud.class +) +public class ChatHudMessageAdded { + @Inject( +//#if MC <= 11404 +//$$ method = "printChatMessageWithOptionalDeletion", +//#else + method = "addMessage(Lnet/minecraft/text/Text;Lnet/minecraft/network/message/MessageSignatureData;Lnet/minecraft/client/gui/hud/MessageIndicator;)V", +//#endif + at = @At("HEAD"), cancellable = true) + private void onAddMessage( + Text message, +//#if MC <= 11404 +//$$ int chatLineId, +//#else + MessageSignatureData signatureData, MessageIndicator indicator, +//#endif + CallbackInfo ci + ) { + if (UltraNotifierEvents.post(new ChatLineAddedEvent()).isCancelled()) { + ci.cancel(); + } + } + +} diff --git a/src/main/kotlin/Constants.kt b/src/main/kotlin/Constants.kt new file mode 100644 index 0000000..a1903ce --- /dev/null +++ b/src/main/kotlin/Constants.kt @@ -0,0 +1,27 @@ +package moe.nea.ultranotifier + + +object Constants { + const val MOD_ID = "ultranotifier" + const val VERSION = "1.0.0" + + enum class Platform { + FORGE, FABRIC + } + + val PLATFORM: Platform = +//#if FORGE +//$$ Platform.FORGE +//#else + Platform.FABRIC +//#endif + + const val MINECRAFT_VERSION: String = +//#if MC == 10809 +//$$ "1.8.9" +//#elseif MC == 12006 + "1.20.6" +//#elseif MC == 11404 +//$$ "1.14.4" +//#endif +} diff --git a/src/main/kotlin/UltraNotifier.kt b/src/main/kotlin/UltraNotifier.kt new file mode 100644 index 0000000..e6ce590 --- /dev/null +++ b/src/main/kotlin/UltraNotifier.kt @@ -0,0 +1,24 @@ +package moe.nea.ultranotifier + +import moe.nea.ultranotifier.init.NeaMixinConfig +import java.io.File + +object UltraNotifier { + val logger = +//#if MC == 10809 +//$$ org.apache.logging.log4j.LogManager.getLogger("UltraNotifier")!! +//#else + org.slf4j.LoggerFactory.getLogger("UltraNotifier")!! +//#endif + + fun onStartup() { + logger.info("Started on ${Constants.MINECRAFT_VERSION} ${Constants.PLATFORM} with version ${Constants.VERSION}!") + for (mixinPlugin in NeaMixinConfig.getMixinPlugins()) { + logger.info("Loaded ${mixinPlugin.mixins.size} mixins for ${mixinPlugin.mixinPackage}.") + } + } + + val configFolder = File("config/ultra-notifier").also { + it.mkdirs() + } +} diff --git a/src/main/kotlin/UltraNotifierEntryPoint.kt b/src/main/kotlin/UltraNotifierEntryPoint.kt new file mode 100644 index 0000000..34525ea --- /dev/null +++ b/src/main/kotlin/UltraNotifierEntryPoint.kt @@ -0,0 +1,25 @@ +package moe.nea.ultranotifier + +//#if FORGE +//$$ import net.minecraftforge.fml.common.Mod +//$$ +//#if MC == 10809 +//$$ import net.minecraftforge.fml.common.event.FMLInitializationEvent +//$$ @Mod(modid = Constants.MOD_ID, version = Constants.VERSION, useMetadata = true) +//#else +//$$ @Mod(Constants.MOD_ID) +//#endif +//$$ class UltraNotifierEntryPoint { +//$$ @Mod.EventHandler +//$$ fun onInit(@Suppress("UNUSED_PARAMETER") event: FMLInitializationEvent) { +//$$ UltraNotifier.onStartup() +//$$ } +//$$ } +//#else +import net.fabricmc.api.ModInitializer +object UltraNotifierEntryPoint : ModInitializer { + override fun onInitialize() { + UltraNotifier.onStartup() + } +} +//#endif diff --git a/src/main/kotlin/UltraNotifierEvents.kt b/src/main/kotlin/UltraNotifierEvents.kt new file mode 100644 index 0000000..eb0d71f --- /dev/null +++ b/src/main/kotlin/UltraNotifierEvents.kt @@ -0,0 +1,53 @@ +package moe.nea.ultranotifier + +object UltraNotifierEvents { + val eventBus = +//#if FORGE +//$$ net.minecraftforge.common.MinecraftForge.EVENT_BUS +//#else + me.bush.eventbus.bus.EventBus { UltraNotifier.logger.warn("EventBus: $it") } +//#endif + @JvmStatic + fun <T : UltraEvent> post(event: T): T { + UltraNotifier.logger.info("Posting $event") + eventBus.post(event) + return event + } +} + +abstract class UltraEvent : +//#if FORGE +//$$ net.minecraftforge.fml.common.eventhandler.Event() +//#else + me.bush.eventbus.event.Event() +//#endif +{ +//#if FORGE +//$$ override fun isCancelable(): Boolean { +//$$ return this.isCancellable() +//$$ } +//$$ fun isCancelled(): Boolean { +//$$ return isCanceled() +//$$ } +//$$ fun setCancelled(value: Boolean) { +//$$ setCanceled(value) +//$$ } +//#else + override +//#endif + + fun isCancellable(): Boolean { + return true + } + +//#if FORGE == 0 + override +//#endif + fun cancel() { + setCancelled(true) + } + +} + + +class ChatLineAddedEvent() : UltraEvent() diff --git a/src/main/resources/mixins.ultranotifier.json b/src/main/resources/mixins.ultranotifier.json new file mode 100644 index 0000000..03c353c --- /dev/null +++ b/src/main/resources/mixins.ultranotifier.json @@ -0,0 +1,7 @@ +{ + "compatibilityLevel": "JAVA_8", + "package": "moe.nea.ultranotifier.mixin", + "plugin": "moe.nea.ultranotifier.init.NeaMixinConfig", + "refmap": "mixins.ultranotifier.refmap.json", + "minVersion": "0.7" +}
\ No newline at end of file diff --git a/versions/1.20.6/src/main/resources/fabric.mod.json b/versions/1.20.6/src/main/resources/fabric.mod.json new file mode 100644 index 0000000..bd24129 --- /dev/null +++ b/versions/1.20.6/src/main/resources/fabric.mod.json @@ -0,0 +1,9 @@ +{ + "schemaVersion": 1, + "id": "ultranotifier", + "name": "Ultra Notifier", + "version": "${version}", + "entrypoints": { + "main": ["moe.nea.ultranotifier.UltraNotifierEntryPoint"] + } +}
\ No newline at end of file diff --git a/versions/1.8.9/src/main/resources/mcmod.info b/versions/1.8.9/src/main/resources/mcmod.info new file mode 100644 index 0000000..2d38802 --- /dev/null +++ b/versions/1.8.9/src/main/resources/mcmod.info @@ -0,0 +1,18 @@ +[ + { + "modid": "ultranotifier", + "name": "nea89s Ultra Notifier", + "description": "Ultratastic chat notifications and similar", + "version": "${version}", + "mcversion": "1.8.9", + "url": "https://github.com/nea89/ultra-notifier/", + "updateUrl": "", + "authorList": [ + "nea89" + ], + "credits": "", + "logoFile": "", + "screenshots": [], + "dependencies": [] + } +]
\ No newline at end of file diff --git a/versions/mainProject b/versions/mainProject new file mode 100644 index 0000000..7ad3277 --- /dev/null +++ b/versions/mainProject @@ -0,0 +1 @@ +1.20.6
\ No newline at end of file diff --git a/versions/mapping-1.14.4-1.14.4-forge.txt b/versions/mapping-1.14.4-1.14.4-forge.txt new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/versions/mapping-1.14.4-1.14.4-forge.txt diff --git a/versions/mapping-1.14.4-forge-1.8.9.txt b/versions/mapping-1.14.4-forge-1.8.9.txt new file mode 100644 index 0000000..0cce902 --- /dev/null +++ b/versions/mapping-1.14.4-forge-1.8.9.txt @@ -0,0 +1,2 @@ +net.minecraft.client.gui.NewChatGui net.minecraft.client.gui.GuiNewChat +net.minecraft.util.text.ITextComponent net.minecraft.util.IChatComponent
\ No newline at end of file diff --git a/versions/mapping-1.20.6-1.14.4.txt b/versions/mapping-1.20.6-1.14.4.txt new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/versions/mapping-1.20.6-1.14.4.txt |