aboutsummaryrefslogtreecommitdiff
path: root/games/devtest/mods/testitems/init.lua
diff options
context:
space:
mode:
authorElias Fleckenstein <eliasfleckenstein@web.de>2022-06-02 20:54:02 +0200
committerElias Fleckenstein <eliasfleckenstein@web.de>2022-06-02 20:54:02 +0200
commit827b9f8d7054158b058679999d77c1345162a293 (patch)
treeb03741002579b03d3657c1e496e73993e4070fa9 /games/devtest/mods/testitems/init.lua
parent3ff3103e98b350712543f926c429ab339700e252 (diff)
parent9fc018ded10225589d2559d24a5db739e891fb31 (diff)
downloaddragonfireclient-827b9f8d7054158b058679999d77c1345162a293.tar.xz
Merge branch 'master' of https://github.com/minetest/minetest
Diffstat (limited to 'games/devtest/mods/testitems/init.lua')
-rw-r--r--games/devtest/mods/testitems/init.lua55
1 files changed, 55 insertions, 0 deletions
diff --git a/games/devtest/mods/testitems/init.lua b/games/devtest/mods/testitems/init.lua
new file mode 100644
index 000000000..33ebf50fc
--- /dev/null
+++ b/games/devtest/mods/testitems/init.lua
@@ -0,0 +1,55 @@
+local S = minetest.get_translator("testitems")
+
+--
+-- Texture overlays for items
+--
+
+-- For the global overlay color test
+local GLOBAL_COLOR_ARG = "orange"
+
+-- Punch handler to set random color with "color" argument in item metadata
+local overlay_on_use = function(itemstack, user, pointed_thing)
+ local meta = itemstack:get_meta()
+ local color = math.random(0x0, 0xFFFFFF)
+ local colorstr = string.format("#%06x", color)
+ meta:set_string("color", colorstr)
+ minetest.log("action", "[testitems] Color of "..itemstack:get_name().." changed to "..colorstr)
+ return itemstack
+end
+-- Place handler to clear item metadata color
+local overlay_on_place = function(itemstack, user, pointed_thing)
+ local meta = itemstack:get_meta()
+ meta:set_string("color", "")
+ return itemstack
+end
+
+minetest.register_craftitem("testitems:overlay_meta", {
+ description = S("Texture Overlay Test Item, Meta Color") .. "\n" ..
+ S("Image must be a square with rainbow cross (inventory and wield)") .. "\n" ..
+ S("Item meta color must only change square color") .. "\n" ..
+ S("Punch: Set random color") .. "\n" ..
+ S("Place: Clear color"),
+ -- Base texture: A grayscale square (can be colorized)
+ inventory_image = "testitems_overlay_base.png",
+ wield_image = "testitems_overlay_base.png",
+ -- Overlay: A rainbow cross (NOT to be colorized!)
+ inventory_overlay = "testitems_overlay_overlay.png",
+ wield_overlay = "testitems_overlay_overlay.png",
+
+ on_use = overlay_on_use,
+ on_place = overlay_on_place,
+ on_secondary_use = overlay_on_place,
+})
+minetest.register_craftitem("testitems:overlay_global", {
+ description = S("Texture Overlay Test Item, Global Color") .. "\n" ..
+ S("Image must be an orange square with rainbow cross (inventory and wield)"),
+ -- Base texture: A grayscale square (to be colorized)
+ inventory_image = "testitems_overlay_base.png",
+ wield_image = "testitems_overlay_base.png",
+ -- Overlay: A rainbow cross (NOT to be colorized!)
+ inventory_overlay = "testitems_overlay_overlay.png",
+ wield_overlay = "testitems_overlay_overlay.png",
+ color = GLOBAL_COLOR_ARG,
+})
+
+