fun_caves/pyramid.lua

144 lines
4.1 KiB
Lua

local max_depth = 31000
-- pyramid stone
newnode = fun_caves.clone_node("default:sandstone_block")
newnode.description = "Pyramid Stone"
newnode.tiles = {'fun_caves_pyramid_stone.png'}
newnode.groups.pyramid = 1
newnode.drop = 'default:sandstone'
minetest.register_node("fun_caves:pyramid_1", newnode)
local newnode = fun_caves.clone_node("default:chest")
newnode.description = "Treasure Casket"
local chest_formspec =
"size[8,9]" ..
default.gui_bg ..
default.gui_bg_img ..
default.gui_slots ..
"list[current_name;main;0,0.3;8,4;]" ..
"list[current_player;main;0,4.85;8,1;]" ..
"list[current_player;main;0,6.08;8,3;8]" ..
"listring[current_name;main]" ..
"listring[current_player;main]" ..
default.get_hotbar_bg(0,4.85)
local filler = {'default:apple 10', 'default:coal_lump 10', 'default:wood 10'}
local gems = {'fun_caves:moonstone', 'fun_caves:coral_gem', 'fun_caves:garnet', 'fun_caves:aquamarine', 'fun_caves:zoisite'}
newnode.on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
local meta = minetest.get_meta(pos)
local true_casket = meta:get_string('true')
if true_casket ~= 'true' then
clicker:set_hp(clicker:get_hp() - 2)
--print('* ouch!')
return
end
local ready = meta:get_string('formspec')
if ready == '' then
meta:set_string("formspec", chest_formspec)
local inv = meta:get_inventory()
inv:set_size("main", 8*4)
for i = 1, math.random(4) do
inv:add_item('main', filler[math.random(#filler)])
end
inv:add_item('main', gems[math.random(#gems)])
end
end
minetest.register_node("fun_caves:casket", newnode)
local pyramid_biomes = {}
for _, i in pairs({"rainforest", "desert", "desertstone_grassland", }) do
pyramid_biomes[i] = true
end
local pyramid_noise_1 = {offset = 0, scale = 1, seed = -6012, spread = {x = 20, y = 10, z = 20}, octaves = 6, persist = 1, lacunarity = 2}
fun_caves.pyramid = function(minp, maxp, data, p2data, area, biomemap, biome_ids, node, heightmap)
if math.random(10) ~= 1 then
return
end
if biomemap then
local biome = biome_ids[biomemap[3240]]
if not pyramid_biomes[biome] then
return
end
--print('* Creating pyramid in '..biome)
elseif math.random(5) ~= 1 then
return
end
local min_y = 80
local index = 0
for z = minp.z, maxp.z do
local dz = z - minp.z
for x = minp.x, maxp.x do
local dx = x - minp.x
index = index + 1
if dz > 8 and dz < 72 and dx > 8 and dx < 72 and heightmap[index] - minp.y < 0 then
return
elseif heightmap[index] - minp.y < min_y then
min_y = heightmap[index] - minp.y
end
end
end
if min_y >= 72 or heightmap[3240] >= 72 then
return
end
local base_height = math.min(min_y, 35)
local csize = vector.add(vector.subtract(maxp, minp), 1)
local map_max = {x = csize.x, y = csize.y, z = csize.z}
local map_min = {x = minp.x, y = minp.y, z = minp.z}
local pyramid_1 = minetest.get_perlin_map(pyramid_noise_1, map_max):get3dMap_flat(map_min)
local write = true
local p2write = false
local caskets = {}
index = 0
local index3d = 0
for z = minp.z, maxp.z do
local dz = z - minp.z
for x = minp.x, maxp.x do
local dx = x - minp.x
index = index + 1
index3d = math.floor((z - minp.z) / 5) * (csize.y) * csize.x + math.floor((x - minp.x) / 5) + 1
local ivm = area:index(x, minp.y, z)
--pyramid_1[index] = math.floor(pyramid_1[index] + 0.5)
for y = minp.y, maxp.y do
local dy = y - minp.y
if dy >= base_height + 3 and dy <= base_height + 37 - math.max(math.abs(dx - 40), math.abs(dz - 40)) and pyramid_1[index3d] > 0 then
if data[ivm - area.ystride] == node['fun_caves:pyramid_1'] and math.random(100) == 1 then
data[ivm] = node['fun_caves:casket']
caskets[#caskets+1] = {x=x, y=y, z=z}
else
data[ivm] = node['air']
end
elseif dy >= base_height and dy <= base_height + 40 - math.max(math.abs(dx - 40), math.abs(dz - 40)) then
data[ivm] = node['fun_caves:pyramid_1']
end
ivm = ivm + area.ystride
if dy % 5 == 0 then
index3d = index3d + csize.x
end
end
end
end
if #caskets > 0 then
return write, p2write, caskets[math.random(#caskets)]
else
return write, p2write
end
end