diff options
25 files changed, 1516 insertions, 0 deletions
diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..8539f5a --- /dev/null +++ b/.editorconfig @@ -0,0 +1,5 @@ +root = true + +[*.java] +ij_java_use_single_class_imports = true + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..69fa48a --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +.idea/ +.vscode/ +run/ +build/ +.gradle/ + diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 0000000..9e73297 --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,98 @@ +plugins { + idea + java + id("gg.essential.loom") version "0.10.0.+" + id("dev.architectury.architectury-pack200") version "0.1.3" + id("com.github.johnrengelman.shadow") version "7.1.2" + kotlin("jvm") version "1.9.10" +} + +group = "com.example.archloomtemplate" +version = "1.0.0" + +// Toolchains: +java { + toolchain.languageVersion.set(JavaLanguageVersion.of(8)) +} + +val fcpEntryPoint = "moe.nea.modernjava.launch.FCPEntryPoint" + +// Minecraft configuration: +loom { + log4jConfigs.from(file("log4j2.xml")) + launchConfigs { + "client" { + property("fml.coreMods.load", fcpEntryPoint) + } + } + forge { + pack200Provider.set(dev.architectury.pack200.java.Pack200Adapter()) + } +} + +repositories { + mavenCentral() + maven("https://jitpack.io") { + content { + includeGroupByRegex("(com|io)\\.github\\..+") + } + } +} + +val shadowImpl: Configuration by configurations.creating { + configurations.implementation.get().extendsFrom(this) +} + +val shadowOnly: Configuration by configurations.creating { + attributes { + this.attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, 16) + } +} + + +dependencies { + minecraft("com.mojang:minecraft:1.8.9") + mappings("de.oceanlabs.mcp:mcp_stable:22-1.8.9") + forge("net.minecraftforge:forge:1.8.9-11.15.1.2318-1.8.9") + + shadowOnly("javax.annotation:javax.annotation-api:1.3.2") + shadowImpl("com.github.Skytils:AsmHelper:91ecc2bd9c") + shadowImpl(enforcedPlatform(kotlin("bom"))) + shadowImpl(kotlin("stdlib")) +} + +// Tasks: + +tasks.withType(JavaCompile::class) { + options.encoding = "UTF-8" +} + +tasks.withType(Jar::class) { + archiveBaseName.set("ModernJavaLauncher") + manifest.attributes.run { + this["FMLCorePlugin"] = fcpEntryPoint + this["ModSide"] = "BOTH" + this["ModType"] = "FML" + this["FMLCorePluginContainsFMLMod"] = "true" + this["ForceLoadAsMod"] = "true" + } +} + + +val remapJar by tasks.named<net.fabricmc.loom.task.RemapJarTask>("remapJar") { + archiveClassifier.set("") + from(tasks.shadowJar) + input.set(tasks.shadowJar.get().archiveFile) +} + +tasks.jar { + archiveClassifier.set("thin-dev") +} + +tasks.shadowJar { + archiveClassifier.set("all-dev") + configurations = listOf(shadowImpl, shadowOnly) +} + +tasks.assemble.get().dependsOn(tasks.remapJar) + diff --git a/examplemod.ipr b/examplemod.ipr new file mode 100644 index 0000000..4ec7ca2 --- /dev/null +++ b/examplemod.ipr @@ -0,0 +1,104 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="CompilerConfiguration"> + <option name="DEFAULT_COMPILER" value="Javac"/> + <resourceExtensions> + <entry name=".+\.(properties|xml|html|dtd|tld)"/> + <entry name=".+\.(gif|png|jpeg|jpg)"/> + </resourceExtensions> + <wildcardResourcePatterns> + <entry name="!?*.class"/> + <entry name="!?*.scala"/> + <entry name="!?*.groovy"/> + <entry name="!?*.java"/> + </wildcardResourcePatterns> + <annotationProcessing enabled="false" useClasspath="true"/> + <bytecodeTargetLevel target="1.8"/> + </component> + <component name="CopyrightManager" default=""> + <module2copyright/> + </component> + <component name="DependencyValidationManager"> + <option name="SKIP_IMPORT_STATEMENTS" value="false"/> + </component> + <component name="Encoding" useUTFGuessing="true" native2AsciiForPropertiesFiles="false"/> + <component name="GradleUISettings"> + <setting name="root"/> + </component> + <component name="GradleUISettings2"> + <setting name="root"/> + </component> + <component name="IdProvider" IDEtalkID="11DA1DB66DD62DDA1ED602B7079FE97C"/> + <component name="JavadocGenerationManager"> + <option name="OUTPUT_DIRECTORY"/> + <option name="OPTION_SCOPE" value="protected"/> + <option name="OPTION_HIERARCHY" value="true"/> + <option name="OPTION_NAVIGATOR" value="true"/> + <option name="OPTION_INDEX" value="true"/> + <option name="OPTION_SEPARATE_INDEX" value="true"/> + <option name="OPTION_DOCUMENT_TAG_USE" value="false"/> + <option name="OPTION_DOCUMENT_TAG_AUTHOR" value="false"/> + <option name="OPTION_DOCUMENT_TAG_VERSION" value="false"/> + <option name="OPTION_DOCUMENT_TAG_DEPRECATED" value="true"/> + <option name="OPTION_DEPRECATED_LIST" value="true"/> + <option name="OTHER_OPTIONS" value=""/> + <option name="HEAP_SIZE"/> + <option name="LOCALE"/> + <option name="OPEN_IN_BROWSER" value="true"/> + </component> + <component name="ProjectModuleManager"> + <modules> + <module fileurl="file://$PROJECT_DIR$/examplemod.iml" filepath="$PROJECT_DIR$/examplemod.iml"/> + </modules> + </component> + <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" assert-keyword="true" jdk-15="true" project-jdk-type="JavaSDK" assert-jdk-15="true" project-jdk-name="19"> + <output url="file://$PROJECT_DIR$/out"/> + </component> + <component name="SvnBranchConfigurationManager"> + <option name="mySupportsUserInfoFilter" value="true"/> + </component> + <component name="VcsDirectoryMappings"> + <mapping directory="" vcs=""/> + </component> + <component name="masterDetails"> + <states> + <state key="ArtifactsStructureConfigurable.UI"> + <UIState> + <splitter-proportions> + <SplitterProportionsDataImpl/> + </splitter-proportions> + <settings/> + </UIState> + </state> + <state key="Copyright.UI"> + <UIState> + <splitter-proportions> + <SplitterProportionsDataImpl/> + </splitter-proportions> + </UIState> + </state> + <state key="ProjectJDKs.UI"> + <UIState> + <splitter-proportions> + <SplitterProportionsDataImpl> + <option name="proportions"> + <list> + <option value="0.2"/> + </list> + </option> + </SplitterProportionsDataImpl> + </splitter-proportions> + <last-edited>1.6</last-edited> + </UIState> + </state> + <state key="ScopeChooserConfigurable.UI"> + <UIState> + <splitter-proportions> + <SplitterProportionsDataImpl/> + </splitter-proportions> + <settings/> + </UIState> + </state> + </states> + </component> +</project> diff --git a/examplemod.iws b/examplemod.iws new file mode 100644 index 0000000..0819613 --- /dev/null +++ b/examplemod.iws @@ -0,0 +1,427 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<project version="4"> + + <component name="ChangeListManager"> + + <option name="TRACKING_ENABLED" value="true"/> + + <option name="SHOW_DIALOG" value="false"/> + + <option name="HIGHLIGHT_CONFLICTS" value="true"/> + + <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false"/> + + <option name="LAST_RESOLUTION" value="IGNORE"/> + + </component> + + <component flattened_view="true" name="ChangesViewManager" show_ignored="false"/> + + <component name="CreatePatchCommitExecutor"> + + <option name="PATCH_PATH" value=""/> + + <option name="REVERSE_PATCH" value="false"/> + + </component> + + <component name="DaemonCodeAnalyzer"> + + <disable_hints/> + + </component> + + <component name="DebuggerManager"> + + <breakpoint_any> + + <breakpoint> + + <option name="NOTIFY_CAUGHT" value="true"/> + + <option name="NOTIFY_UNCAUGHT" value="true"/> + + <option name="ENABLED" value="false"/> + + <option name="LOG_ENABLED" value="false"/> + + <option name="LOG_EXPRESSION_ENABLED" value="false"/> + + <option name="SUSPEND_POLICY" value="SuspendAll"/> + + <option name="COUNT_FILTER_ENABLED" value="false"/> + + <option name="COUNT_FILTER" value="0"/> + + <option name="CONDITION_ENABLED" value="false"/> + + <option name="CLASS_FILTERS_ENABLED" value="false"/> + + <option name="INSTANCE_FILTERS_ENABLED" value="false"/> + + <option name="CONDITION" value=""/> + + <option name="LOG_MESSAGE" value=""/> + + </breakpoint> + + <breakpoint> + + <option name="NOTIFY_CAUGHT" value="true"/> + + <option name="NOTIFY_UNCAUGHT" value="true"/> + + <option name="ENABLED" value="false"/> + + <option name="LOG_ENABLED" value="false"/> + + <option name="LOG_EXPRESSION_ENABLED" value="false"/> + + <option name="SUSPEND_POLICY" value="SuspendAll"/> + + <option name="COUNT_FILTER_ENABLED" value="false"/> + + <option name="COUNT_FILTER" value="0"/> + + <option name="CONDITION_ENABLED" value="false"/> + + <option name="CLASS_FILTERS_ENABLED" value="false"/> + + <option name="INSTANCE_FILTERS_ENABLED" value="false"/> + + <option name="CONDITION" value=""/> + + <option name="LOG_MESSAGE" value=""/> + + </breakpoint> + + </breakpoint_any> + + <breakpoint_rules/> + + <ui_properties/> + + </component> + + <component name="ModuleEditorState"> + + <option name="LAST_EDITED_MODULE_NAME"/> + + <option name="LAST_EDITED_TAB_NAME"/> + + </component> + + <component name="ProjectInspectionProfilesVisibleTreeState"> + + <entry key="Project Default"> + + <profile-state/> + + </entry> + + </component> + + <component name="ProjectLevelVcsManager"> + + <OptionsSetting id="Add" value="true"/> + + <OptionsSetting id="Remove" value="true"/> + + <OptionsSetting id="Checkout" value="true"/> + + <OptionsSetting id="Update" value="true"/> + + <OptionsSetting id="Status" value="true"/> + + <OptionsSetting id="Edit" value="true"/> + + <ConfirmationsSetting id="Add" value="0"/> + + <ConfirmationsSetting id="Remove" value="0"/> + + </component> + + <component name="ProjectReloadState"> + + <option name="STATE" value="0"/> + + </component> + + <component name="PropertiesComponent"> + + <property name="GoToFile.includeJavaFiles" value="false"/> + + <property name="GoToClass.toSaveIncludeLibraries" value="false"/> + + <property name="MemberChooser.sorted" value="false"/> + + <property name="MemberChooser.showClasses" value="true"/> + + <property name="GoToClass.includeLibraries" value="false"/> + + <property name="MemberChooser.copyJavadoc" value="false"/> + + </component> + + <component name="RunManager"> + + <configuration default="true" factoryName="Remote" type="Remote"> + + <option name="USE_SOCKET_TRANSPORT" value="true"/> + + <option name="SERVER_MODE" value="false"/> + + <option name="SHMEM_ADDRESS" value="javadebug"/> + + <option name="HOST" value="localhost"/> + + <option name="PORT" value="5005"/> + + <method> + + <option enabled="false" name="BuildArtifacts"/> + + </method> + + </configuration> + + <configuration default="true" factoryName="Applet" type="Applet"> + + <module name=""/> + + <option name="MAIN_CLASS_NAME"/> + + <option name="HTML_FILE_NAME"/> + + <option name="HTML_USED" value="false"/> + + <option name="WIDTH" value="400"/> + + <option name="HEIGHT" value="300"/> + + <option name="POLICY_FILE" value="$APPLICATION_HOME_DIR$/bin/appletviewer.policy"/> + + <option name="VM_PARAMETERS"/> + + <option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false"/> + + <option name="ALTERNATIVE_JRE_PATH"/> + + <method> + + <option enabled="false" name="BuildArtifacts"/> + + <option enabled="true" name="Make"/> + + </method> + + </configuration> + + <configuration default="true" factoryName="Application" type="Application"> + + <extension enabled="false" merge="false" name="coverage"/> + + <option name="MAIN_CLASS_NAME"/> + + <option name="VM_PARAMETERS"/> + + <option name="PROGRAM_PARAMETERS"/> + + <option name="WORKING_DIRECTORY" value="$PROJECT_DIR$"/> + + <option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false"/> + + <option name="ALTERNATIVE_JRE_PATH"/> + + <option name="ENABLE_SWING_INSPECTOR" value="false"/> + + <option name="ENV_VARIABLES"/> + + <option name="PASS_PARENT_ENVS" value="true"/> + + <module name=""/> + + <envs/> + + <method> + + <option enabled="false" name="BuildArtifacts"/> + + <option enabled="true" name="Make"/> + + </method> + + </configuration> + + <configuration default="true" factoryName="JUnit" type="JUnit"> + + <extension enabled="false" merge="false" name="coverage"/> + + <module name=""/> + + <option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false"/> + + <option name="ALTERNATIVE_JRE_PATH"/> + + <option name="PACKAGE_NAME"/> + + <option name="MAIN_CLASS_NAME"/> + + <option name="METHOD_NAME"/> + + <option name="TEST_OBJECT" value="class"/> + + <option name="VM_PARAMETERS"/> + + <option name="PARAMETERS"/> + + <option name="WORKING_DIRECTORY" value="$PROJECT_DIR$"/> + + <option name="ENV_VARIABLES"/> + + <option name="PASS_PARENT_ENVS" value="true"/> + + <option name="TEST_SEARCH_SCOPE"> + + <value defaultName="moduleWithDependencies"/> + + </option> + + <envs/> + + <method> + + <option enabled="false" name="BuildArtifacts"/> + + <option enabled="true" name="Make"/> + + </method> + + </configuration> + + <list size="0"/> + + <configuration default="true" name="<template>" selected="false" type="WebApp"> + + <Host>localhost</Host> + + <Port>5050</Port> + + </configuration> + + <component name="ProjectRunConfigurationManager"/> + <configuration default="false" factoryName="Application" name="Minecraft Client" type="Application"> + <module name="examplemod.main"/> + <option name="MAIN_CLASS_NAME" value="net.fabricmc.devlaunchinjector.Main"/> + <option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$/run"/> + <option name="VM_PARAMETERS" value=""-Dfabric.dli.config=/home/nea/src/ModernJavaLauncher/.gradle/loom-cache/launch.cfg" "-Dfabric.dli.env=client" "-Dfabric.dli.main=net.minecraft.launchwrapper.Launch""/> + </configuration> + <component name="ProjectRunConfigurationManager"/> + <configuration default="false" factoryName="Application" name="Minecraft Server" type="Application"> + <module name="examplemod.main"/> + <option name="MAIN_CLASS_NAME" value="net.fabricmc.devlaunchinjector.Main"/> + <option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$/run"/> + <option name="VM_PARAMETERS" value=""-Dfabric.dli.config=/home/nea/src/ModernJavaLauncher/.gradle/loom-cache/launch.cfg" "-Dfabric.dli.env=server" "-Dfabric.dli.main=net.minecraft.launchwrapper.Launch""/> + <option name="PROGRAM_PARAMETERS" value=""nogui""/> + </configuration> + </component> + + <component name="ShelveChangesManager" show_recycled="false"/> + + <component maxAnnotateRevisions="500" name="SvnConfiguration"> + + <option name="USER" value=""/> + + <option name="PASSWORD" value=""/> + + <option name="LAST_MERGED_REVISION"/> + + <option name="UPDATE_RUN_STATUS" value="false"/> + + <option name="MERGE_DRY_RUN" value="false"/> + + <option name="MERGE_DIFF_USE_ANCESTRY" value="true"/> + + <option name="UPDATE_LOCK_ON_DEMAND" value="false"/> + + <option name="IGNORE_SPACES_IN_MERGE" value="false"/> + + <option name="DETECT_NESTED_COPIES" value="true"/> + + <option name="IGNORE_SPACES_IN_ANNOTATE" value="true"/> + + <option name="SHOW_MERGE_SOURCES_IN_ANNOTATE" value="true"/> + + <myIsUseDefaultProxy>false</myIsUseDefaultProxy> + + </component> + + <component name="TaskManager"> + + <task active="true" id="Default" summary="Default task"/> + + <servers/> + + </component> + + <component name="VcsManagerConfiguration"> + + <option name="OFFER_MOVE_TO_ANOTHER_CHANGELIST_ON_PARTIAL_COMMIT" value="true"/> + + <option name="CHECK_CODE_SMELLS_BEFORE_PROJECT_COMMIT" value="true"/> + + <option name="PERFORM_UPDATE_IN_BACKGROUND" value="true"/> + + <option name="PERFORM_COMMIT_IN_BACKGROUND" value="true"/> + + <option name="PERFORM_EDIT_IN_BACKGROUND" value="true"/> + + <option name="PERFORM_CHECKOUT_IN_BACKGROUND" value="true"/> + + <option name="PERFORM_ADD_REMOVE_IN_BACKGROUND" value="true"/> + + <option name="PERFORM_ROLLBACK_IN_BACKGROUND" value="false"/> + + <option name="CHECK_LOCALLY_CHANGED_CONFLICTS_IN_BACKGROUND" value="false"/> + + <option name="ENABLE_BACKGROUND_PROCESSES" value="false"/> + + <option name="CHANGED_ON_SERVER_INTERVAL" value="60"/> + + <option name="FORCE_NON_EMPTY_COMMENT" value="false"/> + + <option name="LAST_COMMIT_MESSAGE"/> + + <option name="MAKE_NEW_CHANGELIST_ACTIVE" value="true"/> + + <option name="OPTIMIZE_IMPORTS_BEFORE_PROJECT_COMMIT" value="false"/> + + <option name="CHECK_FILES_UP_TO_DATE_BEFORE_COMMIT" value="false"/> + + <option name="REFORMAT_BEFORE_PROJECT_COMMIT" value="false"/> + + <option name="REFORMAT_BEFORE_FILE_COMMIT" value="false"/> + + <option name="FILE_HISTORY_DIALOG_COMMENTS_SPLITTER_PROPORTION" value="0.8"/> + + <option name="FILE_HISTORY_DIALOG_SPLITTER_PROPORTION" value="0.5"/> + + <option name="ACTIVE_VCS_NAME"/> + + <option name="UPDATE_GROUP_BY_PACKAGES" value="false"/> + + <option name="UPDATE_GROUP_BY_CHANGELIST" value="false"/> + + <option name="SHOW_FILE_HISTORY_AS_TREE" value="false"/> + + <option name="FILE_HISTORY_SPLITTER_PROPORTION" value="0.6"/> + + </component> + + <component name="XDebuggerManager"> + + <breakpoint-manager/> + + </component> + +</project> diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..7a79fe1 --- /dev/null +++ b/gradle.properties @@ -0,0 +1,2 @@ +loom.platform=forge +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..e708b1c --- /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..8049c68 --- /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-7.5-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists @@ -0,0 +1,185 @@ +#!/usr/bin/env sh + +# +# Copyright 2015 the original author or 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 UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$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 "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# 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 + ;; + 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" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=`expr $i + 1` + done + case $i in + 0) set -- ;; + 1) set -- "$args0" ;; + 2) set -- "$args0" "$args1" ;; + 3) set -- "$args0" "$args1" "$args2" ;; + 4) set -- "$args0" "$args1" "$args2" "$args3" ;; + 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=`save "$@"` + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +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/install.sh b/install.sh new file mode 100755 index 0000000..89a94d8 --- /dev/null +++ b/install.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +set -euo pipefail + +rm -f ~/.local/share/PrismLauncher/instances/1.8.9/.minecraft/mods/examplemod-* +./gradlew :build :target:build +cp ./build/libs/examplemod-1.0.0.jar ~/.local/share/PrismLauncher/instances/1.8.9/.minecraft/mods + + + + diff --git a/log4j2.xml b/log4j2.xml new file mode 100644 index 0000000..af9b1b7 --- /dev/null +++ b/log4j2.xml @@ -0,0 +1,5 @@ +<?xml version="1.0" encoding="UTF-8"?> +<Configuration status="WARN"> + <!-- Filter out Hypixel scoreboard and sound errors --> + <RegexFilter regex="Error executing task.*|Unable to play unknown soundEvent.*" onMatch="DENY" onMismatch="NEUTRAL"/> +</Configuration>
\ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 0000000..febc074 --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1,23 @@ +pluginManagement { + repositories { + mavenCentral() + gradlePluginPortal() + maven("https://oss.sonatype.org/content/repositories/snapshots") + maven("https://maven.architectury.dev/") + maven("https://maven.fabricmc.net") + 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) { + "gg.essential.loom" -> useModule("gg.essential:architectury-loom:${requested.version}") + } + } + } +} + +include("target") + +rootProject.name = "ModernJavaLauncher" diff --git a/src/main/java/moe/nea/modernjava/launch/FCPEntryPoint.java b/src/main/java/moe/nea/modernjava/launch/FCPEntryPoint.java new file mode 100644 index 0000000..3c32931 --- /dev/null +++ b/src/main/java/moe/nea/modernjava/launch/FCPEntryPoint.java @@ -0,0 +1,65 @@ +package moe.nea.modernjava.launch; + +import moe.nea.modernjava.launch.util.ClassLoaderManipulations; +import net.minecraftforge.fml.relauncher.IFMLLoadingPlugin; + +import java.net.URI; +import java.util.List; +import java.util.Map; + + +@IFMLLoadingPlugin.Name("ModernJavaRelauncher") +public class FCPEntryPoint implements IFMLLoadingPlugin { + static URI fileUri; + + static { + try { + fileUri = new URI(FCPEntryPoint.class.getProtectionDomain().getCodeSource().getLocation().toString().split("!")[0]); + } catch (Exception e) { + throw new RuntimeException(e); + } + if (System.getProperty("modernjava.hasrelaunched") == null) { + try { + Class.forName("moe.nea.modernjava.launch.FCPRelauncher").getMethod("relaunch").invoke(null); + } catch (Throwable t) { + System.out.println("Failed to relaunch"); + t.printStackTrace(); + } + } else { + try { + ClassLoaderManipulations.addToParentClassLoader(fileUri.toURL()); + } catch (Exception e) { + throw new RuntimeException(e); + } + List<String> tweakClasses = WellKnownBlackboard.tweakerNames(); + tweakClasses.add(FCPMixinAwareTweaker.class.getName()); + } + } + + + @Override + public String[] getASMTransformerClass() { + return new String[]{ + }; + } + + @Override + public String getModContainerClass() { + return null; + } + + @Override + public String getSetupClass() { + return null; + } + + @Override + public void injectData(Map<String, Object> map) { + + } + + @Override + public String getAccessTransformerClass() { + return null; + } +} diff --git a/src/main/java/moe/nea/modernjava/launch/FCPMixinAwareTweaker.java b/src/main/java/moe/nea/modernjava/launch/FCPMixinAwareTweaker.java new file mode 100644 index 0000000..585e943 --- /dev/null +++ b/src/main/java/moe/nea/modernjava/launch/FCPMixinAwareTweaker.java @@ -0,0 +1,28 @@ +package moe.nea.modernjava.launch; + +import net.minecraft.launchwrapper.ITweaker; +import net.minecraft.launchwrapper.LaunchClassLoader; + +import java.io.File; +import java.util.List; + +public class FCPMixinAwareTweaker implements ITweaker { + @Override + public void acceptOptions(List<String> args, File gameDir, File assetsDir, String profile) { + } + + @Override + public void injectIntoClassLoader(LaunchClassLoader classLoader) { + classLoader.registerTransformer("moe.nea.modernjava.launch.transform.TransObjectHolderRef"); + } + + @Override + public String getLaunchTarget() { + return null; + } + + @Override + public String[] getLaunchArguments() { + return new String[0]; + } +} diff --git a/src/main/java/moe/nea/modernjava/launch/FCPRelauncher.java b/src/main/java/moe/nea/modernjava/launch/FCPRelauncher.java new file mode 100644 index 0000000..ec27694 --- /dev/null +++ b/src/main/java/moe/nea/modernjava/launch/FCPRelauncher.java @@ -0,0 +1,102 @@ +package moe.nea.modernjava.launch; + +import net.minecraft.launchwrapper.Launch; +import net.minecraftforge.fml.common.launcher.FMLTweaker; +import net.minecraftforge.fml.nea.moe.modernjava.IAMFML; + +import java.io.File; +import java.io.FileDescriptor; +import java.io.FileOutputStream; +import java.io.IOException; +import java.lang.management.ManagementFactory; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +public class FCPRelauncher { + public static void relaunch() { + + List<String> originalArgs = new ArrayList<>(); + + // Provided by FML + // This is highly processed so there might be some arguments that become lost, but almost everything should be in here. + // Namely non -- arguments get lost. I don't know any of these arguments that the vanilla launcher uses, so it should be fine? + // Also some tweakers are missing. But we can fix this. + Map<String, String> launchArgs = WellKnownBlackboard.launchArgs(); + if ("UnknownFMLProfile".equals(launchArgs.get("--version"))) { + launchArgs.remove("--version"); + } + for (Map.Entry<String, String> argument : launchArgs.entrySet()) { + originalArgs.add(argument.getKey()); + originalArgs.add(argument.getValue()); + } + + + originalArgs.add("--tweakClass"); + originalArgs.add(FMLTweaker.class.getName()); + + System.out.println("Reconstructed original minecraft arguments: " + originalArgs); + + String modernJavaPath = "/home/nea/.sdkman/candidates/java/16.0.2-tem/bin/java"; + + + String thisJarFile = FCPEntryPoint.class.getProtectionDomain().getCodeSource().getLocation().getFile(); + thisJarFile = "/home/nea/src/ModernJavaLauncher/target/build/libs/target.jar"; + System.out.println("Found modern java jar at: " + thisJarFile); + + System.out.println("Located modern minecraft at: " + modernJavaPath); + + ProcessBuilder processBuilder = new ProcessBuilder(); + processBuilder.inheritIO(); + processBuilder.directory(null); + + + List<String> moduleOpens = new ArrayList<>(); + moduleOpens.add("java.base/java.util=ALL-UNNAMED"); + moduleOpens.add("java.base/jdk.internal.loader=ALL-UNNAMED"); + moduleOpens.add("java.base/java.lang.reflect=ALL-UNNAMED"); + + + List<String> fullCommandLine = new ArrayList<>(); + fullCommandLine.add(modernJavaPath); + fullCommandLine.addAll(ManagementFactory.getRuntimeMXBean().getInputArguments()); + fullCommandLine.add("-Dmodernjava.hasrelaunched=true"); + fullCommandLine.add("-Dmodernjava.relaunchclasspath=" + thisJarFile + File.pathSeparator + ManagementFactory.getRuntimeMXBean().getClassPath()); + fullCommandLine.add("--illegal-access=permit"); + for (String open : moduleOpens) { + fullCommandLine.add("--add-opens"); + fullCommandLine.add(open); + } + fullCommandLine.add("-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005"); + fullCommandLine.add("-javaagent:" + thisJarFile); + fullCommandLine.add("--add-modules=ALL-MODULE-PATH,ALL-SYSTEM,ALL-DEFAULT,java.sql"); + fullCommandLine.add("-Xbootclasspath/a:" + thisJarFile); + fullCommandLine.add("moe.nea.modernjava.target.RelaunchEntryPoint"); + fullCommandLine.addAll(originalArgs); + + System.out.println("Full relaunch commandline: " + fullCommandLine); + + + processBuilder.command(fullCommandLine); + int exitCode; + try { + try { + Process process = processBuilder.start(); + exitCode = process.waitFor(); + } finally { + try { + new FileOutputStream(FileDescriptor.out).flush(); + new FileOutputStream(FileDescriptor.err).flush(); + } catch (IOException ignored) { + } + } + } catch (IOException | InterruptedException e) { + throw new RuntimeException("Failed to relaunch with old java version", e); + } + + + System.out.println("Exiting outer relaunch layer"); + IAMFML.shutdown(exitCode); + } + +} diff --git a/src/main/java/moe/nea/modernjava/launch/WellKnownBlackboard.java b/src/main/java/moe/nea/modernjava/launch/WellKnownBlackboard.java new file mode 100644 index 0000000..ee60b2a --- /dev/null +++ b/src/main/java/moe/nea/modernjava/launch/WellKnownBlackboard.java @@ -0,0 +1,17 @@ +package moe.nea.modernjava.launch; + +import net.minecraft.launchwrapper.Launch; + +import java.util.List; +import java.util.Map; + +@SuppressWarnings("unchecked") +public class WellKnownBlackboard { + public static List<String> tweakerNames() { + return (List<String>) Launch.blackboard.get("TweakClasses"); + } + + public static Map<String, String> launchArgs() { + return (Map<String, String>) Launch.blackboard.get("launchArgs"); + } +} diff --git a/src/main/java/moe/nea/modernjava/launch/util/ClassLoaderManipulations.java b/src/main/java/moe/nea/modernjava/launch/util/ClassLoaderManipulations.java new file mode 100644 index 0000000..09f2368 --- /dev/null +++ b/src/main/java/moe/nea/modernjava/launch/util/ClassLoaderManipulations.java @@ -0,0 +1,31 @@ +package moe.nea.modernjava.launch.util; + +import net.minecraft.launchwrapper.Launch; + +import java.io.File; +import java.lang.reflect.Method; +import java.net.MalformedURLException; +import java.net.URL; + +public class ClassLoaderManipulations { + + public static void addToParentClassLoader(File file) { + try { + addToParentClassLoader(file.toURI().toURL()); + } catch (MalformedURLException e) { + throw new RuntimeException(e); + } + } + + public static void addToParentClassLoader(URL file) { + try { + Launch.classLoader.addURL(file); + ClassLoader parentClassLoader = Launch.classLoader.getClass().getClassLoader(); + Method addUrl = parentClassLoader.getClass().getDeclaredMethod("addURL", URL.class); + addUrl.setAccessible(true); + addUrl.invoke(parentClassLoader, file); + } catch (Exception e) { + throw new RuntimeException(e); + } + } +} diff --git a/src/main/java/moe/nea/modernjava/launch/util/ReflectionUtils.java b/src/main/java/moe/nea/modernjava/launch/util/ReflectionUtils.java new file mode 100644 index 0000000..abc2364 --- /dev/null +++ b/src/main/java/moe/nea/modernjava/launch/util/ReflectionUtils.java @@ -0,0 +1,33 @@ +package moe.nea.modernjava.launch.util; + +import sun.misc.Unsafe; + +import java.lang.reflect.Field; + +public class ReflectionUtils { + private static Unsafe unsafe; + + static { + try { + final Field unsafeField = Unsafe.class.getDeclaredField("theUnsafe"); + unsafeField.setAccessible(true); + unsafe = (Unsafe) unsafeField.get(null); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + public static void makeFieldWritable(Field f) { + String s = "Doing nothing. We will use unsafe to set the value instead, if possible"; + } + + public static void doFieldWrite(Field field, Object object) throws IllegalAccessException { + if (unsafe == null) { + field.set(null, object); + } else { + Object o = unsafe.staticFieldBase(field); + long l = unsafe.staticFieldOffset(field); + unsafe.putObject(o, l, object); + } + } +} diff --git a/src/main/java/net/minecraftforge/fml/nea/moe/modernjava/IAMFML.java b/src/main/java/net/minecraftforge/fml/nea/moe/modernjava/IAMFML.java new file mode 100644 index 0000000..99ee7b0 --- /dev/null +++ b/src/main/java/net/minecraftforge/fml/nea/moe/modernjava/IAMFML.java @@ -0,0 +1,8 @@ +package net.minecraftforge.fml.nea.moe.modernjava; + +public class IAMFML { + + public static void shutdown(int code) { + System.exit(code); + } +} diff --git a/src/main/kotlin/moe/nea/modernjava/launch/transform/TransObjectHolderRef.kt b/src/main/kotlin/moe/nea/modernjava/launch/transform/TransObjectHolderRef.kt new file mode 100644 index 0000000..2fb4d04 --- /dev/null +++ b/src/main/kotlin/moe/nea/modernjava/launch/transform/TransObjectHolderRef.kt @@ -0,0 +1,108 @@ +package moe.nea.modernjava.launch.transform + +import dev.falsehonesty.asmhelper.BaseClassTransformer +import dev.falsehonesty.asmhelper.dsl.instructions.InsnListBuilder +import dev.falsehonesty.asmhelper.dsl.instructions.InvokeType +import dev.falsehonesty.asmhelper.dsl.modify +import dev.falsehonesty.asmhelper.dsl.overwrite +import net.minecraft.launchwrapper.Launch +import net.minecraft.launchwrapper.LaunchClassLoader +import org.objectweb.asm.Opcodes +import org.objectweb.asm.tree.AbstractInsnNode +import org.objectweb.asm.tree.FieldInsnNode + +class TransObjectHolderRef : BaseClassTransformer() { + override fun makeTransformers() { + overwrite { + className = "net.minecraftforge.fml.common.registry.ObjectHolderRef" + methodName = "makeWritable" + methodDesc = "(Ljava/lang/reflect/Field;)V" + + insnList { + aload(0/* arg0 */) + invoke( + InvokeType.STATIC, + "moe/nea/modernjava/launch/util/ReflectionUtils", + "makeFieldWritable", + "(Ljava/lang/reflect/Field;)V" + ) + methodReturn() + } + } + modify("net/minecraftforge/fml/common/registry/ObjectHolderRef") { + var end: AbstractInsnNode? = null + var start: AbstractInsnNode? = null + var c = 0 + val m = findMethod("apply", "()V") + for (instruction in m.instructions) { + if (instruction is FieldInsnNode && + instruction.opcode == Opcodes.GETSTATIC && + instruction.name == "newFieldAccessor" + ) { + start = instruction + } + if (instruction.opcode == Opcodes.INVOKEVIRTUAL && start != null) { + c++ + if (c == 2) { + end = instruction.next + break + } + } + } + end!! + val trueStart = start!! + m.instructions.insertBefore(trueStart, InsnListBuilder(m).apply { + aload(0/* this */) + getField("net/minecraftforge/fml/common/registry/ObjectHolderRef", "field", "Ljava/lang/reflect/Field;") + aload(1 /*thing*/) + invokeStatic( + "moe/nea/modernjava/launch/util/ReflectionUtils", + "doFieldWrite", + "(Ljava/lang/reflect/Field;Ljava/lang/Object;)V" + ) + methodReturn() + }.insnList) + m.maxLocals = 0 + var toRemove = start!! + while (true) { + val n = toRemove.next + m.instructions.remove(toRemove) + if (end == toRemove) { + break + } + toRemove = n + } + } + } + + val supCalledSetup = BaseClassTransformer::class.java.getDeclaredField("calledSetup").also { + it.isAccessible = true + } + + fun mySetup() { + myCalledSetup = true + supCalledSetup.set(this, true) + + val classLoader: LaunchClassLoader = Launch.classLoader + + classLoader.addTransformerExclusion("kotlin.") + classLoader.addTransformerExclusion("dev.falsehonesty.asmhelper.") + classLoader.addTransformerExclusion("org.objenesis.") + classLoader.addTransformerExclusion(this.javaClass.name) + + setup(classLoader) + + makeTransformers() + + } + + var myCalledSetup = false + override fun transform(name: String?, transformedName: String?, basicClass: ByteArray?): ByteArray? { + if (!myCalledSetup) { + mySetup() + } + + return super.transform(name, transformedName, basicClass) + } + +}
\ No newline at end of file diff --git a/src/main/resources/mcmod.info b/src/main/resources/mcmod.info new file mode 100644 index 0000000..7b1a26b --- /dev/null +++ b/src/main/resources/mcmod.info @@ -0,0 +1,18 @@ +[ + { + "modid": "examplemod", + "name": "Xample Mod", + "description": "A mod that is used as an example.", + "version": "1.0.0", + "mcversion": "1.8.9", + "url": "https://github.com/romangraef/Forge1.8.9Template/", + "updateUrl": "", + "authorList": [ + "You" + ], + "credits": "", + "logoFile": "", + "screenshots": [], + "dependencies": [] + } +] diff --git a/target/build.gradle.kts b/target/build.gradle.kts new file mode 100644 index 0000000..7ffdde9 --- /dev/null +++ b/target/build.gradle.kts @@ -0,0 +1,44 @@ +plugins { + java + id("com.github.johnrengelman.shadow") version "7.1.2" +} + +java { + toolchain.languageVersion.set(JavaLanguageVersion.of(11)) +} + + +val shadowOnly: Configuration by configurations.creating { + attributes { + this.attribute(org.gradle.api.attributes.java.TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, 11) + } +} +repositories { + mavenCentral() + maven("https://maven.architectury.dev/") + maven("https://repository.ow2.org/nexus/content/repositories/releases/") +} + +dependencies { + shadowOnly(implementation("org.ow2.asm:asm:9.4")!!) + shadowOnly(implementation("org.ow2.asm:asm-commons:9.4")!!) + shadowOnly("dev.architectury:architectury-pack200:0.1.3") +} +tasks.withType(Jar::class) { + manifest { + attributes.apply { + this["Premain-Class"] = "moe.nea.modernjava.target.Pack200Retransformer" + } + } +} + +tasks.shadowJar { + archiveClassifier.set("") + configurations = listOf(shadowOnly) + relocate("org.objectweb.asm", "moe.nea.modernjava.asm") + // relocate("dev.architectury.pack200.java", "java.util.jar") +} +tasks.jar { + archiveClassifier.set("thin") +} +tasks.assemble.get().dependsOn(tasks.shadowJar)
\ No newline at end of file diff --git a/target/src/main/java/moe/nea/modernjava/target/Pack200Retransformer.java b/target/src/main/java/moe/nea/modernjava/target/Pack200Retransformer.java new file mode 100644 index 0000000..385e7ec --- /dev/null +++ b/target/src/main/java/moe/nea/modernjava/target/Pack200Retransformer.java @@ -0,0 +1,46 @@ +package moe.nea.modernjava.target; + +import org.objectweb.asm.ClassReader; +import org.objectweb.asm.ClassVisitor; +import org.objectweb.asm.ClassWriter; +import org.objectweb.asm.commons.ClassRemapper; +import org.objectweb.asm.commons.Remapper; + +import java.lang.instrument.ClassFileTransformer; +import java.lang.instrument.IllegalClassFormatException; +import java.lang.instrument.Instrumentation; +import java.security.ProtectionDomain; +import java.util.Arrays; +import java.util.List; + +public class Pack200Retransformer implements ClassFileTransformer { + // relocate("dev.architectury.pack200.java", "java.util.jar") + List<String> classes = Arrays.asList("AdaptiveCoding", "Attribute", "BandStructure", "ClassReader", "ClassWriter", "Code", "Coding", "CodingChooser", "CodingMethod", "ConstantPool", "Constants", "Driver", "DriverResource", "DriverResource_ja", "DriverResource_zh_CN", "FixedList", "Fixups", "Histogram", "Instruction", "NativeUnpack", "Pack200", "Pack200Adapter", "Pack200Plugin", "Package", "PackageReader", "PackageWriter", "PackerImpl", "PopulationCoding", "PropMap", "TLGlobals", "UnpackerImpl", "Utils"); + String architecturyPackage = "dev/architectury/pack200/java/"; + String javaPackage = "java/util/jar/"; + + public static void premain(String agentArgs, Instrumentation inst) { + inst.addTransformer(new Pack200Retransformer()); + } + + @Override + public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException { + ClassReader reader = new ClassReader(classfileBuffer); + ClassWriter writer = new ClassWriter(reader, 0); + Remapper remapper = new Remapper() { + @Override + public String map(String internalName) { + if (internalName.startsWith(javaPackage)) { + for (String aClass : classes) { + if (internalName.equals(javaPackage + aClass) || (internalName.startsWith(javaPackage + aClass + "$"))) + return internalName.replace(javaPackage, architecturyPackage); + } + } + return internalName; + } + }; + ClassVisitor visitor = new ClassRemapper(writer, remapper); + reader.accept(visitor, 0); + return writer.toByteArray(); + } +} diff --git a/target/src/main/java/moe/nea/modernjava/target/RelaunchEntryPoint.java b/target/src/main/java/moe/nea/modernjava/target/RelaunchEntryPoint.java new file mode 100644 index 0000000..f30de3f --- /dev/null +++ b/target/src/main/java/moe/nea/modernjava/target/RelaunchEntryPoint.java @@ -0,0 +1,56 @@ +package moe.nea.modernjava.target; + +import java.io.File; +import java.lang.reflect.Method; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.Arrays; + +public class RelaunchEntryPoint { + public static void log(String text) { + System.out.println("[MODERNJAVA] " + text); + + } + + public static void main(String[] args) { + log("This is modern java relaunch talking!"); + try { + setupLaunch(args); + } catch (Throwable t) { + log("Encountered exception during relaunching"); + t.printStackTrace(); + } + } + + private static void setupLaunch(String[] args) throws Exception { + log("Original SQLException: " + Thread.currentThread().getContextClassLoader().loadClass("java.sql.SQLException")); + log("Setting up fake launch class loader"); + ClassLoader urlClassLoader = new URLClassLoader(retrieveClassPath(), Thread.currentThread().getContextClassLoader()); + log("Created fake url class loader"); + Thread.currentThread().setContextClassLoader(urlClassLoader); + log("Handing off to Launch"); + Class<?> launchClass = urlClassLoader.loadClass("net.minecraft.launchwrapper.Launch"); + log("LaunchClass: " + launchClass); + log("LaunchClass ClassLoader: " + launchClass.getClassLoader()); + + log("LaunchClass ClassLoader SQLException: " + urlClassLoader.loadClass("java.sql.SQLException")); + + + Method main = launchClass.getMethod("main", String[].class); + main.invoke(null, new Object[]{args}); + } + + private static URL[] retrieveClassPath() throws MalformedURLException { + String property = System.getProperty("modernjava.relaunchclasspath"); + String[] split = property.split(File.pathSeparator); + URL[] urls = new URL[split.length]; + for (int i = 0; i < split.length; i++) { + urls[i] = new File(split[i]).toURI().toURL(); + } + log("Retrieved classpath: " + Arrays.toString(urls)); + return urls; + } + + +} |