1 local S
= minetest
.get_translator("mesecons_pressureplates")
3 local PRESSURE_PLATE_INTERVAL
= 0.04
7 fixed
= { -7/16, -8/16, -7/16, 7/16, -7/16, 7/16 },
12 fixed
= { -7/16, -8/16, -7/16, 7/16, -7.5/16, 7/16 },
15 local function pp_on_timer(pos
, elapsed
)
16 local node
= minetest
.get_node(pos
)
17 local basename
= minetest
.registered_nodes
[node
.name
].pressureplate_basename
18 local activated_by
= minetest
.registered_nodes
[node
.name
].pressureplate_activated_by
20 -- This is a workaround for a strange bug that occurs when the server is started
21 -- For some reason the first time on_timer is called, the pos is wrong
22 if not basename
then return end
24 if activated_by
== nil then
25 activated_by
= { any
= true }
28 local obj_does_activate
= function(obj
, activated_by
)
29 if activated_by
.any
then
31 elseif activated_by
.mob
and obj
:get_luaentity() and obj
:get_luaentity()._cmi_is_mob
== true then
33 elseif activated_by
.player
and obj
:is_player() then
40 local objs
= minetest
.get_objects_inside_radius(pos
, 1)
42 if node
.name
== basename
.. "_on" then
46 elseif not activated_by
.any
then
48 for k
, obj
in pairs(objs
) do
49 if obj_does_activate(obj
, activated_by
) then
56 minetest
.set_node(pos
, {name
= basename
.. "_off"})
57 mesecon
.receptor_off(pos
, mesecon
.rules
.pplate
)
59 elseif node
.name
== basename
.. "_off" then
60 for k
, obj
in pairs(objs
) do
61 local objpos
= obj
:get_pos()
62 if obj_does_activate(obj
, activated_by
) then
63 if objpos
.y
> pos
.y
-1 and objpos
.y
< pos
.y
then
64 minetest
.set_node(pos
, {name
= basename
.. "_on"})
65 mesecon
.receptor_on(pos
, mesecon
.rules
.pplate
)
74 -- Register a Pressure Plate
75 -- basename: base name of the pressure plate
76 -- description: description displayed in the player's inventory
77 -- textures_off:textures of the pressure plate when inactive
78 -- textures_on: textures of the pressure plate when active
79 -- image_w: wield image of the pressure plate
80 -- image_i: inventory image of the pressure plate
81 -- recipe: crafting recipe of the pressure plate
82 -- sounds: sound table (like in minetest.register_node)
83 -- plusgroups: group memberships (attached_node=1 and not_in_creative_inventory=1 are already used)
84 -- activated_by: optinal table with elements denoting by which entities this pressure plate is triggered
85 -- Possible table fields:
86 -- * player=true: Player
88 -- By default, is triggered by all entities
89 -- longdesc: Customized long description for the in-game help (if omitted, a dummy text is used)
91 function mesecon
.register_pressure_plate(basename
, description
, textures_off
, textures_on
, image_w
, image_i
, recipe
, sounds
, plusgroups
, activated_by
, longdesc
)
92 local groups_off
= table.copy(plusgroups
)
93 groups_off
.attached_node
= 1
94 groups_off
.dig_by_piston
= 1
95 groups_off
.pressure_plate
= 1
96 local groups_on
= table.copy(groups_off
)
97 groups_on
.not_in_creative_inventory
= 1
98 groups_on
.pressure_plate
= 2
100 longdesc
= S("A pressure plate is a redstone component which supplies its surrounding blocks with redstone power while someone or something rests on top of it.")
102 local tt
= S("Provides redstone power when pushed")
103 if not activated_by
then
104 tt
= tt
.. "\n" .. S("Pushable by players, mobs and objects")
105 elseif activated_by
.mob
and activated_by
.player
then
106 tt
= tt
.. "\n" .. S("Pushable by players and mobs")
107 elseif activated_by
.mob
then
108 tt
= tt
.. "\n" .. S("Pushable by mobs")
109 elseif activated_by
.player
then
110 tt
= tt
.. "\n" .. S("Pushable by players")
113 mesecon
.register_node(basename
, {
114 drawtype
= "nodebox",
115 inventory_image
= image_i
,
116 wield_image
= image_w
,
119 description
= description
,
120 on_timer
= pp_on_timer
,
121 on_construct
= function(pos
)
122 minetest
.get_node_timer(pos
):start(PRESSURE_PLATE_INTERVAL
)
125 is_ground_content
= false,
126 pressureplate_basename
= basename
,
127 pressureplate_activated_by
= activated_by
,
128 _mcl_blast_resistance
= 0.5,
131 node_box
= pp_box_off
,
132 selection_box
= pp_box_off
,
134 tiles
= textures_off
,
136 mesecons
= {receptor
= { state
= mesecon
.state
.off
, rules
= mesecon
.rules
.pplate
}},
137 _doc_items_longdesc
= longdesc
,
140 node_box
= pp_box_on
,
141 selection_box
= pp_box_on
,
146 mesecons
= {receptor
= { state
= mesecon
.state
.on
, rules
= mesecon
.rules
.pplate
}},
147 _doc_items_create_entry
= false,
150 minetest
.register_craft({
151 output
= basename
.. "_off",
155 if minetest
.get_modpath("doc") then
156 doc
.add_entry_alias("nodes", basename
.. "_off", "nodes", basename
.. "_on")
161 { "wood", "mcl_core:wood", "default_wood.png", S("Oak Pressure Plate") },
162 { "acaciawood", "mcl_core:acaciawood", "default_acacia_wood.png", S("Acacia Pressure Plate") },
163 { "birchwood", "mcl_core:birchwood", "mcl_core_planks_birch.png", S("Birch Pressure Plate") },
164 { "darkwood", "mcl_core:darkwood", "mcl_core_planks_big_oak.png", S("Dark Oak Pressure Plate" )},
165 { "sprucewood", "mcl_core:sprucewood", "mcl_core_planks_spruce.png", S("Spruce Pressure Plate") },
166 { "junglewood", "mcl_core:junglewood", "default_junglewood.png", S("Jungle Pressure Plate") },
170 mesecon
.register_pressure_plate(
171 "mesecons_pressureplates:pressure_plate_"..woods
[w
][1],
177 {{woods
[w
][2], woods
[w
][2]}},
178 mcl_sounds
.node_sound_wood_defaults(),
179 {axey
=1, material_wood
=1},
181 S("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."))
183 minetest
.register_craft({
185 recipe
= "mesecons_pressureplates:pressure_plate_"..woods
[w
][1].."_off",
191 mesecon
.register_pressure_plate(
192 "mesecons_pressureplates:pressure_plate_stone",
193 S("Stone Pressure Plate"),
194 {"default_stone.png"},
195 {"default_stone.png"},
198 {{"mcl_core:stone", "mcl_core:stone"}},
199 mcl_sounds
.node_sound_stone_defaults(),
200 {pickaxey
=1, material_stone
=1},
201 { player
= true, mob
= true },
202 S("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."))