mirror of
https://github.com/joe7575/techpack.git
synced 2024-11-22 15:23:43 +01:00
HP distributor bugfix (issue #26)
This commit is contained in:
parent
472fb56b9d
commit
82fcfad147
@ -110,6 +110,14 @@ local function random_list_elem(list)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function rearrange_table(t)
|
||||||
|
if #t > 1 then
|
||||||
|
local elem = table.remove(t, 1)
|
||||||
|
table.insert(t, elem)
|
||||||
|
end
|
||||||
|
return t
|
||||||
|
end
|
||||||
|
|
||||||
local Side2Color = {B="red", L="green", F="blue", R="yellow"}
|
local Side2Color = {B="red", L="green", F="blue", R="yellow"}
|
||||||
local SlotColors = {"red", "green", "blue", "yellow"}
|
local SlotColors = {"red", "green", "blue", "yellow"}
|
||||||
local Num2Ascii = {"B", "L", "F", "R"}
|
local Num2Ascii = {"B", "L", "F", "R"}
|
||||||
@ -202,7 +210,10 @@ local function distributing(pos, meta)
|
|||||||
local open_ports = table.copy(FilterCache[hash].OpenPorts)
|
local open_ports = table.copy(FilterCache[hash].OpenPorts)
|
||||||
|
|
||||||
-- no filter configured?
|
-- no filter configured?
|
||||||
if not next(kvFilterItemNames) and not next(open_ports) then return end
|
if not next(kvFilterItemNames) and not next(open_ports) then
|
||||||
|
State:idle(pos, meta)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
local busy = false
|
local busy = false
|
||||||
local inv = meta:get_inventory()
|
local inv = meta:get_inventory()
|
||||||
@ -223,23 +234,20 @@ local function distributing(pos, meta)
|
|||||||
local num = stack:get_count()
|
local num = stack:get_count()
|
||||||
local second_try = false
|
local second_try = false
|
||||||
-- try configured output ports
|
-- try configured output ports
|
||||||
local side = random_list_elem(kvFilterItemNames[name])
|
for _, side in ipairs(kvFilterItemNames[name] or {}) do -- configured
|
||||||
if side then -- configured
|
|
||||||
if tubelib.push_items(pos, side, stack, player_name) then
|
if tubelib.push_items(pos, side, stack, player_name) then
|
||||||
stack:set_count(0)
|
stack:set_count(0)
|
||||||
local color = Side2Color[side]
|
local color = Side2Color[side]
|
||||||
counter[color] = counter[color] + num
|
counter[color] = counter[color] + num
|
||||||
|
rearrange_table(kvFilterItemNames[name])
|
||||||
busy = true
|
busy = true
|
||||||
else
|
break
|
||||||
second_try = true -- port blocked
|
|
||||||
end
|
end
|
||||||
else
|
|
||||||
second_try = true -- not configured
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- try unconfigured open output ports
|
-- try unconfigured open output ports
|
||||||
if second_try and (not kvFilterItemNames[name] or #kvFilterItemNames[name] == 1) then
|
if not busy then
|
||||||
side = random_list_elem(open_ports)
|
local side = random_list_elem(open_ports)
|
||||||
if side then
|
if side then
|
||||||
if tubelib.push_items(pos, side, stack, player_name) then
|
if tubelib.push_items(pos, side, stack, player_name) then
|
||||||
stack:set_count(0)
|
stack:set_count(0)
|
||||||
|
Loading…
Reference in New Issue
Block a user