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