fun_caves/pyramid.lua
2016-08-03 08:02:35 -05:00

160 lines
4.8 KiB
Lua

local max_depth = 31000
-- pyramid stone
newnode = fun_caves.clone_node("default:sandstone")
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 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 99', 'default:obsidian_shard', 'farming:seed_cotton 99', 'farming:seed_wheat 99', 'default:junglewood 99', 'default:acacia_wood 99', 'default:glass 99', 'default:obsidian_glass 10', 'default:meselamp 5', 'fun_caves:moon_juice 10', 'default:sword_diamond', 'default:axe_diamond', 'default:paper 25', 'default:book 10', 'default:mese_crystal_fragment'}
if minetest.registered_entities['mobs_monster:sand_monster'] then
filler[#filler+1] = 'mobs_monster:sand_monster'
end
local gems = {'fun_caves:moonstone', 'fun_caves:coral_gem', 'fun_caves:garnet', 'fun_caves:aquamarine', 'fun_caves:sky_iron'}
local newnode = fun_caves.clone_node("default:chest")
newnode.description = "Treasure Casket"
newnode.light_source = 1
newnode.on_construct = nil
newnode.drop = 'default:chest'
newnode.on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
if not (pos and clicker) then
return
end
local meta = minetest.get_meta(pos)
if not meta then
return
end
local ready = meta:get_string('formspec')
if ready == '' then
if math.random(10) == 1 then
meta:set_string("formspec", chest_formspec)
local inv = meta:get_inventory()
inv:set_size("main", 8*4)
for i = 1, math.random(12) do
inv:add_item('main', filler[math.random(#filler)])
end
inv:add_item('main', gems[math.random(#gems)])
else
meta:set_string("formspec", 'del')
clicker:set_hp(clicker:get_hp() - 2)
minetest.remove_node(pos)
end
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 not (minp and maxp and data and p2data and area and node and type(data) == 'table' and type(p2data) == 'table') then
return
end
if math.random(20) ~= 1 then
return
end
if biomemap then
local biome = biome_ids[biomemap[3240]]
if not (fun_caves.pyramids_everywhere or pyramid_biomes[biome]) then
return
end
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)
if not pyramid_1 then
return
end
local write = true
local p2write = false
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)
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(50) == 1 then
data[ivm] = node['fun_caves:casket']
else
data[ivm] = node['air']
end
elseif dy >= base_height + 3 and dy <= base_height + 37 - math.max(math.abs(dx - 40), math.abs(dz - 40)) then
data[ivm] = node['fun_caves:pyramid_1']
elseif dy >= base_height and dy <= base_height + 40 - math.max(math.abs(dx - 40), math.abs(dz - 40)) then
data[ivm] = node['default:sandstone_block']
end
ivm = ivm + area.ystride
if dy % 5 == 0 then
index3d = index3d + csize.x
end
end
end
end
return write, p2write
end