Reworked for a new power model
This commit is contained in:
parent
bb42118f3d
commit
f777123b58
@ -64,10 +64,10 @@ end
|
|||||||
local function on_rightclick(pos, node, clicker)
|
local function on_rightclick(pos, node, clicker)
|
||||||
local mem = tubelib2.get_mem(pos)
|
local mem = tubelib2.get_mem(pos)
|
||||||
if not minetest.is_protected(pos, clicker:get_player_name()) then
|
if not minetest.is_protected(pos, clicker:get_player_name()) then
|
||||||
if CRD(pos).State:is_active(mem) then
|
if CRD(pos).State:get_state(mem) == techage.STOPPED then
|
||||||
CRD(pos).State:stop(pos, mem)
|
|
||||||
else
|
|
||||||
CRD(pos).State:start(pos, mem)
|
CRD(pos).State:start(pos, mem)
|
||||||
|
else
|
||||||
|
CRD(pos).State:stop(pos, mem)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -32,11 +32,6 @@ local function swap_node(pos, name)
|
|||||||
minetest.swap_node(pos, node)
|
minetest.swap_node(pos, node)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- called from pipe network
|
|
||||||
local function valid_power_dir(pos, power_dir, in_dir)
|
|
||||||
return power_dir == in_dir or in_dir == 5
|
|
||||||
end
|
|
||||||
|
|
||||||
local function play_sound(pos)
|
local function play_sound(pos)
|
||||||
local mem = tubelib2.get_mem(pos)
|
local mem = tubelib2.get_mem(pos)
|
||||||
if mem.running then
|
if mem.running then
|
||||||
|
2
init.lua
2
init.lua
@ -106,7 +106,7 @@ else
|
|||||||
dofile(MP.."/coal_power_station/akkubox.lua")
|
dofile(MP.."/coal_power_station/akkubox.lua")
|
||||||
|
|
||||||
--dofile(MP.."/test/generator.lua")
|
--dofile(MP.."/test/generator.lua")
|
||||||
--dofile(MP.."/test/lamp.lua")
|
dofile(MP.."/test/lamp.lua")
|
||||||
-- dofile(MP.."/test/consumer.lua")
|
-- dofile(MP.."/test/consumer.lua")
|
||||||
--dofile(MP.."/test/consumer2.lua")
|
--dofile(MP.."/test/consumer2.lua")
|
||||||
--dofile(MP.."/test/test.lua")
|
--dofile(MP.."/test/test.lua")
|
||||||
|
@ -10,47 +10,44 @@ local I,_ = dofile(MP.."/intllib.lua")
|
|||||||
local POWER_CONSUMPTION = 1
|
local POWER_CONSUMPTION = 1
|
||||||
|
|
||||||
local Power = techage.ElectricCable
|
local Power = techage.ElectricCable
|
||||||
local consumer = techage.consumer
|
|
||||||
|
|
||||||
local function swap_node(pos, name)
|
local function swap_node(pos, name, infotext)
|
||||||
local node = minetest.get_node(pos)
|
local node = minetest.get_node(pos)
|
||||||
if node.name == name then
|
if node.name == name then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
node.name = name
|
node.name = name
|
||||||
minetest.swap_node(pos, node)
|
minetest.swap_node(pos, node)
|
||||||
|
M(pos):set_string("infotext", infotext)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- called from pipe network
|
local function on_power_pass1(pos, mem)
|
||||||
local function valid_power_dir(pos, power_dir, in_dir)
|
if mem.running then
|
||||||
--print("valid_power_dir", power_dir, in_dir)
|
mem.correction = POWER_CONSUMPTION
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
local function lamp_turn_on_clbk(pos, in_dir, sum)
|
|
||||||
local mem = tubelib2.get_mem(pos)
|
|
||||||
--print("lamp_turn_on_clbk", sum)
|
|
||||||
if sum > 0 and mem.running then
|
|
||||||
swap_node(pos, "techage:test_lamp_on")
|
|
||||||
else
|
else
|
||||||
swap_node(pos, "techage:test_lamp")
|
mem.correction = 0
|
||||||
end
|
end
|
||||||
|
return mem.correction
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function on_power_pass2(pos, mem, sum)
|
||||||
|
if sum > 0 and mem.running then
|
||||||
|
swap_node(pos, "techage:test_lamp_on", "On")
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
swap_node(pos, "techage:test_lamp", "Off")
|
||||||
|
return -mem.correction
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local function lamp_on_rightclick(pos, node, clicker)
|
local function lamp_on_rightclick(pos, node, clicker)
|
||||||
local mem = tubelib2.get_mem(pos)
|
local mem = tubelib2.get_mem(pos)
|
||||||
--print("lamp_on_rightclick", dump(mem))
|
|
||||||
if not mem.running then
|
if not mem.running then
|
||||||
swap_node(pos, "techage:test_lamp_on")
|
|
||||||
mem.running = true
|
mem.running = true
|
||||||
M(pos):set_string("infotext", "On")
|
|
||||||
consumer.turn_power_on(pos, POWER_CONSUMPTION)
|
|
||||||
else
|
else
|
||||||
swap_node(pos, "techage:test_lamp")
|
|
||||||
mem.running = false
|
mem.running = false
|
||||||
M(pos):set_string("infotext", "Off")
|
|
||||||
consumer.turn_power_on(pos, 0)
|
|
||||||
end
|
end
|
||||||
|
techage.power.power_distribution(pos)
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_node("techage:test_lamp", {
|
minetest.register_node("techage:test_lamp", {
|
||||||
@ -64,20 +61,8 @@ minetest.register_node("techage:test_lamp", {
|
|||||||
'techage_electric_button.png',
|
'techage_electric_button.png',
|
||||||
'techage_electric_button.png',
|
'techage_electric_button.png',
|
||||||
},
|
},
|
||||||
techage = {
|
|
||||||
turn_on = lamp_turn_on_clbk,
|
|
||||||
read_power_consumption = consumer.read_power_consumption,
|
|
||||||
power_network = Power,
|
|
||||||
power_side = "L",
|
|
||||||
valid_power_dir = valid_power_dir,
|
|
||||||
},
|
|
||||||
|
|
||||||
after_place_node = function(pos, placer)
|
on_construct = tubelib2.init_mem,
|
||||||
local mem = consumer.after_place_node(pos, placer)
|
|
||||||
end,
|
|
||||||
|
|
||||||
after_tube_update = consumer.after_tube_update,
|
|
||||||
after_dig_node = consumer.after_dig_node,
|
|
||||||
on_rightclick = lamp_on_rightclick,
|
on_rightclick = lamp_on_rightclick,
|
||||||
|
|
||||||
paramtype = "light",
|
paramtype = "light",
|
||||||
@ -94,20 +79,11 @@ minetest.register_node("techage:test_lamp_on", {
|
|||||||
tiles = {
|
tiles = {
|
||||||
'techage_electric_button.png',
|
'techage_electric_button.png',
|
||||||
},
|
},
|
||||||
techage = {
|
|
||||||
turn_on = lamp_turn_on_clbk,
|
|
||||||
read_power_consumption = consumer.read_power_consumption,
|
|
||||||
power_network = Power,
|
|
||||||
power_side = "L",
|
|
||||||
valid_power_dir = valid_power_dir,
|
|
||||||
},
|
|
||||||
|
|
||||||
after_tube_update = consumer.after_tube_update,
|
|
||||||
after_dig_node = consumer.after_dig_node,
|
|
||||||
on_rightclick = lamp_on_rightclick,
|
on_rightclick = lamp_on_rightclick,
|
||||||
|
|
||||||
paramtype = "light",
|
paramtype = "light",
|
||||||
light_source = LIGHT_MAX,
|
light_source = minetest.LIGHT_MAX,
|
||||||
sunlight_propagates = true,
|
sunlight_propagates = true,
|
||||||
paramtype2 = "facedir",
|
paramtype2 = "facedir",
|
||||||
drop = "techage:test_lamp",
|
drop = "techage:test_lamp",
|
||||||
@ -116,4 +92,9 @@ minetest.register_node("techage:test_lamp_on", {
|
|||||||
sounds = default.node_sound_wood_defaults(),
|
sounds = default.node_sound_wood_defaults(),
|
||||||
})
|
})
|
||||||
|
|
||||||
Power:add_secondary_node_names({"techage:test_lamp", "techage:test_lamp_on"})
|
techage.power.register_node({"techage:test_lamp", "techage:test_lamp_on"}, {
|
||||||
|
on_power_pass1 = on_power_pass1,
|
||||||
|
on_power_pass2 = on_power_pass2,
|
||||||
|
power_network = Power,
|
||||||
|
})
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user