Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get rid of recursive call in default.dig_up #3133

Merged
Merged
2 changes: 1 addition & 1 deletion game.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
title = Minetest Game
author = Minetest
description = A basic exploration, mining, crafting, and building, sandbox game with no NPCs, monsters, or animals. Minetest Game is usually used with mods added, and many mods are available for this game. Reliably maintained by Minetest Engine core developers.
min_minetest_version = 5.8
min_minetest_version = 5.9
41 changes: 36 additions & 5 deletions mods/default/functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -293,15 +293,46 @@ minetest.register_abm({
-- Dig upwards
--

function default.dig_up(pos, node, digger)
local in_dig_up = false

---Find all nodes above this one that is the same, then dig them all
---@param pos vector The position of the base node
Emojigit marked this conversation as resolved.
Show resolved Hide resolved
---@param node { name: string, param1: integer, param2: integer } Node table of the base node
---@param digger ObjectRef The object (e.g. player) digging the node
---@param max_height The maximum height to search for, excluding the base node
function default.dig_up(pos, node, digger, max_height)
Emojigit marked this conversation as resolved.
Show resolved Hide resolved
if in_dig_up then return end -- Do not recurse
if digger == nil then return end
local np = {x = pos.x, y = pos.y + 1, z = pos.z}
local nn = minetest.get_node(np)
if nn.name == node.name then
minetest.node_dig(np, nn, digger)
max_height = max_height or 100

in_dig_up = true
for y = pos.y + 1, pos.y + max_height do
local up_pos = vector.new(pos.x, y, pos.z)
Emojigit marked this conversation as resolved.
Show resolved Hide resolved
local up_node = minetest.get_node(up_pos)
if up_node.name ~= node.name then
break
end
local noerr, success = xpcall(function()
Emojigit marked this conversation as resolved.
Show resolved Hide resolved
Emojigit marked this conversation as resolved.
Show resolved Hide resolved
return minetest.dig_node(up_pos, digger)
end, function(...)
in_dig_up = false
local errmsg = "Error raised during `default.dig_up` call: " .. minetest.error_handler(...)
for line in errmsg:gmatch("([^\n]*)\n?") do
minetest.log("error", line)
end
end)
sfan5 marked this conversation as resolved.
Show resolved Hide resolved
if not noerr then
error("Error raised during `default.dig_up` call")
elseif not success then
break
end
end
in_dig_up = false
end

minetest.register_globalstep(function()
Emojigit marked this conversation as resolved.
Show resolved Hide resolved
in_dig_up = false
end)

--
-- Fence registration helper
Expand Down
2 changes: 1 addition & 1 deletion mods/default/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ default.get_translator = S
-- and avoids obscure, hard to debug runtime errors.
-- This section should be updated before release and older checks can be dropped
-- when newer ones are introduced.
if ItemStack("").add_wear_by_uses == nil then
if not minetest.features.node_interaction_actor then
sfan5 marked this conversation as resolved.
Show resolved Hide resolved
error("\nThis version of Minetest Game is incompatible with your engine version "..
Emojigit marked this conversation as resolved.
Show resolved Hide resolved
"(which is too old). You should download a version of Minetest Game that "..
"matches the installed engine version.\n")
Expand Down