Imported Upstream version 2
Julien Puydt
7 years ago
24 | 24 | -- Functions |
25 | 25 | |
26 | 26 | local function build_portal(pos, target) |
27 | local p = {x = pos.x - 1, y = pos.y - 1, z = pos.z} | |
28 | 27 | local p1 = {x = pos.x - 1, y = pos.y - 1, z = pos.z} |
29 | 28 | local p2 = {x = p1.x + 3, y = p1.y + 4, z = p1.z} |
30 | 29 | |
31 | for i = 1, 4 do | |
32 | minetest.set_node(p, {name = "default:obsidian"}) | |
33 | p.y = p.y + 1 | |
34 | end | |
35 | for i = 1, 3 do | |
36 | minetest.set_node(p, {name = "default:obsidian"}) | |
37 | p.x = p.x + 1 | |
38 | end | |
39 | for i = 1, 4 do | |
40 | minetest.set_node(p, {name = "default:obsidian"}) | |
41 | p.y = p.y - 1 | |
42 | end | |
43 | for i = 1, 3 do | |
44 | minetest.set_node(p, {name = "default:obsidian"}) | |
45 | p.x = p.x - 1 | |
46 | end | |
47 | ||
30 | local path = minetest.get_modpath("nether") .. "/schematics/nether_portal.mts" | |
31 | minetest.place_schematic({x = p1.x, y = p1.y, z = p1.z - 2}, path, 0, nil, true) | |
32 | ||
33 | for y = p1.y, p2.y do | |
48 | 34 | for x = p1.x, p2.x do |
49 | for y = p1.y, p2.y do | |
50 | p = {x = x, y = y, z = p1.z} | |
51 | if not (x == p1.x or x == p2.x or y == p1.y or y == p2.y) then | |
52 | minetest.set_node(p, {name = "nether:portal", param2 = 0}) | |
53 | end | |
54 | local meta = minetest.get_meta(p) | |
35 | local meta = minetest.get_meta({x = x, y = y, z = p1.z}) | |
55 | 36 | meta:set_string("p1", minetest.pos_to_string(p1)) |
56 | 37 | meta:set_string("p2", minetest.pos_to_string(p2)) |
57 | 38 | meta:set_string("target", minetest.pos_to_string(target)) |
58 | ||
59 | if y ~= p1.y then | |
60 | for z = -2, 2 do | |
61 | if z ~= 0 then | |
62 | p.z = p.z + z | |
63 | if minetest.registered_nodes[ | |
64 | minetest.get_node(p).name].is_ground_content then | |
65 | minetest.remove_node(p) | |
66 | end | |
67 | p.z = p.z - z | |
68 | end | |
69 | end | |
70 | end | |
71 | end | |
72 | end | |
73 | end | |
74 | ||
75 | local function find_nether_target_y(target_x, target_z) | |
76 | local start_y = NETHER_DEPTH - math.random(500, 1500) -- Search start | |
39 | end | |
40 | end | |
41 | end | |
42 | ||
43 | ||
44 | local function volume_is_natural(minp, maxp) | |
45 | local c_air = minetest.get_content_id("air") | |
46 | local c_ignore = minetest.get_content_id("ignore") | |
47 | ||
48 | local vm = minetest.get_voxel_manip() | |
49 | local pos1 = {x = minp.x, y = minp.y, z = minp.z} | |
50 | local pos2 = {x = maxp.x, y = maxp.y, z = maxp.z} | |
51 | local emin, emax = vm:read_from_map(pos1, pos2) | |
52 | local area = VoxelArea:new({MinEdge = emin, MaxEdge = emax}) | |
53 | local data = vm:get_data() | |
54 | ||
55 | for z = pos1.z, pos2.z do | |
56 | for y = pos1.y, pos2.y do | |
57 | local vi = area:index(pos1.x, y, z) | |
58 | for x = pos1.x, pos2.x do | |
59 | local id = data[vi] -- Existing node | |
60 | if id ~= c_air and id ~= c_ignore then -- These are natural | |
61 | local name = minetest.get_name_from_content_id(id) | |
62 | if not minetest.registered_nodes[name].is_ground_content then | |
63 | return false | |
64 | end | |
65 | end | |
66 | vi = vi + 1 | |
67 | end | |
68 | end | |
69 | end | |
70 | ||
71 | return true | |
72 | end | |
73 | ||
74 | ||
75 | local function find_nether_target_y(target_x, target_z, start_y) | |
77 | 76 | local nobj_cave_point = minetest.get_perlin(np_cave) |
78 | 77 | local air = 0 -- Consecutive air nodes found |
79 | 78 | |
84 | 83 | air = air + 1 |
85 | 84 | else -- Not cavern, check if 4 nodes of space above |
86 | 85 | if air >= 4 then |
87 | return y + 2 | |
86 | -- Check volume for non-natural nodes | |
87 | local minp = {x = target_x - 1, y = y - 1, z = target_z - 2} | |
88 | local maxp = {x = target_x + 2, y = y + 3, z = target_z + 2} | |
89 | if volume_is_natural(minp, maxp) then | |
90 | return y + 2 | |
91 | else -- Restart search a little lower | |
92 | find_nether_target_y(target_x, target_z, y - 16) | |
93 | end | |
88 | 94 | else -- Not enough space, reset air to zero |
89 | 95 | air = 0 |
90 | 96 | end |
91 | 97 | end |
92 | 98 | end |
93 | 99 | |
100 | return start_y -- Fallback | |
101 | end | |
102 | ||
103 | ||
104 | local function find_surface_target_y(target_x, target_z, start_y) | |
105 | for y = start_y, start_y - 256, -16 do | |
106 | -- Check volume for non-natural nodes | |
107 | local minp = {x = target_x - 1, y = y - 1, z = target_z - 2} | |
108 | local maxp = {x = target_x + 2, y = y + 3, z = target_z + 2} | |
109 | if volume_is_natural(minp, maxp) then | |
110 | return y | |
111 | end | |
112 | end | |
113 | ||
94 | 114 | return y -- Fallback |
95 | 115 | end |
116 | ||
96 | 117 | |
97 | 118 | local function move_check(p1, max, dir) |
98 | 119 | local p = {x = p1.x, y = p1.y, z = p1.z} |
108 | 129 | return true |
109 | 130 | end |
110 | 131 | |
132 | ||
111 | 133 | local function check_portal(p1, p2) |
112 | 134 | if p1.x ~= p2.x then |
113 | 135 | if not move_check(p1, p2.x, "x") then |
136 | 158 | |
137 | 159 | return true |
138 | 160 | end |
161 | ||
139 | 162 | |
140 | 163 | local function is_portal(pos) |
141 | 164 | for d = -3, 3 do |
152 | 175 | end |
153 | 176 | end |
154 | 177 | end |
178 | ||
155 | 179 | |
156 | 180 | local function make_portal(pos) |
157 | 181 | local p1, p2 = is_portal(pos) |
183 | 207 | local target = {x = p1.x, y = p1.y, z = p1.z} |
184 | 208 | target.x = target.x + 1 |
185 | 209 | if target.y < NETHER_DEPTH then |
186 | target.y = math.random(-32, 1) | |
210 | target.y = find_surface_target_y(target.x, target.z, -16) | |
187 | 211 | else |
188 | target.y = find_nether_target_y(target.x, target.z) | |
212 | local start_y = NETHER_DEPTH - math.random(500, 1500) -- Search start | |
213 | target.y = find_nether_target_y(target.x, target.z, start_y) | |
189 | 214 | end |
190 | 215 | |
191 | 216 | for d = 0, 3 do |
457 | 482 | default.node_sound_stone_defaults() |
458 | 483 | ) |
459 | 484 | |
485 | -- StairsPlus | |
486 | ||
487 | if minetest.get_modpath("moreblocks") then | |
488 | stairsplus:register_all( | |
489 | "nether", "brick", "nether:brick", { | |
490 | description = "Nether Brick", | |
491 | groups = {cracky = 2, level = 2}, | |
492 | tiles = {"nether_brick.png"}, | |
493 | sounds = default.node_sound_stone_defaults(), | |
494 | }) | |
495 | end | |
460 | 496 | |
461 | 497 | -- Craftitems |
462 | 498 |
Binary diff not shown