forked from Mineclonia/Mineclonia
Make mcl_loot/get_random_slots() deterministic
This commit is contained in:
parent
eb62db441b
commit
47db5c5917
|
@ -111,14 +111,14 @@ end
|
|||
Returns a table of length `max_slot` and all natural numbers between 1 and `max_slot`
|
||||
in a random order.
|
||||
]]
|
||||
local function get_random_slots(max_slot)
|
||||
local function get_random_slots(max_slot, pr)
|
||||
local slots = {}
|
||||
for s=1, max_slot do
|
||||
slots[s] = s
|
||||
end
|
||||
local slots_out = {}
|
||||
while #slots > 0 do
|
||||
local r = math.random(1, #slots)
|
||||
local r = pr and pr:next(1, #slots) or math.random(1, #slots)
|
||||
table.insert(slots_out, slots[r])
|
||||
table.remove(slots, r)
|
||||
end
|
||||
|
@ -135,9 +135,9 @@ Items will be added from start of the table to end.
|
|||
If the inventory already has occupied slots, or is
|
||||
too small, placement of some items might fail.
|
||||
]]
|
||||
function mcl_loot.fill_inventory(inv, listname, items)
|
||||
function mcl_loot.fill_inventory(inv, listname, items, pr)
|
||||
local size = inv:get_size(listname)
|
||||
local slots = get_random_slots(size)
|
||||
local slots = get_random_slots(size, pr)
|
||||
local leftovers = {}
|
||||
-- 1st pass: Add items into random slots
|
||||
for i=1, math.min(#items, size) do
|
||||
|
|
|
@ -311,7 +311,7 @@ local function ecb_spawn_dungeon(blockpos, action, calls_remaining, param)
|
|||
|
||||
minetest.set_node(pos, {name="mcl_chests:chest", param2=facedir})
|
||||
local meta = minetest.get_meta(pos)
|
||||
mcl_loot.fill_inventory(meta:get_inventory(), "main", mcl_loot.get_multi_loot(loottable, pr))
|
||||
mcl_loot.fill_inventory(meta:get_inventory(), "main", mcl_loot.get_multi_loot(loottable, pr), pr)
|
||||
end
|
||||
|
||||
-- Mob spawners are placed seperately, too
|
||||
|
|
|
@ -244,7 +244,7 @@ local function igloo_placement_callback(p1, p2, size, orientation, pr)
|
|||
init_node_construct(chest_pos)
|
||||
local meta = minetest.get_meta(chest_pos)
|
||||
local inv = meta:get_inventory()
|
||||
mcl_loot.fill_inventory(inv, "main", lootitems)
|
||||
mcl_loot.fill_inventory(inv, "main", lootitems, pr)
|
||||
end
|
||||
|
||||
mcl_structures.generate_igloo_basement = function(pos, orientation, pr)
|
||||
|
@ -463,7 +463,7 @@ local function temple_placement_callback(p1, p2, size, rotation, pr)
|
|||
init_node_construct(chests[c])
|
||||
local meta = minetest.get_meta(chests[c])
|
||||
local inv = meta:get_inventory()
|
||||
mcl_loot.fill_inventory(inv, "main", lootitems)
|
||||
mcl_loot.fill_inventory(inv, "main", lootitems, pr)
|
||||
end
|
||||
|
||||
-- Initialize pressure plates and randomly remove up to 5 plates
|
||||
|
|
|
@ -178,7 +178,7 @@ function settlements.fill_chest(pos, pr)
|
|||
end
|
||||
|
||||
local items = get_treasures(pr)
|
||||
mcl_loot.fill_inventory(inv, "main", items)
|
||||
mcl_loot.fill_inventory(inv, "main", items, pr)
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
|
|
@ -380,7 +380,7 @@ local function PlaceChest(pos, param2)
|
|||
local meta = minetest.get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
local items = tsm_railcorridors.get_treasures(pr)
|
||||
mcl_loot.fill_inventory(inv, "main", items)
|
||||
mcl_loot.fill_inventory(inv, "main", items, pr)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue