Kangalia Posted November 20, 2021 Posted November 20, 2021 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. Thanks! Quote
Kangalia Posted November 21, 2021 Author Posted November 21, 2021 Update to this. I've managed to get the machine to produce an output depending on a randomly generated number using the Random and SecureRandom java classes. However, I still can't figure out how to do the weighting. Quote
Luis_ST Posted November 22, 2021 Posted November 22, 2021 you need a percentage for each ingredient, when you return the Items of the Recipe you need to check the percentage via a Random Quote
Kangalia Posted December 2, 2021 Author Posted December 2, 2021 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! Quote
Recommended Posts
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.