From b76b4987e8bcca83f4e9f3345efc23882464dfd6 Mon Sep 17 00:00:00 2001 From: SmallJoker Date: Wed, 27 Jul 2016 19:57:44 +0200 Subject: [PATCH] Add mapgen part with a schematic to generate --- peoplecantmapgen/README.txt | 13 +++++++ peoplecantmapgen/depends.txt | 1 + peoplecantmapgen/init.lua | 65 +++++++++++++++++++++++++++++++ peoplecantmapgen/schems/flat.mts | Bin 0 -> 154 bytes 4 files changed, 79 insertions(+) create mode 100644 peoplecantmapgen/README.txt create mode 100644 peoplecantmapgen/depends.txt create mode 100644 peoplecantmapgen/init.lua create mode 100644 peoplecantmapgen/schems/flat.mts diff --git a/peoplecantmapgen/README.txt b/peoplecantmapgen/README.txt new file mode 100644 index 0000000..e7ba0b8 --- /dev/null +++ b/peoplecantmapgen/README.txt @@ -0,0 +1,13 @@ + People can't mapgen +===================== + +Depends: default + + Licenses +---------- + +Source code: + WTFPL (created by Krock) + +Flat schematics: + WTFPL (created by paramat) \ No newline at end of file diff --git a/peoplecantmapgen/depends.txt b/peoplecantmapgen/depends.txt new file mode 100644 index 0000000..331d858 --- /dev/null +++ b/peoplecantmapgen/depends.txt @@ -0,0 +1 @@ +default \ No newline at end of file diff --git a/peoplecantmapgen/init.lua b/peoplecantmapgen/init.lua new file mode 100644 index 0000000..7d47bbb --- /dev/null +++ b/peoplecantmapgen/init.lua @@ -0,0 +1,65 @@ +-- peoplecantmapgen - Generate flats randomly + +local flat_path = minetest.get_modpath("peoplecantmapgen") .. "/schems/flat.mts" + +minetest.register_on_generated(function(minp, maxp, seed) + if maxp.y < 2 and minp.y > 0 then + -- Only generate this stuff around the y=0 position + return + end + + local rand = PseudoRandom(seed + 1234321) + + if rand:next(0, 100) < 50 then + -- Skip the half of all generated chunks + return + end + + -- Convert some nodes into content IDs to use in the VoxelManipulator + local c_air = minetest.get_content_id("air") + local c_grass = minetest.get_content_id("default:dirt_with_grass") + + -- Load all the mapgen stuff + local vm = minetest.get_voxel_manip() + local emin, emax = vm:read_from_map(minp, maxp) + local area = VoxelArea:new{MinEdge=emin, MaxEdge=emax} + -- Array that contains all content IDs of this chunk + local data = vm:get_data() + + -- Make a random position + local random_pos = { + -- x,z: Do not generate on borders + x = rand:next(minp.x + 5, maxp.x - 5), + -- y: Dummy value + y = -1, + z = rand:next(minp.z + 5, maxp.z - 5) + } + + -- Searching the ground position + + local found = false + local last = -1 -- Last content ID, -1 does not exist + + -- From top->down start at y=30 + for y = 30, 0, -1 do + random_pos.y = y + -- Get the content ID of the position in random_pos + last = data[area:index(random_pos.x, random_pos.y, random_pos.z)] + if last ~= c_air then + -- Found something solid, exit the loop + found = true + break + end + end + + if found and last == c_grass then + -- Found grassy ground, place our flat + minetest.place_schematic( + random_pos, + flat_path, + "random", -- Random rotation + nil, -- No replacements + true -- Forced placement + ) + end +end) \ No newline at end of file diff --git a/peoplecantmapgen/schems/flat.mts b/peoplecantmapgen/schems/flat.mts new file mode 100644 index 0000000000000000000000000000000000000000..cee275a5b4c76cd62b25119090ec99e721459f8d GIT binary patch literal 154 zcmeYb3HD`RX5e68W#IS^0t_q+VkxOg^VDa9rEd8tW7naSA<9Oe1>IaWof zDF_w$NyV8dnTdJv={bqT#SF}enMD0>f~L**HdyaP{+7k}(DTQhF}>7X#n!?IfwuN literal 0 HcmV?d00001