User Tools

Site Tools


ko_kr:tutorial:recipe_type

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를 열기 위한 블럭을 만들어야됩니다. 몇몇 다른 클래스는 추후에 만들것 입니다.

TestRecipeBlock.java
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을 등록해야됩니다.

ExampleCustomRecipeMod.java
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.

TestRecipe.java
public class TestRecipe implements Recipe<CraftingInventory> {
	//원하는 입력을 넣을 수 있습니다.
        //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.

TestRecipe.java
public class TestRecipe implements Recipe<CraftingInventory> {
	//[...]
	@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.

TestRecipe.java
public class TestRecipe implements Recipe<CraftingInventory> {
	//[...]
	@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<TestRecipe>.

TestRecipe.java
public class TestRecipe implements Recipe<CraftingInventory> {
	//[...]
	public static Type implements RecipeType<TestRecipe> {
		private Type() {}
		public static final Type INSTANCE = new Type();
		public static final String ID = "test_recipe";
	}
}

SOURCE: Defining Custom Crafting Recipes

ko_kr/tutorial/recipe_type.txt · Last modified: 2021/03/01 05:35 by 127.0.0.1