1 local S = minetest.get_translator("testitems")
4 -- Texture overlays for items
7 -- For the global overlay color test
8 local GLOBAL_COLOR_ARG = "orange"
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)
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", "")
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",
39 on_use = overlay_on_use,
40 on_place = overlay_on_place,
41 on_secondary_use = overlay_on_place,
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,