Robear9992

Wither Builder - OpenComputers

Apr 28th, 2018
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.55 KB | None | 0 0
  1. --Bootstrap
  2. --[[
  3. package.loaded.inventory = nil
  4. package.loaded.nav = nil
  5. package.loaded.status = nil
  6. package.loaded.coord = nil
  7.  
  8. os.execute("pastebin get -f ntSeKmpP coord.lua")
  9. os.execute("pastebin get -f vdUzxZT3 nav.lua")
  10. os.execute("pastebin get -f 0W0MeXti inventory.lua")
  11. os.execute("pastebin get -f 4ZnZ2iXE status.lua")
  12.  
  13. os.execute("pastebin get -f Xe3EHF5u wither.lua")
  14.  
  15. io.write("Done")
  16. --]]
  17.  
  18. local inv = require("inventory")
  19. local sides = require("sides")
  20. local status = require("status")
  21. local nav = require("nav")
  22. local robot = require("robot")
  23.  
  24.  
  25. local SAND = { name = "minecraft:soul_sand", id = 88 }
  26. local SKULL = { name = "minecraft:skull", id = 397, damage = 1 }
  27.  
  28. local function abort(reason)
  29.     io.write(reason.."\n")
  30.     os.exit()
  31. end
  32.  
  33. local function err(reason)
  34.     io.write(reason.."\n")
  35.     return false, reason
  36. end
  37.  
  38. --Config
  39. local distanceForward = 6
  40. local timeBetweenSummons = 12 --seconds
  41. local timeBetweenStockCheck = 1 --seconds
  42.  
  43.  
  44. --State
  45. local lastSummon = 0
  46. local lastStock = 0
  47.  
  48. --Init
  49. local chest = inv.getExternal(sides.bottom)
  50. if chest == nil then abort("A chest below the robot is required to start") end
  51. nav.setHome()
  52. status.set("Initializing")
  53.  
  54.  
  55. --Functions
  56. function wait()
  57.     local timeSinceLastSummon = os.time() - lastSummon
  58.     local timeSinceLastStock = os.time() - lastStock
  59.  
  60.     if timeSinceLastStock > timeBetweenStockCheck and timeSinceLastSummon > timeBetweenSummons then return end
  61.     os.sleep(timeBetweenStockCheck)
  62. end
  63.  
  64. function stock()
  65.     robot.select(1)
  66.     lastStock = os.time()
  67.     inv.stock(sides.bottom, SAND, 4)
  68.     inv.stock(sides.bottom, SKULL, 3)
  69.  
  70.     if      inv.count(SAND) < 4     then status.set("Not enough Soul Sand")
  71.     elseif  inv.count(SKULL) < 3    then status.set("Not enough Wither Skeleton Skulls")
  72.     else    return true end
  73.  
  74.     return false
  75. end
  76.  
  77. --Hack cuz angel upgrade is broken
  78. function place()
  79.     for i=1,distanceForward do
  80.         nav.forward()
  81.     end
  82.     nav.down()
  83.  
  84.     inv.select(SAND)
  85.     robot.placeDown()
  86.     nav.up()
  87.  
  88.     robot.placeDown()
  89.     nav.forward()
  90.     robot.placeDown()
  91.  
  92.     inv.select(SKULL)
  93.     robot.back()
  94.     robot.place()
  95.     robot.back()
  96.     robot.place()
  97.  
  98.     inv.select(SAND)
  99.     robot.placeDown()
  100.     robot.back()
  101.  
  102.     inv.select(SKULL)
  103.     robot.place()
  104.     for i=1,distanceForward-2 do
  105.         robot.back()
  106.     end
  107.     lastSummon = os.time()
  108. end
  109.  
  110. repeat
  111.     if stock() then
  112.         status.set("Making withers")
  113.         wait()
  114.         place()
  115.     else
  116.         wait()
  117.     end
  118. until false
Add Comment
Please, Sign In to add comment