documentation:fabric_loom
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| documentation:fabric_loom [2022/01/20 13:43] – modmuss50 | documentation:fabric_loom [2026/05/16 20:40] (current) – cassiancc | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ~~REDIRECT> | ||
| ====== Fabric Loom ====== | ====== Fabric Loom ====== | ||
| Line 5: | Line 6: | ||
| ==== Useful tasks ==== | ==== Useful tasks ==== | ||
| - | * '' | + | * '' |
| * '' | * '' | ||
| * '' | * '' | ||
| Line 11: | Line 12: | ||
| * '' | * '' | ||
| * '' | * '' | ||
| + | * '' | ||
| * '' | * '' | ||
| * '' | * '' | ||
| Line 24: | Line 26: | ||
| } | } | ||
| </ | </ | ||
| + | |||
| + | If you are using splitsource sets in a multi-project build, you will also need to add a dependency for the other projects client sourceset. | ||
| + | |||
| + | < | ||
| + | dependencies { | ||
| + | clientImplementation project(": | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | ==== Split Client and Common code ==== | ||
| + | |||
| + | For years a common source of server crashes has been from mods accidentally calling client only code when installed on a server. The latest loom and loader verions provide an option to require all client code to be moved into its own sourceset. This is done to provide a compile-time guarantee against calling client only Minecraft code or client only API on the server. A single jar file that works on both the client and server is still built from the two sourcesets. | ||
| + | |||
| + | The following snippet from a build.gradle file shows how you can enable this for your mod. As your mod will now be split across two sourcesets, you will need to use the new DSL to define your mods sourcesets. This enables Fabric Loader to group your mods classpath together. This is also useful for some other complex multi-project setups. | ||
| + | |||
| + | Minecraft 1.18 (1.19 recommended), | ||
| + | |||
| + | < | ||
| + | loom { | ||
| + | splitEnvironmentSourceSets() | ||
| + | |||
| + | mods { | ||
| + | modid { | ||
| + | sourceSet sourceSets.main | ||
| + | sourceSet sourceSets.client | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | ==== Multi project Optimisation ==== | ||
| + | |||
| + | If your Gradle project has many subprojects that use the same Minecraft version such as Fabric-API, starting with Loom 1.1 you can now opt-in to advanced optimistations. Adding < | ||
| ==== Options ==== | ==== Options ==== | ||
| Line 41: | Line 76: | ||
| // When enabled transitive access wideners will be applied from dependencies. | // When enabled transitive access wideners will be applied from dependencies. | ||
| enableTransitiveAccessWideners = true | enableTransitiveAccessWideners = true | ||
| - | // When enabled interface injection will be enabled | ||
| - | enableInterfaceInjection = true | ||
| // When enabled log4j will only be on the runtime classpath, forcing the use of SLF4j. | // When enabled log4j will only be on the runtime classpath, forcing the use of SLF4j. | ||
| runtimeOnlyLog4j = false | runtimeOnlyLog4j = false | ||
| Line 60: | Line 93: | ||
| // Add a program arg | // Add a program arg | ||
| programArg " | programArg " | ||
| + | // Add an environment variable | ||
| + | environmentVariable(" | ||
| // The environment (or side) to run, usually client or server. | // The environment (or side) to run, usually client or server. | ||
| environment = " | environment = " | ||
| Line 88: | Line 123: | ||
| source = sourceSets.test | source = sourceSets.test | ||
| } | } | ||
| + | |||
| + | // Example of removing the built-in server configuration | ||
| + | remove server | ||
| } | } | ||
| Line 119: | Line 157: | ||
| } | } | ||
| } | } | ||
| + | |||
| + | interfaceInjection { | ||
| + | // When enabled injected interfaces from dependecies will be applied. | ||
| + | enableDependencyInterfaceInjection = true | ||
| + | } | ||
| + | |||
| + | // Splits the Minecraft jar and incoming dependencies across the main (common) and client only sourcesets. | ||
| + | // This provides compile time safety for accessing client only code. | ||
| + | splitEnvironmentSourceSets() | ||
| + | |||
| + | // This mods block is used group mods that are made up of multiplue classpath entries. | ||
| + | mods { | ||
| + | modid { | ||
| + | // When using split sources you should add the main and client sourceset | ||
| + | sourceSet sourceSets.main | ||
| + | sourceSet sourceSets.client | ||
| + | } | ||
| + | } | ||
| + | |||
| + | // Create modExampleImplementation and related configurations that remap mods. | ||
| + | createRemapConfigurations(sourceSets.example) | ||
| } | } | ||
| Line 155: | Line 214: | ||
| // Remap a mod from maven and apply to gradle' | // Remap a mod from maven and apply to gradle' | ||
| + | // (Minor detail: it's not exactly applied *to* the configuration, | ||
| modImplementation " | modImplementation " | ||
| Line 166: | Line 226: | ||
| modCompileOnlyApi " | modCompileOnlyApi " | ||
| - | // Remap a mod from maven and apply to gradle' | + | // Remap a mod from maven and apply to gradle' |
| modRuntimeOnly " | modRuntimeOnly " | ||
| Line 189: | Line 249: | ||
| ==== Resolving issues ==== | ==== Resolving issues ==== | ||
| - | Loom and/or gradle can sometimes fail due to corrupted cache files. Running '' | + | Loom and/or gradle can sometimes fail due to corrupted cache files. Running '' |
| ==== Development environment setup ==== | ==== Development environment setup ==== | ||
| Line 203: | Line 263: | ||
| - Adds dependencies of Minecraft. | - Adds dependencies of Minecraft. | ||
| - Downloads Minecraft assets. | - Downloads Minecraft assets. | ||
| - | - Processes and includes mod-augmented dependencies | + | - Processes and includes mod-augmented dependencies. |
| ==== Caches ==== | ==== Caches ==== | ||
| Line 216: | Line 276: | ||
| * '' | * '' | ||
| * '' | * '' | ||
| - | * '' | + | * '' |
| * '' | * '' | ||
| Line 239: | Line 299: | ||
| The client run configuration is configured with '' | The client run configuration is configured with '' | ||
| + | |||
documentation/fabric_loom.1642686211.txt.gz · Last modified: 2022/01/20 13:43 by modmuss50