mirror of
https://github.com/mt-mods/homedecor_modpack.git
synced 2024-12-23 00:20:17 +01:00
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:
parent
92d8a53f5b
commit
e4c02a82d6
@ -281,8 +281,8 @@ function homedecor.place_door(itemstack, placer, pointed_thing, name, side)
|
||||
local node_bottom = minetest.get_node(pos1)
|
||||
local node_top = minetest.get_node(pos2)
|
||||
|
||||
if not homedecor.node_is_owned(pos1, placer)
|
||||
and not homedecor.node_is_owned(pos2, placer) then
|
||||
if not homedecor:node_is_owned(pos1, placer)
|
||||
and not homedecor:node_is_owned(pos2, placer) then
|
||||
|
||||
if not get_nodedef_field(node_bottom.name, "buildable_to")
|
||||
or not get_nodedef_field(node_top.name, "buildable_to") then
|
||||
|
44
init.lua
44
init.lua
@ -13,6 +13,8 @@
|
||||
|
||||
homedecor = {}
|
||||
|
||||
|
||||
homedecor.disable_signs = minetest.setting_getbool("homedecor.disable_signs")
|
||||
homedecor.debug = 0
|
||||
|
||||
homedecor.modpath = minetest.get_modpath("homedecor")
|
||||
@ -27,57 +29,21 @@ else
|
||||
S = function ( s ) return s end
|
||||
end
|
||||
|
||||
-- Global stuff
|
||||
|
||||
homedecor.disable_signs = minetest.setting_getbool("homedecor.disable_signs")
|
||||
|
||||
-- Various Functions
|
||||
|
||||
local dbg = function(s)
|
||||
if homedecor.debug == 1 then
|
||||
print('[HomeDecor] ' .. s)
|
||||
end
|
||||
end
|
||||
|
||||
function homedecor.node_is_owned(pos, placer)
|
||||
local ownername = false
|
||||
if type(IsPlayerNodeOwner) == "function" then -- node_ownership mod
|
||||
if HasOwner(pos, placer) then -- returns true if the node is owned
|
||||
if not IsPlayerNodeOwner(pos, placer:get_player_name()) then
|
||||
if type(getLastOwner) == "function" then -- ...is an old version
|
||||
ownername = getLastOwner(pos)
|
||||
elseif type(GetNodeOwnerName) == "function" then -- ...is a recent version
|
||||
ownername = GetNodeOwnerName(pos)
|
||||
else
|
||||
ownername = S("someone")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
elseif type(isprotect)=="function" then -- glomie's protection mod
|
||||
if not isprotect(5, pos, placer) then
|
||||
ownername = S("someone")
|
||||
end
|
||||
elseif type(protector)=="table" and type(protector.can_dig)=="function" then -- Zeg9's protection mod
|
||||
if not protector.can_dig(5, pos, placer) then
|
||||
ownername = S("someone")
|
||||
end
|
||||
end
|
||||
|
||||
if ownername ~= false then
|
||||
minetest.chat_send_player( placer:get_player_name(), S("Sorry, %s owns that spot."):format(ownername) )
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
if minetest.get_modpath("unified_inventory") or not minetest.setting_getbool("creative_mode") then
|
||||
homedecor.expect_infinite_stacks = false
|
||||
else
|
||||
homedecor.expect_infinite_stacks = true
|
||||
end
|
||||
|
||||
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.."/tables.lua")
|
||||
dofile(homedecor.modpath.."/electronics.lua")
|
||||
|
52
lib_6d.lua
Normal file
52
lib_6d.lua
Normal file
@ -0,0 +1,52 @@
|
||||
-- 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
|
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
|
||||
})
|
||||
|
32
ownership.lua
Normal file
32
ownership.lua
Normal file
@ -0,0 +1,32 @@
|
||||
function homedecor:node_is_owned(pos, placer)
|
||||
local ownername = false
|
||||
if type(IsPlayerNodeOwner) == "function" then -- node_ownership mod
|
||||
if HasOwner(pos, placer) then -- returns true if the node is owned
|
||||
if not IsPlayerNodeOwner(pos, placer:get_player_name()) then
|
||||
if type(getLastOwner) == "function" then -- ...is an old version
|
||||
ownername = getLastOwner(pos)
|
||||
elseif type(GetNodeOwnerName) == "function" then -- ...is a recent version
|
||||
ownername = GetNodeOwnerName(pos)
|
||||
else
|
||||
ownername = S("someone")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
elseif type(isprotect)=="function" then -- glomie's protection mod
|
||||
if not isprotect(5, pos, placer) then
|
||||
ownername = S("someone")
|
||||
end
|
||||
elseif type(protector)=="table" and type(protector.can_dig)=="function" then -- Zeg9's protection mod
|
||||
if not protector.can_dig(5, pos, placer) then
|
||||
ownername = S("someone")
|
||||
end
|
||||
end
|
||||
|
||||
if ownername ~= false then
|
||||
minetest.chat_send_player( placer:get_player_name(), S("Sorry, %s owns that spot."):format(ownername) )
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
@ -119,13 +119,13 @@ if not homedecor.disable_signs then
|
||||
local name
|
||||
name = minetest.get_node(pointed_thing.under).name
|
||||
if fences_with_sign[name] then
|
||||
if homedecor.node_is_owned(pointed_thing.under, placer) then
|
||||
if homedecor:node_is_owned(pointed_thing.under, placer) then
|
||||
return itemstack
|
||||
end
|
||||
else
|
||||
name = minetest.get_node(pointed_thing.above).name
|
||||
local def = minetest.registered_nodes[name]
|
||||
if homedecor.node_is_owned(pointed_thing.above, placer)
|
||||
if homedecor:node_is_owned(pointed_thing.above, placer)
|
||||
or (not def.buildable_to) then
|
||||
return itemstack
|
||||
end
|
||||
@ -202,7 +202,7 @@ if not homedecor.disable_signs then
|
||||
minetest.pos_to_string(pos)
|
||||
))
|
||||
end
|
||||
if homedecor.node_is_owned(pos, sender) then return end
|
||||
if homedecor:node_is_owned(pos, sender) then return end
|
||||
homedecor.update_sign(pos, fields)
|
||||
end,
|
||||
on_punch = function(pos, node, puncher)
|
||||
@ -239,7 +239,7 @@ minetest.register_node(":signs:sign_yard", {
|
||||
minetest.pos_to_string(pos)
|
||||
))
|
||||
end
|
||||
if homedecor.node_is_owned(pos, sender) then return end
|
||||
if homedecor:node_is_owned(pos, sender) then return end
|
||||
homedecor.update_sign(pos, fields)
|
||||
end,
|
||||
on_punch = function(pos, node, puncher)
|
||||
@ -443,7 +443,7 @@ function homedecor.register_fence_with_sign(fencename, fencewithsignname)
|
||||
local fdir = minetest.dir_to_facedir(placer:get_look_dir())
|
||||
if def_under and def_under.on_rightclick then
|
||||
return def_under.on_rightclick(pointed_thing.under, node_under, placer, itemstack) or itemstack
|
||||
elseif (not homedecor.node_is_owned(pointed_thing.under, placer))
|
||||
elseif (not homedecor:node_is_owned(pointed_thing.under, placer))
|
||||
and def_under.buildable_to then
|
||||
minetest.add_node(pointed_thing.under, {name = fencename, param2 = fdir})
|
||||
if not homedecor.expect_infinite_stacks then
|
||||
@ -451,7 +451,7 @@ function homedecor.register_fence_with_sign(fencename, fencewithsignname)
|
||||
end
|
||||
placer:set_wielded_item(itemstack)
|
||||
return itemstack
|
||||
elseif (not homedecor.node_is_owned(pointed_thing.above, placer))
|
||||
elseif (not homedecor:node_is_owned(pointed_thing.above, placer))
|
||||
and def_above.buildable_to then
|
||||
minetest.add_node(pointed_thing.above, {name = fencename, param2 = fdir})
|
||||
if not homedecor.expect_infinite_stacks then
|
||||
@ -475,7 +475,7 @@ function homedecor.register_fence_with_sign(fencename, fencewithsignname)
|
||||
minetest.pos_to_string(pos)
|
||||
))
|
||||
end
|
||||
if homedecor.node_is_owned(pos, sender) then return end
|
||||
if homedecor:node_is_owned(pos, sender) then return end
|
||||
homedecor.update_sign(pos, fields)
|
||||
end
|
||||
def_sign.on_punch = function(pos, node, puncher, ...)
|
||||
|
Loading…
Reference in New Issue
Block a user