forked from nalc/homedecor_modpack
Remove old ownership code and use Minetest's built-in ownership code instead
Some minor code rewrites here and there to accommodate this changeover.
This commit is contained in:
parent
b11b3a95ec
commit
a6122f03d9
|
@ -424,14 +424,19 @@ function homedecor.place_door(itemstack, placer, pointed_thing, name, forceright
|
|||
local pointed = pointed_thing.under
|
||||
local pnode = minetest.get_node(pointed)
|
||||
local pname = pnode.name
|
||||
local rnodedef = minetest.registered_nodes[pname]
|
||||
|
||||
if not minetest.registered_nodes[pname]
|
||||
or not minetest.registered_nodes[pname].on_rightclick then
|
||||
if rnodedef then
|
||||
|
||||
if rnodedef.on_rightclick then
|
||||
rnodedef.on_rightclick(pointed_thing.under, pnode, placer, itemstack)
|
||||
return
|
||||
end
|
||||
|
||||
local pos1 = nil
|
||||
local pos2 = nil
|
||||
|
||||
if minetest.registered_nodes[pname]["buildable_to"] then
|
||||
if rnodedef["buildable_to"] then
|
||||
pos1 = pointed
|
||||
pos2 = {x=pointed.x, y=pointed.y+1, z=pointed.z}
|
||||
else
|
||||
|
@ -442,8 +447,17 @@ function homedecor.place_door(itemstack, placer, pointed_thing, name, forceright
|
|||
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 minetest.is_protected(pos1, placer:get_player_name()) then
|
||||
minetest.record_protection_violation(pos1,
|
||||
placer:get_player_name())
|
||||
return
|
||||
end
|
||||
|
||||
if minetest.is_protected(pos2, placer:get_player_name()) then
|
||||
minetest.record_protection_violation(pos2,
|
||||
placer:get_player_name())
|
||||
return
|
||||
end
|
||||
|
||||
if not get_nodedef_field(node_bottom.name, "buildable_to")
|
||||
or not get_nodedef_field(node_top.name, "buildable_to") then
|
||||
|
@ -473,9 +487,6 @@ function homedecor.place_door(itemstack, placer, pointed_thing, name, forceright
|
|||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
minetest.registered_nodes[pname].on_rightclick(pointed_thing.under, pnode, placer, itemstack)
|
||||
end
|
||||
end
|
||||
|
||||
-- to open a door, you switch left for right and subtract from param2, or vice versa right for left
|
||||
|
|
|
@ -61,8 +61,6 @@ end
|
|||
|
||||
-- load various other components
|
||||
|
||||
dofile(homedecor.modpath.."/ownership.lua")
|
||||
|
||||
dofile(homedecor.modpath.."/misc_nodes.lua") -- the catch-all for all misc nodes
|
||||
dofile(homedecor.modpath.."/tables.lua")
|
||||
dofile(homedecor.modpath.."/electronics.lua")
|
||||
|
|
|
@ -90,7 +90,7 @@ minetest.register_node('homedecor:glowlight_half_yellow', {
|
|||
groups = { snappy = 3 },
|
||||
light_source = LIGHT_MAX,
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
on_place = homedecor.protect_and_rotate
|
||||
on_place = minetest.rotate_node
|
||||
})
|
||||
|
||||
minetest.register_node('homedecor:glowlight_quarter_yellow', {
|
||||
|
@ -120,7 +120,7 @@ minetest.register_node('homedecor:glowlight_quarter_yellow', {
|
|||
groups = { snappy = 3 },
|
||||
light_source = LIGHT_MAX-1,
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
on_place = homedecor.protect_and_rotate
|
||||
on_place = minetest.rotate_node
|
||||
})
|
||||
|
||||
-- White
|
||||
|
@ -152,7 +152,7 @@ minetest.register_node('homedecor:glowlight_half_white', {
|
|||
groups = { snappy = 3 },
|
||||
light_source = LIGHT_MAX,
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
on_place = homedecor.protect_and_rotate
|
||||
on_place = minetest.rotate_node
|
||||
})
|
||||
|
||||
minetest.register_node('homedecor:glowlight_quarter_white', {
|
||||
|
@ -182,7 +182,7 @@ minetest.register_node('homedecor:glowlight_quarter_white', {
|
|||
groups = { snappy = 3 },
|
||||
light_source = LIGHT_MAX-1,
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
on_place = homedecor.protect_and_rotate
|
||||
on_place = minetest.rotate_node
|
||||
})
|
||||
|
||||
-- Glowlight "cubes"
|
||||
|
@ -214,8 +214,7 @@ minetest.register_node('homedecor:glowlight_small_cube_yellow', {
|
|||
groups = { snappy = 3 },
|
||||
light_source = LIGHT_MAX-1,
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
|
||||
on_place = homedecor.protect_and_rotate
|
||||
on_place = minetest.rotate_node
|
||||
})
|
||||
|
||||
minetest.register_node('homedecor:glowlight_small_cube_white', {
|
||||
|
@ -245,6 +244,6 @@ minetest.register_node('homedecor:glowlight_small_cube_white', {
|
|||
groups = { snappy = 3 },
|
||||
light_source = LIGHT_MAX-1,
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
on_place = homedecor.protect_and_rotate
|
||||
on_place = minetest.rotate_node
|
||||
})
|
||||
|
||||
|
|
|
@ -1,48 +0,0 @@
|
|||
|
||||
local S = homedecor.gettext
|
||||
|
||||
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
|
||||
|
||||
-- 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
|
||||
|
|
@ -416,14 +416,20 @@ minetest.register_node(":default:sign_wall", {
|
|||
local name
|
||||
name = minetest.get_node(pointed_thing.under).name
|
||||
if fences_with_sign[name] then
|
||||
if signs_lib.node_is_owned(pointed_thing.under, placer) then
|
||||
if minetest.is_protected(pointed_thing.under, placer:get_player_name()) then
|
||||
minetest.record_protection_violation(pointed_thing.under,
|
||||
placer:get_player_name())
|
||||
return itemstack
|
||||
end
|
||||
else
|
||||
name = minetest.get_node(pointed_thing.above).name
|
||||
local def = minetest.registered_nodes[name]
|
||||
if signs_lib.node_is_owned(pointed_thing.above, placer)
|
||||
or (not def.buildable_to) then
|
||||
if not def.buildable_to then
|
||||
return itemstack
|
||||
end
|
||||
if minetest.is_protected(pointed_thing.above, placer:get_player_name()) then
|
||||
minetest.record_protection_violation(pointed_thing.above,
|
||||
placer:get_player_name())
|
||||
return itemstack
|
||||
end
|
||||
end
|
||||
|
@ -499,7 +505,11 @@ minetest.register_node(":default:sign_wall", {
|
|||
minetest.pos_to_string(pos)
|
||||
))
|
||||
end
|
||||
if signs_lib.node_is_owned(pos, sender) then return end
|
||||
if minetest.is_protected(pos, sender:get_player_name()) then
|
||||
minetest.record_protection_violation(pos,
|
||||
sender:get_player_name())
|
||||
return
|
||||
end
|
||||
signs_lib.update_sign(pos, fields)
|
||||
end,
|
||||
on_punch = function(pos, node, puncher)
|
||||
|
@ -535,7 +545,11 @@ minetest.register_node(":signs:sign_yard", {
|
|||
minetest.pos_to_string(pos)
|
||||
))
|
||||
end
|
||||
if signs_lib.node_is_owned(pos, sender) then return end
|
||||
if minetest.is_protected(pos, sender:get_player_name()) then
|
||||
minetest.record_protection_violation(pos,
|
||||
sender:get_player_name())
|
||||
return
|
||||
end
|
||||
signs_lib.update_sign(pos, fields)
|
||||
end,
|
||||
on_punch = function(pos, node, puncher)
|
||||
|
@ -617,18 +631,28 @@ function signs_lib.register_fence_with_sign(fencename, fencewithsignname)
|
|||
local def_above = minetest.registered_nodes[node_above.name]
|
||||
local def_under = minetest.registered_nodes[node_under.name]
|
||||
local fdir = minetest.dir_to_facedir(placer:get_look_dir())
|
||||
local playername = placer:get_player_name()
|
||||
|
||||
if minetest.is_protected(pointed_thing.under, playername) then
|
||||
minetest.record_protection_violation(pointed_thing.under, playername)
|
||||
return
|
||||
end
|
||||
|
||||
if minetest.is_protected(pointed_thing.above, playername) then
|
||||
minetest.record_protection_violation(pointed_thing.above, playername)
|
||||
return
|
||||
end
|
||||
|
||||
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 signs_lib.node_is_owned(pointed_thing.under, placer))
|
||||
and def_under.buildable_to then
|
||||
elseif def_under.buildable_to then
|
||||
minetest.add_node(pointed_thing.under, {name = fencename, param2 = fdir})
|
||||
if not signs_lib.expect_infinite_stacks then
|
||||
itemstack:take_item()
|
||||
end
|
||||
placer:set_wielded_item(itemstack)
|
||||
return itemstack
|
||||
elseif (not signs_lib.node_is_owned(pointed_thing.above, placer))
|
||||
and def_above.buildable_to then
|
||||
elseif def_above.buildable_to then
|
||||
minetest.add_node(pointed_thing.above, {name = fencename, param2 = fdir})
|
||||
if not signs_lib.expect_infinite_stacks then
|
||||
itemstack:take_item()
|
||||
|
@ -651,7 +675,11 @@ function signs_lib.register_fence_with_sign(fencename, fencewithsignname)
|
|||
minetest.pos_to_string(pos)
|
||||
))
|
||||
end
|
||||
if signs_lib.node_is_owned(pos, sender) then return end
|
||||
if minetest.is_protected(pos, sender:get_player_name()) then
|
||||
minetest.record_protection_violation(pos,
|
||||
sender:get_player_name())
|
||||
return
|
||||
end
|
||||
signs_lib.update_sign(pos, fields)
|
||||
end
|
||||
def_sign.on_punch = function(pos, node, puncher, ...)
|
||||
|
@ -674,8 +702,6 @@ minetest.register_alias("homedecor:fence_wood_with_sign", "signs:sign_post")
|
|||
|
||||
signs_lib.register_fence_with_sign("default:fence_wood", "signs:sign_post")
|
||||
|
||||
dofile(signs_lib.modpath.."/ownership.lua")
|
||||
|
||||
if minetest.setting_get("log_mods") then
|
||||
minetest.log("action", S("signs loaded"))
|
||||
end
|
||||
|
|
|
@ -1,48 +0,0 @@
|
|||
|
||||
local S = signs_lib.gettext
|
||||
|
||||
function signs_lib.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
|
||||
|
||||
-- protection wrapper for 6d stuff
|
||||
|
||||
function signs_lib.protect_and_rotate(itemstack, placer, pointed_thing)
|
||||
if not signs_lib.node_is_owned(pointed_thing.under, placer)
|
||||
and not signs_lib.node_is_owned(pointed_thing.above, placer) then
|
||||
local keys=placer:get_player_control()
|
||||
minetest.rotate_and_place(itemstack, placer, pointed_thing,
|
||||
signs_lib.expect_infinite_stacks, {invert_wall = keys.sneak})
|
||||
end
|
||||
return itemstack
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user