| 1 | package net.minecraft.world.item.crafting;
|
| 2 |
|
| 3 | import com.mojang.serialization.MapCodec;
|
| 4 | import com.mojang.serialization.codecs.RecordCodecBuilder;
|
| 5 | import net.minecraft.network.RegistryFriendlyByteBuf;
|
| 6 | import net.minecraft.network.codec.StreamCodec;
|
| 7 | import net.minecraft.world.item.ItemStack;
|
| 8 | import net.minecraft.world.item.ItemStackTemplate;
|
| 9 | import net.minecraft.world.level.Level;
|
| 10 |
|
| 11 | public class BrewingRecipe implements Recipe<BrewingInput> {
|
| 12 | public static final MapCodec<BrewingRecipe> MAP_CODEC = RecordCodecBuilder.mapCodec(
|
| 13 | i -> i.group(
|
| 14 | PotionIngredient.MAP_CODEC.fieldOf("input").forGetter(o -> o.input),
|
| 15 | PotionIngredient.MAP_CODEC.fieldOf("reagent").forGetter(o -> o.reagent),
|
| 16 | ItemStackTemplate.CODEC.fieldOf("output").forGetter(o -> o.output)
|
| 17 | )
|
| 18 | .apply(i, BrewingRecipe::new)
|
| 19 | );
|
| 20 | public static final StreamCodec<RegistryFriendlyByteBuf, BrewingRecipe> STREAM_CODEC = StreamCodec.composite(
|
| 21 | PotionIngredient.STREAM_CODEC, o -> o.input, PotionIngredient.STREAM_CODEC, o -> o.reagent, ItemStackTemplate.STREAM_CODEC, o -> o.output, BrewingRecipe::new
|
| 22 | );
|
| 23 | public static final RecipeSerializer<BrewingRecipe> SERIALIZER = new RecipeSerializer<>(MAP_CODEC, STREAM_CODEC);
|
| 24 | private final PotionIngredient input;
|
| 25 | private final PotionIngredient reagent;
|
| 26 | private final ItemStackTemplate output;
|
| 27 |
|
| 28 | public BrewingRecipe(final PotionIngredient input, final PotionIngredient reagent, final ItemStackTemplate output) {
|
| 29 | this.input = input;
|
| 30 | this.reagent = reagent;
|
| 31 | this.output = output;
|
| 32 | }
|
| 33 |
|
| 34 | public PotionIngredient getInput() {
|
| 35 | return this.input;
|
| 36 | }
|
| 37 |
|
| 38 | public PotionIngredient getReagent() {
|
| 39 | return this.reagent;
|
| 40 | }
|
| 41 |
|
| 42 | public ItemStackTemplate getOutput() {
|
| 43 | return this.output;
|
| 44 | }
|
| 45 |
|
| 46 | public boolean matches(final BrewingInput brewingInput, final Level level) {
|
| 47 | return this.matches(brewingInput);
|
| 48 | }
|
| 49 |
|
| 50 | public boolean matches(final BrewingInput brewingInput) {
|
| 51 | return this.input.test(brewingInput.input()) && this.reagent.test(brewingInput.reagent());
|
| 52 | }
|
| 53 |
|
| 54 | public ItemStack assemble(final BrewingInput input) {
|
| 55 | return this.output.create();
|
| 56 | }
|
| 57 |
|
| 58 | @Override
|
| 59 | public RecipeType<BrewingRecipe> getType() {
|
| 60 | return RecipeType.BREWING;
|
| 61 | }
|
| 62 |
|
| 63 | @Override
|
| 64 | public PlacementInfo placementInfo() {
|
| 65 | return PlacementInfo.NOT_PLACEABLE;
|
| 66 | }
|
| 67 |
|
| 68 | @Override
|
| 69 | public boolean isSpecial() {
|
| 70 | return true;
|
| 71 | }
|
| 72 |
|
| 73 | @Override
|
| 74 | public boolean showNotification() {
|
| 75 | return false;
|
| 76 | }
|
| 77 |
|
| 78 | @Override
|
| 79 | public String group() {
|
| 80 | return "";
|
| 81 | }
|
| 82 |
|
| 83 | @Override
|
| 84 | public RecipeBookCategory recipeBookCategory() {
|
| 85 | return RecipeBookCategories.CRAFTING_MISC;
|
| 86 | }
|
| 87 |
|
| 88 | @Override
|
| 89 | public RecipeSerializer<BrewingRecipe> getSerializer() {
|
| 90 | return SERIALIZER;
|
| 91 | }
|
| 92 |
|
| 93 | @FunctionalInterface
|
| 94 | public interface Factory<T extends BrewingRecipe> {
|
| 95 | T create(final Recipe.CommonInfo commonInfo, final PotionIngredient input, final PotionIngredient reagent, final ItemStackTemplate output);
|
| 96 | }
|
| 97 | }
|
| 98 |
|