Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[FIXED] [1.14.4] Custom brewing recipes?


Recommended Posts

Is there a method to add your own custom brewing stand recipes? It has nothing to do with adding custom potions and their effects. Let's say I just want to brew ITEM_A from ITEM_B as the ingredient and water bottles inside.

Edited by Xander402

A few bytes about me:

public class Xander402 extends Modder implements IForumMember {
    int javaExperience, moddingExperience;
    LearningWay preferredLearningWay;
    public Xander402() {
        this.javaExperience = BIG;
        this.moddingExperience = NOT_SO_BIG;
        this.preferredLearningWay = LearningWay.through("exampes");
      	super(/*displayName*/"Xander402", /*moddingSince*/"1.9", preferredLearningWay);
    }
    @Override
    public Goal getReasonOfJoining(Forum forum) { return new Goal(() -> { while (true) moddingExperience++; }); }
}

 

Link to post
Share on other sites

Well, I really tried. I looked at BrewingRecipeRegistry, I found 

BrewingRecipeRegistry.addRecipe(Ingredient, Ingredient, ItemStack);

and I put it here:

@SubscribeEvent
    public void registerItems(final RegistryEvent.Register<Item> event) {

        event.getRegistry().registerAll(ItemList.getItems());

        BrewingRecipeRegistry.addRecipe( ... );
    }

but I have no idea how to use Ingredient... I really miss any examples on the internet. I learn the best with examples. My question is:

BrewingRecipeRegistry.addRecipe(
  /* Ingredient input - what to write here? (for example: water bottle*) */,
  /* Ingredient ingredient - what to write here? (for example: ItemList.ITEM_A) */,
  new ItemStack(ItemList.ITEM_B, 1)
);

// * BTW, I'd like to know how to implement water bottle, since it's not an item, but a Potion

 

Edited by Xander402

A few bytes about me:

public class Xander402 extends Modder implements IForumMember {
    int javaExperience, moddingExperience;
    LearningWay preferredLearningWay;
    public Xander402() {
        this.javaExperience = BIG;
        this.moddingExperience = NOT_SO_BIG;
        this.preferredLearningWay = LearningWay.through("exampes");
      	super(/*displayName*/"Xander402", /*moddingSince*/"1.9", preferredLearningWay);
    }
    @Override
    public Goal getReasonOfJoining(Forum forum) { return new Goal(() -> { while (true) moddingExperience++; }); }
}

 

Link to post
Share on other sites

Why on earth did you decide that the item registry event was the appropriate place to do this?! Use FMLCommonSetupEvent and then DeferredWorkQueue (BrewingRecipeRegistry is not threadsafe).

 

10 minutes ago, Xander402 said:

but I have no idea how to use Ingredient...

Look at the class, it has various factory methods.

  • Thanks 1
Link to post
Share on other sites

Alright.
I created a class SoySauceRecipe which looks like this:

package ...

import ...

public class SoySauceRecipe implements IBrewingRecipe {

    private ItemStack output = new ItemStack(ItemList.soy_sauce);

    SoySauceRecipe() {
    }

    @Override
    public boolean isInput(ItemStack input2) {
        return input2.getItem().equals(Items.POTION) && PotionUtils.getEffectsFromStack(input2).isEmpty();
    }

    @Override
    public boolean isIngredient(ItemStack ingredient2) {
        return ingredient2.getItem() == ItemList.soybean;
    }

    @Override
    public ItemStack getOutput(ItemStack input2, ItemStack ingredient2) {
        return output;
    }
}

and registered the recipe here, in main mod file:

package ...

import ...

@Mod("...")
public class SushiMod {

    ...

    public SushiMod() {
        ...
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
    }

    private void setup(final FMLCommonSetupEvent event) {
        DeferredWorkQueue.runLater(this::registerPotions);
    }

    private void registerPotions() {
        BrewingRecipeRegistry.addRecipe(new SoySauceRecipe());
    }
}

Works fine... but not entirely.
There are two problems:

  1. According to you, from Topic #64031: Recipes with Water Bottle ItemStack:
    Quote

    Yes, PotionUtils.getEffectsFromStack will give you all potions in a potion stack. If there are none, it's a water bottle.

    a potion with no effect is exclusively a water bottle. But so are potions such as an Awkward Potion as well. Therefore they get accepted as the input for the recipe, too. How to make the recipe only accept pure water bottle?

  2. After the soy sauce is brewed and there's still remaining soybean in the ingredient slot, the soy sauce gets brewed again with itself as the input. Why is that happening despite the fact that isInput method returns true only when there's a POTION input slot?

Edited by Xander402

A few bytes about me:

public class Xander402 extends Modder implements IForumMember {
    int javaExperience, moddingExperience;
    LearningWay preferredLearningWay;
    public Xander402() {
        this.javaExperience = BIG;
        this.moddingExperience = NOT_SO_BIG;
        this.preferredLearningWay = LearningWay.through("exampes");
      	super(/*displayName*/"Xander402", /*moddingSince*/"1.9", preferredLearningWay);
    }
    @Override
    public Goal getReasonOfJoining(Forum forum) { return new Goal(() -> { while (true) moddingExperience++; }); }
}

 

Link to post
Share on other sites
9 minutes ago, Xander402 said:

a potion with no effect is exclusively a water bottle. But so are potions such as an Awkward Potion as well. Therefore they get accepted as the input for the recipe, too. How to make the recipe only accept pure water bottle?

PotionUtils.getPotionFromItem(stack) == Potions.WATER.

 

12 minutes ago, Xander402 said:

After the soy sauce is brewed and there's still remaining soybean in the ingredient slot, the soy sauce gets brewed again with itself as the input. Why is that happening despite the fact that isInput method returns true only when there's a POTION input slot? 

You did not follow the implementation contract for IBrewingRecipe#getOutput. Read the Javadoc and implement your code accordingly.

Link to post
Share on other sites

diesieben07, I really appreciate that you answer people's question in such way that you make them do some research in their own. I even like that. Learning is more efficient when you put some effort into it. But sometimes this method fails :/. As I said, I learn the best with examples. I'm really tired after sieben hours of trying to do such relatively simple thing as adding a working brewing recipe with my mod items to the game... (yeah, I started this topic 7 hours ago and I've been doing nothing but trying to get this working).

My SoySauceRecipe class looks like this now:

package ...

import ,,,

public class SoySauceRecipe implements IBrewingRecipe {

    private ItemStack input = new ItemStack(Items.POTION);
    private ItemStack ingredient = new ItemStack(ItemList.soybean);
    private ItemStack output = new ItemStack(ItemList.soy_sauce);

    public SoySauceRecipe() {
    }

    @Override
    public boolean isInput(ItemStack input2) {
        return PotionUtils.getPotionFromItem(input2) == Potions.WATER;
    }


    @Override
    public boolean isIngredient(ItemStack ingredient2) {
        return ingredient2.getItem() == ingredient.getItem();
    }

    @Override
    public ItemStack getOutput(ItemStack input2, ItemStack ingredient2) {
        if (ingredient2 != null && input2 != null && isIngredient(ingredient2)) {
            ItemStack output2 = this.output.copy();
            if (input2 != output2) return output2;
            else return null;
        } else return null;
    }
}

(with the line return PotionUtils.getPotionFromItem(input2) == Potions.WATER; from you plus the IBrewingRecipe#getOutput method found somewhere on this forum), and it all works the same way. Both Awkward Potion and Soy Sauce is still acceptable as the input. Moreover, I just found out that when I don't fill all of the 3 brewing stand output slots with bottles and there is Blaze Powder in its upper-left slot.., it gets replaced with soy sauce after brewing is done. -,-
All this mess is shown on the screenshot.

So... yeah.. Sorry, but could you please write for me a properly working class SoySauceRecipe that implements IBrewingRecipe with Water Bottle as the only acceptable input, Items.soybean as the ingredient, and Items.soy_sauce as the output..? I believe that this impossible challenge for a beginner modder like me is a piece of cake for somebody like you.

 

2019-11-25_00.28.53.png

A few bytes about me:

public class Xander402 extends Modder implements IForumMember {
    int javaExperience, moddingExperience;
    LearningWay preferredLearningWay;
    public Xander402() {
        this.javaExperience = BIG;
        this.moddingExperience = NOT_SO_BIG;
        this.preferredLearningWay = LearningWay.through("exampes");
      	super(/*displayName*/"Xander402", /*moddingSince*/"1.9", preferredLearningWay);
    }
    @Override
    public Goal getReasonOfJoining(Forum forum) { return new Goal(() -> { while (true) moddingExperience++; }); }
}

 

Link to post
Share on other sites
11 minutes ago, Xander402 said:

So... yeah.. Sorry, but could you please write for me a properly working class SoySauceRecipe that implements IBrewingRecipe with Water Bottle as the only acceptable input, Items.soybean as the ingredient, and Items.soy_sauce as the output..?

I don't know how to do this off the top of my head either. I would probably make the same mistakes you did now.

And honestly, just looking at the code now I don't know what causes this.

 

This is when you need to turn to the debugger. Put breakpoints in the methods in your recipe class, see what the parameter values are, see what you are returning, etc. That's what I would do as well to give you a ready-made solution here. If this does not get you anywhere, post a working Git repository so I can test this myself.

Link to post
Share on other sites

Well... Although debugging did illuminate some things that are going on when operating the brewing stand, one thing remains a mistery. As for now, the recipe works perfectly as intended... but only once. After one brewing, no further can be performed.

My SoySauceRecipe class now:

package ...

import ...

public class SoySauceRecipe implements IBrewingRecipe {

    private static final ItemStack INGREDIENT = new ItemStack(ItemList.soybean);
    private static final ItemStack OUTPUT = new ItemStack(ItemList.soy_sauce);

    SoySauceRecipe() {
    }

    @Override
    public boolean isInput(@Nonnull ItemStack stack) {
        LOGGER.info("IBrewingRecipe#isInput: return " + PotionUtils.getPotionFromItem(stack) + " == " + Potions.WATER);
        return PotionUtils.getPotionFromItem(stack) == Potions.WATER;
    }

    @Override
    public boolean isIngredient(@Nonnull ItemStack ingredient) {
        LOGGER.info("IBrewingRecipe#isIngredient: return " + INGREDIENT.getItem() + " == " + ItemList.soybean);
        return INGREDIENT.getItem() == ItemList.soybean;
    }

    @Nonnull
    @Override
    public ItemStack getOutput(@Nonnull ItemStack input, @Nonnull ItemStack ingredient) {
        LOGGER.info("IBrewingRecipe#getOutput: isInput(input) = " + isInput(input)
                + " isIngredient(ingredient) = " + isIngredient(ingredient)
                + " -> return " + ((isInput(input) && isIngredient(ingredient))
                ? "OUTPUT (=" + OUTPUT + ")" : "ItemStack.EMPTY"));
        LOGGER.info("Target output: " + OUTPUT);
        if (isInput(input) && isIngredient(ingredient))
            return OUTPUT;
        return ItemStack.EMPTY;
    }
}

Now, when I put Soybean to the ingredient slot, but leave the bottles slots empty, the log shows:

[...] IBrewingRecipe#isIngredient: return soybean == soybean
[...] IBrewingRecipe#isInput: return net.minecraft.potion.Potion@7f70e244 == net.minecraft.potion.Potion@fd14789
[...] IBrewingRecipe#getOutput: isInput(input) = false isIngredient(ingredient) = true -> return ItemStack.EMPTY
[...] Target output: 1 soy_sauce
  1. First line - shows what is compared in isIngredient method.
  2. Second line - shows what is compared in isInput method.
  3. Third line - shows results of isIngredient and isInput methods and resulting ItemStack that is returned as the output.
  4. Fourth line - shows what should be the output of the recipe (it's the item declared in the OUTPUT field.

Looks good for now. After adding water bottles:

[...] IBrewingRecipe#isInput: return net.minecraft.potion.Potion@fd14789 == net.minecraft.potion.Potion@fd14789
[...] IBrewingRecipe#isIngredient: return soybean == soybean
[...] IBrewingRecipe#getOutput: isInput(input) = true isIngredient(ingredient) = true -> return OUTPUT (=1 soy_sauce)
[...] Target output: 1 soy_sauce

As you can see, both isInput and isIngredient are returning true, thus getOutput returns ItemStack with Soy Sauce now, and the brewing begins. Target output is still 1 soy sauce.

But after it finishes:

[...] IBrewingRecipe#isInput: return net.minecraft.potion.Potion@7f70e244 == net.minecraft.potion.Potion@fd14789
[...] IBrewingRecipe#isIngredient: return soybean == soybean
[...] IBrewingRecipe#getOutput: isInput(input) = false isIngredient(ingredient) = true -> return ItemStack.EMPTY
[...] Target output: 0 air

Despite the fact that the ingredient slot hasn't changed (which even the console output agrees with - as shows the second line), the target output somehow has changed to 0 air... Firstly, this state remains the same regardless of the bottles slots contents. Why is that? It should change when I put a water bottle inside, like at the first brewing. And secondly, how on earth is it possible that target output changed if the console reads content of the OUTPUT field which not only isn't changed anywhere in the code, but also is declared as final?? This looks like a Forge bug to me.., but I don't feel suitable to judge such things. Am I missing something..?

---

Here's the GitHub repository: [LINK EXPIRED]

Edited by Xander402

A few bytes about me:

public class Xander402 extends Modder implements IForumMember {
    int javaExperience, moddingExperience;
    LearningWay preferredLearningWay;
    public Xander402() {
        this.javaExperience = BIG;
        this.moddingExperience = NOT_SO_BIG;
        this.preferredLearningWay = LearningWay.through("exampes");
      	super(/*displayName*/"Xander402", /*moddingSince*/"1.9", preferredLearningWay);
    }
    @Override
    public Goal getReasonOfJoining(Forum forum) { return new Goal(() -> { while (true) moddingExperience++; }); }
}

 

Link to post
Share on other sites

You cannot re-use itemStacks like that. ItemStacks are mutable. What you declare as final by making the field final is the reference to the stack, not the stack itself.

You have to either clone the stack before returning it or just create a new one every time.

  • Thanks 1
Link to post
Share on other sites

Well, I'm happy to say that this fixed the error. ? Thank you for all your help on this topic!

A few bytes about me:

public class Xander402 extends Modder implements IForumMember {
    int javaExperience, moddingExperience;
    LearningWay preferredLearningWay;
    public Xander402() {
        this.javaExperience = BIG;
        this.moddingExperience = NOT_SO_BIG;
        this.preferredLearningWay = LearningWay.through("exampes");
      	super(/*displayName*/"Xander402", /*moddingSince*/"1.9", preferredLearningWay);
    }
    @Override
    public Goal getReasonOfJoining(Forum forum) { return new Goal(() -> { while (true) moddingExperience++; }); }
}

 

Link to post
Share on other sites
  • 1 year later...
2 hours ago, eggpasta said:

Can you please share your finished code as i am having the same issues

don't necropost on a thread from 2 year ago
and his solution possibly wouldn't work for you since it was for 1.14
just make a new topic and explain your issues further

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.