diff --git a/.test/akku.lua b/.test/akku.lua index bc3da8f..80893d3 100644 --- a/.test/akku.lua +++ b/.test/akku.lua @@ -55,7 +55,8 @@ local function on_receive_fields(pos, formname, fields, player) end local function after_place_node(pos, placer) - local mem = tubelib2.init_mem(pos) + -- secondary 'after_place_node', called by power. Don't use tubelib2.init_mem(pos)!!! + local mem = tubelib2.get_mem(pos) mem.running = true mem.capa = 0 minetest.get_node_timer(pos):start(CYCLE_TIME) diff --git a/.test/sink.lua b/.test/sink.lua index 65711d7..29a555a 100644 --- a/.test/sink.lua +++ b/.test/sink.lua @@ -65,7 +65,8 @@ minetest.register_node("techage:sink", { tiles = {'techage_electric_button.png'}, after_place_node = function(pos) - local mem = tubelib2.init_mem(pos) + -- secondary 'after_place_node', called by power. Don't use tubelib2.init_mem(pos)!!! + local mem = tubelib2.get_mem(pos) M(pos):set_string("infotext", "off") end, diff --git a/.test/source.lua b/.test/source.lua index b6cf457..aef2cd5 100644 --- a/.test/source.lua +++ b/.test/source.lua @@ -46,7 +46,8 @@ minetest.register_node("techage:source", { 'techage_electric_button.png^techage_appl_electronic_fab.png', }, after_place_node = function(pos) - local mem = tubelib2.init_mem(pos) + -- secondary 'after_place_node', called by power. Don't use tubelib2.init_mem(pos)!!! + local mem = tubelib2.get_mem(pos) M(pos):set_string("infotext", "off") end, diff --git a/basic_machines/source.lua b/basic_machines/source.lua index 1961a69..eaeed2f 100644 --- a/basic_machines/source.lua +++ b/basic_machines/source.lua @@ -126,7 +126,8 @@ minetest.register_node("techage:t2_source", { on_construct = tubelib2.init_mem, after_place_node = function(pos, placer) - local mem = tubelib2.init_mem(pos) + -- secondary 'after_place_node', called by power. Don't use tubelib2.init_mem(pos)!!! + local mem = tubelib2.get_mem(pos) State2:node_init(pos, mem, "") mem.state_num = 2 on_rightclick(pos) @@ -155,6 +156,7 @@ minetest.register_node("techage:t3_source", { on_construct = tubelib2.init_mem, after_place_node = function(pos, placer) + -- secondary 'after_place_node', called by power. Don't use tubelib2.init_mem(pos)!!! local mem = tubelib2.get_mem(pos) State3:node_init(pos, mem, "") mem.state_num = 3 @@ -184,6 +186,7 @@ minetest.register_node("techage:t4_source", { on_construct = tubelib2.init_mem, after_place_node = function(pos, placer) + -- secondary 'after_place_node', called by power. Don't use tubelib2.init_mem(pos)!!! local mem = tubelib2.get_mem(pos) State4:node_init(pos, mem, "") mem.state_num = 4 diff --git a/coal_power_station/akkubox.lua b/coal_power_station/akkubox.lua index 5d16813..a189571 100644 --- a/coal_power_station/akkubox.lua +++ b/coal_power_station/akkubox.lua @@ -130,7 +130,8 @@ minetest.register_node("techage:ta3_akku", { on_construct = tubelib2.init_mem, after_place_node = function(pos, placer, itemstack) - local mem = tubelib2.init_mem(pos) + -- secondary 'after_place_node', called by power. Don't use tubelib2.init_mem(pos)!!! + local mem = tubelib2.get_mem(pos) State:node_init(pos, mem, "") mem.capa = get_capa(itemstack) on_rightclick(pos) diff --git a/coal_power_station/boiler_top.lua b/coal_power_station/boiler_top.lua index a11646b..f7e7c99 100644 --- a/coal_power_station/boiler_top.lua +++ b/coal_power_station/boiler_top.lua @@ -245,7 +245,8 @@ minetest.register_node("techage:coalboiler_top", { end, after_place_node = function(pos, placer) - local mem = tubelib2.init_mem(pos) + -- secondary 'after_place_node', called by power. Don't use tubelib2.init_mem(pos)!!! + local mem = tubelib2.get_mem(pos) State:node_init(pos, mem, "") local node = minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z}) if node.name == "techage:coalboiler_base" then diff --git a/coal_power_station/generator.lua b/coal_power_station/generator.lua index 65da03d..18f73b8 100644 --- a/coal_power_station/generator.lua +++ b/coal_power_station/generator.lua @@ -115,7 +115,8 @@ minetest.register_node("techage:generator", { on_construct = tubelib2.init_mem, after_place_node = function(pos, placer) - local mem = tubelib2.init_mem(pos) + -- secondary 'after_place_node', called by power. Don't use tubelib2.init_mem(pos)!!! + local mem = tubelib2.get_mem(pos) local number = techage.add_node(pos, "techage:generator") State:node_init(pos, mem, number) on_rightclick(pos) diff --git a/furnace/booster.lua b/furnace/booster.lua index 539817a..9206b39 100644 --- a/furnace/booster.lua +++ b/furnace/booster.lua @@ -78,7 +78,8 @@ minetest.register_node("techage:ta3_booster", { on_construct = tubelib2.init_mem, after_place_node = function(pos, placer) - local mem = tubelib2.init_mem(pos) + -- secondary 'after_place_node', called by power. Don't use tubelib2.init_mem(pos)!!! + local mem = tubelib2.get_mem(pos) local node = minetest.get_node(pos) local indir = techage.side_to_indir("R", node.param2) M(pos):set_int("indir", indir) diff --git a/init.lua b/init.lua index 8584a41..463a99b 100644 --- a/init.lua +++ b/init.lua @@ -63,6 +63,7 @@ else dofile(MP.."/power/power_line.lua") dofile(MP.."/power/junctionbox.lua") dofile(MP.."/power/powerswitch.lua") + dofile(MP.."/power/protection.lua") -- Iron Age dofile(MP.."/iron_age/main.lua") @@ -150,7 +151,6 @@ else end dofile(MP.."/nodes/gateblock.lua") dofile(MP.."/nodes/doorblock.lua") - dofile(MP.."/nodes/pillar.lua") -- Logic dofile(MP.."/logic/lib.lua") @@ -178,4 +178,7 @@ else dofile(MP.."/nodes/silicon.lua") dofile(MP.."/solar/minicell.lua") + -- Wind + dofile(MP.."/wind_turbine/rotor.lua") + dofile(MP.."/nodes/pillar.lua") end \ No newline at end of file diff --git a/power/electric_cable.lua b/power/electric_cable.lua index 5b12774..1a52448 100644 --- a/power/electric_cable.lua +++ b/power/electric_cable.lua @@ -23,12 +23,16 @@ local Cable = tubelib2.Tube:new({ max_tube_length = 1000, show_infotext = false, tube_type = "electric_cable", - primary_node_names = {"techage:electric_cableS", "techage:electric_cableA", "techage:power_line", "techage:power_lineS", "techage:power_lineA"}, + primary_node_names = {"techage:electric_cableS", "techage:electric_cableA", + "techage:power_line", "techage:power_lineS", "techage:power_lineA", "techage:power_pole2"}, secondary_node_names = {}, after_place_tube = function(pos, param2, tube_type, num_tubes) -- Handle "power line" nodes local name = minetest.get_node(pos).name - if name == "techage:power_line" or name == "techage:power_lineS" or name == "techage:power_lineA" then + if name == "techage:power_pole2" then + M(pos):set_int("tl2_param2", param2) + return + elseif name == "techage:power_line" or name == "techage:power_lineS" or name == "techage:power_lineA" then minetest.swap_node(pos, {name = "techage:power_line"..tube_type, param2 = param2 % 32}) M(pos):set_int("tl2_param2", param2) return diff --git a/power/power_line.lua b/power/power_line.lua index b744480..f9a4933 100644 --- a/power/power_line.lua +++ b/power/power_line.lua @@ -163,7 +163,7 @@ minetest.register_node("techage:power_lineA", { }) minetest.register_node("techage:power_pole", { - description = S("TA Power Pole"), + description = S("TA Power Pole Top 4"), --tiles = {"techage_power_pole.png"}, tiles = { "default_wood.png^techage_power_pole_top.png", @@ -185,6 +185,109 @@ minetest.register_node("techage:power_pole", { { -2/32, -4/32, 12/32, 2/32, 4/32, 16/32}, }, }, + after_place_node = function(pos, placer, itemstack, pointed_thing) + if techage.is_protected(pos, placer:get_player_name()) then + minetest.remove_node(pos) + return true + end + M(pos):set_string("owner", placer:get_player_name()) + end, + can_dig = function(pos, digger) + local meta = minetest.get_meta(pos) + if meta:get_string("owner") == digger:get_player_name() then + return true + end + if minetest.check_player_privs(digger:get_player_name(), "powerline") then + return true + end + return false + end, + + on_rotate = screwdriver.disallow, -- important! + paramtype = "light", + sunlight_propagates = true, + is_ground_content = false, + groups = {cracky=2, crumbly=2, choppy=2}, + sounds = default.node_sound_defaults(), +}) + +minetest.register_node("techage:power_pole2", { + description = S("TA Power Pole Top 2"), + --tiles = {"techage_power_pole.png"}, + tiles = { + "default_wood.png^techage_power_pole_top.png", + "default_wood.png^techage_power_pole_top.png", + "default_wood.png^techage_power_pole.png" + }, + + paramtype2 = "facedir", -- important! + drawtype = "nodebox", + node_box = { + type = "fixed", + fixed = { + { -4/32, -16/32, -4/32, 4/32, 16/32, 4/32}, + { -1/32, -6/32, -16/32, 1/32, -4/32, 16/32}, + { -2/32, -4/32, -16/32, 2/32, 4/32, -12/32}, + { -2/32, -4/32, 12/32, 2/32, 4/32, 16/32}, + }, + }, + after_place_node = function(pos, placer, itemstack, pointed_thing) + end, + + after_place_node = function(pos, placer, itemstack, pointed_thing) + if techage.is_protected(pos, placer:get_player_name()) then + minetest.remove_node(pos) + return true + end + if not Cable:after_place_tube(pos, placer, pointed_thing) then + minetest.remove_node(pos) + return true + end + M(pos):set_string("owner", placer:get_player_name()) + return false + end, + can_dig = function(pos, digger) + local meta = minetest.get_meta(pos) + if meta:get_string("owner") == digger:get_player_name() then + return true + end + if minetest.check_player_privs(digger:get_player_name(), "powerline") then + return true + end + return false + end, + after_dig_node = function(pos, oldnode, oldmetadata, digger) + if oldmetadata and oldmetadata.fields and oldmetadata.fields.tl2_param2 then + oldnode.param2 = oldmetadata.fields.tl2_param2 + Cable:after_dig_tube(pos, oldnode) + end + end, + + on_rotate = screwdriver.disallow, -- important! + paramtype = "light", + sunlight_propagates = true, + is_ground_content = false, + groups = {cracky=2, crumbly=2, choppy=2}, + sounds = default.node_sound_defaults(), +}) + +minetest.register_node("techage:power_pole3", { + description = S("TA Power Pole"), + --tiles = {"techage_power_pole.png"}, + tiles = { + "default_wood.png", + "default_wood.png", + "default_wood.png" + }, + + paramtype2 = "facedir", -- important! + drawtype = "nodebox", + node_box = { + type = "fixed", + fixed = { + { -4/32, -16/32, -4/32, 4/32, 16/32, 4/32}, + }, + }, on_rotate = screwdriver.disallow, -- important! paramtype = "light", sunlight_propagates = true, @@ -207,19 +310,29 @@ minetest.register_craft({ }) minetest.register_craft({ - output = "techage:power_pole", + output = "techage:power_pole2", recipe = { - {"default:stick", "techage:power_lineS", "default:stick"}, + {"", "default:stick", ""}, {"techage:power_lineS", "default:copper_ingot", "techage:power_lineS"}, - {"default:stick", "techage:power_lineS", "default:stick"}, + {"", "default:stick", ""}, + }, +}) + +minetest.register_craft({ + output = "techage:power_pole", + recipe = { + {"", "", ""}, + {"", "techage:power_pole2", ""}, + {"", "techage:power_pole2", ""}, + }, +}) + +minetest.register_craft({ + output = "techage:power_pole3 4", + recipe = { + {"", "group:wood", ""}, + {"", "techage:power_lineS", ""}, + {"", "group:wood", ""}, }, }) -if minetest.global_exists("minecart") and minecart.register_protected_node then - minecart.register_protected_node("techage:power_line") - minecart.register_protected_node("techage:power_lineS") - minecart.register_protected_node("techage:power_lineA") - minecart.register_protected_node("techage:power_pole") - minecart.register_protected_node("default:fence_wood") - -end \ No newline at end of file diff --git a/solar/minicell.lua b/solar/minicell.lua index 49d96d7..ea39acb 100644 --- a/solar/minicell.lua +++ b/solar/minicell.lua @@ -15,7 +15,6 @@ -- for lazy programmers local P = minetest.string_to_pos local M = minetest.get_meta - local S = techage.S local CYCLE_TIME = 2 @@ -85,7 +84,8 @@ minetest.register_node("techage:ta4_solar_minicell", { local number = techage.add_node(pos, "techage:ta4_solar_minicell") meta:set_string("node_number", number) meta:set_string("infotext", S("TA4 Streetlamp Solar Cell").." "..number) - local mem = tubelib2.init_mem(pos) + -- secondary 'after_place_node', called by power. Don't use tubelib2.init_mem(pos)!!! + local mem = tubelib2.get_mem(pos) mem.capa = 0 mem.providing = false minetest.get_node_timer(pos):start(CYCLE_TIME) diff --git a/steam_engine/boiler.lua b/steam_engine/boiler.lua index 6eb486d..cfa683c 100644 --- a/steam_engine/boiler.lua +++ b/steam_engine/boiler.lua @@ -253,7 +253,8 @@ minetest.register_node("techage:boiler2", { end, after_place_node = function(pos, placer) - local mem = tubelib2.init_mem(pos) + -- secondary 'after_place_node', called by power. Don't use tubelib2.init_mem(pos)!!! + local mem = tubelib2.get_mem(pos) State:node_init(pos, mem, "") local node = minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z}) if node.name == "techage:boiler1" then diff --git a/steam_engine/cylinder.lua b/steam_engine/cylinder.lua index 610c7c8..287dc32 100644 --- a/steam_engine/cylinder.lua +++ b/steam_engine/cylinder.lua @@ -30,6 +30,7 @@ end -- called with any pipe change local function after_tube_update(node, pos, out_dir, peer_pos, peer_in_dir) + -- secondary 'after_place_node', called by power. Don't use tubelib2.init_mem(pos)!!! local mem = tubelib2.get_mem(pos) mem.running = false swap_node(pos, "techage:cylinder") diff --git a/steam_engine/flywheel.lua b/steam_engine/flywheel.lua index 3d831e2..06d27d7 100644 --- a/steam_engine/flywheel.lua +++ b/steam_engine/flywheel.lua @@ -131,7 +131,8 @@ minetest.register_node("techage:flywheel", { on_construct = tubelib2.init_mem, after_place_node = function(pos, placer) - local mem = tubelib2.init_mem(pos) + -- secondary 'after_place_node', called by power. Don't use tubelib2.init_mem(pos)!!! + local mem = tubelib2.get_mem(pos) State:node_init(pos, mem, "") on_rightclick(pos) end, diff --git a/steam_engine/gearbox.lua b/steam_engine/gearbox.lua index 281101b..acf694a 100644 --- a/steam_engine/gearbox.lua +++ b/steam_engine/gearbox.lua @@ -56,7 +56,8 @@ local function on_rightclick(pos, node, clicker) end local function after_place_node(pos, placer, itemstack, pointed_thing) - local mem = tubelib2.init_mem(pos) + -- secondary 'after_place_node', called by power. Don't use tubelib2.init_mem(pos)!!! + local mem = tubelib2.get_mem(pos) minetest.get_node_timer(pos):start(CYCLE_TIME) power.consumer_start(pos, mem, CYCLE_TIME, PWR_NEEDED) end diff --git a/textures/techage_smart_button_on.png b/textures/techage_smart_button_on.png index 88838d6..5f2ab3d 100644 Binary files a/textures/techage_smart_button_on.png and b/textures/techage_smart_button_on.png differ diff --git a/tools/repairkit.lua b/tools/repairkit.lua index 4db07c5..f2719d8 100644 --- a/tools/repairkit.lua +++ b/tools/repairkit.lua @@ -36,7 +36,7 @@ local function read_state(itemstack, user, pointed_thing) local name = minetest.get_biome_name(data.biome) minetest.chat_send_player(user:get_player_name(), S("Biome")..": "..name..", "..S("Position temperature")..": "..math.floor(data.heat).." ") if techage.OceanIdTbl[data.biome] then - minetest.chat_send_player(user:get_player_name(), "Suitable for windmills") + minetest.chat_send_player(user:get_player_name(), "Suitable for wind turbines") end end local number = techage.get_node_number(pos) @@ -76,6 +76,11 @@ local function read_state(itemstack, user, pointed_thing) if power and power ~= "" and power ~= "unsupported" then minetest.chat_send_player(user:get_player_name(), ndef.description.." "..number..": power = "..power.." % ") end + local owner = M(pos):get_string("owner") or "" + if owner ~= "" then + minetest.chat_send_player(user:get_player_name(), S("Node owner")..": "..owner.." ") + end + minetest.chat_send_player(user:get_player_name(), S("Position")..": "..minetest.pos_to_string(pos).." ") itemstack:add_wear(65636/200) return itemstack end @@ -87,6 +92,11 @@ local function read_state(itemstack, user, pointed_thing) minetest.chat_send_player(user:get_player_name(), ndef.description..":"..text) end end + local owner = M(pos):get_string("owner") or "" + if owner ~= "" then + minetest.chat_send_player(user:get_player_name(), S("Node owner")..": "..owner.." ") + end + minetest.chat_send_player(user:get_player_name(), S("Position")..": "..minetest.pos_to_string(pos).." ") itemstack:add_wear(65636/200) return itemstack end