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

@ -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

@ -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!")