forked from pauldpickell/UBC_Campus_Minetest_Map
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinit.lua
121 lines (90 loc) · 4.5 KB
/
init.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
UBCMap = { path = minetest.get_modpath("ubc_campus_minetest_map"), storage = minetest.get_mod_storage() }
function UBCMap:placeSchematic(pos1, pos2, v, rotation, replacement, force_placement)
-- Read data into LVM
local vm = minetest.get_voxel_manip()
local emin, emax = vm:read_from_map(pos1, pos2)
local a = VoxelArea:new {
MinEdge = emin,
MaxEdge = emax
}
minetest.place_schematic_on_vmanip(vm, pos1, UBCMap.path .. "/schems/ubc_blocks_" .. tostring(v) .. ".mts", rotation, replacement, force_placement)
minetest.chat_send_all("combined terrain tile " .. tostring(v))
minetest.place_schematic_on_vmanip(vm, pos1, UBCMap.path .. "/schems/ubc_trees_" .. tostring(v) .. ".mts", rotation, replacement, force_placement)
minetest.chat_send_all("combined trees tile " .. tostring(v))
minetest.place_schematic_on_vmanip(vm, pos1, UBCMap.path .. "/schems/ubc_urban_" .. tostring(v) .. ".mts", rotation, replacement, force_placement)
minetest.chat_send_all("combined urban tile " .. tostring(v))
vm:write_to_map(true)
end
local inProgress = false
function UBCMap.place(startPosition)
-- GC before we start placing the map
collectgarbage("collect")
if (inProgress == true) then
return false, "Map placement already in progress. Try again later", 1
end
-- If we crash during world generation, we'll try again.
local startingValue = UBCMap.storage:get_int("placementProgress")
if (startingValue == nil or startingValue == 0) then
startingValue = 1
UBCMap.storage:set_string("startPosition", minetest.serialize(startPosition))
UBCMap.storage:set_int("generating", 1)
Debug.log(UBCMap.storage:get_int("generating"))
minetest.chat_send_all("Placing UBC Map")
else
startPosition = minetest.deserialize(UBCMap.storage:get_string("startPosition"))
minetest.chat_send_all("Previous minetest instance crashed while placing UBC Map... Trying again from position: " .. startingValue)
end
if (startPosition == nil) then
startPosition = { x = 0, y = -3, z = 0 }
else
startPosition = { x = startPosition.x, y = startPosition.y, z = startPosition.z }
end
local coords = {}
for xx = 0, 2500, 500 do
for zz = 1, 7 do
local z = 3500 - (zz * 500)
table.insert(coords, { xx + startPosition.x, z + startPosition.z })
end
end
if (startingValue <= 28) then
for v = startingValue, 28 do
--for _, v in pairs(tiles) do
local coord = coords[v]
-- y must always be -3 because the schematic pos starts here
-- this maintains the true elevations across the map
-- place terrain first
local startPos = { x = coord[1], y = startPosition.y, z = coord[2] }
local endPos = { x = startPos.x + 500, y = startPos.y + 500, z = startPos.z + 500 }
UBCMap:placeSchematic(startPos, endPos, v, "0", nil, false)
minetest.chat_send_all("Placed combined tile: " .. tostring(v) .. " in world.")
UBCMap.storage:set_int("placementProgress", v)
local completion = tonumber(string.format("%.2f", (v / 28) * 100))
Debug.log(completion .. " % done!")
minetest.chat_send_all(completion .. " % done!")
collectgarbage("collect")
end
-- Collect garbage again;
collectgarbage("collect")
end
UBCMap.storage:set_int("generating", 0)
UBCMap.storage:set_string("placementPos", "")
Debug.log("Finished placing UBC Map!")
minetest.chat_send_all("Finished generating!")
inProgress = false
return true, "Map placed succesfully", 0
end
dofile(UBCMap.path .. "/integration.lua")
minetest.after(0, function()
Debug.log("Checking if the UBC map placement needs to resume...")
local status = UBCMap.storage:get_int("generating")
Debug.log("Status: " .. tostring(status))
Debug.log("Starting position: " .. UBCMap.storage:get_string("startPosition"))
Debug.log("Placement progress: " .. UBCMap.storage:get_int("placementProgress"))
if (status == 1) then
Debug.log(tostring(status) .. ": Resuming UBC map placement...")
local pos = minetest.deserialize(UBCMap.storage:get_string("placementPos"))
UBCMap.place(pos)
else
Debug.log(tostring(status) .. ": No UBC map placement in progress.")
end
end)