From cdbd01a1bd88b618265d7d46bfa54650b3007ccb Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Wed, 17 Aug 2016 12:12:45 +0200 Subject: Sort drop probability when max_drops == 1 --- init.lua | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'init.lua') diff --git a/init.lua b/init.lua index 5f681d8..1242186 100644 --- a/init.lua +++ b/init.lua @@ -530,14 +530,23 @@ doc.new_category("nodes", { for j=1,#data.def.drop.items[i].items do local subrarity = rarity * (#data.def.drop.items[i].items) local dropstack = ItemStack(data.def.drop.items[i].items[j]) + local itemstring = dropstack:get_name() local desc = get_desc(dropstack) local count = dropstack:get_count() - table.insert(probtable, {desc = desc, count = count, rarity = subrarity}) + table.insert(probtable, {itemstring = itemstring, desc = desc, count = count, rarity = subrarity}) end if max ~= nil then remaining_rarity = 1/(1/remaining_rarity - 1/rarity) end end + -- Do some cleanup of the probability table + if max == 1 then + -- Sort by rarity + local comp = function(p1, p2) + return p1.rarity < p2.rarity + end + table.sort(probtable, comp) + end -- Output probability table local icount = 0 for i=1, #probtable do -- cgit v1.2.3