From 47db5c591779119f328079249824ad60d36bc4c9 Mon Sep 17 00:00:00 2001 From: kay27 Date: Mon, 22 Feb 2021 21:58:35 +0400 Subject: [PATCH] Make mcl_loot/get_random_slots() deterministic --- mods/CORE/mcl_loot/init.lua | 8 ++++---- mods/MAPGEN/mcl_dungeons/init.lua | 2 +- mods/MAPGEN/mcl_structures/init.lua | 4 ++-- mods/MAPGEN/mcl_villages/utils.lua | 2 +- mods/MAPGEN/tsm_railcorridors/init.lua | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/mods/CORE/mcl_loot/init.lua b/mods/CORE/mcl_loot/init.lua index e3db73be19..6db743740c 100644 --- a/mods/CORE/mcl_loot/init.lua +++ b/mods/CORE/mcl_loot/init.lua @@ -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 diff --git a/mods/MAPGEN/mcl_dungeons/init.lua b/mods/MAPGEN/mcl_dungeons/init.lua index 7c5f52b037..6749616dc1 100644 --- a/mods/MAPGEN/mcl_dungeons/init.lua +++ b/mods/MAPGEN/mcl_dungeons/init.lua @@ -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 diff --git a/mods/MAPGEN/mcl_structures/init.lua b/mods/MAPGEN/mcl_structures/init.lua index 31b85e151c..8bd1883276 100644 --- a/mods/MAPGEN/mcl_structures/init.lua +++ b/mods/MAPGEN/mcl_structures/init.lua @@ -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 diff --git a/mods/MAPGEN/mcl_villages/utils.lua b/mods/MAPGEN/mcl_villages/utils.lua index dfde4089ae..2f411b3011 100644 --- a/mods/MAPGEN/mcl_villages/utils.lua +++ b/mods/MAPGEN/mcl_villages/utils.lua @@ -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 ------------------------------------------------------------------------------- diff --git a/mods/MAPGEN/tsm_railcorridors/init.lua b/mods/MAPGEN/tsm_railcorridors/init.lua index 483a79f414..982edcd0d0 100644 --- a/mods/MAPGEN/tsm_railcorridors/init.lua +++ b/mods/MAPGEN/tsm_railcorridors/init.lua @@ -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