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
|
||||
end
|
||||
|
||||
local function get_formspec(timer, power, sludge)
|
||||
local function get_formspec(timer, power, sludge, state)
|
||||
return "size[8,8.5]"..
|
||||
default.gui_bg..
|
||||
default.gui_bg_img..
|
||||
default.gui_slots..
|
||||
ele.formspec.state_switcher(7, 2.5, state)..
|
||||
ele.formspec.power_meter(power)..
|
||||
ele.formspec.fluid_bar(7, 0, sludge)..
|
||||
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 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
|
||||
local harvested = {}
|
||||
|
||||
@ -129,16 +134,24 @@ local function on_timer(pos, elapsed)
|
||||
work = work + 1
|
||||
end
|
||||
|
||||
active = "Active"
|
||||
refresh = true
|
||||
ele.helpers.swap_node(pos, "elepower_farming:harvester_active")
|
||||
else
|
||||
if not is_enabled then
|
||||
active = "Off"
|
||||
end
|
||||
|
||||
ele.helpers.swap_node(pos, "elepower_farming:harvester")
|
||||
end
|
||||
|
||||
local power = {capacity = capacity, storage = storage, usage = usage}
|
||||
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("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]"..
|
||||
default.gui_bg..
|
||||
default.gui_bg_img..
|
||||
default.gui_slots..
|
||||
ele.formspec.power_meter(power)..
|
||||
ele.formspec.state_switcher(7, 0, state)..
|
||||
ele.formspec.create_bar(1, 0, 100 - timer, "#00ff11", true)..
|
||||
"list[context;layout;2.5,0;3,3;]"..
|
||||
"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")
|
||||
|
||||
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
|
||||
local planted = 0
|
||||
for index, slot in ipairs(inv:get_list("layout")) do
|
||||
@ -249,13 +254,19 @@ local function on_timer(pos, elapsed)
|
||||
work = work + 1
|
||||
end
|
||||
|
||||
active = "Active"
|
||||
refresh = true
|
||||
elseif not is_enabled then
|
||||
active = "Off"
|
||||
end
|
||||
|
||||
local power = {capacity = capacity, storage = storage, usage = usage}
|
||||
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("src_time", work)
|
||||
|
||||
|
@ -89,12 +89,13 @@ local function spawn(pos, mob)
|
||||
return
|
||||
end
|
||||
|
||||
local function get_formspec(timer, power)
|
||||
local function get_formspec(timer, power, state)
|
||||
return "size[8,8.5]"..
|
||||
default.gui_bg..
|
||||
default.gui_bg_img..
|
||||
default.gui_slots..
|
||||
ele.formspec.power_meter(power)..
|
||||
ele.formspec.state_switcher(7, 0, state)..
|
||||
ele.formspec.create_bar(1, 0, 100 - timer, "#00ff11", true)..
|
||||
"list[context;src;3.5,1.5;1,1;]"..
|
||||
"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 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_name = egg_slot:get_name()
|
||||
local mob_desc = "None"
|
||||
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", "")
|
||||
|
||||
if work == SPAWNER_TICK then
|
||||
@ -142,6 +147,8 @@ local function on_timer(pos, elapsed)
|
||||
|
||||
refresh = true
|
||||
mob_desc = minetest.registered_items[mob_name].description
|
||||
elseif not is_enabled then
|
||||
active = "Off"
|
||||
else
|
||||
work = 0
|
||||
active = "Inactive"
|
||||
@ -153,7 +160,7 @@ local function on_timer(pos, elapsed)
|
||||
local power = {capacity = capacity, storage = storage, usage = usage}
|
||||
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("src_time", work)
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
-- It accepts a recipe type registered beforehand.
|
||||
|
||||
-- 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 input_size = craftstats.inputs
|
||||
|
||||
@ -45,6 +45,7 @@ function ele.formspec.get_crafter_formspec(craft_type, power, percent)
|
||||
default.gui_bg_img..
|
||||
default.gui_slots..
|
||||
ele.formspec.power_meter(power)..
|
||||
ele.formspec.state_switcher(7, 0, state)..
|
||||
"list[context;src;"..x..","..y..";"..in_width..","..in_height..";]"..
|
||||
bar..
|
||||
"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 storage = ele.helpers.get_node_property(meta, pos, "storage")
|
||||
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 pow_buffer = {capacity = capacity, storage = storage, usage = 0}
|
||||
|
||||
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 power_operation = false
|
||||
|
||||
@ -112,24 +123,22 @@ function elepm.register_crafter(nodename, nodedef)
|
||||
|
||||
if result.time == 0 then
|
||||
time = 0
|
||||
meta:set_string("infotext", ("%s Idle"):format(nodedef.description) ..
|
||||
"\n" .. ele.capacity_text(capacity, storage))
|
||||
status = "Idle"
|
||||
else
|
||||
meta:set_string("infotext", ("%s Out of Power!"):format(nodedef.description) ..
|
||||
"\n" .. ele.capacity_text(capacity, storage))
|
||||
status = "Out of Power!"
|
||||
end
|
||||
|
||||
break
|
||||
end
|
||||
|
||||
refresh = true
|
||||
status = "Active"
|
||||
|
||||
-- One step
|
||||
meta:set_int("storage", storage - usage)
|
||||
storage = storage - usage
|
||||
meta:set_int("storage", storage)
|
||||
pow_buffer = {capacity = capacity, storage = storage, usage = usage}
|
||||
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
|
||||
local active_node = nodename.."_active"
|
||||
@ -166,8 +175,7 @@ function elepm.register_crafter(nodename, nodedef)
|
||||
if not room_for_output then
|
||||
ele.helpers.swap_node(pos, machine_node)
|
||||
time = ele.helpers.round(res_time*10)
|
||||
meta:set_string("infotext", ("%s Output Full!"):format(nodedef.description) ..
|
||||
"\n" .. ele.capacity_text(capacity, storage))
|
||||
status = "Output Full!"
|
||||
break
|
||||
end
|
||||
|
||||
@ -182,7 +190,9 @@ function elepm.register_crafter(nodename, nodedef)
|
||||
pct = math.floor((time / ele.helpers.round(res_time * 10)) * 100)
|
||||
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)
|
||||
|
||||
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]"..
|
||||
default.gui_bg..
|
||||
default.gui_bg_img..
|
||||
default.gui_slots..
|
||||
ele.formspec.power_meter(power)..
|
||||
ele.formspec.state_switcher(7, 2.5, state)..
|
||||
ele.formspec.fluid_bar(7, 0, buffer)..
|
||||
"image[3.5,1.5;1,1;default_furnace_fire_bg.png^[lowpart:"..
|
||||
(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 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
|
||||
local flbuffer = fluid_lib.get_buffer_data(pos, buffer_name)
|
||||
local pow_buffer
|
||||
if not flbuffer or flbuffer.fluid == "" then return false end
|
||||
local pow_buffer = {capacity = capacity, storage = storage, usage = 0}
|
||||
local status = "Idle"
|
||||
|
||||
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 burn_time > 0 then
|
||||
if storage + generation > capacity then
|
||||
@ -77,7 +87,7 @@ function ele.register_fluid_generator(nodename, nodedef)
|
||||
meta:set_int("burn_time", burn_time)
|
||||
end
|
||||
|
||||
pow_buffer = {capacity = capacity, storage = storage, usage = 0}
|
||||
status = "Active"
|
||||
|
||||
-- Burn another bucket of lava
|
||||
if burn_time == 0 then
|
||||
@ -95,10 +105,7 @@ function ele.register_fluid_generator(nodename, nodedef)
|
||||
|
||||
refresh = true
|
||||
else
|
||||
meta:set_string("formspec", get_formspec(pow_buffer, 0, flbuffer))
|
||||
meta:set_string("infotext", ("%s Idle\n%s\n%s"):format(nodedef.description,
|
||||
ele.capacity_text(capacity, storage), fluid_lib.buffer_to_string(flbuffer)))
|
||||
|
||||
status = "Idle"
|
||||
ele.helpers.swap_node(pos, nodename)
|
||||
end
|
||||
end
|
||||
@ -107,8 +114,8 @@ function ele.register_fluid_generator(nodename, nodedef)
|
||||
end
|
||||
|
||||
local percent = math.floor((burn_time / burn_totaltime) * 100)
|
||||
meta:set_string("formspec", get_formspec(pow_buffer, percent, flbuffer))
|
||||
meta:set_string("infotext", ("%s Active\n%s\n%s"):format(nodedef.description,
|
||||
meta:set_string("formspec", get_formspec(pow_buffer, percent, flbuffer, state))
|
||||
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)))
|
||||
|
||||
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]"..
|
||||
default.gui_bg..
|
||||
default.gui_bg_img..
|
||||
default.gui_slots..
|
||||
ele.formspec.power_meter(power)..
|
||||
ele.formspec.state_switcher(7, 0, state)..
|
||||
"list[context;src;3,1.5;1,1;]"..
|
||||
"image[4,1.5;1,1;default_furnace_fire_bg.png^[lowpart:"..
|
||||
percent..":default_furnace_fire_fg.png]"..
|
||||
@ -44,6 +45,18 @@ function elepm.register_fuel_generator(nodename, nodedef)
|
||||
local generation = ele.helpers.get_node_property(meta, pos, "usage")
|
||||
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)
|
||||
local status = "Idle"
|
||||
|
||||
local pow_buffer = {capacity = capacity, storage = storage, usage = 0}
|
||||
|
||||
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
|
||||
@ -51,15 +64,15 @@ function elepm.register_fuel_generator(nodename, nodedef)
|
||||
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
|
||||
|
||||
local pow_buffer = {capacity = capacity, storage = storage, usage = 0}
|
||||
status = "Active"
|
||||
|
||||
while true do
|
||||
-- Burn another piece of fuel
|
||||
if burn_time == 0 then
|
||||
local inv = meta:get_inventory()
|
||||
@ -88,9 +101,7 @@ function elepm.register_fuel_generator(nodename, nodedef)
|
||||
|
||||
refresh = true
|
||||
else
|
||||
meta:set_string("formspec", get_formspec(pow_buffer, 0))
|
||||
meta:set_string("infotext", ("%s Idle"):format(nodedef.description) ..
|
||||
"\n" .. ele.capacity_text(capacity, storage))
|
||||
status = "Idle"
|
||||
ele.helpers.swap_node(pos, nodename)
|
||||
end
|
||||
end
|
||||
@ -99,8 +110,8 @@ function elepm.register_fuel_generator(nodename, nodedef)
|
||||
end
|
||||
|
||||
local percent = math.floor((burn_time / burn_totaltime) * 100)
|
||||
meta:set_string("formspec", get_formspec(pow_buffer, percent))
|
||||
meta:set_string("infotext", ("%s Active"):format(nodedef.description) ..
|
||||
meta:set_string("formspec", get_formspec(pow_buffer, percent, state))
|
||||
meta:set_string("infotext", ("%s %s"):format(nodedef.description, status) ..
|
||||
"\n" .. ele.capacity_text(capacity, storage))
|
||||
|
||||
return refresh
|
||||
|
@ -1,5 +1,5 @@
|
||||
|
||||
local function get_formspec(mode, buffer)
|
||||
local function get_formspec(mode, buffer, state)
|
||||
if not mode then
|
||||
mode = 0
|
||||
end
|
||||
@ -13,6 +13,7 @@ local function get_formspec(mode, buffer)
|
||||
default.gui_bg..
|
||||
default.gui_bg_img..
|
||||
default.gui_slots..
|
||||
ele.formspec.state_switcher(0, 0, state)..
|
||||
ele.formspec.fluid_bar(7, 0.75, buffer)..
|
||||
"list[context;src;3.5,1;1,1;]"..
|
||||
"list[context;dst;3.5,2;1,1;]"..
|
||||
@ -35,9 +36,14 @@ local function on_timer(pos, elapsed)
|
||||
|
||||
local buffer = fluid_lib.get_buffer_data(pos, "input")
|
||||
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_name = bucket_slot:get_name()
|
||||
|
||||
if is_enabled then
|
||||
if mode == 0 and bucket_name == "bucket:bucket_empty" and buffer.amount >= 1000 then
|
||||
-- Fill bucket
|
||||
local bitem = bucket.liquids[buffer.fluid]
|
||||
@ -70,6 +76,7 @@ local function on_timer(pos, elapsed)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if buffer.amount <= 0 then
|
||||
buffer.amount = 0
|
||||
@ -114,6 +121,7 @@ ele.register_base_device("elepower_machines:bucketer", {
|
||||
accepts = true,
|
||||
},
|
||||
},
|
||||
paramtype2 = "facedir",
|
||||
on_timer = on_timer,
|
||||
on_construct = function (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 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_slots..
|
||||
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(7, 0, hot_buffer)..
|
||||
"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)
|
||||
end
|
||||
|
||||
|
||||
local function lava_cooler_timer(pos, elapsed)
|
||||
local refresh = false
|
||||
|
||||
@ -69,7 +69,10 @@ local function lava_cooler_timer(pos, elapsed)
|
||||
local time = meta:get_int("src_time")
|
||||
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 time >= TIME then
|
||||
local room_for_output = true
|
||||
@ -101,6 +104,8 @@ local function lava_cooler_timer(pos, elapsed)
|
||||
active = "Idle"
|
||||
refresh = false
|
||||
end
|
||||
elseif not is_enabled then
|
||||
active = "Off"
|
||||
else
|
||||
active = "Idle"
|
||||
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("formspec", get_formspec(timer, coolant_buffer, hot_buffer,
|
||||
power, cooler_recipes, recipe))
|
||||
power, cooler_recipes, recipe, state))
|
||||
|
||||
return refresh
|
||||
end
|
||||
@ -142,7 +147,7 @@ ele.register_machine("elepower_machines:lava_cooler", {
|
||||
inv:set_size("dst", 1)
|
||||
|
||||
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,
|
||||
on_timer = lava_cooler_timer,
|
||||
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]"..
|
||||
default.gui_bg..
|
||||
default.gui_bg_img..
|
||||
default.gui_slots..
|
||||
ele.formspec.power_meter(power)..
|
||||
ele.formspec.state_switcher(3.5, 1.5, state)..
|
||||
ele.formspec.fluid_bar(7, 0, buffer)..
|
||||
"list[current_player;main;0,4.25;8,1;]"..
|
||||
"list[current_player;main;0,5.5;8,3;8]"..
|
||||
|
@ -1,6 +1,28 @@
|
||||
-- Formspec helpers
|
||||
|
||||
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)
|
||||
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*)(.-)$')
|
||||
return left..(num:reverse():gsub('(%d%d%d)','%1,'):reverse())..right
|
||||
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
|
||||
|
||||
local pw = minetest.get_modpath("pipeworks") ~= nil
|
||||
local mc = minetest.get_modpath("mesecons") ~= nil
|
||||
local tl = minetest.get_modpath("tubelib") ~= nil
|
||||
|
||||
--[[
|
||||
@ -84,6 +85,14 @@ function ele.default.metadata_inventory_changed(pos)
|
||||
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
|
||||
local function preserve_metadata(pos, oldnode, oldmeta, drops)
|
||||
local meta = minetest.get_meta(pos)
|
||||
@ -125,6 +134,7 @@ function ele.capacity_text(capacity, storage)
|
||||
ele.helpers.comma_value(capacity), ele.unit)
|
||||
end
|
||||
|
||||
-- API support
|
||||
local tube = {
|
||||
insert_object = function(pos, node, stack, direction)
|
||||
local meta = minetest.get_meta(pos)
|
||||
@ -163,6 +173,55 @@ local tubelib_tube = {
|
||||
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
|
||||
function ele.register_base_device(nodename, nodedef)
|
||||
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
|
||||
|
||||
|
||||
-- Prevent digging when there's items inside
|
||||
if not nodedef.can_dig then
|
||||
nodedef.can_dig = can_dig
|
||||
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
|
||||
if pw and nodedef.groups and (nodedef.groups["tubedevice"] or nodedef.groups["tube"]) then
|
||||
if nodedef['tube'] == false then
|
||||
@ -251,6 +314,32 @@ function ele.register_base_device(nodename, nodedef)
|
||||
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
|
||||
minetest.register_node(nodename, nodedef)
|
||||
local active_name = nil
|
||||
|
@ -1,3 +1,3 @@
|
||||
name = elepower_papi
|
||||
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