diff options
author | Wuzzy <almikes@aol.com> | 2016-08-17 12:12:45 +0200 |
---|---|---|
committer | Wuzzy <almikes@aol.com> | 2016-08-17 12:12:45 +0200 |
commit | cdbd01a1bd88b618265d7d46bfa54650b3007ccb (patch) | |
tree | 01401218a82e27b3a6260104947fe113c72043ca /init.lua | |
parent | 602b81413c34d95b65be76e18e6050ce7c481fe7 (diff) |
Sort drop probability when max_drops == 1
Diffstat (limited to 'init.lua')
-rw-r--r-- | init.lua | 11 |
1 files changed, 10 insertions, 1 deletions
@@ -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 |