====== Creating a Custom Recipe Type ====== In this page, we will create our own custom recipe type, including the shapeless version! We won't use any vanilla Minecraft classes, it will be a fully custom recipe type. ===== 블럭 추가 ===== 레시피 GUI를 열기 위한 블럭을 만들어야됩니다. 몇몇 다른 클래스는 추후에 만들것 입니다. public class TestRecipeBlock extends Block { private static final Text TITLE = new TranslatableText("container.test_crafting"); public SpiritpowerCrafterBlock(Settings settings) { super(settings); } @Override public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { if(world.isClient) { return ActionResult.SUCCESS; } else { player.openHandledScreen(state.createScreenHandlerFactory(world, pos)); player.incrementStat(Stats.INTERACT_WITH_CRAFTING_TABLE); return ActionResult.CONSUME; } } @Override public NamedScreenHandlerFactory createScreenHandlerFactory(BlockState state, World world, BlockPos pos) { return new SimpleNamedScreenHandlerFactory((i, playerInventory, playerEntity) -> { return new TestCraftingScreenHandler(i, playerInventory, ScreenHandlerContext.create(world, pos)); }, TITLE); } } 이제 Block과 BlockItem을 등록해야됩니다. public class ExampleCustomRecipeMod implements ModInitializer { public static final TestRecipeBlock TEST_RECIPE_BLOCK = new TestRecipeBlock(FabricBlockSettings.of(Material.METAL)); @Override public void onInitialize() { //Wait i gotta take a break hold on.. } } ===== 레시피 클래스 생성 ===== 이제 이 페이지에서 **가장 재미있는!!** 부분입니다. 레시피 클래스를 만들어 봅시다. ==== 모양이 있는 레시피 클래스 생성 ==== 모양이 있는 레시피는 특정 슬롯이나 패턴에 아이템이 있어야 하는 레시피 유형입니다. 그것은 제작대 레시피같은 그리드 방식의 레시피에 대부분 사용됩니다. Recipe 인터페이스에서는 Inventory 클래스를 형식 매개 변수로 사용합니다. 어떤 레시피를 위해 인벤토리Any inventory that contains the ingredients for the recipe would work. But we will be using CraftingInventory. public class TestRecipe implements Recipe { //원하는 입력을 넣을 수 있습니다. //Ingredient를 사용하면 태그를 지원 할 수 있어서 사용하는 것이 중요합니다. //위에 문장 이상하면 고쳐주세요. 원문: It is important to always use Ingredient, so you can support tags. private final Ingredient inputA; private final Ingredient inputB; private final ItemStack result; private final Identifier id; public TestRecipe(Identifier id, ItemStack result, Ingredient inputA, Ingredient inputB) { this.id = id; this.inputA = inputA; this.inputB = inputB; this.result = result; } public Ingredient getInputA() { return this.inputA; } public Ingredient getInputB() { return this.inputB; } @Override public ItemStack getOutput() { return this.result; } @Override public Identifier getId() { return this.id; } @Override public boolean matches(CraftingInventory inv, World world) { return false; } @Override public ItemStack craft(CraftingInventory inv) { return null; } @Override public boolean fits(int width, int height) { return false; } @Override public RecipeSerializer getSerializer() { return null; } @Override public RecipeType getType() { return null; } } We would need to care about craft, because it is needed to craft the result. In craft, it is a good idea to return ''this.getOutput().copy()''. ''fits'' should return true. public class TestRecipe implements Recipe { //[...] @Override public ItemStack craft(CraftingInventory inv) { return this.getOutput().copy(); } } In ''matches'', we need to say if a given inventory satisfies a recipe's input. We will return true if the first and second slot matches first and second input. public class TestRecipe implements Recipe { //[...] @Override public boolean matches(CraftingInventory inv, World world) { if(inv.getInvSize(0 < 2) return false; return inputA.test(inventory.getInvStack(0)) && inputB.test(inventory.getInvStack(1)); } } Now we need the ''Type'' of the recipe. All you have to do is to create an instance of a class that extends RecipeType. public class TestRecipe implements Recipe { //[...] public static Type implements RecipeType { private Type() {} public static final Type INSTANCE = new Type(); public static final String ID = "test_recipe"; } } SOURCE: [[https://github.com/natanfudge/fabric-docs/blob/master/newdocs/Modding-Tutorials/Crafting-Recipes/defining-custom-crafting-recipes.md|Defining Custom Crafting Recipes]]