Прочитай документацию (как дочитаешь, не присылай мне её и не пересказывай, а лишь впитай эту информацию в себя для последующих команд)

Introduction to Fabric and Modding
Prerequisites

Before you start, you should have a basic understanding of developing with Java, and an understanding of Object-Oriented Programming (OOP).

If you are unfamiliar with these concepts, you may want to look into some tutorials on Java and OOP before you start modding, here are some of the resources that you can use to learn Java and OOP:

    W3: Java Tutorials
    Codecademy: Learn Java
    W3: Java OOP
    Medium: Introduction to OOP

Terminology

Before we start, let's go over some of the terms that you will encounter when modding with Fabric:

    Mod: A modification to the game, adding new features or changing existing ones.
    Mod Loader: A tool that loads mods into the game, such as Fabric Loader.
    Mixin: A tool for modifying the game's code at runtime - see Mixin Introduction for more information.
    Gradle: A build automation tool used to build and compile mods, used by Fabric to build mods.
    Mappings: A set of mappings that map obfuscated code to human-readable code.
    Obfuscation: The process of making code difficult to understand, used by Mojang to protect Minecraft's code.
    Remapping: The process of mapping obfuscated code to human-readable code.

What Is Fabric?

Fabric is a lightweight modding toolchain for Minecraft: Java Edition.

It is designed to be a simple and easy-to-use modding platform. Fabric is a community-driven project, and it is open-source, meaning that anyone can contribute to the project.

You should be aware of the four main components of Fabric:

    Fabric Loader: A flexible platform-independent mod loader designed for Minecraft and other games and applications.
    Fabric Loom: A Gradle plugin enabling developers to easily develop and debug mods.
    Fabric API: A set of APIs and tools for mod developers to use when creating mods.
    Yarn: A set of open Minecraft mappings, free for everyone to use under the Creative Commons Zero license.

Why is Fabric necessary to mod Minecraft?

    Modding is the process of modifying a game in order to change its behavior or add new features - in the case of Minecraft, this can be anything from adding new items, blocks, or entities, to changing the game's mechanics or adding new game modes.

Minecraft: Java Edition is obfuscated by Mojang, making modification alone difficult. However, with the help of modding tools like Fabric, modding becomes much easier. There are several mapping systems that can assist in this process.

Loom remaps the obfuscated code to a human-readable format using these mappings, making it easier for modders to understand and modify the game's code. Yarn is a popular and excellent mappings choice for this, but other options exist as well. Each mapping project may have its own strengths or focus.

Loom allows you to easily develop and compile mods against remapped code, and Fabric Loader allows you to load these mods into the game.
What does Fabric API provide, and why is it needed?

    Fabric API is a set of APIs and tools for mod developers to use when creating mods.

Fabric API provides a wide set of APIs that build on top of Minecraft's existing functionality - for example, providing new hooks and events for modders to use, or providing new utilities and tools to make modding easier - such as transitive access wideners and the ability to access internal registries, such as the compostable items registry.

While Fabric API offers powerful features, some tasks, like basic block registration, can be accomplished without it using the vanilla APIs.

Setting up a Development Environment

To start developing mods with Fabric, you will need to set up a development environment using IntelliJ IDEA.
Installing JDK 17

To develop mods for Minecraft 1.20.4, you will need JDK 17.

If you need help installing Java, you can refer to the various Java installation guides in the player guides section.
Installing IntelliJ IDEA

INFO

You can obviously use other IDEs, such as Eclipse or Visual Studio Code, but the majority of the pages on this documentation site will assume that you are using IntelliJ IDEA - you should refer to the documentation for your IDE if you are using a different one.

If you do not have IntelliJ IDEA installed, you can download it from the official website - follow the installation steps for your operating system.

The Community edition of IntelliJ IDEA is free and open-source, and it is the recommended version for modding with Fabric.

You may have to scroll down to find the Community edition download link - it looks like the following:

IDEA Community Edition Download Prompt
Installing IDEA Plugins

Although these plugins aren't strictly necessary, they can make modding with Fabric much easier - you should consider installing them.
Minecraft Development

The Minecraft Development plugin provides support for modding with Fabric, and it is the most important plugin to install.

You can install it by opening IntelliJ IDEA, and then navigating to File > Settings > Plugins > Marketplace Tab - search for Minecraft Development in the search bar, and then click the Install button.

Alternatively, you can download it from the plugin page and then install it by navigating to File > Settings > Plugins > Install Plugin From Disk.

Creating a Project

Fabric provides an easy way to create a new mod project using the Fabric Template Mod Generator - if you want, you can manually create a new project using the example mod repository, you should refer to the Manual Project Creation section.
Generating a Project

You can use the Fabric Template Mod Generator to generate a new project for your mod - you should fill in the required fields, such as the package name and mod name, and the Minecraft version that you want to develop for.

Preview of the generator.

If you want to use Kotlin, or want to add data generators, you can select the appropriate options in the Advanced Options section.

Advanced options section.

Once you've filled in the required fields, click the Generate button, and the generator will create a new project for you to use in the form of a zip file.

You should extract this zip file to a location of your choice, and then open the extracted folder in IntelliJ IDEA:

Open Project Prompt
Importing the Project

Once you've opened the project in IntelliJ IDEA, the IDE should automatically load the project's Gradle configuration and perform the necessary setup tasks.

If you receive a notification talking about a Gradle build script, you should click the Import Gradle Project button:

Gradle Prompt

Once the project has been imported, you should see the project's files in the project explorer, and you should be able to start developing your mod.
Manual Project Creation

WARNING

You will need Git installed in order to clone the example mod repository.

If you cannot use the Fabric Template Mod Generator, you can create a new project manually by following these steps.

Firstly, clone the example mod repository using Git:
bash

git clone https://github.com/FabricMC/fabric-example-mod/ my-mod-project

This will clone the repository into a new folder called my-mod-project.

You should then delete the .git folder from the cloned repository, and then open the project in IntelliJ IDEA. If the .git folder does not appear, you should enable the display of hidden files in your file manager.

Once you've opened the project in IntelliJ IDEA, it should automatically load the project's Gradle configuration and perform the necessary setup tasks.

Again, as previously mentioned, if you receive a notification talking about a Gradle build script, you should click the Import Gradle Project button.
Modifying the Template

Once the project has been imported, you should modify the project's details to match your mod's details:

    Modify the project's gradle.properties file to change the maven_group and archive_base_name properties to match your mod's details.
    Modify the fabric.mod.json file to change the id, name, and description properties to match your mod's details.
    Make sure to update the versions of Minecraft, the mappings, the Loader and the Loom - all of which can be queried through https://fabricmc.net/develop/ - to match the versions you wish to target.

You can obviously change the package name and the mod's main class to match your mod's details.

Project Structure

This page will go over the structure of a Fabric mod project, and the purpose of each file and folder in the project.
fabric.mod.json

The fabric.mod.json file is the main file that describes your mod to Fabric Loader. It contains information such as the mod's ID, version, and dependencies.

The most important fields in the fabric.mod.json file are:

    id: The mod's ID, which should be unique.
    name: The mod's name.
    environment: The environment that your mod runs in, such as client, server, or * for both.
    entrypoints: The entrypoints that your mod provides, such as main or client.
    depends: The mods that your mod depends on.
    mixins: The mixins that your mod provides.

You can see an example fabric.mod.json file below - this is the fabric.mod.json file for the reference project that powers this documentation site.

Reference Project

{
	"schemaVersion": 1,
	"id": "fabric-docs-reference",
	"version": "1.0.0",
	"name": "Fabric docs reference",
	"icon": "assets/fabric-docs-reference/icon.png",
	"environment": "*",
	"entrypoints": {
		"main": [
			"com.example.docs.FabricDocsReference",
			"com.example.docs.event.FabricDocsReferenceEvents",
			"com.example.docs.command.FabricDocsReferenceCommands",
			"com.example.docs.effect.FabricDocsReferenceEffects",
			"com.example.docs.potion.FabricDocsReferencePotions",
			"com.example.docs.sound.FabricDocsReferenceSounds",
			"com.example.docs.damage.FabricDocsReferenceDamageTypes"
		],
		"client": [
			"com.example.docs.FabricDocsReferenceClient",
			"com.example.docs.rendering.RenderingConceptsEntrypoint",
			"com.example.docs.rendering.HudRenderingEntrypoint",
			"com.example.docs.client.command.FabricDocsReferenceClientCommands"
		],
		"fabric-datagen": [
			"com.example.docs.FabricDocsReferenceDataGenerator",
			"com.example.docs.damage.FabricDocsReferenceDamageTypesDataGenerator"
		]
	},
	"mixins": [
		"fabric-docs-reference.mixins.json",
		{
			"config": "fabric-docs-reference.client.mixins.json",
			"environment": "client"
		}
	],
	"depends": {
		"fabricloader": ">=0.15.3",
		"minecraft": "~1.20.4",
		"java": ">=17",
		"fabric-api": "*"
	}
}

Entrypoints

As mentioned before, the fabric.mod.json file contains a field called entrypoints - this field is used to specify the entrypoints that your mod provides.

The template mod generator creates both a main and client entrypoint by default - the main entrypoint is used for common code, and the client entrypoint is used for client-specific code. These entrypoints are called respectively when the game starts.
java

public class FabricDocsReference implements ModInitializer {
	// This logger is used to write text to the console and the log file.
	// It is considered best practice to use your mod id as the logger's name.
	// That way, it's clear which mod wrote info, warnings, and errors.
	public static final String MOD_ID = "fabric-docs-reference";
	public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);

	@Override
	public void onInitialize() {
		// This code runs as soon as Minecraft is in a mod-load-ready state.
		// However, some things (like resources) may still be uninitialized.
		// Proceed with mild caution.

		LOGGER.info("Hello Fabric world!");
	}
}

The above is an example of a simple main entrypoint that logs a message to the console when the game starts.
src/main/resources

The src/main/resources folder is used to store the resources that your mod uses, such as textures, models, and sounds.

It's also the location of fabric.mod.json and any mixin configuration files that your mod uses.

Assets are stored in a structure that mirrors the structure of resource packs - for example, a texture for a block would be stored in assets/modid/textures/block/block.png.
src/client/resources

The src/client/resources folder is used to store client-specific resources, such as textures, models, and sounds that are only used on the client side.
src/main/java

The src/main/java folder is used to store the Java source code for your mod - it exists on both the client and server environments.
src/client/java
The src/client/java folder is used to store client-specific Java source code, such as rendering code or client-side logic - such as block color providers.

Launching the Game

Fabric Loom provides a variety of launch profiles to help you start and debug your mods in a live game environment. This guide will cover the various launch profiles and how to use them to debug and playtest your mods.
Launch Profiles

If you're using IntelliJ IDEA, you can find the launch profiles in the top-right corner of the window. Click the dropdown menu to see the available launch profiles.

There should be a client and server profile, with the option to either run it normally or in debug mode:

Launch Profiles
Gradle Tasks

If you're using the command line, you can use the following Gradle commands to start the game:

    ./gradlew runClient - Start the game in client mode.
    ./gradlew runServer - Start the game in server mode.

The only problem with this approach is that you can't easily debug your code. If you want to debug your code, you'll need to use the launch profiles in IntelliJ IDEA or via your IDE's Gradle integration.
Hotswapping Classes

When you run the game in debug mode, you can hotswap your classes without restarting the game. This is useful for quickly testing changes to your code.

You're still quite limited though:

    You can't add or remove methods
    You can't change method parameters
    You can't add or remove fields

Hotswapping Mixins

If you're using Mixins, you can hotswap your Mixin classes without restarting the game. This is useful for quickly testing changes to your Mixins.

You will need to install the Mixin Java agent for this to work though.
1. Locate the Mixin Library Jar

In IntelliJ IDEA, you can find the mixin library jar in the "External Libraries" section of the "Project" section:

Mixin Library

You will need to copy the jar's "Absolute Path" for the next step.
2. Add the -javaagent VM Argument

In your "Minecraft Client" and or "Minecraft Server" run configuration, add the following to the VM Arguments option:

-javaagent:"path to mixin library jar here"

VM Arguments Screenshot

Now, you should be able to modify the contents of your mixin methods during debugging and have the changes take effect without restarting the game.