allow firing with formspec

This commit is contained in:
Thomas Rudin 2018-04-24 11:24:41 +02:00
parent 24f8bf7079
commit bb1e1a44ef
2 changed files with 39 additions and 4 deletions

@ -61,9 +61,7 @@ local register_spacecannon = function(color, range, timeout, speed)
mesecons = {effector = { mesecons = {effector = {
action_on = function (pos, node) action_on = function (pos, node)
local dir = spacecannon.facedir_to_down_dir(node.param2) spacecannon.fire(pos, color, speed)
local obj = minetest.add_entity({x=pos.x+dir.x, y=pos.y+dir.y, z=pos.z+dir.z}, "spacecannon:energycube_" .. color)
obj:setvelocity({x=dir.x*speed, y=dir.y*speed, z=dir.z*speed})
end end
}}, }},
@ -79,12 +77,24 @@ local register_spacecannon = function(color, range, timeout, speed)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
meta:set_int("powerstorage", 0) meta:set_int("powerstorage", 0)
local inv = meta:get_inventory()
inv:set_size("main", 8)
if has_technic_mod then if has_technic_mod then
meta:set_int("HV_EU_input", 0) meta:set_int("HV_EU_input", 0)
meta:set_int("HV_EU_demand", 0) meta:set_int("HV_EU_demand", 0)
end end
spacecannon.update_formspec(meta)
end, end,
can_dig = function(pos,player)
local meta = minetest.get_meta(pos);
local inv = meta:get_inventory()
return inv:is_empty("main")
end,
technic_run = function(pos, node) technic_run = function(pos, node)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local eu_input = meta:get_int("HV_EU_input") local eu_input = meta:get_int("HV_EU_input")
@ -102,7 +112,16 @@ local register_spacecannon = function(color, range, timeout, speed)
-- charged -- charged
meta:set_int("HV_EU_demand", 0) meta:set_int("HV_EU_demand", 0)
end end
end,
on_receive_fields = function(pos, formname, fields, sender)
local meta = minetest.get_meta(pos);
if fields.fire then
spacecannon.fire(pos, color, speed)
end end
end
}) })
if has_technic_mod then if has_technic_mod then

@ -1,5 +1,21 @@
spacecannon.update_formspec = function(meta)
meta:set_string("formspec", "size[8,10;]" ..
"button_exit[0,2;8,1;fire;Fire]" ..
"list[context;main;0,3;8,1;]" ..
"list[current_player;main;0,5;8,4;]")
end
spacecannon.fire = function(pos, color, speed)
local node = minetest.get_node(pos)
local dir = spacecannon.facedir_to_down_dir(node.param2)
local obj = minetest.add_entity({x=pos.x+dir.x, y=pos.y+dir.y, z=pos.z+dir.z}, "spacecannon:energycube_" .. color)
obj:setvelocity({x=dir.x*speed, y=dir.y*speed, z=dir.z*speed})
end
-- destroy stuff in range -- destroy stuff in range
spacecannon.destroy = function(pos,range) spacecannon.destroy = function(pos,range)
for x=-range,range do for x=-range,range do