Advertisement
hoblin

Railbed crafter

Jan 1st, 2013
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.77 KB | None | 0 0
  1. -- -----------------------------
  2. -- Railbed crafter
  3. -- pastebin get k3vJG3ED startup
  4. -- -----------------------------
  5.  
  6. DEBUG = false
  7.  
  8. function log( message )
  9.   if DEBUG then
  10.     print(message)
  11.   end
  12. end
  13.  
  14. function toStartPosition(  )
  15.   while turtle.detect() do
  16.     turtle.turnLeft()
  17.   end
  18.   log('Start position')
  19. end
  20.  
  21. function suckFrom( direction )
  22.   log('suckFrom '..direction)
  23.   sucked = false
  24.   while not sucked do
  25.     if direction == 'front' then
  26.       sucked = turtle.suck()
  27.     elseif direction == 'down' then
  28.       sucked = turtle.suckDown()
  29.     elseif direction == 'up' then
  30.       sucked = turtle.suckUp()
  31.     end
  32.     if not sucked then
  33.       sleep(15)
  34.     end
  35.   end
  36.   log('suck done')
  37. end
  38.  
  39. function dropTo( direction, amount )
  40.   log('dropTo '..direction)
  41.   amount = amount or 64
  42.   dropped = false
  43.   while not dropped do
  44.     if direction == 'front' then
  45.       dropped = turtle.drop(amount)
  46.     elseif direction == 'down' then
  47.       dropped = turtle.dropDown(amount)
  48.     elseif direction == 'up' then
  49.       dropped = turtle.dropUp(amount)
  50.     end
  51.     if not dropped then
  52.       sleep(15)
  53.     end
  54.   end
  55.   log('drop done')
  56. end
  57.  
  58. function compressChest()
  59.   log('compressChest')
  60.   turtle.select(13)
  61.   turtle.suck()
  62.   turtle.suck()
  63.   turtle.drop()
  64.   turtle.select(14)
  65.   turtle.drop()
  66.   log('compress done')
  67. end
  68.  
  69. function suckAmount( slot_num, amount, direction )
  70.   log('suckAmount '..direction)
  71.   compressChest()
  72.   turtle.select(slot_num)
  73.   suckFrom(direction)
  74.   while turtle.getItemCount(slot_num) < amount do
  75.     turtle.drop()
  76.     sleep(15)
  77.     suckFrom(direction)
  78.   end
  79.   if turtle.getItemCount(slot_num) > amount then
  80.     dropTo(direction, turtle.getItemCount(slot_num) - amount)
  81.   end
  82.   log('suck amount done')
  83. end
  84.  
  85. toStartPosition()
  86. rs.setOutput('bottom', false)
  87. for n=1,16 do
  88.   turtle.select(n)
  89.   turtle.drop()
  90. end
  91. turtle.turnLeft()
  92.  
  93. while true do
  94.   -- Craft planks
  95.   log('Craft planks')
  96.   suckAmount(1, 3, 'front')
  97.   turtle.craft()
  98.   turtle.turnLeft()
  99.   dropTo('front', 12)
  100.   -- Craft half-blocks
  101.   log('Craft half-blocks')
  102.   suckAmount(1, 4, 'front')
  103.   suckAmount(2, 4, 'front')
  104.   suckAmount(3, 4, 'front')
  105.   turtle.select(4)
  106.   turtle.craft()
  107.   dropTo( 'front', 24 )
  108.   -- Craft tie
  109.   log('Craft tie')
  110.   suckAmount(5, 8, 'front')
  111.   suckAmount(6, 8, 'front')
  112.   suckAmount(7, 8, 'front')
  113.   for i=1,8 do
  114.     suckAmount(2, 1, 'up')
  115.     turtle.select(1)
  116.     turtle.craft()
  117.     dropTo('front', 1)
  118.     turtle.select(2)
  119.     turtle.turnLeft()
  120.     dropTo( 'front', 1 )
  121.     turtle.turnRight()
  122.   end
  123.   -- Craft railbed
  124.   log('Craft railbed')
  125.   suckAmount(1, 2, 'front')
  126.   suckAmount(2, 2, 'front')
  127.   suckAmount(5, 2, 'front')
  128.   suckAmount(6, 2, 'front')
  129.   turtle.craft()
  130.   turtle.dropDown()
  131.   turtle.turnRight()
  132. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement