diff --git a/api.lua b/api.lua index 3f8f8a1..75bd17c 100644 --- a/api.lua +++ b/api.lua @@ -18,7 +18,7 @@ end mobs = { mod = "redo", - version = "20241110", + version = "20241113", spawning_mobs = {}, translate = S, invis = minetest.global_exists("invisibility") and invisibility or {}, @@ -1402,7 +1402,7 @@ function mob_class:replace(pos) return end - local what, with, y_offset + local what, with, y_offset, reach if type(self.replace_what[1]) == "table" then @@ -1411,15 +1411,23 @@ function mob_class:replace(pos) what = self.replace_what[num][1] or "" with = self.replace_what[num][2] or "" y_offset = self.replace_what[num][3] or 0 + reach = self.replace_what[num][4] or 0 else what = self.replace_what with = self.replace_with or "" y_offset = self.replace_offset or 0 + reach = 0 end pos.y = pos.y + y_offset - if #minetest.find_nodes_in_area(pos, pos, what) > 0 then + local found = minetest.find_nodes_in_area( + {x = pos.x - reach, y = pos.y, z = pos.z - reach}, + {x = pos.x + reach, y = pos.y, z = pos.z + reach}, what) + + if #found > 0 then + + pos = found[random(#found)] -- print("replace node = ".. minetest.get_node(pos).name, pos.y) diff --git a/api.txt b/api.txt index 456b60d..9a50e83 100644 --- a/api.txt +++ b/api.txt @@ -289,11 +289,12 @@ eating. y offset by using this instead: { {"group:grass", "air", 0}, - {"default:dirt_with_grass", "default:dirt", -1} + {"default:dirt_with_grass", "default:dirt", -1, 0} } 'replace_with' replace with what e.g. "air" or in chickens case "mobs:egg" 'replace_rate' how random should the replace rate be (typically 10) - 'replace_offset' +/- value to check specific node to replace + 'replace_offset' +/- y offset value to check specific node to replace + 'reach' horizontal reach around mob for replace, default is 0 'on_replace(self, pos, oldnode, newnode)' is called when mob is about to replace a node.