package net.minecraft.world.item.crafting; import com.mojang.serialization.MapCodec; import net.minecraft.core.NonNullList; import net.minecraft.network.RegistryFriendlyByteBuf; import net.minecraft.network.codec.StreamCodec; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStackTemplate; public interface CraftingRecipe extends Recipe { @Override default RecipeType getType() { return RecipeType.CRAFTING; } @Override RecipeSerializer getSerializer(); CraftingBookCategory category(); default NonNullList getRemainingItems(final CraftingInput input) { return defaultCraftingReminder(input); } static NonNullList defaultCraftingReminder(final CraftingInput input) { NonNullList result = NonNullList.withSize(input.size(), ItemStack.EMPTY); for (int slot = 0; slot < result.size(); slot++) { Item item = input.getItem(slot).getItem(); ItemStackTemplate remainder = item.getCraftingRemainder(); result.set(slot, remainder != null ? remainder.create() : ItemStack.EMPTY); } return result; } @Override default RecipeBookCategory recipeBookCategory() { return switch (this.category()) { case BUILDING -> RecipeBookCategories.CRAFTING_BUILDING_BLOCKS; case EQUIPMENT -> RecipeBookCategories.CRAFTING_EQUIPMENT; case REDSTONE -> RecipeBookCategories.CRAFTING_REDSTONE; case MISC -> RecipeBookCategories.CRAFTING_MISC; }; } public record CraftingBookInfo(CraftingBookCategory category, String group) implements Recipe.BookInfo { public static final MapCodec MAP_CODEC = Recipe.BookInfo.mapCodec( CraftingBookCategory.CODEC, CraftingBookCategory.MISC, CraftingRecipe.CraftingBookInfo::new ); public static final StreamCodec STREAM_CODEC = Recipe.BookInfo.streamCodec( CraftingBookCategory.STREAM_CODEC, CraftingRecipe.CraftingBookInfo::new ); } }