Skip to content

Commit

Permalink
Split data targets for 1.21.4 and remove deprecations.
Browse files Browse the repository at this point in the history
  • Loading branch information
shartte committed Nov 23, 2024
1 parent e45a8db commit 09ee9f5
Show file tree
Hide file tree
Showing 24 changed files with 192 additions and 373 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static void load(final String launchTarget, final String[] arguments) {
LOGGER.debug("Invoking bootstrap method {}", bootstrap.name());
bootstrap.bootstrap(arguments);
});
if (!List.of("forgeclient", "forgeclientuserdev", "forgeclientdev").contains(launchTarget)) {
if (!List.of("neoforgeclient", "neoforgeclientdev").contains(launchTarget)) {
provider = new DummyProvider();
LOGGER.info("ImmediateWindowProvider not loading because launch target is {}", launchTarget);
} else if (!FMLConfig.getBoolConfigValue(FMLConfig.ConfigValue.EARLY_WINDOW_CONTROL)) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ public abstract class CommonLaunchHandler implements ILaunchHandlerService {

public abstract boolean isProduction();

public boolean isData() {
return false;
}

/**
* Return additional locators to be used for locating mods when this launch handler is used.
*/
Expand Down Expand Up @@ -128,10 +124,6 @@ protected void serverService(final String[] arguments, final ModuleLayer layer)
runTarget("net.minecraft.server.Main", arguments, layer);
}

protected void dataService(final String[] arguments, final ModuleLayer layer) throws Throwable {
runTarget("net.minecraft.data.Main", arguments, layer);
}

protected void runTarget(final String target, final String[] arguments, final ModuleLayer layer) throws Throwable {
Class.forName(layer.findModule("minecraft").orElseThrow(), target).getMethod("main", String[].class).invoke(null, (Object) arguments);
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/**
* A launch target for bootstrapping a slim Minecraft environment in forgedev, to be used in JUnit tests.
*/
public class JUnitDevLaunchTarget extends CommonDevLaunchHandler {
public class JUnitDevLaunchTarget extends NeoForgeDevLaunchHandler {
@Override
public Dist getDist() {
return Dist.DEDICATED_SERVER;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,19 @@

import net.neoforged.api.distmarker.Dist;

public class NeoForgeDataDevLaunchHandler extends CommonDevLaunchHandler {
public class NeoForgeClientDataDevLaunchHandler extends NeoForgeDevLaunchHandler {
@Override
public String name() {
return "forgedatadev";
return "neoforgeclientdatadev";
}

@Override
public Dist getDist() {
return Dist.CLIENT;
}

@Override
public boolean isData() {
return true;
}

@Override
public void runService(String[] arguments, ModuleLayer layer) throws Throwable {
dataService(arguments, layer);
runTarget("net.minecraft.client.data.Main", arguments, layer);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,52 @@

package net.neoforged.fml.loading.targets;

import java.util.regex.Matcher;
import java.util.regex.Pattern;
import net.neoforged.api.distmarker.Dist;

public class NeoForgeClientDevLaunchHandler extends CommonDevLaunchHandler {
public class NeoForgeClientDevLaunchHandler extends NeoForgeDevLaunchHandler {
@Override
public String name() {
return "forgeclientdev";
return "neoforgeclientdev";
}

@Override
public Dist getDist() {
return Dist.CLIENT;
}

@Override
protected String[] preLaunch(String[] arguments, ModuleLayer layer) {
var args = ArgumentList.from(arguments);

String username = args.get("username");
if (username != null) { // Replace '#' placeholders with random numbers
Matcher m = Pattern.compile("#+").matcher(username);
var replaced = new StringBuilder();
while (m.find()) {
m.appendReplacement(replaced, getRandomNumbers(m.group().length()));
}
m.appendTail(replaced);
args.put("username", replaced.toString());
} else {
args.putLazy("username", "Dev");
}

if (!args.hasValue("accessToken")) {
args.put("accessToken", "0");
}

return super.preLaunch(arguments, layer);
}

@Override
public void runService(String[] arguments, ModuleLayer layer) throws Throwable {
clientService(arguments, layer);
}

private static String getRandomNumbers(int length) {
// Generate a time-based random number, to mimic how n.m.client.Main works
return Long.toString(System.nanoTime() % (int) Math.pow(10, length));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,46 @@

import java.util.List;
import java.util.function.Consumer;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.fml.loading.LibraryFinder;
import net.neoforged.fml.loading.MavenCoordinate;
import net.neoforged.fml.loading.VersionInfo;
import net.neoforged.fml.loading.moddiscovery.locators.PathBasedLocator;
import net.neoforged.fml.loading.moddiscovery.locators.ProductionClientProvider;
import net.neoforged.neoforgespi.locating.IModFileCandidateLocator;

public class NeoForgeClientLaunchHandler extends CommonClientLaunchHandler {
/**
* For production client environments (i.e. vanilla launcher).
*/
public class NeoForgeClientLaunchHandler extends CommonLaunchHandler {
@Override
public String name() {
return "forgeclient";
return "neoforgeclient";
}

/**
* Overlays the unpatched but renamed Minecraft classes with our patched versions of those classes.
*/
@Override
protected List<MavenCoordinate> getAdditionalMinecraftJarContent(VersionInfo versionInfo) {
return List.of(new MavenCoordinate("net.neoforged", "neoforge", "", "client", versionInfo.neoForgeVersion()));
public Dist getDist() {
return Dist.CLIENT;
}

@Override
public boolean isProduction() {
return true;
}

@Override
protected void runService(String[] arguments, ModuleLayer gameLayer) throws Throwable {
clientService(arguments, gameLayer);
}

@Override
public void collectAdditionalModFileLocators(VersionInfo versionInfo, Consumer<IModFileCandidateLocator> output) {
super.collectAdditionalModFileLocators(versionInfo, output);

// Overlays the unpatched but renamed Minecraft classes with our patched versions of those classes.
var additionalContent = List.of(new MavenCoordinate("net.neoforged", "neoforge", "", "client", versionInfo.neoForgeVersion()));
output.accept(new ProductionClientProvider(additionalContent));

var nfJar = LibraryFinder.findPathForMaven("net.neoforged", "neoforge", "", "universal", versionInfo.neoForgeVersion());
output.accept(new PathBasedLocator("neoforge", nfJar));
}
Expand Down

This file was deleted.

This file was deleted.

Loading

0 comments on commit 09ee9f5

Please sign in to comment.