2021-05-29 16:12:33 +02:00
local S = minetest.get_translator ( minetest.get_current_modname ( ) )
2019-03-08 01:07:41 +01:00
2023-04-03 19:33:50 +02:00
local PRESSURE_PLATE_INTERVAL = 0.25
2017-07-31 00:12:21 +02:00
2015-06-29 19:55:56 +02: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 } ,
}
2022-12-05 21:24:34 +01:00
local function pp_on_rightclick ( pos , node )
local basename = minetest.registered_nodes [ node.name ] . pressureplate_basename
if node.name == basename .. " _off " then
minetest.set_node ( pos , { name = basename .. " _on " } )
mesecon.receptor_on ( pos , mesecon.rules . pplate )
else
minetest.get_meta ( pos ) : set_string ( " deact_time " , " " )
end
end
2017-07-31 00:12:21 +02:00
local function pp_on_timer ( pos , elapsed )
local node = minetest.get_node ( pos )
local basename = minetest.registered_nodes [ node.name ] . pressureplate_basename
2017-09-11 18:29:10 +02:00
local activated_by = minetest.registered_nodes [ node.name ] . pressureplate_activated_by
2015-06-29 19:55:56 +02: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-31 00:12:21 +02:00
if not basename then return end
2015-06-29 19:55:56 +02:00
2017-09-11 18:29:10 +02:00
if activated_by == nil then
activated_by = { any = true }
end
local obj_does_activate = function ( obj , activated_by )
if activated_by.any then
return true
2022-05-25 14:02:10 +02:00
elseif activated_by.mob and obj : get_luaentity ( ) and obj : get_luaentity ( ) . is_mob == true then
2017-09-11 18:29:10 +02:00
return true
elseif activated_by.player and obj : is_player ( ) then
return true
else
return false
end
end
2017-07-31 00:12:21 +02:00
2022-12-01 20:02:30 +01:00
local function obj_touching_plate_pos ( obj_ref , plate_pos )
local obj_pos = obj_ref : get_pos ( )
local props = obj_ref : get_properties ( )
local parent = obj_ref : get_attach ( )
if props and obj_pos and not parent then
local collisionbox = props.collisionbox
local physical = props.physical
local is_player = obj_ref : is_player ( )
local luaentity = obj_ref : get_luaentity ( )
local is_item = luaentity and luaentity.name == " __builtin:item "
if collisionbox and physical or is_player or is_item then
local plate_x_min = plate_pos.x - 7 / 16
local plate_x_max = plate_pos.x + 7 / 16
local plate_z_min = plate_pos.z - 7 / 16
local plate_z_max = plate_pos.z + 7 / 16
local plate_y_max = plate_pos.y - 7 / 16
2017-09-11 18:29:10 +02:00
2022-12-01 20:02:30 +01:00
local obj_x_min = obj_pos.x + collisionbox [ 1 ]
local obj_x_max = obj_pos.x + collisionbox [ 4 ]
local obj_z_min = obj_pos.z + collisionbox [ 3 ]
local obj_z_max = obj_pos.z + collisionbox [ 6 ]
local obj_y_min = obj_pos.y + collisionbox [ 2 ]
if
obj_y_min <= plate_y_max and
not ( obj_x_min >= plate_x_max ) and
not ( obj_x_max <= plate_x_min ) and
not ( obj_z_min >= plate_z_max ) and
not ( obj_z_max <= plate_z_min )
then
return true
2017-09-11 18:29:10 +02:00
end
end
end
2022-12-01 20:02:30 +01:00
return false
end
local objs = minetest.get_objects_inside_radius ( pos , 1 )
if node.name == basename .. " _on " then
local disable = true
for k , obj in pairs ( objs ) do
if
obj_does_activate ( obj , activated_by ) and
obj_touching_plate_pos ( obj , pos )
then
disable = false
2022-12-04 17:53:07 +01:00
minetest.get_meta ( pos ) : set_string ( " deact_time " , " " )
2022-12-01 20:02:30 +01:00
break
end
end
2017-09-11 18:29:10 +02:00
if disable then
2022-12-04 17:53:07 +01:00
local meta = minetest.get_meta ( pos )
local deact_time = meta : get_float ( " deact_time " )
local current_time = minetest.get_us_time ( )
if deact_time == 0 then
deact_time = current_time + 1 * 1000 * 1000
meta : set_float ( " deact_time " , deact_time )
end
if deact_time <= current_time then
minetest.set_node ( pos , { name = basename .. " _off " } )
mesecon.receptor_off ( pos , mesecon.rules . pplate )
meta : set_string ( " deact_time " , " " )
end
2017-09-11 18:29:10 +02:00
end
2017-07-31 00:12:21 +02:00
elseif node.name == basename .. " _off " then
2015-06-29 19:55:56 +02:00
for k , obj in pairs ( objs ) do
2022-12-01 20:02:30 +01:00
if
obj_does_activate ( obj , activated_by ) and
obj_touching_plate_pos ( obj , pos )
then
2022-12-04 17:53:07 +01:00
minetest.set_node ( pos , { name = basename .. " _on " } )
2022-12-01 20:02:30 +01:00
mesecon.receptor_on ( pos , mesecon.rules . pplate )
break
2015-06-29 19:55:56 +02:00
end
end
end
return true
end
-- Register a Pressure Plate
2017-07-31 00:12:21 +02:00
-- basename: base name of the pressure plate
2015-06-29 19:55:56 +02:00
-- description: description displayed in the player's inventory
2017-07-31 00:12:21 +02: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 19:55:56 +02:00
-- recipe: crafting recipe of the pressure plate
2017-02-27 17:29:07 +01:00
-- sounds: sound table (like in minetest.register_node)
-- plusgroups: group memberships (attached_node=1 and not_in_creative_inventory=1 are already used)
2017-09-11 18:29:10 +02:00
-- activated_by: optinal table with elements denoting by which entities this pressure plate is triggered
-- Possible table fields:
-- * player=true: Player
-- * mob=true: Mob
-- By default, is triggered by all entities
2017-09-11 18:38:49 +02:00
-- longdesc: Customized long description for the in-game help (if omitted, a dummy text is used)
2015-06-29 19:55:56 +02:00
2017-09-11 18:38:49 +02:00
function mesecon . register_pressure_plate ( basename , description , textures_off , textures_on , image_w , image_i , recipe , sounds , plusgroups , activated_by , longdesc )
2017-02-27 17:29:07 +01:00
local groups_off = table.copy ( plusgroups )
groups_off.attached_node = 1
2017-03-29 22:58:31 +02:00
groups_off.dig_by_piston = 1
2017-11-22 22:42:00 +01:00
groups_off.pressure_plate = 1
2017-08-29 23:27:20 +02:00
local groups_on = table.copy ( groups_off )
2017-07-31 00:12:21 +02:00
groups_on.not_in_creative_inventory = 1
2017-11-22 22:42:00 +01:00
groups_on.pressure_plate = 2
2017-09-11 18:38:49 +02:00
if not longdesc then
2019-03-08 01:07:41 +01:00
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. " )
2017-09-11 18:38:49 +02:00
end
2020-02-19 04:54:17 +01:00
local tt = S ( " Provides redstone power when pushed " )
if not activated_by then
2020-03-12 01:35:11 +01:00
tt = tt .. " \n " .. S ( " Pushable by players, mobs and objects " )
2020-02-19 04:54:17 +01:00
elseif activated_by.mob and activated_by.player then
2020-03-12 01:35:11 +01:00
tt = tt .. " \n " .. S ( " Pushable by players and mobs " )
2020-02-19 04:54:17 +01:00
elseif activated_by.mob then
2020-03-12 01:35:11 +01:00
tt = tt .. " \n " .. S ( " Pushable by mobs " )
2020-02-19 04:54:17 +01:00
elseif activated_by.player then
2020-03-12 01:35:11 +01:00
tt = tt .. " \n " .. S ( " Pushable by players " )
2020-02-19 04:54:17 +01:00
end
2017-02-27 17:29:07 +01:00
2017-07-31 00:12:21 +02:00
mesecon.register_node ( basename , {
2015-06-29 19:55:56 +02:00
drawtype = " nodebox " ,
2017-07-31 00:12:21 +02:00
inventory_image = image_i ,
wield_image = image_w ,
2015-06-29 19:55:56 +02:00
paramtype = " light " ,
2017-09-11 18:40:34 +02:00
walkable = false ,
2021-05-23 11:01:29 +02:00
description = description ,
2015-06-29 19:55:56 +02:00
on_timer = pp_on_timer ,
2022-12-05 21:24:34 +01:00
on_rightclick = pp_on_rightclick ,
2015-06-29 19:55:56 +02:00
on_construct = function ( pos )
2017-01-11 18:21:46 +01:00
minetest.get_node_timer ( pos ) : start ( PRESSURE_PLATE_INTERVAL )
2015-06-29 19:55:56 +02:00
end ,
2017-07-31 00:12:21 +02:00
sounds = sounds ,
2018-01-31 19:36:27 +01:00
is_ground_content = false ,
2017-07-31 00:12:21 +02:00
pressureplate_basename = basename ,
2017-09-11 18:29:10 +02:00
pressureplate_activated_by = activated_by ,
2020-04-17 21:40:13 +02:00
_mcl_blast_resistance = 0.5 ,
2017-02-27 17:29:07 +01:00
_mcl_hardness = 0.5 ,
2017-07-31 00:12:21 +02:00
} , {
node_box = pp_box_off ,
selection_box = pp_box_off ,
groups = groups_off ,
tiles = textures_off ,
2017-02-27 17:29:07 +01:00
2018-01-12 01:37:32 +01:00
mesecons = { receptor = { state = mesecon.state . off , rules = mesecon.rules . pplate } } ,
2017-09-11 18:38:49 +02:00
_doc_items_longdesc = longdesc ,
2020-02-19 04:54:17 +01:00
_tt_help = tt ,
2017-07-31 00:12:21 +02:00
} , {
2015-06-29 19:55:56 +02:00
node_box = pp_box_on ,
2017-07-31 00:12:21 +02:00
selection_box = pp_box_on ,
2017-02-27 17:29:07 +01:00
groups = groups_on ,
2017-07-31 00:12:21 +02:00
tiles = textures_on ,
2019-12-09 22:32:40 +01:00
description = " " ,
2017-07-31 00:12:21 +02:00
2018-01-12 01:37:32 +01:00
mesecons = { receptor = { state = mesecon.state . on , rules = mesecon.rules . pplate } } ,
2017-09-11 18:38:49 +02:00
_doc_items_create_entry = false ,
2015-06-29 19:55:56 +02:00
} )
minetest.register_craft ( {
2017-07-31 00:12:21 +02:00
output = basename .. " _off " ,
2015-06-29 19:55:56 +02:00
recipe = recipe ,
} )
2017-03-21 04:27:50 +01:00
if minetest.get_modpath ( " doc " ) then
2017-07-31 00:12:21 +02:00
doc.add_entry_alias ( " nodes " , basename .. " _off " , " nodes " , basename .. " _on " )
2017-03-21 04:27:50 +01:00
end
2015-06-29 19:55:56 +02:00
end
2017-11-22 22:08:09 +01:00
local woods = {
2019-03-08 01:07:41 +01:00
{ " wood " , " mcl_core:wood " , " default_wood.png " , S ( " Oak Pressure Plate " ) } ,
{ " acaciawood " , " mcl_core:acaciawood " , " default_acacia_wood.png " , S ( " Acacia Pressure Plate " ) } ,
{ " birchwood " , " mcl_core:birchwood " , " mcl_core_planks_birch.png " , S ( " Birch Pressure Plate " ) } ,
{ " darkwood " , " mcl_core:darkwood " , " mcl_core_planks_big_oak.png " , S ( " Dark Oak Pressure Plate " ) } ,
{ " sprucewood " , " mcl_core:sprucewood " , " mcl_core_planks_spruce.png " , S ( " Spruce Pressure Plate " ) } ,
{ " junglewood " , " mcl_core:junglewood " , " default_junglewood.png " , S ( " Jungle Pressure Plate " ) } ,
2022-11-26 01:14:40 +01:00
{ " mangrove_wood " , " mcl_mangrove:mangrove_wood " , " mcl_mangrove_planks.png " , S ( " Mangrove Pressure Plate " ) } ,
2023-02-15 17:23:08 +01:00
{ " crimson_hyphae_wood " , " mcl_crimson:crimson_hyphae_wood " , " mcl_crimson_crimson_hyphae_wood.png " , S ( " Crimson Pressure Plate " ) } ,
2023-02-08 11:10:42 +01:00
{ " warped_hyphae_wood " , " mcl_crimson:warped_hyphae_wood " , " mcl_crimson_warped_hyphae_wood.png " , S ( " Warped Pressure Plate " ) } ,
2017-11-22 22:08:09 +01:00
}
2017-09-11 18:38:49 +02:00
2017-11-22 22:08:09 +01:00
for w = 1 , # woods do
mesecon.register_pressure_plate (
" mesecons_pressureplates:pressure_plate_ " .. woods [ w ] [ 1 ] ,
woods [ w ] [ 4 ] ,
{ woods [ w ] [ 3 ] } ,
{ woods [ w ] [ 3 ] } ,
woods [ w ] [ 3 ] ,
nil ,
{ { woods [ w ] [ 2 ] , woods [ w ] [ 2 ] } } ,
mcl_sounds.node_sound_wood_defaults ( ) ,
2017-11-22 22:42:00 +01:00
{ axey = 1 , material_wood = 1 } ,
2017-11-22 22:08:09 +01:00
nil ,
2019-03-08 01:07:41 +01:00
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. " ) )
2017-09-11 18:38:49 +02:00
2017-11-22 22:08:09 +01:00
minetest.register_craft ( {
type = " fuel " ,
recipe = " mesecons_pressureplates:pressure_plate_ " .. woods [ w ] [ 1 ] .. " _off " ,
burntime = 15
} )
end
2015-06-29 19:55:56 +02:00
2017-07-31 00:12:21 +02:00
mesecon.register_pressure_plate (
" mesecons_pressureplates:pressure_plate_stone " ,
2019-03-08 01:07:41 +01:00
S ( " Stone Pressure Plate " ) ,
2017-07-31 00:12:21 +02:00
{ " default_stone.png " } ,
{ " default_stone.png " } ,
2015-06-29 19:55:56 +02:00
" default_stone.png " ,
2017-07-31 00:12:21 +02:00
nil ,
2017-01-31 23:32:56 +01:00
{ { " mcl_core:stone " , " mcl_core:stone " } } ,
2017-02-27 17:29:07 +01:00
mcl_sounds.node_sound_stone_defaults ( ) ,
2017-11-22 22:42:00 +01:00
{ pickaxey = 1 , material_stone = 1 } ,
2017-09-11 18:38:49 +02:00
{ player = true , mob = true } ,
2019-03-08 01:07:41 +01:00
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. " ) )
2017-01-10 06:43:07 +01:00
2023-03-27 02:02:29 +02:00
mesecon.register_pressure_plate (
" mesecons_pressureplates:pressure_plate_polished_blackstone " ,
S ( " Polished Blackstone Pressure Plate " ) ,
{ " mcl_blackstone_polished.png " } ,
{ " mcl_blackstone_polished.png " } ,
" mcl_blackstone_polished.png " ,
nil ,
{ { " mcl_blackstone:blackstone_polished " , " mcl_blackstone:blackstone_polished " } } ,
mcl_sounds.node_sound_stone_defaults ( ) ,
{ pickaxey = 1 , material_stone = 1 } ,
{ player = true , mob = true } ,
S ( " A polished blackstone 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. " ) )
2017-03-21 04:27:50 +01:00