mirror of
https://github.com/theFox6/microexpansion.git
synced 2025-01-15 17:07:35 +01:00
Wire up the rest for power.
This commit is contained in:
parent
8d84f7d77f
commit
53ab3c350f
@ -55,18 +55,24 @@ me.register_node("ctrl", {
|
|||||||
--HV_EU_supply = 144,
|
--HV_EU_supply = 144,
|
||||||
--HV_EU_demand = 44,
|
--HV_EU_demand = 44,
|
||||||
technic_run = function(pos, node)
|
technic_run = function(pos, node)
|
||||||
--local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
-- quick cheat sheet for how to wire:
|
-- quick cheat sheet for how to wire:
|
||||||
--meta:set_int("HV_EU_input", 23)
|
--meta:set_int("HV_EU_input", 23)
|
||||||
--meta:set_int("HV_EU_demand", 45)
|
--meta:set_int("HV_EU_demand", 45)
|
||||||
--meta:set_int("HV_EU_supply", 1045)
|
--meta:set_int("HV_EU_supply", 1045)
|
||||||
local net = me.get_network(pos)
|
local net = me.get_network(pos)
|
||||||
if not net then
|
if not net then
|
||||||
|
-- This is impossible, delete?
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
meta:set_int("HV_EU_input", 0)
|
meta:set_int("HV_EU_input", 0)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
net:update_demand()
|
if net.input ~= meta:get_int("HV_EU_input") then
|
||||||
|
net.input = meta:get_int("HV_EU_input")
|
||||||
|
me.log("EU: input changed to "..net.input, "error")
|
||||||
|
-- This only needs to see changes to inbound power levels.
|
||||||
|
me.send_event(pos, "power")
|
||||||
|
end
|
||||||
end,
|
end,
|
||||||
connect_sides = "nobottom",
|
connect_sides = "nobottom",
|
||||||
me_update = function(pos,_,ev)
|
me_update = function(pos,_,ev)
|
||||||
@ -80,12 +86,14 @@ me.register_node("ctrl", {
|
|||||||
mesecons = {effector = {
|
mesecons = {effector = {
|
||||||
action_on = function (pos, node)
|
action_on = function (pos, node)
|
||||||
local net = me.get_network(pos)
|
local net = me.get_network(pos)
|
||||||
|
--me.log("SWITCH: on", "error")
|
||||||
-- turn OFF on mese power
|
-- turn OFF on mese power
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
meta:set_int("enabled", 0)
|
meta:set_int("enabled", 0)
|
||||||
net:update_demand()
|
net:update_demand()
|
||||||
end,
|
end,
|
||||||
action_off = function (pos, node)
|
action_off = function (pos, node)
|
||||||
|
--me.log("SWITCH: off", "error")
|
||||||
local net = me.get_network(pos)
|
local net = me.get_network(pos)
|
||||||
-- turn ON without mesepower
|
-- turn ON without mesepower
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
@ -199,12 +207,14 @@ me.register_machine("cable", {
|
|||||||
if ev.type ~= "disconnect" then return end
|
if ev.type ~= "disconnect" then return end
|
||||||
end
|
end
|
||||||
--maybe this shouldn't be called on every update
|
--maybe this shouldn't be called on every update
|
||||||
|
if false then
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
if me.get_connected_network(pos) then
|
if me.get_connected_network(pos) then
|
||||||
meta:set_string("infotext", "Network connected")
|
meta:set_string("infotext", "Network connected")
|
||||||
else
|
else
|
||||||
meta:set_string("infotext", "No Network")
|
meta:set_string("infotext", "No Network")
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end,
|
end,
|
||||||
machine = {
|
machine = {
|
||||||
type = "conductor",
|
type = "conductor",
|
||||||
|
@ -529,48 +529,59 @@ end
|
|||||||
|
|
||||||
-- Helper to check to see if the controller is on and powered.
|
-- Helper to check to see if the controller is on and powered.
|
||||||
function network:powered(name)
|
function network:powered(name)
|
||||||
|
if not name and minetest.localplayer then
|
||||||
|
-- this works for the client side only
|
||||||
|
name = minetest.localplayer:get_name()
|
||||||
|
-- todo: on the server side, how do we get the player name?
|
||||||
|
end
|
||||||
local net = self
|
local net = self
|
||||||
local meta = minetest.get_meta(net.controller_pos)
|
local meta = minetest.get_meta(net.controller_pos)
|
||||||
local run = meta:get_int("enabled") == 1
|
local run = meta:get_int("enabled") == 1
|
||||||
if not run then
|
if not run then
|
||||||
minetest.chat_send_player(name, "Please enable by turning controller switch.")
|
if name then minetest.chat_send_player(name, "Please enable by turning controller switch.") end
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
--me.log("REMOTE: power level input is "..meta:get_int("HV_EU_input").." and demand is "..meta:get_int("HV_EU_demand"), "error")
|
me.log("NETWORK: powered power level input is "..meta:get_int("HV_EU_input").." and demand is "..meta:get_int("HV_EU_demand"), "error")
|
||||||
run = not technic or (meta:get_int("HV_EU_input") >= meta:get_int("HV_EU_demand") and meta:get_int("HV_EU_input") > 0)
|
run = not technic or (meta:get_int("HV_EU_input") >= meta:get_int("HV_EU_demand") and meta:get_int("HV_EU_input") > 0)
|
||||||
if not run then
|
if not run then
|
||||||
minetest.chat_send_player(name, "Please provide HV power to ME controller.")
|
if name then minetest.chat_send_player(name, "Please provide HV power to ME controller.") end
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
function network:update_demand()
|
function network:update_demand()
|
||||||
local demand = 60
|
|
||||||
local pos = self.controller_pos
|
local pos = self.controller_pos
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
local net = self
|
local net = self
|
||||||
if meta:get_int("enabled") == 0 then
|
if meta:get_int("enabled") == 0 then
|
||||||
|
if meta:get_int("HV_EU_demand") ~= 0 then
|
||||||
meta:set_int("HV_EU_demand", 0)
|
meta:set_int("HV_EU_demand", 0)
|
||||||
meta:set_string("infotext", "Disabled")
|
meta:set_string("infotext", "Disabled")
|
||||||
|
me.send_event(pos, "power")
|
||||||
|
end
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
local demand = 60 -- controller is 60
|
||||||
for ipos in me.connected_nodes(pos) do
|
for ipos in me.connected_nodes(pos) do
|
||||||
local name = me.get_node(ipos).name
|
local name = me.get_node(ipos).name
|
||||||
if name == "microexpansion:cable" then
|
if name == "microexpansion:cable" then
|
||||||
demand = demand + 1
|
demand = demand + 1 -- cables are 1
|
||||||
elseif name == "microexpansion:interface" then
|
elseif name == "microexpansion:interface" then
|
||||||
local meta = minetest.get_meta(ipos)
|
local meta = minetest.get_meta(ipos)
|
||||||
local inventories = minetest.deserialize(meta:get_string("connected"))
|
local inventories = minetest.deserialize(meta:get_string("connected"))
|
||||||
demand = demand + #inventories * 10 + 20
|
demand = demand + #inventories * 10 + 20 -- interfaces are 20 and 10 for each machine or inventory
|
||||||
else
|
else
|
||||||
demand = demand + 10
|
demand = demand + 10 -- everything else is 10
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
if meta:get_int("HV_EU_demand") ~= demand then
|
||||||
local name = meta:get_string("owner")
|
local name = meta:get_string("owner")
|
||||||
meta:set_string("infotext", "Network Controller (owned by "..name..")")
|
meta:set_string("infotext", "Network Controller (owned by "..name..")")
|
||||||
end
|
me.log("NET: demand changed to "..demand, "error")
|
||||||
--me.log("NET: demand is "..demand, "error")
|
|
||||||
meta:set_int("HV_EU_demand", demand)
|
meta:set_int("HV_EU_demand", demand)
|
||||||
|
me.send_event(pos, "power")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- We don't save this data, rather we rewalk upon first use. If 1% of
|
-- We don't save this data, rather we rewalk upon first use. If 1% of
|
||||||
|
@ -63,6 +63,12 @@ local function chest_formspec(pos, start_id, listname, page_max, q)
|
|||||||
"/" .. page_max .."]"
|
"/" .. page_max .."]"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if net and not net:powered() then
|
||||||
|
list = "label[3,2;" .. minetest.colorize("red", "No power!") .. "]"
|
||||||
|
buttons = ""
|
||||||
|
page_number = ""
|
||||||
|
end
|
||||||
|
|
||||||
return [[
|
return [[
|
||||||
size[9,12.5]
|
size[9,12.5]
|
||||||
]]..
|
]]..
|
||||||
|
@ -89,6 +89,12 @@ local function chest_formspec(pos, start_id, listname, page_max, q, c)
|
|||||||
"/" .. page_max .."]"
|
"/" .. page_max .."]"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if net and not net:powered() then
|
||||||
|
list = "label[3,2;" .. minetest.colorize("red", "No power!") .. "]"
|
||||||
|
buttons = ""
|
||||||
|
page_number = ""
|
||||||
|
end
|
||||||
|
|
||||||
return [[
|
return [[
|
||||||
size[9,12.5]
|
size[9,12.5]
|
||||||
]]..
|
]]..
|
||||||
@ -105,6 +111,7 @@ local function chest_formspec(pos, start_id, listname, page_max, q, c)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function update_chest(pos,_,ev)
|
local function update_chest(pos,_,ev)
|
||||||
|
--me.log("CTERM: got event "..((ev and ev.type) or "<null>"), "error")
|
||||||
--for now all events matter
|
--for now all events matter
|
||||||
|
|
||||||
local net = me.get_connected_network(pos)
|
local net = me.get_connected_network(pos)
|
||||||
@ -259,7 +266,7 @@ end
|
|||||||
|
|
||||||
|
|
||||||
function me.register_output_to_inputs(output, inputs)
|
function me.register_output_to_inputs(output, inputs)
|
||||||
me.log("REG: output "..output.." from inputs "..dump(inputs))
|
--me.log("REG: output "..output.." from inputs "..dump(inputs))
|
||||||
me.map_output_to_inputs[output] = inputs
|
me.map_output_to_inputs[output] = inputs
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -455,7 +462,6 @@ me.register_node("cterminal", {
|
|||||||
me_update = update_chest,
|
me_update = update_chest,
|
||||||
on_construct = function(pos)
|
on_construct = function(pos)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
meta:set_string("formspec", chest_formspec(pos, 1))
|
|
||||||
meta:set_string("inv_name", "none")
|
meta:set_string("inv_name", "none")
|
||||||
meta:set_int("page", 1)
|
meta:set_int("page", 1)
|
||||||
|
|
||||||
@ -466,9 +472,7 @@ me.register_node("cterminal", {
|
|||||||
|
|
||||||
local net = me.get_connected_network(pos)
|
local net = me.get_connected_network(pos)
|
||||||
me.send_event(pos, "connect", {net=net})
|
me.send_event(pos, "connect", {net=net})
|
||||||
if net then
|
|
||||||
update_chest(pos)
|
update_chest(pos)
|
||||||
end
|
|
||||||
end,
|
end,
|
||||||
after_destruct = function(pos)
|
after_destruct = function(pos)
|
||||||
me.send_event(pos, "disconnect")
|
me.send_event(pos, "disconnect")
|
||||||
@ -728,7 +732,7 @@ me.register_node("cterminal", {
|
|||||||
elseif fields.crafts then
|
elseif fields.crafts then
|
||||||
meta:set_int("page", 1)
|
meta:set_int("page", 1)
|
||||||
--me.log("CRAFT: craftables: "..dump(net and net.process), "error")
|
--me.log("CRAFT: craftables: "..dump(net and net.process), "error")
|
||||||
me.log("CRAFT: got fields: "..dump(fields), "error")
|
--me.log("CRAFT: got fields: "..dump(fields), "error")
|
||||||
inv_name = "main"
|
inv_name = "main"
|
||||||
if fields.crafts == "true" then
|
if fields.crafts == "true" then
|
||||||
crafts = true
|
crafts = true
|
||||||
@ -783,7 +787,7 @@ me.register_node("cterminal", {
|
|||||||
end
|
end
|
||||||
elseif fields.search or fields.key_enter_field == "filter" then
|
elseif fields.search or fields.key_enter_field == "filter" then
|
||||||
own_inv:set_size("search", 0)
|
own_inv:set_size("search", 0)
|
||||||
me.log("CRAFT: got fields: "..dump(fields), "error")
|
--me.log("CRAFT: got fields: "..dump(fields), "error")
|
||||||
meta:set_int("page", 1)
|
meta:set_int("page", 1)
|
||||||
inv_name = "main"
|
inv_name = "main"
|
||||||
inv = ctrl_inv
|
inv = ctrl_inv
|
||||||
@ -809,7 +813,7 @@ me.register_node("cterminal", {
|
|||||||
meta:set_string("formspec", chest_formspec(pos, 1, inv_name, page_max, fields.filter, crafts))
|
meta:set_string("formspec", chest_formspec(pos, 1, inv_name, page_max, fields.filter, crafts))
|
||||||
end
|
end
|
||||||
elseif fields.clear then
|
elseif fields.clear then
|
||||||
me.log("CRAFT: got fields: "..dump(fields), "error")
|
--me.log("CRAFT: got fields: "..dump(fields), "error")
|
||||||
own_inv:set_size("search", 0)
|
own_inv:set_size("search", 0)
|
||||||
own_inv:set_size("crafts", 0)
|
own_inv:set_size("crafts", 0)
|
||||||
meta:set_int("page", 1)
|
meta:set_int("page", 1)
|
||||||
|
@ -56,11 +56,40 @@ function me.walk_connected(pos)
|
|||||||
return nodes
|
return nodes
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function chest_formspec(pos)
|
||||||
|
local net = me.get_connected_network(pos)
|
||||||
|
local list
|
||||||
|
list = [[
|
||||||
|
list[context;import;0,0.3;9,1]
|
||||||
|
list[context;export;0,0.3;9,1]
|
||||||
|
list[current_player;main;0,3.5;8,1;]
|
||||||
|
list[current_player;main;0,4.73;8,3;8]
|
||||||
|
listring[current_name;import]
|
||||||
|
listring[current_player;main]
|
||||||
|
]]
|
||||||
|
|
||||||
|
if net and not net:powered() then
|
||||||
|
list = "label[3,2;" .. minetest.colorize("red", "No power!") .. "]"
|
||||||
|
end
|
||||||
|
|
||||||
|
local formspec =
|
||||||
|
"size[9,7.5]"..
|
||||||
|
microexpansion.gui_bg ..
|
||||||
|
microexpansion.gui_slots ..
|
||||||
|
"label[0,-0.23;ME Interface]" ..
|
||||||
|
list
|
||||||
|
return formspec
|
||||||
|
end
|
||||||
|
|
||||||
local function update(pos,_,ev)
|
local function update(pos,_,ev)
|
||||||
|
--me.log("INTERFACE: got event "..((ev and ev.type) or "<null>"), "error")
|
||||||
if ev.type == "connect" then
|
if ev.type == "connect" then
|
||||||
-- net.update_counts()
|
-- net.update_counts()
|
||||||
elseif ev.type == "disconnect" then
|
elseif ev.type == "disconnect" then
|
||||||
--
|
--
|
||||||
|
elseif ev.type == "power" then
|
||||||
|
local int_meta = minetest.get_meta(pos)
|
||||||
|
int_meta:set_string("formspec", chest_formspec(pos))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -156,20 +185,7 @@ me.register_node("interface", {
|
|||||||
me_update = update,
|
me_update = update,
|
||||||
on_construct = function(pos)
|
on_construct = function(pos)
|
||||||
local int_meta = minetest.get_meta(pos)
|
local int_meta = minetest.get_meta(pos)
|
||||||
int_meta:set_string("formspec",
|
int_meta:set_string("formspec", chest_formspec(pos))
|
||||||
"size[9,7.5]"..
|
|
||||||
microexpansion.gui_bg ..
|
|
||||||
microexpansion.gui_slots ..
|
|
||||||
[[
|
|
||||||
label[0,-0.23;ME Interface]
|
|
||||||
list[context;import;0,0.3;9,1]
|
|
||||||
list[context;export;0,0.3;9,1]
|
|
||||||
list[current_player;main;0,3.5;8,1;]
|
|
||||||
list[current_player;main;0,4.73;8,3;8]
|
|
||||||
listring[current_name;import]
|
|
||||||
listring[current_player;main]
|
|
||||||
field_close_on_enter[filter;false]
|
|
||||||
]])
|
|
||||||
local inv = int_meta:get_inventory()
|
local inv = int_meta:get_inventory()
|
||||||
inv:set_size("export", 3)
|
inv:set_size("export", 3)
|
||||||
inv:set_size("import", 3)
|
inv:set_size("import", 3)
|
||||||
@ -182,6 +198,7 @@ me.register_node("interface", {
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
me.reload_interface(net, pos, true)
|
me.reload_interface(net, pos, true)
|
||||||
|
net:update_demand()
|
||||||
end,
|
end,
|
||||||
can_dig = function(pos)
|
can_dig = function(pos)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
@ -267,6 +284,7 @@ me.register_node("interface", {
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
net:update_demand()
|
||||||
end,
|
end,
|
||||||
after_destruct = function(pos)
|
after_destruct = function(pos)
|
||||||
me.send_event(pos, "disconnect")
|
me.send_event(pos, "disconnect")
|
||||||
|
@ -59,6 +59,12 @@ local function chest_formspec(pos, start_id, listname, page_max, q)
|
|||||||
"/" .. page_max .."]"
|
"/" .. page_max .."]"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if net and not net:powered() then
|
||||||
|
list = "label[3,2;" .. minetest.colorize("red", "No power!") .. "]"
|
||||||
|
buttons = ""
|
||||||
|
page_number = ""
|
||||||
|
end
|
||||||
|
|
||||||
return [[
|
return [[
|
||||||
size[9,9.5]
|
size[9,9.5]
|
||||||
]]..
|
]]..
|
||||||
@ -117,7 +123,6 @@ me.register_node("term", {
|
|||||||
me_update = update_chest,
|
me_update = update_chest,
|
||||||
on_construct = function(pos)
|
on_construct = function(pos)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
meta:set_string("formspec", chest_formspec(pos, 1))
|
|
||||||
meta:set_string("inv_name", "none")
|
meta:set_string("inv_name", "none")
|
||||||
meta:set_int("page", 1)
|
meta:set_int("page", 1)
|
||||||
|
|
||||||
@ -126,9 +131,7 @@ me.register_node("term", {
|
|||||||
|
|
||||||
local net = me.get_connected_network(pos)
|
local net = me.get_connected_network(pos)
|
||||||
me.send_event(pos, "connect", {net=net})
|
me.send_event(pos, "connect", {net=net})
|
||||||
if net then
|
|
||||||
update_chest(pos)
|
update_chest(pos)
|
||||||
end
|
|
||||||
end,
|
end,
|
||||||
after_destruct = function(pos)
|
after_destruct = function(pos)
|
||||||
me.send_event(pos, "disconnect")
|
me.send_event(pos, "disconnect")
|
||||||
|
Loading…
Reference in New Issue
Block a user