1 local PRESSURE_PLATE_INTERVAL
= 0.04
5 fixed
= { -7/16, -8/16, -7/16, 7/16, -7/16, 7/16 },
10 fixed
= { -7/16, -8/16, -7/16, 7/16, -7.5/16, 7/16 },
13 local function pp_on_timer(pos
, elapsed
)
14 local node
= minetest
.get_node(pos
)
15 local basename
= minetest
.registered_nodes
[node
.name
].pressureplate_basename
16 local activated_by
= minetest
.registered_nodes
[node
.name
].pressureplate_activated_by
18 -- This is a workaround for a strange bug that occurs when the server is started
19 -- For some reason the first time on_timer is called, the pos is wrong
20 if not basename
then return end
22 if activated_by
== nil then
23 activated_by
= { any
= true }
26 local obj_does_activate
= function(obj
, activated_by
)
27 if activated_by
.any
then
29 elseif activated_by
.mob
and obj
:get_luaentity() and obj
:get_luaentity()._cmi_is_mob
== true then
31 elseif activated_by
.player
and obj
:is_player() then
38 local objs
= minetest
.get_objects_inside_radius(pos
, 1)
40 if node
.name
== basename
.. "_on" then
44 elseif not activated_by
.any
then
46 for k
, obj
in pairs(objs
) do
47 if obj_does_activate(obj
, activated_by
) then
54 minetest
.set_node(pos
, {name
= basename
.. "_off"})
55 mesecon
.receptor_off(pos
, mesecon
.rules
.pplate
)
57 elseif node
.name
== basename
.. "_off" then
58 for k
, obj
in pairs(objs
) do
59 local objpos
= obj
:get_pos()
60 if obj_does_activate(obj
, activated_by
) then
61 if objpos
.y
> pos
.y
-1 and objpos
.y
< pos
.y
then
62 minetest
.set_node(pos
, {name
= basename
.. "_on"})
63 mesecon
.receptor_on(pos
, mesecon
.rules
.pplate
)
72 -- Register a Pressure Plate
73 -- basename: base name of the pressure plate
74 -- description: description displayed in the player's inventory
75 -- textures_off:textures of the pressure plate when inactive
76 -- textures_on: textures of the pressure plate when active
77 -- image_w: wield image of the pressure plate
78 -- image_i: inventory image of the pressure plate
79 -- recipe: crafting recipe of the pressure plate
80 -- sounds: sound table (like in minetest.register_node)
81 -- plusgroups: group memberships (attached_node=1 and not_in_creative_inventory=1 are already used)
82 -- activated_by: optinal table with elements denoting by which entities this pressure plate is triggered
83 -- Possible table fields:
84 -- * player=true: Player
86 -- By default, is triggered by all entities
87 -- longdesc: Customized long description for the in-game help (if omitted, a dummy text is used)
89 function mesecon
.register_pressure_plate(basename
, description
, textures_off
, textures_on
, image_w
, image_i
, recipe
, sounds
, plusgroups
, activated_by
, longdesc
)
90 local groups_off
= table.copy(plusgroups
)
91 groups_off
.attached_node
= 1
92 groups_off
.dig_by_piston
= 1
93 groups_off
.pressure_plate
= 1
94 local groups_on
= table.copy(groups_off
)
95 groups_on
.not_in_creative_inventory
= 1
96 groups_on
.pressure_plate
= 2
98 longdesc
= "A pressure plate is a redstone component which supplies its surrounding blocks with redstone power while someone or something rests on top of it."
101 mesecon
.register_node(basename
, {
102 drawtype
= "nodebox",
103 inventory_image
= image_i
,
104 wield_image
= image_w
,
107 description
= description
,
108 on_timer
= pp_on_timer
,
109 on_construct
= function(pos
)
110 minetest
.get_node_timer(pos
):start(PRESSURE_PLATE_INTERVAL
)
113 is_ground_content
= false,
114 pressureplate_basename
= basename
,
115 pressureplate_activated_by
= activated_by
,
116 _mcl_blast_resistance
= 2.5,
119 node_box
= pp_box_off
,
120 selection_box
= pp_box_off
,
122 tiles
= textures_off
,
124 mesecons
= {receptor
= { state
= mesecon
.state
.off
, rules
= mesecon
.rules
.pplate
}},
125 _doc_items_longdesc
= longdesc
,
127 node_box
= pp_box_on
,
128 selection_box
= pp_box_on
,
132 mesecons
= {receptor
= { state
= mesecon
.state
.on
, rules
= mesecon
.rules
.pplate
}},
133 _doc_items_create_entry
= false,
136 minetest
.register_craft({
137 output
= basename
.. "_off",
141 if minetest
.get_modpath("doc") then
142 doc
.add_entry_alias("nodes", basename
.. "_off", "nodes", basename
.. "_on")
147 { "wood", "mcl_core:wood", "default_wood.png", "Oak Pressure Plate" },
148 { "acaciawood", "mcl_core:acaciawood", "default_acacia_wood.png", "Acacia Pressure Plate" },
149 { "birchwood", "mcl_core:birchwood", "mcl_core_planks_birch.png", "Birch Pressure Plate" },
150 { "darkwood", "mcl_core:darkwood", "mcl_core_planks_big_oak.png", "Dark Oak Pressure Plate" },
151 { "sprucewood", "mcl_core:sprucewood", "mcl_core_planks_spruce.png", "Spruce Pressure Plate" },
152 { "junglewood", "mcl_core:junglewood", "default_junglewood.png", "Jungle Pressure Plate" },
156 mesecon
.register_pressure_plate(
157 "mesecons_pressureplates:pressure_plate_"..woods
[w
][1],
163 {{woods
[w
][2], woods
[w
][2]}},
164 mcl_sounds
.node_sound_wood_defaults(),
165 {axey
=1, material_wood
=1},
167 "A wooden pressure plate is a redstone component which supplies its surrounding blocks with redstone power while any movable object (including dropped items, players and mobs) rests on top of it.")
169 minetest
.register_craft({
171 recipe
= "mesecons_pressureplates:pressure_plate_"..woods
[w
][1].."_off",
177 mesecon
.register_pressure_plate(
178 "mesecons_pressureplates:pressure_plate_stone",
179 "Stone Pressure Plate",
180 {"default_stone.png"},
181 {"default_stone.png"},
184 {{"mcl_core:stone", "mcl_core:stone"}},
185 mcl_sounds
.node_sound_stone_defaults(),
186 {pickaxey
=1, material_stone
=1},
187 { player
= true, mob
= true },
188 "A stone pressure plate is a redstone component which supplies its surrounding blocks with redstone power while a player or mob stands on top of it. It is not triggered by anything else.")