2017-07-31 00:12:21 +02:00
local PISTON_MAXIMUM_PUSH = 12
2015-06-29 19:55:56 +02:00
-- Get mesecon rules of pistons
piston_rules =
{ { x = 0 , y = 0 , z = 1 } , --everything apart from z- (pusher side)
{ x = 1 , y = 0 , z = 0 } ,
{ x =- 1 , y = 0 , z = 0 } ,
2017-09-14 02:20:47 +02:00
{ x = 0 , y = 1 , z = 0 } ,
{ x = 0 , y =- 1 , z = 0 } }
2015-06-29 19:55:56 +02:00
local piston_up_rules =
{ { x = 0 , y = 0 , z =- 1 } , --everything apart from y+ (pusher side)
{ x = 0 , y = 0 , z = 1 } ,
2017-09-14 02:20:47 +02:00
{ x =- 1 , y = 0 , z = 0 } ,
2017-12-29 02:28:18 +01:00
{ x = 1 , y = 0 , z = 0 } ,
2017-09-14 02:20:47 +02:00
{ x = 0 , y =- 1 , z = 0 } }
2015-06-29 19:55:56 +02:00
local piston_down_rules =
{ { x = 0 , y = 0 , z =- 1 } , --everything apart from y- (pusher side)
{ x = 0 , y = 0 , z = 1 } ,
2017-09-14 02:20:47 +02:00
{ x =- 1 , y = 0 , z = 0 } ,
2017-12-29 02:28:18 +01:00
{ x = 1 , y = 0 , z = 0 } ,
2017-09-14 02:20:47 +02:00
{ x = 0 , y = 1 , z = 0 } }
2015-06-29 19:55:56 +02:00
local piston_get_rules = function ( node )
local rules = piston_rules
for i = 1 , node.param2 do
2017-07-31 00:12:21 +02:00
rules = mesecon.rotate_rules_left ( rules )
2015-06-29 19:55:56 +02:00
end
return rules
end
piston_facedir_direction = function ( node )
local rules = { { x = 0 , y = 0 , z = - 1 } }
for i = 1 , node.param2 do
2017-07-31 00:12:21 +02:00
rules = mesecon.rotate_rules_left ( rules )
2015-06-29 19:55:56 +02:00
end
return rules [ 1 ]
end
piston_get_direction = function ( dir , node )
if type ( dir ) == " function " then
return dir ( node )
else
return dir
end
end
2017-11-23 21:15:42 +01:00
-- Remove pusher of piston.
-- To be used when piston was destroyed or dug.
2017-11-23 20:52:33 +01:00
local piston_remove_pusher = function ( pos , oldnode )
local pistonspec = minetest.registered_nodes [ oldnode.name ] . mesecons_piston
2015-06-29 19:55:56 +02:00
2017-11-23 20:52:33 +01:00
local dir = piston_get_direction ( pistonspec.dir , oldnode )
2017-07-31 00:12:21 +02:00
local pusherpos = vector.add ( pos , dir )
2017-01-11 18:21:46 +01:00
local pushername = minetest.get_node ( pusherpos ) . name
2015-06-29 19:55:56 +02:00
2017-11-23 21:15:42 +01:00
if pushername == pistonspec.pusher then -- make sure there actually is a pusher
2017-01-11 18:21:46 +01:00
minetest.remove_node ( pusherpos )
2017-01-26 19:14:07 +01:00
core.check_for_falling ( pusherpos )
2017-02-19 20:48:56 +01:00
minetest.sound_play ( " piston_retract " , {
pos = pos ,
max_hear_distance = 20 ,
gain = 0.3 ,
} )
2015-06-29 19:55:56 +02:00
end
end
2017-11-23 21:15:42 +01:00
-- Remove base node of piston.
-- To be used when pusher was destroyed.
local piston_remove_base = function ( pos , oldnode )
local basenodename = minetest.registered_nodes [ oldnode.name ] . corresponding_piston
local pistonspec = minetest.registered_nodes [ basenodename ] . mesecons_piston
local dir = piston_get_direction ( pistonspec.dir , oldnode )
local basepos = vector.subtract ( pos , dir )
local basename = minetest.get_node ( basepos ) . name
if basename == pistonspec.onname then -- make sure there actually is a base node
minetest.remove_node ( basepos )
core.check_for_falling ( basepos )
minetest.sound_play ( " piston_retract " , {
pos = pos ,
max_hear_distance = 20 ,
gain = 0.3 ,
} )
end
end
2015-06-29 19:55:56 +02:00
local piston_on = function ( pos , node )
local pistonspec = minetest.registered_nodes [ node.name ] . mesecons_piston
2017-07-31 00:38:50 +02:00
local dir = piston_get_direction ( pistonspec.dir , node )
2017-07-31 00:12:21 +02:00
local np = vector.add ( pos , dir )
2017-07-31 00:38:50 +02:00
local success , stack , oldstack = mesecon.mvps_push ( np , dir , PISTON_MAXIMUM_PUSH )
2015-06-29 19:55:56 +02:00
if success then
2017-01-11 18:21:46 +01:00
minetest.add_node ( pos , { param2 = node.param2 , name = pistonspec.onname } )
minetest.add_node ( np , { param2 = node.param2 , name = pistonspec.pusher } )
2017-05-14 21:24:17 +02:00
local below = minetest.get_node ( { x = np.x , y = np.y - 1 , z = np.z } )
if below.name == " mcl_farming:soil " or below.name == " mcl_farming:soil_wet " then
minetest.set_node ( { x = np.x , y = np.y - 1 , z = np.z } , { name = " mcl_core:dirt " } )
end
2017-07-31 00:12:21 +02:00
mesecon.mvps_process_stack ( stack )
2017-07-31 00:38:50 +02:00
mesecon.mvps_move_objects ( np , dir , oldstack )
2017-02-19 20:48:56 +01:00
minetest.sound_play ( " piston_extend " , {
pos = pos ,
max_hear_distance = 20 ,
gain = 0.3 ,
} )
2015-06-29 19:55:56 +02:00
end
end
local piston_off = function ( pos , node )
local pistonspec = minetest.registered_nodes [ node.name ] . mesecons_piston
2017-01-11 18:21:46 +01:00
minetest.add_node ( pos , { param2 = node.param2 , name = pistonspec.offname } )
2015-06-29 19:55:56 +02:00
piston_remove_pusher ( pos , node )
if pistonspec.sticky then
2017-07-31 00:38:50 +02:00
local dir = piston_get_direction ( pistonspec.dir , node )
local pullpos = vector.add ( pos , vector.multiply ( dir , 2 ) )
local stack = mesecon.mvps_pull_single ( pullpos , vector.multiply ( dir , - 1 ) , PISTON_MAXIMUM_PUSH )
mesecon.mvps_process_stack ( pos , dir , stack )
2015-06-29 19:55:56 +02:00
end
end
local piston_orientate = function ( pos , placer )
-- not placed by player
if not placer then return end
-- placer pitch in degrees
local pitch = placer : get_look_pitch ( ) * ( 180 / math.pi )
2017-01-11 18:21:46 +01:00
local node = minetest.get_node ( pos )
2015-06-29 19:55:56 +02:00
local pistonspec = minetest.registered_nodes [ node.name ] . mesecons_piston
if pitch > 55 then --looking upwards
2017-01-11 18:21:46 +01:00
minetest.add_node ( pos , { name = pistonspec.piston_down } )
2015-06-29 19:55:56 +02:00
elseif pitch < - 55 then --looking downwards
2017-01-11 18:21:46 +01:00
minetest.add_node ( pos , { name = pistonspec.piston_up } )
2015-06-29 19:55:56 +02:00
end
end
-- Horizontal pistons
2017-02-22 17:13:36 +01:00
local pt = 4 / 16 -- pusher thickness
2015-06-29 19:55:56 +02:00
local piston_pusher_box = {
type = " fixed " ,
fixed = {
{ - 2 / 16 , - 2 / 16 , - .5 + pt , 2 / 16 , 2 / 16 , .5 + pt } ,
{ - .5 , - .5 , - .5 , .5 , .5 , - .5 + pt } ,
}
}
local piston_on_box = {
type = " fixed " ,
fixed = {
{ - .5 , - .5 , - .5 + pt , .5 , .5 , .5 }
}
}
-- Normal (non-sticky) ones:
local pistonspec_normal = {
offname = " mesecons_pistons:piston_normal_off " ,
onname = " mesecons_pistons:piston_normal_on " ,
dir = piston_facedir_direction ,
pusher = " mesecons_pistons:piston_pusher_normal " ,
piston_down = " mesecons_pistons:piston_down_normal_off " ,
piston_up = " mesecons_pistons:piston_up_normal_off " ,
}
2017-03-11 04:14:28 +01:00
local usagehelp_piston = " This block can have one of 6 possible orientations. On placement, the pusher will face you. "
2017-03-11 04:12:55 +01:00
2017-12-05 14:09:39 +01:00
local on_rotate
if minetest.get_modpath ( " screwdriver " ) then
on_rotate = screwdriver.disallow
end
2015-06-29 19:55:56 +02:00
-- offstate
minetest.register_node ( " mesecons_pistons:piston_normal_off " , {
description = " Piston " ,
2017-03-11 04:12:55 +01:00
_doc_items_longdesc = " A piston is a redstone component with a pusher which pushes the block or blocks in front of it when it is supplied with redstone power. Not all blocks can be pushed, however. " ,
_doc_items_usagehelp = usagehelp_piston ,
2015-06-29 19:55:56 +02:00
tiles = {
2017-07-17 17:29:53 +02:00
" mesecons_piston_bottom.png^[transformR180 " ,
" mesecons_piston_bottom.png " ,
" mesecons_piston_bottom.png^[transformR90 " ,
" mesecons_piston_bottom.png^[transformR270 " ,
" mesecons_piston_back.png " ,
2015-06-29 19:55:56 +02:00
" mesecons_piston_pusher_front.png "
} ,
2017-02-27 17:20:51 +01:00
groups = { handy = 1 } ,
2017-06-13 14:26:50 +02:00
paramtype = " light " ,
sunlight_propagates = true ,
2015-06-29 19:55:56 +02:00
paramtype2 = " facedir " ,
2017-01-04 22:36:51 +01:00
is_ground_content = false ,
2015-06-29 19:55:56 +02:00
after_place_node = piston_orientate ,
mesecons_piston = pistonspec_normal ,
2017-02-22 17:07:24 +01:00
sounds = mcl_sounds.node_sound_stone_defaults ( ) ,
2015-06-29 19:55:56 +02:00
mesecons = { effector = {
action_on = piston_on ,
rules = piston_get_rules
2017-02-22 16:22:28 +01:00
} } ,
_mcl_blast_resistance = 2.5 ,
2017-02-27 17:20:51 +01:00
_mcl_hardness = 0.5 ,
2017-12-05 14:09:39 +01:00
on_rotate = on_rotate ,
2015-06-29 19:55:56 +02:00
} )
-- onstate
minetest.register_node ( " mesecons_pistons:piston_normal_on " , {
drawtype = " nodebox " ,
tiles = {
2017-07-17 17:29:53 +02:00
" mesecons_piston_bottom.png^[transformR180 " ,
" mesecons_piston_bottom.png " ,
" mesecons_piston_bottom.png^[transformR90 " ,
" mesecons_piston_bottom.png^[transformR270 " ,
" mesecons_piston_back.png " ,
2015-06-29 19:55:56 +02:00
" mesecons_piston_on_front.png "
} ,
2017-02-27 17:20:51 +01:00
groups = { handy = 1 , not_in_creative_inventory = 1 } ,
2015-06-29 19:55:56 +02:00
paramtype = " light " ,
2017-06-13 14:26:50 +02:00
sunlight_propagates = true ,
2015-06-29 19:55:56 +02:00
paramtype2 = " facedir " ,
2017-01-04 22:36:51 +01:00
is_ground_content = false ,
2015-06-29 19:55:56 +02:00
drop = " mesecons_pistons:piston_normal_off " ,
2017-11-23 20:52:33 +01:00
after_destruct = piston_remove_pusher ,
2015-06-29 19:55:56 +02:00
node_box = piston_on_box ,
selection_box = piston_on_box ,
mesecons_piston = pistonspec_normal ,
2017-02-22 17:07:24 +01:00
sounds = mcl_sounds.node_sound_stone_defaults ( ) ,
2015-06-29 19:55:56 +02:00
mesecons = { effector = {
action_off = piston_off ,
rules = piston_get_rules
2017-02-22 16:22:28 +01:00
} } ,
_mcl_blast_resistance = 2.5 ,
2017-02-27 17:20:51 +01:00
_mcl_hardness = 0.5 ,
2017-12-05 14:09:39 +01:00
on_rotate = on_rotate ,
2015-06-29 19:55:56 +02:00
} )
-- pusher
minetest.register_node ( " mesecons_pistons:piston_pusher_normal " , {
drawtype = " nodebox " ,
tiles = {
" mesecons_piston_pusher_top.png " ,
" mesecons_piston_pusher_bottom.png " ,
" mesecons_piston_pusher_left.png " ,
" mesecons_piston_pusher_right.png " ,
" mesecons_piston_pusher_back.png " ,
" mesecons_piston_pusher_front.png "
} ,
paramtype = " light " ,
2017-06-13 14:26:50 +02:00
sunlight_propagates = true ,
2015-06-29 19:55:56 +02:00
paramtype2 = " facedir " ,
2017-01-04 22:36:51 +01:00
is_ground_content = false ,
2017-11-23 21:15:42 +01:00
after_destruct = piston_remove_base ,
2015-06-29 19:55:56 +02:00
diggable = false ,
corresponding_piston = " mesecons_pistons:piston_normal_on " ,
selection_box = piston_pusher_box ,
node_box = piston_pusher_box ,
2017-02-17 01:56:52 +01:00
sounds = mcl_sounds.node_sound_wood_defaults ( ) ,
2017-02-22 16:22:28 +01:00
_mcl_blast_resistance = 2.5 ,
2017-12-05 14:09:39 +01:00
on_rotate = on_rotate ,
2015-06-29 19:55:56 +02:00
} )
-- Sticky ones
local pistonspec_sticky = {
offname = " mesecons_pistons:piston_sticky_off " ,
onname = " mesecons_pistons:piston_sticky_on " ,
dir = piston_facedir_direction ,
pusher = " mesecons_pistons:piston_pusher_sticky " ,
sticky = true ,
piston_down = " mesecons_pistons:piston_down_sticky_off " ,
piston_up = " mesecons_pistons:piston_up_sticky_off " ,
}
-- offstate
minetest.register_node ( " mesecons_pistons:piston_sticky_off " , {
description = " Sticky Piston " ,
2017-03-11 04:12:55 +01:00
_doc_items_longdesc = " A sticky piston is a redstone component with a sticky pusher which can be extended and retracted. It extends when it is supplied with redstone power. When the pusher extends, it pushes the block or blocks in front of it. When it retracts, it pulls back the single block in front of it. Note that not all blocks can be pushed or pulled. " ,
_doc_items_usagehelp = usagehelp_piston ,
2015-06-29 19:55:56 +02:00
tiles = {
2017-07-17 17:29:53 +02:00
" mesecons_piston_bottom.png^[transformR180 " ,
" mesecons_piston_bottom.png " ,
" mesecons_piston_bottom.png^[transformR90 " ,
" mesecons_piston_bottom.png^[transformR270 " ,
" mesecons_piston_back.png " ,
2015-06-29 19:55:56 +02:00
" mesecons_piston_pusher_front_sticky.png "
} ,
2017-02-27 17:20:51 +01:00
groups = { handy = 1 } ,
2017-06-13 14:26:50 +02:00
paramtype = " light " ,
sunlight_propagates = true ,
2015-06-29 19:55:56 +02:00
paramtype2 = " facedir " ,
2017-01-04 22:36:51 +01:00
is_ground_content = false ,
2015-06-29 19:55:56 +02:00
after_place_node = piston_orientate ,
mesecons_piston = pistonspec_sticky ,
2017-02-22 17:07:24 +01:00
sounds = mcl_sounds.node_sound_stone_defaults ( ) ,
2015-06-29 19:55:56 +02:00
mesecons = { effector = {
action_on = piston_on ,
rules = piston_get_rules
2017-02-22 16:22:28 +01:00
} } ,
_mcl_blast_resistance = 2.5 ,
2017-02-27 17:20:51 +01:00
_mcl_hardness = 0.5 ,
2017-12-05 14:09:39 +01:00
on_rotate = on_rotate ,
2015-06-29 19:55:56 +02:00
} )
-- onstate
minetest.register_node ( " mesecons_pistons:piston_sticky_on " , {
drawtype = " nodebox " ,
tiles = {
2017-07-17 17:29:53 +02:00
" mesecons_piston_bottom.png^[transformR180 " ,
" mesecons_piston_bottom.png " ,
" mesecons_piston_bottom.png^[transformR90 " ,
" mesecons_piston_bottom.png^[transformR270 " ,
" mesecons_piston_back.png " ,
2015-06-29 19:55:56 +02:00
" mesecons_piston_on_front.png "
} ,
2017-02-27 17:20:51 +01:00
groups = { handy = 1 , not_in_creative_inventory = 1 } ,
2015-06-29 19:55:56 +02:00
paramtype = " light " ,
2017-06-13 14:26:50 +02:00
sunlight_propagates = true ,
2015-06-29 19:55:56 +02:00
paramtype2 = " facedir " ,
2017-01-04 22:36:51 +01:00
is_ground_content = false ,
2017-03-15 20:54:33 +01:00
drop = " mesecons_pistons:piston_sticky_off " ,
2017-11-23 20:52:33 +01:00
after_destruct = piston_remove_pusher ,
2015-06-29 19:55:56 +02:00
node_box = piston_on_box ,
selection_box = piston_on_box ,
mesecons_piston = pistonspec_sticky ,
2017-02-22 17:07:24 +01:00
sounds = mcl_sounds.node_sound_stone_defaults ( ) ,
2015-06-29 19:55:56 +02:00
mesecons = { effector = {
action_off = piston_off ,
rules = piston_get_rules
2017-02-22 16:22:28 +01:00
} } ,
_mcl_blast_resistance = 2.5 ,
2017-02-27 17:20:51 +01:00
_mcl_hardness = 0.5 ,
2017-12-05 14:09:39 +01:00
on_rotate = on_rotate ,
2015-06-29 19:55:56 +02:00
} )
-- pusher
minetest.register_node ( " mesecons_pistons:piston_pusher_sticky " , {
drawtype = " nodebox " ,
tiles = {
" mesecons_piston_pusher_top.png " ,
" mesecons_piston_pusher_bottom.png " ,
" mesecons_piston_pusher_left.png " ,
" mesecons_piston_pusher_right.png " ,
" mesecons_piston_pusher_back.png " ,
" mesecons_piston_pusher_front_sticky.png "
} ,
paramtype = " light " ,
2017-06-13 14:26:50 +02:00
sunlight_propagates = true ,
2015-06-29 19:55:56 +02:00
paramtype2 = " facedir " ,
2017-01-04 22:36:51 +01:00
is_ground_content = false ,
2017-11-23 21:15:42 +01:00
after_destruct = piston_remove_base ,
2015-06-29 19:55:56 +02:00
diggable = false ,
corresponding_piston = " mesecons_pistons:piston_sticky_on " ,
selection_box = piston_pusher_box ,
node_box = piston_pusher_box ,
2017-02-17 01:56:52 +01:00
sounds = mcl_sounds.node_sound_wood_defaults ( ) ,
2017-02-22 16:22:28 +01:00
_mcl_blast_resistance = 2.5 ,
2017-12-05 14:09:39 +01:00
on_rotate = on_rotate ,
2015-06-29 19:55:56 +02:00
} )
--
--
-- UP
--
--
local piston_up_pusher_box = {
type = " fixed " ,
fixed = {
{ - 2 / 16 , - .5 - pt , - 2 / 16 , 2 / 16 , .5 - pt , 2 / 16 } ,
{ - .5 , .5 - pt , - .5 , .5 , .5 , .5 } ,
}
}
local piston_up_on_box = {
type = " fixed " ,
fixed = {
{ - .5 , - .5 , - .5 , .5 , .5 - pt , .5 }
}
}
-- Normal
local pistonspec_normal_up = {
offname = " mesecons_pistons:piston_up_normal_off " ,
onname = " mesecons_pistons:piston_up_normal_on " ,
dir = { x = 0 , y = 1 , z = 0 } ,
pusher = " mesecons_pistons:piston_up_pusher_normal "
}
-- offstate
minetest.register_node ( " mesecons_pistons:piston_up_normal_off " , {
tiles = {
" mesecons_piston_pusher_front.png " ,
2017-07-17 17:29:53 +02:00
" mesecons_piston_back.png " ,
" mesecons_piston_bottom.png " ,
" mesecons_piston_bottom.png " ,
" mesecons_piston_bottom.png " ,
" mesecons_piston_bottom.png " ,
2015-06-29 19:55:56 +02:00
} ,
2017-02-27 17:20:51 +01:00
groups = { handy = 1 , not_in_creative_inventory = 1 } ,
2017-06-13 14:26:50 +02:00
paramtype = " light " ,
sunlight_propagates = true ,
2015-06-29 19:55:56 +02:00
paramtype2 = " facedir " ,
2017-01-04 22:36:51 +01:00
is_ground_content = false ,
2015-06-29 19:55:56 +02:00
drop = " mesecons_pistons:piston_normal_off " ,
mesecons_piston = pistonspec_normal_up ,
mesecons = { effector = {
action_on = piston_on ,
rules = piston_up_rules ,
2017-02-17 01:56:52 +01:00
} } ,
sounds = mcl_sounds.node_sound_wood_defaults ( ) ,
2017-02-22 16:22:28 +01:00
_mcl_blast_resistance = 2.5 ,
2017-02-27 17:20:51 +01:00
_mcl_hardness = 0.5 ,
2017-12-05 14:09:39 +01:00
on_rotate = on_rotate ,
2015-06-29 19:55:56 +02:00
} )
-- onstate
minetest.register_node ( " mesecons_pistons:piston_up_normal_on " , {
drawtype = " nodebox " ,
tiles = {
" mesecons_piston_on_front.png " ,
2017-07-17 17:29:53 +02:00
" mesecons_piston_back.png " ,
" mesecons_piston_bottom.png " ,
" mesecons_piston_bottom.png " ,
" mesecons_piston_bottom.png " ,
" mesecons_piston_bottom.png " ,
2015-06-29 19:55:56 +02:00
} ,
2017-02-27 17:20:51 +01:00
groups = { hanry = 1 , not_in_creative_inventory = 1 } ,
2015-06-29 19:55:56 +02:00
paramtype = " light " ,
2017-06-13 14:26:50 +02:00
sunlight_propagates = true ,
2015-06-29 19:55:56 +02:00
paramtype2 = " facedir " ,
2017-01-04 22:36:51 +01:00
is_ground_content = false ,
2015-06-29 19:55:56 +02:00
drop = " mesecons_pistons:piston_normal_off " ,
2017-11-23 20:52:33 +01:00
after_destruct = piston_remove_pusher ,
2015-06-29 19:55:56 +02:00
node_box = piston_up_on_box ,
selection_box = piston_up_on_box ,
mesecons_piston = pistonspec_normal_up ,
2017-02-11 18:46:23 +01:00
sounds = mcl_sounds.node_sound_wood_defaults ( ) ,
2015-06-29 19:55:56 +02:00
mesecons = { effector = {
action_off = piston_off ,
rules = piston_up_rules ,
2017-02-22 16:22:28 +01:00
} } ,
_mcl_blast_resistance = 2.5 ,
2017-02-27 17:20:51 +01:00
_mcl_hardness = 0.5 ,
2017-12-05 14:09:39 +01:00
on_rotate = on_rotate ,
2015-06-29 19:55:56 +02:00
} )
-- pusher
minetest.register_node ( " mesecons_pistons:piston_up_pusher_normal " , {
drawtype = " nodebox " ,
tiles = {
" mesecons_piston_pusher_front.png " ,
" mesecons_piston_pusher_back.png " ,
" mesecons_piston_pusher_left.png^[transformR270 " ,
" mesecons_piston_pusher_right.png^[transformR90 " ,
" mesecons_piston_pusher_bottom.png " ,
" mesecons_piston_pusher_top.png^[transformR180 " ,
} ,
paramtype = " light " ,
2017-06-13 14:26:50 +02:00
sunlight_propagates = true ,
2015-06-29 19:55:56 +02:00
paramtype2 = " facedir " ,
2017-01-04 22:36:51 +01:00
is_ground_content = false ,
2017-11-23 21:15:42 +01:00
after_destruct = piston_remove_base ,
2015-06-29 19:55:56 +02:00
diggable = false ,
corresponding_piston = " mesecons_pistons:piston_up_normal_on " ,
selection_box = piston_up_pusher_box ,
node_box = piston_up_pusher_box ,
2017-02-17 01:56:52 +01:00
sounds = mcl_sounds.node_sound_wood_defaults ( ) ,
2017-02-22 16:22:28 +01:00
_mcl_blast_resistance = 2.5 ,
2017-12-05 14:09:39 +01:00
on_rotate = on_rotate ,
2015-06-29 19:55:56 +02:00
} )
-- Sticky
local pistonspec_sticky_up = {
offname = " mesecons_pistons:piston_up_sticky_off " ,
onname = " mesecons_pistons:piston_up_sticky_on " ,
dir = { x = 0 , y = 1 , z = 0 } ,
pusher = " mesecons_pistons:piston_up_pusher_sticky " ,
sticky = true
}
-- offstate
minetest.register_node ( " mesecons_pistons:piston_up_sticky_off " , {
tiles = {
" mesecons_piston_pusher_front_sticky.png " ,
2017-07-17 17:29:53 +02:00
" mesecons_piston_back.png " ,
" mesecons_piston_bottom.png " ,
" mesecons_piston_bottom.png " ,
" mesecons_piston_bottom.png " ,
" mesecons_piston_bottom.png " ,
2015-06-29 19:55:56 +02:00
} ,
2017-02-27 17:20:51 +01:00
groups = { handy = 1 , not_in_creative_inventory = 1 } ,
2017-06-13 14:26:50 +02:00
paramtype = " light " ,
sunlight_propagates = true ,
2015-06-29 19:55:56 +02:00
paramtype2 = " facedir " ,
2017-01-04 22:36:51 +01:00
is_ground_content = false ,
2015-06-29 19:55:56 +02:00
drop = " mesecons_pistons:piston_sticky_off " ,
mesecons_piston = pistonspec_sticky_up ,
2017-02-11 18:46:23 +01:00
sounds = mcl_sounds.node_sound_wood_defaults ( ) ,
2015-06-29 19:55:56 +02:00
mesecons = { effector = {
action_on = piston_on ,
rules = piston_up_rules ,
2017-02-22 16:22:28 +01:00
} } ,
_mcl_blast_resistance = 2.5 ,
2017-02-27 17:20:51 +01:00
_mcl_hardness = 0.5 ,
2017-12-05 14:09:39 +01:00
on_rotate = on_rotate ,
2015-06-29 19:55:56 +02:00
} )
-- onstate
minetest.register_node ( " mesecons_pistons:piston_up_sticky_on " , {
drawtype = " nodebox " ,
tiles = {
" mesecons_piston_on_front.png " ,
2017-07-17 17:29:53 +02:00
" mesecons_piston_back.png " ,
" mesecons_piston_bottom.png " ,
" mesecons_piston_bottom.png " ,
" mesecons_piston_bottom.png " ,
" mesecons_piston_bottom.png " ,
2015-06-29 19:55:56 +02:00
} ,
2017-02-27 17:20:51 +01:00
groups = { handy = 1 , not_in_creative_inventory = 1 } ,
2015-06-29 19:55:56 +02:00
paramtype = " light " ,
2017-06-13 14:26:50 +02:00
sunlight_propagates = true ,
2015-06-29 19:55:56 +02:00
paramtype2 = " facedir " ,
2017-01-04 22:36:51 +01:00
is_ground_content = false ,
2017-03-15 20:54:33 +01:00
drop = " mesecons_pistons:piston_sticky_off " ,
2017-11-23 20:52:33 +01:00
after_destruct = piston_remove_pusher ,
2015-06-29 19:55:56 +02:00
node_box = piston_up_on_box ,
selection_box = piston_up_on_box ,
mesecons_piston = pistonspec_sticky_up ,
2017-02-11 18:46:23 +01:00
sounds = mcl_sounds.node_sound_wood_defaults ( ) ,
2015-06-29 19:55:56 +02:00
mesecons = { effector = {
action_off = piston_off ,
rules = piston_up_rules ,
2017-02-22 16:22:28 +01:00
} } ,
_mcl_blast_resistance = 2.5 ,
2017-02-27 17:20:51 +01:00
_mcl_hardness = 0.5 ,
2017-12-05 14:09:39 +01:00
on_rotate = on_rotate ,
2015-06-29 19:55:56 +02:00
} )
-- pusher
minetest.register_node ( " mesecons_pistons:piston_up_pusher_sticky " , {
drawtype = " nodebox " ,
tiles = {
" mesecons_piston_pusher_front_sticky.png " ,
" mesecons_piston_pusher_back.png " ,
" mesecons_piston_pusher_left.png^[transformR270 " ,
" mesecons_piston_pusher_right.png^[transformR90 " ,
" mesecons_piston_pusher_bottom.png " ,
" mesecons_piston_pusher_top.png^[transformR180 " ,
} ,
paramtype = " light " ,
2017-06-13 14:26:50 +02:00
sunlight_propagates = true ,
2015-06-29 19:55:56 +02:00
paramtype2 = " facedir " ,
2017-01-04 22:36:51 +01:00
is_ground_content = false ,
2017-11-23 21:15:42 +01:00
after_destruct = piston_remove_base ,
2015-06-29 19:55:56 +02:00
diggable = false ,
corresponding_piston = " mesecons_pistons:piston_up_sticky_on " ,
selection_box = piston_up_pusher_box ,
node_box = piston_up_pusher_box ,
2017-02-17 01:56:52 +01:00
sounds = mcl_sounds.node_sound_wood_defaults ( ) ,
2017-02-22 16:22:28 +01:00
_mcl_blast_resistance = 2.5 ,
2017-12-05 14:09:39 +01:00
on_rotate = on_rotate ,
2015-06-29 19:55:56 +02:00
} )
--
--
-- DOWN
--
--
local piston_down_pusher_box = {
type = " fixed " ,
fixed = {
{ - 2 / 16 , - .5 + pt , - 2 / 16 , 2 / 16 , .5 + pt , 2 / 16 } ,
{ - .5 , - .5 , - .5 , .5 , - .5 + pt , .5 } ,
}
}
local piston_down_on_box = {
type = " fixed " ,
fixed = {
{ - .5 , - .5 + pt , - .5 , .5 , .5 , .5 }
}
}
-- Normal
local pistonspec_normal_down = {
offname = " mesecons_pistons:piston_down_normal_off " ,
onname = " mesecons_pistons:piston_down_normal_on " ,
dir = { x = 0 , y = - 1 , z = 0 } ,
pusher = " mesecons_pistons:piston_down_pusher_normal " ,
}
-- offstate
minetest.register_node ( " mesecons_pistons:piston_down_normal_off " , {
tiles = {
2017-07-17 17:29:53 +02:00
" mesecons_piston_back.png " ,
2015-06-29 19:55:56 +02:00
" mesecons_piston_pusher_front.png " ,
2017-07-17 17:29:53 +02:00
" mesecons_piston_bottom.png^[transformR180 " ,
" mesecons_piston_bottom.png^[transformR180 " ,
" mesecons_piston_bottom.png^[transformR180 " ,
" mesecons_piston_bottom.png^[transformR180 " ,
2015-06-29 19:55:56 +02:00
} ,
2017-02-27 17:20:51 +01:00
groups = { handy = 1 , not_in_creative_inventory = 1 } ,
2017-06-13 14:26:50 +02:00
paramtype = " light " ,
sunlight_propagates = true ,
2015-06-29 19:55:56 +02:00
paramtype2 = " facedir " ,
2017-01-04 22:36:51 +01:00
is_ground_content = false ,
2015-06-29 19:55:56 +02:00
drop = " mesecons_pistons:piston_normal_off " ,
mesecons_piston = pistonspec_normal_down ,
2017-02-22 17:07:24 +01:00
sounds = mcl_sounds.node_sound_stone_defaults ( ) ,
2015-06-29 19:55:56 +02:00
mesecons = { effector = {
action_on = piston_on ,
rules = piston_down_rules ,
2017-02-22 16:22:28 +01:00
} } ,
_mcl_blast_resistance = 2.5 ,
2017-02-27 17:20:51 +01:00
_mcl_hardness = 0.5 ,
2017-12-05 14:09:39 +01:00
on_rotate = on_rotate ,
2015-06-29 19:55:56 +02:00
} )
-- onstate
minetest.register_node ( " mesecons_pistons:piston_down_normal_on " , {
drawtype = " nodebox " ,
tiles = {
2017-07-17 17:29:53 +02:00
" mesecons_piston_back.png " ,
2015-06-29 19:55:56 +02:00
" mesecons_piston_on_front.png " ,
2017-07-17 17:29:53 +02:00
" mesecons_piston_bottom.png^[transformR180 " ,
" mesecons_piston_bottom.png^[transformR180 " ,
" mesecons_piston_bottom.png^[transformR180 " ,
" mesecons_piston_bottom.png^[transformR180 " ,
2015-06-29 19:55:56 +02:00
} ,
2017-02-27 17:20:51 +01:00
groups = { handy = 1 , not_in_creative_inventory = 1 } ,
2015-06-29 19:55:56 +02:00
paramtype = " light " ,
2017-06-13 14:26:50 +02:00
sunlight_propagates = true ,
2015-06-29 19:55:56 +02:00
paramtype2 = " facedir " ,
2017-01-04 22:36:51 +01:00
is_ground_content = false ,
2015-06-29 19:55:56 +02:00
drop = " mesecons_pistons:piston_normal_off " ,
2017-11-23 20:52:33 +01:00
after_destruct = piston_remove_pusher ,
2015-06-29 19:55:56 +02:00
node_box = piston_down_on_box ,
selection_box = piston_down_on_box ,
mesecons_piston = pistonspec_normal_down ,
2017-02-22 17:07:24 +01:00
sounds = mcl_sounds.node_sound_stone_defaults ( ) ,
2015-06-29 19:55:56 +02:00
mesecons = { effector = {
action_off = piston_off ,
rules = piston_down_rules ,
2017-02-22 16:22:28 +01:00
} } ,
_mcl_blast_resistance = 2.5 ,
2017-02-27 17:20:51 +01:00
_mcl_hardness = 0.5 ,
2017-12-05 14:09:39 +01:00
on_rotate = on_rotate ,
2015-06-29 19:55:56 +02:00
} )
-- pusher
minetest.register_node ( " mesecons_pistons:piston_down_pusher_normal " , {
drawtype = " nodebox " ,
tiles = {
" mesecons_piston_pusher_back.png " ,
" mesecons_piston_pusher_front.png " ,
" mesecons_piston_pusher_left.png^[transformR90 " ,
" mesecons_piston_pusher_right.png^[transformR270 " ,
" mesecons_piston_pusher_bottom.png^[transformR180 " ,
" mesecons_piston_pusher_top.png " ,
} ,
paramtype = " light " ,
2017-06-13 14:26:50 +02:00
sunlight_propagates = true ,
2015-06-29 19:55:56 +02:00
paramtype2 = " facedir " ,
2017-01-04 22:36:51 +01:00
is_ground_content = false ,
2017-11-23 21:15:42 +01:00
after_destruct = piston_remove_base ,
2015-06-29 19:55:56 +02:00
diggable = false ,
corresponding_piston = " mesecons_pistons:piston_down_normal_on " ,
selection_box = piston_down_pusher_box ,
node_box = piston_down_pusher_box ,
2017-02-17 01:56:52 +01:00
sounds = mcl_sounds.node_sound_wood_defaults ( ) ,
2017-02-22 16:22:28 +01:00
_mcl_blast_resistance = 2.5 ,
2017-12-05 14:09:39 +01:00
on_rotate = on_rotate ,
2015-06-29 19:55:56 +02:00
} )
-- Sticky
local pistonspec_sticky_down = {
onname = " mesecons_pistons:piston_down_sticky_on " ,
offname = " mesecons_pistons:piston_down_sticky_off " ,
dir = { x = 0 , y = - 1 , z = 0 } ,
pusher = " mesecons_pistons:piston_down_pusher_sticky " ,
sticky = true
}
-- offstate
minetest.register_node ( " mesecons_pistons:piston_down_sticky_off " , {
tiles = {
2017-07-17 17:29:53 +02:00
" mesecons_piston_back.png " ,
2015-06-29 19:55:56 +02:00
" mesecons_piston_pusher_front_sticky.png " ,
2017-07-17 17:29:53 +02:00
" mesecons_piston_bottom.png^[transformR180 " ,
" mesecons_piston_bottom.png^[transformR180 " ,
" mesecons_piston_bottom.png^[transformR180 " ,
" mesecons_piston_bottom.png^[transformR180 " ,
2015-06-29 19:55:56 +02:00
} ,
2017-02-27 17:20:51 +01:00
groups = { handy = 1 , not_in_creative_inventory = 1 } ,
2017-06-13 14:26:50 +02:00
paramtype = " light " ,
sunlight_propagates = true ,
2015-06-29 19:55:56 +02:00
paramtype2 = " facedir " ,
2017-01-04 22:36:51 +01:00
is_ground_content = false ,
2015-06-29 19:55:56 +02:00
drop = " mesecons_pistons:piston_sticky_off " ,
mesecons_piston = pistonspec_sticky_down ,
2017-02-22 17:07:24 +01:00
sounds = mcl_sounds.node_sound_stone_defaults ( ) ,
2015-06-29 19:55:56 +02:00
mesecons = { effector = {
action_on = piston_on ,
rules = piston_down_rules ,
2017-02-22 16:22:28 +01:00
} } ,
_mcl_blast_resistance = 2.5 ,
2017-02-27 17:20:51 +01:00
_mcl_hardness = 0.5 ,
2017-12-05 14:09:39 +01:00
on_rotate = on_rotate ,
2015-06-29 19:55:56 +02:00
} )
-- onstate
minetest.register_node ( " mesecons_pistons:piston_down_sticky_on " , {
drawtype = " nodebox " ,
tiles = {
2017-07-17 17:29:53 +02:00
" mesecons_piston_back.png " ,
2015-06-29 19:55:56 +02:00
" mesecons_piston_on_front.png " ,
2017-07-17 17:29:53 +02:00
" mesecons_piston_bottom.png^[transformR180 " ,
" mesecons_piston_bottom.png^[transformR180 " ,
" mesecons_piston_bottom.png^[transformR180 " ,
" mesecons_piston_bottom.png^[transformR180 " ,
2015-06-29 19:55:56 +02:00
} ,
2017-02-27 17:20:51 +01:00
groups = { handy = 1 , not_in_creative_inventory = 1 } ,
2015-06-29 19:55:56 +02:00
paramtype = " light " ,
2017-06-13 14:26:50 +02:00
sunlight_propagates = true ,
2015-06-29 19:55:56 +02:00
paramtype2 = " facedir " ,
2017-01-04 22:36:51 +01:00
is_ground_content = false ,
2015-06-29 19:55:56 +02:00
drop = " mesecons_pistons:piston_sticky_off " ,
2017-11-23 20:52:33 +01:00
after_destruct = piston_remove_pusher ,
2015-06-29 19:55:56 +02:00
node_box = piston_down_on_box ,
selection_box = piston_down_on_box ,
mesecons_piston = pistonspec_sticky_down ,
2017-02-22 17:07:24 +01:00
sounds = mcl_sounds.node_sound_stone_defaults ( ) ,
2015-06-29 19:55:56 +02:00
mesecons = { effector = {
action_off = piston_off ,
rules = piston_down_rules ,
2017-02-22 16:22:28 +01:00
} } ,
_mcl_blast_resistance = 2.5 ,
2017-02-27 17:20:51 +01:00
_mcl_hardness = 0.5 ,
2017-12-05 14:09:39 +01:00
on_rotate = on_rotate ,
2015-06-29 19:55:56 +02:00
} )
-- pusher
minetest.register_node ( " mesecons_pistons:piston_down_pusher_sticky " , {
drawtype = " nodebox " ,
tiles = {
" mesecons_piston_pusher_back.png " ,
" mesecons_piston_pusher_front_sticky.png " ,
" mesecons_piston_pusher_left.png^[transformR90 " ,
" mesecons_piston_pusher_right.png^[transformR270 " ,
" mesecons_piston_pusher_bottom.png^[transformR180 " ,
" mesecons_piston_pusher_top.png " ,
} ,
paramtype = " light " ,
2017-06-13 14:26:50 +02:00
sunlight_propagates = true ,
2015-06-29 19:55:56 +02:00
paramtype2 = " facedir " ,
2017-01-04 22:36:51 +01:00
is_ground_content = false ,
2017-11-23 21:15:42 +01:00
after_destruct = piston_remove_base ,
2015-06-29 19:55:56 +02:00
diggable = false ,
corresponding_piston = " mesecons_pistons:piston_down_sticky_on " ,
selection_box = piston_down_pusher_box ,
node_box = piston_down_pusher_box ,
2017-02-17 01:56:52 +01:00
sounds = mcl_sounds.node_sound_wood_defaults ( ) ,
2017-02-22 16:22:28 +01:00
_mcl_blast_resistance = 2.5 ,
2017-12-05 14:09:39 +01:00
on_rotate = on_rotate ,
2015-06-29 19:55:56 +02:00
} )
-- Register pushers as stoppers if they would be seperated from the piston
local piston_pusher_get_stopper = function ( node , dir , stack , stackid )
if ( stack [ stackid + 1 ]
and stack [ stackid + 1 ] . node.name == minetest.registered_nodes [ node.name ] . corresponding_piston
and stack [ stackid + 1 ] . node.param2 == node.param2 )
or ( stack [ stackid - 1 ]
and stack [ stackid - 1 ] . node.name == minetest.registered_nodes [ node.name ] . corresponding_piston
and stack [ stackid - 1 ] . node.param2 == node.param2 ) then
return false
end
return true
end
local piston_pusher_up_down_get_stopper = function ( node , dir , stack , stackid )
if ( stack [ stackid + 1 ]
and stack [ stackid + 1 ] . node.name == minetest.registered_nodes [ node.name ] . corresponding_piston )
or ( stack [ stackid - 1 ]
and stack [ stackid - 1 ] . node.name == minetest.registered_nodes [ node.name ] . corresponding_piston ) then
return false
end
return true
end
2017-07-31 00:12:21 +02:00
mesecon.register_mvps_stopper ( " mesecons_pistons:piston_pusher_normal " , piston_pusher_get_stopper )
mesecon.register_mvps_stopper ( " mesecons_pistons:piston_pusher_sticky " , piston_pusher_get_stopper )
2015-06-29 19:55:56 +02:00
2017-07-31 00:12:21 +02:00
mesecon.register_mvps_stopper ( " mesecons_pistons:piston_up_pusher_normal " , piston_pusher_up_down_get_stopper )
mesecon.register_mvps_stopper ( " mesecons_pistons:piston_up_pusher_sticky " , piston_pusher_up_down_get_stopper )
2015-06-29 19:55:56 +02:00
2017-07-31 00:12:21 +02:00
mesecon.register_mvps_stopper ( " mesecons_pistons:piston_down_pusher_normal " , piston_pusher_up_down_get_stopper )
mesecon.register_mvps_stopper ( " mesecons_pistons:piston_down_pusher_sticky " , piston_pusher_up_down_get_stopper )
2015-06-29 19:55:56 +02:00
-- Register pistons as stoppers if they would be seperated from the stopper
local piston_up_down_get_stopper = function ( node , dir , stack , stackid )
if ( stack [ stackid + 1 ]
and stack [ stackid + 1 ] . node.name == minetest.registered_nodes [ node.name ] . mesecons_piston.pusher )
or ( stack [ stackid - 1 ]
and stack [ stackid - 1 ] . node.name == minetest.registered_nodes [ node.name ] . mesecons_piston.pusher ) then
return false
end
return true
end
local piston_get_stopper = function ( node , dir , stack , stackid )
pistonspec = minetest.registered_nodes [ node.name ] . mesecons_piston
dir = piston_get_direction ( pistonspec.dir , node )
2017-07-31 00:12:21 +02:00
local pusherpos = vector.add ( stack [ stackid ] . pos , dir )
2017-01-11 18:21:46 +01:00
local pushernode = minetest.get_node ( pusherpos )
2015-06-29 19:55:56 +02:00
if minetest.registered_nodes [ node.name ] . mesecons_piston.pusher == pushernode.name then
for _ , s in ipairs ( stack ) do
2017-11-20 08:04:09 +01:00
if vector.equals ( s.pos , pusherpos ) -- pusher is also to be pushed
2015-06-29 19:55:56 +02:00
and s.node . param2 == node.param2 then
return false
end
end
end
return true
end
2017-07-31 00:12:21 +02:00
mesecon.register_mvps_stopper ( " mesecons_pistons:piston_normal_on " , piston_get_stopper )
mesecon.register_mvps_stopper ( " mesecons_pistons:piston_sticky_on " , piston_get_stopper )
2015-06-29 19:55:56 +02:00
2017-07-31 00:12:21 +02:00
mesecon.register_mvps_stopper ( " mesecons_pistons:piston_up_normal_on " , piston_up_down_get_stopper )
mesecon.register_mvps_stopper ( " mesecons_pistons:piston_up_sticky_on " , piston_up_down_get_stopper )
2015-06-29 19:55:56 +02:00
2017-07-31 00:12:21 +02:00
mesecon.register_mvps_stopper ( " mesecons_pistons:piston_down_normal_on " , piston_up_down_get_stopper )
mesecon.register_mvps_stopper ( " mesecons_pistons:piston_down_sticky_on " , piston_up_down_get_stopper )
2015-06-29 19:55:56 +02:00
--craft recipes
minetest.register_craft ( {
output = ' mesecons_pistons:piston_normal_off ' ,
recipe = {
{ " group:wood " , " group:wood " , " group:wood " } ,
2017-02-11 21:14:40 +01:00
{ " mcl_core:cobble " , " mcl_core:iron_ingot " , " mcl_core:cobble " } ,
2017-01-31 23:32:56 +01:00
{ " mcl_core:cobble " , " mesecons:redstone " , " mcl_core:cobble " } ,
2015-06-29 19:55:56 +02:00
}
} )
minetest.register_craft ( {
output = " mesecons_pistons:piston_sticky_off " ,
recipe = {
2017-02-11 22:05:14 +01:00
{ " mcl_mobitems:slimeball " } ,
2015-06-29 19:55:56 +02:00
{ " mesecons_pistons:piston_normal_off " } ,
}
} )
2017-03-21 04:27:50 +01:00
-- Add entry aliases for the Help
if minetest.get_modpath ( " doc " ) then
doc.add_entry_alias ( " nodes " , " mesecons_pistons:piston_normal_off " , " nodes " , " mesecons_pistons:piston_normal_on " )
doc.add_entry_alias ( " nodes " , " mesecons_pistons:piston_normal_off " , " nodes " , " mesecons_pistons:piston_up_normal_off " )
doc.add_entry_alias ( " nodes " , " mesecons_pistons:piston_normal_off " , " nodes " , " mesecons_pistons:piston_up_normal_on " )
doc.add_entry_alias ( " nodes " , " mesecons_pistons:piston_normal_off " , " nodes " , " mesecons_pistons:piston_down_normal_off " )
doc.add_entry_alias ( " nodes " , " mesecons_pistons:piston_normal_off " , " nodes " , " mesecons_pistons:piston_down_normal_on " )
doc.add_entry_alias ( " nodes " , " mesecons_pistons:piston_normal_off " , " nodes " , " mesecons_pistons:piston_pusher_normal " )
doc.add_entry_alias ( " nodes " , " mesecons_pistons:piston_normal_off " , " nodes " , " mesecons_pistons:piston_up_pusher_normal " )
doc.add_entry_alias ( " nodes " , " mesecons_pistons:piston_normal_off " , " nodes " , " mesecons_pistons:piston_down_pusher_normal " )
doc.add_entry_alias ( " nodes " , " mesecons_pistons:piston_sticky_off " , " nodes " , " mesecons_pistons:piston_sticky_on " )
doc.add_entry_alias ( " nodes " , " mesecons_pistons:piston_sticky_off " , " nodes " , " mesecons_pistons:piston_up_sticky_off " )
doc.add_entry_alias ( " nodes " , " mesecons_pistons:piston_sticky_off " , " nodes " , " mesecons_pistons:piston_up_sticky_on " )
doc.add_entry_alias ( " nodes " , " mesecons_pistons:piston_sticky_off " , " nodes " , " mesecons_pistons:piston_down_sticky_off " )
doc.add_entry_alias ( " nodes " , " mesecons_pistons:piston_sticky_off " , " nodes " , " mesecons_pistons:piston_down_sticky_on " )
doc.add_entry_alias ( " nodes " , " mesecons_pistons:piston_sticky_off " , " nodes " , " mesecons_pistons:piston_pusher_sticky " )
doc.add_entry_alias ( " nodes " , " mesecons_pistons:piston_sticky_off " , " nodes " , " mesecons_pistons:piston_up_pusher_sticky " )
doc.add_entry_alias ( " nodes " , " mesecons_pistons:piston_sticky_off " , " nodes " , " mesecons_pistons:piston_down_pusher_sticky " )
end