### Getting Entrypoints Example Source: https://wiki.fabricmc.net/documentation%3Aentrypoint?rev=1582331132 Demonstrates how to retrieve entrypoints for a given name and type using FabricLoader. Entrypoint instances are memoized per name and type. ```java FabricLoader.getEntrypoints(name, type) ``` -------------------------------- ### Java Entrypoint Example Source: https://wiki.fabricmc.net/documentation%3Afabric_mod_json?difftype=sidebyside&do=diff&rev2%5B0%5D=1558362514&rev2%5B1%5D=1703681627 Example of how to define main entry points for a Java mod in fabric.mod.json. ```json "main": [ "net.fabricmc.example.ExampleMod", "net.fabricmc.example.ExampleMod::handle" ] ``` -------------------------------- ### Example GameProvider Implementation Source: https://wiki.fabricmc.net/documentation%3Afabric_loader?rev=1671721435 This is a complete example of a GameProvider implementation. It shows how to define game ID, version, entry point, and handle game directory location and launching. ```java public class AppGameProvider implements GameProvider { private Arguments arguments; private Path gameDirectory; private GameTransformer transformer = new AppGameTransformer(); @Override public String getGameId() { return "app"; } @Override public String getGameName() { return "App"; } @Override public String getRawGameVersion() { return App.FULL_VERSION; } @Override public String getNormalizedGameVersion() { return App.VERSION; } @Override public Collection getBuiltinMods() { return Collections.emptyList(); } @Override public String getEntrypoint() { return "net.developer.app.App"; } @Override public Path getLaunchDirectory() { return this.gameDirectory; } @Override public boolean isObfuscated() { return false; } @Override public boolean requiresUrlClassLoader() { return false; } @Override public boolean isEnabled() { return true; } @Override public boolean locateGame(FabricLauncher launcher, String[] args) { this.arguments = new Arguments(); this.arguments.parse(args); this.gameDirectory = Paths.get(this.arguments.get("gameDirectory")); return Files.isDirectory(this.gameDirectory); } @Override public void initialize(FabricLauncher launcher) {} @Override public GameTransformer getEntrypointTransformer() { return this.transformer; } @Override public void unlockClassPath(FabricLauncher launcher) { for (Path path : this.jars) { launcher.addToClassPath(path); } } @Override public void launch(ClassLoader loader) { try { Class main = loader.loadClass(this.getEntrypoint()); Method method = main.getMethod("main", String[].class); method.invoke(null, (Object) this.arguments.toArray()); } catch (Exception e) { e.printStackTrace(); } } @Override ``` -------------------------------- ### Initializing Mods with Fabric Hooks Source: https://wiki.fabricmc.net/documentation%3Afabric_loader?difftype=sidebyside&do=diff&rev2%5B0%5D=1559912522&rev2%5B1%5D=1671721435 Example of how to manually call Fabric Hooks to start the client and initialize mods, particularly when ModInitializer.onInitialize() is not automatically called. ```java public MainApp(App app) { super(); this.development = app.development; this.events.register(this); this.registerCore(this, app.gameDirectory); this.registerFactories(); this.registerFoundation(); this.registerMiscellaneous(); Hooks.startClient(app.gameDirectory, app); if (this.development) { this.watchDog = new WatchDog(this.assetsFolder); this.watchDog.register(this.textures); this.watchDog.register(this.models); this.watchDog.register(this.sounds); this.watchDog.start(); } ``` -------------------------------- ### Example GameProvider Implementation Source: https://wiki.fabricmc.net/documentation%3Afabric_loader?difftype=sidebyside&do=diff&rev2%5B0%5D=1671721435&rev2%5B1%5D=1703681861 A comprehensive example demonstrating how to implement the GameProvider interface. This includes methods for game identification, versioning, launch directory, and launching the application. ```java public class MyGameProvider implements GameProvider { private final File launchDirectory; private final Arguments arguments; public MyGameProvider() { // TODO: Implement logic to find the launch directory this.launchDirectory = new File("."); this.arguments = new Arguments(); } @Override public String getGameId() { return "my_game"; } @Override public String getGameName() { return "My Game"; } @Override public String getRawGameVersion() { return "1.0.0"; } @Override public String getNormalizedGameVersion() { return "1.0.0"; } @Override public Collection getBuiltinMods() { return Collections.emptyList(); } @Override public String getEntryPoint() { return "com.example.MyGameMain"; } @Override public File getLaunchDirectory() { return this.launchDirectory; } @Override public boolean isObfuscated() { return false; } @Override public boolean requiresUrlClassLoader() { return false; } @Override public boolean isEnabled() { return true; } @Override public boolean locateGame(FabricLauncher launcher, String[] args) { this.arguments.parse(args); // TODO: Implement logic to find the game directory return true; } @Override public void unlockClassPath(FabricLauncher launcher) { } @Override public void launch(ClassLoader classLoader) { try { Class mainClass = Class.forName(getEntryPoint(), true, classLoader); Method mainMethod = mainClass.getMethod("main", String[].class); mainMethod.invoke(null, (Object) getLaunchArguments(true)); } catch (Exception e) { throw new RuntimeException(e); } } @Override public Arguments getArguments() { return this.arguments; } @Override public String[] getLaunchArguments(boolean includeNatives) { return this.arguments.toArray(); } } ``` -------------------------------- ### Configuring RemapJarTask Properties Source: https://wiki.fabricmc.net/documentation%3Afabric_loom?difftype=sidebyside&do=diff&rev2%5B0%5D=1560001090&rev2%5B1%5D=1762251382 Example of configuring the input and output for the RemapJarTask, which remaps an input JAR to an output JAR. This task is not an AbstractArchiveTask and requires careful dependency setup. ```gradle tasks.named('remapJar', net.fabricmc.loom.task.RemapJarTask) { input = project.file('build/libs/your-mod-unmapped.jar') output = project.file('build/libs/your-mod.jar') } ``` -------------------------------- ### Example AppGameProvider Implementation Source: https://wiki.fabricmc.net/documentation%3Afabric_loader?difftype=sidebyside&do=diff&rev2%5B0%5D=1582332941&rev2%5B1%5D=1703681861 This is a full implementation of the GameProvider interface for a hypothetical 'App'. It demonstrates how to handle game identification, versioning, entry points, and launching. ```java public class AppGameProvider implements GameProvider { private Arguments arguments; private Path gameDirectory; private GameTransformer transformer = new AppGameTransformer(); @Override public String getGameId() { return "app"; } @Override public String getGameName() { return "App"; } @Override public String getRawGameVersion() { return App.FULL_VERSION; } @Override public String getNormalizedGameVersion() { return App.VERSION; } @Override public Collection getBuiltinMods() { return Collections.emptyList(); } @Override public String getEntrypoint() { return "net.developer.app.App"; } @Override public Path getLaunchDirectory() { return this.gameDirectory; } @Override public boolean isObfuscated() { return false; } @Override public boolean requiresUrlClassLoader() { return false; } @Override public boolean isEnabled() { return true; } @Override public boolean locateGame(FabricLauncher launcher, String[] args) { this.arguments = new Arguments(); this.arguments.parse(args); this.gameDirectory = Paths.get(this.arguments.get("gameDirectory")); return Files.isDirectory(this.gameDirectory); } @Override public void initialize(FabricLauncher launcher) {} @Override public GameTransformer getEntrypointTransformer() { return this.transformer; } @Override public void unlockClassPath(FabricLauncher launcher) { for (Path path : this.jars) { launcher.addToClassPath(path); } } @Override public void launch(ClassLoader loader) { try { Class main = loader.loadClass(this.getEntrypoint()); Method method = main.getMethod("main", String[].class); method.invoke(null, (Object) this.arguments.toArray()); } catch (Exception e) { e.printStackTrace(); } } @Override public Arguments getArguments() { return this.arguments; } @Override public String[] getLaunchArguments(boolean sanitize) { return this.arguments.toArray(); } } ``` -------------------------------- ### Development Environment Setup for Fabric Loader Source: https://wiki.fabricmc.net/documentation%3Afabric_loader?difftype=sidebyside&do=diff&rev2%5B0%5D=1559976293&rev2%5B1%5D=1778963998 This code snippet outlines the initialization steps for a Fabric Loader development environment, including registering factories, foundations, and miscellaneous components. It also shows how to start the client and set up a watch dog for assets in development mode. ```java this.registerFactories(); this.registerFoundation(); this.registerMiscellaneous(); Hooks.startClient(app.gameDirectory, app); if (this.development) { this.watchDog = new WatchDog(this.assetsFolder); this.watchDog.register(this.textures); this.watchDog.register(this.models); this.watchDog.register(this.sounds); this.watchDog.start(); } } ``` -------------------------------- ### GameProvider Implementation Example Source: https://wiki.fabricmc.net/documentation%3Afabric_loader?rev=1671721435 Provides a basic implementation of the GameProvider interface, including methods to retrieve arguments and launch arguments. Assumes '--gameDirectory' is a relevant argument. ```java public Arguments getArguments() { return this.arguments; } @Override public String[] getLaunchArguments(boolean sanitize) { return this.arguments.toArray(); } } ``` -------------------------------- ### Other Language Entrypoint Example Source: https://wiki.fabricmc.net/documentation%3Afabric_mod_json?difftype=sidebyside&do=diff&rev2%5B0%5D=1558873330&rev2%5B1%5D=1703681627 Example of specifying entrypoints for languages other than Java, using an adapter and value pair. This example uses Kotlin. ```json "main": [ { "adapter": "kotlin", "value": "package.ClassName" } ] ``` -------------------------------- ### Example GameProvider Implementation Source: https://wiki.fabricmc.net/documentation%3Afabric_loader A comprehensive example of a GameProvider implementation for a custom application. This snippet demonstrates how to define game ID, name, versions, entry points, and handle game directory location and launching. ```java public class AppGameProvider implements GameProvider { private Arguments arguments; private Path gameDirectory; private GameTransformer transformer = new AppGameTransformer(); @Override public String getGameId() { return "app"; } @Override public String getGameName() { return "App"; } @Override public String getRawGameVersion() { return App.FULL_VERSION; } @Override public String getNormalizedGameVersion() { return App.VERSION; } @Override public Collection getBuiltinMods() { return Collections.emptyList(); } @Override public String getEntrypoint() { return "net.developer.app.App"; } @Override public Path getLaunchDirectory() { return this.gameDirectory; } @Override public boolean isObfuscated() { return false; } @Override public boolean requiresUrlClassLoader() { return false; } @Override public boolean isEnabled() { return true; } @Override public boolean locateGame(FabricLauncher launcher, String[] args) { this.arguments = new Arguments(); this.arguments.parse(args); this.gameDirectory = Paths.get(this.arguments.get("gameDirectory")); return Files.isDirectory(this.gameDirectory); } @Override public void initialize(FabricLauncher launcher) {} @Override public GameTransformer getEntrypointTransformer() { return this.transformer; } @Override public void unlockClassPath(FabricLauncher launcher) { for (Path path : this.jars) { launcher.addToClassPath(path); } } @Override public void launch(ClassLoader loader) { try { Class main = loader.loadClass(this.getEntrypoint()); Method method = main.getMethod("main", String[].class); method.invoke(null, (Object) this.arguments.toArray()); } catch (Exception e) { e.printStackTrace(); } } @Override public Arguments getArguments() { return this.arguments; } @Override public String[] getLaunchArguments(boolean includeNatives) { return this.arguments.toArray(); } } ``` -------------------------------- ### Kotlin Adapter Example Source: https://wiki.fabricmc.net/documentation%3Afabric_mod_json?difftype=sidebyside&do=diff&rev2%5B0%5D=1558362514&rev2%5B1%5D=1703681627 Example of specifying the Kotlin adapter for language support. ```json "kotlin": "net.fabricmc.language.kotlin.KotlinAdapter" ``` -------------------------------- ### FabricLauncher Methods Source: https://wiki.fabricmc.net/documentation%3Afabric_loader?difftype=sidebyside&do=diff&rev2%5B0%5D=1559911718&rev2%5B1%5D=1703681861 Demonstrates various methods within the FabricLauncher interface, including initialization, entrypoint transformation, class path unlocking, and launching the game. ```java public void initialize(FabricLauncher launcher) {} @Override public GameTransformer getEntrypointTransformer() { return this.transformer; } @Override public void unlockClassPath(FabricLauncher launcher) { for (Path path : this.jars) { launcher.addToClassPath(path); } } @Override public void launch(ClassLoader loader) { try { Class main = loader.loadClass(this.getEntrypoint()); Method method = main.getMethod(" main", String[].class); method.invoke(null, (Object) this.arguments.toArray()); } catch (Exception e) { e.printStackTrace(); } } @Override public Arguments getArguments() { return this.arguments; } @Override public String[] getLaunchArguments(boolean sanitize) { return this.arguments.toArray(); } ``` -------------------------------- ### Language Adapters Example Source: https://wiki.fabricmc.net/documentation%3Afabric_mod_json?difftype=sidebyside&do=diff&rev2%5B0%5D=1558362514&rev2%5B1%5D=1703681627 Example of how to define language adapters for non-Java languages used in a mod. ```json "languageAdapters": { ``` -------------------------------- ### Create Test Client Run Configuration Source: https://wiki.fabricmc.net/documentation%3Afabric_loom?difftype=sidebyside&do=diff&rev2%5B0%5D=1560003125&rev2%5B1%5D=1688553290 Example of creating a basic run configuration for tests, inheriting client settings and specifying the test source set. ```gradle testClient { // Copies settings from another run configuration. inherit client configName = "Test Minecraft Client" source = sourceSets.test } ``` -------------------------------- ### Example license in Fabric Mod JSON Source: https://wiki.fabricmc.net/documentation%3Afabric_mod_json?difftype=sidebyside&do=diff&rev2%5B0%5D=1560071334&rev2%5B1%5D=1703681627 Specifies the licensing information for the mod. This example uses an SPDX identifier. ```json { "license": "MIT" } ``` -------------------------------- ### Example GameProvider Implementation Source: https://wiki.fabricmc.net/documentation%3Afabric_loader?difftype=sidebyside&do=diff&rev2%5B0%5D=1647580625&rev2%5B1%5D=1671721435 A sample implementation of the GameProvider interface for a custom application. This includes methods for game identification, versioning, and setting up the launch environment. ```java public class AppGameProvider implements GameProvider { private Arguments arguments; private Path gameDirectory; private GameTransformer transformer = new AppGameTransformer(); @Override public String getGameId() { return "app"; } @Override public String getGameName() { return "App"; } @Override public String getRawGameVersion() { return App.FULL_VERSION; } @Override public String getNormalizedGameVersion() { ```