toying around
parent
be433106f8
commit
515980c5e1
|
@ -1,12 +1,25 @@
|
|||
function settlements.build_schematic(pos)
|
||||
-- list of schematics
|
||||
local schematic_table = {minetest.get_modpath("settlements").."/schems/hut.mts"}
|
||||
local schematic_table = {schem_path.."hut.mts"}
|
||||
-- pick one of those schematics
|
||||
local schematic = schematic_table[math.random(1, #schematic_table)]
|
||||
local building = schematic_table[math.random(1, #schematic_table)]
|
||||
-- get building node material for better integration to surrounding
|
||||
local balcony_material = minetest.get_node_or_nil(pos).name
|
||||
-- pick random material
|
||||
local material = wallmaterial[math.random(1,#wallmaterial)]
|
||||
-- schematic conversion to lua
|
||||
local schem_lua = minetest.serialize_schematic(building, "lua", {lua_use_comments = false, lua_num_indent_spaces = 0}).." return(schematic)"
|
||||
-- replace material
|
||||
schem_lua = schem_lua:gsub("default_cobble", material)
|
||||
-- format schematic string
|
||||
local schematic = loadstring(schem_lua)()
|
||||
-- convert to mts
|
||||
local schem_mts = minetest.serialize_schematic(schematic, "mts", {})
|
||||
-- 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, schematic, "random", {["default:cobble"] = material,["default:dirt_with_grass"] = balcony_material}, true)
|
||||
minetest.place_schematic(pos, schem_path.."temp.mts", "random", nil, true)
|
||||
end
|
|
@ -7,3 +7,4 @@ c_floor_material = "default:wood" -- not local because doors need it
|
|||
surface_mat = {"default:dirt_with_grass","default:dirt_with_snow","default:dirt_with_dray_grass"}
|
||||
above_surface_mat = {"default:air","default:dirt_with_snow"}
|
||||
under_surface_mat = {"default:stone","default:dirt"}
|
||||
schem_path = settlements.modpath.."/schematics/"
|
||||
|
|
4
init.lua
4
init.lua
|
@ -50,7 +50,9 @@ minetest.register_craftitem("settlements:tool", {
|
|||
on_use = function(itemstack, placer, pointed_thing)
|
||||
local p = pointed_thing.under
|
||||
if p then
|
||||
settlements.build_schematic(p)
|
||||
-- settlements.build_schematic(p)
|
||||
settlements.convert_mts_to_lua()
|
||||
-- settlements.mts_save()
|
||||
end
|
||||
end
|
||||
})
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
Binary file not shown.
30
utils.lua
30
utils.lua
|
@ -118,4 +118,34 @@ function settlements.torch(pos)
|
|||
end
|
||||
-- place door
|
||||
minetest.set_node(p3,{name = "default:torch_wall", param2 = wallmounted})
|
||||
end
|
||||
--
|
||||
function settlements.convert_mts_to_lua()
|
||||
local building = schem_path.."hut.mts"
|
||||
local str = minetest.serialize_schematic(building, "lua", {lua_use_comments = true, lua_num_indent_spaces = 0}).." return(schematic)"
|
||||
local schematic = loadstring(str)()
|
||||
local file = io.open(schem_path.."hut"..".lua", "w")
|
||||
file:write(dump(schematic))
|
||||
file:close()
|
||||
print(dump(schematic))
|
||||
end
|
||||
|
||||
|
||||
|
||||
function settlements.mts_save()
|
||||
local f = assert(io.open(schem_path.."hut.lua", "r"))
|
||||
local content = f:read("*all").." return(schematic2)"
|
||||
f:close()
|
||||
|
||||
local schematic2 = loadstring("schematic2 = "..content)()
|
||||
local seb = minetest.serialize_schematic(schematic2, "mts", {})
|
||||
local filename = schem_path .. "hut2" .. ".mts"
|
||||
filename = filename:gsub("\"", "\\\""):gsub("\\", "\\\\")
|
||||
local file, err = io.open(filename, "wb")
|
||||
if err == nil and seb then
|
||||
file:write(seb)
|
||||
file:flush()
|
||||
file:close()
|
||||
end
|
||||
print("Wrote: " .. filename)
|
||||
end
|
Loading…
Reference in New Issue