Reconcile BlS gravelsieve updates with original techpack upgrades #91
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
On BlS we have been re-working the gravelsieve, I think it's time to put these changes back up to the original repo if possible.
Ideally these changes should not change the default behaviour, or run any significantly different code if the settings have not been changed.
I do not expect this to be merged soon, or without discussion, as a lot has changed for a variety of reasons and some of it may not be desirable.
Changes:
Output Types:
The default output type, if you are to register four relative outputs for an input, all with the same probability, say
2, they will all be proportioned to "fill the space", in this case they will all have a1/4chance of occurring. In this sense, a relative probability is more like a "weight" than a true 0-1 probailityThis must be a true 0-1 probability, it will not change based on the probability/weight of other outputs, if these add up to more than
1you may find the outputs are not what you expectedThese will also be true 0-1 probabilities, but they can be dynamically generated at runtime based on the situation - for instance, you could pass in player data or the surrounding nodes to modify the probability depending on them. Instead of registering a number probability, register a function that returns a number when called, you can do whatever calculation is required inside this function to produce unique probabilities.
Run order:
API:
gravelsieve.api.after_ores_calculated(callback)Will call
callbackonce all mods have loaded and the rarity of ores has been calculated - this is useful if you want to proportion your transformations based on the rarity of oresgravelsieve.api.reset_config()Will reset all configs, should probably only be used for testing purposes
gravelsieve.api.register_input(input_name[, outputs])Register an input item,
outputsis optional, it allows you to register outputs while registering the input.outputscan be:string=probabilitypairs, these will become the "relative" output of the inputoutput_type={string=probability}pairs, this will set outputs by their output typeNotes:
gravelsieve.api.override_input(input_name[, outputs])Delete all outputs for the given input and replace them with the new outputs (if given)
gravelsieve.api.remove_input(input_name)Delete all outputs for an input and un-register it
gravelsieve.api.swap_input(input_name, new_input_name)Swaps all the outputs registered for
input_nameand registers them fornew_input_namegravelsieve.api.get_outputs(input_name[, output_type])Get the table of outputs for a given input, if
output_typeis given it will only give the table for that typegravelsieve.api.get_output(input_name, output_name)Checks if
output_nameis one of the outputs forinput_name, returns the probability and output type if foundgravelsieve.api.register_output(input_name, output_name, probability[, output_type])Registers an output for a given
input_namewith the givenprobabilityforoutput_typeif given, if not it will be the default output type (relative)gravelsieve.api.register_relative_output(input_name, output_name, probability)Registers an output for a given
input_namewith the givenprobabilityfor the relative output typegravelsieve.api.register_dynamic_output(input_name, output_name, probability)Registers an output for a given
input_namewith the givenprobabilityfunction for the dynamic output typegravelsieve.api.register_fixed_output(input_name, output_name, probability)Registers an output for a given
input_namewith the givenprobabilityfor the fixed output typegravelsieve.api.override_output(input_name, output_name, probability, output_type)Removes and re-registers an output with the new probability and output type
gravelsieve.api.remove_output(input_name, output_name)Un-registers an output from an input
gravelsieve.api.swap_output(input_name, output_name, new_output_name)Swaps one output for another in the given input
gravelsieve.api.can_process(input_name)Checks if an input is registered with the gravelsieve
gravelsieve.api.get_random_output(input_name[, dynamic_args_generator, args])Chooses a random output for a given input,
dynamic_args_generatorandargsare only required if you're using the dynamic output type,dynamic_args_generator(args)will produce the first argument to be passed into the value generator function that should have been set as the dynamic probability value, they are passed in to avoid calling them when not needed - to avoid any unneeded effort from complex dynamic calculations that might not actually be used.Probability API:
gravelsieve.api.get_ore_frequencies()Calculates the rarity of ores in the world - should be the same as existing logic
gravelsieve.api.report_probabilities(probabilities)Prints out probabilities as a list of
1/n, separated from the original ore frequencies functionalitygravelsieve.api.sum_probabilities(probabilities)Adds up all probabilities in a table of
item=probabilitypairsgravelsieve.api.scale_probabilities_to_fill(probabilities, fill_to)Multiplies all probabilities in a table of
item=probabilitypairs so that, when summed, they add up to the givenfill_tolevel - useful for turning a bunch of "weights" into true probabilities by scaling them to fill1gravelsieve.api.scale_probabilities(probabilities, scale_factor)Multiplies all probabilities in a table of
item=probabilitypairs but the givenscale_factorgravelsieve.api.merge_probabilities( ... )Merges multiple tables of
item=probabilitypairs, adding up probabilities if they exist in more than one table