2016-07-22 16:15:05 +02:00
--[[
Arrow signs mod for Minetest .
This mods adds arrowsigns into Minetest . Rotatable in all directions .
Thanks to :
Jat15 for the place and rotate system
Hectic for the new Textures that fit into Minetest 0.4 .14
2016-07-22 16:40:41 +02:00
This work is licensed under the Creative Commons Attribution - ShareAlike 3.0 Unported License .
2016-07-22 16:15:05 +02:00
To view a copy of this license , visit http : // creativecommons.org / licenses / by - sa / 3.0 / or send a letter to Creative Commons , PO Box 1866 , Mountain View , CA 94042 , USA .
] ]
2013-07-14 17:26:30 +02:00
arrow_signs = { }
2019-12-28 21:26:30 +01:00
arrow_signs.formspec = " size[6,2]real_coordinates[true]field[0.375,0.5;5.25,0.8;text;Sign text: (Hit 'Enter' key to validate);${text}]label[0.375,1.5;(Hint: Use / or | to create a new line)] " ;
2014-08-13 18:00:41 +02:00
2015-03-13 15:02:54 +01:00
arrow_signs.on_place = function ( itemstack , placer , pointed_thing )
2016-07-22 16:40:41 +02: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 ( )
2016-07-23 09:27:09 +02:00
local param2 = 0
2016-07-22 16:40:41 +02:00
2016-07-23 09:27:09 +02:00
-- I wonder if there is a way to calculate the param2 instad of using so much if here.
-- +Y
2014-08-13 17:37:00 +02:00
if posabove.y > posunder.y then
if ( vector.z > 0.5 and vector.z <= 1 ) then
2016-07-23 09:27:09 +02:00
param2 = 10
2014-08-13 17:37:00 +02:00
elseif ( vector.x > 0.5 and vector.x <= 1 ) then
2016-07-23 09:27:09 +02:00
param2 = 19
2014-08-13 17:37:00 +02:00
elseif ( - 0.5 > vector.z and - 1 <= vector.z ) then
2016-07-23 09:27:09 +02:00
param2 = 4
2014-08-13 17:37:00 +02:00
elseif ( - 0.5 > vector.x and - 1 <= vector.x ) then
2016-07-23 09:27:09 +02:00
param2 = 13
2014-08-13 17:37:00 +02:00
end
2016-07-23 09:27:09 +02:00
-- -Y
2014-08-13 17:37:00 +02:00
elseif posabove.y < posunder.y then
if ( vector.z > 0.5 and vector.z <= 1 ) then
2016-07-23 09:27:09 +02:00
param2 = 8
2014-08-13 17:37:00 +02:00
elseif ( vector.x > 0.5 and vector.x <= 1 ) then
2016-07-23 09:27:09 +02:00
param2 = 17
2014-08-13 17:37:00 +02:00
elseif ( - 0.5 > vector.z and - 1 <= vector.z ) then
2016-07-23 09:27:09 +02:00
param2 = 6
2014-08-13 17:37:00 +02:00
elseif ( - 0.5 > vector.x and - 1 <= vector.x ) then
2016-07-23 09:27:09 +02:00
param2 = 15
2014-08-13 17:37:00 +02:00
end
2016-07-23 09:27:09 +02:00
-- +Z
2014-08-13 17:37:00 +02:00
elseif posabove.z > posunder.z then
if ( vector.y > 0.75 and vector.y <= 1 ) then
2016-07-23 09:27:09 +02:00
param2 = 22
2014-08-13 17:37:00 +02:00
elseif ( vector.y >=- 1 and vector.y <- 0.75 ) then
2016-07-23 09:27:09 +02:00
param2 = 2
2014-08-13 17:37:00 +02:00
elseif ( vector.x >= 0 and vector.x <= 1 ) then
2016-07-23 09:27:09 +02:00
param2 = 18
2014-08-13 17:37:00 +02:00
elseif ( vector.x < 0 and vector.x >=- 1 ) then
2016-07-23 09:27:09 +02:00
param2 = 14
2014-03-19 05:43:07 +01:00
end
2016-07-23 09:27:09 +02:00
-- -Z
2014-08-13 17:37:00 +02:00
elseif posabove.z < posunder.z then
if ( vector.y > 0.75 and vector.y <= 1 ) then
2016-07-23 09:27:09 +02:00
param2 = 20
2014-08-13 17:37:00 +02:00
elseif ( vector.y >=- 1 and vector.y <- 0.75 ) then
2016-07-23 09:27:09 +02:00
param2 = 0
2014-08-13 17:37:00 +02:00
elseif ( vector.x >= 0 and vector.x <= 1 ) then
2016-07-23 09:27:09 +02:00
param2 = 16
2014-08-13 17:37:00 +02:00
elseif ( vector.x < 0 and vector.x >=- 1 ) then
2016-07-23 09:27:09 +02:00
param2 = 12
2014-08-13 17:37:00 +02:00
end
2016-07-23 09:27:09 +02:00
-- +X
2014-08-13 17:37:00 +02:00
elseif posabove.x > posunder.x then
if ( vector.y > 0.75 and vector.y <= 1 ) then
2016-07-23 09:27:09 +02:00
param2 = 21
2014-08-13 17:37:00 +02:00
elseif ( vector.y >=- 1 and vector.y <- 0.75 ) then
2016-07-23 09:27:09 +02:00
param2 = 3
2014-08-13 17:37:00 +02:00
elseif ( vector.z >= 0 and vector.z <= 1 ) then
2016-07-23 09:27:09 +02:00
param2 = 11
2014-08-13 17:37:00 +02:00
elseif ( vector.z < 0 and vector.z >=- 1 ) then
2016-07-23 09:27:09 +02:00
param2 = 7
2014-08-13 17:37:00 +02:00
end
2016-07-23 09:27:09 +02:00
-- -X
2014-08-13 17:37:00 +02:00
elseif posabove.x < posunder.x then
if ( vector.y > 0.75 and vector.y <= 1 ) then
2016-07-23 09:27:09 +02:00
param2 = 23
2014-08-13 17:37:00 +02:00
elseif ( vector.y >=- 1 and vector.y <- 0.75 ) then
2016-07-23 09:27:09 +02:00
param2 = 1
2014-08-13 17:37:00 +02:00
elseif ( vector.z >= 0 and vector.z <= 1 ) then
2016-07-23 09:27:09 +02:00
param2 = 9
2014-08-13 17:37:00 +02:00
elseif ( vector.z < 0 and vector.z >=- 1 ) then
2016-07-23 09:27:09 +02:00
param2 = 5
2014-08-13 17:37:00 +02:00
end
2014-03-19 05:43:07 +01:00
end
2014-08-13 17:37:00 +02:00
2016-07-23 09:27:09 +02:00
return minetest.item_place_node ( itemstack , placer , pointed_thing , param2 )
2014-03-19 05:43:07 +01:00
end
2016-09-07 16:47:21 +02:00
local matrix = {
-- Mounted on Ground (-Y)
[ 10 ] = 19 ,
[ 19 ] = 4 ,
[ 4 ] = 13 ,
[ 13 ] = 10 ,
-- Mounted on Top (+Y)
[ 8 ] = 17 ,
[ 17 ] = 6 ,
[ 6 ] = 15 ,
[ 15 ] = 8 ,
-- Mounted at South (-Z)
[ 2 ] = 18 , -- down
[ 18 ] = 22 , -- left
[ 22 ] = 14 , -- up
[ 14 ] = 2 , -- right
-- Mounted at North (+Z)
[ 0 ] = 12 , -- down
[ 12 ] = 20 , -- left
[ 20 ] = 16 , -- up
[ 16 ] = 0 , -- right
-- Mounted at West (-X)
[ 3 ] = 7 , -- down
[ 7 ] = 21 , -- left
[ 21 ] = 11 , -- up
[ 11 ] = 3 , -- right
-- Mounted at East (+X)
[ 1 ] = 9 , -- down
[ 9 ] = 23 , -- left
[ 23 ] = 5 , -- up
[ 5 ] = 1 , -- right
}
arrow_signs.on_rotate = function ( pos , node , player , mode , new_param2 )
node.param2 = matrix [ node.param2 ] or 0 --in case of error
minetest.swap_node ( pos , node )
return true
end
2015-03-13 15:02:54 +01:00
arrow_signs.savetext = function ( pos , formname , fields , sender )
if fields.text then
2016-07-23 09:27:09 +02:00
local playername = sender : get_player_name ( ) or " "
if minetest.is_protected ( pos , playername ) then
minetest.record_protection_violation ( pos , playername )
2015-04-03 10:38:51 +02:00
return
end
2014-01-05 19:01:57 +01:00
local meta = minetest.get_meta ( pos )
2016-07-23 09:27:09 +02:00
minetest.log ( " action " , string.format ( " %q wrote %q to sign at %s " , playername , fields.text , minetest.pos_to_string ( pos ) ) ) ;
2013-07-14 17:26:30 +02:00
meta : set_string ( " text " , fields.text )
2016-07-23 09:27:09 +02:00
local text , lines = arrow_signs.create_lines ( fields.text )
2013-07-14 17:26:30 +02:00
meta : set_string ( " infotext " , ' " ' .. text .. ' " ' )
2016-07-23 09:27:09 +02:00
if lines >= 6 then
minetest.chat_send_player ( playername , " Information: \n You've written " .. lines .. " lines. \n The sign can only display 5 lines \n Please remove the last entries " )
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 /
2016-07-23 09:27:09 +02:00
return text , n + m + 1
2013-07-14 17:26:30 +02:00
end
2016-07-22 17:06:36 +02:00
arrow_signs.nodebox = {
type = " fixed " ,
fixed = {
2016-07-23 05:29:56 +02:00
{ 0.25 , - 0.25 , 0.4375 , - 0.25 , 0.5 , 0.5 } ,
{ 0.1875 , - 0.3125 , 0.4375 , - 0.1875 , - 0.25 , 0.5 } ,
{ 0.125 , - 0.3125 , 0.4375 , - 0.125 , - 0.375 , 0.5 } ,
{ 0.0625 , - 0.375 , 0.4375 , - 0.0625 , - 0.437 , 0.5 }
2016-07-22 17:06:36 +02:00
}
}
arrow_signs.selection_box = {
2016-07-22 16:40:41 +02:00
type = " fixed " ,
fixed = {
2016-07-23 05:29:56 +02:00
{ 0.30 , - 0.5 , 0.4375 , - 0.30 , 0.5 , 0.5 }
2016-07-22 16:40:41 +02:00
}
2013-07-14 17:26:30 +02:00
}
2014-01-05 19:01:57 +01:00
2016-07-22 17:06:36 +02:00
local MODPATH = minetest.get_modpath ( " arrow_signs " )
2013-07-14 17:26:30 +02:00
2016-07-22 17:06:36 +02:00
-- Wooden Sign
dofile ( MODPATH .. " /wood.lua " )
2016-07-23 06:35:59 +02:00
-- Steel Sign
dofile ( MODPATH .. " /steel.lua " )
2016-07-22 17:06:36 +02:00
--Shared Locked sign
if minetest.get_modpath ( " locks " ) then
2014-08-13 17:37:00 +02:00
dofile ( MODPATH .. " /shared_locked.lua " )
2016-07-22 17:06:36 +02:00
end
2018-12-24 02:29:28 +01:00
minetest.log ( " action " , " [arrow_signs] loaded. " )