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.
master
Craig Robbins 2014-07-04 15:09:51 +10:00
parent 5fa14b481a
commit 218738812e
2 changed files with 29 additions and 26 deletions

View File

@ -63,7 +63,7 @@ minetest.register_entity("caverealms:falling_ice", {
if obj:is_player() then if obj:is_player() then
obj:set_hp(obj:get_hp() - 8) obj:set_hp(obj:get_hp() - 8)
end end
end end
-- Note: walkable is in the node definition, not in item groups -- Note: walkable is in the node definition, not in item groups
if not bcd or if not bcd or
(bcd.walkable or (bcd.walkable or
@ -103,19 +103,19 @@ minetest.register_entity("caverealms:falling_ice", {
-- remove entity -- remove entity
--minetest.add_node(np, self.node) --minetest.add_node(np, self.node)
self.object:remove() self.object:remove()
nodeupdate(np) caverealms:nodeupdate(np)
else else
-- Do nothing -- Do nothing
end end
end end
}) })
function spawn_falling_node(p, node) function caverealms:spawn_falling_node(p, node)
obj = minetest.add_entity(p, "caverealms:falling_ice") obj = minetest.add_entity(p, "caverealms:falling_ice")
obj:get_luaentity():set_node(node) obj:get_luaentity():set_node(node)
end end
function drop_attached_node(p) function caverealms:drop_attached_node(p)
local nn = minetest.get_node(p).name local nn = minetest.get_node(p).name
minetest.remove_node(p) minetest.remove_node(p)
for _,item in ipairs(minetest.get_node_drops(nn, "")) do for _,item in ipairs(minetest.get_node_drops(nn, "")) do
@ -128,7 +128,7 @@ function drop_attached_node(p)
end end
end end
function check_attached_node(p, n) function caverealms:check_attached_node(p, n)
local def = minetest.registered_nodes[n.name] local def = minetest.registered_nodes[n.name]
local d = {x=0, y=0, z=0} local d = {x=0, y=0, z=0}
if def.paramtype2 == "wallmounted" then if def.paramtype2 == "wallmounted" then
@ -161,7 +161,7 @@ end
-- Some common functions -- Some common functions
-- --
function nodeupdate_single(p, delay) function caverealms:nodeupdate_single(p, delay)
n = minetest.get_node(p) n = minetest.get_node(p)
if minetest.get_item_group(n.name, "falling_node") ~= 0 then if minetest.get_item_group(n.name, "falling_node") ~= 0 then
p_bottom = {x=p.x, y=p.y-1, z=p.z} 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 (not minetest.registered_nodes[n_bottom.name].walkable or
minetest.registered_nodes[n_bottom.name].buildable_to) then minetest.registered_nodes[n_bottom.name].buildable_to) then
if delay 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 else
n.level = minetest.env:get_node_level(p) n.level = minetest.env:get_node_level(p)
minetest.remove_node(p) minetest.remove_node(p)
spawn_falling_node(p, n) caverealms:spawn_falling_node(p, n)
nodeupdate(p) caverealms:nodeupdate(p)
end end
end end
end end
if minetest.get_item_group(n.name, "attached_node") ~= 0 then if minetest.get_item_group(n.name, "attached_node") ~= 0 then
if not check_attached_node(p, n) then if not check_attached_node(p, n) then
drop_attached_node(p) caverealms:drop_attached_node(p)
nodeupdate(p) caverealms:nodeupdate(p)
end end
end end
end end
function nodeupdate(p, delay) function caverealms:nodeupdate(p, delay)
-- Round p to prevent falling entities to get stuck -- Round p to prevent falling entities to get stuck
p.x = math.floor(p.x+0.5) p.x = math.floor(p.x+0.5)
p.y = math.floor(p.y+0.5) p.y = math.floor(p.y+0.5)
@ -202,7 +202,7 @@ function nodeupdate(p, delay)
for x = -1,1 do for x = -1,1 do
for y = -1,1 do for y = -1,1 do
for z = -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 end
end end

View File

@ -90,13 +90,13 @@ minetest.register_on_generated(function(minp, maxp, seed)
local x0 = minp.x local x0 = minp.x
local y0 = minp.y local y0 = minp.y
local z0 = minp.z local z0 = minp.z
print ("[caverealms] chunk minp ("..x0.." "..y0.." "..z0..")") --tell people you are generating a chunk print ("[caverealms] chunk minp ("..x0.." "..y0.." "..z0..")") --tell people you are generating a chunk
local vm, emin, emax = minetest.get_mapgen_object("voxelmanip") local vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
local area = VoxelArea:new{MinEdge=emin, MaxEdge=emax} local area = VoxelArea:new{MinEdge=emin, MaxEdge=emax}
local data = vm:get_data() local data = vm:get_data()
--grab content IDs --grab content IDs
local c_air = minetest.get_content_id("air") local c_air = minetest.get_content_id("air")
local c_stone = minetest.get_content_id("default:stone") 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_worm = minetest.get_content_id("caverealms:glow_worm")
local c_iciu = minetest.get_content_id("caverealms:icicle_up") local c_iciu = minetest.get_content_id("caverealms:icicle_up")
local c_icid = minetest.get_content_id("caverealms:icicle_down") local c_icid = minetest.get_content_id("caverealms:icicle_down")
--mandatory values --mandatory values
local sidelen = x1 - x0 + 1 --length of a mapblock local sidelen = x1 - x0 + 1 --length of a mapblock
local chulens = {x=sidelen, y=sidelen, z=sidelen} --table of chunk edges local chulens = {x=sidelen, y=sidelen, z=sidelen} --table of chunk edges
local minposxyz = {x=x0, y=y0, z=z0} --bottom corner local minposxyz = {x=x0, y=y0, z=z0} --bottom corner
local minposxz = {x=x0, y=z0} --2D 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_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_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 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 nixyz = 1 --3D node index
local nixz = 1 --2D node index local nixz = 1 --2D node index
local nixyz2 = 1 --second 3D index for second loop local nixyz2 = 1 --second 3D index for second loop
for z = z0, z1 do -- for each xy plane progressing northwards for z = z0, z1 do -- for each xy plane progressing northwards
--structure loop --structure loop
for y = y0, y1 do -- for each x row progressing upwards 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 vi = vi + 1
end end
end end
--decoration loop --decoration loop
for y = y0, y1 do -- for each x row progressing upwards for y = y0, y1 do -- for each x row progressing upwards
local tcave --same as above local tcave --same as above
@ -168,7 +168,7 @@ minetest.register_on_generated(function(minp, maxp, seed)
end end
local vi = area:index(x0, y, z) local vi = area:index(x0, y, z)
for x = x0, x1 do -- for each node do for x = x0, x1 do -- for each node do
--determine biome --determine biome
local biome = false --preliminary declaration local biome = false --preliminary declaration
n_biome = nvals_biome[nixz] --make an easier reference to the noise 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 else
biome = 3 --algae biome = 3 --algae
end end
if math.floor(((nvals_cave[nixyz2] + nvals_wave[nixyz2])/2)*100) == math.floor(tcave*100) then if math.floor(((nvals_cave[nixyz2] + nvals_wave[nixyz2])/2)*100) == math.floor(tcave*100) then
--ceiling --ceiling
local ai = area:index(x,y+1,z) --above index 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 data[ai] = c_iciu
end end
end end
if math.random() < STAGCHA then if math.random() < STAGCHA then
caverealms:stalagmite(x,y,z, area, data) caverealms:stalagmite(x,y,z, area, data)
end end
@ -267,7 +267,7 @@ minetest.register_on_generated(function(minp, maxp, seed)
caverealms:crystal_stalagmite(x,y,z, area, data, biome) caverealms:crystal_stalagmite(x,y,z, area, data, biome)
end end
end end
end end
nixyz2 = nixyz2 + 1 nixyz2 = nixyz2 + 1
nixz = nixz + 1 nixz = nixz + 1
@ -277,7 +277,7 @@ minetest.register_on_generated(function(minp, maxp, seed)
end end
nixz = nixz + sidelen --shift the 2D index up a layer nixz = nixz + sidelen --shift the 2D index up a layer
end end
--send data back to voxelmanip --send data back to voxelmanip
vm:set_data(data) vm:set_data(data)
--calc lighting --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 local chugent = math.ceil((os.clock() - t1) * 1000) --grab how long it took
print ("[caverealms] "..chugent.." ms") --tell people how long print ("[caverealms] "..chugent.." ms") --tell people how long
end) end)
print("[caverealms] loaded!")