1
0
mirror of https://github.com/mt-mods/homedecor_modpack.git synced 2025-06-28 12:56:01 +02:00

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:
Vanessa Ezekowitz
2014-01-30 14:09:46 -05:00
parent b11b3a95ec
commit a6122f03d9
6 changed files with 86 additions and 148 deletions

View File

@ -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,39 +447,45 @@ 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 not get_nodedef_field(node_bottom.name, "buildable_to")
or not get_nodedef_field(node_top.name, "buildable_to") then
minetest.chat_send_player( placer:get_player_name(), S('Not enough space above that spot to place a door!') )
else
local fdir = minetest.dir_to_facedir(placer:get_look_dir())
local p_tests = {
{x=pos1.x-1, y=pos1.y, z=pos1.z},
{x=pos1.x, y=pos1.y, z=pos1.z+1},
{x=pos1.x+1, y=pos1.y, z=pos1.z},
{x=pos1.x, y=pos1.y, z=pos1.z-1},
}
print("fdir="..fdir)
local testnode = minetest.get_node(p_tests[fdir+1])
local side = "left"
if minetest.is_protected(pos2, placer:get_player_name()) then
minetest.record_protection_violation(pos2,
placer:get_player_name())
return
end
if string.find(testnode.name, "homedecor:door_"..name.."_bottom_left") or forceright then
side = "right"
end
if not get_nodedef_field(node_bottom.name, "buildable_to")
or not get_nodedef_field(node_top.name, "buildable_to") then
minetest.chat_send_player( placer:get_player_name(), S('Not enough space above that spot to place a door!') )
else
local fdir = minetest.dir_to_facedir(placer:get_look_dir())
local p_tests = {
{x=pos1.x-1, y=pos1.y, z=pos1.z},
{x=pos1.x, y=pos1.y, z=pos1.z+1},
{x=pos1.x+1, y=pos1.y, z=pos1.z},
{x=pos1.x, y=pos1.y, z=pos1.z-1},
}
print("fdir="..fdir)
local testnode = minetest.get_node(p_tests[fdir+1])
local side = "left"
local def = { name = "homedecor:door_"..name.."_bottom_"..side, param2=fdir}
addDoorNode(pos1, def, true)
minetest.add_node(pos2, { name = "homedecor:door_"..name.."_top_"..side, param2=fdir})
if not homedecor.expect_infinite_stacks then
itemstack:take_item()
return itemstack
end
if string.find(testnode.name, "homedecor:door_"..name.."_bottom_left") or forceright then
side = "right"
end
local def = { name = "homedecor:door_"..name.."_bottom_"..side, param2=fdir}
addDoorNode(pos1, def, true)
minetest.add_node(pos2, { name = "homedecor:door_"..name.."_top_"..side, param2=fdir})
if not homedecor.expect_infinite_stacks then
itemstack:take_item()
return itemstack
end
end
else
minetest.registered_nodes[pname].on_rightclick(pointed_thing.under, pnode, placer, itemstack)
end
end

View File

@ -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")

View File

@ -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
})

View File

@ -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