Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.14 KB | None | 0 0
  1. function getItemList ()
  2.  
  3.     local itemList = {}
  4.  
  5.     for i = 1, 16, 1 do
  6.         itemList[i] = turtle.getItemDetail(i)
  7.     end
  8.  
  9.     return itemList
  10.  
  11. end
  12.  
  13. function checkSlot ( _item, _slot )
  14.  
  15.     if type(_item) ~= "string" then
  16.         print("Invalid item")
  17.         return nil
  18.     end
  19.     if type(_slot) ~= "number" or _slot < 1 or _slot > 16 then
  20.         print("Invalid slot")
  21.         return nil
  22.     end
  23.  
  24.     local item = turtle.getItemDetail(_slot)
  25.     if item ~= nil then
  26.         return item.name == _item
  27.     else
  28.         return false
  29.     end
  30.  
  31. end
  32.  
  33. function checkEmptySlot ()
  34.  
  35.     local itemList = getItemList()
  36.     local emptySlot = 0
  37.  
  38.     for i = 1, 16, 1 do
  39.         if itemList[i] == nil then
  40.             emptySlot = i
  41.             break
  42.         end
  43.     end
  44.  
  45.     return emptySlot
  46.  
  47. end
  48.  
  49.  
  50. function checkForItem ( _item )
  51.  
  52.     local itemSlot = 0
  53.  
  54.     for i = 1, 16, 1 do
  55.         if checkSlot(_item, i) then
  56.             itemSlot = i
  57.             break
  58.         end
  59.     end
  60.  
  61. end
  62.  
  63. function dropIfItems ( _itemList, _slot )
  64.  
  65.     local currentSelectedSlot = turtle.currentSelectedSlot()
  66.     local currentItem = turtle.getItemDetail(_slot)
  67.     local itemFound = false
  68.  
  69.     if currentItem == nil then return true end
  70.  
  71.     for i = 1, #_itemList, 1 do
  72.         if _itemList[i] == currentItem.name then
  73.             itemFound = true
  74.             break
  75.         end
  76.     end
  77.  
  78.     if itemFound = false then return true end
  79.  
  80.     turtle.select(_slot)
  81.     local success = turtle.dropDown()
  82.     turtle.select(currentSelectedSlot)
  83.     return success
  84.  
  85. end
  86.  
  87. function moveItem ( _slot )
  88.  
  89.     local item = turtle.getItemDetail(_slot)
  90.     if item == nil then return true end
  91.  
  92.     local currentSelectedSlot = turtle.currentSelectedSlot()
  93.     turtle.select(_slot)
  94.     local potentialSpot = 0
  95.  
  96.     potentialSpot = checkForItem(item.name)
  97.  
  98.     if potentialSpot ~= 0 then
  99.         local success = turtle.transferTo(potentialSpot)
  100.         local itemAfterTransfer = turtle.getItemDetail()
  101.  
  102.         if success and itemAfterTransfer == nil then
  103.             turtle.select(currentSelectedSlot)
  104.             return true
  105.         end
  106.     end
  107.  
  108.     potentialSpot = checkEmptySlot()
  109.  
  110.     if potentialSpot ~= 0 then
  111.         local success = turtle.transferTo(potentialSpot)
  112.  
  113.         if success then
  114.             turtle.select(currentSelectedSlot)
  115.             return true
  116.         end
  117.     end
  118.  
  119.     return false
  120.  
  121. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement