Codebase list minetest-mod-nether / fea1c76
Imported Upstream version 2 Julien Puydt 7 years ago
3 changed file(s) with 83 addition(s) and 46 deletion(s). Raw diff Collapse all Expand all
00 stairs
11 default
2 moreblocks?
2424 -- Functions
2525
2626 local function build_portal(pos, target)
27 local p = {x = pos.x - 1, y = pos.y - 1, z = pos.z}
2827 local p1 = {x = pos.x - 1, y = pos.y - 1, z = pos.z}
2928 local p2 = {x = p1.x + 3, y = p1.y + 4, z = p1.z}
3029
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
4834 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})
5536 meta:set_string("p1", minetest.pos_to_string(p1))
5637 meta:set_string("p2", minetest.pos_to_string(p2))
5738 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)
7776 local nobj_cave_point = minetest.get_perlin(np_cave)
7877 local air = 0 -- Consecutive air nodes found
7978
8483 air = air + 1
8584 else -- Not cavern, check if 4 nodes of space above
8685 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
8894 else -- Not enough space, reset air to zero
8995 air = 0
9096 end
9197 end
9298 end
9399
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
94114 return y -- Fallback
95115 end
116
96117
97118 local function move_check(p1, max, dir)
98119 local p = {x = p1.x, y = p1.y, z = p1.z}
108129 return true
109130 end
110131
132
111133 local function check_portal(p1, p2)
112134 if p1.x ~= p2.x then
113135 if not move_check(p1, p2.x, "x") then
136158
137159 return true
138160 end
161
139162
140163 local function is_portal(pos)
141164 for d = -3, 3 do
152175 end
153176 end
154177 end
178
155179
156180 local function make_portal(pos)
157181 local p1, p2 = is_portal(pos)
183207 local target = {x = p1.x, y = p1.y, z = p1.z}
184208 target.x = target.x + 1
185209 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)
187211 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)
189214 end
190215
191216 for d = 0, 3 do
457482 default.node_sound_stone_defaults()
458483 )
459484
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
460496
461497 -- Craftitems
462498