light.lua 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. local S = minetest.get_translator("testtools")
  2. local function get_func(is_place)
  3. return function(itemstack, user, pointed_thing)
  4. local pos
  5. if is_place then
  6. pos = pointed_thing.under
  7. else
  8. pos = pointed_thing.above
  9. end
  10. if pointed_thing.type ~= "node" or not pos then
  11. return
  12. end
  13. local node = minetest.get_node(pos)
  14. local pstr = minetest.pos_to_string(pos)
  15. local time = minetest.get_timeofday()
  16. local sunlight = minetest.get_natural_light(pos)
  17. local artificial = minetest.get_artificial_light(node.param1)
  18. local message = ("pos=%s | param1=0x%02x | " ..
  19. "sunlight=%d | artificial=%d | timeofday=%.5f" )
  20. :format(pstr, node.param1, sunlight, artificial, time)
  21. minetest.chat_send_player(user:get_player_name(), message)
  22. end
  23. end
  24. minetest.register_tool("testtools:lighttool", {
  25. description = S("Light Tool") .. "\n" ..
  26. S("Show light values of node") .. "\n" ..
  27. S("Punch: Light of node above touched node") .. "\n" ..
  28. S("Place: Light of touched node itself"),
  29. inventory_image = "testtools_lighttool.png",
  30. groups = { testtool = 1, disable_repair = 1 },
  31. on_use = get_func(false),
  32. on_place = get_func(true),
  33. })