在1.21.4中创建ModRecipesProvider类的相同与区别 V2.0
PS.修改了上个笔记不对的地方
1.仍然要extends FabricRecipeProvider
2.FabricRecipeProvider要求的实现方法和super函数不一样
3.generate()方法改在了getRecipeGenerator()方法的return中实现
4.各种配方的生成函数的形参列表发生改变
5.ShapedRecipeJsonBuilder.create()方法形参列表变化较大(我没研究明白),所以换成createShaped()方法
上述方法的.offerTo()方法第二个参数变为RegistryKey<>类型,所以Identifier.of()如下面这样嵌套,Identifier.of()中填写的参数和视频一致
Example Identifier:
RegistryKey.of(RegistryKeys.RECIPE, getRecipeIdentifier( Identifier_HERE );
这里代码的合成物品以镓矿系列为例子
Example All:
public class ModRecipesProvider extends FabricRecipeProvider
{
private static final List<ItemConvertible> GA_FURNACE = List.of(ModItems.example_item);
public ModRecipesProvider(FabricDataOutput output, CompletableFuture<RegistryWrapper.WrapperLookup> registriesFuture)
{
super(output, registriesFuture);
}
@Override
protected RecipeGenerator getRecipeGenerator(RegistryWrapper.WrapperLookup wrapperLookup, RecipeExporter recipeExporter)
{
return new RecipeGenerator(wrapperLookup, recipeExporter)
{
public void generate()
{
//可逆配方
offerReversibleCompactingRecipes(RecipeCategory.MISC, ModItems.INGOT_GA, RecipeCategory.BUILDING_BLOCKS, ModBlocks.GA_BLOCK);
//熔炉
offerSmelting(GA_FURNACE, RecipeCategory.MISC, ModItems.INGOT_GA, 0.7f, 200, "ga_blast_furnace");
//高炉
offerBlasting(GA_FURNACE, RecipeCategory.MISC, ModItems.INGOT_GA, 0.7f, 100, "ga_blast_furnace");
//烟熏炉
offerFoodCookingRecipe("smoking", RecipeSerializer.SMOKING, SmokingRecipe::new,
600, ModItems.RAW_GA, ModItems.INGOT_GA, 0.35f);
//篝火
offerFoodCookingRecipe("campfire_cooking", RecipeSerializer.CAMPFIRE_COOKING, CampfireCookingRecipe::new,
600, ModItems.RAW_GA, ModItems.INGOT_GA, 0.35f);
//有序配方
createShaped(RecipeCategory.MISC, ModItems.GA_EXAMPLE)
.pattern("XXX")
.input('X',ModItems.INGOT_GA)
.criterion("has_ga_example",conditionsFromItem(ModItems.INGOT_GA))
.offerTo(exporter, RegistryKey.of(RegistryKeys.RECIPE, getRecipeIdentifier(Identifier.of(<yourMODID>, "ga_example"))));
//无序配方
createShapeless(RecipeCategory.MISC, Items.FLINT_AND_STEEL,1)
.input(ModItems.INGOT_GA)
.input(Items.IRON_INGOT)
.criterion("has_flint_steel",conditionsFromItem(ModItems.INGOT_GA))
.criterion("has_flint_steel",conditionsFromItem(Items.IRON_INGOT))
.offerTo(exporter,RegistryKey.of(RegistryKeys.RECIPE, getRecipeIdentifier(Identifier.of(<yourMODID>, "other_flint_and_steel"))));
}
};
}
@Override
public String getName()
{
return <yourMODID>;
}
}
参考代码:
Issue #4252 · FabricMC/fabric (https://github.com/FabricMC/fabric/issues/4252)
Waystones/../datagen/ModRecipeProvider.java (https://github.com/TwelveIterationMods/Waystones)