🇨🇳 中文 (Chinese - China)
🇨🇳 中文 (Chinese - China)
外观
🇨🇳 中文 (Chinese - China)
🇨🇳 中文 (Chinese - China)
外观
本页面基于这个版本编写:
1.21.4
前提
首先,请确保你已完成 Datagen 设置 。
首先,我们需要提供程序。 创建一个 extends FabricRecipeProvider
的类。 我们所有的配方生成都将在提供程序的 generate
方法中进行。
import java.util.List;
import java.util.concurrent.CompletableFuture;
import net.minecraft.data.recipe.RecipeExporter;
import net.minecraft.data.recipe.RecipeGenerator;
import net.minecraft.item.Item;
import net.minecraft.item.Items;
import net.minecraft.recipe.Ingredient;
import net.minecraft.recipe.book.RecipeCategory;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.RegistryWrapper;
import net.minecraft.registry.tag.ItemTags;
import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput;
import net.fabricmc.fabric.api.datagen.v1.provider.FabricRecipeProvider;
public class FabricDocsReferenceRecipeProvider extends FabricRecipeProvider {
public FabricDocsReferenceRecipeProvider(FabricDataOutput output, CompletableFuture<RegistryWrapper.WrapperLookup> registriesFuture) {
super(output, registriesFuture);
}
@Override
protected RecipeGenerator getRecipeGenerator(RegistryWrapper.WrapperLookup registryLookup, RecipeExporter exporter) {
return new RecipeGenerator(registryLookup, exporter) {
@Override
public void generate() {
RegistryWrapper.Impl<Item> itemLookup = registries.getOrThrow(RegistryKeys.ITEM);
}
};
}
@Override
public String getName() {
return "FabricDocsReferenceRecipeProvider";
}
}
要完成设置,将此提供程序添加到 onInitializeDataGenerator
方法中的 DataGeneratorEntrypoint
。
pack.addProvider(FabricDocsReferenceRecipeProvider::new);
无序配方相当的简单。 只需将它们添加到提供程序中的 generate
方法中:
createShapeless(RecipeCategory.BUILDING_BLOCKS, Items.DIRT) // You can also specify an int to produce more than one
.input(Items.COARSE_DIRT) // You can also specify an int to require more than one, or a tag to accept multiple things
// Create an advancement that gives you the recipe
.criterion(hasItem(Items.COARSE_DIRT), conditionsFromItem(Items.COARSE_DIRT))
.offerTo(exporter);
对于有序配方,可以使用 String
定义有序,然后定义 String
中每个 char
代表什么。
createShaped(RecipeCategory.MISC, Items.CRAFTING_TABLE, 4)
.pattern("ll")
.pattern("ll")
.input('l', ItemTags.LOGS) // 'l' means "any log"
.group("multi_bench") // Put it in a group called "multi_bench" - groups are shown in one slot in the recipe book
.criterion(hasItem(Items.CRAFTING_TABLE), conditionsFromItem(Items.CRAFTING_TABLE))
.offerTo(exporter);
createShaped(RecipeCategory.MISC, Items.LOOM, 4)
.pattern("ww")
.pattern("ll")
.input('w', ItemTags.WOOL) // 'w' means "any wool"
.input('l', ItemTags.LOGS)
.group("multi_bench")
.criterion(hasItem(Items.LOOM), conditionsFromItem(Items.LOOM))
.offerTo(exporter);
createDoorRecipe(Items.OAK_DOOR, Ingredient.ofItems(Items.OAK_BUTTON)) // Using a helper method!
.criterion(hasItem(Items.OAK_BUTTON), conditionsFromItem(Items.OAK_BUTTON))
.offerTo(exporter);
TIP
有很多辅助方法可用于创建普通配方。 查看 RecipeProvider
提供的内容! 在 IntelliJ 中按 Alt + 7
打开类的结构,其中包括方法列表。
其他配方的工作原理类似,但需要一些额外的参数。 比如烧炼配方需要了解奖励多少经验。
offerSmelting(
List.of(Items.BREAD, Items.COOKIE, Items.HAY_BLOCK), // Inputs
RecipeCategory.FOOD, // Category
Items.WHEAT, // Output
0.1f, // Experience
300, // Cooking time
"food_to_wheat" // group
);