Add compat for old "wrong" : notation

This commit is contained in:
cora 2022-11-09 06:06:59 +01:00
parent e82c318f0c
commit bbba7cee41
9 changed files with 55 additions and 19 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -19,3 +19,5 @@ dofile(path .. "/mount.lua")
-- Mob Items
dofile(path .. "/crafts.lua")
dofile(path .. "/compat.lua")

View file

@ -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

View file

@ -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

View file

@ -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,

View file

@ -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

View file

@ -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({