diff --git a/build.gradle b/build.gradle index 9b625d065..ceb1167b3 100644 --- a/build.gradle +++ b/build.gradle @@ -163,6 +163,8 @@ project(':forge') { installer 'org.apache.maven:maven-artifact:3.5.3' installer 'net.jodah:typetools:0.5.0' installer 'java3d:vecmath:1.5.2' + installer 'org.apache.logging.log4j:log4j-api:2.11.1' + installer 'org.apache.logging.log4j:log4j-core:2.11.1' } task runclient(type: JavaExec, dependsOn: [":forge:downloadAssets", ":forge:extractNatives"]) { @@ -344,7 +346,16 @@ project(':forge') { type: 'release', mainClass: 'cpw.mods.modlauncher.Launcher', inheritsFrom: MC_VERSION, - logging: [:], + logging: [ client: [ + argument: '-Dlog4j.configurationFile=${path}', + file: [ + id:'client-1.12.xml', + sha1:'ef4f57b922df243d0cef096efe808c72db042149', + size:877, + url:'https://launcher.mojang.com/v1/objects/ef4f57b922df243d0cef096efe808c72db042149/client-1.12.xml' + ], + type: 'log4j2-xml' + ]], arguments: [ game: ['--launchTarget', 'fmlclient'] ], @@ -545,7 +556,9 @@ project(':forge') { artifacts.each { key, lib -> classpath += "libraries/${lib.downloads.artifact.path} " } - classpath += "minecraft_server.${MC_VERSION}.jar" + classpath += "libraries/net/minecraft/server/${MC_VERSION}/server-${MC_VERSION}-data.jar " + classpath += "libraries/net/minecraft/server/${MC_VERSION}/server-${MC_VERSION}-extra.jar" + manifest.attributes([ 'Main-Class': 'net.minecraftforge.server.ServerMain', diff --git a/patches/minecraft/net/minecraft/client/gui/GuiConnecting.java.patch b/patches/minecraft/net/minecraft/client/gui/GuiConnecting.java.patch new file mode 100644 index 000000000..e777bfa1f --- /dev/null +++ b/patches/minecraft/net/minecraft/client/gui/GuiConnecting.java.patch @@ -0,0 +1,10 @@ +--- a/net/minecraft/client/gui/GuiConnecting.java ++++ b/net/minecraft/client/gui/GuiConnecting.java +@@ -62,6 +62,7 @@ + GuiConnecting.this.field_146371_g.func_150719_a(new NetHandlerLoginClient(GuiConnecting.this.field_146371_g, GuiConnecting.this.field_146297_k, GuiConnecting.this.field_146374_i, (p_209549_1_) -> { + GuiConnecting.this.func_209514_a(p_209549_1_); + })); ++ net.minecraftforge.fml.network.NetworkHooks.registerClientLoginChannel(GuiConnecting.this.field_146371_g); + GuiConnecting.this.field_146371_g.func_179290_a(new CPacketHandshake(p_146367_1_, p_146367_2_, EnumConnectionState.LOGIN)); + GuiConnecting.this.field_146371_g.func_179290_a(new CPacketLoginStart(GuiConnecting.this.field_146297_k.func_110432_I().func_148256_e())); + } catch (UnknownHostException unknownhostexception) { diff --git a/src/main/java/net/minecraftforge/fml/loading/FMLServerLaunchProvider.java b/src/main/java/net/minecraftforge/fml/loading/FMLServerLaunchProvider.java new file mode 100644 index 000000000..161c0c028 --- /dev/null +++ b/src/main/java/net/minecraftforge/fml/loading/FMLServerLaunchProvider.java @@ -0,0 +1,81 @@ +/* + * Minecraft Forge + * Copyright (c) 2016-2018. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation version 2.1 + * of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +package net.minecraftforge.fml.loading; + +import cpw.mods.modlauncher.api.IEnvironment; +import cpw.mods.modlauncher.api.ILaunchHandlerService; +import cpw.mods.modlauncher.api.ITransformingClassLoader; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.versions.forge.ForgeVersion; +import net.minecraftforge.versions.mcp.MCPVersion; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.concurrent.Callable; + +public class FMLServerLaunchProvider extends FMLCommonLaunchHandler implements ILaunchHandlerService +{ + private static final Logger LOGGER = LogManager.getLogger(); + + @Override + public String name() + { + return "fmlserver"; + } + + @Override + public Path[] identifyTransformationTargets() + { + Path libsPath = findLibsPath(); + Path patchedBinariesPath = libsPath.resolve(Paths.get("net","minecraftforge","forge",MCPVersion.getMCVersion()+"-"+ForgeVersion.getVersion(),"forge-"+MCPVersion.getMCVersion()+"-"+ForgeVersion.getVersion()+"-server.jar")); + Path srgMcPath = libsPath.resolve(Paths.get("net","minecraft", "server", MCPVersion.getMCPandMCVersion(), "server-"+MCPVersion.getMCPandMCVersion()+"-srg.jar")); + LOGGER.info("SRG MC at {} is {}", srgMcPath.toString(), Files.exists(srgMcPath) ? "present" : "missing"); + LOGGER.info("Forge patches at {} is {}", patchedBinariesPath.toString(), Files.exists(patchedBinariesPath) ? "present" : "missing"); + LOGGER.info("Forge at {} is {}", getForgePath().toString(), Files.exists(getForgePath()) ? "present" : "missing"); + if (!(Files.exists(srgMcPath) && Files.exists(patchedBinariesPath) && Files.exists(getForgePath()))) { + throw new RuntimeException("Failed to find patched jars"); + } + return new Path[] {getForgePath(), patchedBinariesPath, srgMcPath}; + } + + @Override + public Callable launchService(String[] arguments, ITransformingClassLoader launchClassLoader) + { + return () -> { + super.beforeStart(launchClassLoader); + launchClassLoader.addTargetPackageFilter(getPackagePredicate()); + Class.forName("net.minecraft.server.MinecraftServer", true, launchClassLoader.getInstance()).getMethod("main", String[].class).invoke(null, (Object)arguments); + return null; + }; + } + + @Override + public void setup(final IEnvironment environment) { + } + + @Override + public Dist getDist() + { + return Dist.DEDICATED_SERVER; + } +} diff --git a/src/main/java/net/minecraftforge/server/ServerMain.java b/src/main/java/net/minecraftforge/server/ServerMain.java new file mode 100644 index 000000000..c5fe81da3 --- /dev/null +++ b/src/main/java/net/minecraftforge/server/ServerMain.java @@ -0,0 +1,11 @@ +package net.minecraftforge.server; + +import com.google.common.collect.ObjectArrays; +import cpw.mods.modlauncher.Launcher; + +public class ServerMain { + public static void main(String[] args) { + final String[] argArray = ObjectArrays.concat(new String[]{"--launchTarget", "fmlserver","--gameDir", "."}, args, String.class); + Launcher.main(argArray); + } +} diff --git a/src/main/resources/META-INF/services/cpw.mods.modlauncher.api.ILaunchHandlerService b/src/main/resources/META-INF/services/cpw.mods.modlauncher.api.ILaunchHandlerService index d0168ed78..744c350e5 100644 --- a/src/main/resources/META-INF/services/cpw.mods.modlauncher.api.ILaunchHandlerService +++ b/src/main/resources/META-INF/services/cpw.mods.modlauncher.api.ILaunchHandlerService @@ -1,3 +1,4 @@ net.minecraftforge.fml.loading.FMLClientLaunchProvider +net.minecraftforge.fml.loading.FMLServerLaunchProvider net.minecraftforge.fml.loading.FMLDevClientLaunchProvider net.minecraftforge.fml.loading.FMLDevServerLaunchProvider \ No newline at end of file