Advertisement
Guest User

craft

a guest
Oct 11th, 2012
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.13 KB | None | 0 0
  1. itemList={} --table of item locations, you'll want to edit this to fit your layout
  2. itemList[1]={glass=1 , sandstone2=2 , sandstone3=3 , sapling=4 , sapling2=5 , sapling3=6 , sapling4=7 , obsidian=8 }
  3. itemList[2]={flint=1 ,coal=2 ,reed=3 ,stick=4 ,cactus=5 ,glowstone=6 ,netherack=7 ,soulsand=8 }
  4. itemList[3]={saltpeter=1 ,sulfur=2 ,copper=3 ,tin=4 ,apatite=5 ,netherbrick=6 ,gold=7 ,grassblock=8 }
  5. itemList[4]={charcoal=1 ,emerald=2 ,stonebrick=3 ,mossystonebrick=4 ,crackedstonebrick=5 ,stone=6 ,mossycobble=7 ,woodenplanks=8 }
  6. itemList[5]={wood=1 ,iron=2 ,sand=3 ,gravel=4 ,sandstone=5 ,redstone=6 ,diamond=7 ,lapis=8 }
  7. itemList[6]={wood2=1 ,wood3=2 ,wood4=3 ,woodenplanks4=4 ,woodenplanks3=5 ,woodenplanks2=6 ,dirt=7 ,cobble=8 }
  8.  
  9. Recipe={ --these are the recipes, add your own using this formula, where the number is slot number. If a slot should be empty, use "air"
  10.     furnace = {
  11.         [1] = "cobble" ,
  12.         [2] = "cobble" ,
  13.         [3] = "cobble" ,
  14.         [5] = "cobble" ,
  15.         [6] = "air" ,
  16.         [7] = "cobble" ,
  17.         [9] = "cobble" ,
  18.         [10] = "cobble" ,
  19.         [11] = "cobble"
  20.     },
  21.     diamond_pick = {
  22.         [1] = "diamond" ,
  23.         [2] = "diamond" ,
  24.         [3] = "diamond" ,
  25.         [5] = "air" ,
  26.         [6] = "stick" ,
  27.         [7] = "air" ,
  28.         [9] = "air" ,
  29.         [10] = "stick" ,
  30.         [11] = "air"
  31.     },
  32.     piston = {
  33.         [1] = "woodenplanks" ,
  34.         [2] = "woodenplanks" ,
  35.         [3] = "woodenplanks" ,
  36.         [5] = "cobble" ,
  37.         [6] = "iron" ,
  38.         [7] = "cobble" ,
  39.         [9] = "cobble" ,
  40.         [10] = "redstone" ,
  41.         [11] = "cobble"
  42.     },
  43.     chest = {
  44.         [1] = "woodenplanks" ,
  45.         [2] = "woodenplanks" ,
  46.         [3] = "woodenplanks" ,
  47.         [5] = "woodenplanks" ,
  48.         [6] = "air" ,
  49.         [7] = "woodenplanks" ,
  50.         [9] = "woodenplanks" ,
  51.         [10] = "woodenplanks" ,
  52.         [11] = "woodenplanks"
  53.     },
  54.     iron_pick = { --no spaces!
  55.         [1] = "iron" ,
  56.         [2] = "iron" ,
  57.         [3] = "iron" ,
  58.         [5] = "air" ,
  59.         [6] = "stick" ,
  60.         [7] = "air" ,
  61.         [9] = "air" ,
  62.         [10] = "stick" ,
  63.         [11] = "air"
  64.     },
  65.     stone_pick = {
  66.         [1] = "cobble" ,
  67.         [2] = "cobble" ,
  68.         [3] = "cobble" ,
  69.         [5] = "air" ,
  70.         [6] = "stick" ,
  71.         [7] = "air" ,
  72.         [9] = "air" ,
  73.         [10] = "stick" ,
  74.         [11] = "air"
  75.     },
  76.     torch = {
  77.         [1] = "air" ,
  78.         [2] = "air" ,
  79.         [3] = "air" ,
  80.         [5] = "air" ,
  81.         [6] = "coal" ,
  82.         [7] = "air" ,
  83.         [9] = "air" ,
  84.         [10] = "stick" ,
  85.         [11] = "air"
  86.     }
  87. }
  88.  
  89. local args={ ... } --gets and sets inputs
  90. local input=args[1]
  91. local amount=args[2] --might not use
  92. if amount==nil then --defaults to 1 if no number entered (you can change if you want)
  93.     amount=1
  94.     print("No amount given. Defaulting to "..amount)
  95. end
  96.  
  97. local xpos=8 --sets default position
  98. local ypos=6
  99. turtle.forward() --gets in place
  100. turtle.forward()
  101. turtle.turnRight()
  102.  
  103. function GoTo(items) --goes to items location
  104.     if items~=nil then
  105.         for i=1,6 do
  106.             if itemList[i][items]~=nil then --sets x and y depending on the item inputted
  107.                 x=itemList[i][items]
  108.                 y=i
  109.             end
  110.         end
  111.         if x==nil then x=xpos end --these make it so the turtle will stay put if it doesn't understand
  112.         if y==nil then y=ypos end
  113.         turtle.turnRight()
  114.         while x>xpos do --these loops will get the turtle to the right location
  115.             turtle.forward()
  116.             xpos=xpos+1
  117.         end
  118.         while xpos>x do
  119.             turtle.back()
  120.             xpos=xpos-1
  121.         end
  122.         while ypos>y do
  123.             turtle.up()
  124.             ypos=ypos-1
  125.         end
  126.         while y>ypos do
  127.             turtle.down()
  128.             ypos=ypos+1
  129.         end
  130.         turtle.turnLeft()
  131.     end
  132. end
  133.  
  134. function Retrieve(x) --grabs the correct amount of items
  135.     turtle.suck()
  136.     if turtle.getItemCount(x)-amount <=0 then
  137.         turtle.suck()
  138.     end
  139.     turtle.drop(turtle.getItemCount(x)-amount)
  140. end
  141.  
  142. function Decode() --does the work
  143.     for i=1,3 do --goes through each slot and grabs neccisary items
  144.         if Recipe[input][i] ~="air" then
  145.             turtle.select(i)
  146.             GoTo(Recipe[input][i])
  147.             Retrieve(i)
  148.         end
  149.     end
  150.     for i=5,7 do
  151.         if Recipe[input][i] ~="air" then
  152.             turtle.select(i)
  153.             GoTo(Recipe[input][i])
  154.             Retrieve(i)
  155.         end
  156.     end
  157.     for i=9,11 do
  158.         if Recipe[input][i] ~="air" then
  159.             turtle.select(i)
  160.             GoTo(Recipe[input][i])
  161.             Retrieve(i)
  162.         end
  163.     end
  164. end
  165.  
  166. Decode()
  167. turtle.craft()
  168.  
  169. GoTo("cobble") --goes back to beginning and drops left
  170. turtle.turnLeft()
  171. turtle.back()
  172. turtle.back()
  173. turtle.turnLeft()
  174. turtle.drop()
  175. turtle.turnRight()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement