mirror of
https://github.com/pandorabox-io/spacecannon.git
synced 2024-12-21 05:15:47 +01:00
allow firing with formspec
This commit is contained in:
parent
24f8bf7079
commit
bb1e1a44ef
27
cannon.lua
27
cannon.lua
@ -30,7 +30,7 @@ local register_spacecannon = function(color, range, timeout, speed)
|
||||
-- self.on_player_hit(self,pos,player)
|
||||
end
|
||||
end
|
||||
elseif node.name ~= "air" then
|
||||
elseif node.name ~= "air" then
|
||||
-- collision
|
||||
spacecannon.destroy(pos, range)
|
||||
self.object:remove()
|
||||
@ -61,9 +61,7 @@ local register_spacecannon = function(color, range, timeout, speed)
|
||||
|
||||
mesecons = {effector = {
|
||||
action_on = function (pos, node)
|
||||
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})
|
||||
spacecannon.fire(pos, color, speed)
|
||||
end
|
||||
}},
|
||||
|
||||
@ -79,12 +77,24 @@ local register_spacecannon = function(color, range, timeout, speed)
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_int("powerstorage", 0)
|
||||
|
||||
local inv = meta:get_inventory()
|
||||
inv:set_size("main", 8)
|
||||
|
||||
if has_technic_mod then
|
||||
meta:set_int("HV_EU_input", 0)
|
||||
meta:set_int("HV_EU_demand", 0)
|
||||
end
|
||||
|
||||
spacecannon.update_formspec(meta)
|
||||
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)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local eu_input = meta:get_int("HV_EU_input")
|
||||
@ -102,7 +112,16 @@ local register_spacecannon = function(color, range, timeout, speed)
|
||||
-- charged
|
||||
meta:set_int("HV_EU_demand", 0)
|
||||
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
|
||||
|
||||
})
|
||||
|
||||
if has_technic_mod then
|
||||
|
16
util.lua
16
util.lua
@ -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
|
||||
spacecannon.destroy = function(pos,range)
|
||||
for x=-range,range do
|
||||
|
Loading…
Reference in New Issue
Block a user