Problem deserializing WorldEdit schematic

Post Reply
ChristienChapman
Member
Posts: 117
Joined: Sat May 28, 2022 00:04

Problem deserializing WorldEdit schematic

by ChristienChapman » Post

I need to import a worldedit schematic within code. I tried worldedit.deserialize and gave it {x = 0, y = 10, z = 0}, "testWorld" but it did not work. Is there something I am missing? God bless you.
God bless you.

List of releases:
Minetest Zombies Minigame - viewtopic.php?f=9&t=28442&p=412633#p412633

- > cdb_1d60e1a03f83

User avatar
Mr. Rar
Member
Posts: 109
Joined: Tue Oct 04, 2016 20:13
GitHub: MrRar
In-game: MrRar

Re: Problem deserializing WorldEdit schematic

by Mr. Rar » Post

What do you mean by import the schematic? Do you mean that you want to load an existing schematic file or that you want to create a new schematic from the world?
"Only in Christ do we find real love, and the fullness of life. And so I invite you today to look to Christ." - St. John Paul II

bzt
Member
Posts: 217
Joined: Tue Sep 24, 2019 14:26

Re: Problem deserializing WorldEdit schematic

by bzt » Post

ChristienChapman wrote:
Mon Aug 15, 2022 23:29
I need to import a worldedit schematic within code. I tried worldedit.deserialize and gave it {x = 0, y = 10, z = 0}, "testWorld" but it did not work. Is there something I am missing? God bless you.
Forget about worldedit's .we format, use .mts format and then you can use minetest.place_schematic() as-is, easy. For the records, worldedit can save and load .mts files too.

Otherwise if you insist on .we format, then Sokomine's Handle Schematics mod is able to load .we files and can serve as an example.

For some reason (also unknown to Sokomine according to the comments) deserialize doesn't work, so he has created a workaround using worldedit_file.load_schematic().

NOTE: this just loads the schematic into memory as a Lua table, you'll have to place it in the world manually.

Sokomine is using voxel_manip for that, but alternatively (and probably this is more suited for your use case) from that data you can create a Schematic specifier table (see the link for the required table fields) and then simply use minetest.place_schematic(). (First I've thought that .we Lua table and Schematic specifier Lua table are the same, but sadly no, so you have to iterate on the nodes returned by load_schematic() in the first table and copy them as MapNode into the second.)

Code: Select all

local nodes = worldedit_file.load_schematic(value, we_origin)
local schem
-- copy node data to a second table in MapNode format
for i = 1, #nodes do
	local ent = nodes[i]
	-- little magic to parse ent.x, ent.y, ent.z and insert in correct order
	table.insert( schem.data, { name=ent.name, param1=..., param2=... });
end
-- add other required fields, like dimension
schem.size = { width, height, depth }
return schem
and then you can use that returned table with minetest.place_schematic(), probably placing that structure multiple times if you want to.

Hope this helps,
bzt

ChristienChapman
Member
Posts: 117
Joined: Sat May 28, 2022 00:04

Re: Problem deserializing WorldEdit schematic

by ChristienChapman » Post

Thanks
God bless you.

List of releases:
Minetest Zombies Minigame - viewtopic.php?f=9&t=28442&p=412633#p412633

- > cdb_1d60e1a03f83

Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests