NeoForge Documentation
website·Indexed 34 days ago
https://docs.neoforged.net/Developer documentation for the NeoForge modding framework for Minecraft, covering versions 1.21.4 and 1.21.5. Includes guides on networking with Stream Codecs, resource management for models and particles, item and block implementation, data components, registries, and the SavedData system.
What's inside NeoForge
- Capabilities allow blocks, entities, and item stacks to expose features via interfaces without requiring direct implementation of many classes. This separates what an object can do from how it does it. Use capabilities when a behavior is only available for some objects and the implementation depends on the specific object type.
Overview of NeoForge Capabilities
Capabilities allow blocks, entities, and item stacks to expose features (interfaces) in a dynamic way. They separate what an object can do from how it does it, enabling cross-mod compatibility without requiring objects to implement numerous interfaces directly. Use capabilities when a behavior is only available for some objects and the implementation depends on the specific object type.Overview of BakedModel in NeoForge
BakedModelis the in-code representation of a shape with textures. Model JSONs are deserialized intoUnbakedModeland then resolved into aBakedModelviaUnbakedModel#bake. These models are stored in theModelManager, accessible viaMinecraft.getInstance().modelManager. To retrieve a specific model, useModelManager#getModelwith aModelResourceLocation.Overview of Stream Codecs
Stream codecs are serialization tools used to describe how an object should be stored in and read from a stream, such as a buffer. They are primarily used by Vanilla's networking system to synchronize data. AStreamCodecusesencodeto write an object to a stream anddecodeto read an object back from a stream. The stream is typically aByteBuf,FriendlyByteBuf, orRegistryFriendlyByteBuf.// Let exampleStreamCodec represent a StreamCodec<ExampleJavaObject> // Let exampleObject be a ExampleJavaObject // Let buffer be a RegistryFriendlyByteBuf // Encode Java object into the buffer stream exampleStreamCodec.encode(buffer, exampleObject); // Read Java object from buffer stream ExampleJavaObject obj = exampleStreamCodec.decode(buffer);Overview of the Value I/O system
The Value I/O system is a standardized serialization method used to manipulate data in a backing object (such as NBT CompoundTags). It consists of two primary components:ValueOutputfor writing data during serialization andValueInputfor reading data during deserialization. The system expects the backing object to be a dictionary of string keys mapped to object values.// Example for BlockEntity @Override protected void saveAdditional(ValueOutput output) { super.saveAdditional(output); // Write data using output } @Override protected void loadAdditional(ValueInput input) { super.loadAdditional(input); // Read data using input } // Example for Entity @Override protected void addAdditionalSaveData(ValueOutput output) { super.addAdditionalSaveData(output); } @Override protected void readAdditionalSaveData(ValueInput input) { super.readAdditionalSaveData(input); }Overview of Loot Tables
Loot tables are JSON data files used to define randomized loot drops. When rolled, they return a list of item stacks based on pseudo-randomness. Loot tables are stored at
data/<mod_id>/loot_table/<name>.json.Common associations include:
- Blocks: Default location is
<block_namespace>:blocks/<block_name>. Use#noLootTableon blockPropertiesto disable drops. - Entities: Default location is
<entity_namespace>:entities/<entity_name>. This can be overridden by overriding#getLootTable(e.g., for color-coded sheep wool). - Chests: Specified in block entity data, typically located in
minecraft:chests/<chest_name>. - Fishing/Other: Retrieved via
level.getServer().reloadableRegistries().getLootTable(lootTableKey).
Note: To modify existing loot tables rather than creating new ones, use Global Loot Modifiers (GLMs).
- Blocks: Default location is
Overview of Blockstates in NeoForged
Blockstates allow a single block to have multiple visual or functional variations (e.g., growth stages of a crop or the facing direction of a slab) without requiring separate block classes. Blockstates are represented as a combination of properties. For example, a block with a
facingproperty (4 options) and aneyeproperty (2 options) results in 8 unique blockstates.Key technical details:
BlockStateis a final class and cannot be extended.- Every unique
BlockStateexists exactly once in memory; therefore, they should be compared using==. - All logic for blockstate behavior must be implemented in the corresponding
Blockclass.
Overview of NeoForge Capabilities
Capabilities in NeoForge allow blocks, entities, and item stacks to expose specific features (interfaces) in a dynamic way. This decouples what an object can do from how it implements that behavior. Use capabilities when a behavior is only available for some objects and the implementation varies by object type. For example, use capabilities for fluid/item containers or energy storage, but use helper methods for simple checks like distance/range.Overview of Living Entity Attributes in NeoForge 1.21.4
Attributes are double-value fields associated with living entities that define core properties such as maximum health, movement speed, and armor. These values are automatically synchronized between the server and client. While many default attributes are provided by Minecraft, developers can also implement custom attributes. Note that some attributes are entity-specific due to legacy implementation; for example, jump strength affects horses but not players, and flying speed is ignored by ghasts.Overview of Loot Tables in NeoForge 1.21.1
Loot tables are JSON data files used to define randomized item drops. They are located at
data/<mod_id>/loot_table/<name>.json. Loot tables are used for block drops, entity drops, chest loot, and fishing.Default behaviors include:
- Blocks: Default loot table at
<block_namespace>:blocks/<block_name>. Use#noLootTableon block Properties to disable drops. - LivingEntities: Default loot table at
<entity_namespace>:entities/<entity_name>. This can be overridden via#getLootTable(LivingEntity) or#getDefaultLootTable(Mob). - Chests: Specified in block entity data, typically following the
minecraft:chests/<chest_name>pattern. - General Retrieval: Use
level.getServer().reloadableRegistries().getLootTable(lootTableId)to retrieve tables manually.
Note: To modify existing loot tables rather than creating new ones, use Global Loot Modifiers (GLMs).
- Blocks: Default loot table at
Overview of Global Loot Modifiers (GLMs)
Global Loot Modifiers (GLMs) provide a data-driven way to modify loot drops. Unlike standard loot tables, GLMs are stacking (not 'last-load-wins'), allowing multiple mods to modify the same loot table. They operate by rolling the associated loot table first and then applying the GLM to the result. To implement a GLM, you need: 1) A registration file in the neoforge namespace, 2) A JSON definition for the modifier, 3) A Java class implementingIGlobalLootModifieror extendingLootModifier, and 4) A MapCodec for serialization.Overview of Data Components in Minecraft 1.20.5+
Data components are key-value pairs stored on anItemStack. UnlikeCompoundTagorJsonElement, components are stored as actual objects, making them directly operable without dynamic transformation. Each component is associated with aDataComponentType<T>, whereTis the value type. These types act as keys and contain the codecs necessary for disk persistence and network synchronization.