some bugs fixed

This commit is contained in:
Joachim Stolberg 2019-03-02 20:51:16 +01:00
parent e70e638d3a
commit b6d572ba26
12 changed files with 220 additions and 158 deletions

View File

@ -125,14 +125,10 @@ local function side_to_dir(side, param2)
return dir return dir
end end
local function get_dest_node(pos, side) local function get_dest_node(pos, out_dir)
-- TODO die Daten aus dem Cache holen und ueber die node callback wieder loeschen local spos, in_dir = Tube:get_connected_node_pos(pos, out_dir)
local _,node = Tube:get_node(pos) local _,node = Tube:get_node(spos)
local dir = side_to_dir(side, node.param2) return spos, in_dir, Name2Name[node.name] or node.name
local spos, sdir = Tube:get_connected_node_pos(pos, dir)
_,node = Tube:get_node(spos)
local in_side = dir_to_side(sdir, node.param2)
return spos, in_side, Name2Name[node.name] or node.name
end end
local function item_handling_node(name) local function item_handling_node(name)
@ -316,20 +312,20 @@ end
-- Client side Push/Pull item functions -- Client side Push/Pull item functions
------------------------------------------------------------------- -------------------------------------------------------------------
function techage.pull_items(pos, side, num) function techage.pull_items(pos, out_dir, num)
local npos, nside, name = get_dest_node(pos, side) local npos, in_dir, name = get_dest_node(pos, out_dir)
if npos == nil then return end if npos == nil then return end
if NodeDef[name] and NodeDef[name].on_pull_item then if NodeDef[name] and NodeDef[name].on_pull_item then
return NodeDef[name].on_pull_item(npos, nside, num) return NodeDef[name].on_pull_item(npos, in_dir, num)
end end
return nil return nil
end end
function techage.push_items(pos, side, stack) function techage.push_items(pos, out_dir, stack)
local npos, nside, name = get_dest_node(pos, side) local npos, in_dir, name = get_dest_node(pos, out_dir)
if npos == nil then return end if npos == nil then return end
if NodeDef[name] and NodeDef[name].on_push_item then if NodeDef[name] and NodeDef[name].on_push_item then
return NodeDef[name].on_push_item(npos, nside, stack) return NodeDef[name].on_push_item(npos, in_dir, stack)
elseif name == "air" then elseif name == "air" then
minetest.add_item(npos, stack) minetest.add_item(npos, stack)
return true return true
@ -337,11 +333,11 @@ function techage.push_items(pos, side, stack)
return false return false
end end
function techage.unpull_items(pos, side, items) function techage.unpull_items(pos, out_dir, items)
local npos, nside, name = get_dest_node(pos, side) local npos, in_dir, name = get_dest_node(pos, out_dir)
if npos == nil then return end if npos == nil then return end
if NodeDef[name] and NodeDef[name].on_unpull_item then if NodeDef[name] and NodeDef[name].on_unpull_item then
return NodeDef[name].on_unpull_item(npos, nside, items) return NodeDef[name].on_unpull_item(npos, in_dir, items)
end end
return false return false
end end

View File

@ -56,6 +56,11 @@ local function side_to_dir(pos, side)
return dir return dir
end end
function techage.next_pos(pos, side)
local dir = side_to_dir(pos, side)
return tubelib2.get_pos(pos, dir)
end
-- Calculate the power consumption on the given network -- Calculate the power consumption on the given network
local function power_consumption(pos, dir) local function power_consumption(pos, dir)
if pos_already_reached(pos) then return 0 end if pos_already_reached(pos) then return 0 end
@ -66,6 +71,7 @@ local function power_consumption(pos, dir)
if fdir ~= tubelib2.Turn180Deg[dir or 0] then if fdir ~= tubelib2.Turn180Deg[dir or 0] then
local this = TP(fpos) local this = TP(fpos)
if this and this.power_consumption then if this and this.power_consumption then
--print("power_consumption", S(fpos), dump(val), dump(this.power_consumption(fpos, fdir)))
val = val + this.power_consumption(fpos, fdir) val = val + this.power_consumption(fpos, fdir)
else else
val = val + power_consumption(fpos, fdir) val = val + power_consumption(fpos, fdir)
@ -76,12 +82,10 @@ local function power_consumption(pos, dir)
end end
local function turn_tube_on(pos, dir, network, on) local function turn_tube_on(pos, dir, network, on)
if network.switch_tube_line then if on then
if on then network:switch_tube_line(pos, dir, "on")
network:switch_tube_line(pos, dir, "on") else
else network:switch_tube_line(pos, dir, "off")
network:switch_tube_line(pos, dir, "off")
end
end end
end end
@ -89,14 +93,15 @@ local function turn_on(pos, dir, on)
if pos_already_reached(pos) then return end if pos_already_reached(pos) then return end
local mem = tubelib2.get_mem(pos) local mem = tubelib2.get_mem(pos)
local conn = mem.connections or {} local conn = mem.connections or {}
--print("turn_on", dump(conn))
for fdir,fpos in pairs(conn) do for fdir,fpos in pairs(conn) do
if fdir ~= tubelib2.Turn180Deg[dir or 0] then if fdir ~= tubelib2.Turn180Deg[dir or 0] then
local this = TP(fpos) local this = TP(fpos)
if this and this.turn_on then if this and this.turn_on then
this.turn_on(fpos, fdir, on) this.turn_on(fpos, fdir, on)
end end
if this and this.network then if this and this.animated_power_network then
turn_tube_on(pos, fdir, this.network, on) turn_tube_on(pos, fdir, this.power_network, on)
end end
turn_on(fpos, fdir, on) turn_on(fpos, fdir, on)
end end
@ -110,6 +115,7 @@ local function sink_power_consumption(pos, power)
Route = {} Route = {}
local sum = power + power_consumption(pos) local sum = power + power_consumption(pos)
Route = {} Route = {}
print("sink_power_consumption", sum)
turn_on(pos, nil, sum > 0) turn_on(pos, nil, sum > 0)
return sum return sum
end end
@ -128,13 +134,13 @@ techage.source_power_consumption = source_power_consumption
-- --
-- Generator with on power output side -- Generator with on power output side
-- --
function techage.generator_on(pos, power, network) function techage.generator_on(pos, power)
local mem = tubelib2.get_mem(pos) local mem = tubelib2.get_mem(pos)
mem.power_produce = power mem.power_produce = power
return source_power_consumption(pos, mem) return source_power_consumption(pos, mem)
end end
function techage.generator_off(pos, network) function techage.generator_off(pos)
local mem = tubelib2.get_mem(pos) local mem = tubelib2.get_mem(pos)
mem.power_produce = 0 mem.power_produce = 0
return source_power_consumption(pos, mem) return source_power_consumption(pos, mem)
@ -142,19 +148,19 @@ end
function techage.generator_power_consumption(pos, dir) function techage.generator_power_consumption(pos, dir)
local mem = tubelib2.get_mem(pos) local mem = tubelib2.get_mem(pos)
--print("generator_power_consumption", dir, mem.power_dir)
if dir == tubelib2.Turn180Deg[mem.power_dir or 0] then if dir == tubelib2.Turn180Deg[mem.power_dir or 0] then
return mem.power_produce return mem.power_produce or 0
end end
return 0 return 0
end end
function techage.generator_after_place_node(pos) function techage.generator_after_place_node(pos)
local mem = tubelib2.init_mem(pos) local mem = tubelib2.init_mem(pos)
mem.power_dir = side_to_dir(pos, TP(pos).side or 'R') mem.power_dir = side_to_dir(pos, TP(pos).power_side or 'R')
mem.power_produce = 0 -- will be set via generator_on mem.power_produce = 0 -- will be set via generator_on
mem.power_result = 0 mem.power_result = 0
local network = TP(pos).network TP(pos).power_network:after_place_node(pos)
network:after_place_node(pos)
end end
function techage.generator_after_tube_update(node, pos, out_dir, peer_pos, peer_in_dir) function techage.generator_after_tube_update(node, pos, out_dir, peer_pos, peer_in_dir)
@ -171,13 +177,13 @@ function techage.generator_on_destruct(pos)
techage.generator_off(pos) techage.generator_off(pos)
end end
function techage.generator_after_dig_node(pos, oldnode, oldmetadata, digger) function techage.generator_after_dig_node(pos, oldnode)
TN(oldnode).network:after_dig_node(pos) TN(oldnode).power_network:after_dig_node(pos)
tubelib2.del_mem(pos) tubelib2.del_mem(pos)
end end
function techage.generator_formspec_level(mem) function techage.generator_formspec_level(mem)
print("generator_formspec_level", mem.power_result, mem.power_produce) --print("generator_formspec_level", mem.power_result, mem.power_produce)
local percent = ((mem.power_result or 0) * 100) / (mem.power_produce or 1) local percent = ((mem.power_result or 0) * 100) / (mem.power_produce or 1)
return "techage_form_level_bg.png^[lowpart:"..percent..":techage_form_level_fg.png]" return "techage_form_level_bg.png^[lowpart:"..percent..":techage_form_level_fg.png]"
end end
@ -192,11 +198,12 @@ end
function techage.distributor_after_place_node(pos, placer) function techage.distributor_after_place_node(pos, placer)
local this = TP(pos) local this = TP(pos)
this.network:after_place_node(pos) this.power_network:after_place_node(pos)
sink_power_consumption(pos, -this.power_consume) sink_power_consumption(pos, -this.power_consume)
end end
function techage.distributor_after_tube_update(node, pos, out_dir, peer_pos, peer_in_dir) function techage.distributor_after_tube_update(node, pos, out_dir, peer_pos, peer_in_dir)
print("Distributor", node, S(pos), out_dir, S(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 {}
mem.connections[out_dir] = peer_pos mem.connections[out_dir] = peer_pos
@ -207,38 +214,42 @@ function techage.distributor_on_destruct(pos)
sink_power_consumption(pos, -TP(pos).power_consume) sink_power_consumption(pos, -TP(pos).power_consume)
end end
function techage.distributor_after_dig_node(pos, oldnode, oldmetadata, digger) function techage.distributor_after_dig_node(pos, oldnode)
TN(oldnode).network:after_dig_node(pos) TN(oldnode).power_network:after_dig_node(pos)
tubelib2.del_mem(pos) tubelib2.del_mem(pos)
end end
-- --
-- Consumer with on power input side (default) -- Consumer with one power input side (default)
-- --
function techage.consumer_power_consumption(pos) function techage.consumer_power_consumption(pos, dir)
print("consumer_power_consumption")
return -TP(pos).power_consume return -TP(pos).power_consume
end end
function techage.consumer_after_place_node(pos, placer) function techage.consumer_after_place_node(pos, placer)
print("consumer_after_place_node")
local mem = tubelib2.init_mem(pos) local mem = tubelib2.init_mem(pos)
mem.power_dir = tubelib2.Turn180Deg[side_to_dir(pos, TP(pos).side or 'L')]
local this = TP(pos) local this = TP(pos)
this.network:after_place_node(pos) mem.power_dir = tubelib2.Turn180Deg[side_to_dir(pos, this.power_side or 'L')]
sink_power_consumption(pos, -this.power_consume) this.power_network:after_place_node(pos)
--sink_power_consumption(pos, -this.power_consume)
end 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 = {[out_dir] = peer_pos}
mem.connections[out_dir] = peer_pos print("consumer_after_tube_update", out_dir, S(peer_pos))
sink_power_consumption(pos, -TP(pos).power_consume) local sum = sink_power_consumption(pos, -TP(pos).power_consume)
-- Needed to be able to turn off the consumer itself
TP(pos).turn_on(pos, nil, sum > 0)
end end
function techage.consumer_on_destruct(pos) function techage.consumer_on_destruct(pos)
sink_power_consumption(pos, -TP(pos).power_consume) sink_power_consumption(pos, -TP(pos).power_consume)
end end
function techage.consumer_after_dig_node(pos, oldnode, oldmetadata, digger) function techage.consumer_after_dig_node(pos, oldnode)
TN(oldnode).network:after_dig_node(pos) TN(oldnode).power_network:after_dig_node(pos)
tubelib2.del_mem(pos) tubelib2.del_mem(pos)
end end

View File

@ -26,6 +26,7 @@ local Cable = tubelib2.Tube:new({
dirs_to_check = {1,2,3,4,5,6}, dirs_to_check = {1,2,3,4,5,6},
max_tube_length = 1000, max_tube_length = 1000,
show_infotext = false, show_infotext = false,
force_to_use_tubes = true,
primary_node_names = {"techage:electric_cableS", "techage:electric_cableA"}, primary_node_names = {"techage:electric_cableS", "techage:electric_cableA"},
secondary_node_names = {"techage:lamp", "techage:lamp_on", "techage:power"}, secondary_node_names = {"techage:lamp", "techage:lamp_on", "techage:power"},
after_place_tube = function(pos, param2, tube_type, num_tubes) after_place_tube = function(pos, param2, tube_type, num_tubes)
@ -149,6 +150,11 @@ techage.register_junction("techage:electric_junction", 2/8, Boxes, Cable, {
tiles = {"techage_electric_junction.png"}, tiles = {"techage_electric_junction.png"},
groups = {snappy = 2, choppy = 2, oddly_breakable_by_hand = 3, techage_trowel = 1}, groups = {snappy = 2, choppy = 2, oddly_breakable_by_hand = 3, techage_trowel = 1},
sounds = default.node_sound_defaults(), sounds = default.node_sound_defaults(),
techage = {
power_consumption = techage.distributor_power_consumption,
power_network = Cable,
power_consume = 0,
},
after_place_node = function(pos, placer, itemstack, pointed_thing) after_place_node = function(pos, placer, itemstack, pointed_thing)
tubelib2.init_mem(pos) tubelib2.init_mem(pos)

View File

@ -18,14 +18,14 @@ local function swap_node(pos, name)
end end
local function lamp_turn_on(pos, dir, on) local function lamp_turn_on(pos, dir, on)
local mem = tubelib2.get_mem(pos) -- local mem = tubelib2.get_mem(pos)
if mem.power_dir == dir or mem.power_dir == tubelib2.Turn180Deg[dir] then -- if mem.power_dir == dir or mem.power_dir == tubelib2.Turn180Deg[dir] then
if on then if on then
swap_node(pos, "techage:lamp_on") swap_node(pos, "techage:lamp_on")
else else
swap_node(pos, "techage:lamp") swap_node(pos, "techage:lamp")
end end
end -- end
end end
minetest.register_node("techage:lamp", { minetest.register_node("techage:lamp", {
@ -36,15 +36,15 @@ minetest.register_node("techage:lamp", {
'techage_electric_button.png', 'techage_electric_button.png',
'techage_electric_button.png', 'techage_electric_button.png',
'techage_electric_button.png', 'techage_electric_button.png',
'techage_electric_button.png^techage_electric_plug.png', 'techage_electric_button.png',
'techage_electric_button.png^techage_electric_plug.png', 'techage_electric_button.png',
}, },
techage = { techage = {
turn_on = lamp_turn_on, turn_on = lamp_turn_on,
power_consumption = techage.consumer_power_consumption, power_consumption = techage.consumer_power_consumption,
network = techage.ElectricCable, power_network = techage.ElectricCable,
power_consume = POWER_CONSUME, power_consume = POWER_CONSUME,
side = 'B', power_side = 'B',
}, },
after_place_node = techage.consumer_after_place_node, after_place_node = techage.consumer_after_place_node,
@ -69,7 +69,7 @@ minetest.register_node("techage:lamp_on", {
techage = { techage = {
turn_on = lamp_turn_on, turn_on = lamp_turn_on,
power_consumption = techage.consumer_power_consumption, power_consumption = techage.consumer_power_consumption,
network = techage.ElectricCable, power_network = techage.ElectricCable,
power_consume = POWER_CONSUME, power_consume = POWER_CONSUME,
}, },
@ -106,7 +106,7 @@ minetest.register_node("techage:power", {
is_ground_content = false, is_ground_content = false,
techage = { techage = {
network = Cable, power_network = Cable,
power_consumption = techage.generator_power_consumption, power_consumption = techage.generator_power_consumption,
}, },

View File

@ -22,7 +22,7 @@ dofile(MP.."/steam_engine/drive_axle.lua")
dofile(MP.."/steam_engine/steam_pipe.lua") dofile(MP.."/steam_engine/steam_pipe.lua")
dofile(MP.."/steam_engine/firebox.lua") dofile(MP.."/steam_engine/firebox.lua")
dofile(MP.."/steam_engine/boiler.lua") dofile(MP.."/steam_engine/boiler.lua")
--dofile(MP.."/steam_engine/cylinder.lua") dofile(MP.."/steam_engine/cylinder.lua")
dofile(MP.."/steam_engine/flywheel.lua") dofile(MP.."/steam_engine/flywheel.lua")
dofile(MP.."/steam_engine/gearbox.lua") dofile(MP.."/steam_engine/gearbox.lua")

View File

@ -93,7 +93,7 @@ local function start_boiler(pos)
mem.water_level = mem.water_level or 0 mem.water_level = mem.water_level or 0
local inv = M(pos):get_inventory() local inv = M(pos):get_inventory()
local water_stack = inv:get_stack("water", 1) local water_stack = inv:get_stack("water", 1)
print("trigger_boiler", mem.fire_trigger, mem.water_level, water_stack:get_count()) --print("trigger_boiler", mem.fire_trigger, mem.water_level, water_stack:get_count())
if mem.fire_trigger and (mem.water_level > 0 or water_stack:get_count() > 0) then if mem.fire_trigger and (mem.water_level > 0 or water_stack:get_count() > 0) then
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)
@ -191,14 +191,45 @@ local function node_timer(pos)
end end
minetest.register_node("techage:boiler", { minetest.register_node("techage:boiler1", {
description = I("TA2 Boiler"), description = I("TA2 Boiler"),
tiles = {"techage_boiler.png"}, tiles = {"techage_boiler.png"},
drawtype = "mesh", drawtype = "mesh",
mesh = "techage_boiler.obj", mesh = "techage_boiler.obj",
selection_box = { selection_box = {
type = "fixed", type = "fixed",
fixed = {-10/32, -16/32, -10/32, 10/32, 46/32, 10/32}, fixed = {-8/32, -16/32, -8/32, 8/32, 16/32, 8/32},
},
on_construct = function(pos)
local param2 = minetest.get_node(pos).param2
local pos2 = {x=pos.x, y=pos.y+1, z=pos.z}
local node = minetest.get_node(pos2)
if node.name == "air" then
minetest.set_node(pos2, {name="techage:boiler2", param2 = param2})
minetest.registered_nodes["techage:boiler2"].on_construct(pos2)
minetest.registered_nodes["techage:boiler2"].after_place_node(pos2)
on_rightclick(pos2)
end
end,
paramtype2 = "facedir",
--diggable = false,
groups = {cracky=1},
on_rotate = screwdriver.disallow,
is_ground_content = false,
sounds = default.node_sound_metal_defaults(),
})
-- boiler2: Main part, needed as generator
minetest.register_node("techage:boiler2", {
description = ("TA2 Boiler"),
tiles = {"techage_boiler2.png"},
drawtype = "mesh",
mesh = "techage_boiler.obj",
selection_box = {
type = "fixed",
fixed = {-10/32, -48/32, -10/32, 10/32, 16/32, 10/32},
}, },
can_dig = can_dig, can_dig = can_dig,
@ -209,85 +240,44 @@ minetest.register_node("techage:boiler", {
on_rightclick = on_rightclick, on_rightclick = on_rightclick,
techage = { techage = {
network = techage.SteamPipe, power_network = techage.SteamPipe,
power_consumption = function(pos, dir) power_consumption = techage.generator_power_consumption,
techage.generator_power_consumption(pos, dir) power_consume = 0,
end,
trigger_boiler = function(pos) trigger_boiler = function(pos)
local mem = tubelib2.get_mem(pos) local mem = tubelib2.get_mem(pos)
mem.fire_trigger = true mem.fire_trigger = true
start_boiler(pos) start_boiler(pos)
end, end,
power_side = "U",
}, },
on_destruct = function(pos) after_place_node = techage.generator_after_place_node,
techage.generator_on_destruct({x=pos.x, y=pos.y+1, z=pos.z}) after_tube_update = techage.generator_after_tube_update,
end, on_destruct = techage.generator_on_destruct,
on_construct = function(pos) on_construct = function(pos)
local inv = M(pos):get_inventory() local inv = M(pos):get_inventory()
inv:set_size('water', 1) inv:set_size('water', 1)
inv:set_size('input', 1) inv:set_size('input', 1)
local node = minetest.get_node({x=pos.x, y=pos.y+1, z=pos.z})
if node.name ~= "air" then
return
end
minetest.add_node({x=pos.x, y=pos.y+1, z=pos.z}, {name = "techage:boiler2", param2 = minetest.get_node(pos).param2})
end, end,
after_place_node = function(pos, placer, pointed_thing) after_dig_node = function(pos, oldnode)
techage.generator_after_place_node({x=pos.x, y=pos.y+1, z=pos.z}, placer) techage.generator_after_dig_node(pos, oldnode)
local mem = tubelib2.get_mem(pos) local node = minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z})
mem.running = false if node.name == "techage:boiler1" then
mem.water_level = 0 minetest.remove_node({x=pos.x, y=pos.y-1, z=pos.z})
mem.temperatur = 20 end
M(pos):set_string("formspec", formspec(mem))
end, end,
on_metadata_inventory_put = function(pos) on_metadata_inventory_put = function(pos)
minetest.after(0.5, move_to_water, pos) minetest.after(0.5, move_to_water, pos)
end, end,
after_dig_node = function(pos, oldnode, oldmetadata, digger)
local node = minetest.get_node({x=pos.x, y=pos.y+1, z=pos.z})
if node.name == "techage:boiler2" then
minetest.remove_node({x=pos.x, y=pos.y+1, z=pos.z})
techage.generator_after_dig_node({x=pos.x, y=pos.y+1, z=pos.z}, oldnode, oldmetadata, digger)
end
end,
paramtype2 = "facedir", paramtype2 = "facedir",
groups = {cracky=1}, groups = {cracky=1, not_in_creative_inventory=1},
drop = "techage:boiler1",
on_rotate = screwdriver.disallow, on_rotate = screwdriver.disallow,
is_ground_content = false, is_ground_content = false,
sounds = default.node_sound_metal_defaults(), sounds = default.node_sound_metal_defaults(),
}) })
-- boiler2
minetest.register_node("techage:boiler2", {
description = ("TA2 Boiler"),
tiles = {"techage_boiler2.png"},
drawtype = "mesh",
mesh = "techage_boiler.obj",
selection_box = {
type = "fixed",
fixed = {-10/32, -16/32, -10/32, 10/32, 16/32, 10/32},
},
techage = {
network = techage.SteamPipe,
power_consumption = function(pos, dir)
techage.generator_power_consumption({x=pos.x, y=pos.y-1, z=pos.z}, dir)
end,
},
after_tube_update = function(node, pos, out_dir, peer_pos, peer_in_dir)
techage.generator_after_tube_update(node,
{x=pos.x, y=pos.y-1, z=pos.z}, out_dir, peer_pos, peer_in_dir)
end,
diggable = false,
--pointable = false,
groups = {not_in_creative_inventory = 1},
})

View File

@ -16,16 +16,14 @@
local S = function(pos) if pos then return minetest.pos_to_string(pos) end end local S = function(pos) if pos then return minetest.pos_to_string(pos) end end
local P = minetest.string_to_pos local P = minetest.string_to_pos
local M = minetest.get_meta local M = minetest.get_meta
local TP = function(pos) return minetest.registered_nodes[minetest.get_node(pos).name].techage end
local TN = function(node) return minetest.registered_nodes[node.name].techage end
-- Load support for intllib. -- Load support for intllib.
local MP = minetest.get_modpath("tubelib2") local MP = minetest.get_modpath("tubelib2")
local I,_ = dofile(MP.."/intllib.lua") local I,_ = dofile(MP.."/intllib.lua")
local POWER_CONSUME = 8
local function can_dig(pos, player)
local inv = M(pos):get_inventory()
return inv:is_empty("fuel")
end
local function swap_node(pos, name) local function swap_node(pos, name)
local node = minetest.get_node(pos) local node = minetest.get_node(pos)
@ -36,6 +34,24 @@ 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 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
end
local function node_timer(pos, elapsed) local function node_timer(pos, elapsed)
local mem = tubelib2.get_mem(pos) local mem = tubelib2.get_mem(pos)
local inv = M(pos):get_inventory() local inv = M(pos):get_inventory()
@ -48,11 +64,23 @@ minetest.register_node("techage:cylinder", {
-- up, down, right, left, back, front -- up, down, right, left, back, front
"techage_filling_ta2.png^techage_frame_ta2.png", "techage_filling_ta2.png^techage_frame_ta2.png",
"techage_filling_ta2.png^techage_frame_ta2.png", "techage_filling_ta2.png^techage_frame_ta2.png",
"techage_filling_ta2.png^techage_frame_ta2.png", "techage_filling_ta2.png^techage_appl_open.png^techage_frame_ta2.png",
"techage_filling_ta2.png^techage_frame_ta2.png", "techage_filling_ta2.png^techage_frame_ta2.png^techage_steam_hole.png",
"techage_filling_ta2.png^techage_cylinder.png^techage_frame_ta2.png", "techage_filling_ta2.png^techage_cylinder.png^techage_frame_ta2.png",
"techage_filling_ta2.png^techage_cylinder.png^techage_frame_ta2.png", "techage_filling_ta2.png^techage_cylinder.png^techage_frame_ta2.png",
}, },
techage = {
turn_on = turn_on,
power_consumption = techage.consumer_power_consumption,
power_network = techage.SteamPipe,
power_consume = POWER_CONSUME,
power_side = 'L',
},
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", paramtype2 = "facedir",
groups = {cracky=2, crumbly=2, choppy=2}, groups = {cracky=2, crumbly=2, choppy=2},
@ -67,8 +95,8 @@ minetest.register_node("techage:cylinder_on", {
-- up, down, right, left, back, front -- up, down, right, left, back, front
"techage_filling_ta2.png^techage_frame_ta2.png", "techage_filling_ta2.png^techage_frame_ta2.png",
"techage_filling_ta2.png^techage_frame_ta2.png", "techage_filling_ta2.png^techage_frame_ta2.png",
"techage_filling_ta2.png^techage_frame_ta2.png", "techage_filling_ta2.png^techage_appl_open.png^techage_frame_ta2.png",
"techage_filling_ta2.png^techage_frame_ta2.png", "techage_filling_ta2.png^techage_frame_ta2.png^techage_steam_hole.png",
{ {
image = "techage_filling4_ta2.png^techage_cylinder4.png^techage_frame4_ta2.png", image = "techage_filling4_ta2.png^techage_cylinder4.png^techage_frame4_ta2.png",
backface_culling = false, backface_culling = false,
@ -90,14 +118,24 @@ minetest.register_node("techage:cylinder_on", {
}, },
}, },
}, },
paramtype = "light", techage = {
light_source = 0, turn_on = turn_on,
sunlight_propagates = true, power_consumption = techage.consumer_power_consumption,
power_network = techage.SteamPipe,
power_consume = POWER_CONSUME,
power_side = 'L',
},
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", paramtype2 = "facedir",
groups = {not_in_creative_inventory=1},
diggable = false,
on_rotate = screwdriver.disallow, on_rotate = screwdriver.disallow,
groups = {cracky=2, crumbly=2, choppy=2, not_in_creative_inventory = 1},
drop = "techage:cylinder",
is_ground_content = false, is_ground_content = false,
sounds = default.node_sound_metal_defaults(), sounds = default.node_sound_wood_defaults(),
}) })

View File

@ -79,7 +79,7 @@ minetest.register_node("techage:axle", {
sunlight_propagates = true, sunlight_propagates = true,
is_ground_content = false, is_ground_content = false,
groups = {crumbly = 3, cracky = 3, snappy = 3}, groups = {crumbly = 3, cracky = 3, snappy = 3},
sounds = default.node_sound_metal_defaults(), sounds = default.node_sound_wood_defaults(),
}) })
minetest.register_node("techage:axle_on", { minetest.register_node("techage:axle_on", {
@ -173,5 +173,5 @@ minetest.register_node("techage:axle_on", {
is_ground_content = false, is_ground_content = false,
diggable = false, diggable = false,
groups = {not_in_creative_inventory = 1}, groups = {not_in_creative_inventory = 1},
sounds = default.node_sound_metal_defaults(), sounds = default.node_sound_wood_defaults(),
}) })

View File

@ -105,9 +105,9 @@ end
local function node_timer(pos, elapsed) local function node_timer(pos, elapsed)
local mem = tubelib2.get_mem(pos) local mem = tubelib2.get_mem(pos)
if mem.running then if mem.running then
local this = TP({x=pos.x, y=pos.y+1, z=pos.z}) local this = TP({x=pos.x, y=pos.y+2, z=pos.z})
if this and this.trigger_boiler then if this and this.trigger_boiler then
this.trigger_boiler({x=pos.x, y=pos.y+1, z=pos.z}) this.trigger_boiler({x=pos.x, y=pos.y+2, z=pos.z})
end end
mem.burn_cycles = (mem.burn_cycles or 0) - 1 mem.burn_cycles = (mem.burn_cycles or 0) - 1
if mem.burn_cycles <= 0 then if mem.burn_cycles <= 0 then

View File

@ -33,6 +33,34 @@ 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)
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
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
end
local function formspec(mem) local function formspec(mem)
return "size[8,7]".. return "size[8,7]"..
default.gui_bg.. default.gui_bg..
@ -69,21 +97,6 @@ local function node_timer(pos, elapsed)
return true return true
end end
local function on_punch(pos, node, puncher, pointed_thing)
local mem = tubelib2.get_mem(pos)
if mem.power_produce and mem.power_produce > 0 then
swap_node(pos, "techage:flywheel")
techage.generator_off(pos, techage.Axle)
--techage.generator_off(pos)
minetest.get_node_timer(pos):stop()
else
swap_node(pos, "techage:flywheel_on")
techage.generator_on(pos, POWER, techage.Axle)
--techage.generator_on(pos, POWER)
minetest.get_node_timer(pos):start(CYCLE_TIME)
end
end
minetest.register_node("techage:flywheel", { minetest.register_node("techage:flywheel", {
description = I("TA2 Flywheel"), description = I("TA2 Flywheel"),
tiles = { tiles = {
@ -96,8 +109,12 @@ minetest.register_node("techage:flywheel", {
"techage_filling_ta2.png^techage_frame_ta2.png^techage_flywheel.png^[transformFX]", "techage_filling_ta2.png^techage_frame_ta2.png^techage_flywheel.png^[transformFX]",
}, },
techage = { techage = {
network = techage.Axle, power_network = techage.Axle,
power_consumption = techage.generator_power_consumption, power_consumption = techage.generator_power_consumption,
power_consume = 0,
animated_power_network = true,
turn_on = turn_on,
try_to_start = try_to_start,
}, },
after_place_node = techage.generator_after_place_node, after_place_node = techage.generator_after_place_node,
@ -108,7 +125,6 @@ minetest.register_node("techage:flywheel", {
on_timer = node_timer, on_timer = node_timer,
on_receive_fields = on_receive_fields, on_receive_fields = on_receive_fields,
on_rightclick = on_rightclick, on_rightclick = on_rightclick,
on_punch = on_punch,
paramtype2 = "facedir", paramtype2 = "facedir",
groups = {cracky=2, crumbly=2, choppy=2}, groups = {cracky=2, crumbly=2, choppy=2},
@ -156,8 +172,12 @@ minetest.register_node("techage:flywheel_on", {
}, },
}, },
techage = { techage = {
network = techage.Axle, power_network = techage.Axle,
power_consumption = techage.generator_power_consumption, power_consumption = techage.generator_power_consumption,
power_consume = 0,
animated_power_network = true,
turn_on = turn_on,
try_to_start = try_to_start,
}, },
after_place_node = techage.generator_after_place_node, after_place_node = techage.generator_after_place_node,
@ -168,7 +188,6 @@ minetest.register_node("techage:flywheel_on", {
on_timer = node_timer, on_timer = node_timer,
on_receive_fields = on_receive_fields, on_receive_fields = on_receive_fields,
on_rightclick = on_rightclick, on_rightclick = on_rightclick,
on_punch = on_punch,
paramtype2 = "facedir", paramtype2 = "facedir",
groups = {cracky=2, crumbly=2, choppy=2, not_in_creative_inventory=1}, groups = {cracky=2, crumbly=2, choppy=2, not_in_creative_inventory=1},

View File

@ -47,8 +47,9 @@ minetest.register_node("techage:gearbox", {
techage = { techage = {
turn_on = turn_on, turn_on = turn_on,
power_consumption = techage.distributor_power_consumption, power_consumption = techage.distributor_power_consumption,
network = techage.Axle, power_network = techage.Axle,
power_consume = POWER_CONSUME, power_consume = POWER_CONSUME,
animated_power_network = true,
}, },
after_place_node = techage.distributor_after_place_node, after_place_node = techage.distributor_after_place_node,
@ -81,8 +82,9 @@ minetest.register_node("techage:gearbox_on", {
techage = { techage = {
turn_on = turn_on, turn_on = turn_on,
power_consumption = techage.distributor_power_consumption, power_consumption = techage.distributor_power_consumption,
network = techage.Axle, power_network = techage.Axle,
power_consume = POWER_CONSUME, power_consume = POWER_CONSUME,
animated_power_network = true,
}, },
after_place_node = techage.distributor_after_place_node, after_place_node = techage.distributor_after_place_node,

View File

@ -24,10 +24,10 @@ local I,_ = dofile(MP.."/intllib.lua")
local Pipe = tubelib2.Tube:new({ local Pipe = tubelib2.Tube:new({
dirs_to_check = {1,2,3,4,5,6}, dirs_to_check = {1,2,3,4,5,6},
max_tube_length = 1000, max_tube_length = 6,
show_infotext = false, show_infotext = false,
primary_node_names = {"techage:steam_pipeS", "techage:steam_pipeA"}, primary_node_names = {"techage:steam_pipeS", "techage:steam_pipeA"},
secondary_node_names = {"techage:cylinder", "techage:boiler2"}, secondary_node_names = {"techage:cylinder", "techage:cylinder_on", "techage:boiler2"},
after_place_tube = function(pos, param2, tube_type, num_tubes) after_place_tube = function(pos, param2, tube_type, num_tubes)
minetest.swap_node(pos, {name = "techage:steam_pipe"..tube_type, param2 = param2}) minetest.swap_node(pos, {name = "techage:steam_pipe"..tube_type, param2 = param2})
end, end,