From bbba7cee41e627cefb6606c786dbb33bbea5f6d7 Mon Sep 17 00:00:00 2001 From: cora Date: Wed, 9 Nov 2022 06:06:59 +0100 Subject: [PATCH] Add compat for old "wrong" : notation --- mods/ENTITIES/mcl_mobs/api.lua | 4 +--- mods/ENTITIES/mcl_mobs/compat.lua | 32 ++++++++++++++++++++++++++++++ mods/ENTITIES/mcl_mobs/effects.lua | 6 +++++- mods/ENTITIES/mcl_mobs/init.lua | 2 ++ mods/ENTITIES/mobs_mc/enderman.lua | 4 ++-- mods/ENTITIES/mobs_mc/parrot.lua | 2 +- mods/ENTITIES/mobs_mc/pillager.lua | 12 +++++------ mods/ENTITIES/mobs_mc/shulker.lua | 6 +++--- mods/ENTITIES/mobs_mc/wolf.lua | 6 +++--- 9 files changed, 55 insertions(+), 19 deletions(-) create mode 100644 mods/ENTITIES/mcl_mobs/compat.lua diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index e0206b722..be0b9351c 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -46,8 +46,6 @@ local disable_blood = minetest.settings:get_bool("mobs_disable_blood") local mobs_drop_items = minetest.settings:get_bool("mobs_drop_items") ~= false local mobs_griefing = minetest.settings:get_bool("mobs_griefing") ~= false local spawn_protected = minetest.settings:get_bool("mobs_spawn_protected") ~= false -local player_transfer_distance = tonumber(minetest.settings:get("player_transfer_distance")) or 128 -if player_transfer_distance == 0 then player_transfer_distance = math.huge end local remove_far = true local difficulty = tonumber(minetest.settings:get("mob_difficulty")) or 1.0 local show_health = false @@ -659,7 +657,7 @@ local breed = function(self) self.animation = nil local anim = self._current_animation self._current_animation = nil -- Mobs Redo does nothing otherwise - mcl_mobs.self:set_animation( anim) + self:set_animation(anim) end return diff --git a/mods/ENTITIES/mcl_mobs/compat.lua b/mods/ENTITIES/mcl_mobs/compat.lua new file mode 100644 index 000000000..020a089b2 --- /dev/null +++ b/mods/ENTITIES/mcl_mobs/compat.lua @@ -0,0 +1,32 @@ + +-- this is to make the register_mob and register egg functions commonly used by mods not break +-- when they use the weird old : notation AND self as first argument +local oldregmob = mcl_mobs.register_mob +function mcl_mobs.register_mob(self,name,def) + if type(self) == "string" then + def = name + name = self + end + return oldregmob(name,def) +end +local oldregegg = mcl_mobs.register_egg +function mcl_mobs.register_egg(self, mob, desc, background_color, overlay_color, addegg, no_creative) + if type(self) == "string" then + no_creative = addegg + addegg = overlay_color + overlay_color = background_color + background_color = desc + desc = mob + mob = self + end + return oldregegg(mob, desc, background_color, overlay_color, addegg, no_creative) +end + +local oldregarrow = mcl_mobs.register_mob +function mcl_mobs.register_mob(self,name,def) + if type(self) == "string" then + def = name + name = self + end + return oldregarrow(name,def) +end diff --git a/mods/ENTITIES/mcl_mobs/effects.lua b/mods/ENTITIES/mcl_mobs/effects.lua index 45199852a..3e62f2539 100644 --- a/mods/ENTITIES/mcl_mobs/effects.lua +++ b/mods/ENTITIES/mcl_mobs/effects.lua @@ -2,6 +2,10 @@ local math, vector, minetest, mcl_mobs = math, vector, minetest, mcl_mobs local mob_class = mcl_mobs.mob_class local active_particlespawners = {} local DEFAULT_FALL_SPEED = -9.81*1.5 + +local player_transfer_distance = tonumber(minetest.settings:get("player_transfer_distance")) or 128 +if player_transfer_distance == 0 then player_transfer_distance = math.huge end + -- play sound function mob_class:mob_sound(soundname, is_opinion, fixed_pitch) @@ -264,5 +268,5 @@ end -- above function exported for mount.lua function mcl_mobs:set_animation(self, anim) - set_animation(self, anim) + self:set_animation(anim) end diff --git a/mods/ENTITIES/mcl_mobs/init.lua b/mods/ENTITIES/mcl_mobs/init.lua index 16961d66b..b98dd07ee 100644 --- a/mods/ENTITIES/mcl_mobs/init.lua +++ b/mods/ENTITIES/mcl_mobs/init.lua @@ -19,3 +19,5 @@ dofile(path .. "/mount.lua") -- Mob Items dofile(path .. "/crafts.lua") + +dofile(path .. "/compat.lua") diff --git a/mods/ENTITIES/mobs_mc/enderman.lua b/mods/ENTITIES/mobs_mc/enderman.lua index 2c777fc34..2688977fe 100644 --- a/mods/ENTITIES/mobs_mc/enderman.lua +++ b/mods/ENTITIES/mobs_mc/enderman.lua @@ -497,7 +497,7 @@ mcl_mobs.register_mob("mobs_mc:enderman", { self.base_texture = create_enderman_textures(block_type, self._taken_node) self.object:set_properties({ textures = self.base_texture }) self.animation = select_enderman_animation("block") - mcl_mobs:set_animation(self, self.animation.current) + self:set_animation(self.animation.current) if def.sounds and def.sounds.dug then minetest.sound_play(def.sounds.dug, {pos = take_pos, max_hear_distance = 16}, true) end @@ -520,7 +520,7 @@ mcl_mobs.register_mob("mobs_mc:enderman", { local def = minetest.registered_nodes[self._taken_node] -- Update animation accordingly (removes visible block) self.animation = select_enderman_animation("normal") - mcl_mobs:set_animation(self, self.animation.current) + self:set_animation(self.animation.current) if def.sounds and def.sounds.place then minetest.sound_play(def.sounds.place, {pos = place_pos, max_hear_distance = 16}, true) end diff --git a/mods/ENTITIES/mobs_mc/parrot.lua b/mods/ENTITIES/mobs_mc/parrot.lua index 0aeebde8d..ed2892aca 100644 --- a/mods/ENTITIES/mobs_mc/parrot.lua +++ b/mods/ENTITIES/mobs_mc/parrot.lua @@ -87,7 +87,7 @@ local function perch(self,player) local shoulder = get_shoulder(player) if not shoulder then return true end self.object:set_attach(player,"",shoulder,vector.new(0,0,0),true) - mcl_mobs:set_animation(self, "stand") + self:set_animation("stand") end end diff --git a/mods/ENTITIES/mobs_mc/pillager.lua b/mods/ENTITIES/mobs_mc/pillager.lua index 84a975592..0b6b036f7 100644 --- a/mods/ENTITIES/mobs_mc/pillager.lua +++ b/mods/ENTITIES/mobs_mc/pillager.lua @@ -12,7 +12,7 @@ end local function reset_animation(self, animation) if not self.object:get_pos() or self._current_animation ~= animation then return end self._current_animation = "stand_reload" -- Mobs Redo won't set the animation unless we do this - mcl_mobs:set_animation(self, animation) + self:set_animation(animation) end pillager = { @@ -96,25 +96,25 @@ pillager = { self.object:set_properties(props) local old_anim = self._current_animation if old_anim == "run" or old_anim == "walk" then - mcl_mobs:set_animation(self, "reload_run") + self:set_animation("reload_run") end if old_anim == "stand" then - mcl_mobs:set_animation(self, "reload_stand") + self:set_animation("reload_stand") end self._current_animation = old_anim -- Mobs Redo will imediately reset the animation otherwise minetest.after(1, reload, self) minetest.after(2, reset_animation, self, old_anim) - + -- 2-4 damage per arrow local dmg = math.max(4, math.random(2, 8)) mcl_bows_s.shoot_arrow_crossbow("mcl_bows:arrow", pos, dir, self.object:get_yaw(), self.object, nil, dmg) - + -- While we are at it, change the sounds since there is no way to do this in Mobs Redo if self.sounds and self.sounds.random then self.sounds = table.copy(self.sounds) self.sounds.random = "mobs_mc_pillager_grunt" .. math.random(2) end - + -- Randomize reload time self.shoot_interval = math.random(3, 4) end, diff --git a/mods/ENTITIES/mobs_mc/shulker.lua b/mods/ENTITIES/mobs_mc/shulker.lua index e0f7b3c5a..46737e90f 100644 --- a/mods/ENTITIES/mobs_mc/shulker.lua +++ b/mods/ENTITIES/mobs_mc/shulker.lua @@ -83,10 +83,10 @@ mcl_mobs.register_mob("mobs_mc:shulker", { end if self.state == "walk" or self.state == "stand" then self.state = "stand" - mcl_mobs:set_animation(self, "stand") + self:set_animation("stand") end if self.state == "attack" then - mcl_mobs:set_animation(self, "punch") + self:set_animation("punch") end self.path.way = false self.look_at_players = false @@ -134,7 +134,7 @@ mcl_mobs.register_mob("mobs_mc:shulker", { for n=1, math.min(8, #nodes) do local r = pr:next(1, #nodes) local nodepos = nodes[r] - local tg = vector.offset(nodepos,0,1,0) + local tg = vector.offset(nodepos,0,0.5,0) if check_spot(tg) then self.object:set_pos(tg) node_ok = true diff --git a/mods/ENTITIES/mobs_mc/wolf.lua b/mods/ENTITIES/mobs_mc/wolf.lua index 09377cc26..bc8f126dd 100644 --- a/mods/ENTITIES/mobs_mc/wolf.lua +++ b/mods/ENTITIES/mobs_mc/wolf.lua @@ -71,7 +71,7 @@ local wolf = { ent = dog:get_luaentity() ent.owner = clicker:get_player_name() ent.tamed = true - mcl_mobs:set_animation(ent, "sit") + ent:set_animation("sit") ent.walk_chance = 0 ent.jump = false ent.health = self.health @@ -209,7 +209,7 @@ dog.on_rightclick = function(self, clicker) self.state = "stand" self.walk_chance = default_walk_chance self.jump = true - mcl_mobs:set_animation(self, "stand") + self:set_animation("stand") -- TODO: Add sitting model else particle = "mobs_mc_wolf_icon_sit.png" @@ -217,7 +217,7 @@ dog.on_rightclick = function(self, clicker) self.state = "stand" self.walk_chance = 0 self.jump = false - mcl_mobs:set_animation(self, "sit") + self:set_animation("sit") end -- Display icon to show current order (sit or roam) minetest.add_particle({