Skip to content

Commit 02e2cab

Browse files
committedMar 17, 2019
Dungeon loot: Don't crash on unknown items
fixes #2228
1 parent b853c8a commit 02e2cab

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed
 

Diff for: ‎mods/dungeon_loot/mapgen.lua

+3-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@ local function populate_chest(pos, rand, dungeontype)
8888
amount = rand:next(loot.count[1], loot.count[2])
8989
end
9090

91-
if itemdef.tool_capabilities then
91+
if itemdef == nil then
92+
-- item doesn't exist, do nothing
93+
elseif itemdef.tool_capabilities then
9294
for n = 1, amount do
9395
local wear = rand:next(0.20 * 65535, 0.75 * 65535) -- 20% to 75% wear
9496
table.insert(items, ItemStack({name = loot.name, wear = wear}))

3 commit comments

Comments
 (3)

paramat commented on Mar 18, 2019

@paramat
Contributor

Makes lua check fail.

Checking mods/dungeon_loot/mapgen.lua             1 warning
    mods/dungeon_loot/mapgen.lua:91:22: empty if branch

Yukitty commented on Mar 22, 2019

@Yukitty

Suggesting alternative:
if itemdef and itemdef.tool_capabilities then

paramat commented on Mar 23, 2019

@paramat
Contributor

Fixed in #2344

Please sign in to comment.