Wiki 9Minecraft Fabric API Wiki
Fabric API Wiki › Guide

Fabric API — Guide

Mechanics and Hooks

Fabric API introduces several advanced mechanics that replace or supplement traditional modding techniques like Mixins.

Event System

Events are the primary way mods react to game actions. Instead of overwriting Minecraft's code, mods "listen" for specific events.

  • Interaction Events: Triggered when a player right-clicks a block, attacks an entity, or uses an item.
  • Entity Events: Triggered when an entity is spawned, killed, or changes its equipment.
  • Tick Events: Fired every game tick (1/20th of a second), allowing mods to run logic continuously on the client or server.

Networking and Packets

To ensure synchronization in multiplayer, Fabric API provides a robust Networking API. This allows mods to send "Payloads" (custom data) across the network. For example, if a mod adds a mana bar, the server uses this API to tell the client exactly how much mana the player has so the GUI can update correctly.

Rendering and Indigo

Fabric API includes a specialized rendering engine called Indigo. Indigo is the default implementation of the Fabric Rendering API and is designed to be compatible with modern graphics features while remaining highly performant.

  • Enhanced Models: Allows for complex block models that go beyond the standard 16x16 cube.
  • Dynamic Textures: Supports textures that change based on game conditions without requiring complex custom code.
  • Compatibility: Indigo is built to work alongside optimization mods like Sodium, ensuring that players can have both high performance and visual variety.

Core Architecture

The API is designed with a modular philosophy. This allows developers to include only the parts of the API they need, keeping the game's memory footprint small and making updates more efficient.

Modular Components

Fabric API is divided into several key modules. In version 1.20.1, these include:

Module Name Primary Function
fabric-api-base The foundation for all other API modules.
fabric-registry-sync-v0 Ensures that block and item IDs match between the server and the client.
fabric-lifecycle-events-v1 Provides hooks for when the server starts, stops, or when a world is loaded.
fabric-networking-api-v1 Handles the transmission of custom data packets between the client and server.
fabric-resource-loader-v1 Allows mods to inject custom textures, models, and data packs into the game.
fabric-rendering-v1 Provides advanced rendering hooks for custom block models and entity layers.

Items and Blocks Registry

While Fabric API adds no items or blocks of its own, it provides the Object Builder API and Item API which are the standard tools for all other mods.

Registration Process

Mods use the API to register their content into Minecraft's internal registries. This process includes: * Custom Item Groups: Creating new tabs in the Creative Inventory. * Fuel and Compost Registries: Defining how long a modded item burns in a furnace or how much it fills a composter. * Mining Levels: Defining which tools (wood, stone, iron, etc.) are required to break modded blocks.

Data Generation

The Data Generation API is a powerful tool included in Fabric API that allows modders to automatically generate the hundreds of JSON files required for modern Minecraft mods, such as block states, item models, and recipes, ensuring they are always formatted correctly for version 1.20.1.

World and Biome API

The Biome API and Dimension API allow mods to safely modify the world generation process.

  • Biome Modification: Mods can use this to add new features (like trees or ores) to existing vanilla biomes without overwriting the biome file itself.
  • Custom Dimensions: Provides the hooks necessary to create entirely new worlds with their own sky colors, weather patterns, and gravity settings.
  • Loot Table Manipulation: The Loot API allows mods to inject new items into vanilla chests (like dungeon or village chests) dynamically.