forked from mtcontrib/arrow_signs
Huge Improvements for sign placing
* respect protected areas * respect creative mode
This commit is contained in:
parent
e74f54c342
commit
c65a10ac27
105
init.lua
105
init.lua
@ -13,122 +13,101 @@
|
|||||||
|
|
||||||
arrow_signs={}
|
arrow_signs={}
|
||||||
|
|
||||||
arrow_signs.formspec = "field[text;Sign text:;${text}]";
|
arrow_signs.formspec = "field[text;Sign text: (Hint: Use / or | to create a new line);${text}]";
|
||||||
|
|
||||||
local creative = minetest.setting_getbool("creative_mode") or false
|
|
||||||
arrow_signs.on_place = function(itemstack, placer, pointed_thing)
|
arrow_signs.on_place = function(itemstack, placer, pointed_thing)
|
||||||
|
|
||||||
local posabove = pointed_thing.above
|
local posabove = pointed_thing.above
|
||||||
local posunder = pointed_thing.under
|
local posunder = pointed_thing.under
|
||||||
local vector = placer:get_look_dir()
|
local vector = placer:get_look_dir()
|
||||||
local place = true
|
local param2 = 0
|
||||||
|
|
||||||
|
-- I wonder if there is a way to calculate the param2 instad of using so much if here.
|
||||||
|
-- +Y
|
||||||
if posabove.y>posunder.y then
|
if posabove.y>posunder.y then
|
||||||
if(vector.z>0.5 and vector.z<=1) then
|
if(vector.z>0.5 and vector.z<=1) then
|
||||||
minetest.add_node(posabove,{name = itemstack:get_name(), param2 = 10})
|
param2 = 10
|
||||||
elseif (vector.x>0.5 and vector.x<=1) then
|
elseif (vector.x>0.5 and vector.x<=1) then
|
||||||
minetest.add_node(posabove,{name = itemstack:get_name(), param2 = 19})
|
param2 = 19
|
||||||
elseif(-0.5>vector.z and -1<=vector.z) then
|
elseif(-0.5>vector.z and -1<=vector.z) then
|
||||||
minetest.add_node(posabove,{name = itemstack:get_name(), param2 = 4})
|
param2 = 4
|
||||||
elseif (-0.5>vector.x and -1<=vector.x) then
|
elseif (-0.5>vector.x and -1<=vector.x) then
|
||||||
minetest.add_node(posabove,{name = itemstack:get_name(), param2 = 13})
|
param2 = 13
|
||||||
else
|
|
||||||
place = false
|
|
||||||
end
|
end
|
||||||
|
-- -Y
|
||||||
elseif posabove.y<posunder.y then
|
elseif posabove.y<posunder.y then
|
||||||
if(vector.z>0.5 and vector.z<=1) then
|
if(vector.z>0.5 and vector.z<=1) then
|
||||||
minetest.add_node(posabove,{name = itemstack:get_name(), param2 = 8})
|
param2 = 8
|
||||||
elseif (vector.x>0.5 and vector.x<=1) then
|
elseif (vector.x>0.5 and vector.x<=1) then
|
||||||
minetest.add_node(posabove,{name = itemstack:get_name(), param2 = 17})
|
param2 = 17
|
||||||
elseif(-0.5>vector.z and -1<=vector.z) then
|
elseif(-0.5>vector.z and -1<=vector.z) then
|
||||||
minetest.add_node(posabove,{name = itemstack:get_name(), param2 = 6})
|
param2 = 6
|
||||||
elseif (-0.5>vector.x and -1<=vector.x) then
|
elseif (-0.5>vector.x and -1<=vector.x) then
|
||||||
minetest.add_node(posabove,{name = itemstack:get_name(), param2 = 15})
|
param2 = 15
|
||||||
else
|
|
||||||
place = false
|
|
||||||
end
|
end
|
||||||
|
-- +Z
|
||||||
elseif posabove.z>posunder.z then
|
elseif posabove.z>posunder.z then
|
||||||
if(vector.y>0.75 and vector.y<=1) then
|
if(vector.y>0.75 and vector.y<=1) then
|
||||||
minetest.add_node(posabove,{name = itemstack:get_name(), param2 = 22})
|
param2 = 22
|
||||||
elseif (vector.y>=-1 and vector.y<-0.75) then
|
elseif (vector.y>=-1 and vector.y<-0.75) then
|
||||||
minetest.add_node(posabove,{name = itemstack:get_name(), param2 = 2})
|
param2 = 2
|
||||||
elseif (vector.x>=0 and vector.x<=1) then
|
elseif (vector.x>=0 and vector.x<=1) then
|
||||||
minetest.add_node(posabove,{name = itemstack:get_name(), param2 = 18})
|
param2 = 18
|
||||||
elseif (vector.x<0 and vector.x>=-1) then
|
elseif (vector.x<0 and vector.x>=-1) then
|
||||||
minetest.add_node(posabove,{name = itemstack:get_name(), param2 = 14})
|
param2 = 14
|
||||||
else
|
|
||||||
place = false
|
|
||||||
end
|
end
|
||||||
|
-- -Z
|
||||||
elseif posabove.z<posunder.z then
|
elseif posabove.z<posunder.z then
|
||||||
if(vector.y>0.75 and vector.y<=1) then
|
if(vector.y>0.75 and vector.y<=1) then
|
||||||
minetest.add_node(posabove,{name = itemstack:get_name(), param2 = 20})
|
param2 = 20
|
||||||
elseif (vector.y>=-1 and vector.y<-0.75) then
|
elseif (vector.y>=-1 and vector.y<-0.75) then
|
||||||
minetest.add_node(posabove,{name = itemstack:get_name(), param2 = 0})
|
param2 = 0
|
||||||
elseif (vector.x>=0 and vector.x<=1) then
|
elseif (vector.x>=0 and vector.x<=1) then
|
||||||
minetest.add_node(posabove,{name = itemstack:get_name(), param2 = 16})
|
param2 = 16
|
||||||
elseif (vector.x<0 and vector.x>=-1) then
|
elseif (vector.x<0 and vector.x>=-1) then
|
||||||
minetest.add_node(posabove,{name = itemstack:get_name(), param2 = 12})
|
param2 = 12
|
||||||
else
|
|
||||||
place = false
|
|
||||||
end
|
end
|
||||||
|
-- +X
|
||||||
elseif posabove.x>posunder.x then
|
elseif posabove.x>posunder.x then
|
||||||
if(vector.y>0.75 and vector.y<=1) then
|
if(vector.y>0.75 and vector.y<=1) then
|
||||||
minetest.add_node(posabove,{name = itemstack:get_name(), param2 = 21})
|
param2 = 21
|
||||||
elseif (vector.y>=-1 and vector.y<-0.75) then
|
elseif (vector.y>=-1 and vector.y<-0.75) then
|
||||||
minetest.add_node(posabove,{name = itemstack:get_name(), param2 = 3})
|
param2 = 3
|
||||||
elseif (vector.z>=0 and vector.z<=1) then
|
elseif (vector.z>=0 and vector.z<=1) then
|
||||||
minetest.add_node(posabove,{name = itemstack:get_name(), param2 = 11})
|
param2 = 11
|
||||||
elseif (vector.z<0 and vector.z>=-1) then
|
elseif (vector.z<0 and vector.z>=-1) then
|
||||||
minetest.add_node(posabove,{name = itemstack:get_name(), param2 = 7})
|
param2 = 7
|
||||||
else
|
|
||||||
place = false
|
|
||||||
end
|
end
|
||||||
|
-- -X
|
||||||
elseif posabove.x<posunder.x then
|
elseif posabove.x<posunder.x then
|
||||||
if(vector.y>0.75 and vector.y<=1) then
|
if(vector.y>0.75 and vector.y<=1) then
|
||||||
minetest.add_node(posabove,{name = itemstack:get_name(), param2 = 23})
|
param2 = 23
|
||||||
elseif (vector.y>=-1 and vector.y<-0.75) then
|
elseif (vector.y>=-1 and vector.y<-0.75) then
|
||||||
minetest.add_node(posabove,{name = itemstack:get_name(), param2 = 1})
|
param2 = 1
|
||||||
elseif (vector.z>=0 and vector.z<=1) then
|
elseif (vector.z>=0 and vector.z<=1) then
|
||||||
minetest.add_node(posabove,{name = itemstack:get_name(), param2 = 9})
|
param2 = 9
|
||||||
elseif (vector.z<0 and vector.z>=-1) then
|
elseif (vector.z<0 and vector.z>=-1) then
|
||||||
minetest.add_node(posabove,{name = itemstack:get_name(), param2 = 5})
|
param2 = 5
|
||||||
else
|
|
||||||
place = false
|
|
||||||
end
|
end
|
||||||
else
|
|
||||||
place = false
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if place then
|
return minetest.item_place_node(itemstack, placer, pointed_thing, param2)
|
||||||
if not creative then
|
|
||||||
itemstack:take_item()
|
|
||||||
end
|
|
||||||
else
|
|
||||||
itemstack = minetest.rotate_node(itemstack, placer, pointed_thing)
|
|
||||||
end
|
|
||||||
|
|
||||||
return itemstack
|
|
||||||
end
|
end
|
||||||
|
|
||||||
arrow_signs.savetext = function(pos, formname, fields, sender)
|
arrow_signs.savetext = function(pos, formname, fields, sender)
|
||||||
if fields.text then
|
if fields.text then
|
||||||
if not minetest.get_player_privs(sender:get_player_name())["interact"] then
|
local playername = sender:get_player_name() or ""
|
||||||
minetest.chat_send_player(sender:get_player_name(), "error: you don't have permission to edit the sign. you need the interact priv")
|
if minetest.is_protected(pos, playername) then
|
||||||
return
|
minetest.record_protection_violation(pos, playername)
|
||||||
end
|
|
||||||
if minetest.is_protected(pos, sender:get_player_name()) then
|
|
||||||
minetest.record_protection_violation(pos, sender:get_player_name())
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
fields.text = fields.text or ""
|
minetest.log("action", string.format("%q wrote %q to sign at %s", playername, fields.text, minetest.pos_to_string(pos)));
|
||||||
minetest.log("action", (sender:get_player_name() or "").." wrote \""..fields.text..
|
|
||||||
"\" to sign at "..minetest.pos_to_string(pos));
|
|
||||||
meta:set_string("text", fields.text)
|
meta:set_string("text", fields.text)
|
||||||
local text,lines = arrow_signs.create_lines(fields.text)
|
local text, lines = arrow_signs.create_lines(fields.text)
|
||||||
meta:set_string("infotext", '"'..text..'"')
|
meta:set_string("infotext", '"'..text..'"')
|
||||||
if lines > 4 then
|
if lines >= 6 then
|
||||||
minetest.chat_send_player(sender:get_player_name(),"Information: \nYou've written more than 5 lines. \nIt may be that not all lines are displayed. \nPlease remove the last entry")
|
minetest.chat_send_player(playername, "Information: \nYou've written "..lines.." lines. \nThe sign can only display 5 lines \nPlease remove the last entries")
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
@ -138,7 +117,7 @@ end
|
|||||||
arrow_signs.create_lines = function(text)
|
arrow_signs.create_lines = function(text)
|
||||||
local text, n = text:gsub("[ ]*(%|)[ ]*", '"\n"')--search for |
|
local text, n = text:gsub("[ ]*(%|)[ ]*", '"\n"')--search for |
|
||||||
local text, m = text:gsub("[ ]*(%/)[ ]*", '"\n"')--search for /
|
local text, m = text:gsub("[ ]*(%/)[ ]*", '"\n"')--search for /
|
||||||
return text, n+m
|
return text, n+m+1
|
||||||
end
|
end
|
||||||
|
|
||||||
arrow_signs.nodebox = {
|
arrow_signs.nodebox = {
|
||||||
|
Loading…
Reference in New Issue
Block a user