Skip to content

Conversation

sylvxa
Copy link

@sylvxa sylvxa commented Jun 12, 2025

there's no vanilla method for generating a Smithing Table recipe that modifies the components of an item, so this PR adds an interface onto the class that adds this functionality

* limitations under the License.
*/

package net.fabricmc.fabric.impl.datagen.smithing;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pretty sure this should be an api class, as otherwise, all the methods added are implementation methods

* limitations under the License.
*/

package net.fabricmc.fabric.impl.datagen.smithing;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same for this

import net.minecraft.recipe.Ingredient;
import net.minecraft.recipe.book.RecipeCategory;

public interface SmithingTransformRecipeCreator {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in fabric api, we typically forgo the practice of naming injected interfaces after their purpose. usually it's something like FabricXX to allow the injected interface to remain once the functionality changes. I would guess this should be named FabricRecipeGenerator

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you; i moved the interfaces to the api package and renamed them to match conventions


import net.minecraft.component.ComponentChanges;

public interface SmithingTransformParameters {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably should be FabricSmithingTransformRecipeJsonBuilder


@Shadow
public static String getItemPath(ItemConvertible item) {
return null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: usually the convention is for these to throw?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i forgot to clear out the Shadows after switching my implementation from an offerRecipe-type method to a createRecipe one, sorry

Copy link
Contributor

@cputnam-a11y cputnam-a11y left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🎉

import net.minecraft.recipe.Ingredient;
import net.minecraft.recipe.book.RecipeCategory;

public interface FabricRecipeGenerator {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could use a short doc comment (the methods in this itf don't really need it since they're duplicates of the vanilla ones)


import net.minecraft.component.ComponentChanges;

public interface FabricSmithingTransformRecipeJsonBuilder {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

import net.fabricmc.fabric.api.datagen.v1.smithing.FabricRecipeGenerator;

@Mixin(RecipeGenerator.class)
public abstract class RecipeGeneratorMixin implements FabricRecipeGenerator {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public abstract class RecipeGeneratorMixin implements FabricRecipeGenerator {
abstract class RecipeGeneratorMixin implements FabricRecipeGenerator {

import net.fabricmc.fabric.api.datagen.v1.smithing.FabricSmithingTransformRecipeJsonBuilder;

@Mixin(SmithingTransformRecipeJsonBuilder.class)
public class SmithingTransformRecipeJsonBuilderMixin implements FabricSmithingTransformRecipeJsonBuilder {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public class SmithingTransformRecipeJsonBuilderMixin implements FabricSmithingTransformRecipeJsonBuilder {
class SmithingTransformRecipeJsonBuilderMixin implements FabricSmithingTransformRecipeJsonBuilder {

import net.minecraft.recipe.book.RecipeCategory;

public interface FabricRecipeGenerator {
default SmithingTransformRecipeJsonBuilder createSmithingTransformRecipe(Ingredient template, Ingredient input, Ingredient addition, RecipeCategory category, Item result, int count, @Nullable ComponentChanges componentChanges) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it'd be better to just have one method with an ItemStack result parameter instead of all the overloads 🤔

This is probably fine too, but a bit messy with the long param lists.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

implemented; i still kept some overloads for ingredient/item but switched to itemstack for the result (aside from the base method, since its probably better to leave specifying them individually as an option)

"has_the_recipe": {
"trigger": "minecraft:recipe_unlocked",
"conditions": {
"recipe": "minecraft:stick_smithing"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: the recipe key uses the wrong namespace since it ends up being wrong in here as well (use the RegistryKey<Recipe> overload instead of the String overload of offerTo).

I think the string overload should be fixed on FAPI level to give the correct ns, but it's out of scope for this PR and quite possibly annoying to implement with mixins 😄

@cputnam-a11y cputnam-a11y requested a review from Juuxel July 30, 2025 02:21
@cputnam-a11y
Copy link
Contributor

seems like this is read for review again :)

@cputnam-a11y cputnam-a11y added enhancement New feature or request small change labels Jul 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request small change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants