Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Output Chances Deterministic #2565

Open
wants to merge 45 commits into
base: master
Choose a base branch
from

Conversation

ghzdude
Copy link
Contributor

@ghzdude ghzdude commented Aug 4, 2024

What

Changes the chanced output logic to be more deterministic instead of purely relying on pseudo-rng.
Adds the ability to use fractions as a chance.

Implementation Details

Chances are made deterministic by caching failed chances when rolling to add to it on the next roll. A role is considered successful if the chance + cached chance exceeds the entry's max chance. The OR chance logic also has the added behavior of succeeding several times if the chance is many times over the max chance.

Cached chances are stored in ARL as a Object2Int map, and is serialized to NBT. If a chanced entry is rolled for the first time, a random number between [0,entry.getMaxChance()) is returned, acting as an initial offset. The cache is cleared when a new recipe is found and is different from the previous recipe.

added extra methods to RecipeBuilder to interpret a string as a fractional chance, allowing for irrational fractions to be used as chances. the fraction is split into numerator and denominator, and then scaled up to the max chance (10,000) to make adding chance boosts easier.

Outcome

death to rng

@ghzdude ghzdude added the type: refactor Suggestion to refactor a section of code label Aug 4, 2024
@ghzdude ghzdude requested a review from a team as a code owner August 4, 2024 00:39
@ghzdude ghzdude force-pushed the gh-deterministic-chances branch from c008e07 to f1275d9 Compare September 7, 2024 23:16
add check for previous recipe
make XOR use cache getter method
simplify constructors
fix FluidStackHashStrategy javadocs
compare fluids only for strategy
try to make outputs appear more random initially
rip rollover
make `passesChance()` defualt for override
move cache, machine tier, recipe tier, and boost function into RecipeContext
add CalculatedOutput so that chance logic set amounts for overflowing chances
fix XOR logic tests because the behavior of XOR was changed slightly
@ghzdude ghzdude force-pushed the gh-deterministic-chances branch from 07c6168 to 2cb3f2a Compare November 16, 2024 05:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: refactor Suggestion to refactor a section of code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant