Use this skill to implement or review Minecraft mods targeting NeoForge. Prefer project-local versions, mappings, Gradle plugins, and existing conventions over generic examples. When behavior depends on a specific Minecraft or NeoForge version, verify against the matching page on https://docs.neoforged.net/ before coding.
First Checks
- Confirm the Minecraft and NeoForge versions from
gradle.properties,build.gradle,settings.gradle, or generated MDK files. - Confirm the mod id, package, and Java version: 1.20.1 uses Java 17, 1.21.x Java 21, and 26.1 Java 25. Do not infer loader or version from a directory named
forge. - Read version contracts and inspected projects before copying current-doc APIs into 1.21.1. Resolve actual source roots, metadata expansion, and node-qualified tasks through settings/build/convention plugins.
- Prefer the generated Gradle workflow:
./gradlew build,./gradlew runClient,./gradlew runServer, and datagen runs configured by the project. - Reload Gradle after changing Gradle files; avoid editing
build.gradle/settings.gradlewhengradle.propertiesis sufficient. - Always test server safety for common code, even for client-focused mods.
Project Structure
- Keep common code free of
net.minecraft.clientimports. - Put client-only setup behind physical-client gates: a client-only event subscriber, or a separate
@Mod(value = MOD_ID, dist = Dist.CLIENT)class where the target FML supports it. Older targets need their matching subscriber annotation/bus syntax. - Use
src/main/javafor code,src/main/resources/assets/<modid>for client assets, andsrc/main/resources/data/<modid>for gameplay data. - Use generated resources under
src/generated/resourceswhen the Gradle project is configured for datagen. - Keep registration classes small and grouped by registry type, e.g.
ModItems,ModBlocks,ModCreativeTabs.
Registration
- Prefer
DeferredRegisterover rawRegisterEventunless the project needs low-level control. - Create one deferred register per registry and attach it to the mod event bus in the mod constructor.
- Store registered objects as
Supplier<T>,DeferredHolder<R, T>,DeferredItem<T>, orDeferredBlock<T>according to the API expected by surrounding code. - Do not instantiate registry objects outside registration; blocks, items, entities, tabs, data components, and similar entries must be singleton registry entries.
- Use the mod id namespace for every custom
Identifier/resource location and keep registry names lowercase snake_case.
Official 1.21.1 item-helper shape (also prefer ID-supplying helpers on later targets):
public static final DeferredRegister.Items ITEMS = DeferredRegister.createItems(MOD_ID);
public static final Supplier<Item> EXAMPLE_ITEM = ITEMS.registerSimpleItem("example_item");
public ExampleMod(IEventBus modBus) {
ModItems.ITEMS.register(modBus);
}
Items And Blocks
- From 1.21.2, item/block properties require IDs; use loader helpers that supply them, or set them explicitly before construction. Do not copy
Item.Properties#setIdinto 1.21.1, where it does not exist. Configure supported behavior through properties/components. - Treat
ItemStackas mutable; callcopy()orcopyWithCount()before mutating stacks that may be shared or treated as immutable. - For blocks, use
DeferredRegister.createBlocks(MOD_ID); on ID-requiring targets use a helper that supplies the key orBlockBehaviour.Properties#setIdbefore construction. - Register a matching
BlockItemif a block must appear in inventories or be placeable by players. - Add items to existing creative tabs with
BuildCreativeModeTabContentsEvent; register customCreativeModeTabentries through a deferred register. - Put models, blockstates, item models, lang entries, recipes, tags, and loot tables in assets/data or datagen providers instead of hardcoding them.
Events
- Register game events on
NeoForge.EVENT_BUS; register mod lifecycle/registry/setup/datagen/network payload events on the mod event bus. - Event handlers must be
voidmethods with a single event parameter. - Use
IEventBus#addListener,@SubscribeEvent, or@EventBusSubscriber(modid = MOD_ID)consistently with the project style. - Do not subscribe to abstract event classes such as base
LivingEvent,PlayerEvent, orBlockEvent; subscribe to concrete subevents. - For cancellable events, use
setCanceledonly when cancellation is documented for that event; for tri-state/result events, prefer the event’s explicit result setter. - For parallel lifecycle events, use
event.enqueueWork(...)when work must run on the main thread.
Sides
- Use
level.isClientSide()for logical-side game logic decisions; run authoritative gameplay logic only when it isfalse. - Use the target FML physical-side API (
FMLEnvironment.diston 1.21.1; newer versions may exposegetDist()) and gated client classes. Neither a logical-side branch nor an ungated common static reference is safe isolation. - Never assume singleplayer means server-only code can touch client classes; singleplayer has both a logical client and logical server inside a physical client.
- Transfer state between logical sides with networking payloads, not static fields.
- Run
runServeror a dedicated-server test path to catchNoClassDefFoundErrorfrom client-only imports.
Networking
- Register custom payloads during
RegisterPayloadHandlersEventon the mod event bus usingevent.registrar("<protocol-version>"). - Implement payloads as
CustomPacketPayloadrecords/classes with a uniqueTypeand aStreamCodec. - Choose
playToServer,playToClient, orplayBidirectionalaccording to direction. On 1.21.1 handlers are supplied to the registrar (bidirectional handlers can useDirectionalPayloadHandler); current 26.1 usesRegisterClientPayloadHandlersEventfor client handlers. Keep their implementation physically client-only in either case. - Keep gameplay handlers on the main thread by default.
HandlerThread.NETWORKchanges execution context; it is not an unbounded worker pool. Bound parsing/work, never block network I/O with expensive computation, and useIPayloadContext#enqueueWorkfor game state with exception handling. - Validate serverbound permissions, distances, counts, identifiers, and loaded-chunk/entity existence; do not load arbitrary chunks on client request.
- On 1.21.1 use
PacketDistributor.sendToServer; on current 26.1 useClientPacketDistributor.sendToServerin client-only code. Server-to-client sends usePacketDistributorhelpers. - Respect payload size limits: clientbound payloads are at most 1 MiB, serverbound payloads are less than 32 KiB.
Resources And Datagen
- Put client resources under
assets/<modid>and server data underdata/<modid>. - Remember NeoForge generates built-in resource/data packs for mods and modern NeoForge handles
pack.mcmetaat runtime. - Use vanilla and NeoForge external resources in the IDE as the source of truth for JSON formats.
- Prefer datagen for repetitive or fragile JSON: models, blockstates, lang, tags, recipes, loot tables, sounds, particles, data maps, and datapack registries.
- On 1.21.1 register providers from
GatherDataEventwith the appropriate include flags. Later versions split gathering intoGatherDataEvent.Client/Server; inspect the exact target provider helpers and configured runs rather than backporting current examples. - Use
RegistrySetBuilderandBootstrapContextfor datapack registry entries that need generated JSON.
Validation Checklist
- Run the narrowest relevant Gradle task first, then
./gradlew buildif practical. - Run client and dedicated-server paths when touching sides, events, networking, rendering, or resources.
- Verify generated JSON is included in the resource output and checked for namespace/path correctness.
- Check logs for missing models, missing translations, registry freeze errors, packet version mismatches, and client-only class loading on server.
- When unsure about an API, inspect existing project usage and the matching NeoForge docs version before inventing patterns.
Official References
- Main docs:
https://docs.neoforged.net/ - Getting started:
https://docs.neoforged.net/docs/gettingstarted/ - Registries:
https://docs.neoforged.net/docs/concepts/registries/ - Events:
https://docs.neoforged.net/docs/concepts/events/ - Sides:
https://docs.neoforged.net/docs/concepts/sides/ - Items:
https://docs.neoforged.net/docs/items/ - Blocks:
https://docs.neoforged.net/docs/blocks/ - Resources and datagen:
https://docs.neoforged.net/docs/resources/ - Networking payloads:
https://docs.neoforged.net/docs/networking/payload/