Griffork

MC:CC:OC:AutoBuild v0.19

Oct 8th, 2020
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.36 KB | None | 0 0
  1. local robot = require("robot");
  2. local component = require("component")
  3. local sides = require("sides")
  4. --local inventory = component.proxy("inventory_controller")
  5. local inventory = component.inventory_controller
  6. local os = require("os")
  7.  
  8. --wget https://gist.githubusercontent.com/Fingercomp/6563c64d70a4472f26923f78d77caeb9/raw/aa4f461ddee2af70a8040065be8974069e240e27/crash.lua /usr/bin/crash.lua
  9. --pastebin get [-f] <pastebin code> AutoBuild -- without path it will store the file in the current work directory
  10. --pastebin get -f 2fEiNSNA AutoBuild
  11.  
  12. title=CompactMachineStuffs
  13. author=Griffork
  14. mats={
  15.     x="blockIron",
  16.     r="blockRedstone",
  17.     m="dustRedstone",
  18. }
  19. matloc={
  20.     x=1,
  21.     r=2,
  22.     m=3
  23. }
  24. --Size of the space we can build in, probably unused.
  25. spacex=3
  26. spacey=3
  27. spacez=3
  28. --Location of the power slot.
  29. powerx=-3
  30. powery=3
  31. powerz=1
  32. --Location of the robot.
  33. locationx=powerx
  34. locationy=powery
  35. locationz=powerz
  36.  
  37. --Arrays are also apparently defined with {}
  38. levels={
  39.     {
  40.         "   ",
  41.         " x ",
  42.         "   "
  43.     },
  44.     {
  45.         "   ",
  46.         " m ",
  47.         "   "
  48.     },
  49.     {
  50.         "   ",
  51.         "   ",
  52.         "   "
  53.     }
  54. }
  55.  
  56. function moveTo(x, y, z)
  57.     repeat
  58.         if locationz < z then
  59.             if robot.up() then
  60.                 locationz=locationz+1
  61.             else
  62.                 os.sleep(1)
  63.             end
  64.         elseif locationz > z then
  65.             if robot.down() then
  66.                 locationz=locationz-1
  67.             else
  68.                 os.sleep(1)
  69.             end
  70.         end
  71.     until locationz==z
  72.     if locationy < y then
  73.         robot.turnLeft()
  74.         repeat
  75.             if robot.forward() then
  76.                 locationy=locationy+1
  77.             else
  78.                 os.sleep(1)
  79.             end
  80.         until locationy==y
  81.         robot.turnRight()
  82.     elseif locationy > y then
  83.         robot.turnRight()
  84.         repeat
  85.             if robot.forward() then
  86.                 locationy=locationy-1
  87.             else
  88.                 os.sleep(1)
  89.             end
  90.         until locationy==y
  91.         robot.turnLeft()
  92.     end
  93.     repeat
  94.         if locationx < x then
  95.             if robot.forward() then
  96.                 locationx=locationx+1
  97.             else
  98.                 os.sleep(1)
  99.             end
  100.         elseif locationx > x then
  101.             if robot.back() then
  102.                 locationx=locationx-1
  103.             else
  104.                 os.sleep(1)
  105.             end
  106.         end
  107.     until locationx==x
  108. end
  109.  
  110. repeat
  111.  
  112.     moveTo(powerx, powery, powerz)
  113.     os.sleep(1)
  114.  
  115.     robot.turnLeft()
  116.     for i=0, 64, 1 do
  117.         data = inventory.getStackInSlot(sides.front, i)
  118.         print(data.label)
  119.         for name, label in pairs(mats) do
  120.             if label==data.label then
  121.                 robot.select(matloc[name])
  122.                 inventory.suckFromSlot(sides.front, i)
  123.             end
  124.         end
  125.     end
  126.     robot.turnRight()
  127.  
  128.     for k=#levels, 0, -1 do
  129.         moveTo(0,0,k)
  130.         for j=#levels[k], 0, -1 do
  131.             for i=string.len(levels[k][j]), 0, -1 do
  132.                 --Move 1 back because the block should be at the targeted location.
  133.                 moveTo(i,j-1,k)
  134.                 block=string.sub(levels[k][j], i, i)
  135.                 robot.select(matloc[block])
  136.                 robot.place(1)
  137.             end
  138.         end
  139.     end
  140.  
  141. until false
  142.  
Add Comment
Please, Sign In to add comment