1
0
mirror of https://github.com/Uberi/Minetest-WorldEdit.git synced 2025-07-15 22:30:24 +02:00

5 Commits

Author SHA1 Message Date
40b49ee9bc Make placeholders not pointable 2019-07-17 01:22:12 +02:00
4f2c7b18cc Fix //allocate with 0 nodes 2019-07-17 01:20:40 +02:00
b2e086f9ec Fix //load with 0 nodes (#177) 2019-06-15 16:46:12 +02:00
d1cbd420bb serialize: Fix detecting empty metadata (#176) 2019-04-24 22:51:18 +02:00
0aeee79af6 Implement full facedir and color* in //orient
Thanks to entuland for the Rhotator facedir to matrix and matrix to facedir code, which helped creating the tables.
2019-04-05 00:12:02 +02:00
4 changed files with 55 additions and 35 deletions

View File

@ -529,20 +529,22 @@ end
-- @param pos2 -- @param pos2
-- @param angle Angle in degrees (90 degree increments only). -- @param angle Angle in degrees (90 degree increments only).
-- @return The number of nodes oriented. -- @return The number of nodes oriented.
-- TODO: Support 6D facedir rotation along arbitrary axis.
function worldedit.orient(pos1, pos2, angle) function worldedit.orient(pos1, pos2, angle)
local pos1, pos2 = worldedit.sort_pos(pos1, pos2) local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
local registered_nodes = minetest.registered_nodes local registered_nodes = minetest.registered_nodes
local wallmounted = { local wallmounted = {
[90] = {[0]=0, 1, 5, 4, 2, 3}, [90] = {0, 1, 5, 4, 2, 3, 0, 0},
[180] = {[0]=0, 1, 3, 2, 5, 4}, [180] = {0, 1, 3, 2, 5, 4, 0, 0},
[270] = {[0]=0, 1, 4, 5, 3, 2} [270] = {0, 1, 4, 5, 3, 2, 0, 0}
} }
local facedir = { local facedir = {
[90] = {[0]=1, 2, 3, 0}, [90] = { 1, 2, 3, 0, 13, 14, 15, 12, 17, 18, 19, 16,
[180] = {[0]=2, 3, 0, 1}, 9, 10, 11, 8, 5, 6, 7, 4, 23, 20, 21, 22},
[270] = {[0]=3, 0, 1, 2} [180] = { 2, 3, 0, 1, 10, 11, 8, 9, 6, 7, 4, 5,
18, 19, 16, 17, 14, 15, 12, 13, 22, 23, 20, 21},
[270] = { 3, 0, 1, 2, 19, 16, 17, 18, 15, 12, 13, 14,
7, 4, 5, 6, 11, 8, 9, 10, 21, 22, 23, 20}
} }
angle = angle % 360 angle = angle % 360
@ -558,8 +560,7 @@ function worldedit.orient(pos1, pos2, angle)
worldedit.keep_loaded(pos1, pos2) worldedit.keep_loaded(pos1, pos2)
local count = 0 local count = 0
local set_node, get_node, get_meta, swap_node = minetest.set_node, local get_node, swap_node = minetest.get_node, minetest.swap_node
minetest.get_node, minetest.get_meta, minetest.swap_node
local pos = {x=pos1.x, y=0, z=0} local pos = {x=pos1.x, y=0, z=0}
while pos.x <= pos2.x do while pos.x <= pos2.x do
pos.y = pos1.y pos.y = pos1.y
@ -569,17 +570,20 @@ function worldedit.orient(pos1, pos2, angle)
local node = get_node(pos) local node = get_node(pos)
local def = registered_nodes[node.name] local def = registered_nodes[node.name]
if def then if def then
if def.paramtype2 == "wallmounted" then local paramtype2 = def.paramtype2
node.param2 = wallmounted_substitution[node.param2] if paramtype2 == "wallmounted" or
local meta = get_meta(pos):to_table() paramtype2 == "colorwallmounted" then
set_node(pos, node) local orient = node.param2 % 8
get_meta(pos):from_table(meta) node.param2 = node.param2 - orient +
wallmounted_substitution[orient + 1]
swap_node(pos, node)
count = count + 1 count = count + 1
elseif def.paramtype2 == "facedir" then elseif paramtype2 == "facedir" or
node.param2 = facedir_substitution[node.param2] paramtype2 == "colorfacedir" then
local meta = get_meta(pos):to_table() local orient = node.param2 % 32
set_node(pos, node) node.param2 = node.param2 - orient +
get_meta(pos):from_table(meta) facedir_substitution[orient + 1]
swap_node(pos, node)
count = count + 1 count = count + 1
end end
end end

View File

@ -56,10 +56,19 @@ function worldedit.serialize(pos1, pos2)
worldedit.keep_loaded(pos1, pos2) worldedit.keep_loaded(pos1, pos2)
local get_node, get_meta, hash_node_position =
minetest.get_node, minetest.get_meta, minetest.hash_node_position
-- Find the positions which have metadata
local has_meta = {}
local meta_positions = minetest.find_nodes_with_meta(pos1, pos2)
for i = 1, #meta_positions do
has_meta[hash_node_position(meta_positions[i])] = true
end
local pos = {x=pos1.x, y=0, z=0} local pos = {x=pos1.x, y=0, z=0}
local count = 0 local count = 0
local result = {} local result = {}
local get_node, get_meta = minetest.get_node, minetest.get_meta
while pos.x <= pos2.x do while pos.x <= pos2.x do
pos.y = pos1.y pos.y = pos1.y
while pos.y <= pos2.y do while pos.y <= pos2.y do
@ -68,20 +77,19 @@ function worldedit.serialize(pos1, pos2)
local node = get_node(pos) local node = get_node(pos)
if node.name ~= "air" and node.name ~= "ignore" then if node.name ~= "air" and node.name ~= "ignore" then
count = count + 1 count = count + 1
local meta = get_meta(pos):to_table()
local meta_empty = true local meta
-- Convert metadata item stacks to item strings if has_meta[hash_node_position(pos)] then
for name, inventory in pairs(meta.inventory) do meta = get_meta(pos):to_table()
for index, stack in ipairs(inventory) do
meta_empty = false -- Convert metadata item stacks to item strings
inventory[index] = stack.to_string and stack:to_string() or stack for _, invlist in pairs(meta.inventory) do
end for index = 1, #invlist do
end local itemstack = invlist[index]
for k in pairs(meta) do if itemstack.to_string then
if k ~= "inventory" then invlist[index] = itemstack:to_string()
meta_empty = false end
break end
end end
end end
@ -92,7 +100,7 @@ function worldedit.serialize(pos1, pos2)
name = node.name, name = node.name,
param1 = node.param1 ~= 0 and node.param1 or nil, param1 = node.param1 ~= 0 and node.param1 or nil,
param2 = node.param2 ~= 0 and node.param2 or nil, param2 = node.param2 ~= 0 and node.param2 or nil,
meta = not meta_empty and meta or nil, meta = meta,
} }
end end
pos.z = pos.z + 1 pos.z = pos.z + 1
@ -188,7 +196,7 @@ end
-- @return The number of nodes. -- @return The number of nodes.
function worldedit.allocate(origin_pos, value) function worldedit.allocate(origin_pos, value)
local nodes = load_schematic(value) local nodes = load_schematic(value)
if not nodes then return nil end if not nodes or #nodes == 0 then return nil end
return worldedit.allocate_with_nodes(origin_pos, nodes) return worldedit.allocate_with_nodes(origin_pos, nodes)
end end
@ -219,6 +227,7 @@ end
function worldedit.deserialize(origin_pos, value) function worldedit.deserialize(origin_pos, value)
local nodes = load_schematic(value) local nodes = load_schematic(value)
if not nodes then return nil end if not nodes then return nil end
if #nodes == 0 then return #nodes end
local pos1, pos2 = worldedit.allocate_with_nodes(origin_pos, nodes) local pos1, pos2 = worldedit.allocate_with_nodes(origin_pos, nodes)
worldedit.keep_loaded(pos1, pos2) worldedit.keep_loaded(pos1, pos2)

View File

@ -6,6 +6,7 @@ minetest.register_node("worldedit:placeholder", {
paramtype = "light", paramtype = "light",
sunlight_propagates = true, sunlight_propagates = true,
diggable = false, diggable = false,
pointable = false,
walkable = false, walkable = false,
groups = {not_in_creative_inventory=1}, groups = {not_in_creative_inventory=1},
}) })

View File

@ -1163,9 +1163,15 @@ minetest.register_chatcommand("/allocate", {
return return
elseif version > worldedit.LATEST_SERIALIZATION_VERSION then elseif version > worldedit.LATEST_SERIALIZATION_VERSION then
worldedit.player_notify(name, "File was created with newer version of WorldEdit!") worldedit.player_notify(name, "File was created with newer version of WorldEdit!")
return
end end
local nodepos1, nodepos2, count = worldedit.allocate(pos, value) local nodepos1, nodepos2, count = worldedit.allocate(pos, value)
if not nodepos1 then
worldedit.player_notify(name, "Schematic empty, nothing allocated")
return
end
worldedit.pos1[name] = nodepos1 worldedit.pos1[name] = nodepos1
worldedit.mark_pos1(name) worldedit.mark_pos1(name)
worldedit.pos2[name] = nodepos2 worldedit.pos2[name] = nodepos2