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; public class SimpleCraftingRecipeSerializer implements RecipeSerializer { private final MapCodec codec; private final StreamCodec streamCodec; public SimpleCraftingRecipeSerializer(SimpleCraftingRecipeSerializer.Factory constructor) { this.codec = RecordCodecBuilder.mapCodec( instance -> instance.group(CraftingBookCategory.CODEC.fieldOf("category").orElse(CraftingBookCategory.MISC).forGetter(CraftingRecipe::category)) .apply(instance, constructor::create) ); this.streamCodec = StreamCodec.composite(CraftingBookCategory.STREAM_CODEC, CraftingRecipe::category, constructor::create); } @Override public MapCodec codec() { return this.codec; } @Override public StreamCodec streamCodec() { return this.streamCodec; } @FunctionalInterface public interface Factory { T create(CraftingBookCategory craftingBookCategory); } }