Advertisement
Xenogami

pearls_to_diamonds1.0

Jun 13th, 2013
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.67 KB | None | 0 0
  1. m=peripheral.wrap("right")
  2. t=peripheral.wrap("top")
  3.  
  4. -- If chunk unloads or server resets, this will reorient to the proper facing and makes sure the inv is clear
  5. local function firstRun()
  6.     while turtle.detect() do
  7.         turtle.turnLeft()
  8.     end
  9.     turtle.turnRight()
  10.     for i=1,16 do
  11.         turtle.select(i)
  12.         turtle.drop()
  13.     end
  14. end
  15.  
  16. -- This is a replacement for sleep()
  17. function wait( _nsec )
  18.     local timer = os.startTimer( _nsec )
  19.     repeat
  20.         local sEvent, param = os.pullEvent("timer")
  21.     until param == timer
  22. end
  23.  
  24. -- Prints out current actin on the monitor
  25. local function monitorControl()
  26.     local t=peripheral.wrap("top")
  27.     t.setTextScale(1)
  28.     t.clear()
  29.     t.setCursorPos(x,y)
  30.     t.write(status)
  31. end
  32.      
  33. -- Pull the pearls out of the ME system. If the ME system is out of pearls it will shut down.
  34. local function getPearls()
  35.     turtle.select(1)
  36.     turtle.suck()
  37.     if turtle.getItemCount(1) < 9 then
  38.         status="Out of Pearls!"
  39.         x=2
  40.         y=1
  41.         monitorControl()
  42.         turtle.drop()
  43.         wait(30)
  44.         os.reboot()
  45.     end
  46. end
  47.      
  48. -- Convert enderpears to iron
  49. local function endtoiron()
  50.     turtle.select(1)
  51.     for a=1,8 do
  52.         wait(.5)
  53.         m.transmuteItem(1)
  54.     end
  55.     turtle.transferTo(2)
  56. end
  57.  
  58.      
  59. -- Convert iron to gold
  60. local function irontogold()
  61.     turtle.select(2)
  62.     for a=1,4 do
  63.         m.transmuteItem(8)
  64.         wait(.5)
  65.     end
  66.     turtle.select(2)
  67.     turtle.transferTo(3)
  68. end
  69.      
  70. -- Convert gold to diamonds
  71. local function goldtodia()
  72.     turtle.select(3)
  73.     m.transmuteItem(4)
  74. end
  75.      
  76. -- Pulls a fresh minium stone out of the ME system and recharges. Shuts down if there are no stones in the ME
  77. local function chargeUp()
  78.     if m.getMiniumCharge() < 25 then
  79.         turtle.turnRight()
  80.         turtle.select(1)
  81.         turtle.suck()
  82.         if turtle.getItemCount(1) < 1 then
  83.             status="Out of Minium"
  84.             x=2
  85.             y=1
  86.             monitorControl()
  87.             wait(30)
  88.             os.reboot()
  89.         end
  90.         m.rechargeMinium()
  91.         turtle.turnLeft()
  92.     end
  93. end
  94.      
  95. -- Reads the level emitters to determine what to make.
  96. local function readLevels()
  97.     mode=1
  98.     if not redstone.getInput("bottom") then
  99.         mode=2
  100.     end
  101.     if not redstone.getInput("back") then
  102.         mode=3
  103.     end
  104. end
  105.  
  106. -- Puts it all together and makes it run
  107. firstRun()    
  108. while true do
  109.     readLevels()
  110.     chargeUp()
  111.     if mode==3 then
  112.         x=2
  113.         y=1
  114.         status="Making Diamonds"
  115.         monitorControl()
  116.         getPearls()
  117.         endtoiron()
  118.         irontogold()
  119.         goldtodia()
  120.     end
  121.      
  122.     if mode==2 then
  123.         x=2
  124.         y=1
  125.         status="Making Gold"    
  126.         monitorControl()
  127.         getPearls()
  128.         endtoiron()
  129.         irontogold()
  130.     end
  131.      
  132.     if mode==1 then
  133.         x=2
  134.         y=1
  135.         status="Making Iron"
  136.         monitorControl()
  137.         getPearls()
  138.         endtoiron()
  139.     end
  140.     for a=1,4 do
  141.         turtle.select(a)
  142.         turtle.drop()
  143.     end
  144.     turtle.select(1)
  145. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement