Featured image of post 在1.21.4中创建ModRecipesProvider类的相同与区别 V2.0

在1.21.4中创建ModRecipesProvider类的相同与区别 V2.0

FirstFabricModDev 2

参考视频:

相同与区别

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:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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
Waystones/../datagen/ModRecipeProvider.java

本作品采用知识共享署名-非商业性使用-相同方式共享4.0国际许可协议进行许可(CC BY-NC-SA 4.0)
文章浏览量:Loading
Powered By MC ZBD Studio
发表了21篇文章 · 总计29.03k字
载入天数...载入时分秒...
总浏览量Loading | 访客总数Loading

主题 StackJimmy 设计
由ZephyrBD修改