From 7139c627d29d955b5ca9b4d33385b4e63f198c34 Mon Sep 17 00:00:00 2001 From: Jordan Irwin Date: Wed, 5 May 2021 10:21:03 -0700 Subject: [PATCH] Titleize displayed egg names --- CHANGES.txt | 4 ++++ api.lua | 15 ++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/CHANGES.txt b/CHANGES.txt index 0abb394..92a1d75 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,4 +1,8 @@ +1.1 +- Egg names are titleized & underscores are replaced with space. + + 1.0 - Made independent of any other mods or games. - Renamed to "asm_spawneggs" (Another Spawneggs Mod). diff --git a/api.lua b/api.lua index 139a422..2219883 100644 --- a/api.lua +++ b/api.lua @@ -53,6 +53,19 @@ end asm.addEggRecipe = asm.registerEggRecipe +local function formatTitle(s) + s = s:gsub("_", " ") + + local t = {} + + for m in (s .. " "):gmatch("(.-) ") do + local v = m:gsub("^%l", string.upper) + table.insert(t, v) + end + + return table.concat(t, " ") .. " Spawn Egg" +end + --- Registers new egg in game. -- -- Alias: *asm.addEgg* @@ -66,7 +79,7 @@ asm.registerEgg = function(def) end core.register_craftitem(":spawneggs:" .. def.name:lower(), { - description = def.name:gsub("^%l", string.upper) .. " Spawn Egg", + description = formatTitle(def.name), inventory_image = img, on_place = function(itemstack, placer, target)