From 854834f04ebe64a8c128d454d3e7c35caf3ef8d6 Mon Sep 17 00:00:00 2001 From: tenplus1 Date: Fri, 4 Apr 2025 10:12:46 +0100 Subject: [PATCH] deprecate self.jump and add mobs.compatibility_check function. --- api.lua | 17 +++++++++++------ api.txt | 2 +- compatibility.lua | 8 ++++++++ 3 files changed, 20 insertions(+), 7 deletions(-) create mode 100644 compatibility.lua diff --git a/api.lua b/api.lua index 0f83fc1..0c7e5f0 100644 --- a/api.lua +++ b/api.lua @@ -18,7 +18,7 @@ end -- Global table mobs = { - mod = "redo", version = "20250320", + mod = "redo", version = "20250404", spawning_mobs = {}, translate = S, node_snow = has(minetest.registered_aliases["mapgen_snow"]) or has("mcl_core:snow") or has("default:snow") or "air", @@ -27,6 +27,10 @@ mobs = { } mobs.fallback_node = mobs.node_dirt +-- load compatibility check function + +dofile(minetest.get_modpath("mobs") .. "/compatibility.lua") + -- localize common functions local pi, abs, min, max = math.pi, math.abs, math.min, math.max @@ -1078,7 +1082,7 @@ function mob_class:do_jump() ndef = minetest.registered_nodes[self.looking_at] -- jump if possible - if self.jump and self.jump_height > 0 + if self.jump_height > 0 and (self.walk_chance == 0 or (ndef.walkable and ndef.drawtype == "normal")) and not blocked and not self.facing_fence then @@ -1561,7 +1565,7 @@ function mob_class:smart_mobs(s, p, dist, dtime) local jumpheight = 0 - if self.jump and self.jump_height >= pathfinding_max_jump then + if self.jump_height >= pathfinding_max_jump then jumpheight = min(ceil( self.jump_height / pathfinding_max_jump), pathfinding_max_jump) @@ -2879,9 +2883,6 @@ function mob_class:mob_staticdata() self.following = nil self.state = "stand" - -- used to rotate older mobs - if self.drawtype and self.drawtype == "side" then self.rotate = rad(90) end - if use_cmi then self.serialized_cmi_components = cmi.serialize_components(self._cmi_components) end @@ -3426,6 +3427,10 @@ function mobs:register_mob(name, def) end }, mob_class_meta)) + + -- look for any older settings for compatibility + local self = minetest.registered_entities[name] + mobs.compatibility_check(self) end -- count how many mobs of one type are inside an area diff --git a/api.txt b/api.txt index 24264f8..b700d2e 100644 --- a/api.txt +++ b/api.txt @@ -50,7 +50,7 @@ functions needed for the mob to work properly which contains the following: set to 0 for jumping mobs only. 'randomly_turn' if set to false then mob will not turn to face player or randomly turn while walking or standing. - 'jump' when true allows your mob to jump updwards. + 'jump' when true allows your mob to jump updwards[DEPRECATED]. 'jump_height' holds the height your mob can jump, 0 to disable jumping. 'can_leap' when true obstacles like fences or pits wont stop a mob from trying to jump out. diff --git a/compatibility.lua b/compatibility.lua new file mode 100644 index 0000000..9054b4f --- /dev/null +++ b/compatibility.lua @@ -0,0 +1,8 @@ + +-- called after mob registration to check for older settings + +function mobs.compatibility_check(self) + + -- simple mobs rotation setting + if self.drawtype == "side" then self.rotate = math.rad(90) end +end