diff options
author | Vanessa Dannenberg <vanessa.e.dannenberg@gmail.com> | 2018-09-12 18:32:38 -0400 |
---|---|---|
committer | Vanessa Dannenberg <vanessa.e.dannenberg@gmail.com> | 2018-09-12 20:19:07 -0400 |
commit | 4b8899736084cee9bb3ac1090ea9f3f7275d573a (patch) | |
tree | 97fc5f1990ca44908dcb2447d338698bbec9833d | |
parent | ef7d357e0b51938a42c4bdbfe22ce68079283d1a (diff) | |
download | unifieddyes-4b8899736084cee9bb3ac1090ea9f3f7275d573a.tar unifieddyes-4b8899736084cee9bb3ac1090ea9f3f7275d573a.tar.gz unifieddyes-4b8899736084cee9bb3ac1090ea9f3f7275d573a.tar.bz2 unifieddyes-4b8899736084cee9bb3ac1090ea9f3f7275d573a.tar.xz unifieddyes-4b8899736084cee9bb3ac1090ea9f3f7275d573a.zip |
add helper function for registering split palette nodes
-rw-r--r-- | API.md | 5 | ||||
-rw-r--r-- | init.lua | 29 |
2 files changed, 34 insertions, 0 deletions
@@ -123,6 +123,11 @@ This will loop through all of Unified Dyes' color lists, generating one recipe f Makes a colored itemstack out of the given `itemstack` and `color` (as a dye, e.g. "dye:dark_red_s50"), setting the correct index per the `palette` field, which works as described above for `unifieddyes.getpaletteidx()`. Said itemstack is returned as a string suitable for use as the output field of a craft recipe, equal in size to the itemstack passed into the function (e.g. if you give it "mymod:colored_node 7", it'll return a stack of 7 colored items). +**`unifieddyes.generate_split_palette_nodes(name, def, drop)`** + +Does just what it sounds like - it registers all the nodes that are needed for a given base node (`def`) to be able to use the split palette, each named according to `name`, with the palette hue appended. If a custom drop is needed, it can be passed along (only a string is allowed here, specifying a single item). + + #### Tables In addition to the above API calls, Unified Dyes provides several useful tables @@ -206,6 +206,35 @@ end function unifieddyes.after_dig_node(foo) end +-- This helper function creates multiple copies of the passed node, +-- for the split palette - one per hue, plus grey - and assigns +-- proper palettes and other attributes + +function unifieddyes.generate_split_palette_nodes(name, def, drop) + for _, color in ipairs(unifieddyes.HUES_WITH_GREY) do + local def2 = table.copy(def) + local desc_color = string.gsub(string.upper(string.sub(color, 1, 1))..string.sub(color, 2), "_", " ") + if string.sub(def2.description, -1) == ")" then + def2.description = string.sub(def2.description, 1, -2)..", "..desc_color..")" + else + def2.description = def2.description.."("..desc_color..")" + end + def2.palette = "unifieddyes_palette_"..color.."s.png" + def2.paramtype2 = "colorfacedir" + def2.groups.ud_param2_colorable = 1 + + if drop then + def2.drop = { + items = { + {items = {drop.."_"..color}, inherit_color = true }, + } + } + end + + minetest.register_node(":"..name.."_"..color, def2) + end +end + -- This helper function creates a colored itemstack function unifieddyes.make_colored_itemstack(item, palette, color) |