mirror of
https://github.com/joe7575/techpack.git
synced 2024-11-26 09:03:46 +01:00
prevent defect dummies when metadata is messed up
This commit is contained in:
parent
5c4f117b40
commit
fb32942625
@ -13,6 +13,15 @@ minetest.register_node("tubelib:defect_dummy", {
|
|||||||
is_ground_content = false,
|
is_ground_content = false,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
local reported_machines = {}
|
||||||
|
local function report(pos)
|
||||||
|
reported_machines[minetest.pos_to_string(pos)] = true
|
||||||
|
end
|
||||||
|
local function already_reported(pos)
|
||||||
|
local key = minetest.pos_to_string(pos)
|
||||||
|
return reported_machines[key]
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
function tubelib.data_not_corrupted(pos)
|
function tubelib.data_not_corrupted(pos)
|
||||||
if minetest.pos_to_string(pos) ~= minetest.get_meta(pos):get_string("my_pos") then
|
if minetest.pos_to_string(pos) ~= minetest.get_meta(pos):get_string("my_pos") then
|
||||||
@ -29,18 +38,22 @@ function tubelib.data_not_corrupted(pos)
|
|||||||
number = meta:get_string("own_number")
|
number = meta:get_string("own_number")
|
||||||
end
|
end
|
||||||
if number == "" then
|
if number == "" then
|
||||||
tubelib.remove_node(pos)
|
if not already_reported(pos) then
|
||||||
minetest.set_node(pos, {name = "tubelib:defect_dummy"})
|
minetest.log('error', ('[tubelib] machine @ %s has no number'):format(minetest.pos_to_string(pos)))
|
||||||
meta:from_table(nil)
|
report(pos)
|
||||||
return false
|
end
|
||||||
end
|
end
|
||||||
-- node moved?
|
-- node moved?
|
||||||
local info = tubelib.get_node_info(number)
|
local info = tubelib.get_node_info(number)
|
||||||
if not info or not vector.equals(info.pos, pos) then
|
if not info or not vector.equals(info.pos, pos) then
|
||||||
tubelib.remove_node(pos)
|
if not already_reported(pos) then
|
||||||
minetest.set_node(pos, {name = "tubelib:defect_dummy"})
|
if not info then
|
||||||
meta:from_table(nil)
|
minetest.log('error', ('[tubelib] machine @ %s has no info'):format(minetest.pos_to_string(pos)))
|
||||||
return false
|
else
|
||||||
|
minetest.log('error', ('[tubelib] machine @ %s thinks it is at %s'):format(minetest.pos_to_string(pos), minetest.pos_to_string(info.pos)))
|
||||||
|
end
|
||||||
|
report(pos)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
minetest.get_meta(pos):get_string("my_pos", minetest.pos_to_string(pos))
|
minetest.get_meta(pos):get_string("my_pos", minetest.pos_to_string(pos))
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user