Griffork

MC:CC:OC:AutoBuild v0.1

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