]> git.lizzy.rs Git - dragonfireclient.git/blob - games/devtest/mods/testitems/init.lua
DevTest: Add nodes and items for testing overlays (#12304)
[dragonfireclient.git] / games / devtest / mods / testitems / init.lua
1 local S = minetest.get_translator("testitems")
2
3 --
4 -- Texture overlays for items
5 --
6
7 -- For the global overlay color test
8 local GLOBAL_COLOR_ARG = "orange"
9
10 -- Punch handler to set random color with "color" argument in item metadata
11 local overlay_on_use = function(itemstack, user, pointed_thing)
12         local meta = itemstack:get_meta()
13         local color = math.random(0x0, 0xFFFFFF)
14         local colorstr = string.format("#%06x", color)
15         meta:set_string("color", colorstr)
16         minetest.log("action", "[testitems] Color of "..itemstack:get_name().." changed to "..colorstr)
17         return itemstack
18 end
19 -- Place handler to clear item metadata color
20 local overlay_on_place = function(itemstack, user, pointed_thing)
21         local meta = itemstack:get_meta()
22         meta:set_string("color", "")
23         return itemstack
24 end
25
26 minetest.register_craftitem("testitems:overlay_meta", {
27         description = S("Texture Overlay Test Item, Meta Color") .. "\n" ..
28                 S("Image must be a square with rainbow cross (inventory and wield)") .. "\n" ..
29                 S("Item meta color must only change square color") .. "\n" ..
30                 S("Punch: Set random color") .. "\n" ..
31                 S("Place: Clear color"),
32         -- Base texture: A grayscale square (can be colorized)
33         inventory_image = "testitems_overlay_base.png",
34         wield_image = "testitems_overlay_base.png",
35         -- Overlay: A rainbow cross (NOT to be colorized!)
36         inventory_overlay = "testitems_overlay_overlay.png",
37         wield_overlay = "testitems_overlay_overlay.png",
38
39         on_use = overlay_on_use,
40         on_place = overlay_on_place,
41         on_secondary_use = overlay_on_place,
42 })
43 minetest.register_craftitem("testitems:overlay_global", {
44         description = S("Texture Overlay Test Item, Global Color") .. "\n" ..
45                 S("Image must be an orange square with rainbow cross (inventory and wield)"),
46         -- Base texture: A grayscale square (to be colorized)
47         inventory_image = "testitems_overlay_base.png",
48         wield_image = "testitems_overlay_base.png",
49         -- Overlay: A rainbow cross (NOT to be colorized!)
50         inventory_overlay = "testitems_overlay_overlay.png",
51         wield_overlay = "testitems_overlay_overlay.png",
52         color = GLOBAL_COLOR_ARG,
53 })
54
55