Griffork

MC:CC:OC:AutoBuild v0.11

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 cyjXAUyC 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. --Arrays are also apparently defined with {}
  34. levels={
  35.     {
  36.         "   ",
  37.         " x ",
  38.         "   "
  39.     },
  40.     {
  41.         "   ",
  42.         " m ",
  43.         "   "
  44.     },
  45.     {
  46.         "   ",
  47.         "   ",
  48.         "   "
  49.     }
  50. }
  51.  
  52. function moveTo(x, y, z)
  53.     repeat
  54.         if locationz < z then
  55.             if robot.up() then
  56.                 locationz=locationz+1
  57.             else
  58.                 sleep(1)
  59.             end
  60.         elseif locationz > z then
  61.             if robot.down() then
  62.                 locationz=locationz-1
  63.             else
  64.                 sleep(1)
  65.             end
  66.         end
  67.     until locationz==z
  68.     if locationy < y then
  69.         robot.turnleft()
  70.         repeat
  71.             if robot.forward() then
  72.                 locationy=locationy+1
  73.             else
  74.                 sleep(1)
  75.             end
  76.         until locationy==y
  77.         robot.turnright()
  78.     elseif locationy > y then
  79.         robot.turnright()
  80.         repeat
  81.             if robot.forward() then
  82.                 locationy=locationy-1
  83.             else
  84.                 sleep(1)
  85.             end
  86.         until locationy==y
  87.         robot.turnleft()
  88.     end
  89.     repeat
  90.         if locationx < x then
  91.             if robot.forward()
  92.                 locationx=locationx+1
  93.             else
  94.                 sleep(1)
  95.             end
  96.         elseif locationx > x then
  97.             if robot.back() then
  98.                 locationx=locationx-1
  99.             else
  100.                 sleep(1)
  101.             end
  102.         end
  103.     until locationx==x
  104. end
  105.  
  106. repeat
  107.  
  108.     moveTo(powerx, powery, powerz)
  109.     sleep(1)
  110.  
  111.     robot.turnleft()
  112.     for i=0, 64, 1 do
  113.         data = inventory.getStackInSlot(sides.front, i)
  114.         print(data.label)
  115.         for (name, label) in pairs(mats) do
  116.             if label==data.label then
  117.                 robot.select(matloc[name])
  118.                 inventory.suckFromSlot(sides.front, i)
  119.             end
  120.         end
  121.     end
  122.     robot.turnright()
  123.  
  124.     for k=#levels, 0, -1 do
  125.         moveTo(0,0,k)
  126.         for j=#levels[k], 0, -1 do
  127.             for i=string.len(levels[k][j]), 0, -1 do
  128.                 --Move 1 back because the block should be at the targeted location.
  129.                 moveTo(i,j-1,k)
  130.                 block=string.sub(levels[k][j], i, i)
  131.                 robot.select(matloc[block])
  132.                 robot.place(1)
  133.             end
  134.         end
  135.     end
  136.  
  137. until false
  138.  
Add Comment
Please, Sign In to add comment