mirror of
https://github.com/ComfyFactory/ComfyFactorio.git
synced 2025-01-06 00:23:49 +02:00
Autostash
Fixed that stone was inserted when count equals 1.
This commit is contained in:
parent
6e441730d4
commit
f213de2e74
@ -4,7 +4,7 @@
|
||||
local Global = require 'utils.global'
|
||||
local Event = require 'utils.event'
|
||||
local BottomFrame = require 'comfy_panel.bottom_frame'
|
||||
local math_floor = math.floor
|
||||
local floor = math.floor
|
||||
local print_color = {r = 120, g = 255, b = 0}
|
||||
|
||||
local this = {
|
||||
@ -131,7 +131,7 @@ local function sort_entities_by_distance(position, entities)
|
||||
|
||||
for _, entity in pairs(entities) do
|
||||
distance = (entity.position.x - position.x) ^ 2 + (entity.position.y - position.y) ^ 2
|
||||
index = math_floor(distance) + 1
|
||||
index = floor(distance) + 1
|
||||
if not t[index] then
|
||||
t[index] = {}
|
||||
end
|
||||
@ -208,11 +208,17 @@ local function insert_item_into_chest(player_inventory, chests, filtered_chests,
|
||||
['container'] = true,
|
||||
['logistic-container'] = true
|
||||
}
|
||||
local to_insert = math.floor(count / #chests)
|
||||
local variator = count % #chests
|
||||
local try = 0
|
||||
|
||||
local to_insert = floor(count / #chests)
|
||||
local variate = count % #chests
|
||||
local chests_available = #chests
|
||||
local tries = #chests
|
||||
|
||||
::retry::
|
||||
|
||||
--Attempt to store into furnaces.
|
||||
if furnace then
|
||||
if furnace then -- items
|
||||
for _, chest in pairs(chests) do
|
||||
local chest_inventory
|
||||
if chest.type == 'assembling-machine' then
|
||||
@ -221,28 +227,61 @@ local function insert_item_into_chest(player_inventory, chests, filtered_chests,
|
||||
chest_inventory = chest.get_inventory(defines.inventory.furnace_source)
|
||||
end
|
||||
local amount = to_insert
|
||||
if variator > 0 then
|
||||
if variate > 0 then
|
||||
amount = amount + 1
|
||||
variator = variator - 1
|
||||
variate = variate - 1
|
||||
end
|
||||
if amount <= 0 then
|
||||
return
|
||||
end
|
||||
if chest_inventory and (chest.type == 'furnace' or chest.type == 'assembling-machine') then
|
||||
if chest_inventory.can_insert({name = name, count = amount}) then
|
||||
local inserted_count = chest_inventory.insert({name = name, count = amount})
|
||||
player_inventory.remove({name = name, count = inserted_count})
|
||||
create_floaty_text(chest.surface, chest.position, name, inserted_count)
|
||||
|
||||
if chest_inventory then
|
||||
if (chest.type == 'furnace' or chest.type == 'assembling-machine') then
|
||||
if name == 'stone' then
|
||||
local valid_to_insert = (amount % 2 == 0)
|
||||
if valid_to_insert then
|
||||
if chest_inventory.can_insert({name = name, count = amount}) then
|
||||
local inserted_count = chest_inventory.insert({name = name, count = amount})
|
||||
player_inventory.remove({name = name, count = inserted_count})
|
||||
create_floaty_text(chest.surface, chest.position, name, inserted_count)
|
||||
count = count - inserted_count
|
||||
if count <= 0 then
|
||||
return
|
||||
end
|
||||
end
|
||||
else
|
||||
try = try + 1
|
||||
if try <= tries then
|
||||
chests_available = chests_available - 1
|
||||
to_insert = floor(count / chests_available)
|
||||
variate = count % chests_available
|
||||
goto retry
|
||||
end
|
||||
end
|
||||
else
|
||||
if chest_inventory.can_insert({name = name, count = amount}) then
|
||||
local inserted_count = chest_inventory.insert({name = name, count = amount})
|
||||
player_inventory.remove({name = name, count = inserted_count})
|
||||
create_floaty_text(chest.surface, chest.position, name, inserted_count)
|
||||
count = count - inserted_count
|
||||
if count <= 0 then
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
for _, chest in pairs(chests) do
|
||||
to_insert = floor(count / #chests)
|
||||
variate = count % #chests
|
||||
|
||||
for _, chest in pairs(chests) do -- fuel
|
||||
if chest.type == 'furnace' or chest.type == 'assembling-machine' then
|
||||
local amount = to_insert
|
||||
if variator > 0 then
|
||||
if variate > 0 then
|
||||
amount = amount + 1
|
||||
variator = variator - 1
|
||||
variate = variate - 1
|
||||
end
|
||||
if amount <= 0 then
|
||||
return
|
||||
@ -252,6 +291,10 @@ local function insert_item_into_chest(player_inventory, chests, filtered_chests,
|
||||
local inserted_count = chest_inventory.insert({name = name, count = amount})
|
||||
player_inventory.remove({name = name, count = inserted_count})
|
||||
create_floaty_text(chest.surface, chest.position, name, inserted_count)
|
||||
count = count - inserted_count
|
||||
if count <= 0 then
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user