User Tools

Site Tools


documentation:fabric_loom

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
documentation:fabric_loom [2022/01/24 21:39] modmuss50documentation:fabric_loom [2023/01/28 15:43] modmuss50
Line 24: Line 24:
 } }
 </code> </code>
 +
 +==== 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.
 +
 +<code>
 +loom {
 + splitEnvironmentSourceSets()
 +
 + mods {
 +        modid {
 +            sourceSet sourceSets.main
 +            sourceSet sourceSets.client
 +        }
 + }
 + }
 +</code>
 +
 +==== Mutli 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 <code>fabric.loom.multiProjectOptimisation=true</code> to the settings.gradle file will help decrease build time and memory usage by sharing the Tiny Remapper instance between projects when remapping your output jars.
  
 ==== Options ==== ==== Options ====
Line 58: Line 81:
  // Add a program arg  // Add a program arg
  programArg "--example"  programArg "--example"
 + // Add an environment variable
 + environmentVariable("example", "true")
  // The environment (or side) to run, usually client or server.  // The environment (or side) to run, usually client or server.
  environment = "client"  environment = "client"
Line 122: Line 147:
  enableDependencyInterfaceInjection = true  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 158: Line 199:
  
  // Remap a mod from maven and apply to gradle's implementation configuration  // Remap a mod from maven and apply to gradle's implementation configuration
 + // (Minor detail: it's not exactly applied *to* the configuration, but a clone of it intended for mod dependencies)
  modImplementation "net.fabricmc.fabric-api:fabric-api:0.46.2+1.18"  modImplementation "net.fabricmc.fabric-api:fabric-api:0.46.2+1.18"
  
Line 169: Line 211:
  modCompileOnlyApi "net.fabricmc.fabric-api:fabric-api:0.46.2+1.18"  modCompileOnlyApi "net.fabricmc.fabric-api:fabric-api:0.46.2+1.18"
  
- // Remap a mod from maven and apply to gradle'runtimeOnlyApi configuration+ // Remap a mod from maven and apply to gradle'runtimeOnly configuration
  modRuntimeOnly "net.fabricmc.fabric-api:fabric-api:0.46.2+1.18"  modRuntimeOnly "net.fabricmc.fabric-api:fabric-api:0.46.2+1.18"
  
documentation/fabric_loom.txt · Last modified: 2023/12/22 14:39 by modmuss50