Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function getItemList ()
- local itemList = {}
- for i = 1, 16, 1 do
- itemList[i] = turtle.getItemDetail(i)
- end
- return itemList
- end
- function checkSlot ( _item, _slot )
- if type(_item) ~= "string" then
- print("Invalid item")
- return nil
- end
- if type(_slot) ~= "number" or _slot < 1 or _slot > 16 then
- print("Invalid slot")
- return nil
- end
- local item = turtle.getItemDetail(_slot)
- if item ~= nil then
- return item.name == _item
- else
- return false
- end
- end
- function checkEmptySlot ()
- local itemList = getItemList()
- local emptySlot = 0
- for i = 1, 16, 1 do
- if itemList[i] == nil then
- emptySlot = i
- break
- end
- end
- return emptySlot
- end
- function checkForItem ( _item )
- local itemSlot = 0
- for i = 1, 16, 1 do
- if checkSlot(_item, i) then
- itemSlot = i
- break
- end
- end
- end
- function dropIfItems ( _itemList, _slot )
- local currentSelectedSlot = turtle.currentSelectedSlot()
- local currentItem = turtle.getItemDetail(_slot)
- local itemFound = false
- if currentItem == nil then return true end
- for i = 1, #_itemList, 1 do
- if _itemList[i] == currentItem.name then
- itemFound = true
- break
- end
- end
- if itemFound = false then return true end
- turtle.select(_slot)
- local success = turtle.dropDown()
- turtle.select(currentSelectedSlot)
- return success
- end
- function moveItem ( _slot )
- local item = turtle.getItemDetail(_slot)
- if item == nil then return true end
- local currentSelectedSlot = turtle.currentSelectedSlot()
- turtle.select(_slot)
- local potentialSpot = 0
- potentialSpot = checkForItem(item.name)
- if potentialSpot ~= 0 then
- local success = turtle.transferTo(potentialSpot)
- local itemAfterTransfer = turtle.getItemDetail()
- if success and itemAfterTransfer == nil then
- turtle.select(currentSelectedSlot)
- return true
- end
- end
- potentialSpot = checkEmptySlot()
- if potentialSpot ~= 0 then
- local success = turtle.transferTo(potentialSpot)
- if success then
- turtle.select(currentSelectedSlot)
- return true
- end
- end
- return false
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement