forked from nalc/homedecor_modpack
Split ownership checking and 6d facedir into separate files. Changed
related functions to use homedecor: and lib_6d: namespaces, as necessary, instead of simple "homedecor_" name prefixes.
This commit is contained in:
80
lighting.lua
80
lighting.lua
@ -10,56 +10,6 @@ else
|
||||
S = function ( s ) return s end
|
||||
end
|
||||
|
||||
local dirs1 = { 20, 23, 22, 21 }
|
||||
local dirs2 = { 9, 18, 7, 12 }
|
||||
|
||||
function homedecor.rotate_and_place(itemstack, placer, pointed_thing)
|
||||
if not homedecor.node_is_owned(pointed_thing.under, placer)
|
||||
and not homedecor.node_is_owned(pointed_thing.above, placer) then
|
||||
local node = minetest.get_node(pointed_thing.under)
|
||||
if not minetest.registered_nodes[node.name] or not minetest.registered_nodes[node.name].on_rightclick then
|
||||
|
||||
local above = pointed_thing.above
|
||||
local under = pointed_thing.under
|
||||
local pitch = placer:get_look_pitch()
|
||||
local pname = minetest.get_node(under).name
|
||||
local node = minetest.get_node(above)
|
||||
local fdir = minetest.dir_to_facedir(placer:get_look_dir())
|
||||
local wield_name = itemstack:get_name()
|
||||
|
||||
if not minetest.registered_nodes[pname]
|
||||
or not minetest.registered_nodes[pname].on_rightclick then
|
||||
|
||||
local iswall = (above.x ~= under.x) or (above.z ~= under.z)
|
||||
local isceiling = (above.x == under.x) and (above.z == under.z) and (pitch > 0)
|
||||
local pos1 = above
|
||||
|
||||
if minetest.registered_nodes[pname]["buildable_to"] then
|
||||
pos1 = under
|
||||
iswall = false
|
||||
end
|
||||
|
||||
if not minetest.registered_nodes[minetest.get_node(pos1).name]["buildable_to"] then return end
|
||||
|
||||
if iswall then
|
||||
minetest.add_node(pos1, {name = wield_name, param2 = dirs2[fdir+1] }) -- place wall variant
|
||||
elseif isceiling then
|
||||
minetest.add_node(pos1, {name = wield_name, param2 = 20 }) -- place upside down variant
|
||||
else
|
||||
minetest.add_node(pos1, {name = wield_name, param2 = 0 }) -- place right side up
|
||||
end
|
||||
|
||||
if not homedecor.expect_infinite_stacks then
|
||||
itemstack:take_item()
|
||||
return itemstack
|
||||
end
|
||||
end
|
||||
else
|
||||
minetest.registered_nodes[node.name].on_rightclick(pointed_thing.under, node, placer, itemstack)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local colors = {"yellow","white"}
|
||||
|
||||
for i in ipairs(colors) do
|
||||
@ -146,7 +96,10 @@ minetest.register_node('homedecor:glowlight_half_yellow', {
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
|
||||
on_place = function(itemstack, placer, pointed_thing)
|
||||
homedecor.rotate_and_place(itemstack, placer, pointed_thing)
|
||||
if not homedecor:node_is_owned(pointed_thing.under, placer)
|
||||
and not homedecor:node_is_owned(pointed_thing.above, placer) then
|
||||
lib_6d:rotate_and_place(itemstack, placer, pointed_thing, homedecor.expect_infinite_stacks)
|
||||
end
|
||||
return itemstack
|
||||
end
|
||||
})
|
||||
@ -179,7 +132,10 @@ minetest.register_node('homedecor:glowlight_quarter_yellow', {
|
||||
light_source = LIGHT_MAX-1,
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
on_place = function(itemstack, placer, pointed_thing)
|
||||
homedecor.rotate_and_place(itemstack, placer, pointed_thing)
|
||||
if not homedecor:node_is_owned(pointed_thing.under, placer)
|
||||
and not homedecor:node_is_owned(pointed_thing.above, placer) then
|
||||
lib_6d:rotate_and_place(itemstack, placer, pointed_thing, homedecor.expect_infinite_stacks)
|
||||
end
|
||||
return itemstack
|
||||
end
|
||||
})
|
||||
@ -216,7 +172,10 @@ minetest.register_node('homedecor:glowlight_half_white', {
|
||||
light_source = LIGHT_MAX,
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
on_place = function(itemstack, placer, pointed_thing)
|
||||
homedecor.rotate_and_place(itemstack, placer, pointed_thing)
|
||||
if not homedecor:node_is_owned(pointed_thing.under, placer)
|
||||
and not homedecor:node_is_owned(pointed_thing.above, placer) then
|
||||
lib_6d:rotate_and_place(itemstack, placer, pointed_thing, homedecor.expect_infinite_stacks)
|
||||
end
|
||||
return itemstack
|
||||
end
|
||||
})
|
||||
@ -249,7 +208,10 @@ minetest.register_node('homedecor:glowlight_quarter_white', {
|
||||
light_source = LIGHT_MAX-1,
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
on_place = function(itemstack, placer, pointed_thing)
|
||||
homedecor.rotate_and_place(itemstack, placer, pointed_thing)
|
||||
if not homedecor:node_is_owned(pointed_thing.under, placer)
|
||||
and not homedecor:node_is_owned(pointed_thing.above, placer) then
|
||||
lib_6d:rotate_and_place(itemstack, placer, pointed_thing, homedecor.expect_infinite_stacks)
|
||||
end
|
||||
return itemstack
|
||||
end
|
||||
})
|
||||
@ -285,7 +247,10 @@ minetest.register_node('homedecor:glowlight_small_cube_yellow', {
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
|
||||
on_place = function(itemstack, placer, pointed_thing)
|
||||
homedecor.rotate_and_place(itemstack, placer, pointed_thing)
|
||||
if not homedecor:node_is_owned(pointed_thing.under, placer)
|
||||
and not homedecor:node_is_owned(pointed_thing.above, placer) then
|
||||
lib_6d:rotate_and_place(itemstack, placer, pointed_thing, homedecor.expect_infinite_stacks)
|
||||
end
|
||||
return itemstack
|
||||
end
|
||||
})
|
||||
@ -318,7 +283,10 @@ minetest.register_node('homedecor:glowlight_small_cube_white', {
|
||||
light_source = LIGHT_MAX-1,
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
on_place = function(itemstack, placer, pointed_thing)
|
||||
homedecor.rotate_and_place(itemstack, placer, pointed_thing)
|
||||
if not homedecor:node_is_owned(pointed_thing.under, placer)
|
||||
and not homedecor:node_is_owned(pointed_thing.above, placer) then
|
||||
lib_6d:rotate_and_place(itemstack, placer, pointed_thing, homedecor.expect_infinite_stacks)
|
||||
end
|
||||
return itemstack
|
||||
end
|
||||
})
|
||||
|
Reference in New Issue
Block a user