2015-03-13 15:02:54 +01:00
--arrow_signs by addi
--thanks to Jat15 for the new place and rotate-system.
2013-07-14 17:26:30 +02:00
--Code and Textures are under the CC by-sa 3.0 licence
--see: http://creativecommons.org/licenses/by-sa/3.0/
arrow_signs = { }
2014-08-13 18:00:41 +02:00
arrow_signs.formspec = " field[text;Sign text:;${text}] " ;
2015-03-13 15:02:54 +01:00
arrow_signs.on_place = function ( itemstack , placer , pointed_thing )
2014-03-19 05:43:07 +01:00
2014-08-13 17:37:00 +02:00
local posabove = pointed_thing.above
local posunder = pointed_thing.under
local vector = placer : get_look_dir ( )
local place = true
2014-03-19 05:43:07 +01:00
2014-08-13 17:37:00 +02:00
if posabove.y > posunder.y then
if ( vector.z > 0.5 and vector.z <= 1 ) then
minetest.add_node ( posabove , { name = itemstack : get_name ( ) , param2 = 10 } )
elseif ( vector.x > 0.5 and vector.x <= 1 ) then
minetest.add_node ( posabove , { name = itemstack : get_name ( ) , param2 = 19 } )
elseif ( - 0.5 > vector.z and - 1 <= vector.z ) then
minetest.add_node ( posabove , { name = itemstack : get_name ( ) , param2 = 4 } )
elseif ( - 0.5 > vector.x and - 1 <= vector.x ) then
minetest.add_node ( posabove , { name = itemstack : get_name ( ) , param2 = 13 } )
else
place = false
end
elseif posabove.y < posunder.y then
if ( vector.z > 0.5 and vector.z <= 1 ) then
minetest.add_node ( posabove , { name = itemstack : get_name ( ) , param2 = 8 } )
elseif ( vector.x > 0.5 and vector.x <= 1 ) then
minetest.add_node ( posabove , { name = itemstack : get_name ( ) , param2 = 17 } )
elseif ( - 0.5 > vector.z and - 1 <= vector.z ) then
minetest.add_node ( posabove , { name = itemstack : get_name ( ) , param2 = 6 } )
elseif ( - 0.5 > vector.x and - 1 <= vector.x ) then
minetest.add_node ( posabove , { name = itemstack : get_name ( ) , param2 = 15 } )
else
place = false
end
elseif posabove.z > posunder.z then
if ( vector.y > 0.75 and vector.y <= 1 ) then
minetest.add_node ( posabove , { name = itemstack : get_name ( ) , param2 = 22 } )
elseif ( vector.y >=- 1 and vector.y <- 0.75 ) then
minetest.add_node ( posabove , { name = itemstack : get_name ( ) , param2 = 2 } )
elseif ( vector.x >= 0 and vector.x <= 1 ) then
minetest.add_node ( posabove , { name = itemstack : get_name ( ) , param2 = 18 } )
elseif ( vector.x < 0 and vector.x >=- 1 ) then
minetest.add_node ( posabove , { name = itemstack : get_name ( ) , param2 = 14 } )
else
place = false
2014-03-19 05:43:07 +01:00
end
2014-08-13 17:37:00 +02:00
elseif posabove.z < posunder.z then
if ( vector.y > 0.75 and vector.y <= 1 ) then
minetest.add_node ( posabove , { name = itemstack : get_name ( ) , param2 = 20 } )
elseif ( vector.y >=- 1 and vector.y <- 0.75 ) then
minetest.add_node ( posabove , { name = itemstack : get_name ( ) , param2 = 0 } )
elseif ( vector.x >= 0 and vector.x <= 1 ) then
minetest.add_node ( posabove , { name = itemstack : get_name ( ) , param2 = 16 } )
elseif ( vector.x < 0 and vector.x >=- 1 ) then
minetest.add_node ( posabove , { name = itemstack : get_name ( ) , param2 = 12 } )
else
place = false
end
elseif posabove.x > posunder.x then
if ( vector.y > 0.75 and vector.y <= 1 ) then
minetest.add_node ( posabove , { name = itemstack : get_name ( ) , param2 = 21 } )
elseif ( vector.y >=- 1 and vector.y <- 0.75 ) then
minetest.add_node ( posabove , { name = itemstack : get_name ( ) , param2 = 3 } )
elseif ( vector.z >= 0 and vector.z <= 1 ) then
minetest.add_node ( posabove , { name = itemstack : get_name ( ) , param2 = 11 } )
elseif ( vector.z < 0 and vector.z >=- 1 ) then
minetest.add_node ( posabove , { name = itemstack : get_name ( ) , param2 = 7 } )
else
place = false
end
elseif posabove.x < posunder.x then
if ( vector.y > 0.75 and vector.y <= 1 ) then
minetest.add_node ( posabove , { name = itemstack : get_name ( ) , param2 = 23 } )
elseif ( vector.y >=- 1 and vector.y <- 0.75 ) then
minetest.add_node ( posabove , { name = itemstack : get_name ( ) , param2 = 1 } )
elseif ( vector.z >= 0 and vector.z <= 1 ) then
minetest.add_node ( posabove , { name = itemstack : get_name ( ) , param2 = 9 } )
elseif ( vector.z < 0 and vector.z >=- 1 ) then
minetest.add_node ( posabove , { name = itemstack : get_name ( ) , param2 = 5 } )
else
place = false
end
else
place = false
2014-03-19 05:43:07 +01:00
end
2014-08-13 17:37:00 +02:00
2014-03-19 05:43:07 +01:00
if not ( place ) then
minetest.rotate_node ( itemstack , placer , pointed_thing )
else
itemstack : take_item ( )
end
2014-08-13 19:31:09 +02:00
if not minetest.setting_getbool ( " creative_mode " ) then
return itemstack
end
2014-08-13 18:13:25 +02:00
2014-03-19 05:43:07 +01:00
end
2015-03-13 15:02:54 +01:00
arrow_signs.savetext = function ( pos , formname , fields , sender )
if fields.text then
2013-07-14 17:26:30 +02:00
if not minetest.get_player_privs ( sender : get_player_name ( ) ) [ " interact " ] then
minetest.chat_send_player ( sender : get_player_name ( ) , " error: you don't have permission to edit the sign. you need the interact priv " )
return
end
2015-04-03 10:38:51 +02:00
if minetest.is_protected ( pos , sender : get_player_name ( ) ) then
minetest.record_protection_violation ( pos , sender : get_player_name ( ) )
return
end
2014-01-05 19:01:57 +01:00
local meta = minetest.get_meta ( pos )
2013-07-14 17:26:30 +02:00
fields.text = fields.text or " "
2015-03-13 15:02:54 +01:00
minetest.log ( " action " , ( sender : get_player_name ( ) or " " ) .. " wrote \" " .. fields.text ..
" \" to sign at " .. minetest.pos_to_string ( pos ) ) ;
2013-07-14 17:26:30 +02:00
meta : set_string ( " text " , fields.text )
2015-04-03 10:32:57 +02:00
local text , lines = arrow_signs.create_lines ( fields.text )
2013-07-14 17:26:30 +02:00
meta : set_string ( " infotext " , ' " ' .. text .. ' " ' )
2015-04-03 10:32:57 +02:00
if lines > 4 then
minetest.chat_send_player ( sender : get_player_name ( ) , " \t Information: \n You've written more than 5 lines. \n it may be that not all lines are displayed. \n Please remove the last entry " )
2013-07-14 17:26:30 +02:00
end
return true
end
2015-03-13 15:02:54 +01:00
end
2013-07-14 17:26:30 +02:00
2015-03-13 15:02:54 +01:00
--this function creates the linebreaks
arrow_signs.create_lines = function ( text )
2015-04-03 10:32:57 +02:00
local text , n = text : gsub ( " [ ]*(%|)[ ]* " , ' " \n " ' ) --search for |
local text , m = text : gsub ( " [ ]*(%/)[ ]* " , ' " \n " ' ) --search for /
return text , n + m
2013-07-14 17:26:30 +02:00
end
2014-08-13 18:00:41 +02:00
minetest.override_item ( " default:sign_wall " , {
groups = { choppy = 2 , dig_immediate = 2 , attached_node = 1 , sign = 1 } ,
} )
2013-07-14 17:26:30 +02:00
2014-01-05 19:01:57 +01:00
--Sign arrow
minetest.register_node ( " arrow_signs:wall " , {
description = " Arrow signs " ,
drawtype = " nodebox " ,
node_box = {
type = " fixed " ,
fixed = {
2014-01-08 08:27:10 +01:00
{ 0.25 , - 0.25 , 0.5 , - 0.25 , 0.5 , 0.47 } ,
{ 0.1875 , - 0.3125 , 0.5 , - 0.1875 , - 0.25 , 0.47 } ,
{ 0.125 , - 0.3125 , 0.5 , - 0.125 , - 0.375 , 0.47 } ,
{ 0.0625 , - 0.375 , 0.5 , - 0.0625 , - 0.437 , 0.47 }
2014-01-05 19:01:57 +01:00
}
2013-07-14 17:26:30 +02:00
} ,
2014-08-13 19:48:11 +02:00
selection_box = {
type = " fixed " ,
fixed = {
{ 0.30 , - 0.5 , 0.5 , - 0.30 , 0.5 , 0.47 }
}
} ,
2014-01-08 08:27:10 +01:00
tiles = { " arrow_sign_border_left.png " , " arrow_sign_border_right.png " , " arrow_sign_border_up.png " , " arrow_sign_border_down.png " , " arrow_sign.png " , " arrow_sign.png " } ,
2014-01-05 19:01:57 +01:00
inventory_image = " arrow_sign.png " ,
2013-07-14 17:26:30 +02:00
paramtype = " light " ,
2014-01-05 19:01:57 +01:00
paramtype2 = " facedir " ,
2013-07-14 17:26:30 +02:00
sunlight_propagates = true ,
walkable = false ,
2014-01-05 19:01:57 +01:00
groups = { choppy = 2 , dig_immediate = 2 , sign = 1 } ,
2013-07-14 17:26:30 +02:00
sounds = default.node_sound_defaults ( ) ,
2015-03-13 15:02:54 +01:00
on_place = arrow_signs.on_place ,
2013-07-14 17:26:30 +02:00
on_construct = function ( pos )
2014-01-05 19:01:57 +01:00
--local n = minetest.get_node(pos)
local meta = minetest.get_meta ( pos )
2014-08-13 18:00:41 +02:00
meta : set_string ( " formspec " , arrow_signs.formspec )
2015-03-13 15:02:54 +01:00
meta : set_string ( " infotext " , [[""]] )
2013-07-14 17:26:30 +02:00
end ,
2015-03-13 15:02:54 +01:00
on_receive_fields = arrow_signs.savetext ,
2013-07-14 17:26:30 +02:00
} )
2014-01-05 19:01:57 +01:00
--Recipes
2013-07-14 17:26:30 +02:00
minetest.register_craft ( {
2014-01-05 19:01:57 +01:00
type = ' shapeless ' ,
output = ' arrow_signs:wall ' ,
recipe = { ' group:sign ' , ' default:stick ' } ,
2013-07-14 17:26:30 +02:00
} )
minetest.register_craft ( {
output = ' default:sign_wall ' ,
recipe = {
{ ' group:sign ' } ,
}
} )
2014-01-05 19:01:57 +01:00
--Redefinition
minetest.register_abm ( {
2014-03-19 06:06:34 +01:00
nodenames = { " arrow_signs:wall_right " , " arrow_signs:wall_left " , " arrow_signs:wall_up " , " arrow_signs:wall_down " ,
" more_signs:wall_right " , " more_signs:wall_left " , " more_signs:wall_up " , " more_signs:wall_down "
} ,
2014-01-05 19:01:57 +01:00
interval = 1 ,
chance = 1 ,
action = function ( pos , node )
local convert_facedir = {
2014-03-19 06:06:34 +01:00
[ " arrow_signs:wall_right " ] = { 6 , 4 , 5 , 11 , 16 , 14 } ,
[ " arrow_signs:wall_left " ] = { 8 , 10 , 9 , 7 , 12 , 18 } ,
[ " arrow_signs:wall_up " ] = { 15 , 19 , 23 , 21 , 20 , 22 } ,
[ " arrow_signs:wall_down " ] = { 17 , 13 , 1 , 3 , 0 , 2 } ,
-- For old mod
[ " more_signs:wall_right " ] = { 6 , 4 , 5 , 11 , 16 , 14 } ,
[ " more_signs:wall_left " ] = { 8 , 10 , 9 , 7 , 12 , 18 } ,
[ " more_signs:wall_up " ] = { 15 , 19 , 23 , 21 , 20 , 22 } ,
[ " more_signs:wall_down " ] = { 17 , 13 , 1 , 3 , 0 , 2 } ,
2014-01-05 19:01:57 +01:00
}
2014-01-08 08:27:10 +01:00
minetest.swap_node ( pos , { name = " arrow_signs:wall " , param2 = convert_facedir [ node.name ] [ node.param2 + 1 ] } )
2014-01-05 19:01:57 +01:00
end ,
} )
2013-07-14 17:26:30 +02:00
2014-01-05 19:01:57 +01:00
--Locked sign
2013-07-14 17:26:30 +02:00
if locks then
2014-08-13 17:37:00 +02:00
local MODPATH = minetest.get_modpath ( " arrow_signs " ) ;
dofile ( MODPATH .. " /shared_locked.lua " )
2013-07-14 17:26:30 +02:00
end