Skip to content

Instantly share code, notes, and snippets.

@alcatrazEscapee
Last active May 20, 2019 14:34
Show Gist options
  • Save alcatrazEscapee/c078386d7a41ddb48d0010b25fdec109 to your computer and use it in GitHub Desktop.
Save alcatrazEscapee/c078386d7a41ddb48d0010b25fdec109 to your computer and use it in GitHub Desktop.

TFC Recipes Code Style

Outline

The purpose of this document is to specify how developers and contributors should build recipes into TFC-TNG. As we are developing for 1.12 while preparing to update to 1.13/14, we are trying to design systems that will require minimal changes during the update. In addition, one of the goals of TFC-TNG is to increase compatibility with other mods, and specifically allow pack makers to modify recipes without requiring an addon mod. Finally, it is beneficial to have all recipe systems in TFC use a similar system, as it makes them easier to maintain and understand independent of the original author.

Future Plans

Minecraft 1.13 adds Datapacks and along with forge, a fancy RecipeType / IRecipeSerializer system. This system will allow all TFC recipes to move to json based recipes, which are handled completely by vanilla resource managers. This will allow users to add new recipes, override old recipes, and remove recipes all by specifying them via json.

Under this system, TFC will not provide any hooks for craft tweaker, mine tweaker, or other tools to modify recipes, as it will just complicate the process of managing TFC-specific recipes. Both addon mods and pack makers will be able to use the data pack system.

TFC-TNG 1.12 Recipes

With that in mind, here is the current plan for TFC-TNG 1.12 Recipe implementations:

  • Each recipe should create a recipe class, suffixed with Recipe. Example, AnvilRecipe, or PitKilnRecipe
  • The recipe class should extend IForgeRegistryEntry.Impl<TRecipe>
  • Recipes are collectively stored into an IForgeRegistry<TRecipe>
  • Recipes are registered by TFC in DefaultRecipes, by subscribing to the respective registry event.
  • Recipes are queried using TFCRegistries.RECIPE.getValuesCollection/.getValue, or by specific helper methods in the recipe class (i.e. one that matches against an inventory and returns the first matching recipe)
  • Recipes that match ItemStacks should try and use TFC's IIngredient<ItemStack> when possible, as it allows matching both standard item stacks, and also ore dictionary entries. It is also a bit more attuned to non-crafting recipes than vanilla's Inredient

In order to add a new recipe, the developer needs to:

  • Create the respective recipe class
  • Add a recipe registry name to TFCRegistryNames
  • Add a newRegistry call to Registries
  • Add a new IForgeRegistry<RecipeClass> field to TFCRegistries

Most of TFC's recipes already follow this system to some extent. Any recipes that don't that do not have a good reason for noncompliance, should.

Compatibility Hooks

If the development of TFC-TNG in 1.12 reaches a stage where it makes sense to add craft tweaker hooks for recipes, this can be accomplished within TFC as an optional/soft dependency, using CraftTweaker's plugin API. The rough outline for the craft tweaker methods provided would be:

  • addRecipe(ResourceLocation, [Recipe Specific Data...]): Adds a recipe to the respective forge registry.
  • removeRecipe(ResourceLocation): Removes a recipe by resource location
  • (Optional depending on the recipe) removeRecipe([Recipe Specific Data...]): Removes a recipe by resource location

Note: this will require some additional casting / checking involving the register and remove calls to the forge registry. This should not cause any significant problems.

Additionally, recipes that depend on capabilities (i.e. welding or anvil) require more craft tweaker hooks to add the respective items to a registry of "register these capabilities when this item stack is created" in AttachCapabilitiesEvent

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment