]> git.lizzy.rs Git - xdecor.git/commitdiff
Add pressure plates
authorJean-Patrick Guerrero <jeanpatrick.guerrero@gmail.com>
Sat, 27 Feb 2016 19:54:38 +0000 (20:54 +0100)
committerJean-Patrick Guerrero <jeanpatrick.guerrero@gmail.com>
Sat, 27 Feb 2016 20:08:55 +0000 (21:08 +0100)
init.lua
nodes.lua
pressureplates.lua [new file with mode: 0644]
recipes.lua
textures/xdecor_pressure_stone.png [new file with mode: 0644]
textures/xdecor_pressure_wooden.png [new file with mode: 0644]

index f5f29c94ff7ff76a29b3af79a6e17db3552749b5..3b19a6b92640d2e526828ff5d8b5715f104c8992 100644 (file)
--- 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")
index cb8d84493b095bcc65ee1e1c547d42c8526c922d..2f3ca8a10a9f59c778f89418adddb525ba67eca0 100644 (file)
--- 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 (file)
index 0000000..1c3c943
--- /dev/null
@@ -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
index 37e46e8562282d2b046ea9be6d7d249ed47b60f0..5f50a4ff64da9232c5387db8198054c3001a77a2 100644 (file)
@@ -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 (file)
index 0000000..899e8f2
Binary files /dev/null and b/textures/xdecor_pressure_stone.png differ
diff --git a/textures/xdecor_pressure_wooden.png b/textures/xdecor_pressure_wooden.png
new file mode 100644 (file)
index 0000000..1313479
Binary files /dev/null and b/textures/xdecor_pressure_wooden.png differ