2021-05-29 17:12:33 +03:00
local S = minetest.get_translator ( minetest.get_current_modname ( ) )
2019-03-08 02:07:41 +02:00
2018-01-12 02:37:32 +02:00
local lever_get_output_rules = mesecon.rules . buttonlike_get
2018-01-08 18:45:30 +02:00
2021-05-29 17:12:33 +03:00
local function on_rotate ( pos , node , user , mode )
2019-12-09 19:49:59 +02:00
if mode == screwdriver.ROTATE_FACE then
if node.param2 == 10 then
node.param2 = 13
minetest.swap_node ( pos , node )
return true
elseif node.param2 == 13 then
node.param2 = 10
minetest.swap_node ( pos , node )
return true
elseif node.param2 == 8 then
node.param2 = 15
minetest.swap_node ( pos , node )
return true
elseif node.param2 == 15 then
node.param2 = 8
minetest.swap_node ( pos , node )
return true
end
end
-- TODO: Rotate axis
return false
end
2018-01-08 18:45:30 +02:00
-- LEVER
2015-06-29 20:55:56 +03:00
minetest.register_node ( " mesecons_walllever:wall_lever_off " , {
2017-07-31 06:35:55 +03:00
drawtype = " mesh " ,
2015-06-29 20:55:56 +03:00
tiles = {
2017-07-31 06:35:55 +03:00
" jeija_wall_lever_lever_light_on.png " ,
2015-06-29 20:55:56 +03:00
} ,
2021-02-18 15:00:17 +02:00
use_texture_alpha = minetest.features . use_texture_alpha_string_modes and " opaque " or false ,
2015-06-29 20:55:56 +03:00
inventory_image = " jeija_wall_lever.png " ,
wield_image = " jeija_wall_lever.png " ,
paramtype = " light " ,
paramtype2 = " facedir " ,
2017-07-31 06:35:55 +03:00
mesh = " jeija_wall_lever_off.obj " ,
2015-06-29 20:55:56 +03:00
sunlight_propagates = true ,
walkable = false ,
selection_box = {
type = " fixed " ,
2018-01-08 21:11:33 +02:00
fixed = { - 3 / 16 , - 4 / 16 , 2 / 16 , 3 / 16 , 4 / 16 , 8 / 16 } ,
2015-06-29 20:55:56 +03:00
} ,
2018-01-08 21:11:33 +02:00
groups = { handy = 1 , dig_by_water = 1 , destroy_by_lava_flow = 1 , dig_by_piston = 1 , attached_node_facedir = 1 } ,
2017-01-04 23:36:51 +02:00
is_ground_content = false ,
2019-03-08 02:07:41 +02:00
description = S ( " Lever " ) ,
2020-03-12 02:35:11 +02:00
_tt_help = S ( " Provides redstone power while it's turned on " ) ,
2019-03-08 02:07:41 +02:00
_doc_items_longdesc = S ( " A lever is a redstone component which can be flipped on and off. It supplies redstone power to adjacent blocks while it is in the “on” state. " ) ,
2019-03-16 03:00:48 +02:00
_doc_items_usagehelp = S ( " Use the lever to flip it on or off. " ) ,
2021-05-29 17:12:33 +03:00
on_rightclick = function ( pos , node )
2017-07-31 01:12:21 +03:00
minetest.swap_node ( pos , { name = " mesecons_walllever:wall_lever_on " , param2 = node.param2 } )
2018-01-08 22:00:36 +02:00
mesecon.receptor_on ( pos , lever_get_output_rules ( node ) )
2020-12-07 05:59:10 +02:00
minetest.sound_play ( " mesecons_button_push " , { pos = pos , max_hear_distance = 16 } , true )
2015-06-29 20:55:56 +03:00
end ,
2018-01-08 18:45:30 +02:00
node_placement_prediction = " " ,
on_place = function ( itemstack , placer , pointed_thing )
if pointed_thing.type ~= " node " then
-- no interaction possible with entities
return itemstack
end
local under = pointed_thing.under
local node = minetest.get_node ( under )
local def = minetest.registered_nodes [ node.name ]
if not def then return end
local groups = def.groups
-- Check special rightclick action of pointed node
if def and def.on_rightclick then
if not placer : get_player_control ( ) . sneak then
return def.on_rightclick ( under , node , placer , itemstack ,
pointed_thing ) or itemstack , false
end
end
-- If the pointed node is buildable, let's look at the node *behind* that node
if def.buildable_to then
local dir = vector.subtract ( pointed_thing.above , pointed_thing.under )
local actual = vector.subtract ( under , dir )
local actualnode = minetest.get_node ( actual )
def = minetest.registered_nodes [ actualnode.name ]
groups = def.groups
end
-- Only allow placement on full-cube solid opaque nodes
if ( not groups ) or ( not groups.solid ) or ( not groups.opaque ) or ( def.node_box and def.node_box . type ~= " regular " ) then
return itemstack
end
local above = pointed_thing.above
2018-01-08 21:11:33 +02:00
local dir = vector.subtract ( under , above )
2018-01-08 18:45:30 +02:00
local tau = math.pi * 2
2018-01-08 21:11:33 +02:00
local wdir = minetest.dir_to_facedir ( dir , true )
if dir.y ~= 0 then
2018-01-08 18:45:30 +02:00
local yaw = placer : get_look_horizontal ( )
if ( yaw > tau / 8 and yaw < ( tau / 8 ) * 3 ) or ( yaw < ( tau / 8 ) * 7 and yaw > ( tau / 8 ) * 5 ) then
if dir.y == - 1 then
2018-01-08 21:11:33 +02:00
wdir = 13
2018-01-08 18:45:30 +02:00
else
2018-01-08 21:11:33 +02:00
wdir = 15
2018-01-08 18:45:30 +02:00
end
else
if dir.y == - 1 then
2018-01-08 21:11:33 +02:00
wdir = 10
2018-01-08 18:45:30 +02:00
else
2018-01-08 21:11:33 +02:00
wdir = 8
2018-01-08 18:45:30 +02:00
end
end
end
local idef = itemstack : get_definition ( )
local itemstack , success = minetest.item_place_node ( itemstack , placer , pointed_thing , wdir )
if success then
if idef.sounds and idef.sounds . place then
2020-04-07 01:55:45 +03:00
minetest.sound_play ( idef.sounds . place , { pos = above , gain = 1 } , true )
2018-01-08 18:45:30 +02:00
end
end
return itemstack
end ,
2017-07-31 06:35:55 +03:00
sounds = mcl_sounds.node_sound_stone_defaults ( ) ,
2015-06-29 20:55:56 +03:00
mesecons = { receptor = {
2018-01-08 18:45:30 +02:00
rules = lever_get_output_rules ,
2015-06-29 20:55:56 +03:00
state = mesecon.state . off
2017-02-22 17:22:28 +02:00
} } ,
2019-12-09 19:49:59 +02:00
on_rotate = on_rotate ,
2020-04-17 22:40:13 +03:00
_mcl_blast_resistance = 0.5 ,
2017-02-27 18:20:51 +02:00
_mcl_hardness = 0.5 ,
2015-06-29 20:55:56 +03:00
} )
minetest.register_node ( " mesecons_walllever:wall_lever_on " , {
2017-07-31 06:35:55 +03:00
drawtype = " mesh " ,
2015-06-29 20:55:56 +03:00
tiles = {
2017-07-31 06:35:55 +03:00
" jeija_wall_lever_lever_light_on.png " ,
2015-06-29 20:55:56 +03:00
} ,
2021-02-18 15:00:17 +02:00
use_texture_alpha = minetest.features . use_texture_alpha_string_modes and " opaque " or false ,
2015-06-29 20:55:56 +03:00
paramtype = " light " ,
paramtype2 = " facedir " ,
2017-07-31 06:35:55 +03:00
mesh = " jeija_wall_lever_on.obj " ,
2015-06-29 20:55:56 +03:00
sunlight_propagates = true ,
walkable = false ,
selection_box = {
type = " fixed " ,
2018-01-08 21:11:33 +02:00
f ixed = { - 3 / 16 , - 4 / 16 , 2 / 16 , 3 / 16 , 4 / 16 , 8 / 16 } ,
2015-06-29 20:55:56 +03:00
} ,
2018-01-08 21:11:33 +02:00
groups = { handy = 1 , not_in_creative_inventory = 1 , dig_by_water = 1 , destroy_by_lava_flow = 1 , dig_by_piston = 1 , attached_node_facedir = 1 } ,
2017-01-04 23:36:51 +02:00
is_ground_content = false ,
2021-05-29 17:12:33 +03:00
drop = " mesecons_walllever:wall_lever_off " ,
2017-03-11 04:56:29 +02:00
_doc_items_create_entry = false ,
2021-05-29 17:12:33 +03:00
on_rightclick = function ( pos , node )
2017-07-31 01:12:21 +03:00
minetest.swap_node ( pos , { name = " mesecons_walllever:wall_lever_off " , param2 = node.param2 } )
2018-01-08 22:00:36 +02:00
mesecon.receptor_off ( pos , lever_get_output_rules ( node ) )
2020-12-07 05:59:10 +02:00
minetest.sound_play ( " mesecons_button_push " , { pos = pos , max_hear_distance = 16 , pitch = 0.9 } , true )
2015-06-29 20:55:56 +03:00
end ,
2017-07-31 06:35:55 +03:00
sounds = mcl_sounds.node_sound_stone_defaults ( ) ,
2015-06-29 20:55:56 +03:00
mesecons = { receptor = {
2018-01-08 18:45:30 +02:00
rules = lever_get_output_rules ,
2015-06-29 20:55:56 +03:00
state = mesecon.state . on
2017-02-22 17:22:28 +02:00
} } ,
2019-12-09 19:49:59 +02:00
on_rotate = on_rotate ,
2020-04-17 22:40:13 +03:00
_mcl_blast_resistance = 0.5 ,
2017-02-27 18:20:51 +02:00
_mcl_hardness = 0.5 ,
2015-06-29 20:55:56 +03:00
} )
minetest.register_craft ( {
2021-05-29 17:12:33 +03:00
output = " mesecons_walllever:wall_lever_off " ,
2015-06-29 20:55:56 +03:00
recipe = {
2021-05-29 17:12:33 +03:00
{ " mcl_core:stick " } ,
{ " mcl_core:cobble " } ,
2015-06-29 20:55:56 +03:00
}
} )
2017-03-21 05:27:50 +02:00
if minetest.get_modpath ( " doc " ) then
doc.add_entry_alias ( " nodes " , " mesecons_walllever:wall_lever_off " , " nodes " , " mesecons_walllever:wall_lever_on " )
end