Griffork

MC:CC:OC:AutoBuild v0.6

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