Recreate destroyed translocators...
since mobs doesn't check for protection. Sooo many ways this could go wrong.
This commit is contained in:
parent
419fc2f583
commit
fcee06b6e1
3 changed files with 56 additions and 14 deletions
|
@ -314,6 +314,7 @@ minetest.register_craft({
|
|||
local function translocate(pos, node, clicker, itemstack, pointed_thing)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local id = meta:get_string('id')
|
||||
local owner = meta:get_string('owner')
|
||||
if not (id and tonumber(id)) then
|
||||
return
|
||||
end
|
||||
|
@ -325,9 +326,33 @@ local function translocate(pos, node, clicker, itemstack, pointed_thing)
|
|||
|
||||
local pos2
|
||||
if minetest.serialize(pair[2]) == minetest.serialize(pos) then
|
||||
clicker:setpos(pair[1])
|
||||
pos2 = pair[1]
|
||||
else
|
||||
clicker:setpos(pair[2])
|
||||
pos2 = pair[2]
|
||||
end
|
||||
|
||||
if pos2 then
|
||||
clicker:setpos(pos2)
|
||||
|
||||
-- If the mated translocator doesn't exist, recreate it.
|
||||
minetest.after(1, function()
|
||||
if not owner then
|
||||
return
|
||||
end
|
||||
|
||||
-- If we can't get the node, we can't set it.
|
||||
local node = minetest.get_node_or_nil(pos2)
|
||||
if not node or node.name == 'fun_caves:translocator' then
|
||||
return
|
||||
end
|
||||
|
||||
minetest.set_node(pos2, {name = 'fun_caves:translocator'})
|
||||
local meta = minetest.get_meta(pos2)
|
||||
meta:set_string('id', id)
|
||||
meta:set_string('owner', owner)
|
||||
|
||||
print('Fun Caves: recreated a missing translocator')
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -426,6 +451,32 @@ local function trans_dig(pos, node, digger)
|
|||
end
|
||||
end
|
||||
|
||||
local function trans_dest(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local id = meta:get_string('id')
|
||||
local owner = meta:get_string('owner')
|
||||
if not (id and owner) then
|
||||
return
|
||||
end
|
||||
|
||||
if not fun_caves.db.translocators[tonumber(id)] then
|
||||
return
|
||||
end
|
||||
local pair = table.copy(fun_caves.db.translocators[tonumber(id)])
|
||||
|
||||
minetest.after(1, function()
|
||||
if not fun_caves.db.translocators[tonumber(id)] or #fun_caves.db.translocators[tonumber(id)] < #pair then
|
||||
return
|
||||
end
|
||||
minetest.set_node(pos, {name = 'fun_caves:translocator'})
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_string('id', id)
|
||||
meta:set_string('owner', owner)
|
||||
|
||||
print('Fun Caves: recreated a destroyed translocator')
|
||||
end)
|
||||
end
|
||||
|
||||
minetest.register_node("fun_caves:translocator", {
|
||||
visual = 'mesh',
|
||||
mesh = "fun_caves_translocator.obj",
|
||||
|
@ -449,6 +500,7 @@ minetest.register_node("fun_caves:translocator", {
|
|||
on_use = trans_use,
|
||||
on_place = trans_place,
|
||||
on_dig = trans_dig,
|
||||
on_destruct = trans_dest,
|
||||
})
|
||||
|
||||
for _, gem in pairs(gems) do
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue