SythsGod

Turtle_Altar

Mar 24th, 2020
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local slates = {Blank, Reinforced, Imbued, Demonic, Ethereal}
  2. local stoneAmount = 0
  3. local slatesAmount = {}
  4. local waitingTimes = {13, 0, 0, 0, 0}
  5. local defaultSlot = 16
  6. local fuelUse = 15
  7.  
  8. function init()
  9.     -- count stone
  10.     stone = turtle.getItemCount(9)
  11.    
  12.     -- count slates
  13.     for i = 0, 4 do
  14.         slatesAmount[i] = turtle.getItemCount(i + 1)
  15.     end
  16.    
  17.     -- open rednet
  18.     rednet.open("right")
  19. end
  20.  
  21. function getStone(amount)
  22.     turtle.select(9)
  23.     turtle.down()
  24.     turtle.turnLeft()
  25.     turtle.forward()
  26.     turtle.forward()
  27.     turtle.suckUp(amount)
  28.     turtle.back()
  29.     turtle.back()
  30.     turtle.up()
  31.     turtle.turnRight()
  32.    
  33.     selectDefault()
  34. end
  35.  
  36. function selectDefault()
  37.     turtle.select(defaultSlot)
  38. end
  39.  
  40. function makeSlate(amount, wait, type)
  41.     if stoneAmount < amount then
  42.         getStone(amount - stoneAmount)
  43.     end
  44.    
  45.     term.clear()
  46.     term.setCursorPos(1,1)
  47.    
  48.     for i = 1, amount do
  49.         -- select stone
  50.         turtle.select(9)
  51.         turtle.dropUp(1)
  52.        
  53.         for j = 0, wait - 1 do
  54.             term.clear()
  55.             term.setCursorPos(1,1)
  56.             term.write("Making slate #" .. tostring(i))
  57.             term.setCursorPos(1,2)
  58.             term.write("Waiting: " .. tostring(wait - j))
  59.             os.sleep(1)
  60.         end
  61.        
  62.         turtle.select(type)
  63.         turtle.suckUp()
  64.         selectDefault()
  65.     end
  66. end
  67.  
  68. function dropOff()
  69.     -- move to position
  70.     turtle.down()
  71.     turtle.turnRight()
  72.     turtle.forward()
  73.     turtle.forward()
  74.    
  75.     -- drop off items
  76.     for i = 1, 5 do
  77.         turtle.select(i)
  78.         turtle.dropUp()
  79.     end
  80.    
  81.     -- move back
  82.     turtle.back()
  83.     turtle.back()
  84.     turtle.turnLeft()
  85.     turtle.up()
  86. end
  87.  
  88. function checkFuel()
  89.     return turtle.getFuelLevel() >= fuelUse
  90. end
  91.  
  92. init()
  93.  
  94. while true do
  95.     term.write("Waiting on message...")
  96.     id, msg, prot = rednet.receive("bloodaltar")
  97.     term.clear()
  98.     term.setCursorPos(1,1)
  99.     term.write("Message received, executing...")
  100.          
  101.     if checkFuel() then  
  102.         local amountToMake = tonumber(msg[0])
  103.         local slateToMake = msg[1]
  104.         local timerToWait = waitingTimes[msg[1]]
  105.        
  106.         stoneAmount = turtle.getItemCount(9)
  107.         makeSlate(amountToMake, timerToWait, slateToMake)
  108.    
  109.         item = turtle.getItemCount(slateToMake)
  110.         if item == amountToMake then
  111.             rednet.broadcast("succes", "bloodaltar")
  112.             dropOff()
  113.         else
  114.             rednet.broadcast("failure", "bloodaltar")
  115.         end  
  116.     else
  117.         rednet.broadcast("no_fuel", "bloodaltar")
  118.     end
  119.    
  120.     term.clear()
  121.     term.setCursorPos(1,1)
  122. end
Add Comment
Please, Sign In to add comment