Commit 21873881 authored by Craig Robbins's avatar Craig Robbins
Browse files

Bug fix (falling nodes)

Without this fix falling nodes (e.g. sand) do not work correctly. For example, placing sand on top of water the sand will drop and disappear.
parent 5fa14b48
......@@ -63,7 +63,7 @@ minetest.register_entity("caverealms:falling_ice", {
if obj:is_player() then
obj:set_hp(obj:get_hp() - 8)
end
end
end
-- Note: walkable is in the node definition, not in item groups
if not bcd or
(bcd.walkable or
......@@ -103,19 +103,19 @@ minetest.register_entity("caverealms:falling_ice", {
-- remove entity
--minetest.add_node(np, self.node)
self.object:remove()
nodeupdate(np)
caverealms:nodeupdate(np)
else
-- Do nothing
end
end
})
function spawn_falling_node(p, node)
function caverealms:spawn_falling_node(p, node)
obj = minetest.add_entity(p, "caverealms:falling_ice")
obj:get_luaentity():set_node(node)
end
function drop_attached_node(p)
function caverealms:drop_attached_node(p)
local nn = minetest.get_node(p).name
minetest.remove_node(p)
for _,item in ipairs(minetest.get_node_drops(nn, "")) do
......@@ -128,7 +128,7 @@ function drop_attached_node(p)
end
end
function check_attached_node(p, n)
function caverealms:check_attached_node(p, n)
local def = minetest.registered_nodes[n.name]
local d = {x=0, y=0, z=0}
if def.paramtype2 == "wallmounted" then
......@@ -161,7 +161,7 @@ end
-- Some common functions
--
function nodeupdate_single(p, delay)
function caverealms:nodeupdate_single(p, delay)
n = minetest.get_node(p)
if minetest.get_item_group(n.name, "falling_node") ~= 0 then
p_bottom = {x=p.x, y=p.y-1, z=p.z}
......@@ -175,25 +175,25 @@ function nodeupdate_single(p, delay)
(not minetest.registered_nodes[n_bottom.name].walkable or
minetest.registered_nodes[n_bottom.name].buildable_to) then
if delay then
minetest.after(0.1, nodeupdate_single, {x=p.x, y=p.y, z=p.z}, false)
minetest.after(0.1, caverealms.nodeupdate_single, {x=p.x, y=p.y, z=p.z}, false)
else
n.level = minetest.env:get_node_level(p)
minetest.remove_node(p)
spawn_falling_node(p, n)
nodeupdate(p)
caverealms:spawn_falling_node(p, n)
caverealms:nodeupdate(p)
end
end
end
if minetest.get_item_group(n.name, "attached_node") ~= 0 then
if not check_attached_node(p, n) then
drop_attached_node(p)
nodeupdate(p)
caverealms:drop_attached_node(p)
caverealms:nodeupdate(p)
end
end
end
function nodeupdate(p, delay)
function caverealms:nodeupdate(p, delay)
-- Round p to prevent falling entities to get stuck
p.x = math.floor(p.x+0.5)
p.y = math.floor(p.y+0.5)
......@@ -202,7 +202,7 @@ function nodeupdate(p, delay)
for x = -1,1 do
for y = -1,1 do
for z = -1,1 do
nodeupdate_single({x=p.x+x, y=p.y+y, z=p.z+z}, delay or not (x==0 and y==0 and z==0))
caverealms:nodeupdate_single({x=p.x+x, y=p.y+y, z=p.z+z}, delay or not (x==0 and y==0 and z==0))
end
end
end
......
......@@ -90,13 +90,13 @@ minetest.register_on_generated(function(minp, maxp, seed)
local x0 = minp.x
local y0 = minp.y
local z0 = minp.z
print ("[caverealms] chunk minp ("..x0.." "..y0.." "..z0..")") --tell people you are generating a chunk
local vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
local area = VoxelArea:new{MinEdge=emin, MaxEdge=emax}
local data = vm:get_data()
--grab content IDs
local c_air = minetest.get_content_id("air")
local c_stone = minetest.get_content_id("default:stone")
......@@ -118,21 +118,21 @@ minetest.register_on_generated(function(minp, maxp, seed)
local c_worm = minetest.get_content_id("caverealms:glow_worm")
local c_iciu = minetest.get_content_id("caverealms:icicle_up")
local c_icid = minetest.get_content_id("caverealms:icicle_down")
--mandatory values
local sidelen = x1 - x0 + 1 --length of a mapblock
local chulens = {x=sidelen, y=sidelen, z=sidelen} --table of chunk edges
local minposxyz = {x=x0, y=y0, z=z0} --bottom corner
local minposxz = {x=x0, y=z0} --2D bottom corner
local nvals_cave = minetest.get_perlin_map(np_cave, chulens):get3dMap_flat(minposxyz) --cave noise for structure
local nvals_wave = minetest.get_perlin_map(np_wave, chulens):get3dMap_flat(minposxyz) --wavy structure of cavern ceilings and floors
local nvals_biome = minetest.get_perlin_map(np_biome, chulens):get2dMap_flat({x=x0+150, y=z0+50}) --2D noise for biomes (will be 3D humidity/temp later)
local nixyz = 1 --3D node index
local nixz = 1 --2D node index
local nixyz2 = 1 --second 3D index for second loop
for z = z0, z1 do -- for each xy plane progressing northwards
--structure loop
for y = y0, y1 do -- for each x row progressing upwards
......@@ -155,7 +155,7 @@ minetest.register_on_generated(function(minp, maxp, seed)
vi = vi + 1
end
end
--decoration loop
for y = y0, y1 do -- for each x row progressing upwards
local tcave --same as above
......@@ -168,7 +168,7 @@ minetest.register_on_generated(function(minp, maxp, seed)
end
local vi = area:index(x0, y, z)
for x = x0, x1 do -- for each node do
--determine biome
local biome = false --preliminary declaration
n_biome = nvals_biome[nixz] --make an easier reference to the noise
......@@ -186,7 +186,7 @@ minetest.register_on_generated(function(minp, maxp, seed)
else
biome = 3 --algae
end
if math.floor(((nvals_cave[nixyz2] + nvals_wave[nixyz2])/2)*100) == math.floor(tcave*100) then
--ceiling
local ai = area:index(x,y+1,z) --above index
......@@ -259,7 +259,7 @@ minetest.register_on_generated(function(minp, maxp, seed)
data[ai] = c_iciu
end
end
if math.random() < STAGCHA then
caverealms:stalagmite(x,y,z, area, data)
end
......@@ -267,7 +267,7 @@ minetest.register_on_generated(function(minp, maxp, seed)
caverealms:crystal_stalagmite(x,y,z, area, data, biome)
end
end
end
nixyz2 = nixyz2 + 1
nixz = nixz + 1
......@@ -277,7 +277,7 @@ minetest.register_on_generated(function(minp, maxp, seed)
end
nixz = nixz + sidelen --shift the 2D index up a layer
end
--send data back to voxelmanip
vm:set_data(data)
--calc lighting
......@@ -289,3 +289,6 @@ minetest.register_on_generated(function(minp, maxp, seed)
local chugent = math.ceil((os.clock() - t1) * 1000) --grab how long it took
print ("[caverealms] "..chugent.." ms") --tell people how long
end)
print("[caverealms] loaded!")
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment