New method for place signs.

This commit is contained in:
Jat 2014-08-13 17:37:00 +02:00
parent 9b4970622a
commit 129efd98d8

114
init.lua
View File

@ -7,47 +7,95 @@
arrow_signs={}
arrow_signs_on_place = function(itemstack, placer, pointed_thing)
local function transformvector(vector)
local vectorlist ={
{cmin = -1, cmax = -0.5},
{cmin = -0.5, cmax = 0},
{cmin = 0, cmax = 0.5},
{cmin = 0.5, cmax = 1}
}
local r = {}
for n,res in pairs(vector) do
for ia=1,table.getn(vectorlist) do
if vectorlist[ia].cmin<res and vectorlist[ia].cmax>res then
r[n]=ia
end
end
end
return r["x"]*10+r["z"]
end
local pos = pointed_thing.above
local vector = transformvector(placer:get_look_dir())
local changer = {
{31,5},
{12,14},
{24,11},
{43,16},
}
local place = false
local posabove = pointed_thing.above
local posunder = pointed_thing.under
local vector = placer:get_look_dir()
local place = true
for i=1,table.getn(changer) do
if vector == changer[i][1] then
minetest.add_node(pos,{name = itemstack:get_name(), param2 = changer[i][2]})
place = true
break
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
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 = 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
end
if not(place) then
minetest.rotate_node(itemstack, placer, pointed_thing)
else
itemstack:take_item()
return itemstack
end
end
function arrow_signs:savetext(pos, formname, fields, sender)
@ -186,6 +234,6 @@ minetest.register_abm({
--Locked sign
if locks then
local MODPATH = minetest.get_modpath("arrow_signs");
dofile(MODPATH.."/shared_locked.lua")
local MODPATH = minetest.get_modpath("arrow_signs");
dofile(MODPATH.."/shared_locked.lua")
end