From df387e2394425ca9a0d535ca18d821fe632f4c68 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sun, 17 Mar 2019 13:56:23 +0100 Subject: [PATCH 1/2] Dungeon loot: Don't crash on unknown items fixes #2228 --- mods/dungeon_loot/mapgen.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mods/dungeon_loot/mapgen.lua b/mods/dungeon_loot/mapgen.lua index c6a45094..4394c510 100644 --- a/mods/dungeon_loot/mapgen.lua +++ b/mods/dungeon_loot/mapgen.lua @@ -88,7 +88,9 @@ local function populate_chest(pos, rand, dungeontype) amount = rand:next(loot.count[1], loot.count[2]) end - if itemdef.tool_capabilities then + if itemdef == nil then + -- item doesn't exist, do nothing + elseif itemdef.tool_capabilities then for n = 1, amount do local wear = rand:next(0.20 * 65535, 0.75 * 65535) -- 20% to 75% wear table.insert(items, ItemStack({name = loot.name, wear = wear})) From 86782651253b757a633b473a56a56ff11c76982e Mon Sep 17 00:00:00 2001 From: Paramat Date: Sat, 23 Mar 2019 23:16:41 +0000 Subject: [PATCH 2/2] Dungeon loot: Avoid empty 'if' branch to satisfy lua check --- mods/dungeon_loot/mapgen.lua | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/mods/dungeon_loot/mapgen.lua b/mods/dungeon_loot/mapgen.lua index 4394c510..366d4ce4 100644 --- a/mods/dungeon_loot/mapgen.lua +++ b/mods/dungeon_loot/mapgen.lua @@ -88,20 +88,20 @@ local function populate_chest(pos, rand, dungeontype) amount = rand:next(loot.count[1], loot.count[2]) end - if itemdef == nil then - -- item doesn't exist, do nothing - elseif itemdef.tool_capabilities then - for n = 1, amount do - local wear = rand:next(0.20 * 65535, 0.75 * 65535) -- 20% to 75% wear - table.insert(items, ItemStack({name = loot.name, wear = wear})) + if itemdef then + if itemdef.tool_capabilities then + for n = 1, amount do + local wear = rand:next(0.20 * 65535, 0.75 * 65535) -- 20% to 75% wear + table.insert(items, ItemStack({name = loot.name, wear = wear})) + end + elseif itemdef.stack_max == 1 then + -- not stackable, add separately + for n = 1, amount do + table.insert(items, loot.name) + end + else + table.insert(items, ItemStack({name = loot.name, count = amount})) end - elseif itemdef.stack_max == 1 then - -- not stackable, add separately - for n = 1, amount do - table.insert(items, loot.name) - end - else - table.insert(items, ItemStack({name = loot.name, count = amount})) end end end