| 1 | package net.minecraft.data.recipes;
|
| 2 |
|
| 3 | import java.util.ArrayList;
|
| 4 | import java.util.HashSet;
|
| 5 | import java.util.List;
|
| 6 | import java.util.Set;
|
| 7 | import net.minecraft.core.Holder;
|
| 8 | import net.minecraft.world.item.Item;
|
| 9 | import net.minecraft.world.item.alchemy.Potion;
|
| 10 | import net.minecraft.world.item.alchemy.Potions;
|
| 11 |
|
| 12 | public abstract class BrewingProvider {
|
| 13 | private final List<Item> containers = new ArrayList<>();
|
| 14 | private final List<BrewingProvider.ContainerTransformation> containerTransformations = new ArrayList<>();
|
| 15 | private final Set<Holder<Potion>> potions = new HashSet<>();
|
| 16 | private final RecipeOutput output;
|
| 17 |
|
| 18 | protected BrewingProvider(final RecipeOutput output) {
|
| 19 | this.output = output;
|
| 20 | }
|
| 21 |
|
| 22 | protected void addContainerTransformation(final Item container, final Item reagent, final Item output) {
|
| 23 | if (!this.containers.contains(container)) {
|
| 24 | throw new IllegalStateException("Adding a transformation for an unknown container: " + container);
|
| 25 | }
|
| 26 |
|
| 27 | this.containerTransformations.add(new BrewingProvider.ContainerTransformation(container, reagent, output));
|
| 28 | }
|
| 29 |
|
| 30 | protected void addContainer(final Item container) {
|
| 31 | this.containers.add(container);
|
| 32 | }
|
| 33 |
|
| 34 | protected void buildMix(final Holder<Potion> input, final Item reagent, final Holder<Potion> output) {
|
| 35 | for (Item container : this.containers) {
|
| 36 | this.save(BrewingRecipeBuilder.brewingMix(container, input, reagent, output));
|
| 37 | }
|
| 38 |
|
| 39 | this.potions.add(input);
|
| 40 | this.potions.add(output);
|
| 41 | }
|
| 42 |
|
| 43 | protected void buildStartMix(final Item reagent, final Holder<Potion> output) {
|
| 44 | this.buildMix(Potions.WATER, reagent, Potions.MUNDANE);
|
| 45 | this.buildMix(Potions.AWKWARD, reagent, output);
|
| 46 | }
|
| 47 |
|
| 48 | protected void buildTransformations() {
|
| 49 | for (BrewingProvider.ContainerTransformation transformation : this.containerTransformations) {
|
| 50 | for (Holder<Potion> potion : this.potions) {
|
| 51 | this.save(BrewingRecipeBuilder.brewingContainerTransform(transformation.container(), potion, transformation.reagent(), transformation.output()));
|
| 52 | }
|
| 53 | }
|
| 54 | }
|
| 55 |
|
| 56 | protected void save(final BrewingRecipeBuilder builder) {
|
| 57 | builder.save(this.output);
|
| 58 | }
|
| 59 |
|
| 60 | public final void buildRecipes() {
|
| 61 | this.addContainers();
|
| 62 | this.addContainerTransformations();
|
| 63 | this.buildMixes();
|
| 64 | this.buildTransformations();
|
| 65 | }
|
| 66 |
|
| 67 | protected abstract void addContainers();
|
| 68 |
|
| 69 | protected abstract void addContainerTransformations();
|
| 70 |
|
| 71 | protected abstract void buildMixes();
|
| 72 |
|
| 73 | private record ContainerTransformation(Item container, Item reagent, Item output) {
|
| 74 | }
|
| 75 | }
|
| 76 |
|