2015-06-29 20:55:56 +03: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 } ,
}
pp_on_timer = function ( pos , elapsed )
2017-01-11 19:21:46 +02:00
local node = minetest.get_node ( pos )
2015-06-29 20:55:56 +03:00
local ppspec = minetest.registered_nodes [ node.name ] . pressureplate
-- 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
2017-01-11 19:21:46 +02:00
local objs = minetest.get_objects_inside_radius ( pos , 1 )
2015-06-29 20:55:56 +03:00
local two_below = mesecon : addPosRule ( pos , { x = 0 , y = - 2 , z = 0 } )
if objs [ 1 ] == nil and node.name == ppspec.onstate then
2017-01-11 19:21:46 +02:00
minetest.add_node ( pos , { name = ppspec.offstate } )
2015-06-29 20:55:56 +03:00
mesecon : receptor_off ( pos )
-- force deactivation of mesecon two blocks below (hacky)
if not mesecon : connected_to_receptor ( two_below ) then
mesecon : turnoff ( two_below )
end
2017-07-31 03:14:11 +03:00
elseif node.name == ppspec.offstate then
2015-06-29 20:55:56 +03: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-01-11 19:21:46 +02:00
minetest.add_node ( pos , { name = ppspec.onstate } )
2015-06-29 20:55:56 +03:00
mesecon : receptor_on ( pos )
-- force activation of mesecon two blocks below (hacky)
mesecon : turnon ( two_below )
end
end
end
return true
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
2017-02-27 18:29:07 +02: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 20:55:56 +03:00
2017-02-27 18:29:07 +02:00
function mesecon : register_pressure_plate ( offstate , onstate , description , texture_off , texture_on , recipe , sounds , plusgroups )
2015-06-29 20:55:56 +03:00
local ppspec = {
offstate = offstate ,
onstate = onstate
}
2017-02-27 18:29:07 +02:00
local groups_off = table.copy ( plusgroups )
groups_off.attached_node = 1
2017-03-29 23:58:31 +03:00
groups_off.dig_by_piston = 1
2017-02-27 18:29:07 +02:00
2015-06-29 20:55:56 +03:00
minetest.register_node ( offstate , {
drawtype = " nodebox " ,
tiles = { texture_off } ,
wield_image = texture_off ,
2017-03-02 18:03:14 +02:00
wield_scale = { x = 1 , y = 1 , z = 0.5 } ,
2015-06-29 20:55:56 +03:00
paramtype = " light " ,
2017-06-13 15:20:49 +03:00
sunlight_propagates = true ,
2015-06-29 20:55:56 +03:00
selection_box = pp_box_off ,
node_box = pp_box_off ,
2017-02-27 18:29:07 +02:00
groups = groups_off ,
2017-01-04 23:36:51 +02:00
is_ground_content = false ,
2015-06-29 20:55:56 +03:00
description = description ,
2017-03-14 07:00:39 +02:00
_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 20:55:56 +03:00
pressureplate = ppspec ,
on_timer = pp_on_timer ,
2017-01-17 18:41:04 +02:00
sounds = sounds ,
2015-06-29 20:55:56 +03:00
mesecons = { receptor = {
state = mesecon.state . off
} } ,
on_construct = function ( pos )
2017-01-11 19:21:46 +02:00
minetest.get_node_timer ( pos ) : start ( PRESSURE_PLATE_INTERVAL )
2015-06-29 20:55:56 +03:00
end ,
2017-02-22 17:22:28 +02:00
_mcl_blast_resistance = 2.5 ,
2017-02-27 18:29:07 +02:00
_mcl_hardness = 0.5 ,
2015-06-29 20:55:56 +03:00
} )
2017-02-27 18:29:07 +02:00
local groups_on = table.copy ( groups_off )
groups_on.not_in_creative_inventory = 1
2015-06-29 20:55:56 +03:00
minetest.register_node ( onstate , {
drawtype = " nodebox " ,
tiles = { texture_on } ,
2017-03-02 18:03:14 +02:00
wield_image = texture_on ,
wield_scale = { x = 1 , y = 1 , z = 0.25 } ,
2015-06-29 20:55:56 +03:00
paramtype = " light " ,
2017-06-13 15:20:49 +03:00
sunlight_propagates = true ,
2015-06-29 20:55:56 +03:00
selection_box = pp_box_on ,
node_box = pp_box_on ,
2017-02-27 18:29:07 +02:00
groups = groups_on ,
2017-01-04 23:36:51 +02:00
is_ground_content = false ,
2015-06-29 20:55:56 +03:00
drop = offstate ,
pressureplate = ppspec ,
on_timer = pp_on_timer ,
2017-01-17 18:41:04 +02:00
sounds = sounds ,
2015-06-29 20:55:56 +03:00
mesecons = { receptor = {
state = mesecon.state . on
} } ,
on_construct = function ( pos )
2017-01-11 19:21:46 +02:00
minetest.get_node_timer ( pos ) : start ( PRESSURE_PLATE_INTERVAL )
2015-06-29 20:55:56 +03:00
end ,
after_dig_node = function ( pos )
local two_below = mesecon : a ddPosRule ( pos , { x = 0 , y = - 2 , z = 0 } )
if not mesecon : connected_to_receptor ( two_below ) then
mesecon : turnoff ( two_below )
end
2017-02-22 17:22:28 +02:00
end ,
_mcl_blast_resistance = 2.5 ,
2017-02-27 18:29:07 +02:00
_mcl_hardness = 0.5 ,
2015-06-29 20:55:56 +03:00
} )
minetest.register_craft ( {
output = offstate ,
recipe = recipe ,
} )
2017-03-21 05:27:50 +02:00
if minetest.get_modpath ( " doc " ) then
doc.add_entry_alias ( " nodes " , offstate , " nodes " , onstate )
end
2015-06-29 20:55:56 +03:00
end
mesecon : register_pressure_plate (
" mesecons_pressureplates:pressure_plate_wood_off " ,
" mesecons_pressureplates:pressure_plate_wood_on " ,
" Wooden Pressure Plate " ,
" default_wood.png " ,
" default_wood.png " ,
2017-01-17 18:41:04 +02:00
{ { " group:wood " , " group:wood " } } ,
2017-02-27 18:29:07 +02:00
mcl_sounds.node_sound_wood_defaults ( ) ,
2017-03-11 06:34:58 +02:00
{ axey = 1 , material_wood = 1 } )
2015-06-29 20:55:56 +03:00
mesecon : register_pressure_plate (
" mesecons_pressureplates:pressure_plate_stone_off " ,
" mesecons_pressureplates:pressure_plate_stone_on " ,
" Stone Pressure Plate " ,
" default_stone.png " ,
" default_stone.png " ,
2017-02-01 00:32:56 +02:00
{ { " mcl_core:stone " , " mcl_core:stone " } } ,
2017-02-27 18:29:07 +02:00
mcl_sounds.node_sound_stone_defaults ( ) ,
2017-03-11 06:34:58 +02:00
{ pickaxey = 1 , material_stone = 1 } )
2017-01-10 07:43:07 +02:00
minetest.register_craft ( {
type = " fuel " ,
recipe = " mesecons_pressureplates:pressure_plate_wood_off " ,
burntime = 15
} )
2017-03-21 05:27:50 +02:00