Optimize quarry_run

Don't load the whole digging area when only a small piece is relevant.
Also, move the (time expensive) check whether the air above a block is free to the last position, which spares unneccessary checks when multiple quarries are placed together, or a quarry has to loop over air for another reason.
This commit is contained in:
est31
2015-01-24 04:30:48 +01:00
parent ec73a8508f
commit c38da0945c
3 changed files with 22 additions and 15 deletions

View File

@ -108,23 +108,28 @@ local function quarry_run(pos, node)
vector.multiply(pdir, rp)),
vector.multiply(qdir, rq))
local can_dig = true
for ay = startpos.y, digpos.y+1, -1 do
if data[area:index(digpos.x, ay, digpos.z)] ~= c_air then
can_dig = false
break
end
end
if can_dig and minetest.is_protected and minetest.is_protected(digpos, owner) then
can_dig = false
end
local dignode
if can_dig then
dignode = minetest.get_node(digpos)
dignode = technic.get_or_load_node(digpos) or minetest.get_node(digpos)
local dignodedef = minetest.registered_nodes[dignode.name] or {diggable=false}
if not dignodedef.diggable or (dignodedef.can_dig and not dignodedef.can_dig(digpos, nil)) then
can_dig = false
end
end
if can_dig then
for ay = startpos.y, digpos.y+1, -1 do
local checkpos = {x=digpos.x, y=ay, z=digpos.z}
local checknode = technic.get_or_load_node(checkpos) or minetest.get_node(checkpos)
if checknode.name ~= "air" then
can_dig = false
break
end
end
end
nd = nd + 1
if can_dig then
minetest.remove_node(digpos)