Skip to content

Commit

Permalink
Make the language adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
Treetrain1 committed Jul 15, 2024
1 parent ab302a9 commit 6a4677b
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 0 deletions.
2 changes: 2 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ dependencies {
} else {
modImplementation("maven.modrinth:frozenlib:${frozenlib_version}")?.let { include(it) }
}

compileOnly("org.projectlombok:lombok:1.18.34")?.let { annotationProcessor(it) }
}

tasks {
Expand Down
37 changes: 37 additions & 0 deletions src/main/java/net/frozenblock/unforked/FabricLoaderInterface.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package net.frozenblock.unforked;

import lombok.experimental.UtilityClass;
import net.fabricmc.loader.impl.FabricLoaderImpl;
import net.fabricmc.loader.impl.discovery.ModCandidate;
import net.fabricmc.loader.impl.metadata.LoaderModMetadata;
import org.jetbrains.annotations.ApiStatus;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.List;

// Inspired by ModsMod
@ApiStatus.Internal
@UtilityClass
public class FabricLoaderInterface {
static void init() {}

private static final Method ADD_MOD;
private static final Method CREATE_PLAIN;
private static final Field MODS;

static {
try {
ADD_MOD = FabricLoaderImpl.class.getDeclaredMethod("addMod", ModCandidate.class);
ADD_MOD.setAccessible(true);

MODS = FabricLoaderImpl.class.getDeclaredField("mods");
MODS.setAccessible(true);

CREATE_PLAIN = ModCandidate.class.getDeclaredMethod("createPlain", List.class, LoaderModMetadata.class, boolean.class, Collection.class);
CREATE_PLAIN.setAccessible(true);
} catch (NoSuchMethodException | NoSuchFieldException e) {
throw new RuntimeException(e);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package net.frozenblock.unforked;


import net.fabricmc.loader.api.LanguageAdapter;
import net.fabricmc.loader.api.ModContainer;

public final class UnforkedLanguageAdapter implements LanguageAdapter {
@Override
public native <T> T create(ModContainer mod, String value, Class<T> type);

static {
UnforkedLoader.init();
}
}
13 changes: 13 additions & 0 deletions src/main/java/net/frozenblock/unforked/UnforkedLoader.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package net.frozenblock.unforked;

import lombok.experimental.UtilityClass;
import org.jetbrains.annotations.ApiStatus;

@ApiStatus.Internal
@UtilityClass
public class UnforkedLoader {

void init() {
System.out.println("This is working");
}
}
3 changes: 3 additions & 0 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
"net.frozenblock.unforked.datagen.UnforkedDataGenerator"
]
},
"languageAdapters": {
"unforked": "net.frozenblock.unforked.UnforkedLanguageAdapter"
},
"mixins": [
"unforked.mixins.json"
],
Expand Down

0 comments on commit 6a4677b

Please sign in to comment.