From 203a82c9bf1b2de0f6604e5cdb295a2d8f5dc241 Mon Sep 17 00:00:00 2001 From: Jean-Patrick Guerrero Date: Sat, 27 Feb 2016 20:54:38 +0100 Subject: [PATCH] Add pressure plates --- init.lua | 1 + nodes.lua | 1 + pressureplates.lua | 61 ++++++++++++++++++++++++++++ recipes.lua | 12 ++++++ textures/xdecor_pressure_stone.png | Bin 0 -> 258 bytes textures/xdecor_pressure_wooden.png | Bin 0 -> 407 bytes 6 files changed, 75 insertions(+) create mode 100644 pressureplates.lua create mode 100644 textures/xdecor_pressure_stone.png create mode 100644 textures/xdecor_pressure_wooden.png diff --git a/init.lua b/init.lua index f5f29c9..3b19a6b 100644 --- a/init.lua +++ b/init.lua @@ -18,6 +18,7 @@ dofile(modpath.."/hive.lua") dofile(modpath.."/itemframe.lua") dofile(modpath.."/mailbox.lua") dofile(modpath.."/nodes.lua") +dofile(modpath.."/pressureplates.lua") dofile(modpath.."/recipes.lua") dofile(modpath.."/rope.lua") dofile(modpath.."/workbench.lua") diff --git a/nodes.lua b/nodes.lua index cb8d844..2f3ca8a 100644 --- a/nodes.lua +++ b/nodes.lua @@ -562,3 +562,4 @@ xdecor.register("wood_tile", { groups = {choppy=1, oddly_breakable_by_hand=1, wood=1, flammable=2}, sounds = default.node_sound_wood_defaults() }) + diff --git a/pressureplates.lua b/pressureplates.lua new file mode 100644 index 0000000..1c3c943 --- /dev/null +++ b/pressureplates.lua @@ -0,0 +1,61 @@ +-- Thanks to sofar for helping with that code. +local plate = {} + +function plate.construct(pos) + local timer = minetest.get_node_timer(pos) + timer:start(0.5) +end + +function plate.door_toggle(pos_plate, pos_door, player) + local plate = minetest.get_node(pos_plate) + local door = doors.get(pos_door) + + minetest.set_node(pos_plate, {name=plate.name:gsub("_off", "_on"), param2=plate.param2}) + door:open(player) + + minetest.after(2, function() + minetest.set_node(pos_plate, {name=plate.name, param2=plate.param2}) + door:close(player) + end) +end + +function plate.timer(pos) + local objs = minetest.get_objects_inside_radius(pos, 0.8) + if objs == {} then return true end + local minp = {x=pos.x-2, y=pos.y, z=pos.z-2} + local maxp = {x=pos.x+2, y=pos.y, z=pos.z+2} + local doors = minetest.find_nodes_in_area(minp, maxp, "group:door") + + for _, player in pairs(objs) do + if player:is_player() then + for i = 1, #doors do + plate.door_toggle(pos, doors[i], player) + end + end + end + return true +end + +for _, m in pairs({"wooden", "stone"}) do + xdecor.register("pressure_"..m.."_off", { + description = m:gsub("^%l", string.upper).." Pressure Plate", + tiles = {"xdecor_pressure_"..m..".png"}, + drawtype = "nodebox", + node_box = xdecor.pixelbox(16, {{1, 0, 1, 14, 1, 14}}), + groups = {snappy=3}, + sounds = default.node_sound_wood_defaults(), + sunlight_propagates = true, + on_construct = plate.construct, + on_timer = plate.timer + }) + + xdecor.register("pressure_"..m.."_on", { + tiles = {"xdecor_pressure_"..m..".png"}, + drawtype = "nodebox", + node_box = xdecor.pixelbox(16, {{1, 0, 1, 14, 0.4, 14}}), + groups = {snappy=3, not_in_creative_inventory=1}, + sounds = default.node_sound_wood_defaults(), + drop = "xdecor:pressure_"..m.."_off", + sunlight_propagates = true + }) +end diff --git a/recipes.lua b/recipes.lua index 37e46e8..5f50a4f 100644 --- a/recipes.lua +++ b/recipes.lua @@ -254,6 +254,18 @@ minetest.register_craft({ } }) +minetest.register_craft({ + output = "xdecor:pressure_stone_off", + type = "shapeless", + recipe = {"default:stone", "default:stone"} +}) + +minetest.register_craft({ + output = "xdecor:pressure_wooden_off", + type = "shapeless", + recipe = {"group:wood", "group:wood"} +}) + minetest.register_craft({ output = "xdecor:rope", recipe = { diff --git a/textures/xdecor_pressure_stone.png b/textures/xdecor_pressure_stone.png new file mode 100644 index 0000000000000000000000000000000000000000..899e8f2070907538840c3095c055fe1f125b445c GIT binary patch literal 258 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!73?$#)eFPFP2=EDU1=8!+Z_dpvEG#TdNl8C- z>g?vt+gGhxzjNo_*|X=ZUcG+8gem9FU0k?uX;V|{wr#tUy~{FzdKgQB{DK)Ap4~_T zavD5c978y+Cnp%11qGHF6(tlj8pKHS^vm(~a`J{I1#q3wTC-{bi=kXu$5+o?20LV4 z|JTq^^d{i{HgI9S{GRT=}xq?x#c}#&`J;IV@gIqejh+4CN zQ?q?ch-O8hY(dtmdeNhE(4la~m1n??T)Tu+kaJF`az@jqbJ0G168^+5+O2TXAFo;#GiwhzKXSdm2T*3-y9aaUR60f<_4KL z)laWVQS8f-v{+po%c#|zK2{iO3nwAi?H1rSfH!