From b332556c633af69e4ab1987b0745cd3edeae2a02 Mon Sep 17 00:00:00 2001 From: "A. Demant" Date: Tue, 13 Nov 2018 05:07:20 +0100 Subject: [PATCH] dungeon loot --- mods/dungeon_loot/mapgen.lua | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/mods/dungeon_loot/mapgen.lua b/mods/dungeon_loot/mapgen.lua index c6a4509..c2f7a82 100644 --- a/mods/dungeon_loot/mapgen.lua +++ b/mods/dungeon_loot/mapgen.lua @@ -87,19 +87,20 @@ local function populate_chest(pos, rand, dungeontype) if loot.count ~= nil then amount = rand:next(loot.count[1], loot.count[2]) end - - 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})) + if itemdef ~= nil 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