User Tools

Site Tools


zh_cn:tutorial:recipe_types_introduction

配方类型介绍

什么是配方类型

配方类型与配方本身不一样。为便于理解,我们先看一个例子:

my_recipe.json
{
  "type": "minecraft:smelting",
  "ingredient": {
    "tag": "minecraft:logs_that_burn"
  },
  "result": "minecraft:charcoal",
  "experience": 0.15,
  "cookingtime": 200
}

文件本身定义了获得木炭的配方,配方类型是冶炼(smelting)。配方类型可以定义为一组配方。配方类型用于熔炉,不过你也可以创建另一个同样使用此配方类型但是使用不同统计的熔炉。

配方类型如何起作用

配方类型起作用需要一个 Recipe 类和 RecipeSerializer 类。

Recipe 类定义了输入、输出、如何合成等。创建像木炭的例子的配方时,会创建一个你的 Recipe 类的实例,用于注册配方类型。

RecipeSerializer 用于序列化一个对象(这里是定义一个配方的 Recipe 类的实例)到一个封包(packet),然后从封包或者json对象反序列化到你的 Recipe 类的实例。RecipeSerializer 帮助我们更快地创建配方,而不需要我们自己为我们需要的每个配方实例化我们的 Recipe 类。

配方类型如何使用

To test if different items in an inventory work as inputs of a recipe and get the expected output, we use the RecipeManager class. It has some usefull method such as getAllOfType returning a map of all the recipes of a certain type with their Identifier or getAllMatches returning a List of recipes usable with the inventory of a ScreenHandler.

The easiest way to add a RecipeType is to use some vanilla classes to save a lot of code. An example of this would be all the abstract classes related to cooking. Theses classes are used for the furnace, the smoker, the blast furnace and even the campfire. If your RecipeType behave the same has a vanilla RecipeType you should first try to extends the used classes if they exist(sometime a RecipeType for a block does't have classes that you can use and it is easier to create your RecipeType from scratch).

深入教程

zh_cn/tutorial/recipe_types_introduction.txt · Last modified: 2023/04/20 11:33 by solidblock