Advertisement
Guest User

fwcrafter

a guest
Feb 14th, 2016
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.04 KB | None | 0 0
  1. mats = peripheral.wrap("back")
  2. -- done = peripheral.wrap("left")
  3. shapeDone = false
  4.  
  5.  
  6. function randomInt(min,max)
  7.   return min + math.floor(math.random() * (max - min +1))
  8. end
  9.  
  10. paper = 9
  11. firstColor = 1
  12. lastColor = 8
  13. firstShape = 10
  14. lastShape = 13
  15. firstSpecial = 14
  16. lastSpecial = 15
  17. firstGunpowder = 16
  18. lastGunpowder = 19
  19.  
  20. function randomColor()
  21.   return randomInt(firstColor,lastColor)
  22. end
  23.  
  24. function randomGunpowder()
  25.   return randomInt(firstGunpowder,lastGunpowder)
  26. end
  27.  
  28. function randomShape()
  29.   return randomInt(firstShape,lastShape)
  30. end
  31.  
  32. function pull(n,optional)
  33.   if not optional and mats.getStackInSlot(n).qty == nil then
  34.     print("Refill Slot: ",n)
  35.   while mats.getStackInSlot(n).qty == nil do
  36.     sleep(3)
  37.   end
  38.   end
  39.  
  40.   os.sleep(.1)
  41.   mats.pushItem("west", n, 1)
  42. end
  43.  
  44. function pullThings(first,last,start)
  45.   start = start or 0
  46.   d = last - first
  47.   n = 2^d
  48.   r = randomInt(start,n-1)
  49.   for i = 0,d-1 do
  50.     if bit.band(r,2^i) ~= 0 then    
  51.         if first+1 < firstShape and first+i > lastShape then
  52.           pull(first+i, true)
  53.         end
  54.     end
  55.   end
  56. end
  57.  
  58. function repack()
  59.   turtle.select(4)
  60.   turtle.transferTo(9)
  61.   turtle.select(8)
  62.   turtle.transferTo(10)
  63.   turtle.select(1)
  64. end
  65.  
  66. while true do
  67. turtle.select(1)
  68.   pull(randomColor()) print("color")
  69.   pull(randomGunpowder()) print("gunpowder")
  70.   shapeNum = randomShape() print("shape")
  71.   if shapeNum ~= lastShape then
  72.     pull(shapeNum)
  73.   end
  74.   pullThings(firstSpecial,lastSpecial) print("special")
  75.   if turtle.getItemCount(2) > 1 then
  76.     turtle.select(2)
  77.     turtle.transferTo(9,1)
  78.     turtle.transferTo(10,1)
  79.     turtle.transferTo(11,1)
  80.   end
  81.   repack()
  82.   turtle.craft()
  83.   os.sleep(1)
  84.   for numGun = 1,randomInt(1,3) do
  85.     pull(randomGunpowder()) print("gunpowder")
  86.   end
  87.   pull(paper) print("paper")
  88.   repack()
  89.   if turtle.getItemCount(2) > 1 then
  90.     turtle.select(2)
  91.     turtle.transferTo(9,1)
  92.     turtle.transferTo(10,1)
  93.     turtle.transferTo(11,1)
  94.   end
  95.   turtle.craft()
  96.   turtle.drop() print("dump")
  97.   os.sleep(1)
  98. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement