package net.minecraft.world.item.crafting; import com.mojang.serialization.MapCodec; import com.mojang.serialization.codecs.RecordCodecBuilder; import net.minecraft.network.RegistryFriendlyByteBuf; import net.minecraft.network.codec.StreamCodec; import net.minecraft.world.item.crafting.CustomRecipe.Serializer.Factory; public abstract class CustomRecipe implements CraftingRecipe { private final CraftingBookCategory category; public CustomRecipe(CraftingBookCategory category) { this.category = category; } @Override public boolean isSpecial() { return true; } @Override public CraftingBookCategory category() { return this.category; } @Override public PlacementInfo placementInfo() { return PlacementInfo.NOT_PLACEABLE; } @Override public abstract RecipeSerializer getSerializer(); public static class Serializer implements RecipeSerializer { private final MapCodec codec; private final StreamCodec streamCodec; public Serializer(Factory factory) { this.codec = RecordCodecBuilder.mapCodec( instance -> instance.group(CraftingBookCategory.CODEC.fieldOf("category").orElse(CraftingBookCategory.MISC).forGetter(CraftingRecipe::category)) .apply(instance, factory::create) ); this.streamCodec = StreamCodec.composite(CraftingBookCategory.STREAM_CODEC, CraftingRecipe::category, factory::create); } @Override public MapCodec codec() { return this.codec; } @Override public StreamCodec streamCodec() { return this.streamCodec; } } }