-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update groovy and hopefully allow use with fabric loader
- Loading branch information
1 parent
f80cb9d
commit 06c43a7
Showing
9 changed files
with
86 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/main/groovy/org/groovymc/groovyduvet/core/impl/PlatformSpecificGetter.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright (C) 2023 Luke Bemish, GroovyMC, and contributors | ||
* SPDX-License-Identifier: LGPL-3.0-or-later | ||
*/ | ||
|
||
package org.groovymc.groovyduvet.core.impl | ||
|
||
import groovy.transform.CompileStatic | ||
import groovy.transform.stc.POJO | ||
import net.fabricmc.loader.api.FabricLoader | ||
|
||
import java.lang.invoke.MethodHandles | ||
import java.lang.invoke.MethodType | ||
|
||
@CompileStatic | ||
@POJO | ||
class PlatformSpecificGetter { | ||
private PlatformSpecificGetter() {} | ||
|
||
private static final String QUILT_CLASS = 'org.quiltmc.loader.api.QuiltLoader' | ||
private static final String FABRIC_CLASS = 'net.fabricmc.loader.impl.FabricLoaderImpl' | ||
private static final String GAME_PROVIDER_CLASS = 'net.fabricmc.loader.impl.game.GameProvider' | ||
|
||
public static final String RAW_GAME_VERSION = calculateRawGameVersion() | ||
|
||
private static String calculateRawGameVersion() { | ||
var lookup = MethodHandles.lookup() | ||
try { | ||
Class<?> clazz = PlatformSpecificGetter.classLoader.loadClass(QUILT_CLASS) | ||
return (String) lookup.findStatic(clazz, 'getRawGameVersion', MethodType.methodType(String.class)).invokeWithArguments() | ||
} catch (ClassNotFoundException ignored) { | ||
Class<?> clazz = PlatformSpecificGetter.classLoader.loadClass(FABRIC_CLASS) | ||
Class<?> gameProviderClazz = PlatformSpecificGetter.classLoader.loadClass(GAME_PROVIDER_CLASS) | ||
Object gameProvider = lookup.findVirtual(clazz, 'getGameProvider', MethodType.methodType(gameProviderClazz)).invokeWithArguments(FabricLoader.instance) | ||
return (String) lookup.findVirtual(gameProviderClazz, 'getRawGameVersion', MethodType.methodType(String.class)).invokeWithArguments(gameProvider) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters