Sokomine wrote:You are not doing anything wrong. The replacements are cached. I ran across that some time ago and eventually had to resort to my own placement function. Perhaps my handle_schematics and basic_houses mods can be of use to you.
Thank you for your helpful reply.
I'm still not perfectly satisfied ;-) and I'm trying a different approach:
- convert mts to lua
Code: Select all
local schem_lua = minetest.serialize_schematic(building, "lua", {lua_use_comments = false, lua_num_indent_spaces = 0}).." return(schematic)"
- replace material
Code: Select all
schem_lua = schem_lua:gsub("default:cobble", material)
- format schematic string
Code: Select all
local schematic = loadstring(schem_lua)()
- reconvert to mts
Code: Select all
local schem_mts = minetest.serialize_schematic(schematic, "mts", {})
My problem is, that when I call the function place_schematic like this, I get an error:
Code: Select all
minetest.place_schematic(pos, schem_mts, "random", nil, true)
The function expects a file-path as second parameter, instead of binary MTS data.
If I write schem_mts to a mts-file, and call the function with this file, it works, but the replacement only works once, because of caching.
Code: Select all
-- write file
local file, err = io.open(schem_path.."temp.mts", "wb")
file:write(schem_mts)
file:flush()
file:close()
-- place schematic
minetest.place_schematic(pos, schem_path.."temp.mts", "random", nil, true)
Maybe with random filenames, it would work, but there would be a huge amount of disk i/o.
Is it possible with lua to "fake" the existence of a file, that isn't physically there? Or modify the function place_schematic so it accepts binary MTS data?