Lamps and a switch added

master
Joachim Stolberg 2019-05-21 22:04:05 +02:00
parent f777123b58
commit 1ffd1e4bb6
14 changed files with 366 additions and 102 deletions

View File

@ -53,4 +53,3 @@ function techage.is_primary_node(pos, dir)
local param2 = M(npos):get_int("tl2_param2")
return param2 ~= 0
end

View File

@ -51,6 +51,7 @@ else
dofile(MP.."/power/biogas_pipe.lua")
dofile(MP.."/power/electric_cable.lua")
dofile(MP.."/power/junctionbox.lua")
dofile(MP.."/power/powerswitch.lua")
-- Iron Age
dofile(MP.."/iron_age/main.lua")
@ -105,8 +106,14 @@ else
dofile(MP.."/coal_power_station/cooler.lua")
dofile(MP.."/coal_power_station/akkubox.lua")
-- Lamps
dofile(MP.."/lamps/lib.lua")
dofile(MP.."/lamps/simplelamp.lua")
dofile(MP.."/lamps/streetlamp.lua")
--dofile(MP.."/test/generator.lua")
dofile(MP.."/test/lamp.lua")
--dofile(MP.."/test/lamp.lua")
-- dofile(MP.."/test/consumer.lua")
--dofile(MP.."/test/consumer2.lua")
--dofile(MP.."/test/test.lua")

68
lamps/lib.lua Normal file
View File

@ -0,0 +1,68 @@
-- for lazy programmers
local S = function(pos) if pos then return minetest.pos_to_string(pos) end end
local P = minetest.string_to_pos
local M = minetest.get_meta
local POWER_CONSUMPTION = 1
local Power = techage.ElectricCable
local function swap_node(pos, postfix)
local node = Power:get_node_lvm(pos)
local parts = string.split(node.name, "_")
if postfix == parts[2] then
return
end
node.name = parts[1].."_"..postfix
minetest.swap_node(pos, node)
end
local function on_power_pass1(pos, mem)
if mem.running then
mem.correction = POWER_CONSUMPTION
else
mem.correction = 0
end
return mem.correction
end
local function on_power_pass2(pos, mem, sum)
local node = minetest
if sum > 0 and mem.running then
swap_node(pos, "on")
return 0
else
swap_node(pos, "off")
return -mem.correction
end
end
local function lamp_on_rightclick(pos, node, clicker)
if minetest.is_protected(pos, clicker:get_player_name()) then
return
end
local mem = tubelib2.get_mem(pos)
if not mem.running then
mem.running = true
else
mem.running = false
end
techage.power.power_distribution(pos)
end
function techage.register_lamp(basename, ndef_off, ndef_on)
ndef_off.on_construct = tubelib2.init_mem
ndef_off.on_rightclick = lamp_on_rightclick
ndef_on.on_construct = tubelib2.init_mem
ndef_on.on_rightclick = lamp_on_rightclick
minetest.register_node(basename.."_off", ndef_off)
minetest.register_node(basename.."_on", ndef_on)
techage.power.register_node({basename.."_off", basename.."_on"}, {
on_power_pass1 = on_power_pass1,
on_power_pass2 = on_power_pass2,
power_network = Power,
})
end

54
lamps/simplelamp.lua Normal file
View File

@ -0,0 +1,54 @@
--[[
TechAge
=======
Copyright (C) 2019 Joachim Stolberg
LGPLv2.1+
See LICENSE.txt for more information
TA3/TA4 Lamp
]]--
-- Load support for intllib.
local MP = minetest.get_modpath("techage")
local I,_ = dofile(MP.."/intllib.lua")
techage.register_lamp("techage:simplelamp", {
description = I("TA Lamp"),
tiles = {
'techage_electric_button.png',
},
paramtype = "light",
light_source = 0,
sunlight_propagates = true,
paramtype2 = "facedir",
groups = {choppy=2, cracky=2, crumbly=2},
is_ground_content = false,
sounds = default.node_sound_wood_defaults(),
},{
description = I("TA Lamp"),
tiles = {
'techage_electric_button.png',
},
paramtype = "light",
light_source = minetest.LIGHT_MAX,
sunlight_propagates = true,
paramtype2 = "facedir",
drop = "techage:test_lamp",
groups = {choppy=2, cracky=2, crumbly=2, not_in_creative_inventory=1},
is_ground_content = false,
sounds = default.node_sound_wood_defaults(),
})
minetest.register_craft({
output = "techage:simplelamp_off 2",
recipe = {
{"", "", ""},
{"", "default:glass", ""},
{"", "basic_materials:heating_element", ""},
},
})

83
lamps/streetlamp.lua Normal file
View File

@ -0,0 +1,83 @@
--[[
TechAge
=======
Copyright (C) 2019 Joachim Stolberg
LGPLv2.1+
See LICENSE.txt for more information
TA3/TA4 Street Lamp
]]--
-- Load support for intllib.
local MP = minetest.get_modpath("techage")
local I,_ = dofile(MP.."/intllib.lua")
techage.register_lamp("techage:streetlamp", {
description = "TA Street Lamp",
tiles = {
-- up, down, right, left, back, front
'techage_streetlamp_top.png',
'techage_streetlamp_top.png',
'techage_streetlamp_off.png',
},
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = {
{-5/16, -8/16, -5/16, 5/16, 8/16, 5/16},
{-2/16, -8/16, -2/16, 2/16, 8/16, 2/16},
{-8/16, 4/16, -8/16, 8/16, 5/16, 8/16},
{-5/16, -8/16, -5/16, 5/16, -7/16, 5/16},
},
},
selection_box = {
type = "fixed",
fixed = {-8/16, -8/16, -8/16, 8/16, 8/16, 8/16},
},
paramtype = "light",
light_source = 0,
sunlight_propagates = true,
paramtype2 = "facedir",
groups = {choppy=2, cracky=2, crumbly=2},
is_ground_content = false,
sounds = default.node_sound_glass_defaults(),
},{
description = "TA Street Lamp",
tiles = {
-- up, down, right, left, back, front
'techage_streetlamp_top.png',
'techage_streetlamp_top.png',
'techage_streetlamp.png',
},
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = {
{-5/16, -8/16, -5/16, 5/16, 8/16, 5/16},
{-8/16, 4/16, -8/16, 8/16, 5/16, 8/16},
},
},
selection_box = {
type = "fixed",
fixed = {-8/16, -8/16, -8/16, 8/16, 8/16, 8/16},
},
paramtype = "light",
light_source = minetest.LIGHT_MAX,
sunlight_propagates = true,
paramtype2 = "facedir",
groups = {crumbly=0, not_in_creative_inventory=1},
is_ground_content = false,
sounds = default.node_sound_wood_defaults(),
})
minetest.register_craft({
type = "shapeless",
output = "techage:streetlamp_off 2",
recipe = {"techage:simplelamp_off", "default:steel_ingot", "default:glass"},
})

View File

@ -151,6 +151,29 @@ techage.power = {}
techage.power.power_distribution = power_distribution
-- User to turn on/off the power by means of a power switch
function techage.power.power_cut(pos, dir, cable, cut)
local npos = vector.add(pos, tubelib2.Dir6dToVector[dir or 0])
local meta = M(npos)
if cut then
local param2 = meta:get_int("tl2_param2")
if param2 ~= 0 then
meta:set_int("cable_cut", param2)
meta:set_int("tl2_param2", 0)
cable:after_dig_node(npos)
end
else
local param2 = meta:get_int("cable_cut")
if param2 ~= 0 then
meta:set_int("tl2_param2", param2)
meta:set_int("cable_cut", 0)
cable:tool_repair_tube(npos)
end
end
end
function techage.power.register_node(names, pwr_def)
for _,name in ipairs(names) do
local ndef = minetest.registered_nodes[name]

130
power/powerswitch.lua Normal file
View File

@ -0,0 +1,130 @@
--[[
TechAge
=======
Copyright (C) 2019 Joachim Stolberg
LGPLv2.1+
See LICENSE.txt for more information
TA3 Power Station Generator
]]--
-- for lazy programmers
local S = function(pos) if pos then return minetest.pos_to_string(pos) end end
local P = minetest.string_to_pos
local M = minetest.get_meta
-- Load support for intllib.
local MP = minetest.get_modpath("techage")
local I,_ = dofile(MP.."/intllib.lua")
local Param2ToDir = {
[0] = 6,
[1] = 5,
[2] = 2,
[3] = 4,
[4] = 1,
[5] = 3,
}
local function switch_on(pos, node, clicker)
if minetest.is_protected(pos, clicker:get_player_name()) then
return
end
node.name = "techage:powerswitch_on"
minetest.swap_node(pos, node)
minetest.sound_play("techage_button", {
pos = pos,
gain = 0.5,
max_hear_distance = 5,
})
local dir = Param2ToDir[node.param2]
techage.power.power_cut(pos, dir, techage.ElectricCable, false)
end
local function switch_off(pos, node, clicker)
if minetest.is_protected(pos, clicker:get_player_name()) then
return
end
node.name = "techage:powerswitch"
minetest.swap_node(pos, node)
minetest.get_node_timer(pos):stop()
minetest.sound_play("techage_button", {
pos = pos,
gain = 0.5,
max_hear_distance = 5,
})
local dir = Param2ToDir[node.param2]
techage.power.power_cut(pos, dir, techage.ElectricCable, true)
end
minetest.register_node("techage:powerswitch", {
description = I("TA Power Switch"),
inventory_image = "techage_appl_switch_inv.png",
tiles = {
'techage_appl_switch_off.png',
},
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = {
{ -1/4, -8/16, -1/4, 1/4, -7/16, 1/4},
},
},
on_rightclick = function(pos, node, clicker)
switch_on(pos, node, clicker)
end,
on_rotate = screwdriver.disallow,
paramtype = "light",
sunlight_propagates = true,
paramtype2 = "wallmounted",
groups = {choppy=2, cracky=2, crumbly=2},
is_ground_content = false,
sounds = default.node_sound_wood_defaults(),
})
minetest.register_node("techage:powerswitch_on", {
description = I("TA Power Switch"),
inventory_image = "techage_appl_switch_inv.png",
tiles = {
'techage_appl_switch_on.png',
},
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = {
{ -1/4, -8/16, -1/4, 1/4, -7/16, 1/4},
},
},
on_rightclick = function(pos, node, clicker)
switch_off(pos, node, clicker)
end,
on_rotate = screwdriver.disallow,
paramtype = "light",
sunlight_propagates = true,
paramtype2 = "wallmounted",
groups = {choppy=2, cracky=2, crumbly=2, not_in_creative_inventory = 1},
is_ground_content = false,
sounds = default.node_sound_wood_defaults(),
})
minetest.register_craft({
output = "techage:powerswitch_on 2",
recipe = {
{"", "", ""},
{"dye:yellow", "dye:red", "dye:yellow"},
{"basic_materials:plastic_sheet", "basic_materials:copper_wire", "basic_materials:plastic_sheet"},
},
})

View File

@ -1,100 +0,0 @@
-- for lazy programmers
local S = function(pos) if pos then return minetest.pos_to_string(pos) end end
local P = minetest.string_to_pos
local M = minetest.get_meta
-- Load support for intllib.
local MP = minetest.get_modpath("techage")
local I,_ = dofile(MP.."/intllib.lua")
local POWER_CONSUMPTION = 1
local Power = techage.ElectricCable
local function swap_node(pos, name, infotext)
local node = minetest.get_node(pos)
if node.name == name then
return
end
node.name = name
minetest.swap_node(pos, node)
M(pos):set_string("infotext", infotext)
end
local function on_power_pass1(pos, mem)
if mem.running then
mem.correction = POWER_CONSUMPTION
else
mem.correction = 0
end
return mem.correction
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 mem = tubelib2.get_mem(pos)
if not mem.running then
mem.running = true
else
mem.running = false
end
techage.power.power_distribution(pos)
end
minetest.register_node("techage:test_lamp", {
description = "TechAge Lamp",
tiles = {
-- up, down, right, left, back, front
'techage_electric_button.png',
'techage_electric_button.png',
'techage_electric_button.png',
'techage_electric_button.png',
'techage_electric_button.png',
'techage_electric_button.png',
},
on_construct = tubelib2.init_mem,
on_rightclick = lamp_on_rightclick,
paramtype = "light",
light_source = 0,
sunlight_propagates = true,
paramtype2 = "facedir",
groups = {choppy=2, cracky=2, crumbly=2},
is_ground_content = false,
sounds = default.node_sound_wood_defaults(),
})
minetest.register_node("techage:test_lamp_on", {
description = "TechAge Lamp",
tiles = {
'techage_electric_button.png',
},
on_rightclick = lamp_on_rightclick,
paramtype = "light",
light_source = minetest.LIGHT_MAX,
sunlight_propagates = true,
paramtype2 = "facedir",
drop = "techage:test_lamp",
groups = {choppy=2, cracky=2, crumbly=2, not_in_creative_inventory=1},
is_ground_content = false,
sounds = default.node_sound_wood_defaults(),
})
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,
})

Binary file not shown.

After

Width:  |  Height:  |  Size: 459 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 687 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 713 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 286 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 606 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 216 B