Skip to content

Commit

Permalink
Update groovy and hopefully allow use with fabric loader
Browse files Browse the repository at this point in the history
  • Loading branch information
lukebemish committed Aug 23, 2023
1 parent f80cb9d commit 06c43a7
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 51 deletions.
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {
id 'groovy'
id 'maven-publish'
id 'signing'
alias libs.plugins.quilt.loom
alias libs.plugins.fabric.loom
alias libs.plugins.quilt.licenser
alias libs.plugins.mdg.plugin
alias libs.plugins.simpleci
Expand Down Expand Up @@ -112,7 +112,7 @@ repositories {

modsDotGroovy {
dslVersion = libs.versions.mdg.dsl.get()
platform 'quilt'
platform 'fabric'
}

dependencies {
Expand All @@ -123,7 +123,7 @@ dependencies {
officialMojangMappings()
parchment("org.parchmentmc.data:parchment-${libs.versions.parchment.minecraft.get()}:${libs.versions.parchment.mappings.get()}@zip")
}
modImplementation libs.quilt.loader
modImplementation libs.fabric.loader

annotationProcessor libs.autoextension
annotationProcessor libs.autoservice
Expand Down
10 changes: 5 additions & 5 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[versions]
minecraft = "1.19.4"
quilt_loader = "0.18.5"
fabric_loader = "0.14.21"
parchment_minecraft = "1.19.3"
parchment_mappings = "2023.03.12"
groovy = "4.0.13"
groovy = "4.0.14"
mappingio = "0.4.2"
quilt_loom = "1.2.3"
fabric_loom = "1.2.7"
quilt_licenser = "2.0.1"
jackson = "<jackson-resolve>"
autoservice = "1.1.1"
Expand All @@ -19,7 +19,7 @@ tinyremapper = "0.8.6+lukebemish.1+local"

[libraries]
minecraft = { module = "com.mojang:minecraft", version.ref = "minecraft" }
quilt_loader = { module = "org.quiltmc:quilt-loader", version.ref = "quilt_loader" }
fabric_loader = { module = "net.fabricmc:fabric-loader", version.ref = "fabric_loader" }

mappingio = { module = "net.fabricmc:mapping-io", version.ref = "mappingio" }

Expand Down Expand Up @@ -51,7 +51,7 @@ autoextension = { module = "dev.lukebemish.autoextension:autoextension", version
mdg_dsl = { module = "org.groovymc.modsdotgroovy:dsl", version.ref = "mdg_dsl" }

[plugins]
quilt_loom = { id = "org.quiltmc.loom", version.ref = "quilt_loom" }
fabric_loom = { id = "fabric-loom", version.ref = "fabric_loom" }
quilt_licenser = { id = "org.quiltmc.gradle.licenser", version.ref = "quilt_licenser" }
mdg_plugin = { id = "org.groovymc.modsdotgroovy", version.ref = "mdg_plugin" }
simpleci = { id = "org.groovymc.simpleci", version.ref = "simpleci" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ package org.groovymc.groovyduvet.core.impl

import groovy.transform.CompileStatic
import groovy.transform.stc.POJO
import net.fabricmc.loader.api.FabricLoader
import net.fabricmc.loader.api.entrypoint.PreLaunchEntrypoint
import org.codehaus.groovy.reflection.CachedClass
import org.codehaus.groovy.runtime.m12n.ExtensionModule
import org.codehaus.groovy.runtime.m12n.ExtensionModuleScanner
import org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl
import org.quiltmc.loader.api.ModContainer
import org.quiltmc.loader.api.QuiltLoader
import org.quiltmc.loader.api.entrypoint.PreLaunchEntrypoint

import java.nio.file.Files
import java.nio.file.Path
Expand All @@ -23,8 +22,8 @@ import java.nio.file.Path
class DevExtensionLoader implements PreLaunchEntrypoint {

@Override
void onPreLaunch(ModContainer mod) {
if (QuiltLoader.isDevelopmentEnvironment()) {
void onPreLaunch() {
if (FabricLoader.instance.developmentEnvironment) {
if (GroovySystem.metaClassRegistry instanceof MetaClassRegistryImpl) {
MetaClassRegistryImpl registry = GroovySystem.metaClassRegistry as MetaClassRegistryImpl
Map<CachedClass, List<MetaMethod>> map = [:]
Expand All @@ -46,9 +45,9 @@ class DevExtensionLoader implements PreLaunchEntrypoint {
methods.add(metaMethod)
}
}, DevExtensionLoader.classLoader)
QuiltLoader.allMods.each {
Path path = it.getPath(ExtensionModuleScanner.MODULE_META_INF_FILE)
if (Files.exists(path)) {
FabricLoader.instance.allMods.each {
Path path = it.findPath(ExtensionModuleScanner.MODULE_META_INF_FILE).orElse(null)
if (path !== null && Files.exists(path)) {
Properties properties = new Properties()
properties.load(path.newReader())
if (properties.extensionClasses != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

import com.mojang.logging.LogUtils;
import net.fabricmc.api.EnvType;
import net.fabricmc.loader.api.FabricLoader;
import org.objectweb.asm.AnnotationVisitor;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.Opcodes;
import org.quiltmc.loader.api.minecraft.MinecraftQuiltLoader;
import org.slf4j.Logger;

import java.util.Locale;
Expand Down Expand Up @@ -48,24 +48,24 @@ public void visitEnum(String name, String descriptor, String value) {
if (name.equals("value")) {
String s = value.toUpperCase(Locale.ROOT);
if (s.equals("SERVER") || s.equals("DEDICATED_SERVER")) {
isOnDist.set(MinecraftQuiltLoader.getEnvironmentType() == EnvType.SERVER);
if (MinecraftQuiltLoader.getEnvironmentType() == EnvType.CLIENT)
isOnDist.set(FabricLoader.getInstance().getEnvironmentType() == EnvType.SERVER);
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT)
LOGGER.info(skipOnClient, className);
} else if (s.equals("CLIENT")) {
isOnDist.set(MinecraftQuiltLoader.getEnvironmentType() == EnvType.CLIENT);
if (MinecraftQuiltLoader.getEnvironmentType() == EnvType.SERVER)
isOnDist.set(FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT);
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.SERVER)
LOGGER.info(skipOnServer, className);
}
}
}
};
} else if (desc.equals(SERVER_ONLY)) {
isOnDist.set(MinecraftQuiltLoader.getEnvironmentType() == EnvType.SERVER);
if (MinecraftQuiltLoader.getEnvironmentType() == EnvType.CLIENT)
isOnDist.set(FabricLoader.getInstance().getEnvironmentType() == EnvType.SERVER);
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT)
LOGGER.info(skipOnClient, className);
} else if (desc.equals(CLIENT_ONLY)) {
isOnDist.set(MinecraftQuiltLoader.getEnvironmentType() == EnvType.CLIENT);
if (MinecraftQuiltLoader.getEnvironmentType() == EnvType.SERVER)
isOnDist.set(FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT);
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.SERVER)
LOGGER.info(skipOnServer, className);
}
return super.visitAnnotation(desc, visible);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

package org.groovymc.groovyduvet.core.impl;

import org.quiltmc.loader.api.LanguageAdapter;
import org.quiltmc.loader.api.LanguageAdapterException;
import org.quiltmc.loader.api.ModContainer;
import net.fabricmc.loader.api.LanguageAdapter;
import net.fabricmc.loader.api.LanguageAdapterException;
import net.fabricmc.loader.api.ModContainer;

import java.lang.reflect.InvocationTargetException;
import java.util.function.Supplier;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ package org.groovymc.groovyduvet.core.impl

import groovy.transform.CompileStatic
import groovy.transform.stc.POJO
import net.fabricmc.loader.api.LanguageAdapterException
import net.fabricmc.loader.api.ModContainer
import org.codehaus.groovy.runtime.MethodClosure
import org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation
import org.codehaus.groovy.runtime.typehandling.GroovyCastException
import org.quiltmc.loader.api.LanguageAdapterException
import org.quiltmc.loader.api.ModContainer

import java.lang.reflect.Constructor
import java.lang.reflect.Method
Expand Down
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)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ import com.google.common.collect.HashBiMap
import groovy.json.JsonSlurper
import groovy.transform.CompileStatic
import groovy.transform.stc.POJO
import net.fabricmc.loader.api.FabricLoader
import net.fabricmc.loader.api.entrypoint.PreLaunchEntrypoint
import net.fabricmc.loader.impl.FabricLoaderImpl
import org.groovymc.groovyduvet.core.impl.PlatformSpecificGetter
import org.groovymc.groovyduvet.core.impl.compile.ClassMappings
import net.fabricmc.api.EnvType
import net.fabricmc.mappingio.MappedElementKind
import net.fabricmc.mappingio.MappingVisitor
import net.fabricmc.mappingio.format.ProGuardReader
import org.quiltmc.loader.api.ModContainer
import org.quiltmc.loader.api.QuiltLoader
import org.quiltmc.loader.api.entrypoint.PreLaunchEntrypoint
import org.quiltmc.loader.api.minecraft.MinecraftQuiltLoader
import org.slf4j.Logger
import org.slf4j.LoggerFactory

Expand All @@ -37,8 +37,8 @@ import java.util.zip.GZIPInputStream
class MetaclassMappingsProvider implements PreLaunchEntrypoint {
private static final String OFFICIAL_NAMESPACE = 'official'
private static final String PISTON_META = 'https://piston-meta.mojang.com/mc/game/version_manifest_v2.json'
private static final Path CACHE_DIR = QuiltLoader.gameDir.resolve('mod_data/groovyduvet')
private static final String MC_VERSION = QuiltLoader.getRawGameVersion()
private static final String MC_VERSION = PlatformSpecificGetter.RAW_GAME_VERSION
private static final Path CACHE_DIR = FabricLoader.instance.gameDir.resolve('mod_data').resolve('groovyduvet').resolve(MC_VERSION)
private static final Path OFFICIAL_FILE = CACHE_DIR.resolve("official_${MC_VERSION}.txt")
private static final Path VERSION_FILE = CACHE_DIR.resolve("version_${MC_VERSION}.json")
private static final JsonSlurper JSON_SLURPER = new JsonSlurper()
Expand All @@ -48,8 +48,8 @@ class MetaclassMappingsProvider implements PreLaunchEntrypoint {
private static volatile HttpClient client = HttpClient.newBuilder().build()

@Override
void onPreLaunch(ModContainer mod) {
if (!QuiltLoader.developmentEnvironment) {
void onPreLaunch() {
if (!FabricLoader.instance.developmentEnvironment) {
setup()
}
}
Expand Down Expand Up @@ -137,11 +137,11 @@ class MetaclassMappingsProvider implements PreLaunchEntrypoint {

private static void checkAndUpdateOfficialFile() throws IOException {
Map versionMeta = (Map) JSON_SLURPER.parse(VERSION_FILE)
String sha1 = switch (MinecraftQuiltLoader.environmentType) {
String sha1 = switch (FabricLoader.instance.environmentType) {
case EnvType.CLIENT -> ((versionMeta.downloads as Map).client_mappings as Map).sha1
case EnvType.SERVER -> ((versionMeta.downloads as Map).server_mappings as Map).sha1
}
String url = switch (MinecraftQuiltLoader.environmentType) {
String url = switch (FabricLoader.instance.environmentType) {
case EnvType.CLIENT -> ((versionMeta.downloads as Map).client_mappings as Map).url
case EnvType.SERVER -> ((versionMeta.downloads as Map).server_mappings as Map).url
}
Expand Down Expand Up @@ -285,15 +285,15 @@ class MetaclassMappingsProvider implements PreLaunchEntrypoint {
}

String getRuntimeClassName() {
QuiltLoader.mappingResolver.mapClassName(OFFICIAL_NAMESPACE, lastClassObf)
FabricLoader.instance.mappingResolver.mapClassName(OFFICIAL_NAMESPACE, lastClassObf)
}

String getRuntimeMethodName(String obf) {
QuiltLoader.mappingResolver.mapMethodName(OFFICIAL_NAMESPACE, lastClassObf, obf, descMojToObf(lastMethodDesc))
FabricLoader.instance.mappingResolver.mapMethodName(OFFICIAL_NAMESPACE, lastClassObf, obf, descMojToObf(lastMethodDesc))
}

String getRuntimeFieldName(String obf) {
QuiltLoader.mappingResolver.mapFieldName(OFFICIAL_NAMESPACE, lastClassObf, obf, descMojToObf(lastFieldDesc))
FabricLoader.instance.mappingResolver.mapFieldName(OFFICIAL_NAMESPACE, lastClassObf, obf, descMojToObf(lastFieldDesc))
}

String descMojToObf(String moj) {
Expand All @@ -304,7 +304,7 @@ class MetaclassMappingsProvider implements PreLaunchEntrypoint {

String descMojToRuntime(String moj) {
descMojToObf(moj).replaceAll(/L(.*?);/, { full, inner ->
"L${QuiltLoader.mappingResolver.mapClassName(OFFICIAL_NAMESPACE, (inner as String).replace('/','.')).replace('.','/')};"
"L${FabricLoader.instance.mappingResolver.mapClassName(OFFICIAL_NAMESPACE, (inner as String).replace('/','.')).replace('.','/')};"
})
}

Expand Down
12 changes: 5 additions & 7 deletions src/main/resources/mods.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,21 @@
ModsDotGroovy.make {
issueTrackerUrl = 'https://github.com/GroovyMC/groovyduvet/issues'
license = 'LGPL-3.0-or-later'
languageAdapters = [
'groovyduvet': 'org.groovymc.groovyduvet.core.impl.GroovyAdapter'
]
mod {
modId = 'groovyduvet_core'
version = this.version
group = this.group
displayName = 'GroovyDuvet: Core'
description = 'Core module for GroovyDuvet'
author 'Luke Bemish'
intermediate_mappings = "net.fabricmc:intermediary"
language_adapters = [
'groovyduvet': 'org.groovymc.groovyduvet.core.impl.GroovyAdapter'
]
dependencies {
quiltLoader = ">=${this.quiltLoaderVersion}"
fabricLoader = ">=${this.fabricLoaderVersion}"
}
displayUrl = 'https://github.com/GroovyMC/groovyduvet'
entrypoints {
pre_launch = [
preLaunch = [
adapted {
adapter = 'groovyduvet'
value = 'org.groovymc.groovyduvet.core.impl.DevExtensionLoader'
Expand Down

0 comments on commit 06c43a7

Please sign in to comment.