Jump to content

[1.16.5] How to get a custom machine pick a custom recipe based on a percentage chance.


Recommended Posts

Hi there. I'm trying to make one of my custom machines to choose a specific custom recipe depending on a percentage chance assigned to each recipe. This percentage chance will be based on one of the ingredients. For example, ingredient 1 + ingredient 2 has a 30% to produce output 1, 20% for output 2, and 50% for output 3. However, if you do ingredient 1 + ingredient 3, they'd have a 15% chance for output 1, 10% for output 2, and 75% for output 3. I have no idea how to go about this.

Cureently I have implemented the machine (including tile entity, screen, container, etc.) as as well as the RecipeType and Serialiser. My machine currently works to produce one output 100% of the time. It would be hugely appreciated if I could get, if not a solution, then maybe some ideas for implementing this, as I've been working on this for several days now and have completely run dry on ideas.


Link to comment
Share on other sites

  • 2 weeks later...

Thank you! I managed to get this working finally after puzzling through it, and your answer gave me a good place to start. I ended up using a combination of several for loops and an int array which was filled with the values of my "weight" json attribute for each recipe. Iterating through each recipe in my main list, I could add to a new array several repeats of the same number for the weight, and this number would correlate to a specific recipe in the main list. E.g. if the weight for the recipe in index 0 was 5, then 0 would be added to the array 5 times. My random number would then be chosen from this new array, and the recipe fetched from the main list using it. This works like an absolute charm. Hope this helps anyone else that might stumble on this thread! 

Link to comment
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.
Note: Your post will require moderator approval before it will be visible.

Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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 Terms of Use.