Fix some minor bugs
This commit is contained in:
@@ -195,12 +195,17 @@ enqueueItem = function(item, queue, predicate)
|
|||||||
-- Only machines have multiple
|
-- Only machines have multiple
|
||||||
-- So inventrorY should be fine here
|
-- So inventrorY should be fine here
|
||||||
-- debugPrint("Item has its own inventory, enqueuing inventory...")
|
-- debugPrint("Item has its own inventory, enqueuing inventory...")
|
||||||
queue, _ = enqueueInventory(item.OwnInventory, queue)
|
queue, _ = enqueueInventory(item.OwnInventory, queue, predicate)
|
||||||
-- if err then
|
-- if err then
|
||||||
-- debugPrint(string.format("Error enqueuing inventory: %s", err))
|
-- debugPrint(string.format("Error enqueuing inventory: %s", err))
|
||||||
-- end
|
-- end
|
||||||
end
|
end
|
||||||
if predicate(item) then queue[#queue + 1] = item end
|
local ok, stop = predicate(item)
|
||||||
|
if ok then
|
||||||
|
-- debugPrint(string.format("Enqueuing item: %s", item.Prefab.Identifier.Value))
|
||||||
|
queue[#queue + 1] = item
|
||||||
|
end
|
||||||
|
if stop then return queue, nil end
|
||||||
-- debugPrint(string.format("Item enqueued. Current queue size: %d", #queue))
|
-- debugPrint(string.format("Item enqueued. Current queue size: %d", #queue))
|
||||||
return queue, nil
|
return queue, nil
|
||||||
end
|
end
|
||||||
@@ -385,8 +390,8 @@ local function quickStackItems(character)
|
|||||||
for _, container in ipairs(openContainers) do
|
for _, container in ipairs(openContainers) do
|
||||||
local inventories = container.OwnInventories
|
local inventories = container.OwnInventories
|
||||||
debugPrint(string.format("Found %d inventories in the open container", #inventories))
|
debugPrint(string.format("Found %d inventories in the open container", #inventories))
|
||||||
for i, containerInventory in ipairs(inventories) do
|
for containerInventory in inventories do
|
||||||
debugPrint(string.format("Enqueuing inventory %d with %d slots", i, #containerInventory.slots))
|
debugPrint(string.format("Enqueuing inventory with %d slots", #containerInventory.slots))
|
||||||
local before = #toMove
|
local before = #toMove
|
||||||
toMove = enqueueInventory(containerInventory, toMove)
|
toMove = enqueueInventory(containerInventory, toMove)
|
||||||
local after = #toMove
|
local after = #toMove
|
||||||
@@ -464,7 +469,7 @@ local function getSelectedRecipeRequirements(fabricator)
|
|||||||
if not selectedRecipe then return nil, "No selected recipe found" end
|
if not selectedRecipe then return nil, "No selected recipe found" end
|
||||||
|
|
||||||
local requiredItems = {}
|
local requiredItems = {}
|
||||||
for _, requiredItem in pairs(selectedRecipe.RequiredItems) do
|
for requiredItem in selectedRecipe.RequiredItems do
|
||||||
local itemInfo = {
|
local itemInfo = {
|
||||||
amount = tonumber(requiredItem.Amount),
|
amount = tonumber(requiredItem.Amount),
|
||||||
minCondition = tonumber(requiredItem.MinCondition),
|
minCondition = tonumber(requiredItem.MinCondition),
|
||||||
@@ -473,7 +478,7 @@ local function getSelectedRecipeRequirements(fabricator)
|
|||||||
}
|
}
|
||||||
|
|
||||||
for prefab in requiredItem.ItemPrefabs do
|
for prefab in requiredItem.ItemPrefabs do
|
||||||
itemInfo.prefabs[#itemInfo.prefabs + 1] = prefab.Identifier
|
itemInfo.prefabs[#itemInfo.prefabs + 1] = prefab.Identifier.Value
|
||||||
end
|
end
|
||||||
|
|
||||||
requiredItems[#requiredItems + 1] = itemInfo
|
requiredItems[#requiredItems + 1] = itemInfo
|
||||||
@@ -547,34 +552,42 @@ Hook.Patch("Barotrauma.Character", "ControlLocalPlayer", function(instance, ptab
|
|||||||
---@type fun(item: Barotrauma.Item): boolean
|
---@type fun(item: Barotrauma.Item): boolean
|
||||||
local filter = function(item)
|
local filter = function(item)
|
||||||
local found = false
|
local found = false
|
||||||
if #toFind == 0 then return false end
|
|
||||||
-- toFind are all items we need to find
|
-- toFind are all items we need to find
|
||||||
for i, itemInfo in ipairs(toFind) do
|
for i, itemInfo in ipairs(toFind) do
|
||||||
-- prefabs are all items that satisfy the requirements
|
-- prefabs are all items that satisfy the requirements
|
||||||
for _, prefab in ipairs(itemInfo.prefabs) do
|
for _, prefab in ipairs(itemInfo.prefabs) do
|
||||||
if item.Prefab.Identifier == prefab then
|
-- debugPrint(string.format("Checking %s against %s", item.Prefab.Identifier.Value, prefab))
|
||||||
|
if item.Prefab.Identifier.Value == prefab then
|
||||||
|
-- debugPrint(string.format("That'll do %s %s", item.Prefab.Identifier.Value, prefab))
|
||||||
toGet[#toGet + 1] = item
|
toGet[#toGet + 1] = item
|
||||||
itemInfo.amount = itemInfo.amount - 1
|
itemInfo.amount = itemInfo.amount - 1
|
||||||
found = true
|
found = false
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if itemInfo.amount <= 0 then
|
if itemInfo.amount <= 0 then toFind[i] = nil end
|
||||||
toFind[i] = nil
|
|
||||||
end
|
|
||||||
if found then break end
|
if found then break end
|
||||||
end
|
end
|
||||||
return found
|
-- debugPrint(string.format("Found %s %s", item.Prefab.Identifier.Value, tostring(found)))
|
||||||
|
return found, #toFind == 0
|
||||||
end
|
end
|
||||||
|
-- DumpTable(toGet)
|
||||||
|
|
||||||
local items = enqueueInventory(bagItem.OwnInventory, {}, filter)
|
local items = enqueueInventory(bagItem.OwnInventory, {}, filter)
|
||||||
-- TODO: This might explode... Oh well?
|
-- TODO: This might explode... Oh well?
|
||||||
local inputInventory = fabricator.item.OwnInventories[1]
|
local inputInventory = fabricator.item.OwnInventories[1]
|
||||||
|
for iinventory in fabricator.item.OwnInventories do
|
||||||
|
if #iinventory.slots > 1 then
|
||||||
|
inputInventory = iinventory
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local slot = -1
|
local slot = -1
|
||||||
local previous = nil
|
local previous = nil
|
||||||
for _, item in ipairs(items) do
|
for _, item in ipairs(items) do
|
||||||
if previous ~= item.Prefab.Identifier then slot = slot + 1 end
|
if previous ~= item.Prefab.Identifier then slot = slot + 1 end
|
||||||
inputInventory.TryPutItem(item, slot, false, true, nil)
|
-- inputInventory.TryPutItem(item, slot, false, true, nil)
|
||||||
previous = item.Prefab.Identifier
|
previous = item.Prefab.Identifier
|
||||||
end
|
end
|
||||||
DumpTable(items)
|
DumpTable(items)
|
||||||
|
|||||||
Reference in New Issue
Block a user