Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added fallback gradle run config, started adding forge jvm args to game launch #2

Open
wants to merge 2 commits into
base: MCU4-Refactor
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,47 @@ javafx {
}

version = sharedVersion
sourceCompatibility = 17

dependencies {
implementation project(':MCU-API')
implementation project(':MCU-DownloadLib')
implementation project(':PackBuilder')

implementation 'com.mojang:authlib:1.6.25'

runtimeOnly project(':MCU-ForgeLoader')
runtimeOnly project(':MCU-ForgeLoaderV2')
}

application {
mainClass = 'org.mcupdater.gui.javafx.Main'
}

def testMCURoot = "c:\\Users\\"+System.properties['user.name']+"\\MCU-Test"
run.doFirst {
// provide default args if we're running via gradle
if( args.size() == 0 ) {
mkdir(testMCURoot)
args = [
"-ServerPack", "http://files.mcupdater.com/official_packs/mcu-1.16.5-together.xml",
"-MCURoot", testMCURoot,
"--runtimes=8#c:\\temp\\jdk8u302-b08-jre\\bin\\java.exe;11#c:\\temp\\jdk-11.0.12+7-jre\\bin\\java.exe;17#c:\\temp\\jdk-17+35\\bin\\java.exe",
]

// make sure we have current forgeloader jars
copyForgeLoaders
}
}
tasks.register("copyForgeLoaders", Copy) {
def dest = mkdir(testMCURoot + "\\lib" )

from file("..\\MCU-ForgeLoader\\build\\libs\\MCU-ForgeLoader.jar"),
file("..\\MCU-ForgeLoaderV2\\build\\libs\\MCU-ForgeLoaderV2.jar"),
file("..\\MCU-LegacyForgeLoader\\build\\libs\\MCU-LegacyForgeLoader.jar")
into dest
}

processResources {
duplicatesStrategy = DuplicatesStrategy.INCLUDE
from(sourceSets*.resources.srcDirs) {
Expand Down
9 changes: 8 additions & 1 deletion src/main/java/org/mcupdater/gui/javafx/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,17 @@ public void start(Stage stage) throws Exception {
}
} else {
newProfile = settings.findProfile(settings.getLastProfile());
// if no 'last profile' was saved, just default to the first one in the list
if (newProfile == null) {
newProfile = settings.getProfiles().get(0);
}
}
controller.refreshInstanceList();
controller.refreshProfiles();
controller.profiles.setSelectedProfile(newProfile.getName());
// if no profile is set, avoid npe on the name lookup
if (newProfile != null) {
controller.profiles.setSelectedProfile(newProfile.getName());
}
}

public Image getImage(String filename) {
Expand Down
16 changes: 14 additions & 2 deletions src/main/java/org/mcupdater/gui/javafx/MainController.java
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,13 @@ private void tryNewLaunch(ServerList selected, List<ModuleEntry> modules, Profil
}
String playerName = launchProfile.getName();
String sessionKey = launchProfile.getSessionKey(this);

MCUpdater mcu = MCUpdater.getInstance();
Path instancePath = mcu.getInstanceRoot().resolve(selected.getServerId());
// NB: we want to use the loader's version json for arguments if one exists
MinecraftVersion loaderVersion = MinecraftVersion.loadLocalVersion(instancePath.toFile(), selected.getLoaderVersion());
MinecraftVersion mcVersion = MinecraftVersion.loadVersion(selected.getVersion());

selected.getLoaders().sort(new OrderComparator());
String indexName = mcVersion.getAssets();
if (indexName == null) {
Expand All @@ -409,8 +415,6 @@ private void tryNewLaunch(ServerList selected, List<ModuleEntry> modules, Profil
clArgs = new StringBuilder();
}
List<String> libs = new ArrayList<>();
MCUpdater mcu = MCUpdater.getInstance();
Path instancePath = mcu.getInstanceRoot().resolve(selected.getServerId());
File indexesPath = mcu.getArchiveFolder().resolve("assets").resolve("indexes").toFile();
File indexFile = new File(indexesPath, indexName + ".json");
String json;
Expand Down Expand Up @@ -442,7 +446,12 @@ private void tryNewLaunch(ServerList selected, List<ModuleEntry> modules, Profil
args.add("-Xms" + settings.getMinMemory());
args.add("-Xmx" + settings.getMaxMemory());
//args.add("-XX:PermSize=" + settings.getPermGen());
if (loaderVersion != null && !loaderVersion.getJVMArguments().isEmpty()) {
clArgs.append(" ");
clArgs.append(loaderVersion.getJVMArguments());
}
if (!mcVersion.getJVMArguments().isEmpty()) {
// we may only want to try the mc version's args if we don't have one for forge?
args.add(mcVersion.getJVMArguments());
}
if (!settings.getJvmOpts().isEmpty()) {
Expand Down Expand Up @@ -526,6 +535,9 @@ private void tryNewLaunch(ServerList selected, List<ModuleEntry> modules, Profil
fields.put("user_properties", "{}"); //TODO: This will likely actually get used at some point.
fields.put("user_type", (launchProfile.getStyle()));
fields.put("version_type", mcVersion.getType());
fields.put("library_directory", mcu.getInstanceRoot().resolve("libraries").toString());
fields.put("classpath_separator", File.pathSeparator);
//fields.put("version_name", "minecraft"); // the filename of the jar to be executed
String[] fieldArr = tmpclArgs.split(" ");
for (int i = 0; i < fieldArr.length; i++) {
fieldArr[i] = fieldReplacer.replace(fieldArr[i]);
Expand Down