Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local drone = component.proxy(component.list("drone")())
- local ic = component.proxy(component.list("inventory_controller")())
- local maxSlot = drone.inventorySize()
- local valid_sides = {0, 1, 2, 3, 4, 5}
- function getItemName(slot)
- local item = ic.getStackInInternalSlot(slot)
- if item then
- return item.name
- else
- return ''
- end
- end
- function isItem(slot, name)
- return getItemName(slot) == name
- end
- function getSideItemName(side, slot)
- local item = ic.getStackInSlot(side, slot)
- if item then
- return item.name
- else
- return ''
- end
- end
- function isSideItem(side, slot, name)
- return getSideItemName(side, slot) == name
- end
- function findSideItem(side, itemName)
- local max = ic.getInventorySize(side)
- if max then
- for slot = 1, max, 1 do
- if isSideItem(side, slot, itemName) then
- return slot
- end
- end
- end
- return 0
- end
- function findItemOnSides(itemName)
- for k, side in pairs(valid_sides) do
- local slot = findSideItem(side, itemName)
- if slot > 0 then
- return suckFromSlot(side, slot)
- end
- end
- return 0
- end
- function suckFromSlot(side, slot)
- local newSlot = findEmptySlot()
- if newSlot == 0 then
- newSlot = cleanASlot()
- end
- if newSlot > 0 then
- drone.select(newSlot)
- ic.suckFromSlot(side, slot)
- insertSideEmptySlots(side, slot)
- return newSlot
- end
- return 0
- end
- function dropIntoSlot(slot)
- drone.select(slot)
- local name = getItemName(slot)
- local side, newSlot = findEmptySlotOnSides()
- if newSlot > 0 then
- ic.dropIntoSlot(side, newSlot)
- insertSideItems(side, newSlot, name)
- return true
- end
- return false
- end
- function findItem(itemName, slot)
- for slot = slot, maxSlot, 1 do
- if isItem(slot, itemName) then
- return slot
- end
- end
- return 0
- end
- function findEmptySlot()
- for slot = 1, maxSlot, 1 do
- if isEmptySlot(slot) then
- return slot
- end
- end
- return 0
- end
- function isEmptySlot(slot)
- local count = drone.count(slot)
- if count == 0 then
- return true
- else
- return false
- end
- end
- function findEmptySideSlot(side)
- local max = ic.getInventorySize(side)
- if max then
- for slot = 1, max, 1 do
- if isEmptySideSlot(side, slot) then
- return slot
- end
- end
- end
- return 0
- end
- function isEmptySideSlot(side, slot)
- return ic.getSlotStackSize(side, slot) == 0
- end
- function isFullSideSlot(side, slot)
- return ic.getSlotStackSize(side, slot) == 64
- end
- function findEmptySlotOnSides()
- for k, side in pairs(valid_sides) do
- local slot = findEmptySideSlot(side)
- if slot > 0 then
- return side, slot
- end
- end
- return 0, 0
- end
- function cleanASlot()
- for slot = 1, maxSlot, 1 do
- if isFullSlot(slot) then
- if dropIntoSlot(slot) then
- return slot
- end
- break
- end
- end
- return 0
- end
- function isFullSlot(slot)
- local count = drone.count(slot)
- if count == 64 then
- return true
- else
- return false
- end
- end
- drone.setStatusText(drone.name())
- local itemName
- local ret
- while true do
- computer.pullSignal(0.5)
- itemName = getItemName(1)
- ret = findItemOnSides(itemName)
- drone.setStatusText(tostring(ret))
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement