Add more things
This commit is contained in:
parent
be2262fa17
commit
d6662e8094
26 changed files with 565 additions and 26 deletions
|
|
@ -94,7 +94,7 @@ end
|
|||
|
||||
function ns.get_workspace(name)
|
||||
local ws = db:get("workspace:"..name)
|
||||
if ws then return mietest.deserialize(ws) end
|
||||
if ws then return minetest.deserialize(ws) end
|
||||
end
|
||||
|
||||
function ns.place_workspace(name, pos)
|
||||
|
|
@ -127,12 +127,68 @@ function ns.clear_workspace(ws)
|
|||
vm:write_to_map()
|
||||
end
|
||||
|
||||
function ns.load_plot(ws, plot)
|
||||
function ns.load_plot(ws, plot, actor)
|
||||
if vector.distance(ws.size, rgt_towns.plots[plot].size) > 0.1 then
|
||||
tell(actor, "Workspace size and plot size do not match!")
|
||||
return
|
||||
end
|
||||
minetest.place_schematic(ws.pos, rgt_towns.plots[plot].schematic, nil, nil, true, {})
|
||||
end
|
||||
|
||||
function ns.set_workspace_size(ws, x, y, z)
|
||||
|
||||
local vm_data = {}
|
||||
function ns.init_plot(ws, lvl)
|
||||
if lvl and lvl -1 > 0 and lvl < ws.size.y *15 then
|
||||
lvl = lvl -1
|
||||
local min = ws.pos
|
||||
local max = vector.add(ws.pos, vector.multiply(ws.size, 15))
|
||||
local vm = minetest.get_voxel_manip(min, max)
|
||||
local area = VoxelArea(vm:get_emerged_area())
|
||||
|
||||
local c_grass = minetest.get_content_id("dirt_grass")
|
||||
local c_path = minetest.get_content_id("path_grass")
|
||||
local c_dirt = minetest.get_content_id("dirt")
|
||||
|
||||
vm:get_data(vm_data)
|
||||
|
||||
for x = min.x, max.x -1 do
|
||||
for z = min.z, max.z -1 do
|
||||
for y = 0, lvl do
|
||||
vm_data[area:index(x, ws.pos.y +y, z)] = y == lvl and ((
|
||||
x +1 == max.x or x == min.x or
|
||||
z +1 == max.z or z == min.z or
|
||||
x +2 == max.x and z +2 == max.z or
|
||||
x +2 == max.x and z -1 == min.z or
|
||||
x -1 == min.x and z +2 == max.z or
|
||||
x -1 == min.x and z -1 == min.z
|
||||
) and c_path or c_grass) or c_dirt
|
||||
end
|
||||
end
|
||||
end
|
||||
vm:set_data(vm_data)
|
||||
vm:write_to_map()
|
||||
end
|
||||
end
|
||||
|
||||
function ns.set_workspace_size(name, x, y, z)
|
||||
local ws = ns.get_workspace(name)
|
||||
ws.size.x = x
|
||||
ws.size.y = y
|
||||
ws.size.z = z
|
||||
db:set_string("workspace:"..name, minetest.serialize(ws))
|
||||
for k, x in pairs(ns.workspaces[name]) do
|
||||
if k ~= "marker" then
|
||||
if x.remove then
|
||||
|
||||
elseif type(x) == "table" then
|
||||
for _, y in pairs(x) do
|
||||
minetest.delete_particlespawner(y)
|
||||
end
|
||||
else
|
||||
minetest.delete_particlespawner(y)
|
||||
end
|
||||
end
|
||||
end
|
||||
ns.workspaces[name].outline = rgt_towns.add_cube(vector.offset(ws.pos, -0.5,-0.5,-0.5), vector.add(ws.pos, vector.multiply(ws.size, 15)):offset(-0.5,-0.5,-0.5))
|
||||
end
|
||||
|
||||
function ns.export_workspace(ws, label)
|
||||
|
|
@ -144,8 +200,10 @@ end
|
|||
minetest.register_chatcommand("new_plot", {
|
||||
func = function(name, args)
|
||||
local ws = ns.place_workspace(name, minetest.get_player_by_name(name):get_pos())
|
||||
if args == "clear" then
|
||||
if args == "clear" then
|
||||
ns.clear_workspace(ws)
|
||||
else
|
||||
ns.init_plot(ws, tonumber(args))
|
||||
end
|
||||
end
|
||||
})
|
||||
|
|
@ -159,7 +217,7 @@ minetest.register_chatcommand("load_plot", {
|
|||
return
|
||||
end
|
||||
if args and args ~= "" then
|
||||
ns.load_plot(ws, args)
|
||||
ns.load_plot(ws, args, name)
|
||||
end
|
||||
end
|
||||
})
|
||||
|
|
@ -167,10 +225,14 @@ minetest.register_chatcommand("load_plot", {
|
|||
minetest.register_chatcommand("set_plot_size", {
|
||||
func = function(name, args)
|
||||
if args and args ~= "" then
|
||||
local x, y, z = args:match "(%d+)%s+(%d+)%s+(%d+)"
|
||||
local x, y, z, regen, lvl = args:match "^(%d+)%s+(%d+)%s+(%d+)%s+(regenerate)%s+(%d+)"
|
||||
if not x then return end
|
||||
if not y then y = x end
|
||||
if not z then z = x end
|
||||
ns.set_workspace_size(ns.get_workspace(name), x, y, z)
|
||||
ns.set_workspace_size(name, x, y, z)
|
||||
if regen and lvl then
|
||||
ns.init_plot(ns.get_workspace(name), tonumber(lvl))
|
||||
end
|
||||
tell(name, "Size set to "..x.."x"..y.."x"..z..".")
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ rgt_towns.register_plot{
|
|||
label = "Empty Plot",
|
||||
description = "Hello world",
|
||||
schematic = minetest.get_modpath(minetest.get_current_modname()).."/schems/empty_plot.mts",
|
||||
size = vector.new(1, 2, 1),
|
||||
recipe = {
|
||||
"", "", "",
|
||||
"dirt_grass 1", "dirt_grass 1", "dirt_grass 1",
|
||||
|
|
@ -48,6 +49,7 @@ rgt_towns.register_plot{
|
|||
label = "House",
|
||||
description = "Hello world",
|
||||
schematic = minetest.get_modpath(minetest.get_current_modname()).."/schems/house.mts",
|
||||
size = vector.new(1, 2, 1),
|
||||
recipe = {
|
||||
"oak_planks 1", "oak_planks 1", "oak_planks 1",
|
||||
"oak_log 1", "glass 1", "oak_log 1",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue