[Mod] GroupLib: General Grouping API [grouplib]

Post Reply
User avatar
rudzik8
Member
Posts: 245
Joined: Wed Jun 02, 2021 04:13
GitHub: rudzik8
In-game: db75c and rudzik8
Location: Siberia

[Mod] GroupLib: General Grouping API [grouplib]

by rudzik8 » Post

GroupLib: General Grouping API

A robust and optimized solution for all your grouping needs.

Usage

grouplib.item_get(name)

Gets the groups of an item by name.

Either returns a table or nil.

Code: Select all

groups = grouplib.item_get("sand")

grouplib.item_set(name, groups)

Sets the groups of an item by name.

This is not the same as just plain overriding, because this doesn't replace the entire groups table of an item, only update it with new values; if you want to do the former then use grouplib.item_replace.

Code: Select all

grouplib.item_set("sand", {yellow = 1, crumbly = -1, magic = 9})

grouplib.item_replace(name, groups)

Replaces the groups of an item by name.

The old groups are completely thrown out; if what you want to do is to update the existing values then use grouplib.item_set.

Code: Select all

grouplib.item_replace("sand", {oddly_breakable_by_hand = 1})

grouplib.item_get_rating(name, ...)

Gets the ratings of groups of an item by its name and group names.

The amount of return values will be the same as the amount of secondary arguments passed to the function.

Code: Select all

one, two, three = grouplib.item_get_rating("sand", "crumbly", "falling_node", "soil")

grouplib.group_override(group, override)

Bulk-overrides all items with specified group (~= 0) with the override table.

Values are added to a queue on call and the overrides are performed after all mods have loaded.

Keep in mind this is basically a wrapper for minetest.override_item.

Code: Select all

grouplib.group_override("leaves", {drawtype = "firelike"})

License

The license of the source code is MIT. See LICENSE file for details.
Maintainer of Voxelgarden and VoxeLibre dev and modder || Codeberg

Post Reply