Griffork

MC:CC:OC:AutoBuild v0.15

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