CraftingRecipe .java

net.minecraft.world.item.crafting.CraftingRecipe (interface, 57 lines): members: defaultCraftingReminder, CraftingBookInfo, getRemainingItems, category.

net.minecraft.world.item.craftinginterface57 linescommonextends Recipe<CraftingInput>2.0 KB

API Surface (0)

No public/protected methods detected (fields or constants only).

Full Source

CraftingRecipe.java57 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.item.crafting;
2
3
import com.mojang.serialization.MapCodec;
4
import net.minecraft.core.NonNullList;
5
import net.minecraft.network.RegistryFriendlyByteBuf;
6
import net.minecraft.network.codec.StreamCodec;
7
import net.minecraft.world.item.Item;
8
import net.minecraft.world.item.ItemStack;
9
import net.minecraft.world.item.ItemStackTemplate;
10
11
public interface CraftingRecipe extends Recipe<CraftingInput> {
12
	@Override
13
	default RecipeType<CraftingRecipe> getType() {
14
		return RecipeType.CRAFTING;
15
	}
16
17
	@Override
18
	RecipeSerializer<? extends CraftingRecipe> getSerializer();
19
20
	CraftingBookCategory category();
21
22
	default NonNullList<ItemStack> getRemainingItems(final CraftingInput input) {
23
		return defaultCraftingReminder(input);
24
	}
25
26
	static NonNullList<ItemStack> defaultCraftingReminder(final CraftingInput input) {
27
		NonNullList<ItemStack> result = NonNullList.withSize(input.size(), ItemStack.EMPTY);
28
29
		for (int slot = 0; slot < result.size(); slot++) {
30
			Item item = input.getItem(slot).getItem();
31
			ItemStackTemplate remainder = item.getCraftingRemainder();
32
			result.set(slot, remainder != null ? remainder.create() : ItemStack.EMPTY);
33
		}
34
35
		return result;
36
	}
37
38
	@Override
39
	default RecipeBookCategory recipeBookCategory() {
40
		return switch (this.category()) {
41
			case BUILDING -> RecipeBookCategories.CRAFTING_BUILDING_BLOCKS;
42
			case EQUIPMENT -> RecipeBookCategories.CRAFTING_EQUIPMENT;
43
			case REDSTONE -> RecipeBookCategories.CRAFTING_REDSTONE;
44
			case MISC -> RecipeBookCategories.CRAFTING_MISC;
45
		};
46
	}
47
48
	record CraftingBookInfo(CraftingBookCategory category, String group) implements Recipe.BookInfo<CraftingBookCategory> {
49
		public static final MapCodec<CraftingRecipe.CraftingBookInfo> MAP_CODEC = Recipe.BookInfo.mapCodec(
50
			CraftingBookCategory.CODEC, CraftingBookCategory.MISC, CraftingRecipe.CraftingBookInfo::new
51
		);
52
		public static final StreamCodec<RegistryFriendlyByteBuf, CraftingRecipe.CraftingBookInfo> STREAM_CODEC = Recipe.BookInfo.streamCodec(
53
			CraftingBookCategory.STREAM_CODEC, CraftingRecipe.CraftingBookInfo::new
54
		);
55
	}
56
}
57

Decompiled Minecraft 26.3 source of CraftingRecipe (net/minecraft/world/item/crafting/CraftingRecipe.java) with Mojang official mappings, stored verbatim on the site.