Griffork

MC:CC:OC:AutoBuild v0.18

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