Fix getting mob definition when name prefixed with colon

master
Jordan Irwin 2021-06-01 18:35:23 -07:00
parent 5c4d361fea
commit 47b65a761f
3 changed files with 27 additions and 12 deletions

View File

@ -23,6 +23,8 @@
-- Localizations
local rnd = math.random
local translate_name = dofile(cmer.modpath .. "/misc_functions.lua")
local function knockback(selfOrObject, dir, old_dir, strengh)
local object = selfOrObject
@ -177,7 +179,7 @@ end
local function onDamage(self, hp, hitsound)
local me = self.object
local def = core.registered_entities[self.mob_name]
local def = core.registered_entities[translate_name(self.mob_name)]
hp = hp or me:get_hp()
if hp <= 0 then
@ -368,7 +370,7 @@ end
cmer.on_step = function(self, dtime)
-- first get the relevant specs; exit if we don't know anything (1-3ms)
local def = core.registered_entities[self.mob_name]
local def = core.registered_entities[translate_name(self.mob_name)]
if not def then
throw_error("Can't load creature-definition")
return

11
misc_functions.lua Normal file
View File

@ -0,0 +1,11 @@
local function translate_name(name)
if name:find(":") == 1 then
name = name:sub(2)
end
return name
end
return translate_name

View File

@ -24,13 +24,7 @@
-- @module register.lua
local function translate_name(name)
if name:find(":") == 1 then
name = name:sub(2)
end
return name
end
local translate_name = dofile(cmer.modpath .. "/misc_functions.lua")
local function translate_def(def)
@ -387,6 +381,12 @@ function cmer.register_spawn(spawn_def)
return
end
local mob_name = translate_name(spawn_def.mob_name)
if cmer.debug then
print("ABM reached: " .. tostring(mob_name))
end
-- time check
local tod = core.get_timeofday() * 24000
if spawn_def.time_range then
@ -412,8 +412,6 @@ function cmer.register_spawn(spawn_def)
return
end
local mob_name translate_name(spawn_def.mob_name)
-- creature count check
local max
if active_object_count_wider > (spawn_def.max_number or 1) then
@ -447,7 +445,11 @@ function cmer.register_spawn(spawn_def)
if not checkSpace(pos, height_min) then
return
end
core.add_entity(pos, mob_name)
if not core.add_entity(pos, mob_name) then
cmer.log("error", "could not spawn entity: " .. tostring(mob_name))
elseif cmer.debug then
print("Spawned entity: " .. tostring(mob_name))
end
end
end,
})