]> git.lizzy.rs Git - xdecor.git/blobdiff - mechanisms.lua
Mailbox: minor code cleaning
[xdecor.git] / mechanisms.lua
index b1b6e9b245f6b1c82478ccd66ff16f072051734e..36e0ef8bc91bd69c037eb283a2268720dafa1f87 100644 (file)
@@ -1,4 +1,8 @@
--- Thanks to sofar for helping with that code.
+--[[ Thanks to sofar for helping with that code.
+Pressure plates work better with this setting in minetest.conf (requires 0.4.14):
+       nodetimer_interval = 0.1
+]]
+
 local plate = {}
 screwdriver = screwdriver or {}
 
@@ -23,7 +27,7 @@ end
 
 function plate.construct(pos)
        local timer = minetest.get_node_timer(pos)
-       timer:start(0.5)
+       timer:start(0.1)
 end
 
 function plate.timer(pos)
@@ -44,36 +48,41 @@ function plate.timer(pos)
        return true
 end
 
-for _, m in pairs({"wooden", "stone"}) do
-       local sound = default.node_sound_wood_defaults()
-       if m == "stone" then
-               sound = default.node_sound_stone_defaults()
-       end
-       xdecor.register("pressure_"..m.."_off", {
-               description = m:gsub("^%l", string.upper).." Pressure Plate",
-               tiles = {"xdecor_pressure_"..m..".png"},
+function plate.register(material, desc, def)
+       xdecor.register("pressure_"..material.."_off", {
+               description = desc.." Pressure Plate",
+               tiles = {"xdecor_pressure_"..material..".png"},
                drawtype = "nodebox",
                node_box = xdecor.pixelbox(16, {{1, 0, 1, 14, 1, 14}}),
-               groups = {snappy=3},
-               sounds = sound,
+               groups = def.groups,
+               sounds = def.sounds,
                sunlight_propagates = true,
                on_rotate = screwdriver.rotate_simple,
                on_construct = plate.construct,
                on_timer = plate.timer
        })
-
-       xdecor.register("pressure_"..m.."_on", {
-               tiles = {"xdecor_pressure_"..m..".png"},
+       xdecor.register("pressure_"..material.."_on", {
+               tiles = {"xdecor_pressure_"..material..".png"},
                drawtype = "nodebox",
                node_box = xdecor.pixelbox(16, {{1, 0, 1, 14, 0.4, 14}}),
-               groups = {snappy=3, not_in_creative_inventory=1},
-               sounds = sound,
-               drop = "xdecor:pressure_"..m.."_off",
+               groups = def.groups,
+               sounds = def.sounds,
+               drop = "xdecor:pressure_"..material.."_off",
                sunlight_propagates = true,
                on_rotate = screwdriver.rotate_simple
        })
 end
 
+plate.register("wood", "Wooden", {
+       sounds = default.node_sound_wood_defaults(),
+       groups = {choppy=3, oddly_breakable_by_hand=2, flammable=2}
+})
+
+plate.register("stone", "Stone", {
+       sounds = default.node_sound_stone_defaults(),
+       groups = {cracky=3, oddly_breakable_by_hand=2}
+})
+
 xdecor.register("lever_off", {
        description = "Lever",
        tiles = {"xdecor_lever_off.png"},