Rewrite lighting to use engine's 6d facedir prediction code

changed the names of a couple of internal functions to compensate.

this makes lib_6d.lua obsolete.
This commit is contained in:
Vanessa Ezekowitz 2013-11-07 21:22:16 -05:00
parent dfd45b2c10
commit c8be033292
4 changed files with 21 additions and 99 deletions

View File

@ -59,8 +59,21 @@ function homedecor.table_copy(t)
return nt return nt
end end
-- protection wrapper for 6d stuff
function homedecor.protect_and_rotate(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 keys=placer:get_player_control()
minetest.rotate_and_place(itemstack, placer, pointed_thing,
homedecor.expect_infinite_stacks, {invert_wall = keys.sneak})
end
return itemstack
end
-- load various other components
dofile(homedecor.modpath.."/ownership.lua") dofile(homedecor.modpath.."/ownership.lua")
dofile(homedecor.modpath.."/lib_6d.lua")
dofile(homedecor.modpath.."/misc_nodes.lua") -- the catch-all for all misc nodes dofile(homedecor.modpath.."/misc_nodes.lua") -- the catch-all for all misc nodes
dofile(homedecor.modpath.."/tables.lua") dofile(homedecor.modpath.."/tables.lua")

View File

@ -1,52 +0,0 @@
-- Simplified 6d facedir rotation/prediction library
-- by VanessaE
-- license: WTFPL
lib_6d = {}
local dirs1 = { 20, 23, 22, 21 }
local dirs2 = { 9, 18, 7, 12 }
function lib_6d:rotate_and_place(itemstack, placer, pointed_thing, infinitestacks)
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 infinitestacks then
itemstack:take_item()
return itemstack
end
end
else
minetest.registered_nodes[node.name].on_rightclick(pointed_thing.under, node, placer, itemstack)
end
end

View File

@ -87,14 +87,7 @@ minetest.register_node('homedecor:glowlight_half_yellow', {
groups = { snappy = 3 }, groups = { snappy = 3 },
light_source = LIGHT_MAX, light_source = LIGHT_MAX,
sounds = default.node_sound_wood_defaults(), sounds = default.node_sound_wood_defaults(),
on_place = homedecor.protect_and_rotate
on_place = function(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
}) })
minetest.register_node('homedecor:glowlight_quarter_yellow', { minetest.register_node('homedecor:glowlight_quarter_yellow', {
@ -124,17 +117,9 @@ minetest.register_node('homedecor:glowlight_quarter_yellow', {
groups = { snappy = 3 }, groups = { snappy = 3 },
light_source = LIGHT_MAX-1, light_source = LIGHT_MAX-1,
sounds = default.node_sound_wood_defaults(), sounds = default.node_sound_wood_defaults(),
on_place = function(itemstack, placer, pointed_thing) on_place = homedecor.protect_and_rotate
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
}) })
-- White -- White
minetest.register_node('homedecor:glowlight_half_white', { minetest.register_node('homedecor:glowlight_half_white', {
@ -164,13 +149,7 @@ minetest.register_node('homedecor:glowlight_half_white', {
groups = { snappy = 3 }, groups = { snappy = 3 },
light_source = LIGHT_MAX, light_source = LIGHT_MAX,
sounds = default.node_sound_wood_defaults(), sounds = default.node_sound_wood_defaults(),
on_place = function(itemstack, placer, pointed_thing) on_place = homedecor.protect_and_rotate
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
}) })
minetest.register_node('homedecor:glowlight_quarter_white', { minetest.register_node('homedecor:glowlight_quarter_white', {
@ -200,13 +179,7 @@ minetest.register_node('homedecor:glowlight_quarter_white', {
groups = { snappy = 3 }, groups = { snappy = 3 },
light_source = LIGHT_MAX-1, light_source = LIGHT_MAX-1,
sounds = default.node_sound_wood_defaults(), sounds = default.node_sound_wood_defaults(),
on_place = function(itemstack, placer, pointed_thing) on_place = homedecor.protect_and_rotate
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
}) })
-- Glowlight "cubes" -- Glowlight "cubes"
@ -239,13 +212,7 @@ minetest.register_node('homedecor:glowlight_small_cube_yellow', {
light_source = LIGHT_MAX-1, light_source = LIGHT_MAX-1,
sounds = default.node_sound_wood_defaults(), sounds = default.node_sound_wood_defaults(),
on_place = function(itemstack, placer, pointed_thing) on_place = homedecor.protect_and_rotate
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
}) })
minetest.register_node('homedecor:glowlight_small_cube_white', { minetest.register_node('homedecor:glowlight_small_cube_white', {
@ -275,12 +242,6 @@ minetest.register_node('homedecor:glowlight_small_cube_white', {
groups = { snappy = 3 }, groups = { snappy = 3 },
light_source = LIGHT_MAX-1, light_source = LIGHT_MAX-1,
sounds = default.node_sound_wood_defaults(), sounds = default.node_sound_wood_defaults(),
on_place = function(itemstack, placer, pointed_thing) on_place = homedecor.protect_and_rotate
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
}) })

View File

@ -1,7 +1,7 @@
local S = homedecor.gettext local S = homedecor.gettext
function homedecor:node_is_owned(pos, placer) function homedecor.node_is_owned(pos, placer)
local ownername = false local ownername = false
if type(IsPlayerNodeOwner) == "function" then -- node_ownership mod if type(IsPlayerNodeOwner) == "function" then -- node_ownership mod
if HasOwner(pos, placer) then -- returns true if the node is owned if HasOwner(pos, placer) then -- returns true if the node is owned