🔀 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,
Bases:
BaseModelConfiguration 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.
- 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,
Bases:
JsonFileBase[Sorter]JSON file handler for sorter configurations.
This class handles the serialization and deserialization of sorter configuration files within the datapack namespace.
extend_datapack#
match#
- generate_sorter(
- ctx: Context,
- sorter: JsonDict,
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,
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,
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.