From 346a8c171ef3ef5f06bba0a4d8023e6132d72fb8 Mon Sep 17 00:00:00 2001 From: Joachim Stolberg Date: Sun, 25 Aug 2019 22:02:33 +0200 Subject: [PATCH] power switch added --- power/powerswitch.lua | 101 ++++++++++++++++++-- textures/techage_smart_button_inventory.png | Bin 0 -> 421 bytes textures/techage_smart_button_off.png | Bin 0 -> 500 bytes textures/techage_smart_button_on.png | Bin 0 -> 355 bytes 4 files changed, 91 insertions(+), 10 deletions(-) create mode 100644 textures/techage_smart_button_inventory.png create mode 100644 textures/techage_smart_button_off.png create mode 100644 textures/techage_smart_button_on.png diff --git a/power/powerswitch.lua b/power/powerswitch.lua index f939888..6683960 100644 --- a/power/powerswitch.lua +++ b/power/powerswitch.lua @@ -8,7 +8,7 @@ GPL v3 See LICENSE.txt for more information - TA3 Power Station Generator + TA3 Power Switch (large and small) ]]-- @@ -31,11 +31,11 @@ local Param2ToDir = { [5] = 3, } -local function switch_on(pos, node, clicker) +local function switch_on(pos, node, clicker, name) if clicker and minetest.is_protected(pos, clicker:get_player_name()) then return end - node.name = "techage:powerswitch_on" + node.name = name minetest.swap_node(pos, node) minetest.sound_play("techage_button", { pos = pos, @@ -46,11 +46,11 @@ local function switch_on(pos, node, clicker) power_cut(pos, dir, Cable, false) end -local function switch_off(pos, node, clicker) +local function switch_off(pos, node, clicker, name) if clicker and minetest.is_protected(pos, clicker:get_player_name()) then return end - node.name = "techage:powerswitch" + node.name = name minetest.swap_node(pos, node) minetest.get_node_timer(pos):stop() minetest.sound_play("techage_button", { @@ -88,7 +88,7 @@ minetest.register_node("techage:powerswitch", { end, on_rightclick = function(pos, node, clicker) - switch_on(pos, node, clicker) + switch_on(pos, node, clicker, "techage:powerswitch_on") end, on_rotate = screwdriver.disallow, @@ -118,7 +118,7 @@ minetest.register_node("techage:powerswitch_on", { }, on_rightclick = function(pos, node, clicker) - switch_off(pos, node, clicker) + switch_off(pos, node, clicker, "techage:powerswitch") end, drop = "techage:powerswitch", @@ -131,6 +131,75 @@ minetest.register_node("techage:powerswitch_on", { sounds = default.node_sound_wood_defaults(), }) +minetest.register_node("techage:powerswitchsmall", { + description = S("TA Power Switch Small"), + inventory_image = "techage_smart_button_inventory.png", + tiles = { + 'techage_smart_button_off.png', + }, + + drawtype = "nodebox", + node_box = { + type = "fixed", + fixed = { + { -5/32, -16/32, -5/32, 5/32, -15/32, 5/32}, + { -2/16, -12/16, -2/16, 2/16, -8/16, 2/16}, + }, + }, + + after_place_node = function(pos, placer) + local meta = M(pos) + local number = techage.add_node(pos, "techage:powerswitchsmall") + meta:set_string("node_number", number) + meta:set_string("owner", placer:get_player_name()) + meta:set_string("infotext", S("TA Power Switch Small").." "..number) + end, + + on_rightclick = function(pos, node, clicker) + switch_on(pos, node, clicker, "techage:powerswitchsmall_on") + 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:powerswitchsmall_on", { + description = S("TA Power Switch Small"), + inventory_image = "techage_appl_switch_inv.png", + tiles = { + 'techage_smart_button_on.png', + }, + + drawtype = "nodebox", + node_box = { + type = "fixed", + fixed = { + { -5/32, -16/32, -5/32, 5/32, -15/32, 5/32}, + { -2/16, -12/16, -2/16, 2/16, -8/16, 2/16}, + }, + }, + + on_rightclick = function(pos, node, clicker) + switch_off(pos, node, clicker, "techage:powerswitchsmall") + end, + + drop = "techage:powerswitchsmall", + 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(), +}) + + local function get_conn_dirs(pos, node) local tbl = {[0]= {2,4}, {1,3}, {2,4}, {1,3}, @@ -197,13 +266,19 @@ techage.register_node({"techage:powerswitch", "techage:powerswitch_on"}, { on_recv_message = function(pos, src, topic, payload) local node = minetest.get_node(pos) if topic == "on" and node.name == "techage:powerswitch" then - switch_on(pos, node) + switch_on(pos, node, "techage:powerswitch_on") + return true + elseif topic == "on" and node.name == "techage:powerswitchsmall" then + switch_on(pos, node, "techage:powerswitchsmall_on") return true elseif topic == "off" and node.name == "techage:powerswitch_on" then - switch_off(pos, node) + switch_off(pos, node, "techage:powerswitch") + return true + elseif topic == "off" and node.name == "techage:powerswitchsmall_on" then + switch_off(pos, node, "techage:powerswitchsmall") return true elseif topic == "state" then - if node.name == "techage:powerswitch_on" then + if node.name == "techage:powerswitch_on" or node.name == "techage:powerswitchsmall_on"then return "on" end return "off" @@ -230,6 +305,12 @@ minetest.register_craft({ }, }) +minetest.register_craft({ + type = "shapeless", + output = "techage:powerswitchsmall", + recipe = {"techage:powerswitch"}, +}) + minetest.register_craft({ output = "techage:powerswitch_box", recipe = { diff --git a/textures/techage_smart_button_inventory.png b/textures/techage_smart_button_inventory.png new file mode 100644 index 0000000000000000000000000000000000000000..b049987ba37d226706a3d099ff394d3d192daf4c GIT binary patch literal 421 zcmeAS@N?(olHy`uVBq!ia0vp^1|ZDA1|-9oezpTCwj^(N7a$D;Kb?2i11Zh|kH}&M z25w;xW@MN(M*=9wUgGKN%Kn%`Qdo{#W?HryP)Ig2B%;JQKQ}iuuLQ_tU~n!H z#9p6hFf(;#9=qd#2~JCbGiI3iUY=kO87jI;0OXSJQ!my(nj>v2$oVj~rNEf!qSNEm z${zw}Et|o-n{mdiTR*1oKCk>&>Ypa_pmP7YI{W)_o6|P(<)|*b@+fdS*94W$zgj6t zPs}_Q*7s^HeZ$P-&ycf(Wz~f!S$`%$h6C%K9nkK(+k4>Feof(|$I?=oOW$SOp5`)Z zO6tnni4u=Wq(Dx1+PY?4_UhliH6OOMZIZa>#gOovA>U9po{76_=Sq+QPgg&ebxsLQ E02c0?0RR91 literal 0 HcmV?d00001 diff --git a/textures/techage_smart_button_off.png b/textures/techage_smart_button_off.png new file mode 100644 index 0000000000000000000000000000000000000000..b0a0a93a31709e54d277ab93ac1d2f97e6ce2d2f GIT binary patch literal 500 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0I1|(Ny7TyC=Y)RhkE)4%caKYZ?lYt_f1s;*b z3=G`DAk4@xYmNj^kiEpy*OmP-horDMa~OBcf1r?TW=KSdbAE1aYF-JD%fR4Vl$uzQ znxasiS(2gP?&%wlqL<3fz`z*c>EaktaqI0Y!@On(0oV2uG7W58dWUR_8bekt4%k)J z`Q+Brr7}(07YevoggiJnIk`0Es6`ZR3VNf{m;CK-mSe_|eRF5tmE5pul~u>VDuKhS z3=9(MroLMCde^kRi`lAScfWg0deQ*23Ii;7#~u@P{`Iw&+ozPSeb${NZ}GIb zI;Yb%I&;JbF%@S-ZA_E^a)ek8%x!J(+V_6`*O+ic@4cR)h^fqVix+9!U^~h9eFpO~RN5LfK+NS%G}U;vjb? zhIQv;UIIC?nIRD+&iT2ysd*(pE(3#eQEFmIYKlU6W=V#EyQgnJie4%^P@J>CBeIx* zfm;}a85w5HkpK!x2l#}z`eYWqdi84i_U$K5oVa-L;{X5uO9~5rEVaCI=gu$Nn?^uo zj3q&S!3+-1ZlnP@vproLLp+Wr3#c$iu(dNWvT-E12(>b$B|i>iZH{SVSSymiD8O1! zTQH3~fQii`Sb>rC*bWgBGcS&&35I#X2R>E!2=KBt9dJudj#2C2V&e6fa$vColZQIj zBjbg8VhoPDo|ITF&7r|C`$1E*V|({%Zbw!JhnY<#3I~=maAhn%5W&fIBD6vK;vv-s pY#O~<5*xW%rhH&{dT=2FgICY4fHUt^G=a`!@O1TaS?83{1OWaeapwR4 literal 0 HcmV?d00001