summaryrefslogtreecommitdiff
path: root/mesecons_pressureplates
diff options
context:
space:
mode:
authorJeija <norrepli@gmail.com>2012-12-27 22:28:39 +0100
committerJeija <norrepli@gmail.com>2012-12-27 22:28:39 +0100
commit2bbc9dd4b76ba5df543442b1e30f91b26de45da5 (patch)
treeb8334b44c60d4ddb0e0bb0d051ffe1d14490912c /mesecons_pressureplates
parent72d58d20187c332f823f4b090935fb193c134ef5 (diff)
downloadmesecons-2bbc9dd4b76ba5df543442b1e30f91b26de45da5.tar
mesecons-2bbc9dd4b76ba5df543442b1e30f91b26de45da5.tar.gz
mesecons-2bbc9dd4b76ba5df543442b1e30f91b26de45da5.tar.bz2
mesecons-2bbc9dd4b76ba5df543442b1e30f91b26de45da5.tar.xz
mesecons-2bbc9dd4b76ba5df543442b1e30f91b26de45da5.zip
Rework the next nodes: Pressure Plates
Diffstat (limited to 'mesecons_pressureplates')
-rw-r--r--mesecons_pressureplates/init.lua248
1 files changed, 101 insertions, 147 deletions
diff --git a/mesecons_pressureplates/init.lua b/mesecons_pressureplates/init.lua
index 78389a4..2e80edb 100644
--- a/mesecons_pressureplates/init.lua
+++ b/mesecons_pressureplates/init.lua
@@ -1,159 +1,113 @@
--- PRESSURE PLATE WOOD
+local pp_box_off = {
+ type = "fixed",
+ fixed = { -7/16, -8/16, -7/16, 7/16, -7/16, 7/16 },
+}
-minetest.register_node("mesecons_pressureplates:pressure_plate_wood_off", {
- drawtype = "nodebox",
- tiles = {"jeija_pressure_plate_wood_off.png"},
- inventory_image = "jeija_pressure_plate_wood_off.png",
- wield_image = "jeija_pressure_plate_wood_off.png",
- paramtype = "light",
- is_ground_content = true,
- walkable = true,
- selection_box = {
- type = "fixed",
- fixed = { -7/16, -8/16, -7/16, 7/16, -7/16, 7/16 },
- },
- node_box = {
- type = "fixed",
- fixed = { -7/16, -8/16, -7/16, 7/16, -7/16, 7/16 },
- },
- groups = {snappy=2,choppy=2,oddly_breakable_by_hand=3},
- description="Wood Pressure Plate",
-
- on_timer = function(pos, elapsed)
- local objs = minetest.env:get_objects_inside_radius(pos, 1)
- for k, obj in pairs(objs) do
- local objpos=obj:getpos()
- if objpos.y>pos.y-1 and objpos.y<pos.y then
- minetest.env:add_node(pos, {name="mesecons_pressureplates:pressure_plate_wood_on"})
- mesecon:receptor_on(pos)
- end
- end
- return true
- end,
- mesecons = {receptor = {
- state = mesecon.state.off
- }},
- on_construct = function(pos)
- minetest.env:get_node_timer(pos):start(PRESSURE_PLATE_INTERVAL)
- end,
-})
+local pp_box_on = {
+ type = "fixed",
+ fixed = { -7/16, -8/16, -7/16, 7/16, -7/16, 7/16 },
+}
-minetest.register_node("mesecons_pressureplates:pressure_plate_wood_on", {
- drawtype = "nodebox",
- tiles = {"jeija_pressure_plate_wood_on.png"},
- paramtype = "light",
- is_ground_content = true,
- walkable = true,
- selection_box = {
- type = "fixed",
- fixed = { -7/16, -8/16, -7/16, 7/16, -7/16, 7/16 },
- },
- node_box = {
- type = "fixed",
- fixed = { -7/16, -8/16, -7/16, 7/16, -31/64, 7/16 },
- },
- groups = {snappy=2,choppy=2,oddly_breakable_by_hand=3,not_in_creative_inventory=1},
- drop='"mesecons_pressureplates:pressure_plate_wood_off" 1',
-
- on_timer = function(pos, elapsed)
- local objs = minetest.env:get_objects_inside_radius(pos, 1)
- if objs[1]==nil then
- minetest.env:add_node(pos, {name="mesecons_pressureplates:pressure_plate_wood_off"})
- mesecon:receptor_off(pos)
- end
- return true
- end,
- mesecons = {receptor = {
- state = mesecon.state.on
- }},
- on_construct = function(pos)
- minetest.env:get_node_timer(pos):start(PRESSURE_PLATE_INTERVAL)
- end,
-})
+pp_on_timer = function (pos, elapsed)
+ local node = minetest.env:get_node(pos)
+ local ppspec = minetest.registered_nodes[node.name].pressureplate
-minetest.register_craft({
- output = '"mesecons_pressureplates:pressure_plate_wood_off" 1',
- recipe = {
- {'"default:wood"', '"default:wood"'},
- }
-})
+ -- This is a workaround for a strange bug that occurs when the server is started
+ -- For some reason the first time on_timer is called, the pos is wrong
+ if not ppspec then return end
--- PRESSURE PLATE STONE
+ local objs = minetest.env:get_objects_inside_radius(pos, 1)
-minetest.register_node("mesecons_pressureplates:pressure_plate_stone_off", {
- drawtype = "nodebox",
- tiles = {"jeija_pressure_plate_stone_off.png"},
- inventory_image = "jeija_pressure_plate_stone_off.png",
- wield_image = "jeija_pressure_plate_stone_off.png",
- paramtype = "light",
- is_ground_content = true,
- walkable = true,
- selection_box = {
- type = "fixed",
- fixed = { -7/16, -8/16, -7/16, 7/16, -7/16, 7/16 },
- },
- node_box = {
- type = "fixed",
- fixed = { -7/16, -8/16, -7/16, 7/16, -7/16, 7/16 },
- },
- groups = {snappy=2,choppy=2,oddly_breakable_by_hand=3},
- description="Stone Pressure Plate",
-
- on_timer = function(pos, elapsed)
- local objs = minetest.env:get_objects_inside_radius(pos, 1)
+ if objs[1] == nil and node.name == ppspec.onstate then
+ minetest.env:add_node(pos, {name = ppspec.offstate})
+ mesecon:receptor_off(pos)
+ -- force deactivation of mesecon two blocks below (hacky)
+ mesecon:turnoff(mesecon:addPosRule(pos, {x = 0, y = -2, z = 0}))
+ else
for k, obj in pairs(objs) do
- local objpos=obj:getpos()
- if objpos.y>pos.y-1 and objpos.y<pos.y then
- minetest.env:add_node(pos, {name="mesecons_pressureplates:pressure_plate_stone_on"})
+ local objpos = obj:getpos()
+ if objpos.y > pos.y-1 and objpos.y < pos.y then
+ minetest.env:add_node(pos, {name=ppspec.onstate})
mesecon:receptor_on(pos)
+ -- force activation of mesecon two blocks below (hacky)
+ mesecon:turnon(mesecon:addPosRule(pos, {x = 0, y = -2, z = 0}))
end
end
- return true
- end,
- mesecons = {receptor = {
- state = mesecon.state.off
- }},
- on_construct = function(pos)
- minetest.env:get_node_timer(pos):start(PRESSURE_PLATE_INTERVAL)
- end,
-})
+ end
+ return true
+end
-minetest.register_node("mesecons_pressureplates:pressure_plate_stone_on", {
- drawtype = "nodebox",
- tiles = {"jeija_pressure_plate_stone_on.png"},
- paramtype = "light",
- is_ground_content = true,
- walkable = true,
- selection_box = {
- type = "fixed",
- fixed = { -7/16, -8/16, -7/16, 7/16, -7/16, 7/16 },
- },
- node_box = {
- type = "fixed",
- fixed = { -7/16, -8/16, -7/16, 7/16, -31/64, 7/16 },
- },
- groups = {snappy=2,choppy=2,oddly_breakable_by_hand=3,not_in_creative_inventory=1},
- drop='"mesecons_pressureplates:pressure_plate_stone_off" 1',
-
- on_timer = function(pos, elapsed)
- local objs = minetest.env:get_objects_inside_radius(pos, 1)
- if objs[1]==nil then
- minetest.env:add_node(pos, {name="mesecons_pressureplates:pressure_plate_stone_off"})
- mesecon:receptor_off(pos)
- end
- return true
- end,
- mesecons = {receptor = {
- state = mesecon.state.on
- }},
- on_construct = function(pos)
- minetest.env:get_node_timer(pos):start(PRESSURE_PLATE_INTERVAL)
- end,
-})
+-- Register a Pressure Plate
+-- offstate: name of the pressure plate when inactive
+-- onstate: name of the pressure plate when active
+-- description: description displayed in the player's inventory
+-- tiles_off: textures of the pressure plate when inactive
+-- tiles_on: textures of the pressure plate when active
+-- image: inventory and wield image of the pressure plate
+-- recipe: crafting recipe of the pressure plate
-minetest.register_craft({
- output = '"mesecons_pressureplates:pressure_plate_stone_off" 1',
- recipe = {
- {'"default:cobble"', '"default:cobble"'},
+function mesecon:register_pressure_plate(offstate, onstate, description, texture_off, texture_on, recipe)
+ local ppspec = {
+ offstate = offstate,
+ onstate = onstate
}
-})
+
+ minetest.register_node(offstate, {
+ drawtype = "nodebox",
+ tiles = {texture_off},
+ inventory_image = texture_off,
+ wield_image = image,
+ paramtype = "light",
+ selection_box = pp_box_off,
+ node_box = pp_box_off,
+ groups = {snappy = 2, oddly_breakable_by_hand = 3},
+ description = description,
+ pressureplate = ppspec,
+ on_timer = pp_on_timer,
+ mesecons = {receptor = {
+ state = mesecon.state.off
+ }},
+ on_construct = function(pos)
+ minetest.env:get_node_timer(pos):start(PRESSURE_PLATE_INTERVAL)
+ end,
+ })
+
+ minetest.register_node(onstate, {
+ drawtype = "nodebox",
+ tiles = {texture_on},
+ paramtype = "light",
+ selection_box = pp_box_on,
+ node_box = pp_box_on,
+ groups = {snappy = 2, oddly_breakable_by_hand = 3, not_in_creative_inventory = 1},
+ drop = offstate,
+ pressureplate = ppspec,
+ on_timer = pp_on_timer,
+ mesecons = {receptor = {
+ state = mesecon.state.on
+ }},
+ on_construct = function(pos)
+ minetest.env:get_node_timer(pos):start(PRESSURE_PLATE_INTERVAL)
+ end,
+ })
+
+ minetest.register_craft({
+ output = offstate,
+ recipe = recipe,
+ })
+end
+
+mesecon:register_pressure_plate(
+ "mesecons_pressureplates:pressure_plate_wood_off",
+ "mesecons_pressureplates:pressure_plate_wood_on",
+ "Wooden Pressure Plate",
+ "jeija_pressure_plate_wood_off.png",
+ "jeija_pressure_plate_wood_on.png",
+ {{"default:wood", "default:wood"}})
+
+mesecon:register_pressure_plate(
+ "mesecons_pressureplates:pressure_plate_stone_off",
+ "mesecons_pressureplates:pressure_plate_stone_on",
+ "Stone Pressure Plate",
+ "jeija_pressure_plate_stone_off.png",
+ "jeija_pressure_plate_stone_on.png",
+ {{"default:cobble", "default:cobble"}})