From e28b55c16a7255f5bb30f2aecc333e131b9d6ac6 Mon Sep 17 00:00:00 2001 From: teknomunk Date: Sat, 28 Dec 2024 17:04:05 -0600 Subject: [PATCH] Replace linear cart fill with mcl_loot.fill_inventory() using a fake inventory, remove debug print --- mods/MAPGEN/tsm_railcorridors/gameconfig.lua | 26 ++++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/mods/MAPGEN/tsm_railcorridors/gameconfig.lua b/mods/MAPGEN/tsm_railcorridors/gameconfig.lua index 1cfeb8368..177ddef9d 100644 --- a/mods/MAPGEN/tsm_railcorridors/gameconfig.lua +++ b/mods/MAPGEN/tsm_railcorridors/gameconfig.lua @@ -88,15 +88,25 @@ function tsm_railcorridors.create_cart_staticdata(entity_id, pos, pr) if cartdata and has_loot[entity_id] then local items = tsm_railcorridors.get_treasures(pr) - -- TODO: determine if we should convert to use mcl_loot - -- mcl_loot.fill_inventory(inv, "main", items, pr_carts) - -- Convert from ItemStack to itemstrings - for k,item in pairs(items) do - items[k] = item:to_string() - end - cartdata.inventory = items + local size = core.registered_entities[entity_id]._inv_size + local inventory = {} + for i = 1,size do inventory[i] = "" end + cartdata.inventory = inventory + + -- Fill a fake inventory using mcl_loot + local fake_inv = { + get_size = function(self) + return size + end, + get_stack = function(self, _, i) + return ItemStack(inventory[i]) + end, + set_stack = function(self, _, i, stack) + inventory[i] = stack:to_string() + end, + } + mcl_loot.fill_inventory(fake_inv, "main", items, pr_carts) - print("cartdata = "..dump(cartdata)) save_cart_data(uuid) end