Nancok

turtlelua

Feb 2nd, 2023 (edited)
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.41 KB | None | 0 0
  1. local slots = {1,2,3,5,6,7,9,10,11}
  2. local possibleCrafts = {"ladder","chest"}
  3.  
  4. local SlotPlank = 13
  5. local SlotStick = 14
  6.  
  7. function queryOptions()
  8.     orderItems()
  9.     listCraftings()
  10.     local itemToCraft = tonumber(read())
  11.     print("Define an amount")
  12.     local itemAmount = tonumber(read())
  13.     for i=1, itemAmount, 1 do
  14.         arrangeForItem(itemToCraft)
  15.         craftItems(1)
  16.     end
  17. end
  18.  
  19. function orderItems()
  20.     for slot=1, 16 do
  21.         turtle.select(slot)
  22.         local itemData = turtle.getItemDetail()
  23.        
  24.         if itemData ~= nil then
  25.            
  26.             if itemData.name == "minecraft:stick" then
  27.                  turtle.transferTo(SlotStick)
  28.             end
  29.             if itemData.name == "minecraft:oak_planks" then
  30.                 turtle.transferTo(SlotPlank)
  31.             end
  32.            
  33.        end
  34.        
  35.     end
  36. end
  37.  
  38.    
  39. function listCraftings()
  40.     print("Select a recipe:")
  41.     for key,value in ipairs(possibleCrafts) do
  42.         print(key," ",value)
  43.     end
  44. end
  45.  
  46. function arrangeForItem(item)
  47.     if item == 1 then
  48.         placeItem(SlotStick,slots[1])
  49.         placeItem(SlotStick,slots[3])
  50.         placeItem(SlotStick,slots[4])
  51.         placeItem(SlotPlank,slots[5])
  52.         placeItem(SlotStick,slots[6])
  53.         placeItem(SlotStick,slots[7])
  54.         placeItem(SlotStick,slots[9])
  55.     end
  56. end
  57.  
  58. function placeItem(from,to)
  59.     local originalSlot = turtle.getSelectedSlot()
  60.     turtle.select(from)
  61.     turtle.transferTo(to,1)
  62.     turtle.select(originalSlot)
  63. end
  64.  
  65. function craftItems(amount)
  66.     turtle.select(4)
  67.     turtle.craft()
  68. end
  69.    
  70.  
  71. local MaterialStick = "minecraft:stick"
  72. local MaterialPlanks = "minecraft:oak_planks"
  73. local RecipeLadder = {
  74.     MaterialSticks,"",MaterialSticks,
  75.     MaterialSticks,MaterialPlanks,MaterialSticks,
  76.     MaterialSticks,"",MaterialSticks
  77. }
  78.  
  79. function findMaterial(name)
  80.     for slot=1, 16 do
  81.             turtle.select(slot)
  82.             local itemData = turtle.getItemDetail()
  83.        
  84.             if itemData ~= nil and itemData.name == name then
  85.                 return slot
  86.             else
  87.                 return nil
  88.             end
  89.     end
  90. end
  91.  
  92. function craftFromRecipe(materialArray)
  93.     for slot=1 , #slots do
  94.         local usedMaterialSlot = findMaterial(materialArray[slot])
  95.        
  96.         if usedMaterialSlot ~= nil then
  97.             placeItem(usedMaterialSlot,slot)
  98.         end
  99.        
  100.     end
  101. end
  102.    
  103. craftFromRecipe(RecipeLadder)
Add Comment
Please, Sign In to add comment