SilentWarrior

altar1

Nov 23rd, 2017
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.50 KB | None | 0 0
  1. local chest = peripheral.find('iron') --'container_chest' for wooden chests
  2. local altar = peripheral.find('tealtar')
  3.  
  4. local chestToTurtle = 'south'
  5. local altarToTurtle = 'east'
  6.  
  7. local debugEnabled = true
  8.  
  9. if not chest or not altar then
  10.   error('Setup error: Failed to find peripherals')
  11. end
  12.  
  13. local slates = {
  14.   { id = 'AWWayofTime:blankSlate', amount = 64, essence = 1000, input = 'minecraft:stone' },
  15.   { id = 'AWWayofTime:reinforcedSlate', amount = 128, essence = 2000, input = 'AWWayofTime:blankSlate' },
  16.   { id = 'AWWayofTime:imbuedSlate', amount  =  128, essence = 5000, input = 'AWWayofTime:reinforcedSlate' },
  17.   { id = 'AWWayofTime:demonicSlate', amount  =  64, essence = 15000, input = 'AWWayofTime:imbuedSlate' },
  18.   { id = 'AWWayofTime:bloodMagicBaseItems:27', amount = 64, essence = 30000, input = 'AWWayofTime:demonicSlate' }
  19. }
  20.  
  21. local orb = 'AWWayofTime:transcendentBloodOrb'
  22.  
  23. function debug(msg)
  24.   if debugEnabled then
  25.     print(msg)
  26.   end
  27. end
  28.  
  29. -- inspects the chest and returns relevant information about it's contents
  30. function getChestContents()
  31.   local contents = {}
  32.   local stacks = chest.getAllStacks()
  33.    
  34.   for i=1,chest.getInventorySize() do
  35.     local stack = stacks[i]
  36.    
  37.     if stack then
  38.       local id = idToString(stack.id, stack.dmg)
  39.      
  40.       if contents[id] then
  41.         contents[id].amount = contents[id].amount + stack.qty
  42.       else
  43.         contents[id] = { amount = stack.qty, slots={} }
  44.       end
  45.       table.insert(contents[id].slots, { slot=i, size=stack.qty })
  46.  
  47. --      debug(id .. ': ' .. contents[id].amount)
  48.     end
  49.   end
  50.  
  51.   return contents  
  52. end
  53.  
  54. function idToString(id, damage)
  55.   if not damage or damage == 0 then
  56.     return id
  57.   else
  58.     return id .. ":" .. damage
  59.   end
  60. end
  61.  
  62. function selectSlate()
  63.   local tank = altar.getTankInfo('up')[1]
  64.   local chestContents = getChestContents()
  65.  
  66.   local haveAllSlates = true
  67.  
  68.   for i, slate in ipairs(slates) do
  69.     if (not chestContents[slate.id] or chestContents[slate.id].amount < slate.amount) then
  70.       haveAllSlates = false
  71.  
  72.       if tank.amount >= slate.essence
  73.         and chestContents[slate.input] and chestContents[slate.input].amount > 0 then
  74.         return slate, chestContents[slate.input]
  75.       end
  76.     end      
  77.   end
  78.  
  79.   if haveAllSlates then
  80.     return true, chestContents[orb]
  81.   end
  82.  
  83.   return false
  84. end
  85.  
  86. function pushToAltar(slot, amount)
  87.   chest.pushItem(chestToTurtle, slot, amount or 1)
  88.   altar.pullItem(altarToTurtle, 1)
  89. end
  90.  
  91. function pushToChest()
  92.   altar.pushItem(altarToTurtle, 1)
  93.   chest.pullItem(chestToTurtle, 1)
  94. end
  95.  
  96. function waitForItem(id)
  97.   while true do
  98.     local stack = altar.getStackInSlot(1)
  99.     if stack and idToString(stack.id, stack.dmg) == id then
  100.       return
  101.     end
  102.  
  103.     sleep(1)
  104.   end
  105. end
  106.  
  107. function create(slate, input)
  108.   pushToAltar(input.slots[1].slot, 1)
  109.   pcall(waitForItem, slate.id)
  110.   pushToChest()
  111. end
  112.  
  113. while true do
  114.   if rs.getInput('bottom') then
  115.     sleep(5)
  116.   else
  117.     local selected, input = selectSlate()
  118.    
  119.     if type(selected) == 'table' and input then
  120.       pushToChest()
  121.       create(selected, input)
  122.     elseif selected then
  123.       local altarContent = altar.getStackInSlot(1)
  124.  
  125.       if input and (not altarContent or idToString(altarContent.id, altarContent.dmg) ~= orb) then
  126.         debug('All slates done, switching to orb')
  127.         pushToChest()
  128.         pushToAltar(input.slots[1].slot, 1)
  129.       end
  130.       sleep(30)
  131.     else
  132.       debug('Waiting for resources')
  133.       sleep(5)
  134.     end
  135.   end
  136. end
Add Comment
Please, Sign In to add comment