generator.lua 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. minetest.register_node("rangedweapons:generator", {
  2. description = "" ..core.colorize("#35cdff","Power particle generator\n")..core.colorize("#FFFFFF", "generates 1 power particle every 3 seconds (can hold up to 200). Punch to harvest them"),
  3. tiles = {
  4. "rangedweapons_generator_top.png",
  5. "rangedweapons_generator_bottom.png",
  6. "rangedweapons_generator_side.png",
  7. "rangedweapons_generator_side.png",
  8. "rangedweapons_generator_side.png",
  9. "rangedweapons_generator_side.png"
  10. },
  11. paramtype = "light",
  12. light_source = 9,
  13. groups = {cracky = 3, oddly_breakable_by_hand = 3},
  14. on_timer = function(pos, elapsed)
  15. minetest.get_node_timer(pos):start(3)
  16. local nodemeta = minetest.get_meta(pos)
  17. if nodemeta:get_int("power_generated") < 200 then
  18. nodemeta:set_int("power_generated",nodemeta:get_int("power_generated")+1)
  19. nodemeta:set_string("infotext", "currently generated power:"..nodemeta:get_int("power_generated"))
  20. end
  21. end,
  22. on_punch = function(pos, node, puncher)
  23. local nodemeta = minetest.get_meta(pos)
  24. local inv = puncher:get_inventory()
  25. inv:add_item("main", "rangedweapons:power_particle "..nodemeta:get_int("power_generated"))
  26. nodemeta:set_int("power_generated",0)
  27. nodemeta:set_string("infotext", "currently generated power:"..nodemeta:get_int("power_generated"))
  28. end,
  29. on_construct = function(pos)
  30. minetest.get_node_timer(pos):start(3)
  31. end,
  32. sounds = default.node_sound_wood_defaults(),
  33. })