mirror of
https://github.com/pandorabox-io/spacecannon.git
synced 2024-12-30 09:37: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 = {
|
||||
action_on = function (pos, node)
|
||||
spacecannon.fire(pos, color, speed)
|
||||
spacecannon.fire(pos, color, speed, range)
|
||||
end
|
||||
}},
|
||||
|
||||
@ -103,7 +103,7 @@ local register_spacecannon = function(color, range, timeout, speed)
|
||||
|
||||
meta:set_string("infotext", "Power: " .. eu_input .. "/" .. demand .. " Store: " .. store)
|
||||
|
||||
if store < spacecannon.config.powerstorage then
|
||||
if store < spacecannon.config.powerstorage * range then
|
||||
-- charge
|
||||
meta:set_int("HV_EU_demand", spacecannon.config.powerrequirement)
|
||||
store = store + eu_input
|
||||
@ -118,7 +118,7 @@ local register_spacecannon = function(color, range, timeout, speed)
|
||||
local meta = minetest.get_meta(pos);
|
||||
|
||||
if fields.fire then
|
||||
spacecannon.fire(pos, color, speed)
|
||||
spacecannon.fire(pos, color, speed, range)
|
||||
end
|
||||
end
|
||||
|
||||
|
7
init.lua
7
init.lua
@ -2,11 +2,16 @@
|
||||
spacecannon = {
|
||||
config = {
|
||||
-- technic EU storage value
|
||||
powerstorage = 100000,
|
||||
powerstorage = 10000,
|
||||
|
||||
-- charge value in EU
|
||||
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;]")
|
||||
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 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)
|
||||
|
Loading…
Reference in New Issue
Block a user