zh_cn:documentation:fabric_loom
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| zh_cn:documentation:fabric_loom [2022/03/20 13:11] – 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 { | ||
| - | // 若禁用,会使用微小重映射器来重映射 Mixin 而非 AP。实验性。 | + | // 若禁用,会使用 |
| useLegacyMixinAp = true | useLegacyMixinAp = true | ||
| // 设置默认的 refmap 名称 | // 设置默认的 refmap 名称 | ||
| 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) | ||
| } | } | ||
| 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.1647781899.txt.gz · Last modified: 2022/03/20 13:11 by solidblock