mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-13 23:14:53 +09:00
Support for transferring crafting queues
This commit is contained in:
1 parent
40301f59b7
commit
87218e4803
8 files changed
+339
-182
No files matched your search
@@ -0,0 +1,35 @@
|
||||
-- Load crafting queue from a table
|
||||
function load_crafting_queue(crafting_queue, player)
|
||||
local inventory = player.get_main_inventory()
|
||||
|
||||
-- Give player some more inventory space to avoid duplicating items
|
||||
player.character_inventory_slots_bonus = player.character_inventory_slots_bonus + 100
|
||||
|
||||
-- Load crafting queue
|
||||
for _, queueItem in pairs(crafting_queue) do
|
||||
local recipe = game.recipe_prototypes[queueItem.recipe]
|
||||
game.print("Crafting "..queueItem.recipe)
|
||||
-- Add items to inventory
|
||||
for _, item in pairs(recipe.ingredients) do
|
||||
local count = math.floor(item.amount * queueItem.count / math.max(recipe.main_product.amount, 1))
|
||||
if count > 0 then
|
||||
inventory.insert({
|
||||
name = item.name,
|
||||
count = count,
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
-- Start crafting (consume items)
|
||||
player.begin_crafting {
|
||||
count = queueItem.count,
|
||||
recipe = queueItem.recipe,
|
||||
silent = true, -- Fail silently if items are missing
|
||||
}
|
||||
end
|
||||
|
||||
-- Remove extra inventory slots
|
||||
player.character_inventory_slots_bonus = player.character_inventory_slots_bonus - 100
|
||||
end
|
||||
|
||||
return load_crafting_queue
|
||||
Reference in new issue
Block a user