mirror of
https://github.com/sirrobzeroone/elepower.git
synced 2024-08-20 12:54:05 +02:00
Mesecons and toggleable machines!
This commit is contained in:
parent
65102544f6
commit
674703f31e
@ -79,11 +79,12 @@ local function harvest(pos, harvested, fdir)
|
|||||||
return harvested
|
return harvested
|
||||||
end
|
end
|
||||||
|
|
||||||
local function get_formspec(timer, power, sludge)
|
local function get_formspec(timer, power, sludge, state)
|
||||||
return "size[8,8.5]"..
|
return "size[8,8.5]"..
|
||||||
default.gui_bg..
|
default.gui_bg..
|
||||||
default.gui_bg_img..
|
default.gui_bg_img..
|
||||||
default.gui_slots..
|
default.gui_slots..
|
||||||
|
ele.formspec.state_switcher(7, 2.5, state)..
|
||||||
ele.formspec.power_meter(power)..
|
ele.formspec.power_meter(power)..
|
||||||
ele.formspec.fluid_bar(7, 0, sludge)..
|
ele.formspec.fluid_bar(7, 0, sludge)..
|
||||||
ele.formspec.create_bar(1, 0, 100 - timer, "#00ff11", true)..
|
ele.formspec.create_bar(1, 0, 100 - timer, "#00ff11", true)..
|
||||||
@ -108,7 +109,11 @@ local function on_timer(pos, elapsed)
|
|||||||
local work = meta:get_int("src_time")
|
local work = meta:get_int("src_time")
|
||||||
local sludge = fluid_lib.get_buffer_data(pos, "sludge")
|
local sludge = fluid_lib.get_buffer_data(pos, "sludge")
|
||||||
|
|
||||||
if storage > usage and sludge.amount + SLUDGE_PRODUCED < sludge.capacity then
|
local state = meta:get_int("state")
|
||||||
|
local is_enabled = ele.helpers.state_enabled(meta, pos, state)
|
||||||
|
local active = "Idle"
|
||||||
|
|
||||||
|
if storage > usage and sludge.amount + SLUDGE_PRODUCED < sludge.capacity and is_enabled then
|
||||||
if work == HARVESTER_TICK then
|
if work == HARVESTER_TICK then
|
||||||
local harvested = {}
|
local harvested = {}
|
||||||
|
|
||||||
@ -129,16 +134,24 @@ local function on_timer(pos, elapsed)
|
|||||||
work = work + 1
|
work = work + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
active = "Active"
|
||||||
refresh = true
|
refresh = true
|
||||||
ele.helpers.swap_node(pos, "elepower_farming:harvester_active")
|
ele.helpers.swap_node(pos, "elepower_farming:harvester_active")
|
||||||
else
|
else
|
||||||
|
if not is_enabled then
|
||||||
|
active = "Off"
|
||||||
|
end
|
||||||
|
|
||||||
ele.helpers.swap_node(pos, "elepower_farming:harvester")
|
ele.helpers.swap_node(pos, "elepower_farming:harvester")
|
||||||
end
|
end
|
||||||
|
|
||||||
local power = {capacity = capacity, storage = storage, usage = usage}
|
local power = {capacity = capacity, storage = storage, usage = usage}
|
||||||
local work_percent = math.floor((work / HARVESTER_TICK)*100)
|
local work_percent = math.floor((work / HARVESTER_TICK)*100)
|
||||||
|
|
||||||
meta:set_string("formspec", get_formspec(work_percent, power, sludge))
|
meta:set_string("formspec", get_formspec(work_percent, power, sludge, state))
|
||||||
|
meta:set_string("infotext", ("Harvester %s\n%s"):format(active,
|
||||||
|
ele.capacity_text(capacity, storage)))
|
||||||
|
|
||||||
meta:set_int("storage", storage)
|
meta:set_int("storage", storage)
|
||||||
meta:set_int("src_time", work)
|
meta:set_int("src_time", work)
|
||||||
|
|
||||||
|
@ -51,12 +51,13 @@ local ranges = {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
local function get_formspec(timer, power)
|
local function get_formspec(timer, power, state)
|
||||||
return "size[8,10]"..
|
return "size[8,10]"..
|
||||||
default.gui_bg..
|
default.gui_bg..
|
||||||
default.gui_bg_img..
|
default.gui_bg_img..
|
||||||
default.gui_slots..
|
default.gui_slots..
|
||||||
ele.formspec.power_meter(power)..
|
ele.formspec.power_meter(power)..
|
||||||
|
ele.formspec.state_switcher(7, 0, state)..
|
||||||
ele.formspec.create_bar(1, 0, 100 - timer, "#00ff11", true)..
|
ele.formspec.create_bar(1, 0, 100 - timer, "#00ff11", true)..
|
||||||
"list[context;layout;2.5,0;3,3;]"..
|
"list[context;layout;2.5,0;3,3;]"..
|
||||||
"list[context;src;0,3.5;8,2;]"..
|
"list[context;src;0,3.5;8,2;]"..
|
||||||
@ -231,7 +232,11 @@ local function on_timer(pos, elapsed)
|
|||||||
|
|
||||||
local work = meta:get_int("src_time")
|
local work = meta:get_int("src_time")
|
||||||
|
|
||||||
if storage > usage then
|
local state = meta:get_int("state")
|
||||||
|
local is_enabled = ele.helpers.state_enabled(meta, pos, state)
|
||||||
|
local active = "Idle"
|
||||||
|
|
||||||
|
if storage > usage and is_enabled then
|
||||||
if work == PLANTER_TICK then
|
if work == PLANTER_TICK then
|
||||||
local planted = 0
|
local planted = 0
|
||||||
for index, slot in ipairs(inv:get_list("layout")) do
|
for index, slot in ipairs(inv:get_list("layout")) do
|
||||||
@ -249,13 +254,19 @@ local function on_timer(pos, elapsed)
|
|||||||
work = work + 1
|
work = work + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
active = "Active"
|
||||||
refresh = true
|
refresh = true
|
||||||
|
elseif not is_enabled then
|
||||||
|
active = "Off"
|
||||||
end
|
end
|
||||||
|
|
||||||
local power = {capacity = capacity, storage = storage, usage = usage}
|
local power = {capacity = capacity, storage = storage, usage = usage}
|
||||||
local work_percent = math.floor((work / PLANTER_TICK)*100)
|
local work_percent = math.floor((work / PLANTER_TICK)*100)
|
||||||
|
|
||||||
meta:set_string("formspec", get_formspec(work_percent, power))
|
meta:set_string("formspec", get_formspec(work_percent, power, state))
|
||||||
|
meta:set_string("infotext", ("Planter %s\n%s"):format(active,
|
||||||
|
ele.capacity_text(capacity, storage)))
|
||||||
|
|
||||||
meta:set_int("storage", storage)
|
meta:set_int("storage", storage)
|
||||||
meta:set_int("src_time", work)
|
meta:set_int("src_time", work)
|
||||||
|
|
||||||
|
@ -89,12 +89,13 @@ local function spawn(pos, mob)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local function get_formspec(timer, power)
|
local function get_formspec(timer, power, state)
|
||||||
return "size[8,8.5]"..
|
return "size[8,8.5]"..
|
||||||
default.gui_bg..
|
default.gui_bg..
|
||||||
default.gui_bg_img..
|
default.gui_bg_img..
|
||||||
default.gui_slots..
|
default.gui_slots..
|
||||||
ele.formspec.power_meter(power)..
|
ele.formspec.power_meter(power)..
|
||||||
|
ele.formspec.state_switcher(7, 0, state)..
|
||||||
ele.formspec.create_bar(1, 0, 100 - timer, "#00ff11", true)..
|
ele.formspec.create_bar(1, 0, 100 - timer, "#00ff11", true)..
|
||||||
"list[context;src;3.5,1.5;1,1;]"..
|
"list[context;src;3.5,1.5;1,1;]"..
|
||||||
"image[3.5,1.5;1,1;elefarming_egg_silhouette.png]"..
|
"image[3.5,1.5;1,1;elefarming_egg_silhouette.png]"..
|
||||||
@ -117,11 +118,15 @@ local function on_timer(pos, elapsed)
|
|||||||
|
|
||||||
local work = meta:get_int("src_time")
|
local work = meta:get_int("src_time")
|
||||||
|
|
||||||
|
local state = meta:get_int("state")
|
||||||
|
local is_enabled = ele.helpers.state_enabled(meta, pos, state)
|
||||||
|
|
||||||
local egg_slot = inv:get_stack("src", 1)
|
local egg_slot = inv:get_stack("src", 1)
|
||||||
local egg_name = egg_slot:get_name()
|
local egg_name = egg_slot:get_name()
|
||||||
local mob_desc = "None"
|
local mob_desc = "None"
|
||||||
local active = "Active"
|
local active = "Active"
|
||||||
if storage > usage and not egg_slot:is_empty() and ele.helpers.get_item_group(egg_name, "spawn_egg") then
|
|
||||||
|
if storage > usage and not egg_slot:is_empty() and ele.helpers.get_item_group(egg_name, "spawn_egg") and is_enabled then
|
||||||
local mob_name = egg_name:gsub("_set", "")
|
local mob_name = egg_name:gsub("_set", "")
|
||||||
|
|
||||||
if work == SPAWNER_TICK then
|
if work == SPAWNER_TICK then
|
||||||
@ -142,6 +147,8 @@ local function on_timer(pos, elapsed)
|
|||||||
|
|
||||||
refresh = true
|
refresh = true
|
||||||
mob_desc = minetest.registered_items[mob_name].description
|
mob_desc = minetest.registered_items[mob_name].description
|
||||||
|
elseif not is_enabled then
|
||||||
|
active = "Off"
|
||||||
else
|
else
|
||||||
work = 0
|
work = 0
|
||||||
active = "Inactive"
|
active = "Inactive"
|
||||||
@ -153,7 +160,7 @@ local function on_timer(pos, elapsed)
|
|||||||
local power = {capacity = capacity, storage = storage, usage = usage}
|
local power = {capacity = capacity, storage = storage, usage = usage}
|
||||||
local work_percent = math.floor((work / SPAWNER_TICK)*100)
|
local work_percent = math.floor((work / SPAWNER_TICK)*100)
|
||||||
|
|
||||||
meta:set_string("formspec", get_formspec(work_percent, power))
|
meta:set_string("formspec", get_formspec(work_percent, power, state))
|
||||||
meta:set_int("storage", storage)
|
meta:set_int("storage", storage)
|
||||||
meta:set_int("src_time", work)
|
meta:set_int("src_time", work)
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
-- It accepts a recipe type registered beforehand.
|
-- It accepts a recipe type registered beforehand.
|
||||||
|
|
||||||
-- Specialized formspec for crafters
|
-- Specialized formspec for crafters
|
||||||
function ele.formspec.get_crafter_formspec(craft_type, power, percent)
|
function ele.formspec.get_crafter_formspec(craft_type, power, percent, pos, state)
|
||||||
local craftstats = elepm.craft.types[craft_type]
|
local craftstats = elepm.craft.types[craft_type]
|
||||||
local input_size = craftstats.inputs
|
local input_size = craftstats.inputs
|
||||||
|
|
||||||
@ -45,6 +45,7 @@ function ele.formspec.get_crafter_formspec(craft_type, power, percent)
|
|||||||
default.gui_bg_img..
|
default.gui_bg_img..
|
||||||
default.gui_slots..
|
default.gui_slots..
|
||||||
ele.formspec.power_meter(power)..
|
ele.formspec.power_meter(power)..
|
||||||
|
ele.formspec.state_switcher(7, 0, state)..
|
||||||
"list[context;src;"..x..","..y..";"..in_width..","..in_height..";]"..
|
"list[context;src;"..x..","..y..";"..in_width..","..in_height..";]"..
|
||||||
bar..
|
bar..
|
||||||
"list[context;dst;5,1;2,2;]"..
|
"list[context;dst;5,1;2,2;]"..
|
||||||
@ -92,11 +93,21 @@ function elepm.register_crafter(nodename, nodedef)
|
|||||||
local usage = ele.helpers.get_node_property(meta, pos, "usage")
|
local usage = ele.helpers.get_node_property(meta, pos, "usage")
|
||||||
local storage = ele.helpers.get_node_property(meta, pos, "storage")
|
local storage = ele.helpers.get_node_property(meta, pos, "storage")
|
||||||
local time = meta:get_int("src_time")
|
local time = meta:get_int("src_time")
|
||||||
|
local state = meta:get_int("state")
|
||||||
|
local status = "Idle"
|
||||||
|
|
||||||
|
local is_enabled = ele.helpers.state_enabled(meta, pos, state)
|
||||||
local res_time = 0
|
local res_time = 0
|
||||||
|
|
||||||
local pow_buffer = {capacity = capacity, storage = storage, usage = 0}
|
local pow_buffer = {capacity = capacity, storage = storage, usage = 0}
|
||||||
|
|
||||||
while true do
|
while true do
|
||||||
|
if not is_enabled then
|
||||||
|
time = 0
|
||||||
|
status = "Off"
|
||||||
|
break
|
||||||
|
end
|
||||||
|
|
||||||
local result = elepm.get_recipe(craft_type, inv:get_list("src"))
|
local result = elepm.get_recipe(craft_type, inv:get_list("src"))
|
||||||
local power_operation = false
|
local power_operation = false
|
||||||
|
|
||||||
@ -112,24 +123,22 @@ function elepm.register_crafter(nodename, nodedef)
|
|||||||
|
|
||||||
if result.time == 0 then
|
if result.time == 0 then
|
||||||
time = 0
|
time = 0
|
||||||
meta:set_string("infotext", ("%s Idle"):format(nodedef.description) ..
|
status = "Idle"
|
||||||
"\n" .. ele.capacity_text(capacity, storage))
|
|
||||||
else
|
else
|
||||||
meta:set_string("infotext", ("%s Out of Power!"):format(nodedef.description) ..
|
status = "Out of Power!"
|
||||||
"\n" .. ele.capacity_text(capacity, storage))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
|
|
||||||
refresh = true
|
refresh = true
|
||||||
|
status = "Active"
|
||||||
|
|
||||||
-- One step
|
-- One step
|
||||||
meta:set_int("storage", storage - usage)
|
storage = storage - usage
|
||||||
|
meta:set_int("storage", storage)
|
||||||
pow_buffer = {capacity = capacity, storage = storage, usage = usage}
|
pow_buffer = {capacity = capacity, storage = storage, usage = usage}
|
||||||
time = time + ele.helpers.round(machine_speed * 10)
|
time = time + ele.helpers.round(machine_speed * 10)
|
||||||
meta:set_string("infotext", ("%s Active"):format(nodedef.description) ..
|
|
||||||
"\n" .. ele.capacity_text(capacity, storage))
|
|
||||||
|
|
||||||
if nodedef.ele_active_node then
|
if nodedef.ele_active_node then
|
||||||
local active_node = nodename.."_active"
|
local active_node = nodename.."_active"
|
||||||
@ -166,8 +175,7 @@ function elepm.register_crafter(nodename, nodedef)
|
|||||||
if not room_for_output then
|
if not room_for_output then
|
||||||
ele.helpers.swap_node(pos, machine_node)
|
ele.helpers.swap_node(pos, machine_node)
|
||||||
time = ele.helpers.round(res_time*10)
|
time = ele.helpers.round(res_time*10)
|
||||||
meta:set_string("infotext", ("%s Output Full!"):format(nodedef.description) ..
|
status = "Output Full!"
|
||||||
"\n" .. ele.capacity_text(capacity, storage))
|
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -182,7 +190,9 @@ function elepm.register_crafter(nodename, nodedef)
|
|||||||
pct = math.floor((time / ele.helpers.round(res_time * 10)) * 100)
|
pct = math.floor((time / ele.helpers.round(res_time * 10)) * 100)
|
||||||
end
|
end
|
||||||
|
|
||||||
meta:set_string("formspec", get_formspec(craft_type, pow_buffer, pct, pos))
|
meta:set_string("formspec", get_formspec(craft_type, pow_buffer, pct, pos, state))
|
||||||
|
meta:set_string("infotext", ("%s %s"):format(nodedef.description, status) ..
|
||||||
|
"\n" .. ele.capacity_text(capacity, storage))
|
||||||
meta:set_int("src_time", time)
|
meta:set_int("src_time", time)
|
||||||
|
|
||||||
return refresh
|
return refresh
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
|
|
||||||
local function get_formspec_default(power, percent, buffer)
|
local function get_formspec_default(power, percent, buffer, state)
|
||||||
return "size[8,8.5]"..
|
return "size[8,8.5]"..
|
||||||
default.gui_bg..
|
default.gui_bg..
|
||||||
default.gui_bg_img..
|
default.gui_bg_img..
|
||||||
default.gui_slots..
|
default.gui_slots..
|
||||||
ele.formspec.power_meter(power)..
|
ele.formspec.power_meter(power)..
|
||||||
|
ele.formspec.state_switcher(7, 2.5, state)..
|
||||||
ele.formspec.fluid_bar(7, 0, buffer)..
|
ele.formspec.fluid_bar(7, 0, buffer)..
|
||||||
"image[3.5,1.5;1,1;default_furnace_fire_bg.png^[lowpart:"..
|
"image[3.5,1.5;1,1;default_furnace_fire_bg.png^[lowpart:"..
|
||||||
(percent)..":default_furnace_fire_fg.png]"..
|
(percent)..":default_furnace_fire_fg.png]"..
|
||||||
@ -58,12 +59,21 @@ function ele.register_fluid_generator(nodename, nodedef)
|
|||||||
local generation = ele.helpers.get_node_property(meta, pos, "usage")
|
local generation = ele.helpers.get_node_property(meta, pos, "usage")
|
||||||
local storage = ele.helpers.get_node_property(meta, pos, "storage")
|
local storage = ele.helpers.get_node_property(meta, pos, "storage")
|
||||||
|
|
||||||
|
local state = meta:get_int("state")
|
||||||
|
local is_enabled = ele.helpers.state_enabled(meta, pos, state)
|
||||||
|
|
||||||
-- Fluid buffer
|
-- Fluid buffer
|
||||||
local flbuffer = fluid_lib.get_buffer_data(pos, buffer_name)
|
local flbuffer = fluid_lib.get_buffer_data(pos, buffer_name)
|
||||||
local pow_buffer
|
local pow_buffer = {capacity = capacity, storage = storage, usage = 0}
|
||||||
if not flbuffer or flbuffer.fluid == "" then return false end
|
local status = "Idle"
|
||||||
|
|
||||||
while true do
|
while true do
|
||||||
|
if not flbuffer or flbuffer.fluid == "" then break end
|
||||||
|
if not is_enabled then
|
||||||
|
status = "Off"
|
||||||
|
break
|
||||||
|
end
|
||||||
|
|
||||||
-- If more to burn and the energy produced was used: produce some more
|
-- If more to burn and the energy produced was used: produce some more
|
||||||
if burn_time > 0 then
|
if burn_time > 0 then
|
||||||
if storage + generation > capacity then
|
if storage + generation > capacity then
|
||||||
@ -77,7 +87,7 @@ function ele.register_fluid_generator(nodename, nodedef)
|
|||||||
meta:set_int("burn_time", burn_time)
|
meta:set_int("burn_time", burn_time)
|
||||||
end
|
end
|
||||||
|
|
||||||
pow_buffer = {capacity = capacity, storage = storage, usage = 0}
|
status = "Active"
|
||||||
|
|
||||||
-- Burn another bucket of lava
|
-- Burn another bucket of lava
|
||||||
if burn_time == 0 then
|
if burn_time == 0 then
|
||||||
@ -95,10 +105,7 @@ function ele.register_fluid_generator(nodename, nodedef)
|
|||||||
|
|
||||||
refresh = true
|
refresh = true
|
||||||
else
|
else
|
||||||
meta:set_string("formspec", get_formspec(pow_buffer, 0, flbuffer))
|
status = "Idle"
|
||||||
meta:set_string("infotext", ("%s Idle\n%s\n%s"):format(nodedef.description,
|
|
||||||
ele.capacity_text(capacity, storage), fluid_lib.buffer_to_string(flbuffer)))
|
|
||||||
|
|
||||||
ele.helpers.swap_node(pos, nodename)
|
ele.helpers.swap_node(pos, nodename)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -107,8 +114,8 @@ function ele.register_fluid_generator(nodename, nodedef)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local percent = math.floor((burn_time / burn_totaltime) * 100)
|
local percent = math.floor((burn_time / burn_totaltime) * 100)
|
||||||
meta:set_string("formspec", get_formspec(pow_buffer, percent, flbuffer))
|
meta:set_string("formspec", get_formspec(pow_buffer, percent, flbuffer, state))
|
||||||
meta:set_string("infotext", ("%s Active\n%s\n%s"):format(nodedef.description,
|
meta:set_string("infotext", ("%s %s\n%s\n%s"):format(nodedef.description, status,
|
||||||
ele.capacity_text(capacity, storage), fluid_lib.buffer_to_string(flbuffer)))
|
ele.capacity_text(capacity, storage), fluid_lib.buffer_to_string(flbuffer)))
|
||||||
|
|
||||||
meta:set_int(buffer_name .. "_fluid_storage", flbuffer.amount)
|
meta:set_int(buffer_name .. "_fluid_storage", flbuffer.amount)
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
|
|
||||||
local function get_formspec_default(power, percent)
|
local function get_formspec_default(power, percent, state)
|
||||||
return "size[8,8.5]"..
|
return "size[8,8.5]"..
|
||||||
default.gui_bg..
|
default.gui_bg..
|
||||||
default.gui_bg_img..
|
default.gui_bg_img..
|
||||||
default.gui_slots..
|
default.gui_slots..
|
||||||
ele.formspec.power_meter(power)..
|
ele.formspec.power_meter(power)..
|
||||||
|
ele.formspec.state_switcher(7, 0, state)..
|
||||||
"list[context;src;3,1.5;1,1;]"..
|
"list[context;src;3,1.5;1,1;]"..
|
||||||
"image[4,1.5;1,1;default_furnace_fire_bg.png^[lowpart:"..
|
"image[4,1.5;1,1;default_furnace_fire_bg.png^[lowpart:"..
|
||||||
percent..":default_furnace_fire_fg.png]"..
|
percent..":default_furnace_fire_fg.png]"..
|
||||||
@ -44,22 +45,34 @@ function elepm.register_fuel_generator(nodename, nodedef)
|
|||||||
local generation = ele.helpers.get_node_property(meta, pos, "usage")
|
local generation = ele.helpers.get_node_property(meta, pos, "usage")
|
||||||
local storage = ele.helpers.get_node_property(meta, pos, "storage")
|
local storage = ele.helpers.get_node_property(meta, pos, "storage")
|
||||||
|
|
||||||
-- If more to burn and the energy produced was used: produce some more
|
local state = meta:get_int("state")
|
||||||
if burn_time > 0 then
|
local is_enabled = ele.helpers.state_enabled(meta, pos, state)
|
||||||
if storage + generation > capacity then
|
local status = "Idle"
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
storage = storage + generation
|
|
||||||
meta:set_int("storage", storage)
|
|
||||||
|
|
||||||
burn_time = burn_time - 1
|
|
||||||
meta:set_int("burn_time", burn_time)
|
|
||||||
end
|
|
||||||
|
|
||||||
local pow_buffer = {capacity = capacity, storage = storage, usage = 0}
|
local pow_buffer = {capacity = capacity, storage = storage, usage = 0}
|
||||||
|
|
||||||
while true do
|
while true do
|
||||||
|
if not is_enabled then
|
||||||
|
status = "Off"
|
||||||
|
break
|
||||||
|
end
|
||||||
|
|
||||||
|
-- If more to burn and the energy produced was used: produce some more
|
||||||
|
if burn_time > 0 then
|
||||||
|
if storage + generation > capacity then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
storage = storage + generation
|
||||||
|
pow_buffer.storage = storage
|
||||||
|
meta:set_int("storage", storage)
|
||||||
|
|
||||||
|
burn_time = burn_time - 1
|
||||||
|
meta:set_int("burn_time", burn_time)
|
||||||
|
end
|
||||||
|
|
||||||
|
status = "Active"
|
||||||
|
|
||||||
-- Burn another piece of fuel
|
-- Burn another piece of fuel
|
||||||
if burn_time == 0 then
|
if burn_time == 0 then
|
||||||
local inv = meta:get_inventory()
|
local inv = meta:get_inventory()
|
||||||
@ -88,9 +101,7 @@ function elepm.register_fuel_generator(nodename, nodedef)
|
|||||||
|
|
||||||
refresh = true
|
refresh = true
|
||||||
else
|
else
|
||||||
meta:set_string("formspec", get_formspec(pow_buffer, 0))
|
status = "Idle"
|
||||||
meta:set_string("infotext", ("%s Idle"):format(nodedef.description) ..
|
|
||||||
"\n" .. ele.capacity_text(capacity, storage))
|
|
||||||
ele.helpers.swap_node(pos, nodename)
|
ele.helpers.swap_node(pos, nodename)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -99,8 +110,8 @@ function elepm.register_fuel_generator(nodename, nodedef)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local percent = math.floor((burn_time / burn_totaltime) * 100)
|
local percent = math.floor((burn_time / burn_totaltime) * 100)
|
||||||
meta:set_string("formspec", get_formspec(pow_buffer, percent))
|
meta:set_string("formspec", get_formspec(pow_buffer, percent, state))
|
||||||
meta:set_string("infotext", ("%s Active"):format(nodedef.description) ..
|
meta:set_string("infotext", ("%s %s"):format(nodedef.description, status) ..
|
||||||
"\n" .. ele.capacity_text(capacity, storage))
|
"\n" .. ele.capacity_text(capacity, storage))
|
||||||
|
|
||||||
return refresh
|
return refresh
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
|
|
||||||
local function get_formspec(mode, buffer)
|
local function get_formspec(mode, buffer, state)
|
||||||
if not mode then
|
if not mode then
|
||||||
mode = 0
|
mode = 0
|
||||||
end
|
end
|
||||||
@ -13,6 +13,7 @@ local function get_formspec(mode, buffer)
|
|||||||
default.gui_bg..
|
default.gui_bg..
|
||||||
default.gui_bg_img..
|
default.gui_bg_img..
|
||||||
default.gui_slots..
|
default.gui_slots..
|
||||||
|
ele.formspec.state_switcher(0, 0, state)..
|
||||||
ele.formspec.fluid_bar(7, 0.75, buffer)..
|
ele.formspec.fluid_bar(7, 0.75, buffer)..
|
||||||
"list[context;src;3.5,1;1,1;]"..
|
"list[context;src;3.5,1;1,1;]"..
|
||||||
"list[context;dst;3.5,2;1,1;]"..
|
"list[context;dst;3.5,2;1,1;]"..
|
||||||
@ -35,38 +36,44 @@ local function on_timer(pos, elapsed)
|
|||||||
|
|
||||||
local buffer = fluid_lib.get_buffer_data(pos, "input")
|
local buffer = fluid_lib.get_buffer_data(pos, "input")
|
||||||
local mode = meta:get_int("mode")
|
local mode = meta:get_int("mode")
|
||||||
|
local state = meta:get_int("state")
|
||||||
|
|
||||||
|
local is_enabled = ele.helpers.state_enabled(meta, pos, state)
|
||||||
|
|
||||||
local bucket_slot = inv:get_stack("src", 1)
|
local bucket_slot = inv:get_stack("src", 1)
|
||||||
local bucket_name = bucket_slot:get_name()
|
local bucket_name = bucket_slot:get_name()
|
||||||
if mode == 0 and bucket_name == "bucket:bucket_empty" and buffer.amount >= 1000 then
|
|
||||||
-- Fill bucket
|
|
||||||
local bitem = bucket.liquids[buffer.fluid]
|
|
||||||
if bitem and bitem.itemname then
|
|
||||||
local bstack = ItemStack(bitem.itemname)
|
|
||||||
if inv:room_for_item("dst", bstack) then
|
|
||||||
inv:add_item("dst", bstack)
|
|
||||||
buffer.amount = buffer.amount - 1000
|
|
||||||
|
|
||||||
bucket_slot:take_item()
|
if is_enabled then
|
||||||
inv:set_stack("src", 1, bucket_slot)
|
if mode == 0 and bucket_name == "bucket:bucket_empty" and buffer.amount >= 1000 then
|
||||||
|
-- Fill bucket
|
||||||
|
local bitem = bucket.liquids[buffer.fluid]
|
||||||
|
if bitem and bitem.itemname then
|
||||||
|
local bstack = ItemStack(bitem.itemname)
|
||||||
|
if inv:room_for_item("dst", bstack) then
|
||||||
|
inv:add_item("dst", bstack)
|
||||||
|
buffer.amount = buffer.amount - 1000
|
||||||
|
|
||||||
refresh = true
|
bucket_slot:take_item()
|
||||||
|
inv:set_stack("src", 1, bucket_slot)
|
||||||
|
|
||||||
|
refresh = true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
elseif mode == 1 and bucket.get_liquid_for_bucket(bucket_name) then
|
||||||
elseif mode == 1 and bucket.get_liquid_for_bucket(bucket_name) then
|
-- Empty bucket
|
||||||
-- Empty bucket
|
local fluid = bucket.get_liquid_for_bucket(bucket_name)
|
||||||
local fluid = bucket.get_liquid_for_bucket(bucket_name)
|
if buffer.fluid == fluid or buffer.fluid == "" then
|
||||||
if buffer.fluid == fluid or buffer.fluid == "" then
|
local bitem = ItemStack("bucket:bucket_empty")
|
||||||
local bitem = ItemStack("bucket:bucket_empty")
|
if inv:room_for_item("dst", bitem) and buffer.amount + 1000 <= buffer.capacity then
|
||||||
if inv:room_for_item("dst", bitem) and buffer.amount + 1000 <= buffer.capacity then
|
buffer.amount = buffer.amount + 1000
|
||||||
buffer.amount = buffer.amount + 1000
|
buffer.fluid = fluid
|
||||||
buffer.fluid = fluid
|
inv:add_item("dst", bitem)
|
||||||
inv:add_item("dst", bitem)
|
|
||||||
|
|
||||||
bucket_slot:take_item()
|
bucket_slot:take_item()
|
||||||
inv:set_stack("src", 1, bucket_slot)
|
inv:set_stack("src", 1, bucket_slot)
|
||||||
|
|
||||||
refresh = true
|
refresh = true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -114,6 +121,7 @@ ele.register_base_device("elepower_machines:bucketer", {
|
|||||||
accepts = true,
|
accepts = true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
paramtype2 = "facedir",
|
||||||
on_timer = on_timer,
|
on_timer = on_timer,
|
||||||
on_construct = function (pos)
|
on_construct = function (pos)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
|
@ -16,7 +16,7 @@ local cooler_recipes = {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
local function get_formspec(item_percent, coolant_buffer, hot_buffer, power, recipes, recipe)
|
local function get_formspec(item_percent, coolant_buffer, hot_buffer, power, recipes, recipe, state)
|
||||||
local rclist = {}
|
local rclist = {}
|
||||||
|
|
||||||
local x = 2.5
|
local x = 2.5
|
||||||
@ -34,6 +34,7 @@ local function get_formspec(item_percent, coolant_buffer, hot_buffer, power, rec
|
|||||||
default.gui_bg_img..
|
default.gui_bg_img..
|
||||||
default.gui_slots..
|
default.gui_slots..
|
||||||
ele.formspec.power_meter(power)..
|
ele.formspec.power_meter(power)..
|
||||||
|
ele.formspec.state_switcher(3.5, 2.5, state)..
|
||||||
ele.formspec.fluid_bar(1, 0, coolant_buffer)..
|
ele.formspec.fluid_bar(1, 0, coolant_buffer)..
|
||||||
ele.formspec.fluid_bar(7, 0, hot_buffer)..
|
ele.formspec.fluid_bar(7, 0, hot_buffer)..
|
||||||
"list[context;dst;3.5,1.5;1,1;]"..
|
"list[context;dst;3.5,1.5;1,1;]"..
|
||||||
@ -50,7 +51,6 @@ local function get_formspec(item_percent, coolant_buffer, hot_buffer, power, rec
|
|||||||
default.get_hotbar_bg(0, 4.25)
|
default.get_hotbar_bg(0, 4.25)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
local function lava_cooler_timer(pos, elapsed)
|
local function lava_cooler_timer(pos, elapsed)
|
||||||
local refresh = false
|
local refresh = false
|
||||||
|
|
||||||
@ -69,7 +69,10 @@ local function lava_cooler_timer(pos, elapsed)
|
|||||||
local time = meta:get_int("src_time")
|
local time = meta:get_int("src_time")
|
||||||
local active = "Active"
|
local active = "Active"
|
||||||
|
|
||||||
if storage > usage then
|
local state = meta:get_int("state")
|
||||||
|
local is_enabled = ele.helpers.state_enabled(meta, pos, state)
|
||||||
|
|
||||||
|
if storage > usage and is_enabled then
|
||||||
if coolant_buffer.amount >= 1000 and hot_buffer.amount >= 1000 then
|
if coolant_buffer.amount >= 1000 and hot_buffer.amount >= 1000 then
|
||||||
if time >= TIME then
|
if time >= TIME then
|
||||||
local room_for_output = true
|
local room_for_output = true
|
||||||
@ -101,6 +104,8 @@ local function lava_cooler_timer(pos, elapsed)
|
|||||||
active = "Idle"
|
active = "Idle"
|
||||||
refresh = false
|
refresh = false
|
||||||
end
|
end
|
||||||
|
elseif not is_enabled then
|
||||||
|
active = "Off"
|
||||||
else
|
else
|
||||||
active = "Idle"
|
active = "Idle"
|
||||||
end
|
end
|
||||||
@ -113,7 +118,7 @@ local function lava_cooler_timer(pos, elapsed)
|
|||||||
meta:set_string("infotext", ("Lava Cooler %s\n%s"):format(active, ele.capacity_text(capacity, storage)))
|
meta:set_string("infotext", ("Lava Cooler %s\n%s"):format(active, ele.capacity_text(capacity, storage)))
|
||||||
|
|
||||||
meta:set_string("formspec", get_formspec(timer, coolant_buffer, hot_buffer,
|
meta:set_string("formspec", get_formspec(timer, coolant_buffer, hot_buffer,
|
||||||
power, cooler_recipes, recipe))
|
power, cooler_recipes, recipe, state))
|
||||||
|
|
||||||
return refresh
|
return refresh
|
||||||
end
|
end
|
||||||
@ -142,7 +147,7 @@ ele.register_machine("elepower_machines:lava_cooler", {
|
|||||||
inv:set_size("dst", 1)
|
inv:set_size("dst", 1)
|
||||||
|
|
||||||
meta:set_string("recipe", "default:cobble")
|
meta:set_string("recipe", "default:cobble")
|
||||||
meta:set_string("formspec", get_formspec(0,nil,nil,0,cooler_recipes, "default:cobble"))
|
meta:set_string("formspec", get_formspec(0,nil,nil,nil,cooler_recipes, "default:cobble"))
|
||||||
end,
|
end,
|
||||||
on_timer = lava_cooler_timer,
|
on_timer = lava_cooler_timer,
|
||||||
on_receive_fields = function (pos, formname, fields, sender)
|
on_receive_fields = function (pos, formname, fields, sender)
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
|
|
||||||
local function get_formspec(power, percent, buffer)
|
local function get_formspec(power, percent, buffer, state)
|
||||||
return "size[8,8.5]"..
|
return "size[8,8.5]"..
|
||||||
default.gui_bg..
|
default.gui_bg..
|
||||||
default.gui_bg_img..
|
default.gui_bg_img..
|
||||||
default.gui_slots..
|
default.gui_slots..
|
||||||
ele.formspec.power_meter(power)..
|
ele.formspec.power_meter(power)..
|
||||||
|
ele.formspec.state_switcher(3.5, 1.5, state)..
|
||||||
ele.formspec.fluid_bar(7, 0, buffer)..
|
ele.formspec.fluid_bar(7, 0, buffer)..
|
||||||
"list[current_player;main;0,4.25;8,1;]"..
|
"list[current_player;main;0,4.25;8,1;]"..
|
||||||
"list[current_player;main;0,5.5;8,3;8]"..
|
"list[current_player;main;0,5.5;8,3;8]"..
|
||||||
|
@ -1,6 +1,28 @@
|
|||||||
-- Formspec helpers
|
-- Formspec helpers
|
||||||
|
|
||||||
ele.formspec = {}
|
ele.formspec = {}
|
||||||
|
ele.formspec.gui_switcher_icons = {
|
||||||
|
[0] = "elepower_gui_check.png",
|
||||||
|
"elepower_gui_cancel.png",
|
||||||
|
"mesecons_wire_on.png",
|
||||||
|
"mesecons_wire_off.png",
|
||||||
|
}
|
||||||
|
|
||||||
|
function ele.formspec.state_switcher(x, y, state)
|
||||||
|
if not state then state = 0 end
|
||||||
|
local icon = ele.formspec.gui_switcher_icons[state]
|
||||||
|
local statedesc = ele.default.states[state]
|
||||||
|
|
||||||
|
if statedesc then
|
||||||
|
statedesc = statedesc.d
|
||||||
|
else
|
||||||
|
statedesc = ""
|
||||||
|
end
|
||||||
|
statedesc = statedesc .. "\nPress to toggle"
|
||||||
|
|
||||||
|
return "image_button["..x..","..y..";1,1;"..icon..";cyclestate;]"..
|
||||||
|
"tooltip[cyclestate;"..statedesc.."]"
|
||||||
|
end
|
||||||
|
|
||||||
function ele.formspec.create_bar(x, y, metric, color, small)
|
function ele.formspec.create_bar(x, y, metric, color, small)
|
||||||
if not metric or type(metric) ~= "number" or metric < 0 then metric = 0 end
|
if not metric or type(metric) ~= "number" or metric < 0 then metric = 0 end
|
||||||
|
@ -103,3 +103,23 @@ function ele.helpers.comma_value(n) -- credit http://richard.warburton.it
|
|||||||
local left,num,right = string.match(n,'^([^%d]*%d)(%d*)(.-)$')
|
local left,num,right = string.match(n,'^([^%d]*%d)(%d*)(.-)$')
|
||||||
return left..(num:reverse():gsub('(%d%d%d)','%1,'):reverse())..right
|
return left..(num:reverse():gsub('(%d%d%d)','%1,'):reverse())..right
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function ele.helpers.state_enabled(meta, pos, state)
|
||||||
|
if not state then
|
||||||
|
state = meta:get_int("state")
|
||||||
|
end
|
||||||
|
|
||||||
|
if state == 0 then
|
||||||
|
return true
|
||||||
|
elseif state == 1 then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
if state == 2 and meta:get_int("signal_interrupt") == 1 then
|
||||||
|
return true
|
||||||
|
elseif state == 3 and meta:get_int("signal_interrupt") == 0 then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
-- Machine definitions
|
-- Machine definitions
|
||||||
|
|
||||||
local pw = minetest.get_modpath("pipeworks") ~= nil
|
local pw = minetest.get_modpath("pipeworks") ~= nil
|
||||||
|
local mc = minetest.get_modpath("mesecons") ~= nil
|
||||||
local tl = minetest.get_modpath("tubelib") ~= nil
|
local tl = minetest.get_modpath("tubelib") ~= nil
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
@ -84,6 +85,14 @@ function ele.default.metadata_inventory_changed(pos)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- State machine descriptions
|
||||||
|
ele.default.states = {
|
||||||
|
[0] = {s = "on", d = "Always on", e = "toggle"},
|
||||||
|
{s = "off", d = "Always off", e = "toggle"},
|
||||||
|
{s = "signal", d = "Enable by Mesecons signal", e = "mesecons"},
|
||||||
|
{s = "interrupt", d = "Disable by Mesecons signal", e = "mesecons"},
|
||||||
|
}
|
||||||
|
|
||||||
-- Preserve power storage in the item stack dropped
|
-- Preserve power storage in the item stack dropped
|
||||||
local function preserve_metadata(pos, oldnode, oldmeta, drops)
|
local function preserve_metadata(pos, oldnode, oldmeta, drops)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
@ -125,6 +134,7 @@ function ele.capacity_text(capacity, storage)
|
|||||||
ele.helpers.comma_value(capacity), ele.unit)
|
ele.helpers.comma_value(capacity), ele.unit)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- API support
|
||||||
local tube = {
|
local tube = {
|
||||||
insert_object = function(pos, node, stack, direction)
|
insert_object = function(pos, node, stack, direction)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
@ -163,6 +173,55 @@ local tubelib_tube = {
|
|||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
local mesecons_def = {}
|
||||||
|
if mc then
|
||||||
|
mesecons_def = {
|
||||||
|
effector = {
|
||||||
|
action_on = function (pos, node)
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
meta:set_int("signal_interrupt", 1)
|
||||||
|
end,
|
||||||
|
action_off = function (pos, node)
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
meta:set_int("signal_interrupt", 0)
|
||||||
|
end,
|
||||||
|
action_change = function (pos, node)
|
||||||
|
local t = minetest.get_node_timer(pos)
|
||||||
|
if not t:is_started() then
|
||||||
|
t:start(1.0)
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Functions
|
||||||
|
|
||||||
|
local function switch_state(pos, state_def)
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
local state = meta:get_int("state")
|
||||||
|
local states = {}
|
||||||
|
for id,state in pairs(ele.default.states) do
|
||||||
|
if state_def[state.e] then
|
||||||
|
states[#states + 1] = id
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if #states == 0 then return end
|
||||||
|
|
||||||
|
state = state + 1
|
||||||
|
if state >= #states then
|
||||||
|
state = 0
|
||||||
|
end
|
||||||
|
state = states[state + 1]
|
||||||
|
meta:set_int("state", state)
|
||||||
|
|
||||||
|
local t = minetest.get_node_timer(pos)
|
||||||
|
if not t:is_started() then
|
||||||
|
t:start(1.0)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- Register a base device
|
-- Register a base device
|
||||||
function ele.register_base_device(nodename, nodedef)
|
function ele.register_base_device(nodename, nodedef)
|
||||||
local tlsupp = tl and nodedef.groups and (nodedef.groups["tubedevice"] or nodedef.groups["tube"])
|
local tlsupp = tl and nodedef.groups and (nodedef.groups["tubedevice"] or nodedef.groups["tube"])
|
||||||
@ -228,12 +287,16 @@ function ele.register_base_device(nodename, nodedef)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- Prevent digging when there's items inside
|
-- Prevent digging when there's items inside
|
||||||
if not nodedef.can_dig then
|
if not nodedef.can_dig then
|
||||||
nodedef.can_dig = can_dig
|
nodedef.can_dig = can_dig
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Explicitly allow the disabling of the state machine
|
||||||
|
if nodedef.groups["state_machine"] ~= 0 and not nodedef["states"] then
|
||||||
|
nodedef.states = {toggle = true}
|
||||||
|
end
|
||||||
|
|
||||||
-- Pipeworks support
|
-- Pipeworks support
|
||||||
if pw and nodedef.groups and (nodedef.groups["tubedevice"] or nodedef.groups["tube"]) then
|
if pw and nodedef.groups and (nodedef.groups["tubedevice"] or nodedef.groups["tube"]) then
|
||||||
if nodedef['tube'] == false then
|
if nodedef['tube'] == false then
|
||||||
@ -251,6 +314,32 @@ function ele.register_base_device(nodename, nodedef)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Mesecons support
|
||||||
|
if mc then
|
||||||
|
nodedef["mesecons"] = mesecons_def
|
||||||
|
if nodedef.groups["state_machine"] ~= 1 then
|
||||||
|
nodedef.states["mesecons"] = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- STATE MACHINE
|
||||||
|
local original_on_receive_fields = nodedef.on_receive_fields
|
||||||
|
nodedef.on_receive_fields = function (pos, formname, fields, sender)
|
||||||
|
if sender and sender ~= "" and minetest.is_protected(pos, sender:get_player_name()) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if nodedef.states then
|
||||||
|
if fields["cyclestate"] then
|
||||||
|
switch_state(pos, nodedef.states)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if original_on_receive_fields then
|
||||||
|
return original_on_receive_fields(pos, formname, fields, sender)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- Finally, register the damn thing already
|
-- Finally, register the damn thing already
|
||||||
minetest.register_node(nodename, nodedef)
|
minetest.register_node(nodename, nodedef)
|
||||||
local active_name = nil
|
local active_name = nil
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
name = elepower_papi
|
name = elepower_papi
|
||||||
description = Elepower Power Network API
|
description = Elepower Power Network API
|
||||||
optional_depends = default,pipeworks,tubelib
|
optional_depends = default,pipeworks,tubelib,mesecons
|
||||||
|
BIN
elepower_papi/textures/elepower_gui_cancel.png
Normal file
BIN
elepower_papi/textures/elepower_gui_cancel.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 458 B |
BIN
elepower_papi/textures/elepower_gui_check.png
Normal file
BIN
elepower_papi/textures/elepower_gui_check.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 613 B |
Loading…
Reference in New Issue
Block a user