How benhengeveld/nbt-recipes works
Based on our analysis of the file tree and README, the project is a Minecraft mod named “NBT Recipes” designed to extend the standard JSON recipe system. Its purpose is to allow modders to add detailed NBT (Named Binary Tag) data to recipe outputs and to support additional features (like setting counts for smelting, stonecutting, and smithing recipes). The mod leverages mixin injections to modify behavior in the vanilla Minecraft code, and it is organized into distinct client and core (or “main”) components.
Main Components
• Core Mod Component (located in src/main):
• Contains the core classes NbtRecipes.java and NbtRecipesDataGenerator.java.
• Includes mixin modifications that target vanilla functionality in crafting, smelting, stonecutting, and smithing. For example, classes like MixinItemStack, MixinShapedRecipe, MixinAbstractFurnaceBlockEntity, etc.
• Holds the Fabric mod configuration (fabric.mod.json) and mixin configuration (nbt-recipes.mixins.json).
• Client Component (located in src/client):
• Contains client-specific modifications in NbtRecipesClient.java.
• Includes its own set of mixins (e.g., ExampleClientMixin.java) and corresponding mixin configuration (nbt-recipes.client.mixins.json in resources).
• Build and Configuration Infrastructure:
• Gradle build scripts (build.gradle, gradlew, gradlew.bat, settings.gradle) for compiling and building the mod.
• GitHub workflows (.github/workflows/build.yml) for CI/CD.
• Other configuration files (gradle.properties, .gitignore, LICENSE).
Relationships and Interactions
• The mod hooks into the Minecraft runtime via Fabric’s mod loader. The Fabric environment calls the mod’s entry points (e.g., NbtRecipes.java).
• When Minecraft loads its recipes, the mixins (applied to classes like ItemStack or various recipe serializers) intercept recipe parsing logic to allow additional NBT data and custom count values. Some mixins are in the main package while others are client-specific.
• There is a clear separation:
• The core component handles the backend mod logic and data generation.
• The client component deals with any client-rendered modifications or display specifics.
• The build and configuration infrastructure integrates with CI/CD tools and Gradle to manage dependencies and deployments.
Architectural Patterns and Design Principles
• Use of Mixin:
• A common pattern in Minecraft modding that allows the mod to modify or extend the behavior of existing classes without direct source modification.
• Separation of Concerns:
• The project clearly divides client-side versus core functionality.
• Data generation for recipes (NbtRecipesDataGenerator) is separated from the recipe logic.
• Extendable JSON-based Recipe System:
• It follows the design principle of modifying existing JSON definitions (crafting, smelting, etc.) to incorporate additional data.
Specific Elements
• Clear labels for each modular component (Core, Client, Mixins, Build/Config).
• Initialization flow from the Fabric Mod Loader → NbtRecipes.java.
• Data flow from JSON definitions to processed recipes.
• Dependency/injection lines from mixin classes to the vanilla Minecraft classes they modify.
• For example, use rectangles for core modules, rounded rectangles for mixins, and ellipses for external systems like the Minecraft runtime.
• Annotations that note where configuration files (like fabric.mod.json and mixins JSON files) fit into the overall setup.