Skip to content

Instantly share code, notes, and snippets.

@MEXAHOTABOP
Last active July 24, 2018 14:34
Show Gist options
  • Save MEXAHOTABOP/3647c1d52db8f950cc46c3122cb733cd to your computer and use it in GitHub Desktop.
Save MEXAHOTABOP/3647c1d52db8f950cc46c3122cb733cd to your computer and use it in GitHub Desktop.
trans = component.proxy(component.list("transposer")())
--[[
Bottom (bottom), Number: 0 -z
Top (top), Number: 1 +y
Back (back), Number: 2 -z
Front (front), Number: 3 +z
Right (right), Number: 4 -x
Left (left), Number: 5 +x
]]
input, centrifuge, nullifier, pile = 1,0,4,2 --стороны
input_inventory_size = trans.getInventorySize(input)
pile_inventory_size = trans.getInventorySize(pile)
function sort(slot)
local stack = trans.getStackInSlot(input, slot)
if stack == nil then
return
end
if stack.label:find("Stone") ~= nil then
trans.transferItem(input, nullifier, stack.size, slot ,1)
elseif stack.label:find("Tiny") ~= nil then
sort_tiny(stack,slot)
elseif stack.label:find("Purified") ~= nil then
sort_purified(stack,slot)
end
end
function sort_purified(stack, slot)
local target_stack = trans.getStackInSlot(centrifuge, 9) --9 слот вход центрифуги
if target_stack == nil then
trans.transferItem(input, centrifuge, stack.size, slot, 9)
elseif target_stack.label == stack.label then
local to_drop = target_stack.maxSize - target_stack.size
if to_drop > stack.size then
to_drop = stack.size
end
trans.transferItem(input, centrifuge, to_drop, slot, 9)
end
end
function sort_tiny(stack, slot)
local first_empty = 0
local left_to_drop = stack.size - (stack.size % 9)
for j = 1, pile_inventory_size do --наполняем стаки
if left_to_drop == 0 then return end
local target_stack = trans.getStackInSlot(pile,j)
if first_empty == 0 and target_stack == nil then
first_empty = j
end
if target_stack ~= nil and stack.label == target_stack.label and target_stack.size ~= target_stack.maxSize then
local to_drop = target_stack.maxSize - target_stack.size
if to_drop < left_to_drop then
left_to_drop = left_to_drop - to_drop
else
to_drop = left_to_drop
left_to_drop = 0
end
trans.transferItem(input, pile, to_drop, slot ,j)
end
end
if left_to_drop > 0 then
trans.transferItem(input, pile, left_to_drop, slot, first_empty)
end
end
while true do
for i = 1, input_inventory_size do
sort(i)
end
computer.pullSignal(1)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment