-
Notifications
You must be signed in to change notification settings - Fork 2
/
init.lua
137 lines (132 loc) · 3.97 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
--package.cpath = package.cpath .. ";/usr/share/lua/5.2/?.so"
--package.path = package.path .. ";/usr/share/zbstudio/lualibs/mobdebug/?.lua"
--require('mobdebug').start()
settlements = {}
settlements.modpath = minetest.get_modpath("settlements");
dofile(settlements.modpath.."/const.lua")
dofile(settlements.modpath.."/utils.lua")
dofile(settlements.modpath.."/foundation.lua")
dofile(settlements.modpath.."/buildings.lua")
dofile(settlements.modpath.."/paths.lua")
--
-- load settlements on server
--
settlements_in_world = settlements.load()
--
-- register block for npc spawn
--
minetest.register_node("settlements:junglewood", {
description = "special junglewood floor",
tiles = {"default_junglewood.png"},
groups = {choppy=3, wood=2},
sounds = default.node_sound_wood_defaults(),
})
--
-- register inhabitants
--
if minetest.get_modpath("mobs_npc") ~= nil then
mobs:register_spawn("mobs_npc:npc", --name
{"settlements:junglewood"}, --nodes
20, --max_light
0, --min_light
20, --chance
7, --active_object_count
31000, --max_height
nil) --day_toggle
mobs:register_spawn("mobs_npc:trader", --name
{"settlements:junglewood"}, --nodes
20, --max_light
0, --min_light
20, --chance
7, --active_object_count
31000, --max_height
nil)--day_toggle
end
--
-- on map generation, try to build a settlement
--
minetest.register_on_generated(function(minp, maxp)
--
-- randomly try to build settlements
--
if math.random(1,10)<9 then
--
-- don't build settlement underground
--
if maxp.y < 0 then
return
end
--
-- don't build settlements too close to each other
--
local center_of_chunk = {
x=maxp.x-half_map_chunk_size,
y=maxp.y-half_map_chunk_size,
z=maxp.z-half_map_chunk_size
}
local dist_ok = settlements.check_distance_other_settlements(center_of_chunk)
if dist_ok == false
then
return
end
--
-- don't build settlements on (too) uneven terrain
--
local height_difference = settlements.evaluate_heightmap(minp, maxp)
if height_difference > max_height_difference
then
return
end
--
-- if nothing prevents the settlement -> do it
--
settlements.place_settlement_circle(minp, maxp)
end
end)
--
-- manually place buildings, for debugging only
--
minetest.register_craftitem("settlements:tool", {
description = "settlements build tool",
inventory_image = "default_tool_woodshovel.png",
--
-- build single house
--
on_use = function(itemstack, placer, pointed_thing)
local center_surface = pointed_thing.under
if center_surface then
local building_all_info = {name = "blacksmith",
mts = schem_path.."blacksmith.mts",
hsize = 13,
max_num = 0.9,
rplc = "n"}
settlements.build_schematic(center_surface,
building_all_info["mts"],
building_all_info["rplc"],
building_all_info["name"])
-- settlements.convert_mts_to_lua()
-- settlements.mts_save()
end
end,
--
-- build ssettlement
--
on_place = function(itemstack, placer, pointed_thing)
-- enable debug routines
settlements.debug = true
local center_surface = pointed_thing.under
if center_surface then
local minp = {
x=center_surface.x-half_map_chunk_size,
y=center_surface.y-half_map_chunk_size,
z=center_surface.z-half_map_chunk_size
}
local maxp = {
x=center_surface.x+half_map_chunk_size,
y=center_surface.y+half_map_chunk_size,
z=center_surface.z+half_map_chunk_size
}
settlements.place_settlement_circle(minp, maxp)
end
end
})