Advertisement
Myros27

Treefeller

Feb 27th, 2021 (edited)
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.07 KB | None | 0 0
  1. local link = "wget -f https://pastebin.com/raw/ Treefeller.lua"
  2. local robot = require("robot")
  3. local term = require("term")
  4. local computer = require("computer")
  5. local component = require("component")
  6. local sides = require("sides")
  7. local keyboard = require("keyboard")
  8.  
  9. robot.select(1);
  10. lastExp = 0;
  11. maxbatt = 100000;
  12.  
  13. file = io.open("quant", "r");
  14. io.input(file);
  15. treeFeller = io.read();
  16. io.close(file);
  17.  
  18. local function printStuff()
  19.     local double expdouble = component.experience.level();
  20.     exp = string.format("%.4f",expdouble);
  21.     local double diff = expdouble - lastExp;
  22.     felled = string.format("%.0f",treeFeller);
  23.     lastExp = expdouble;
  24.     diffExp = string.format("%.8f",diff);
  25.     term.clear();
  26.     print("I have " .. exp .. " Exp.\nThats " .. diffExp .. " more than last time.\nI planted " .. felled .. " Crops.");
  27.     component.sign.setValue("I have\n" .. exp .. " Exp.\nI planted\n" .. felled .. " Crops.");
  28.     file = io.open("quant", "wb");
  29.     io.output(file);
  30.     io.write(treeFeller);
  31.     io.close(file);
  32. end
  33.  
  34. local function errorStuff(err)
  35.     print(err);
  36. end
  37.  
  38. local function updateStuff()
  39.     error = xpcall(printStuff, errorStuff);
  40.     while (error == false) do
  41.         os.sleep(1);
  42.         error = xpcall(printStuff, errorStuff);
  43.     end
  44. end
  45.  
  46. local function checkCorrect()
  47.     x, y, z = component.navigation.getPosition();
  48.     if ( x == -7.5 and y == 65.5 and z == -24.5) then
  49.         result = true;
  50.     else
  51.         result = false;
  52.     end
  53.     return result;
  54. end
  55.  
  56. local function sucky()
  57.     component.tractor_beam.suck()
  58.     while (component.tractor_beam.suck()) do
  59.         component.tractor_beam.suck();
  60.         end
  61. end
  62.  
  63. local function gotoX(arg)
  64.     x, y, z = component.navigation.getPosition();
  65.     if ( x >= arg ) then
  66.         while ( x > arg ) do
  67.             while ( component.navigation.getFacing() ~= 4 ) do
  68.                 robot.turnLeft();
  69.             end
  70.             robot.forward();
  71.             x, y, z = component.navigation.getPosition();
  72.         end
  73.     else
  74.         while ( x < arg ) do
  75.             while ( component.navigation.getFacing() ~= 5 ) do
  76.                 robot.turnLeft();
  77.             end
  78.             robot.forward();
  79.             x, y, z = component.navigation.getPosition();
  80.         end
  81.     end
  82. end
  83.  
  84. local function gotoY(arg)
  85.     x, y, z = component.navigation.getPosition();
  86.     if ( y >= arg ) then
  87.         while ( y > arg ) do
  88.             robot.down();
  89.             x, y, z = component.navigation.getPosition();
  90.         end
  91.     else
  92.         while ( y < arg ) do
  93.             robot.up();
  94.             x, y, z = component.navigation.getPosition();
  95.         end
  96.     end
  97. end
  98.  
  99. local function gotoZ(arg)
  100.     x, y, z = component.navigation.getPosition();
  101.     if ( z >= arg ) then
  102.         while ( z > arg ) do
  103.             while ( component.navigation.getFacing() ~= 2 ) do
  104.                 robot.turnLeft();
  105.             end
  106.             robot.forward();
  107.             x, y, z = component.navigation.getPosition();
  108.         end
  109.     else
  110.         while ( z < arg ) do
  111.             while ( component.navigation.getFacing() ~= 3 ) do
  112.                 robot.turnLeft();
  113.             end
  114.             robot.forward();
  115.             x, y, z = component.navigation.getPosition();
  116.         end
  117.     end
  118. end
  119.  
  120. local function breaktoX(arg)
  121.     x, y, z = component.navigation.getPosition();
  122.     if ( x >= arg ) then
  123.         while ( x > arg ) do
  124.             while ( component.navigation.getFacing() ~= 4 ) do
  125.                 robot.turnLeft();
  126.             end
  127.             robot.swing()
  128.             sucky()
  129.             robot.forward();
  130.             x, y, z = component.navigation.getPosition();
  131.         end
  132.     else
  133.         while ( x < arg ) do
  134.             while ( component.navigation.getFacing() ~= 5 ) do
  135.                 robot.turnLeft();
  136.             end
  137.             robot.swing()
  138.             sucky()
  139.             robot.forward();
  140.             x, y, z = component.navigation.getPosition();
  141.         end
  142.     end
  143. end
  144.  
  145. local function breaktoY(arg)
  146.     x, y, z = component.navigation.getPosition();
  147.     if ( y >= arg ) then
  148.         while ( y > arg ) do
  149.             robot.swingDown()
  150.             robot.down();
  151.             x, y, z = component.navigation.getPosition();
  152.         end
  153.     else
  154.         while ( y < arg ) do
  155.             robot.swingUp()
  156.             robot.up();
  157.             x, y, z = component.navigation.getPosition();
  158.         end
  159.     end
  160. end
  161.  
  162. local function breaktoZ(arg)
  163.     x, y, z = component.navigation.getPosition();
  164.     if ( z >= arg ) then
  165.         while ( z > arg ) do
  166.             while ( component.navigation.getFacing() ~= 2 ) do
  167.                 robot.turnLeft();
  168.             end
  169.             robot.swing()
  170.             sucky()
  171.             robot.forward();
  172.             x, y, z = component.navigation.getPosition();
  173.         end
  174.     else
  175.         while ( z < arg ) do
  176.             while ( component.navigation.getFacing() ~= 3 ) do
  177.                 robot.turnLeft();
  178.             end
  179.             robot.swing()
  180.             sucky()
  181.             robot.forward();
  182.             x, y, z = component.navigation.getPosition();
  183.         end
  184.     end
  185. end
  186.  
  187. local function farmtoZ(arg)
  188.     x, y, z = component.navigation.getPosition();
  189.     if ( z >= arg ) then
  190.         while ( z > arg ) do
  191.             while ( component.navigation.getFacing() ~= 2 ) do
  192.                 robot.turnLeft();
  193.             end
  194.             treeFeller = treeFeller + 1 ;
  195.             robot.useDown()
  196.             sucky()
  197.             robot.forward();
  198.             x, y, z = component.navigation.getPosition();
  199.         end
  200.     else
  201.         while ( z < arg ) do
  202.             while ( component.navigation.getFacing() ~= 3 ) do
  203.                 robot.turnLeft();
  204.             end
  205.             treeFeller = treeFeller + 1 ;
  206.             robot.useDown()
  207.             sucky()
  208.             robot.forward();
  209.             x, y, z = component.navigation.getPosition();
  210.         end
  211.     end
  212. end
  213.  
  214. local function init()
  215.     local correct = checkCorrect();
  216.     if (correct) then
  217.         os.sleep(1)
  218.     else
  219.         gotoY(67.5);
  220.         gotoX(-7.5);
  221.         gotoZ(-24.5);
  222.         gotoY(65.5);
  223.     end
  224.     while ( component.navigation.getFacing() ~= 4 ) do
  225.         robot.turnLeft();
  226.     end
  227. end
  228.  
  229. local function dumpme()
  230.     for i = 1, robot.inventorySize() do
  231.         robot.select(i)
  232.         robot.drop()
  233.     end
  234.     robot.select(1);
  235.     while computer.energy() < maxbatt do
  236.         os.sleep(1);
  237.     end
  238. end
  239.  
  240. local function updatierer()
  241.     gotoY(66.5);
  242.     gotoX(-22.5);
  243.     gotoY(65.5);
  244.     updateStuff();
  245.     gotoY(66.5);
  246.     gotoX(-7.5);
  247.     gotoY(65.5);
  248. end
  249.  
  250. local function gotomelon()
  251.     gotoZ(-26.5);
  252.     gotoX(-23.5);
  253. end
  254.  
  255. while true do
  256.     init();
  257.     dumpme();
  258.     updatierer();
  259.     gotomelon();
  260.     breaktoZ(-62.5)
  261.     breaktoY(66.5)
  262.     breaktoX(-19.5)
  263.     breaktoY(65.5)
  264.     breaktoZ(-28.5)
  265.     breaktoY(66.5)
  266.     breaktoX(-18.5)
  267.     farmtoZ(-62.5)
  268.     breaktoX(-16.5)
  269.     farmtoZ(-28.5)
  270.     breaktoX(-15.5)
  271.     farmtoZ(-62.5)
  272.     breaktoX(-13.5)
  273.     farmtoZ(-28.5)
  274.     breaktoX(-12.5)
  275.     farmtoZ(-62.5)
  276.     breaktoX(-10.5)
  277.     farmtoZ(-28.5)
  278.     breaktoX(-9.5)
  279.     farmtoZ(-62.5)
  280.     breaktoX(-7.5)
  281.     farmtoZ(-28.5)
  282.     breaktoX(-6.5)
  283.     farmtoZ(-62.5)
  284.     breaktoX(-4.5)
  285.     farmtoZ(-28.5)
  286. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement