Codebase list minetest-mod-nether / 47d3987
Caverns. Fix node defs/crafting. Smaller emerge. Find cavern floor (#17) Large caverns using squashed 3D noise Less lava, more glowstone, no air pockets Preserve nether dungeons Allow light to spread from glowstone and make brighter Fix 'is ground content' settings, portals should not be excavated by overgenerated caves Rack drops itself as normal Make brick, fence, stair, slab groups consistent Use 'node sound gravel defaults' for sand Make brick crafting consistent with default Make fence recipe output number consistent with default Make 'emerge area' volume mimimum required size Add 'find nether target y' function to search for a cavern floor with space above for nether portal spawn Paramat authored 7 years ago Auke Kok committed 7 years ago
1 changed file(s) with 190 addition(s) and 71 deletion(s). Raw diff Collapse all Expand all
00 -- Parameters
11
22 local NETHER_DEPTH = -5000
3 local TCAVE = 0.6
4 local BLEND = 128
5
6
7 -- 3D noise
8
9 local np_cave = {
10 offset = 0,
11 scale = 1,
12 spread = {x = 384, y = 128, z = 384}, -- squashed 3:1
13 seed = 59033,
14 octaves = 5,
15 persist = 0.7
16 }
17
18
19 -- Stuff
20
21 local yblmax = NETHER_DEPTH - BLEND * 2
322
423
524 -- Functions
4160 for z = -2, 2 do
4261 if z ~= 0 then
4362 p.z = p.z + z
44 if minetest.registered_nodes[minetest.get_node(p).name].is_ground_content then
63 if minetest.registered_nodes[
64 minetest.get_node(p).name].is_ground_content then
4565 minetest.remove_node(p)
4666 end
4767 p.z = p.z - z
5070 end
5171 end
5272 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
77 local nobj_cave_point = minetest.get_perlin(np_cave)
78 local air = 0 -- Consecutive air nodes found
79
80 for y = start_y, start_y - 4096, -1 do
81 local nval_cave = nobj_cave_point:get3d({x = target_x, y = y, z = target_z})
82
83 if nval_cave > TCAVE then -- Cavern
84 air = air + 1
85 else -- Not cavern, check if 4 nodes of space above
86 if air >= 4 then
87 return y + 2
88 else -- Not enough space, reset air to zero
89 air = 0
90 end
91 end
92 end
93
94 return y -- Fallback
5395 end
5496
5597 local function move_check(p1, max, dir)
141183 local target = {x = p1.x, y = p1.y, z = p1.z}
142184 target.x = target.x + 1
143185 if target.y < NETHER_DEPTH then
144 target.y = math.random(-50, 20)
186 target.y = math.random(-32, 1)
145187 else
146 target.y = NETHER_DEPTH - math.random(500, 1500)
188 target.y = find_nether_target_y(target.x, target.z)
147189 end
148190
149191 for d = 0, 3 do
200242 minetest.get_voxel_manip():read_from_map(target, target)
201243 if not minetest.get_node_or_nil(target) then
202244 minetest.emerge_area(
203 vector.subtract(target, 80), vector.add(target, 80))
245 vector.subtract(target, 4), vector.add(target, 4))
204246 end
205247 -- teleport the player
206248 minetest.after(3, function(obj, pos, target)
270312 diggable = false,
271313 pointable = false,
272314 buildable_to = false,
315 is_ground_content = false,
273316 drop = "",
274317 light_source = 5,
275318 post_effect_color = {a = 180, r = 128, g = 0, b = 128},
286329 minetest.register_node(":default:obsidian", {
287330 description = "Obsidian",
288331 tiles = {"default_obsidian.png"},
289 is_ground_content = true,
332 is_ground_content = false,
290333 sounds = default.node_sound_stone_defaults(),
291334 groups = {cracky = 1, level = 2},
292335
349392 description = "Netherrack",
350393 tiles = {"nether_rack.png"},
351394 is_ground_content = true,
352 drop = {
353 max_items = 1,
354 items = {
355 {rarity = 3, items = {"nether:rack"}},
356 }
357 },
358395 groups = {cracky = 3, level = 2},
359396 sounds = default.node_sound_stone_defaults(),
360397 })
364401 tiles = {"nether_sand.png"},
365402 is_ground_content = true,
366403 groups = {crumbly = 3, level = 2, falling_node = 1},
367 sounds = default.node_sound_dirt_defaults({
404 sounds = default.node_sound_gravel_defaults({
368405 footstep = {name = "default_gravel_footstep", gain = 0.45},
369406 }),
370407 })
373410 description = "Glowstone",
374411 tiles = {"nether_glowstone.png"},
375412 is_ground_content = true,
376 light_source = 13,
413 light_source = 14,
414 paramtype = "light",
377415 groups = {cracky = 3, oddly_breakable_by_hand = 3},
378416 sounds = default.node_sound_glass_defaults(),
379417 })
381419 minetest.register_node("nether:brick", {
382420 description = "Nether Brick",
383421 tiles = {"nether_brick.png"},
422 is_ground_content = false,
384423 groups = {cracky = 2, level = 2},
385424 sounds = default.node_sound_stone_defaults(),
386425 })
401440 type = "fixed",
402441 fixed = {-1/7, -1/2, -1/7, 1/7, 1/2, 1/7},
403442 },
404 groups = {cracky = 3, level = 2},
443 groups = {cracky = 2, level = 2},
405444 sounds = default.node_sound_stone_defaults(),
406445 })
407446
411450 stairs.register_stair_and_slab(
412451 "nether_brick",
413452 "nether:brick",
414 {cracky = 3, oddly_breakable_by_hand = 1},
453 {cracky = 2, level = 2},
415454 {"nether_brick.png"},
416455 "nether stair",
417456 "nether slab",
440479 -- Crafting
441480
442481 minetest.register_craft({
443 output = "nether:brick",
444 type = "shapeless",
482 output = "nether:brick 4",
445483 recipe = {
446 "nether:rack",
447 "nether:rack",
448 "nether:rack",
449 "nether:rack",
450 },
484 {"nether:rack", "nether:rack"},
485 {"nether:rack", "nether:rack"},
486 }
451487 })
452488
453489 minetest.register_craft({
454 output = "nether:fence_nether_brick 16",
490 output = "nether:fence_nether_brick 6",
455491 recipe = {
456492 {"nether:brick", "nether:brick", "nether:brick"},
457493 {"nether:brick", "nether:brick", "nether:brick"},
461497
462498 -- Mapgen
463499
464 local air = minetest.get_content_id("air")
465 local stone_with_coal = minetest.get_content_id("default:stone_with_coal")
466 local stone_with_iron = minetest.get_content_id("default:stone_with_iron")
467 local stone_with_mese = minetest.get_content_id("default:stone_with_mese")
468 local stone_with_diamond = minetest.get_content_id("default:stone_with_diamond")
469 local stone_with_gold = minetest.get_content_id("default:stone_with_gold")
470 local stone_with_copper = minetest.get_content_id("default:stone_with_copper")
471 local gravel = minetest.get_content_id("default:gravel")
472 local dirt = minetest.get_content_id("default:dirt")
473 local sand = minetest.get_content_id("default:sand")
474 local cobble = minetest.get_content_id("default:cobble")
475 local mossycobble = minetest.get_content_id("default:mossycobble")
476 local stair_cobble = minetest.get_content_id("stairs:stair_cobble")
477 local lava_source = minetest.get_content_id("default:lava_source")
478 local lava_flowing = minetest.get_content_id("default:lava_flowing")
479
480 local glowstone = minetest.get_content_id("nether:glowstone")
481 local nethersand = minetest.get_content_id("nether:sand")
482 local netherbrick = minetest.get_content_id("nether:brick")
483 local netherrack = minetest.get_content_id("nether:rack")
500 -- Initialize noise object and localise noise buffer
501
502 local nobj_cave = nil
503 local nbuf_cave
504
505
506 -- Content ids
507
508 local c_air = minetest.get_content_id("air")
509
510 local c_stone_with_coal = minetest.get_content_id("default:stone_with_coal")
511 local c_stone_with_iron = minetest.get_content_id("default:stone_with_iron")
512 local c_stone_with_mese = minetest.get_content_id("default:stone_with_mese")
513 local c_stone_with_diamond = minetest.get_content_id("default:stone_with_diamond")
514 local c_stone_with_gold = minetest.get_content_id("default:stone_with_gold")
515 local c_stone_with_copper = minetest.get_content_id("default:stone_with_copper")
516 local c_mese = minetest.get_content_id("default:mese")
517
518 local c_gravel = minetest.get_content_id("default:gravel")
519 local c_dirt = minetest.get_content_id("default:dirt")
520 local c_sand = minetest.get_content_id("default:sand")
521
522 local c_cobble = minetest.get_content_id("default:cobble")
523 local c_mossycobble = minetest.get_content_id("default:mossycobble")
524 local c_stair_cobble = minetest.get_content_id("stairs:stair_cobble")
525
526 local c_lava_source = minetest.get_content_id("default:lava_source")
527 local c_lava_flowing = minetest.get_content_id("default:lava_flowing")
528 local c_water_source = minetest.get_content_id("default:water_source")
529 local c_water_flowing = minetest.get_content_id("default:water_flowing")
530
531 local c_glowstone = minetest.get_content_id("nether:glowstone")
532 local c_nethersand = minetest.get_content_id("nether:sand")
533 local c_netherbrick = minetest.get_content_id("nether:brick")
534 local c_netherrack = minetest.get_content_id("nether:rack")
535
536
537 -- On-generated function
484538
485539 minetest.register_on_generated(function(minp, maxp, seed)
486 if maxp.y > NETHER_DEPTH then
540 if minp.y > NETHER_DEPTH then
487541 return
488542 end
489543
544 local t1 = os.clock()
545
546 local x1 = maxp.x
547 local y1 = maxp.y
548 local z1 = maxp.z
549 local x0 = minp.x
550 local y0 = minp.y
551 local z0 = minp.z
552
490553 local vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
554 local area = VoxelArea:new{MinEdge = emin, MaxEdge = emax}
491555 local data = vm:get_data()
492 local area = VoxelArea:new{MinEdge = emin, MaxEdge = emax}
493
494 for vi in area:iterp(minp, maxp) do
495 local id = data[vi]
496 if id == air or
497 id == stone_with_coal or
498 id == stone_with_iron then
499 data[vi] = air
500 elseif id == stone_with_mese or
501 id == stone_with_diamond or
502 id == lava_source then
503 data[vi] = lava_source
504 elseif id == lava_flowing then
505 -- nothing
506 elseif id == stone_with_gold then
507 data[vi] = glowstone
508 elseif id == stone_with_copper or
509 id == gravel or
510 id == dirt or
511 id == sand then
512 data[vi] = nethersand
513 elseif id == cobble or
514 id == mossycobble or
515 id == stair_cobble then
516 data[vi] = netherbrick
517 else
518 data[vi] = netherrack
556
557 local x11 = emax.x -- Limits of mapchunk plus mapblock shell
558 local y11 = emax.y
559 local z11 = emax.z
560 local x00 = emin.x
561 local y00 = emin.y
562 local z00 = emin.z
563
564 local ystride = x1 - x0 + 1
565 local zstride = ystride * ystride
566 local chulens = {x = ystride, y = ystride, z = ystride}
567 local minposxyz = {x = x0, y = y0, z = z0}
568
569 nobj_cave = nobj_cave or minetest.get_perlin_map(np_cave, chulens)
570 local nvals_cave = nobj_cave:get3dMap_flat(minposxyz, nbuf_cave)
571
572 for y = y00, y11 do -- Y loop first to minimise tcave calculations
573 local tcave
574 local in_chunk_y = false
575 if y >= y0 and y <= y1 then
576 if y > yblmax then
577 tcave = TCAVE + ((y - yblmax) / BLEND) ^ 2
578 else
579 tcave = TCAVE
580 end
581 in_chunk_y = true
582 end
583
584 for z = z00, z11 do
585 local vi = area:index(x00, y, z) -- Initial voxelmanip index
586 local ni
587 local in_chunk_yz = in_chunk_y and z >= z0 and z <= z1
588
589 for x = x00, x11 do
590 if in_chunk_yz and x == x0 then
591 -- Initial noisemap index
592 ni = (z - z0) * zstride + (y - y0) * ystride + 1
593 end
594 local in_chunk_yzx = in_chunk_yz and x >= x0 and x <= x1 -- In mapchunk
595
596 local id = data[vi] -- Existing node
597 -- Cave air, cave liquids and dungeons are overgenerated,
598 -- convert these throughout mapchunk plus shell
599 if id == c_air or -- Air and liquids to air
600 id == c_lava_source or
601 id == c_lava_flowing or
602 id == c_water_source or
603 id == c_water_flowing then
604 data[vi] = c_air
605 -- Dungeons are preserved so we don't need
606 -- to check for cavern in the shell
607 elseif id == c_cobble or -- Dungeons (preserved) to netherbrick
608 id == c_mossycobble or
609 id == c_stair_cobble then
610 data[vi] = c_netherbrick
611 end
612
613 if in_chunk_yzx then -- In mapchunk
614 if nvals_cave[ni] > tcave then -- Only excavate cavern in mapchunk
615 data[vi] = c_air
616 elseif id == c_mese then -- Mese block to lava
617 data[vi] = c_lava_source
618 elseif id == c_stone_with_gold or -- Precious ores to glowstone
619 id == c_stone_with_mese or
620 id == c_stone_with_diamond then
621 data[vi] = c_glowstone
622 elseif id == c_gravel or -- Blob ore to nethersand
623 id == c_dirt or
624 id == c_sand then
625 data[vi] = c_nethersand
626 else -- All else to netherstone
627 data[vi] = c_netherrack
628 end
629
630 ni = ni + 1 -- Only increment noise index in mapchunk
631 end
632
633 vi = vi + 1
634 end
519635 end
520636 end
521637
524640 vm:calc_lighting()
525641 vm:update_liquids()
526642 vm:write_to_map()
643
644 local chugent = math.ceil((os.clock() - t1) * 1000)
645 print ("[nether] generate chunk " .. chugent .. " ms")
527646 end)