mirror of
https://github.com/pandorabox-io/spacecannon.git
synced 2025-01-02 02:57:29 +01:00
use up mese crystals
This commit is contained in:
parent
bb1e1a44ef
commit
b33fd0cb5e
@ -61,7 +61,7 @@ local register_spacecannon = function(color, range, timeout, speed)
|
|||||||
|
|
||||||
mesecons = {effector = {
|
mesecons = {effector = {
|
||||||
action_on = function (pos, node)
|
action_on = function (pos, node)
|
||||||
spacecannon.fire(pos, color, speed)
|
spacecannon.fire(pos, color, speed, range)
|
||||||
end
|
end
|
||||||
}},
|
}},
|
||||||
|
|
||||||
@ -103,7 +103,7 @@ local register_spacecannon = function(color, range, timeout, speed)
|
|||||||
|
|
||||||
meta:set_string("infotext", "Power: " .. eu_input .. "/" .. demand .. " Store: " .. store)
|
meta:set_string("infotext", "Power: " .. eu_input .. "/" .. demand .. " Store: " .. store)
|
||||||
|
|
||||||
if store < spacecannon.config.powerstorage then
|
if store < spacecannon.config.powerstorage * range then
|
||||||
-- charge
|
-- charge
|
||||||
meta:set_int("HV_EU_demand", spacecannon.config.powerrequirement)
|
meta:set_int("HV_EU_demand", spacecannon.config.powerrequirement)
|
||||||
store = store + eu_input
|
store = store + eu_input
|
||||||
@ -118,7 +118,7 @@ local register_spacecannon = function(color, range, timeout, speed)
|
|||||||
local meta = minetest.get_meta(pos);
|
local meta = minetest.get_meta(pos);
|
||||||
|
|
||||||
if fields.fire then
|
if fields.fire then
|
||||||
spacecannon.fire(pos, color, speed)
|
spacecannon.fire(pos, color, speed, range)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
7
init.lua
7
init.lua
@ -2,11 +2,16 @@
|
|||||||
spacecannon = {
|
spacecannon = {
|
||||||
config = {
|
config = {
|
||||||
-- technic EU storage value
|
-- technic EU storage value
|
||||||
powerstorage = 100000,
|
powerstorage = 10000,
|
||||||
|
|
||||||
-- charge value in EU
|
-- charge value in EU
|
||||||
powerrequirement = 2500,
|
powerrequirement = 2500,
|
||||||
|
|
||||||
|
-- fuel item and count
|
||||||
|
power_item = "default:mese_crystal",
|
||||||
|
power_item_count = 1
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
26
util.lua
26
util.lua
@ -9,7 +9,31 @@ spacecannon.update_formspec = function(meta)
|
|||||||
"list[current_player;main;0,5;8,4;]")
|
"list[current_player;main;0,5;8,4;]")
|
||||||
end
|
end
|
||||||
|
|
||||||
spacecannon.fire = function(pos, color, speed)
|
spacecannon.fire = function(pos, color, speed, range)
|
||||||
|
-- check fuel/power
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
local owner = meta:get_string("owner")
|
||||||
|
|
||||||
|
if meta:get_int("powerstorage") < spacecannon.config.powerstorage * range then
|
||||||
|
|
||||||
|
-- check inventory
|
||||||
|
local inv = meta:get_inventory()
|
||||||
|
local power_item = spacecannon.config.power_item
|
||||||
|
local power_item_count = spacecannon.config.power_item_count * range
|
||||||
|
|
||||||
|
if not inv:contains_item("main", {name=power_item, count=power_item_count}) then
|
||||||
|
minetest.chat_send_player(owner, "Not enough fuel to fire cannon, expected " .. power_item_count .. " " .. power_item)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
-- use up items
|
||||||
|
inv:remove_item("main", {name=power_item, count=power_item_count})
|
||||||
|
else
|
||||||
|
-- use power
|
||||||
|
meta:set_int("powerstorage", 0)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
local node = minetest.get_node(pos)
|
local node = minetest.get_node(pos)
|
||||||
local dir = spacecannon.facedir_to_down_dir(node.param2)
|
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)
|
local obj = minetest.add_entity({x=pos.x+dir.x, y=pos.y+dir.y, z=pos.z+dir.z}, "spacecannon:energycube_" .. color)
|
||||||
|
Loading…
Reference in New Issue
Block a user