Keledan

Crafty Turtle

Apr 26th, 2015
994
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.97 KB | None | 0 0
  1. -- carica un materiale dalla chest
  2. -- divide per nove e restituisce nella chest quello in eccesso
  3. -- posizione 9 mucchietti nell'inventario; craft; mette il risultato nella chest
  4. -- craft negli slot: 5,6,7,9,10,11,13,14,15
  5.  
  6. craftingSlot = 13
  7.  
  8. function getFromChest(pezzi)
  9.     turtle.turnLeft()
  10.     for i = 1, 5 do
  11.         turtle.select(i)
  12.         turtle.suck()
  13.     end
  14.     turtle.turnRight() 
  15. end
  16.  
  17. function prepareCrafting(usableSlot)
  18. -- divide in mucchi multipli di 9
  19.     turtle.select(usableSlot)
  20.     pezzi = turtle.getItemCount(usableSlot)
  21.     amountCraftable = math.floor(pezzi/9)
  22.     print (amountCraftable)
  23.     turtle.transferTo(6,amountCraftable)       
  24.     turtle.transferTo(7,amountCraftable)       
  25.     turtle.transferTo(8,amountCraftable)       
  26.     turtle.transferTo(10,amountCraftable)      
  27.     turtle.transferTo(11,amountCraftable)      
  28.     turtle.transferTo(12,amountCraftable)      
  29.     turtle.transferTo(14,amountCraftable)      
  30.     turtle.transferTo(15,amountCraftable)      
  31.     turtle.transferTo(16,amountCraftable)      
  32. end
  33.  
  34. function craft()
  35.     turtle.select(craftingSlot)
  36.     turtle.craft()
  37. end
  38.  
  39. function unloadCrafted()
  40.     turtle.turnRight()
  41.     turtle.select(craftingSlot)
  42.     turtle.drop()
  43.     turtle.turnLeft()  
  44. end
  45.  
  46. function unloadRemnant()
  47.     turtle.turnLeft()
  48.     for i = 1, 5 do
  49.         turtle.select(i)
  50.         turtle.drop()
  51.     end
  52.     turtle.turnRight() 
  53. end
  54.  
  55. function craftableSlot()
  56. -- verifica quale slot ha almeno 9 oggetti. Ritorna lo slot oppure 0 se nessun slot è compatibile
  57.     for i=1, 5 do
  58.         pezzi = turtle.getItemCount(i)
  59.         if pezzi >= 9 then return (i) end
  60.     end
  61.     return 0
  62. end
  63.  
  64. while true do
  65. -- la turtle guarda il giocatore. Come prima cosa ruota a destra verso lo scrigno di carico
  66. -- prende i primi 5 stack
  67. getFromChest()
  68.  
  69. -- se ci sono almeno 9 pezzi in uno dei primi 5 slot va al crafting altrimenti rimette nella chest
  70. usableSlot = craftableSlot()
  71. if usableSlot > 0 then
  72.     prepareCrafting(usableSlot)
  73.     unloadRemnant()
  74.     craft()
  75.     unloadCrafted()
  76. else
  77.     print("Materiale insufficiente")
  78.     unloadRemnant()
  79.     sleep(17)
  80. end
  81.  
  82. end
Advertisement
Add Comment
Please, Sign In to add comment