2017-07-30 22:12:21 +00:00
local PRESSURE_PLATE_INTERVAL = 0.04
2015-06-29 17:55:56 +00:00
local pp_box_off = {
type = " fixed " ,
fixed = { - 7 / 16 , - 8 / 16 , - 7 / 16 , 7 / 16 , - 7 / 16 , 7 / 16 } ,
}
local pp_box_on = {
type = " fixed " ,
fixed = { - 7 / 16 , - 8 / 16 , - 7 / 16 , 7 / 16 , - 7.5 / 16 , 7 / 16 } ,
}
2017-07-30 22:12:21 +00:00
local function pp_on_timer ( pos , elapsed )
local node = minetest.get_node ( pos )
local basename = minetest.registered_nodes [ node.name ] . pressureplate_basename
2015-06-29 17:55:56 +00:00
-- 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
2017-07-30 22:12:21 +00:00
if not basename then return end
2015-06-29 17:55:56 +00:00
2017-01-11 17:21:46 +00:00
local objs = minetest.get_objects_inside_radius ( pos , 1 )
2017-07-30 22:12:21 +00:00
local two_below = vector.add ( pos , vector.new ( 0 , - 2 , 0 ) )
if objs [ 1 ] == nil and node.name == basename .. " _on " then
minetest.set_node ( pos , { name = basename .. " _off " } )
mesecon.receptor_off ( pos , mesecon.rules . pplate )
elseif node.name == basename .. " _off " then
2015-06-29 17:55:56 +00:00
for k , obj in pairs ( objs ) do
local objpos = obj : getpos ( )
if objpos.y > pos.y - 1 and objpos.y < pos.y then
2017-07-30 22:12:21 +00:00
minetest.set_node ( pos , { name = basename .. " _on " } )
mesecon.receptor_on ( pos , mesecon.rules . pplate )
2015-06-29 17:55:56 +00:00
end
end
end
return true
end
-- Register a Pressure Plate
2017-07-30 22:12:21 +00:00
-- basename: base name of the pressure plate
2015-06-29 17:55:56 +00:00
-- description: description displayed in the player's inventory
2017-07-30 22:12:21 +00:00
-- textures_off:textures of the pressure plate when inactive
-- textures_on: textures of the pressure plate when active
-- image_w: wield image of the pressure plate
-- image_i: inventory image of the pressure plate
2015-06-29 17:55:56 +00:00
-- recipe: crafting recipe of the pressure plate
2017-02-27 16:29:07 +00:00
-- sounds: sound table (like in minetest.register_node)
-- plusgroups: group memberships (attached_node=1 and not_in_creative_inventory=1 are already used)
2015-06-29 17:55:56 +00:00
2017-07-30 22:12:21 +00:00
function mesecon . register_pressure_plate ( basename , description , textures_off , textures_on , image_w , image_i , recipe , sounds , plusgroups )
2017-02-27 16:29:07 +00:00
local groups_off = table.copy ( plusgroups )
groups_off.attached_node = 1
2017-03-29 20:58:31 +00:00
groups_off.dig_by_piston = 1
2017-08-29 21:27:20 +00:00
local groups_on = table.copy ( groups_off )
2017-07-30 22:12:21 +00:00
groups_on.not_in_creative_inventory = 1
2017-02-27 16:29:07 +00:00
2017-07-30 22:12:21 +00:00
mesecon.register_node ( basename , {
2015-06-29 17:55:56 +00:00
drawtype = " nodebox " ,
2017-07-30 22:12:21 +00:00
inventory_image = image_i ,
wield_image = image_w ,
2015-06-29 17:55:56 +00:00
paramtype = " light " ,
description = description ,
on_timer = pp_on_timer ,
on_construct = function ( pos )
2017-01-11 17:21:46 +00:00
minetest.get_node_timer ( pos ) : start ( PRESSURE_PLATE_INTERVAL )
2015-06-29 17:55:56 +00:00
end ,
2017-07-30 22:12:21 +00:00
sounds = sounds ,
pressureplate_basename = basename ,
2017-02-22 15:22:28 +00:00
_mcl_blast_resistance = 2.5 ,
2017-02-27 16:29:07 +00:00
_mcl_hardness = 0.5 ,
2017-07-30 22:12:21 +00:00
} , {
node_box = pp_box_off ,
selection_box = pp_box_off ,
groups = groups_off ,
tiles = textures_off ,
2017-02-27 16:29:07 +00:00
2017-07-30 22:12:21 +00:00
mesecons = { receptor = { state = mesecon.state . off , rules = mesecon.rules . pplate } } ,
_doc_items_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. " ,
} , {
2015-06-29 17:55:56 +00:00
node_box = pp_box_on ,
2017-07-30 22:12:21 +00:00
selection_box = pp_box_on ,
2017-02-27 16:29:07 +00:00
groups = groups_on ,
2017-07-30 22:12:21 +00:00
tiles = textures_on ,
mesecons = { receptor = { state = mesecon.state . on , rules = mesecon.rules . pplate } } ,
2015-06-29 17:55:56 +00:00
} )
minetest.register_craft ( {
2017-07-30 22:12:21 +00:00
output = basename .. " _off " ,
2015-06-29 17:55:56 +00:00
recipe = recipe ,
} )
2017-03-21 03:27:50 +00:00
if minetest.get_modpath ( " doc " ) then
2017-07-30 22:12:21 +00:00
doc.add_entry_alias ( " nodes " , basename .. " _off " , " nodes " , basename .. " _on " )
2017-03-21 03:27:50 +00:00
end
2015-06-29 17:55:56 +00:00
end
2017-07-30 22:12:21 +00:00
mesecon.register_pressure_plate (
" mesecons_pressureplates:pressure_plate_wood " ,
2015-06-29 17:55:56 +00:00
" Wooden Pressure Plate " ,
2017-07-30 22:12:21 +00:00
{ " default_wood.png " } ,
{ " default_wood.png " } ,
2015-06-29 17:55:56 +00:00
" default_wood.png " ,
2017-07-30 22:12:21 +00:00
nil ,
2017-01-17 16:41:04 +00:00
{ { " group:wood " , " group:wood " } } ,
2017-02-27 16:29:07 +00:00
mcl_sounds.node_sound_wood_defaults ( ) ,
2017-03-11 04:34:58 +00:00
{ axey = 1 , material_wood = 1 } )
2015-06-29 17:55:56 +00:00
2017-07-30 22:12:21 +00:00
mesecon.register_pressure_plate (
" mesecons_pressureplates:pressure_plate_stone " ,
2015-06-29 17:55:56 +00:00
" Stone Pressure Plate " ,
2017-07-30 22:12:21 +00:00
{ " default_stone.png " } ,
{ " default_stone.png " } ,
2015-06-29 17:55:56 +00:00
" default_stone.png " ,
2017-07-30 22:12:21 +00:00
nil ,
2017-01-31 22:32:56 +00:00
{ { " mcl_core:stone " , " mcl_core:stone " } } ,
2017-02-27 16:29:07 +00:00
mcl_sounds.node_sound_stone_defaults ( ) ,
2017-03-11 04:34:58 +00:00
{ pickaxey = 1 , material_stone = 1 } )
2017-01-10 05:43:07 +00:00
minetest.register_craft ( {
type = " fuel " ,
recipe = " mesecons_pressureplates:pressure_plate_wood_off " ,
burntime = 15
} )
2017-03-21 03:27:50 +00:00