infotext.lua 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. local S = minetest.get_translator("kilns")
  2. local function get_description(stack)
  3. local def = minetest.registered_items[stack:get_name()]
  4. if def then
  5. return def.description or S("Unknown Item")
  6. else
  7. return S("Unknown Item")
  8. end
  9. end
  10. local function get_contents(fuelstack, instack, outstack)
  11. local str = S("Kiln") ..
  12. "\n" .. S("Contents") ..
  13. "\n" .. S("Fuel") .. ": "
  14. str = str .. fuelstack:get_count() .. "\n"
  15. if not instack:is_empty()
  16. then
  17. str = str .. S("To smelt") .. ": " .. get_description(instack) ..
  18. ": " .. instack:get_count() .. "\n"
  19. end
  20. if not outstack:is_empty()
  21. then
  22. str = str .. S("Finished smelting") .. ": " .. get_description(outstack) ..
  23. ": " .. outstack:get_count() .. "\n"
  24. end
  25. return str
  26. end
  27. local empty_text = S([[Empty Kiln
  28. Use to put in items
  29. Punch to take out a single item
  30. Hold Special to process a whole stack at once
  31. ]])
  32. local function update_infotext(meta, burning)
  33. local inv = meta:get_inventory()
  34. local fuelstack = inv:get_stack("fuel", 1)
  35. local instack = inv:get_stack("in", 1)
  36. local outstack = inv:get_stack("out", 1)
  37. local infotext
  38. if fuelstack:is_empty() and
  39. instack:is_empty() and
  40. outstack:is_empty()
  41. then
  42. infotext = empty_text
  43. else
  44. infotext = get_contents(fuelstack, instack, outstack)
  45. end
  46. meta:set_string("infotext", infotext)
  47. end
  48. return update_infotext