diff --git a/CHANGES.txt b/CHANGES.txt index 92a1d75..69d6a1d 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,4 +1,8 @@ +1.2 +- Added method to retrieve registered egg by entity name. + + 1.1 - Egg names are titleized & underscores are replaced with space. diff --git a/api.lua b/api.lua index 8772116..75d2386 100644 --- a/api.lua +++ b/api.lua @@ -29,6 +29,18 @@ -- @module api.lua +local registered_eggs = {} + +--- Retrieves egg that spawns specified entity. +-- +-- @function asm.getEgg +-- @tparam string entity Entity name spawned by egg. +-- @treturn string Egg name or `nil`. +function asm.getEgg(entity) + return registered_eggs[entity] +end + + --- Adds a craft recipe for an egg. -- -- Alias: *asm.addEggRecipe* @@ -83,7 +95,9 @@ asm.registerEgg = function(def) title = formatTitle(def.name) end - core.register_craftitem(":spawneggs:" .. def.name:lower(), { + local egg_name = "spawneggs:" .. def.name:lower() + + core.register_craftitem(":" .. egg_name, { description = title, inventory_image = img, @@ -106,6 +120,9 @@ asm.registerEgg = function(def) end }) + -- store registration + registered_eggs[def.spawn] = egg_name + if def.ingredients then asm.registerEggRecipe(def.name:lower(), def.ingredients) end