zh_cn:tutorial:primer
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| zh_cn:tutorial:primer [2023/01/11 15:44] – [Fabric 是什么?] tao0lu | zh_cn:tutorial:primer [2025/11/11 13:04] (current) – sinoaakira | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== Minecraft 模组编写基础 ====== | + | ~~REDIRECT> |
| - | // | + | ====== |
| - | 本文档是给模组编写的初学者使用的,比如还不知道 ``BlockState`` 和 ``BlockPos`` 的玩家。如果你有编写数据包的经验并想要将技巧提升到更高水平,或者需要学习面向对象的语言并开启一个有趣的项目,那么本文档适合你。首先从你需要了解的几个概念开始: | + | //注意:本文假设您没有任何 Minecraft Mod 制作经验。但是,您需要熟练掌握 Java 编程语言才能修改 Minecraft 源码 (请参阅“准备工作”部分)。如果您是从其他 Mod Loader (例如 Forge) 转到 Fabric,那么本入门指南的内容可能更适合您。// |
| - | ===== Minecraft 模组编写的前提 ===== | ||
| - | - 你必须知道代码编写的基础。如果你从没接触过代码,你应该先知道如何使用代码。这里所说的基础,包括变量、函数、类和方法等,以及一些面向对象的概念,如继承、多态、类型强转。要是不知道,先搜索。 | + | 本文旨在为那些对“方块位置” ('' |
| - | - 你应该要有一些编程语言的经验,例如 Java、C、C++ 和 C#。Java 的语法和 C 系列的比较类似。 | + | 首先,让我们从您需要事先了解的内容开始: |
| - | - 熟悉 Java 的语法,例如 lambda 方法、泛型(你应该知道这些是什么),以及一些语法糖,这些语法应该会在学习的时候一并遇到。 | + | |
| - | - 你必须知道如何使用 Internet 查找问题与答案,以及如何在网络论坛或者群里提问求助。 | + | |
| - | ===== 模组编写是什么? ===== | + | ===== Mod 制作是什么?===== |
| - | 模组编写(Modding)是指的往程序的源代码里面**增添**或者**修改**内容,这个程序就是指的 | + | Mod 制作是指对程序进行**功能添加**或**修改**的过程;在本文中,该程序是 Minecraft。你制作的所有 |
| - | ===== Fabric 是什么? ===== | + | ===== Fabric 是什么?===== |
| - | Fabric 是一系列用于编写 Minecraft 模组的工具,包括: | + | Fabric 是一套工具集,可以方便地制作 Fabric Mod 对 Minecraft 进行修改。这些工具包括: |
| - | * **Fabric Loader**-- | + | * **Fabric Loader**-- |
| - | * **Fabric Loom**,用于使用 Fabric | + | * **Fabric Loom**-- 一个专为使用 Fabric |
| - | * Fabric 的 **语言模块** 允许你使用其他的 JVM 语言(例如 Kotlin 或 Scala)来编写你的模组。注意:建议初学者还是先从 Java 开始,因为 Minecraft 就是用这种语言编写的,Java 也是最容易寻求帮助的。 | + | * Fabric 的 **编程语言模块** 允许你使用其他 JVM 语言 |
| - | * **Fabric API**-- 一系列能让添加或修改 Minecraft | + | * **Fabric API**-- 一套可以更轻松地添加或修改某些常见 |
| - | * **Fabric | + | * **Fabric |
| - | 为了更好的理解 Minecraft 的代码干了什么,当你使用 Fabric 进行模组编写时,你有机会接触到 | + | 为了更轻松地理解 Minecraft 的代码,当您使用 Fabric 进行 |
| - | * **中介**映射器是一个程序,它将会给予 Minecraft | + | * **Intermediary** 映射器是一个程序,它会给 Minecraft |
| + | * **Yarn** | ||
| - | * **yarn** 是反混淆过程中的最后一步。Yarn 是一个自由的、开源的社区驱动的 Minecraft 中所有方法和类的名称库。当你看 Minecraft 的源代码时,对于任何类、变量或方法,描述其作用的名称都是由 Yarn 编写的。社区中会有人分析并决定为其命名。每次有新的更新或快照出现时,社区就会开始工作,梳理代码,看看有哪些新的对象需要命名。((注意:虽然 Mojang 发布了所有 Minecraft 版本的官方映射,但在模组编写中使用这些映射的合法性在未来可能会改变。而 Yarn 映射是自由的,每个人都可以使用,并且足以满足大多数模组编写的目的,所以不鼓励你使用官方的映射。)) | + | 然而,并非 Minecraft 中的所有内容都已被 Yarn 映射——有时您会看到一些变量仍然使用 Intermediary |
| - | + | ||
| - | 但是,在反编译的 | + | |
| ===== 代码结构 ===== | ===== 代码结构 ===== | ||
| - | Minecraft: Java Edition | + | Minecraft: Java Edition |
| + | |||
| + | ==== 注册表 ==== | ||
| + | |||
| + | Minecraft 中的大多数“功能” (你可能想要添加的东西,例如方块、物品、界面、实体、区块生成器等等) 会在游戏加载时加载到对应的注册表中。例如,每个物品 ('' | ||
| - | === 注册表 | + | ==== 端 ==== |
| - | Most " | + | Minecraft 的处理分为两个线程,通常称为“端”:服务端和客户端。客户端始终运行在玩家的计算机上,负责渲染和输入。服务端可以独立运行,作为专用服务器 |
| - | === 端 === | + | 客户端与服务端必须就某些事项达成一致:世界中有哪些方块、箱子里有什么、玩家位置等等。由于这些由服务端处理,因此服务端会将这些值告知客户端,客户端再将这些值显示给玩家。任何由客户端处理的内容都不需要告知服务端——这包括方块和实体的外观 (资源包) 以及如何绘制世界 (着色器)。这就是客户端 Mod (例如着色器)、服务端 Mod (例如运行小游戏的 Mod) 和双端 Mod (例如添加机器、新方块和新物品的 Mod) 之间的区别。 |
| - | Minecraft' | + | 重要的是,不要在服务端调用仅供客户端使用的代码 |
| - | The client and server must agree on certain things: what blocks are in the world, what is inside chests, player position, etc. Since these are handled by the server, it dictates to the client what these values should be, and the client displays them to the person playing the game. Anything handled by the client does not have to be told to the server at all-- this includes what blocks and entities look like (resource packs), and how to draw the world (shaders). This is the distinction between clientside mods (like shaders), serverside mods (like those that run minigames), and both-sided mods (those that add things like machines or new blocks and items). | + | |
| - | It is important to not call client-only code (i.e., relating to rendering) on the server, and server-only code on the client. This is the purpose of the ubiquitous | + | |
| - | ===== 下一步 ===== | + | ===== 后续步骤 ===== |
| - | Once you've achieved the prerequisites and have read this document, it's time to get started! Check out the [[introduction]] | + | 完成所有准备工作并阅读本文档后,就可以开始了!请查看 |
zh_cn/tutorial/primer.1673451851.txt.gz · Last modified: 2023/01/11 15:44 by tao0lu