Skip to content

Commit 4915992

Browse files
authored
Merge pull request #246 from 3arthqu4ke/245-1215-lwjgl
1.21.5 Support
2 parents 6246cba + dcaf2ef commit 4915992

File tree

4 files changed

+44
-4
lines changed

4 files changed

+44
-4
lines changed

headlessmc-launcher/src/main/java/me/earth/headlessmc/launcher/command/download/InstallerService.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import java.util.EnumMap;
1414
import java.util.Map;
1515
import java.util.function.Function;
16+
import java.util.function.Predicate;
1617

1718
public class InstallerService {
1819
private final Map<Modlauncher, ModLauncherCommand> modLauncherCommands = new EnumMap<>(Modlauncher.class);
@@ -24,8 +25,10 @@ public InstallerService(Launcher launcher) {
2425
// TODO: this is super bad!!!
2526
this.downloadCommand = findCommand(launcher, DownloadCommand.class, DownloadCommand::new);
2627
this.modLauncherCommands.put(Modlauncher.FABRIC, findCommand(launcher, FabricCommand.class, FabricCommand::new));
27-
this.modLauncherCommands.put(Modlauncher.LEXFORGE, findCommand(launcher, ForgeCommand.class, ForgeCommand::lexforge));
28-
this.modLauncherCommands.put(Modlauncher.NEOFORGE, findCommand(launcher, ForgeCommand.class, ForgeCommand::neoforge));
28+
this.modLauncherCommands.put(Modlauncher.LEXFORGE, findCommand(launcher, ForgeCommand.class, ForgeCommand::lexforge,
29+
c -> "lexforge".equalsIgnoreCase(c.getName()) || "forge".equalsIgnoreCase(c.getName())));
30+
this.modLauncherCommands.put(Modlauncher.NEOFORGE, findCommand(launcher, ForgeCommand.class, ForgeCommand::neoforge,
31+
c -> "neoforge".equalsIgnoreCase(c.getName())));
2932
}
3033

3134
public void install(VersionArgument versionArgument, String... args) throws CommandException {
@@ -56,8 +59,16 @@ public void installModLauncher(VersionArgument versionArgument, String... args)
5659
}
5760

5861
private <C extends Command> @Nullable C findCommand(Launcher launcher, Class<C> clazz, Function<Launcher, C> fallback) {
62+
return findCommand(launcher, clazz, fallback, null);
63+
}
64+
65+
private <C extends Command> @Nullable C findCommand(Launcher launcher, Class<C> clazz, Function<Launcher, C> fallback, @Nullable Predicate<C> predicate) {
5966
for (Command command : launcher.getCommandLine().getCommandContext()) {
6067
if (clazz.isAssignableFrom(command.getClass())) {
68+
if (predicate != null && !predicate.test((clazz.cast(command)))) {
69+
continue;
70+
}
71+
6172
return clazz.cast(command);
6273
}
6374
}

headlessmc-launcher/src/main/java/me/earth/headlessmc/launcher/launch/ProcessFactory.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,9 @@ protected List<Target> processLibraries(LaunchOptions options, Version version,
187187
}
188188

189189
libPaths.clear();
190-
try (Progressbar progressbar = options.getLauncher().getCommandLine().displayProgressBar(new Progressbar.Configuration("Downloading Libraries", librariesTODownload))) {
190+
try (Progressbar progressbar = librariesTODownload == 0
191+
? Progressbar.dummy()
192+
: options.getLauncher().getCommandLine().displayProgressBar(new Progressbar.Configuration("Downloading Libraries", librariesTODownload))) {
191193
libraryDownloader.setShouldLog(progressbar.isDummy());
192194
for (val library : version.getLibraries()) {
193195
if (library.getRule().apply(os, features) == Rule.Action.ALLOW) {

headlessmc-lwjgl/src/main/java/me/earth/headlessmc/lwjgl/LwjglProperties.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
public interface LwjglProperties {
44
String DISPLAY_UPDATE = "hmc.lwjgl.update_sleep";
5+
String GL_TEXTURE_INTERNAL_FORMAT = "hmc.lwjgl.gltextureinternalformat";
56
String TEXTURE_SIZE = "hmc.lwjgl.texturesize";
67
String FULLSCREEN = "hmc.lwjgl.fullscreen";
78
String SCREEN_WIDTH = "hmc.lwjgl.screenwidth";

headlessmc-lwjgl/src/main/java/me/earth/headlessmc/lwjgl/redirections/LwjglRedirections.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
// TODO: redirect Keyboard and Mouse?
1616
@UtilityClass
1717
public class LwjglRedirections {
18+
public static final int GL_TEXTURE_WIDTH = 4096;
19+
public static final int GL_TEXTURE_INTERNAL_FORMAT_CONST = 4099;
20+
public static final int GL_TEXTURE_INTERNAL_FORMAT = Integer.parseInt(
21+
System.getProperty(LwjglProperties.GL_TEXTURE_INTERNAL_FORMAT, "32856")); //RGBA8
1822
public static final int TEXTURE_SIZE = Integer.parseInt(
1923
System.getProperty(LwjglProperties.TEXTURE_SIZE, "1024"));
2024
public static final boolean FULLSCREEN = Boolean.parseBoolean(
@@ -110,7 +114,18 @@ public static void register(RedirectionManager manager) {
110114
-> System.nanoTime() / 1000000L);
111115

112116
manager.redirect("Lorg/lwjgl/opengl/GL11;glGetTexLevelParameteri(III)I",
113-
of(TEXTURE_SIZE));
117+
(obj, desc, type, args) -> {
118+
if ((int) args[2] == GL_TEXTURE_INTERNAL_FORMAT_CONST) {
119+
// Neoforge 1.21.5
120+
// Couldn't find a matching vanilla TextureFormat for OpenGL internal format id
121+
// com.mojang.blaze3d.opengl.GlDevice
122+
return GL_TEXTURE_INTERNAL_FORMAT;
123+
} else if ((int) args[2] == GL_TEXTURE_WIDTH && (int) args[1]/*level*/ > 0) {
124+
return 0; // otherwise Neoforge 1.21.5 gets caught in an endless loop of checking width != 0; for higher levels
125+
}
126+
127+
return TEXTURE_SIZE;
128+
});
114129
manager.redirect("Lorg/lwjgl/opengl/GL11;glGenLists(I)I", of(-1));
115130

116131
manager.redirect(
@@ -278,6 +293,17 @@ public static void register(RedirectionManager manager) {
278293
// 1.20.4 (3?)
279294
MemReallocRedirections.redirect(manager);
280295

296+
// 1.21.5
297+
manager.redirect(
298+
"Lorg/lwjgl/opengl/GL30;glMapBufferRange(IJJI)Ljava/nio/ByteBuffer;",
299+
(obj, desc, type, args) -> ByteBuffer.wrap(new byte[(int) ((long) args[2])])
300+
);
301+
302+
manager.redirect(
303+
"Lorg/lwjgl/system/MemoryUtil;memByteBufferSafe(JI)Ljava/nio/ByteBuffer;",
304+
(obj, desc, type, args) -> ByteBuffer.wrap(new byte[(int) args[1]])
305+
);
306+
281307
// Embeddium
282308
// https://github.com/3arthqu4ke/headlessmc/issues/208
283309
// manager.redirect("Lorg/lwjgl/opengl/GL32C;glFenceSync(II)J", of(1L));

0 commit comments

Comments
 (0)