🔀 sorters#

Generates functions that sort lists in storage.

beet_default(ctx: Context)[source]#

Main entry point for the sorters plugin. This plugin generates functions that sort lists in storage.

Parameters:

ctx – The beet context.

constants#

class Sorter(
*,
algorithm: Literal['quick_sort', 'selection_sort'] = 'selection_sort',
functions_location: str,
to_sort: dict[str, str],
key: str,
scale: int = 1,
limit: int | None = None,
)[source]#

Bases: BaseModel

Configuration model for sorting operations.

This class defines the parameters required to generate datapack functions that can sort lists stored in storage using various algorithms.

{
        "algorithm": "selection_sort",
        "functions_location": "switch:stats/minigame/sort_leaderboard",
        "to_sort": {
                "storage": "switch:stats",
                "target": "all.modes.sheepwars.played"
        },
        "key": "count",
        "scale": 100
}
algorithm: Literal['quick_sort', 'selection_sort'][source]#

Algorithm used to sort the elements, defaults to selection_sort.

functions_location: str[source]#

Namespaced id where the sorting functions are generated.

to_sort: dict[str, str][source]#

Location of the list to sort.

key: str[source]#

The key to the number getting compared.

scale: int[source]#

(Option) By how many the number should be scaled before getting rounded.

model_config: ClassVar[ConfigDict] = {}[source]#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

limit: int | None[source]#

(Option) Limit of how many elements to sort, if not specified all elements will be sorted. (Only compatible with selection_sort algorithm.)

class SorterFile(
_content: ValueType | SerializeType | None = None,
source_path: FileSystemPath | None = None,
source_start: int | None = None,
source_stop: int | None = None,
on_bind: Callable[[Any, Any, str], Any] | None = None,
serializer: Callable[[ValueType], SerializeType] = None,
deserializer: Callable[[SerializeType], ValueType] = None,
reader: Callable[[FileSystemPath, int, int], SerializeType] = None,
original: File = None,
encoding: str | None = 'utf-8',
errors: str | None = None,
newline: str | None = None,
encoder: Callable[[Any], str] = None,
decoder: Callable[[str], Any] = None,
)[source]#

Bases: JsonFileBase[Sorter]

JSON file handler for sorter configurations.

This class handles the serialization and deserialization of sorter configuration files within the datapack namespace.

snake_name: ClassVar[str] = 'sorter_file'[source]#
model[source]#

alias of Sorter

scope: ClassVar[NamespaceFileScope] = ('sorter',)[source]#
extension: ClassVar[str] = '.json'[source]#
data: ClassVar[FileDeserialize[Sorter]][source]#

Descriptor that makes sure that content of the file is deserialized.

extend_datapack#

beet_default(ctx: Context)[source]#

Extend the datapack namespace with the sorter resource type.

This function registers the SorterFile class with the datapack context, allowing sorter configuration files to be recognized and processed.

Parameters:

ctx – The beet context.

match#

generate_sorter(
ctx: Context,
sorter: JsonDict,
)[source]#

Generate sorting functions based on the specified algorithm.

Currently an abstraction layer in case more algorithms are added in the future. Routes to the appropriate algorithm-specific generator function.

Parameters:
  • ctx – The beet context for generating functions.

  • sorter – Configuration dictionary containing sorting parameters.

quick_sort#

Quick Sort Algorithm for Minecraft Storage Lists

This algorithm is less efficient than the Selection Sort algorithm for Minecraft due to the cost of macro calls. It is recommended to use Selection Sort.

Author: Darukshock

generate_quick_sort(
ctx: Context,
sorter: JsonDict,
) → None[source]#

Generate quick_sort algorithm functions for sorting storage lists.

This function creates a set of minecraft functions that implement the quick_sort algorithm to sort lists stored in minecraft storage. The algorithm is implemented using recursive function calls with macro parameters.

Parameters:
  • ctx – The beet context for generating functions.

  • sorter – Configuration dictionary containing sorting parameters.

selection_sort#

generate_selection_sort(
ctx: Context,
sorter: JsonDict,
) → None[source]#

Generate selection sort algorithm functions for sorting storage lists.

This function creates a set of minecraft functions that implement the selection sort algorithm to sort lists stored in minecraft storage. The algorithm finds the minimum element and moves it to a new sorted array repeatedly.

Parameters:
  • ctx – The beet context for generating functions.

  • sorter – Configuration dictionary containing sorting parameters.

silent#