Advertisement
imhelbling

CC Coalbot

Feb 8th, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.21 KB | None | 0 0
  1. local instructions = [[
  2. WOOD PHASE
  3.  
  4.  
  5.     fill inv with logs
  6.  
  7.     go up, up, left
  8.  
  9.     dump portion of wood into right hopper
  10.  
  11.     go left, fwd, right
  12.  
  13.     dump portion of wood into left hopper
  14.  
  15.     go down, down, right, fwd
  16.  
  17.     dump remaining wood into output
  18.  
  19.  
  20.  
  21.  
  22. COAL PHASE
  23.  
  24.  
  25.     go left
  26.  
  27.     fill inv with coal
  28.  
  29.     check own fuel level
  30.  
  31.     go left up
  32.  
  33.     refill right furnace
  34.  
  35.     go left, fwd, right
  36.  
  37.     refill left furnace
  38.  
  39.     go left, fwd, left
  40.  
  41.     put portion of fuel into collector chest
  42.  
  43.     go left, fwd, fwd, right
  44.  
  45.     put portion of fuel into harvester chest
  46.  
  47.     go left, down
  48.  
  49.     dump remaining coal into ouptut
  50.  
  51. ]]
  52. local right_hopper_portion = 28
  53. local left_hopper_portion = 28
  54. local collector_portion = 16
  55. local harvester_portion = 16
  56. local check_fuel
  57. check_fuel = function()
  58.   print("Checking fuel level...")
  59.   if turtle.getFuelLevel() < 100 then
  60.     print("Fuel low, refueling...")
  61.     turtle.refuel(10)
  62.   end
  63.   return print("Fuel level: ", turtle.getFuelLevel())
  64. end
  65. local tally_items
  66. tally_items = function()
  67.   local slot_count = turtle.getItemCount()
  68.   if slot_count == nil then
  69.     slot_count = 0
  70.   end
  71.   for i = 1, 16 do
  72.     turtle.select(i)
  73.     local tally = tally + slot_count
  74.   end
  75.   return tally
  76. end
  77. local fill_inv
  78. fill_inv = function(direction)
  79.   for i = 1, 16 do
  80.     turtle.select(i)
  81.     if direction == "up" then
  82.       turtle.suckUp()
  83.     elseif direction == "forward" then
  84.       turtle.suck()
  85.     elseif direction == "down" then
  86.       turtle.suckDown()
  87.     end
  88.   end
  89. end
  90. local portion_dump
  91. portion_dump = function(amount)
  92.   local amount_to_dump = amount
  93.   for i = 1, 16 do
  94.     turtle.select(i)
  95.     if amount_to_dump < 1 then
  96.       break
  97.     end
  98.     local slot_count = turtle.getItemCount()
  99.     if slot_count == nil then
  100.       slot_count = 0
  101.     end
  102.     if slot_count > 0 then
  103.       for i = 1, slot_count do
  104.         turtle.drop(1)
  105.         amount_to_dump = amount_to_dump - 1
  106.         if amount_to_dump < 1 then
  107.           break
  108.         end
  109.       end
  110.     end
  111.   end
  112. end
  113. local fill_furnace
  114. fill_furnace = function()
  115.   for i = 1, 16 do
  116.     turtle.select(i)
  117.     if turtle.getItemDetail == "minecraft:coal" then
  118.       turtle.drop()
  119.     end
  120.   end
  121. end
  122. local wood_phase
  123. wood_phase = function()
  124.   fill_inv("down")
  125.   local tally = tally_items()
  126.   turtle.up()
  127.   turtle.up()
  128.   turtle.turnLeft()
  129.   portion_dump((tally() * (28 / 64)))
  130.   turtle.turnLeft()
  131.   turtle.forward()
  132.   turtle.turnRight()
  133.   portion_dump((tally() * (28 / 64)))
  134.   turtle.down()
  135.   turtle.down()
  136.   turtle.turnRight()
  137.   turtle.forward()
  138.   return portion_dump((tally() * (64 / 64)))
  139. end
  140. local coal_phase
  141. coal_phase = function()
  142.   turtle.turnLeft()
  143.   fill_inv("forward")
  144.   check_fuel()
  145.   turtle.turnLeft()
  146.   turtle.up()
  147.   fill_furnace()
  148.   turtle.turnLeft()
  149.   turtle.forward()
  150.   turtle.turnRight()
  151.   fill_furnace()
  152.   local tally = tally_items()
  153.   turtle.turnLeft()
  154.   turtle.forward()
  155.   turtle.turnLeft()
  156.   portion_dump((tally() * (16 / 64)))
  157.   turtle.turnLeft()
  158.   turtle.forward()
  159.   turtle.forward()
  160.   turtle.turnRight()
  161.   portion_dump((tally() * (16 / 64)))
  162.   turtle.turnLeft()
  163.   turtle.down()
  164.   return portion_dump((tally() * (64 / 64)))
  165. end
  166. while true do
  167.   wood_phase()
  168.   coal_phase()
  169. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement