cylinder and flywheel are working
This commit is contained in:
parent
7233be550b
commit
a638068db4
@ -103,11 +103,14 @@ local function turn_on(pos, dir, on)
|
|||||||
if out_dir ~= tubelib2.Turn180Deg[dir or 0] then
|
if out_dir ~= tubelib2.Turn180Deg[dir or 0] then
|
||||||
if item.pos then
|
if item.pos then
|
||||||
local this = TP(item.pos)
|
local this = TP(item.pos)
|
||||||
if this and this.turn_on then
|
if this and this.turn_on and this.valid_power_dir then
|
||||||
this.turn_on(item.pos, item.in_dir, on)
|
local mem = tubelib2.get_mem(item.pos)
|
||||||
|
if this.valid_power_dir(item.pos, mem, item.in_dir) then
|
||||||
|
this.turn_on(item.pos, item.in_dir, on)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
if this and this.animated_power_network then
|
if this and this.animated_power_network then
|
||||||
turn_tube_on(item.pos, item.in_dir, this.power_network, on)
|
turn_tube_on(pos, out_dir, this.power_network, on)
|
||||||
end
|
end
|
||||||
turn_on(item.pos, item.in_dir, on)
|
turn_on(item.pos, item.in_dir, on)
|
||||||
end
|
end
|
||||||
@ -220,16 +223,21 @@ function techage.distributor_after_dig_node(pos, oldnode)
|
|||||||
end
|
end
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Consumer with one power input side (default)
|
-- Consumer Nodes
|
||||||
--
|
--
|
||||||
function techage.consumer_power_consumption(pos, dir)
|
function techage.consumer_power_consumption(pos, dir)
|
||||||
local mem = tubelib2.get_mem(pos)
|
local mem = tubelib2.get_mem(pos)
|
||||||
|
if not TP(pos).valid_power_dir(pos, mem, dir) then return 0 end
|
||||||
mem.power_consume = mem.power_consume or 0
|
mem.power_consume = mem.power_consume or 0
|
||||||
return -mem.power_consume
|
return -mem.power_consume
|
||||||
end
|
end
|
||||||
|
|
||||||
function techage.consumer_after_place_node(pos, placer)
|
function techage.consumer_after_place_node(pos, placer)
|
||||||
local mem = tubelib2.init_mem(pos)
|
local mem = tubelib2.init_mem(pos)
|
||||||
|
if TP(pos).power_side then
|
||||||
|
-- For the consumer, power_dir is in-dir
|
||||||
|
mem.power_dir = tubelib2.Turn180Deg[side_to_dir(pos, TP(pos).power_side)]
|
||||||
|
end
|
||||||
TP(pos).power_network:after_place_node(pos)
|
TP(pos).power_network:after_place_node(pos)
|
||||||
return mem
|
return mem
|
||||||
end
|
end
|
||||||
@ -237,6 +245,7 @@ end
|
|||||||
function techage.consumer_after_tube_update(node, pos, out_dir, peer_pos, peer_in_dir)
|
function techage.consumer_after_tube_update(node, pos, out_dir, peer_pos, peer_in_dir)
|
||||||
local mem = tubelib2.get_mem(pos)
|
local mem = tubelib2.get_mem(pos)
|
||||||
mem.connections = mem.connections or {}
|
mem.connections = mem.connections or {}
|
||||||
|
if not TP(pos).valid_power_dir(pos, mem, tubelib2.Turn180Deg[out_dir]) then return end
|
||||||
-- Only one connection is allowed, which can be overwritten, if necessary.
|
-- Only one connection is allowed, which can be overwritten, if necessary.
|
||||||
if not peer_pos or not next(mem.connections) or mem.connections[out_dir] then
|
if not peer_pos or not next(mem.connections) or mem.connections[out_dir] then
|
||||||
if not peer_in_dir then
|
if not peer_in_dir then
|
||||||
|
@ -17,9 +17,14 @@ local function swap_node(pos, name)
|
|||||||
minetest.swap_node(pos, node)
|
minetest.swap_node(pos, node)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function lamp_turn_on(pos, dir, on)
|
-- To be able to check if power connection is on the
|
||||||
-- local mem = tubelib2.get_mem(pos)
|
-- correct node side (mem.power_dir == in_dir)
|
||||||
-- if mem.power_dir == dir or mem.power_dir == tubelib2.Turn180Deg[dir] then
|
local function valid_power_dir(pos, mem, in_dir)
|
||||||
|
print("valid_power_dir", mem.power_dir, in_dir)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
local function lamp_turn_on(pos, in_dir, on)
|
||||||
if on then
|
if on then
|
||||||
swap_node(pos, "techage:lamp_on")
|
swap_node(pos, "techage:lamp_on")
|
||||||
else
|
else
|
||||||
@ -43,6 +48,9 @@ minetest.register_node("techage:lamp", {
|
|||||||
turn_on = lamp_turn_on,
|
turn_on = lamp_turn_on,
|
||||||
power_consumption = techage.consumer_power_consumption,
|
power_consumption = techage.consumer_power_consumption,
|
||||||
power_network = techage.ElectricCable,
|
power_network = techage.ElectricCable,
|
||||||
|
power_side = "L",
|
||||||
|
valid_power_dir = valid_power_dir,
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
after_place_node = function(pos, placer)
|
after_place_node = function(pos, placer)
|
||||||
@ -72,6 +80,7 @@ minetest.register_node("techage:lamp_on", {
|
|||||||
power_consumption = techage.consumer_power_consumption,
|
power_consumption = techage.consumer_power_consumption,
|
||||||
power_network = techage.ElectricCable,
|
power_network = techage.ElectricCable,
|
||||||
power_consume = POWER_CONSUME,
|
power_consume = POWER_CONSUME,
|
||||||
|
valid_power_dir = valid_power_dir,
|
||||||
},
|
},
|
||||||
|
|
||||||
after_place_node = techage.consumer_after_place_node,
|
after_place_node = techage.consumer_after_place_node,
|
||||||
|
@ -24,7 +24,7 @@ local I,_ = dofile(MP.."/intllib.lua")
|
|||||||
|
|
||||||
local CYCLE_TIME = 4
|
local CYCLE_TIME = 4
|
||||||
local HEAT_STEP = 10
|
local HEAT_STEP = 10
|
||||||
local WATER_CONSUMPTION = 2
|
local WATER_CONSUMPTION = 0.5
|
||||||
local MAX_WATER = 10
|
local MAX_WATER = 10
|
||||||
local POWER = 10
|
local POWER = 10
|
||||||
|
|
||||||
|
@ -34,22 +34,22 @@ local function swap_node(pos, name)
|
|||||||
minetest.swap_node(pos, node)
|
minetest.swap_node(pos, node)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function turn_on(pos, dir, on)
|
local function valid_power_dir(pos, mem, in_dir)
|
||||||
--local mem = tubelib2.get_mem(pos)
|
return mem.power_dir == in_dir
|
||||||
--print("turn_on", mem.power_dir, dir, on)
|
end
|
||||||
--if mem.power_dir == dir then
|
|
||||||
local npos = techage.next_pos(pos, "R")
|
local function turn_on(pos, in_dir, on)
|
||||||
print("turn_on", S(pos), S(npos))
|
local npos = techage.next_pos(pos, "R")
|
||||||
local this = TP(npos)
|
print("turn_on", S(pos), S(npos), on)
|
||||||
if this and this.try_to_start then
|
local this = TP(npos)
|
||||||
on = this.try_to_start(npos, on)
|
if this and this.try_to_start then
|
||||||
end
|
on = this.try_to_start(npos, on)
|
||||||
if on then
|
end
|
||||||
swap_node(pos, "techage:cylinder_on")
|
if on then
|
||||||
else
|
swap_node(pos, "techage:cylinder_on")
|
||||||
swap_node(pos, "techage:cylinder")
|
else
|
||||||
end
|
swap_node(pos, "techage:cylinder")
|
||||||
--end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function node_timer(pos, elapsed)
|
local function node_timer(pos, elapsed)
|
||||||
@ -75,11 +75,11 @@ minetest.register_node("techage:cylinder", {
|
|||||||
power_network = techage.SteamPipe,
|
power_network = techage.SteamPipe,
|
||||||
power_consume = POWER_CONSUME,
|
power_consume = POWER_CONSUME,
|
||||||
power_side = 'L',
|
power_side = 'L',
|
||||||
|
valid_power_dir = valid_power_dir,
|
||||||
},
|
},
|
||||||
|
|
||||||
after_place_node = techage.consumer_after_place_node,
|
after_place_node = techage.consumer_after_place_node,
|
||||||
after_tube_update = techage.consumer_after_tube_update,
|
after_tube_update = techage.consumer_after_tube_update,
|
||||||
on_destruct = techage.consumer_on_destruct,
|
|
||||||
after_dig_node = techage.consumer_after_dig_node,
|
after_dig_node = techage.consumer_after_dig_node,
|
||||||
|
|
||||||
paramtype2 = "facedir",
|
paramtype2 = "facedir",
|
||||||
@ -124,11 +124,11 @@ minetest.register_node("techage:cylinder_on", {
|
|||||||
power_network = techage.SteamPipe,
|
power_network = techage.SteamPipe,
|
||||||
power_consume = POWER_CONSUME,
|
power_consume = POWER_CONSUME,
|
||||||
power_side = 'L',
|
power_side = 'L',
|
||||||
|
valid_power_dir = valid_power_dir,
|
||||||
},
|
},
|
||||||
|
|
||||||
after_place_node = techage.consumer_after_place_node,
|
after_place_node = techage.consumer_after_place_node,
|
||||||
after_tube_update = techage.consumer_after_tube_update,
|
after_tube_update = techage.consumer_after_tube_update,
|
||||||
on_destruct = techage.consumer_on_destruct,
|
|
||||||
after_dig_node = techage.consumer_after_dig_node,
|
after_dig_node = techage.consumer_after_dig_node,
|
||||||
|
|
||||||
paramtype2 = "facedir",
|
paramtype2 = "facedir",
|
||||||
|
@ -35,30 +35,29 @@ end
|
|||||||
|
|
||||||
local function turn_on(pos, dir, on)
|
local function turn_on(pos, dir, on)
|
||||||
print("jou")
|
print("jou")
|
||||||
-- if on then
|
if on then
|
||||||
-- swap_node(pos, "techage:flywheel_on")
|
swap_node(pos, "techage:flywheel_on")
|
||||||
-- if not minetest.get_node_timer(pos):is_started() then
|
if not minetest.get_node_timer(pos):is_started() then
|
||||||
-- minetest.get_node_timer(pos):start(CYCLE_TIME)
|
minetest.get_node_timer(pos):start(CYCLE_TIME)
|
||||||
-- end
|
end
|
||||||
-- else
|
else
|
||||||
-- swap_node(pos, "techage:flywheel")
|
swap_node(pos, "techage:flywheel")
|
||||||
-- if minetest.get_node_timer(pos):is_started() then
|
if minetest.get_node_timer(pos):is_started() then
|
||||||
-- minetest.get_node_timer(pos):stop()
|
minetest.get_node_timer(pos):stop()
|
||||||
-- end
|
end
|
||||||
-- end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function try_to_start(pos, on)
|
local function try_to_start(pos, on)
|
||||||
print("try_to_start", S(pos))
|
print("try_to_start", S(pos))
|
||||||
-- if on then
|
if on then
|
||||||
-- if techage.generator_on(pos, POWER) then
|
if techage.generator_on(pos, POWER) then
|
||||||
-- return true
|
return true
|
||||||
-- end
|
end
|
||||||
-- else
|
else
|
||||||
-- techage.generator_off(pos)
|
techage.generator_off(pos)
|
||||||
-- end
|
end
|
||||||
-- return false
|
return false
|
||||||
return on
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function formspec(mem)
|
local function formspec(mem)
|
||||||
@ -85,7 +84,7 @@ local function on_receive_fields(pos, formname, fields, player)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function on_rightclick(pos, node, clicker)
|
local function on_rightclick(pos)
|
||||||
local mem = tubelib2.get_mem(pos)
|
local mem = tubelib2.get_mem(pos)
|
||||||
M(pos):set_string("formspec", formspec(mem))
|
M(pos):set_string("formspec", formspec(mem))
|
||||||
end
|
end
|
||||||
@ -117,6 +116,10 @@ minetest.register_node("techage:flywheel", {
|
|||||||
try_to_start = try_to_start,
|
try_to_start = try_to_start,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
on_construct = function(pos)
|
||||||
|
on_rightclick(pos)
|
||||||
|
end,
|
||||||
|
|
||||||
after_place_node = techage.generator_after_place_node,
|
after_place_node = techage.generator_after_place_node,
|
||||||
after_tube_update = techage.generator_after_tube_update,
|
after_tube_update = techage.generator_after_tube_update,
|
||||||
on_destruct = techage.generator_on_destruct,
|
on_destruct = techage.generator_on_destruct,
|
||||||
|
Loading…
Reference in New Issue
Block a user