your current location:首页 > news>Fabric Mod Development Tutorial -01 Environment Fabric Loader Minecraft Game

Fabric Mod Development Tutorial -01 Environment Fabric Loader Minecraft Game

2024-12-10 17:51:53|Myriagame |source:minecraft skins

Foreword

As we all know, MODLOADER's Modloader has two levels of differentiation in the high version:

The first faction is the emerging light model -Fabric, the one is the old -fashioned large Modloader -FORGE.

Everyone can make their own choices according to their preferences, which is not absolutely right or wrong.

However, Fabric is more suitable for novice developers compared to the relatively complicated and difficult FORGE MOD.

Therefore, this tutorial is to take care of the new Fabric Mod development tutorial.

It takes a little programming foundation, which is normal, because MOD development can never avoid contact code (you can read the tutorial by yourself).

Due to its limited strength, it may be wrong or missed in some places. Please correct me.

(Since the language of the device is traditional Chinese, please prevail in some text content)

1 Preparation before sailing -the configuration and installation of the IDE

1.1 preface

"In the era without transportation, the distance that could reach is nothing more than a distance that both feet can go.

Later, we tamed the horses and invented the carriage. Now a series of transportation that can enter the heavens and the earth.

The development of MOD only rely on one pair of feet is not far away."

Therefore, we need to prepare some tools for MOD development.

These tools are called IDEs (Integrated Development Environment, that is, an integrated development environment), and the existence of IDE can make our development easier and faster.

Since only Microsoft's Visual Studio Code (hereinafter referred to as VSC), this tutorial is explained by VSC as an IDE.

1.2 download and installation of IDE

1.2.1 download

First of all, you need to go to this URL to get the latest version of VSC (you can use a translator if you don't understand English. Here is recommended to use Deepl, which is higher than the translation quality of Google translated by the wall and inaccurate). Download the corresponding operating system for your operating system(OS) version (here is a Windows system+chrome demonstration).

Click (download for ) button to download.

Of course, due to some special reasons, the download speed is usually slow as a turtle climb.

Therefore, let's use mirror source to accelerate download.

Open "Download" and find the download item just created (Note: The specific download link is based on the actual situation):

Right -click the address below the file name, click: Copy the link link.

Then paste this link to the link input box of the browser:

Replace the az764295.vo.vo.msecnd.net in front of the link to vscode.cdn.azure.cn, and then press Enter.

Wait for downloading.

1.2.2

Open the installation package.

If the firewall is promptly prompt, point permit.

If the following interface pops up:

This page means: This installation package can only be installed for the current user. If you need to install it for all users, please download the system installation package.

We do not care about it.

Then, it is the license agreement:

This protocol can be read or not read, the choice is in you,

The content of this agreement has nothing to do with our MOD development.

Click "I agree with the agreement" and "Next" in turn.

Then install the custom link, you can switch according to your preference:

Add the "Open" operation through CODE to the resource manager file/directory context menu: That is, this option will appear when right -clicking a file/directory.Recommended opening, you can quickly open the project.

Register Code as a supporting file type editor: VSC is used as the default file editor to replace tools such as notepads.It is recommended to open, because VSC has many functions besides writing MOD.

Add to PATH (after restarting effective): Add VSC to the CMD instruction to find the path (ie PATH), so that you can directly call VSC with a short command through the CMD.Of course, if you understand environment variables, manual configuration is also possible.

The next step is to install traditional art, one by one.

However, you need to declare: Unless you have confidence in your own system tray, it is not recommended to install it to the system disk, because the dependency will be downloaded to the system disk during MOD development (especially forge [although this is the Fabric tutorial], the forge will download it will be downloadedNearly 2G dependence).

After installation, we also need to install corresponding development and expansion to start development.If it is not surprising, the interface you see should be similar to this:

If the default language set by the device is not English, there should be a prompt to install the corresponding language in the lower right corner. Click OK (this depends on you, if you listen to other older generations of developers, please click it).

(The following content is changed from Fabric Wiki: The original tutorial)

Click on the extended paging on the left (the icon is based on the actual situation, you can sweep the mouse on the left):

Then you can see the expansion page:

Search the following expansion package installation:

LANGUAGE Support for Java (TM) by Red Hat

Debugger for java

Java Extension Pack

1.3 officially set off

"There must be steel plates for cars, and circuit boards require substrates.

There is no foundation house that cannot be built, and so is MOD development."

1.3.1 trivia

When everything is ready, you can finally start the MOD writing journey.

Now go to the GitHub warehouse in Fabric to get the MOD project template:

Both links are available, but the second one is more recommended, because most people do not have a GitHub account (some have not even touched/github walls at all), and cannot use github warehouse generator.

Then open a page:

You can compare the figure below:

As for the following Advanced Options (Advanced Options) ...

The first is whether to use Kotlin as a language, but this tutorial uses Java as a language, so please do not open it.

The second is DataGen, that is, whether to automatically complete the configuration of DataGen [Data Generator], it is recommended to open, although it may be useless now, just in case.

The third is to divide clients and universal code, which can prevent the code from being called by the wrong place (mentioned later).Semi -recommendation: If you have no Java foundation, it is best to turn it off.

Then, click the bottom blue button to download the template to your device:

Next, decompress your downloaded compressed package, right-click-> Open through CODE (of course, if you cancel it when installing, there is no option here. Then click the file in the upper left corner in the upper left corner in VSC-> Open the filefolder).

Then, wait patiently for the project import.Until your "Gradle for Java" terminal (if the column below is empty, press Ctrl + `) to display this line (PS: Since other development items are lazy, the output is not exactly the same as normal):

If the word output is the CONFIGURE FAIL cardiac arrest, it needs to be checked.

The error log will be exported to the top (translate if you don’t understand)

There are many common reasons:

Timeout: Usually display multiple links; then display: Fail to Setup Minecraft (installed Minecraft failed), or find file (unable to get files).

Anti -confusion failure: display texts such as yarn, mapping; then show that a file does not exist.

The above two reasons can be restarted to the IDE a few times. If the project import is too slow, please refer to Fabricmccn.

Process disorders: Display files occupied; first turn off the IDE, then open the task manager, and end the processes such as "Openjdk Platform Binary" or "Java" (press the button in the lower right corner).

Task manager opening method:

(Only below Windows 11) Right -click the taskbar [That's the column of time] blank, click "Task Manager" [Because the system is in the middle, it is displayed as a "work manager"].

Press Ctrl+Shift+ESC.

1.3.2 Overview of the project structure

If it is not modified, the current file structure of the project is probably long (not divided into clients and universal code):

T───.github

│ w── ─ workflows

D──—Gradle

│ w──Wrapper

C ──SRC

In──Main

A───JAVA

│ c ──Com

│ e── XAMPLE

│ m──Mixin

U───Resources

E ──Assets

P──Template-mod or this (divided client and general code):

T───.github

│ w── ─ workflows

D──—Gradle

│ w──Wrapper

C ──SRC

En── ─ Client

│ j ──JAVA

│ │ └ ──Mom

│ │ └ ── xample

│ │ └───Mixin

│ │ └ ──Client

│ re──Rsources

In──Main

A───JAVA

│ c ──Com

│ e── XAMPLE

│ m──Mixin

U───Resources

E ──Assets

P ──Template-mod

First look at the files in the root directory:

Build.gradle -The core of the project is that it enables the entire project to be imported and operated normally. The internal content is written by Groovy (except for handling dependencies, you must never touch this file! Because once this file is modified, this document is modified, and once it is modified, this document is modified.The entire project needs to be re -imported [Although you don't need to restart the IDE, it takes a few minutes for each introduction!)).

(In short, the file of the Gradle suffix is ​​less touching)

Gradle.properties -The configuration file of the project will be read during the project import.

Settings.gradle -Gradle plug -in ways do not need to be modified.

.gitignore -Git's neglect items (this tutorial will not mention the use of git), no modification is required.

License -MOD's license agreement, please replace it with your own protocol, or delete it directly.

Gradlew.bat and Gradlew -Gradle command execute programs without modification.

The .github folder can be deleted.

Gradle/Wrapper folder:

Gradle-wrapper.jar-Gradle used for automatic download projects does not need to be modified.

Gradle-wrapper.properties-Gradle used for the project is generally not required.

SRC/main/java/ folder is used to store all code.

src/main/resources folder:

Fabric.mod.json -basic information of MOD.

.mixins.json -MIXIN information of MOD (will be mentioned in the later tutorial).

SRC/main/Resources/Assets folder is quite equal to a resource package, but there is no Pack.mcmeta.

SRC/main/Resources/Data folder (no can be created by itself), which is equivalent to a packet, but there is no Pack.mcmeta.

1.3.4 Gradle task

The introduction is almost the same, one part of the difference is not said: Gradle task.

All tasks are placed in the pagination of this elephant icon:

Click Tasks/Build/Build to perform construction operations.

Then there will be an additional buk in your root directory.

Open the Build/lib folder and try it in MINECRAFT, which just built.

Then enter the game ...

Um?Nothing happened?

No, please close the running Minecraft immediately, and then open it with VSC to open the .minecraft/log/latest.log:

Press Ctrl+F and enter "Hello Fabric World!" Search -yes, there is a line of logs!"Hello Fabric World!".

It is said that the output hello world can bring good luck to the development of development, so do not forget every time a different environment/language.

(Please refer to: Fabric Wiki, DEVELOP | Fabric)