From 0b9f97dd14481d5ee1b71e930e27e6fa5a1ef04c Mon Sep 17 00:00:00 2001
From: Novatux <nathanael.courant@laposte.net>
Date: Sat, 28 Sep 2013 19:03:49 +0200
Subject: [PATCH] Randomly scatter items in chests

---
 init.lua | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/init.lua b/init.lua
index ebaa32f..37e846a 100644
--- a/init.lua
+++ b/init.lua
@@ -689,7 +689,11 @@ minetest.register_on_generated(function(minp, maxp, seed)
 					stacksz = math.floor(items[ii]:get_count() / 2 ^ 8)
 					if pr:next(0, prob) == 0 then
 						stk = ItemStack({name=items[ii]:get_name(), count=stacksz, wear=items[ii]:get_count(), metadata=items[ii]:get_metadata()})
-						inv:add_item("main", stk)
+						local ind = pr:next(1, inv:get_size("main"))
+						while not inv:get_stack("main",ind):is_empty() do
+							ind = pr:next(1, inv:get_size("main"))
+						end
+						inv:set_stack("main", ind, stk)
 					end
 				end
 			end