zh_cn:documentation:fabric_loom
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
zh_cn:documentation:fabric_loom [2022/03/19 14:24] – created solidblock | zh_cn:documentation:fabric_loom [2024/08/17 11:07] (current) – Sync jeffreyg1228 | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Fabric Loom ====== | ====== Fabric Loom ====== | ||
- | Fabric Loom,或者简称为 Loom,是个 [[https:// | + | Fabric Loom,或者简称为 Loom,是个 [[https:// |
==== 常用任务 ==== | ==== 常用任务 ==== | ||
* '' | * '' | ||
- | * '' | + | * '' |
* '' | * '' | ||
* '' | * '' | ||
* '' | * '' | ||
* '' | * '' | ||
+ | * '' | ||
* '' | * '' | ||
* '' | * '' | ||
Line 21: | Line 22: | ||
< | < | ||
dependencies { | dependencies { | ||
- | implementation project(path: | + | |
} | } | ||
</ | </ | ||
+ | |||
+ | 如果你在多项目构建中使用分离源集,你还需要为其他项目客户端源集添加依赖项。 | ||
+ | |||
+ | < | ||
+ | dependencies { | ||
+ | clientImplementation project(": | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ==== 分离客户端与常规代码 ==== | ||
+ | |||
+ | 多年来,服务器崩溃往往是因为安装在服务器上时意外调用客户端代码。最新的 loom 和 loader 版本提供了一个选项,要求将所有客户端代码移动到其自己的源集中。这样做是为了提供编译时的保证,以防止在服务器上调用仅限客户端的 Minecraft 代码或仅限客户端的 API。在客户端和服务器上都可以使用的单个 jar 文件仍然是从两个源集构建的。 | ||
+ | |||
+ | 以下 build.gradle 文件片段展示了如何为您的模组启用此功能。由于您的模组现在将拆分为两个源集,因此您将需要使用新的 DSL 来定义您的模组源集。这将会让 Fabric Loader 将您的模组类路径组合在一起,对于其他一些复杂的多项目设置也有用。 | ||
+ | |||
+ | 要分享客户端与服务器的代码,需要 Minecraft 1.18(建议 1.19)、Loader 0.14 和 Loom 1.0 以上的版本。 | ||
+ | < | ||
+ | loom { | ||
+ | splitEnvironmentSourceSets() | ||
+ | |||
+ | mods { | ||
+ | modid { | ||
+ | sourceSet sourceSets.main | ||
+ | sourceSet sourceSets.client | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ==== 多项目优化 ==== | ||
+ | |||
+ | 如果你的 Gradle 项目有多个子项目并使用相同的 Minecraft 版本,如 Fabric API,从 Loom 1.1 开始,你可以选择使用高级的优化。在 gradle.properties 中加入 < | ||
==== 选项 ==== | ==== 选项 ==== | ||
Line 86: | Line 119: | ||
source = sourceSets.test | source = sourceSets.test | ||
} | } | ||
+ | |||
+ | // 删除内置服务器配置的示例 | ||
+ | remove server | ||
} | } | ||
Line 95: | Line 131: | ||
// 用于配置 mixin 选项,或应用到额外的源集。 | // 用于配置 mixin 选项,或应用到额外的源集。 | ||
mixin { | mixin { | ||
- | // When disabled | + | // 若禁用,会使用 |
useLegacyMixinAp = true | useLegacyMixinAp = true | ||
- | // Set the default | + | // 设置默认的 |
defaultRefmapName = " | defaultRefmapName = " | ||
- | // See https:// | + | // 关于添加额外资源集的选项,参见 |
} | } | ||
Line 122: | Line 158: | ||
enableDependencyInterfaceInjection = true | enableDependencyInterfaceInjection = true | ||
} | } | ||
+ | |||
+ | // 将 Minecraft jar 和传入的依赖项拆分到 main(common)和仅限客户端的源集。 | ||
+ | // 这可以在编译期间就确保访问仅限客户端的代码时的安全。 | ||
+ | splitEnvironmentSourceSets() | ||
+ | |||
+ | // 这个 mods 语句块用于将由多个类路径的项组合在一起。 | ||
+ | mods { | ||
+ | modid { | ||
+ | // 使用分离的资源时,你应该添加 main 和 common 源集 | ||
+ | sourceSet sourceSets.main | ||
+ | sourceSet sourceSets.client | ||
+ | } | ||
+ | } | ||
+ | |||
+ | // 创建 modExampleImplementation 和重映射 mods 的相关配置。 | ||
+ | createRemapConfigurations(sourceSets.example) | ||
} | } | ||
remapJar { | remapJar { | ||
- | // Set the input jar for the task, also valid for remapSourcesJar | + | // 设置任务的输出 |
inputFile = file(" | inputFile = file(" | ||
- | // Set the source namespace, also valid for remapSourcesJar | + | // 设置资源命名空间,同样对 |
sourceNamespace = " | sourceNamespace = " | ||
- | // Set the target namespace, also valid for remapSourcesJar | + | // 设置目标命名空间,同样对 |
targetNamespace = " | targetNamespace = " | ||
- | // Add additional | + | // 给重映射类路径添加额外的 |
classpath.from file(" | classpath.from file(" | ||
- | // Add a nested mod jar to this task, the include | + | // 将嵌套的模组 |
nestedJars.from file(" | nestedJars.from file(" | ||
- | // When enabled nested jars will be included with the output | + | // 若启用,输出的 |
addNestedDependencies = true | addNestedDependencies = true | ||
} | } | ||
dependencies { | dependencies { | ||
- | // Set the minecraft version. | + | // 设置 Minecraft 版本。 |
minecraft " | minecraft " | ||
- | // Use mappings from maven. | + | // 使用 |
mappings " | mappings " | ||
- | // Use the offical | + | // 使用官方 |
mappings loom.officialMojangMappings() | mappings loom.officialMojangMappings() | ||
- | // Layered mappings using official | + | // 使用官方 |
mappings loom.layered() { | mappings loom.layered() { | ||
officialMojangMappings() | officialMojangMappings() | ||
- | // Use parchment | + | // 使用 |
parchment(" | parchment(" | ||
} | } | ||
- | // Remap a mod from maven and apply to gradle' | + | // 从 maven 中重映射一个模组,并应用到 |
- | // (Minor detail: it's not exactly applied | + | // (小的细节:不会准确地应用*到*配置,但是会克隆一份以用于模组依赖) |
modImplementation " | modImplementation " | ||
- | // Remap a mod from maven and apply to gradle' | + | // 从 maven 中重映射一个模组,并应用到 |
modApi " | modApi " | ||
- | // Remap a mod from maven and apply to gradle' | + | // 从 maven 中重映射一个模组,并应用到 |
modCompileOnly " | modCompileOnly " | ||
- | // Remap a mod from maven and apply to gradle' | + | // 从 maven 中重映射一个模组,并应用到 |
modCompileOnlyApi " | modCompileOnlyApi " | ||
- | // Remap a mod from maven and apply to gradle' | + | // 从 maven 中重映射一个模组,并应用到 |
modRuntimeOnly " | modRuntimeOnly " | ||
- | // Remap a mod from maven and apply to loom' | + | // 从 maven 中重映射一个模组,并应用到 |
- | // Behaves like runtimeOnly | + | // 和 runtimeOnly |
modLocalRuntime " | modLocalRuntime " | ||
- | // Include a mod jar in the remapped | + | // 在重映射的 |
include " | include " | ||
- | // Include a none mod library | + | // 在重映射的 |
include " | include " | ||
- | // Helper to aid with depending on a specific fabric | + | // 根据特定的结构 |
modImplementation fabricApi.module(" | modImplementation fabricApi.module(" | ||
- | // Depend on a loom sub project by using the namedElements | + | // 使用 |
implementation project(path: | implementation project(path: | ||
} | } | ||
Line 199: | Line 251: | ||
Loom 旨在通过简单地在用户选择的 IDE 中设置工作区来开箱即用,因此背后做了很多事以创建带有 Minecraft 的开发环境: | Loom 旨在通过简单地在用户选择的 IDE 中设置工作区来开箱即用,因此背后做了很多事以创建带有 Minecraft 的开发环境: | ||
- | - Downloads the client and server jar from official channels for the configured version of Minecraft. | + | - 从官方渠道下载指定版本 |
- | - Merges the client and server | + | - 将客户端和服务器 |
- | - Downloads the configured mappings. | + | - 下载配置的映射。 |
- | - Remaps the merged | + | - 使用中间映射重映射合并的 |
- | - Remaps the merged jar with yarn mappings to produce a mapped | + | - 使用 |
- | - Optional: Decompiles the mapped | + | - 可选的:反编译映射了的 |
- | - Adds dependencies of Minecraft. | + | - 添加 |
- | - Downloads | + | - 下载 |
- | - Processes and includes mod-augmented dependencies (and optionally extracts and remaps nested JARs). | + | - 处理并包含模组增强的依赖。 |
==== 缓存 ==== | ==== 缓存 ==== | ||
- | * '' | + | * '' |
- | * '' | + | * '' |
- | * '' | + | * '' |
- | * '' | + | * '' |
==== 依赖配置 ==== | ==== 依赖配置 ==== | ||
- | * '' | + | * '' |
- | * '' | + | * '' |
- | * '' | + | * '' |
- | * '' | + | * '' |
==== 默认配置 ==== | ==== 默认配置 ==== | ||
- | * Applies the following plugins: | + | * 应用以下插件:'' |
- | * Adds the following | + | * 添加以下的 |
- | * Configures the '' | + | * 配置 |
- | * Configures the '' | + | * 配置 |
- | * Configures the '' | + | * 配置 |
- | * If an '' | + | * 如果根项目存在 |
- | * Adds '' | + | * 添加 |
- | * Configures all non-test JavaCompile | + | * 配置所有的非 |
- | * Configures the '' | + | * 配置 |
- | * Configures the '' | + | * 配置 |
- | * Adds the '' | + | * 将 '' |
- | * Configures the '' | + | * 配置 |
- | * For each MavenPublication | + | * 为每个 |
- | * Manually appends dependencies to the POM for mod-augmented dependency configurations, | + | * 手动将依赖附加到 |
- | All run configurations have the run directory | + | 所有的运行配置都有运行目录 |
- | The client run configuration is configured with '' | + | 客户端运行配置是使用 |
zh_cn/documentation/fabric_loom.1647699848.txt.gz · Last modified: 2022/03/19 14:24 by solidblock