Skip to content

Commit

Permalink
Merge branch 'fork-20240617-dig_up-no-recursive' into fork-master
Browse files Browse the repository at this point in the history
  • Loading branch information
Emojigit committed Aug 31, 2024
2 parents 55a9e5f + 45ef266 commit afcf2c2
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 21 deletions.
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.9
min_minetest_version = 5.8
8 changes: 8 additions & 0 deletions game_api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1217,3 +1217,11 @@ These can be influenced using this API.
* `player`: ObjectRef of the relevant player
* You can override this function to change the weather effects by simply returning different values.
Setting `clouds` or `lighting` in the result table to `nil` will *prevent* those from changing.

Utilities
---------

`default.dig_up(pos, node, digger, max_height)`

* Find all nodes above `pos` that is the same, then dig them all
* `max_height` Maximum number of nodes to iterate. Default: 100
23 changes: 4 additions & 19 deletions mods/default/functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -295,35 +295,19 @@ minetest.register_abm({

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
---@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)
if in_dig_up then return end -- Do not recurse
if digger == nil then return end
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)
for y = 1, max_height do
local up_pos = vector.offset(pos, 0, y, 0)
local up_node = minetest.get_node(up_pos)
if up_node.name ~= node.name then
break
end
local noerr, success = xpcall(function()
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)
if not noerr then
error("Error raised during `default.dig_up` call")
elseif not success then
if not minetest.node_dig(up_pos, up_node, digger) then
break
end
end
Expand All @@ -334,6 +318,7 @@ minetest.register_globalstep(function()
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 not minetest.features.node_interaction_actor then
if ItemStack("").add_wear_by_uses == nil then
error("\nThis version of Minetest Game is incompatible with your engine version "..
"(which is too old). You should download a version of Minetest Game that "..
"matches the installed engine version.\n")
Expand Down

0 comments on commit afcf2c2

Please sign in to comment.