From 1ffd1e4bb661a87386b2603e66c2a42fca793f8e Mon Sep 17 00:00:00 2001 From: Joachim Stolberg Date: Tue, 21 May 2019 22:04:05 +0200 Subject: [PATCH] Lamps and a switch added --- basis/lib.lua | 1 - init.lua | 9 +- lamps/lib.lua | 68 ++++++++++++++ lamps/simplelamp.lua | 54 +++++++++++ lamps/streetlamp.lua | 83 +++++++++++++++++ power/power.lua | 23 +++++ power/powerswitch.lua | 130 +++++++++++++++++++++++++++ test/lamp.lua | 100 --------------------- textures/techage_appl_switch_inv.png | Bin 0 -> 459 bytes textures/techage_appl_switch_off.png | Bin 0 -> 687 bytes textures/techage_appl_switch_on.png | Bin 0 -> 713 bytes textures/techage_streetlamp.png | Bin 0 -> 286 bytes textures/techage_streetlamp_off.png | Bin 0 -> 606 bytes textures/techage_streetlamp_top.png | Bin 0 -> 216 bytes 14 files changed, 366 insertions(+), 102 deletions(-) create mode 100644 lamps/lib.lua create mode 100644 lamps/simplelamp.lua create mode 100644 lamps/streetlamp.lua create mode 100644 power/powerswitch.lua delete mode 100644 test/lamp.lua create mode 100644 textures/techage_appl_switch_inv.png create mode 100644 textures/techage_appl_switch_off.png create mode 100644 textures/techage_appl_switch_on.png create mode 100644 textures/techage_streetlamp.png create mode 100644 textures/techage_streetlamp_off.png create mode 100644 textures/techage_streetlamp_top.png diff --git a/basis/lib.lua b/basis/lib.lua index 07b1d2d..6c29454 100644 --- a/basis/lib.lua +++ b/basis/lib.lua @@ -53,4 +53,3 @@ function techage.is_primary_node(pos, dir) local param2 = M(npos):get_int("tl2_param2") return param2 ~= 0 end - diff --git a/init.lua b/init.lua index 3e8706b..dae9f9a 100644 --- a/init.lua +++ b/init.lua @@ -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") diff --git a/lamps/lib.lua b/lamps/lib.lua new file mode 100644 index 0000000..ab27d6b --- /dev/null +++ b/lamps/lib.lua @@ -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 diff --git a/lamps/simplelamp.lua b/lamps/simplelamp.lua new file mode 100644 index 0000000..a228411 --- /dev/null +++ b/lamps/simplelamp.lua @@ -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", ""}, + }, +}) diff --git a/lamps/streetlamp.lua b/lamps/streetlamp.lua new file mode 100644 index 0000000..f533a0e --- /dev/null +++ b/lamps/streetlamp.lua @@ -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"}, +}) diff --git a/power/power.lua b/power/power.lua index ebe6fea..316d5ce 100644 --- a/power/power.lua +++ b/power/power.lua @@ -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] diff --git a/power/powerswitch.lua b/power/powerswitch.lua new file mode 100644 index 0000000..6007cfe --- /dev/null +++ b/power/powerswitch.lua @@ -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"}, + }, +}) + diff --git a/test/lamp.lua b/test/lamp.lua deleted file mode 100644 index f3f77df..0000000 --- a/test/lamp.lua +++ /dev/null @@ -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, -}) - diff --git a/textures/techage_appl_switch_inv.png b/textures/techage_appl_switch_inv.png new file mode 100644 index 0000000000000000000000000000000000000000..934d139a6e5bc96f62ad999c81c9d17ab4d51b47 GIT binary patch literal 459 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=fdzwj^(N7l!{JxM1({$v_d#0*}aI z1_o|n5N2eUHAey{$X?><>&pI^Ra8(xtbh9Er$8au%#er@=ltB<)VvZPmw~~#C^fMp zHASI3vm`^o-P1Q9MK6_|fq_xq)5S3);_%yPj#-BsMB4WEII;*XS-q?Dw%+bn>mG0x zwaYE6=+LWT_{jC{PN%k}Zplh+!AF|}xW~Z;$=deVh_y6~s>+k7V z{A9J$x06b3i!Jpw@jtxbaUk;>L%_atw+(y(%f9$+ZvSLE<^5X+AEyb0DSQuRsU7RT z_d|LE;|9}hOcnJK#y@#7W3Mns=%|E$DJ?!?d8V}Jvu#JtD*Gi9Wo{qU&|~<-n_zUiKU1YX;b(s1S|2#1iQNW3I3y> x`~*I^iqrer%s9JO%S1q7>gnp|vd$@?2>{I{w?Y5_ literal 0 HcmV?d00001 diff --git a/textures/techage_appl_switch_off.png b/textures/techage_appl_switch_off.png new file mode 100644 index 0000000000000000000000000000000000000000..513b1e992447fdcd47eec98c59c07df7f0d95c3c GIT binary patch literal 687 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0I1|(Ny7TyC=Y)RhkE)4%caKYZ?lYt_f1s;*b z3=G`DAk4@xYmNj^kiEpy*OmP-tEiy7iu}A2kw78Y%#er@=ltB<)VvZPmw~~#C^fMp zHASI3vm`^o-P1Q9MK6_|fq_Zb)5S5Q;?~>QzTQlMB5n6)vT?dE>~HnFa47d3PgB{# z3-?_AFPJazmqT1P+GX{(&Bcll+MP|)wsjl`6H-<@xWtdmZ}t>VojLsP=YFx(-rM*6 z&gV0h<>z*`2li}^Ri7T)8h?TJ8yYl$qPmn2L=TCFqiA~N@fMY&vTQkuFYj$t&{rk z`quO({QArNZwvq2__@VyOJ5{sSa5Xefpx!st)67qX1UA$?%!$KU*BI}SMzp8Y^CCY z6dsFSr8#beEKSu6j4n@X99nk7-v2K5VLsytvly+0>5r}C?&XMFo5awNb^Fk_Q%0AT zzNulBkm5^7`SYQ8Ywp8`FXAjXLYI8ZYd(I|_SwENJ%%5K9wIEJUB|jx4!CHnD*wOT z@{r%`mr$2)o@5Yo>!al%y#+5AH-`xv;dT*mb+S3oueeCdDN*skQH6<5H(dDKP@>sw z!Z63i@6XEI*A9htd4GWU}?JU%omc>D47tWsn&XPTkL_NlAr#(J(1Sk-*znjwJ3RT` zx?jfo<-84BJvnwsGO=uUQSET~4eKli|F0JfcL#~dhm>D_^N`zzeOa?wB4Z*b-FUkC KxvXEaktaqI2u{r-m>M2_!Y%WEjol%b^P#x9duY*2Xh z$lQZ>585~GKXmZoNsArj$qJ5YNlA}ZOy=}+$>y0D5_P0ySA*b+wtE+MU)yKySbt~t z_lNK9e!t6l)Z%vG_U_0Hv*uYlTwmkV_VHKVOuj8|lfEEKs`%Jr=BPpT7C@w=4IK)H%sVU0?I*>Xk6o7k3T!t`g~)=$8KZZvDsae|}%R zaeZCp>Df$P2ODnd9L$}z&oO{cfkE*mzd)jWyInC~hY`cgMsL;+A>ZOmKdB%6&--Be z0rmIYEDPIIE3Tz0Gd8Fy1PWX+VAB_JdSLnB-`e9}>+HA~*7aL4G~B)Vd}a0T)0xl8 zvU9oppYGnc#A4EgjR8$Sp?88Jm6~Uan~pFCu!r!Ry`7b-y^kR)mpj_K`(Zq5nZD6s z|Cuip`tpBHJIEPn^PWkoKvv+3zQixh1Hm^sG`d=zFidlB32iwvX~FykmuZKczB9Wu z9xZcrNn0>c)Cm+K3`_zqv<_6;#O2%kvRb+|F7`&gR@ILK2_HIJU1h73cy9-8+;@|) zCgjTU=luT`@jj}!bN%O@9PY~>EuJzkA%!f%&8-dBUDwx#|6RFWU1gcU?B@JgOe_lT tEEl9&#qhq^X}4>c?$XbD_C+si)~^*_8yE8+`xyfec)I$ztaD0e0sxLzEY|=4 literal 0 HcmV?d00001 diff --git a/textures/techage_streetlamp.png b/textures/techage_streetlamp.png new file mode 100644 index 0000000000000000000000000000000000000000..974da017f67f1f73aa0b30a7ed43c6e75df17bca GIT binary patch literal 286 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=fdzwj^(N7lxl8cu2T=3s8i!z$3Dl zfq`2Xgc%uT&5-~KvX^-Jy0SlFmKP9_6JSj#0}8G7ba4!cIQ;hFMy^8!0&EZV2c4Lv zn&5EU#?7nsQFlvFjpxhe5F;&@6O(jr*F=6I)~ISXnA0@4iZ@nrzqm()ZF@zb#Bm0u2l-3Ji=K4h&3xbQaWw&+!wU75n+V beF1ZYP1@s*ss<0Bvl%>H{an^LB{Ts5w|Hp} literal 0 HcmV?d00001 diff --git a/textures/techage_streetlamp_off.png b/textures/techage_streetlamp_off.png new file mode 100644 index 0000000000000000000000000000000000000000..4385f298406fdb239fd73556cf28549fa3945530 GIT binary patch literal 606 zcmV-k0-^nhP)=;AC`)QU4OFfj1(@iE-JdzUJf zD=RC*%*Aj36T<)lY$5QHfq{YH)2B~Vvjl3^OKftCsp+ZzU%qLny82vLSeQXv zOnl&@VAKIPfwi6We_bt&|LEe&S1l(>32rOT<{C{LvBqJd)nnVFE zi;%_eg#^V8AmmGOLxP1EMT=VlP<+Os8qV;Jq5Vh$goI8Y&nUn5P-#Tdbk0^0)8Ea zKOe6!ptEPLyue6GdSJv?4t#p^mf`ZX8;t02i{T5TG=a>Ht=_<>tEKUuPehpE=%J&G zR7nHqA>a^P&TwSUR)#+xA3#E&nzWoiRxW^mFAOZI0XJBApP(Voo#O4B$ zi(+hrPIg+%e_U#)UKGRFNA_&RD^F}fWTB)eM)oE?JbkMCqg3EGZYeteCK#akpLntBNdN!< literal 0 HcmV?d00001 diff --git a/textures/techage_streetlamp_top.png b/textures/techage_streetlamp_top.png new file mode 100644 index 0000000000000000000000000000000000000000..f4ea4abc9c4680efe6a6f844184c021a09c4d3c8 GIT binary patch literal 216 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnL3?x0byx0z;SkfJR9T^xl_H+M9WCijWi-X*q z7}lMWc?slj7I;J!Gca%qgD@k*tT_@uLAC&&5LZ=oRckxzbH6LAfFjYJE{-7_*IWBG z3La44VLlodV8pc8KuS_~u>q4R>+$2?mP55w literal 0 HcmV?d00001