Fix variable == nil error.

This commit is contained in:
Duane 2016-07-19 12:00:20 -05:00
parent b2c104d53a
commit a1a5fb0a7f
5 changed files with 135 additions and 2 deletions

106
castles.lua Normal file
View file

@ -0,0 +1,106 @@
local csize
fun_caves.ice_castle = function(minp, maxp, data, p2data, area, node, heightmap, biomemap, biome_ids, underzone)
csize = vector.add(vector.subtract(maxp, minp), 1)
local write = false
local write_p2 = false
local max_height = -33000
local min_height = 33000
local avg_height = 0
local avg_count = 0
local height_grid = {{}, {}, {}, {}, {}, {}, {}, {}, {}, {}}
for z = minp.z, maxp.z do
local dz = math.ceil((z - minp.z + 1) / 8)
for x = minp.x, maxp.x do
local dx = math.ceil((x - minp.x + 1) / 8)
local ivm = area:index(x, maxp.y, z)
for y = maxp.y, minp.y, -1 do
if data[ivm] ~= node['air'] then
if y > minp.y + 50 then
return
end
if y > max_height then
max_height = y
end
if y < min_height then
min_height = y
end
print(dx, dz)
if not height_grid[dx][dz] then
height_grid[dx][dz] = -33000
end
if y > height_grid[dx][dz] then
height_grid[dx][dz] = y
end
if x == minp.x + 8 or x == maxp.x - 8 or z == minp.z + 8 or z == maxp.z - 8 then
avg_height = avg_height + y
avg_count = avg_count + 1
end
break
end
ivm = ivm - area.ystride
end
end
end
avg_height = avg_height / avg_count
max_height = max_height
for z = 1, 10 do
for x = 1, 10 do
height_grid[x][z] = height_grid[x][z] + math.random(20) + 5
end
end
local index = 0
local index3d = 0
local pos = {x=0, y=0, z=0}
local math_floor = math.floor
local math_max = math.max
local math_min = math.min
local math_log = math.log
for z = minp.z + 8, maxp.z - 8 do
local dz = math.ceil((z - minp.z + 1) / 8)
local r1z = (z - minp.z) % 8
local r2z = r1z < 4 and r1z or 7 - r1z
for x = minp.x + 8, maxp.x - 8 do
local dx = math.ceil((x - minp.x + 1) / 8)
local r1x = (x - minp.x) % 8
local r2x = r1x < 4 and r1x or 7 - r1x
index = index + 1
index3d = (z - minp.z) * (csize.y + 2) * csize.x + (x - minp.x) + 1
local ivm = area:index(x, minp.y, z)
for y = minp.y, maxp.y do
if y > height_grid[dx][dz] + 2 * math.min(r2x, r2z) then
data[ivm] = node['air']
elseif r1x == 0 and (dx < 3 or height_grid[dx - 1][dz] < y) then
data[ivm] = node['default:ice']
elseif r1x == 7 and (dx > 8 or height_grid[dx + 1][dz] < y) then
data[ivm] = node['default:ice']
elseif r1z == 0 and (dz < 3 or height_grid[dx][dz - 1] < y) then
data[ivm] = node['default:ice']
elseif r1z == 7 and (dz > 8 or height_grid[dx][dz + 1] < y) then
data[ivm] = node['default:ice']
elseif y > height_grid[dx][dz] + 2 * math.min(r2x, r2z) - 2 then
data[ivm] = node['default:ice']
elseif y > min_height - 5 and (not ((dx < 5 or dx > 6) or (dz < 5 or dz > 6)) or ((y - minp.y) % 8 ~= 0 and y < height_grid[dx][dz] - 5)) then
data[ivm] = node['air']
elseif y > min_height - 5 and (y - minp.y) % 8 == 0 then
data[ivm] = node['default:ice']
elseif y > min_height - 10 then
data[ivm] = node['default:ice']
end
ivm = ivm + area.ystride
index3d = index3d + csize.x
end
end
end
return write, write_p2
end

View file

@ -1,3 +1,5 @@
dofile(fun_caves.path .. "/castles.lua")
local deco_depth = -30 -- place cave stuff this far beneath the surface local deco_depth = -30 -- place cave stuff this far beneath the surface
local light_depth = -13 -- depth above which to place corals/sea plants local light_depth = -13 -- depth above which to place corals/sea plants
local water_level = 1 local water_level = 1
@ -55,6 +57,13 @@ fun_caves.decogen = function(minp, maxp, data, p2data, area, node, heightmap, bi
end end
end end
if false and underzone and underzone.name == 'Caina' and math.abs(minp.y - underzone.floor) < math.abs(minp.y - underzone.ceiling) then
local write, writep2 = fun_caves.ice_castle(minp, maxp, data, p2data, area, node, heightmap, biomemap, biome_ids, underzone)
if write then
return write, writep2
end
end
local undersea = fun_caves.underzones['Styx'].sealevel local undersea = fun_caves.underzones['Styx'].sealevel
local write = false local write = false

View file

@ -322,7 +322,7 @@ if fun_caves.register_status and fun_caves.set_status then
end end
local armor = player:get_armor_groups() local armor = player:get_armor_groups()
if not (armor and armor.fleshy and armor.fleshy ~= value) then if not (armor and armor.fleshy and armor.fleshy >= value) then
return return
end end

View file

@ -456,3 +456,21 @@ minetest.register_craft({
{'', 'group:wood', ''}, {'', 'group:wood', ''},
}, },
}) })
minetest.register_craft({
output = 'default:diamondblock',
recipe = {
{'default:coalblock', 'default:coalblock', 'default:coalblock'},
{'default:coalblock', 'default:mese_crystal_fragment', 'default:coalblock'},
{'default:coalblock', 'default:coalblock', 'default:coalblock'},
}
})
minetest.register_craft({
output = 'default:mese_crystal 2',
recipe = {
{'default:diamond', 'default:diamond', 'default:diamond'},
{'default:diamond', 'default:mese_crystal', 'default:diamond'},
{'default:diamond', 'default:diamond', 'default:diamond'},
}
})

View file

@ -102,7 +102,7 @@ minetest.register_craftitem("fun_caves:bucket_wood_empty", {
end end
local liquiddef = bucket.liquids[node.name] local liquiddef = bucket.liquids[node.name]
if node.name ~= liquiddef.source then if not liquiddef or node.name ~= liquiddef.source then
return return
end end