Hiranus

CC plant farmer

Mar 22nd, 2019
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.78 KB | None | 0 0
  1. local Orientations = {"north","east","south","west"};
  2. local programData = nil;
  3.  
  4. local function TurnLeft()
  5.   turtle.turnLeft()
  6.   programData.Orientation = programData.Orientation - 1;
  7.   if programData.Orientation == -1 then
  8.     programData.Orientation = 3;
  9.   end
  10. end
  11. local function TurnRight()
  12.   turtle.turnRight()
  13.   programData.Orientation = programData.Orientation + 1;
  14.   if programData.Orientation == 4 then
  15.     programData.Orientation = 0;
  16.   end
  17. end
  18.  
  19. local function Save()
  20.   local file = io.open("programData", "w")
  21.   file:write(programData)
  22.   file:close()
  23. end
  24.  
  25. local function Load()
  26.   local file = io.open("programData", "r") --open in read mode
  27.   programData = file:read()
  28.   file:close()
  29. end
  30.  
  31.  
  32. local function init()
  33.  
  34.   if fs.exists("programData") then
  35.     Load()
  36.   else
  37.     programData = {};
  38.     programData.Orientation = 0;
  39.   end
  40. end
  41.  
  42. local function BreakPlants()
  43.   TurnRight();
  44.   if turtle.detect() then
  45.     turtle.dig();
  46.     turtle.suck();
  47.   end
  48.   TurnLeft()
  49.   TurnLeft()
  50.   if turtle.detect() then
  51.     turtle.dig();
  52.     turtle.suck();
  53.   end
  54.   TurnRight();
  55. end
  56.  
  57. local function DumpEverything()
  58.   for i=1,16 do
  59.     turtle.select(i);
  60.     turtle.drop();
  61.   end
  62. end
  63.  
  64. local function Refuel()
  65.   turtle.select(1);
  66.   while turtle.getFuelLevel() < 500 do
  67.     turtle.suck();
  68.     turtle.refuel();
  69.   end
  70. end
  71.  
  72. local function BlockAction()
  73.   local success, data = turtle.inspect();
  74.   if data.name == "minecraft:obsidian" then
  75.     TurnLeft()
  76.     TurnLeft()
  77.   elseif data.name == "EnderStorage:EnderStorage" then
  78.     DumpEverything();
  79.     Refuel();
  80.     TurnLeft();
  81.     TurnLeft();
  82.   else
  83.     error("Unknown block in front");
  84.   end
  85. end
  86. init();
  87. while true do
  88.   BreakPlants()
  89.   if turtle.detect() then
  90.     BlockAction()
  91.   end
  92.   turtle.forward()
  93. end
Advertisement
Add Comment
Please, Sign In to add comment