-
Notifications
You must be signed in to change notification settings - Fork 3
/
generator.lua
39 lines (33 loc) · 1.42 KB
/
generator.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
minetest.register_node("rangedweapons:generator", {
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"),
tiles = {
"rangedweapons_generator_top.png",
"rangedweapons_generator_bottom.png",
"rangedweapons_generator_side.png",
"rangedweapons_generator_side.png",
"rangedweapons_generator_side.png",
"rangedweapons_generator_side.png"
},
paramtype = "light",
light_source = 9,
groups = {cracky = 3, oddly_breakable_by_hand = 3},
on_timer = function(pos, elapsed)
minetest.get_node_timer(pos):start(3)
local nodemeta = minetest.get_meta(pos)
if nodemeta:get_int("power_generated") < 200 then
nodemeta:set_int("power_generated",nodemeta:get_int("power_generated")+1)
nodemeta:set_string("infotext", "currently generated power:"..nodemeta:get_int("power_generated"))
end
end,
on_punch = function(pos, node, puncher)
local nodemeta = minetest.get_meta(pos)
local inv = puncher:get_inventory()
inv:add_item("main", "rangedweapons:power_particle "..nodemeta:get_int("power_generated"))
nodemeta:set_int("power_generated",0)
nodemeta:set_string("infotext", "currently generated power:"..nodemeta:get_int("power_generated"))
end,
on_construct = function(pos)
minetest.get_node_timer(pos):start(3)
end,
sounds = default.node_sound_wood_defaults(),
})