Actually call mod entrypoints.
This commit is contained in:
parent
771f22eaa8
commit
0b11a7795e
@ -1,11 +1,14 @@
|
|||||||
package sib.bedohswe.hellofabric;
|
package sib.bedohswe.hellofabric;
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
|
public static void callEntrypoints() {}
|
||||||
|
|
||||||
public String getMessage() {
|
public String getMessage() {
|
||||||
return "Hello World!";
|
return "Hello World!";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String args[]) {
|
public static void main(String args[]) {
|
||||||
|
callEntrypoints();
|
||||||
System.out.println(new Main().getMessage());
|
System.out.println(new Main().getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,49 @@
|
|||||||
|
package sib.bedohswe.hellofabric.modloader;
|
||||||
|
|
||||||
|
import com.google.j2objc.annotations.Property;
|
||||||
|
import net.fabricmc.api.ClientModInitializer;
|
||||||
|
import net.fabricmc.api.ModInitializer;
|
||||||
|
import net.fabricmc.loader.impl.FabricLoaderImpl;
|
||||||
|
import net.fabricmc.loader.impl.game.patch.GamePatch;
|
||||||
|
import net.fabricmc.loader.impl.launch.FabricLauncher;
|
||||||
|
import org.objectweb.asm.Opcodes;
|
||||||
|
import org.objectweb.asm.tree.*;
|
||||||
|
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
import static sib.bedohswe.hellofabric.modloader.GameProviderImpl.PROPERTY_APP_DIRECTORY;
|
||||||
|
|
||||||
|
public class GamePatchImpl extends GamePatch {
|
||||||
|
public static void initClient() {
|
||||||
|
Path runDir = Paths.get(System.getProperty(PROPERTY_APP_DIRECTORY));
|
||||||
|
FabricLoaderImpl loader = FabricLoaderImpl.INSTANCE;
|
||||||
|
loader.prepareModInit(runDir, FabricLoaderImpl.INSTANCE.getGameInstance());
|
||||||
|
loader.invokeEntrypoints("main", ModInitializer.class, ModInitializer::onInitialize);
|
||||||
|
loader.invokeEntrypoints("client", ClientModInitializer.class, ClientModInitializer::onInitializeClient);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void process(FabricLauncher launcher, Function<String, ClassNode> classSource, Consumer<ClassNode> classEmitter) {
|
||||||
|
String entrypoint = launcher.getEntrypoint();
|
||||||
|
ClassNode entrypointClazz = Objects.requireNonNull(classSource.apply(entrypoint), "Failed to load entrypoint class.");
|
||||||
|
|
||||||
|
MethodNode initMethod = Objects.requireNonNull(findMethod(entrypointClazz,
|
||||||
|
(method) -> method.name.equals("callEntrypoints") && method.desc.equals("()V")
|
||||||
|
), "Failed load load entrypoint method.");
|
||||||
|
|
||||||
|
initMethod.instructions.insertBefore(initMethod.instructions.getFirst(), new MethodInsnNode(
|
||||||
|
Opcodes.INVOKESTATIC,
|
||||||
|
"sib/bedohswe/hellofabric/modloader/GamePatchImpl",
|
||||||
|
"initClient",
|
||||||
|
"()V",
|
||||||
|
false));
|
||||||
|
|
||||||
|
classEmitter.accept(entrypointClazz);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -26,7 +26,7 @@ public class GameProviderImpl implements GameProvider {
|
|||||||
|
|
||||||
public static final String PROPERTY_APP_DIRECTORY = "appDirectory";
|
public static final String PROPERTY_APP_DIRECTORY = "appDirectory";
|
||||||
|
|
||||||
private static final GameTransformer TRANSFORMER = new GameTransformerImpl();
|
private static final GameTransformer TRANSFORMER = new GameTransformer(new GamePatchImpl());
|
||||||
|
|
||||||
private Arguments arguments;
|
private Arguments arguments;
|
||||||
private Path appJar;
|
private Path appJar;
|
||||||
|
|||||||
@ -1,15 +0,0 @@
|
|||||||
package sib.bedohswe.hellofabric.modloader;
|
|
||||||
|
|
||||||
import net.fabricmc.loader.impl.game.patch.GameTransformer;
|
|
||||||
|
|
||||||
public class GameTransformerImpl extends GameTransformer {
|
|
||||||
/*
|
|
||||||
* @param className The class name,
|
|
||||||
* @return The transformed class data.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public byte[] transform(String name) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Loading…
x
Reference in New Issue
Block a user