mirror of
https://github.com/HybridDog/we_undo.git
synced 2025-01-05 20:27:35 +01:00
Use minetest.find_nodes_with_meta to test if meta is empty where possible
This commit is contained in:
parent
e53175df55
commit
cb482c91e1
38
init.lua
38
init.lua
@ -764,13 +764,23 @@ local function is_meta_empty(metatabl)
|
|||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
-- copied from we to get the same meta format
|
-- Gets information about meta if it is set, otherwise returns nil
|
||||||
local function make_meta_serializable(metat)
|
-- the format of the information is the same as in WorldEdit
|
||||||
|
local function get_meta_serializable(pos)
|
||||||
|
if not minetest.find_nodes_with_meta(pos, pos) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
local metat = meta:to_table()
|
||||||
for _, inventory in pairs(metat.inventory) do
|
for _, inventory in pairs(metat.inventory) do
|
||||||
for index, stack in ipairs(inventory) do
|
for index = 1,#inventory do
|
||||||
inventory[index] = stack.to_string and stack:to_string() or stack
|
local itemstack = inventory[index]
|
||||||
|
if itemstack.to_string then
|
||||||
|
inventory[index] = itemstack:to_string()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
return metat, meta
|
||||||
end
|
end
|
||||||
|
|
||||||
local we_deserialize = worldedit.deserialize
|
local we_deserialize = worldedit.deserialize
|
||||||
@ -802,15 +812,11 @@ local function my_we_deserialize(pos, ...)
|
|||||||
end
|
end
|
||||||
local pos = {x=entry.x, y=entry.y, z=entry.z}
|
local pos = {x=entry.x, y=entry.y, z=entry.z}
|
||||||
-- we calls add_node always before setting any meta, save it here
|
-- we calls add_node always before setting any meta, save it here
|
||||||
local metat = minetest.get_meta(pos):to_table()
|
local metat = get_meta_serializable(pos)
|
||||||
if is_meta_empty(metat) then
|
|
||||||
metat = nil
|
|
||||||
else
|
|
||||||
make_meta_serializable(metat)
|
|
||||||
end
|
|
||||||
local new_metat = entry.meta
|
local new_metat = entry.meta
|
||||||
if new_metat
|
if new_metat
|
||||||
and is_meta_empty(new_metat) then
|
and is_meta_empty(new_metat) then
|
||||||
|
-- Worldedit save files usually contain redundant metadata
|
||||||
new_metat = nil
|
new_metat = nil
|
||||||
end
|
end
|
||||||
local meta_changed = (metat or new_metat)
|
local meta_changed = (metat or new_metat)
|
||||||
@ -1014,17 +1020,13 @@ undo_funcs.nodes = function(name, data)
|
|||||||
local metastrings = decompressed_data.metastrings
|
local metastrings = decompressed_data.metastrings
|
||||||
for k = 1,#indices_m do
|
for k = 1,#indices_m do
|
||||||
local i = indices_m[k]
|
local i = indices_m[k]
|
||||||
local meta = minetest.get_meta(vector.add(pos1, {
|
local pos = vector.add(pos1, {
|
||||||
x = i % ystride,
|
x = i % ystride,
|
||||||
y = math.floor(i / ystride) % ylen,
|
y = math.floor(i / ystride) % ylen,
|
||||||
z = math.floor(i / (ystride * ylen))
|
z = math.floor(i / (ystride * ylen))
|
||||||
}))
|
})
|
||||||
local metat = meta:to_table()
|
local metat, meta = get_meta_serializable(pos)
|
||||||
if is_meta_empty(metat) then
|
meta = meta or minetest.get_meta(pos)
|
||||||
metat = nil
|
|
||||||
else
|
|
||||||
make_meta_serializable(metat)
|
|
||||||
end
|
|
||||||
meta:from_table(minetest.deserialize(metastrings[k]))
|
meta:from_table(minetest.deserialize(metastrings[k]))
|
||||||
metastrings[k] = minetest.serialize(metat)
|
metastrings[k] = minetest.serialize(metat)
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user