Corbinhol

DroneSoftwar

Jun 19th, 2021 (edited)
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.92 KB | None | 0 0
  1. local drone = component.proxy(component.list("drone")());
  2. local link = component.proxy(component.list("tunnel")());
  3. local scanner = component.proxy(component.list("geolyzer")());
  4. local inv = component.proxy(component.list("inventory_controller")());
  5.  
  6. num = 0;
  7. drone.setLightColor(0x800080);
  8. version = "3.5";
  9.  
  10. xOff = 0;
  11. yOff = 0;
  12. zOff = 0;
  13.  
  14. farmW = 9;
  15. farmH = 9;
  16.  
  17. xOffTemp = 1;
  18. yOffTemp = 1;
  19.  
  20. lastCrop = "minecraft:wheat";
  21.  
  22. previousBlock = 0;
  23. function scanInventory(itemName)
  24.     for i=1, 8, 1 do
  25.         slotData = inv.getStackInInternalSlot(i);
  26.         if slotData == nil then t = 0
  27.         elseif slotData.name == itemName then return i end
  28.     end
  29. end
  30.  
  31.  
  32.  
  33. run = true;
  34. lightStartingUp = 0x2550200;
  35. lightIdle = 0x2552510;
  36. lightMoving = 0x025542;
  37.  
  38. dirX = 1;
  39. dirY = 1;
  40.  
  41. function setStatus(status)
  42.     drone.setStatusText(status);
  43. end
  44. function move(x, y, z);
  45. setColor(lightMoving);
  46. drone.move(x, y, z);
  47. xOff = xOff + x;
  48. yOff = yOff + y;
  49. zOff = zOff + z;
  50. setColor(lightIdle);
  51. end
  52.  
  53. function setColor(light)
  54. drone.setLightColor(light);
  55. end
  56.  
  57. function nextGridSpace()
  58.    
  59.     if xOffTemp < farmW then
  60.         move(dirX, 0, 0)
  61.         xOffTemp = xOffTemp + 1;
  62.     elseif xOffTemp == farmW then
  63.         if yOffTemp == 9 then
  64.         dirY = dirY * -1;
  65.         dirX = dirX * -1;
  66.         yOffTemp = 1;
  67.         xOffTemp = 1;
  68.         else
  69.         move(0, 0, dirY);
  70.         yOffTemp = yOffTemp + 1;
  71.         xOffTemp = 1;
  72.         dirX = dirX * -1;
  73.         end
  74. end
  75. end
  76.  
  77. function scan()
  78.     data = scanner.analyze(0);
  79.     if data.name == "minecraft:air" then t = 0
  80.     else lastCrop = data.name;
  81.     end
  82.     return data.growth;
  83. end
  84.  
  85. function wait(freq)
  86. computer.pullSignal(freq);
  87. end
  88. move(0, 1, 0)
  89. link.send("CONNECTED");
  90.  
  91. function plantSeeds()
  92.     if lastCrop == "minecraft:wheat" then place("minecraft:wheat_seeds")
  93.     elseif lastCrop == "minecraft:potatoes" then place("minecraft:potato")
  94.     elseif lastCrop == "minecraft:carrots" then place("minecraft:carrot");
  95.     end
  96. end
  97.  
  98. function place(item)
  99.     drone.select(scanInventory(item))
  100.     drone.place(0);
  101.     drone.select(1);
  102. end
  103.  
  104. function collect()
  105.     for i=0, 5, 1 do
  106.         drone.suck(i);
  107.     end
  108. end
  109.  
  110. function harvest()
  111.     drone.swing(0);
  112.     collect();
  113. end
  114.  
  115. function checkBlock()
  116.     data = scanner.analyze(0);
  117.     name = data.name;
  118.     if name ~= "minecraft:water" then
  119.     move(0, -1, 0)
  120.     drone.place(0);
  121.     wait(.5);
  122.     move(0, 1, 0);
  123.     wait(.3)
  124.     plantSeeds();
  125.     wait(.5)
  126.     else move(0, 1, 0);
  127.     end
  128. end
  129.  
  130. function storeItems()
  131.     side = 0;
  132.     for i=0, 5, 1 do
  133.         block = scanner.analyze(i)
  134.         if block.name == "minecraft:chest" then
  135.         side = i;
  136.         break;
  137.         end
  138.     end
  139.    
  140.     for i=2, 8, 1 do
  141.         drone.select(i)
  142.         drone.drop(side);
  143.     end
  144.     drone.select(1);
  145. end
  146. function recharge()
  147.     storeItems();
  148.     setStatus("RECHARGING");
  149.     wait(5);
  150. end
  151.  
  152. while run == true do
  153.     grow = scan();
  154.     if grow == nil then checkBlock();
  155.     elseif grow == 1 then
  156.     harvest();
  157.     plantSeeds();
  158.     end;
  159.     if yOffTemp == 9 and xOffTemp == 9 then
  160.         recharge();
  161.     end
  162.     wait(.5);
  163.     setStatus(lastCrop);
  164.     nextGridSpace();
  165. end
  166.  
  167.  
Add Comment
Please, Sign In to add comment