zh_cn:tutorial:primer
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| zh_cn:tutorial:primer [2022/10/22 11:24] – created solidblock | 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 |
| - | To more easily understand what is going on in Minecraft's code, when you mod with Fabric, you will also have access to Minecraft's source code. Since Java is a compiled language, we need to decompile the code before it can be read. This turns it from Java bytecode into human-readable | + | 为了更轻松地理解 |
| - | * the **intermediary** mapper is a program that gives every single object in Minecraft's code a name like "field_10832", or "method_12991()". Critically, this program always names each object the same thing. So a method that does not change between versions will always have the same intermediary name. | + | * **Intermediary** 映射器是一个程序,它会给 |
| - | * **yarn** is the final step in the deobfuscation process. Yarn is a libre, open-source community-driven library of names for all the methods and classes in Minecraft. When you look at the source code for Minecraft, any class, variable, or method that has a name describing what is does was written with Yarn. Someone in the community analyzed and decided to name it that. Every time a new update or snapshot comes out, the community gets to work combing through the code to see what new objects need names. | + | * **Yarn** 是反混淆过程的最后一步,它从 Intermediary 映射器的产物为 |
| - | Not everything in the Minecraft | + | 然而,并非 |
| ===== 代码结构 ===== | ===== 代码结构 ===== | ||
| - | Minecraft: Java Edition | + | Minecraft: Java Edition |
| - | === 注册表 === | + | ==== 注册表 |
| - | Most " | + | Minecraft 中的大多数“功能” |
| - | === 端 === | + | ==== 端 ==== |
| - | Minecraft's processing is split between two threads, commonly called " | + | 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 '' | + | |
| - | ===== 下一步 ===== | + | 客户端与服务端必须就某些事项达成一致:世界中有哪些方块、箱子里有什么、玩家位置等等。由于这些由服务端处理,因此服务端会将这些值告知客户端,客户端再将这些值显示给玩家。任何由客户端处理的内容都不需要告知服务端——这包括方块和实体的外观 (资源包) 以及如何绘制世界 (着色器)。这就是客户端 Mod (例如着色器)、服务端 Mod (例如运行小游戏的 Mod) 和双端 Mod (例如添加机器、新方块和新物品的 Mod) 之间的区别。 |
| - | Once you've achieved the prerequisites and have read this document, it's time to get started! Check out the [[introduction]] | + | 重要的是,不要在服务端调用仅供客户端使用的代码 (即与渲染相关的代码),也不要将仅供服务端使用的代码放在客户端。这就是你在 Minecraft Mod 中经常看到的无处不在的 '' |
| + | |||
| + | ===== 后续步骤 ===== | ||
| + | |||
| + | 完成所有准备工作并阅读本文档后,就可以开始了!请查看 | ||
zh_cn/tutorial/primer.1666437891.txt.gz · Last modified: 2022/10/22 11:24 by solidblock