diff options
Diffstat (limited to 'mods/ma_pan')
| -rw-r--r-- | mods/ma_pan/init.lua | 116 | ||||
| -rw-r--r-- | mods/ma_pan/mod.conf | 3 |
2 files changed, 119 insertions, 0 deletions
diff --git a/mods/ma_pan/init.lua b/mods/ma_pan/init.lua new file mode 100644 index 0000000..de0d586 --- /dev/null +++ b/mods/ma_pan/init.lua @@ -0,0 +1,116 @@ +local chunkgen = {} +chunkgen.__index = chunkgen + +function chunkgen.new(minp, maxp, blockseed) + local new = {} + setmetatable(new, chunkgen) + new.minp, new.maxp, new.blockseed = minp, maxp, blockseed + return new +end + +local perlin_noise_params = { + offset = 0, + scale = 1, + spread = {x=10, y=10, z=10}, + seed = 0xBEE, + octaves = 2, + persistence = 0.5, + lacunarity = 2, + flags = {"noeased", "absvalue"} +} + +local perlin_noise_params_2 = { + offset = 0, + scale = 1, + spread = {x=32, y=32, z=32}, + seed = 0xBEE5, + octaves = 2, + persistence = 0.5, + lacunarity = 2, + flags = {"noeased", "absvalue"} +} + +local ingredients = {"alasa_pan:telo", "alasa_pan:ko_pan", "alasa_pan:ko_suli"} +local blocks = {"alasa_pan:leko_loje", "alasa_pan:leko_loje2", "alasa_pan:leko_jelo", "alasa_pan:leko_laso", "alasa_pan:leko_laso2", "alasa_pan:leko_laso3", "alasa_pan:leko_unu", "alasa_pan:leko_pimeja"} +local min_height = -1.3 +local max_height = 1.3 +local function get_color(height) + height = (height - min_height) / (max_height - min_height) + height = height * #blocks + height = math.floor(height)+1 + if height < 1 then height = 1 end + if height > #blocks then height = #blocks end + return blocks[height] +end + +function chunkgen:block_at_pos(x, y, z) + if y < 0 then + return "alasa_pan:anpa" + end + if y > 2 then return "air" end + local height = self.heightmap and self.heightmap[x-self.minp.x+1][z-self.minp.z+1] or 0 + local height2 = self.heightmap_2 and self.heightmap_2[x-self.minp.x+1][z-self.minp.z+1] or 0 + if height > 0 and x*x + z*z > 70 then return get_color(height2) end + + if y == 0 and math.random(1, 100) == 1 then + return ingredients[math.random(1, 3)] + end + + return "air" +end + +local oven_structure = {"alasa_pan:ilo_seli", nil, nil, nil, "alasa_pan:ilo_pona"} +local oven_w = 5 +local oven_h = 1 +function chunkgen:oven_override(block, x, y, z, ox, oz) + if y < 0 or y > 1 then return block end + local in_oven = x >= ox and x <= ox + oven_w - 1 and z >= oz and z <= oz + oven_h - 1 + if not in_oven then return block end + local oven_block = oven_structure[x-ox + (z-oz)*oven_w + 1] + if not oven_block then return block end + if y == 0 then return "alasa_pan:leko" end + return oven_block +end + + +function chunkgen:generate() + local minp, maxp = self.minp, self.maxp + if minp.y > 1 then return end + math.randomseed(self.blockseed, 34802398420983428) + + local has_oven = math.random(1, 25) == 1 -- ni li suli tan ni: leko li lon la jan li ken ala lukin e ilo seli. + local oven_x = math.random(minp.x, maxp.x - oven_w + 1) + local oven_z = math.random(minp.z, maxp.z - oven_h + 1) + if minp.x == -32 and minp.z == -32 then + has_oven = true + oven_x = -2 + oven_z = 0 + end + + local nontrivial_chunk = (minp.y <= 0 and maxp.y >= 2) + if nontrivial_chunk then + local noise_map = minetest.get_perlin_map(perlin_noise_params, {x=80, y=80}) + local noise_map_2 = minetest.get_perlin_map(perlin_noise_params_2, {x=80, y=80}) + self.heightmap = noise_map:get_2d_map({x=minp.x, y=minp.z}) + self.heightmap_2 = noise_map_2:get_2d_map({x=minp.x, y=minp.z}) + end + + local voxel_manip = minetest.get_voxel_manip(minp, maxp) + local data = {} + for x=minp.x, maxp.x do + for y=minp.y, maxp.y do + for z=minp.z, maxp.z do + local block = self:block_at_pos(x, y, z) + if has_oven then block = self:oven_override(block, x, y, z, oven_x, oven_z) end + table.insert(data, minetest.get_content_id(block)) + end + end + end + voxel_manip:set_data(data) + voxel_manip:write_to_map(true) +end + +minetest.register_on_generated(function(minp, maxp, blockseed) + local cg = chunkgen.new(minp, maxp, blockseed) + cg:generate() +end)
\ No newline at end of file diff --git a/mods/ma_pan/mod.conf b/mods/ma_pan/mod.conf new file mode 100644 index 0000000..c61d4d5 --- /dev/null +++ b/mods/ma_pan/mod.conf @@ -0,0 +1,3 @@ +name = ma_pan +description = ilo pi pali ma tan musi "alasa pan". +depends = leko_pan
\ No newline at end of file |
