Raon_Hook

Untitled

Jun 17th, 2021 (edited)
1,506
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.49 KB | None | 0 0
  1. -- Very basic oak tree farming lua script for the turtles from the Computercraft mod
  2. -- Requires specific setup for tree growth, turtle position, refueling, restocking and unloading of wood
  3.  
  4. -- Performs the farming of the wood
  5. function farm()
  6.     -- Mines down
  7.         turtle.digDown()
  8.     for i=0,4 do
  9.         turtle.down()
  10.         turtle.digDown()
  11.     end
  12.  
  13.     -- Places sapling
  14.     turtle.placeDown()
  15.  
  16.     -- Returns to position
  17.     for i=0,4 do
  18.         turtle.up()
  19.     end
  20. end
  21.  
  22. -- Performs the unloading of the wood
  23. function unload_wood()
  24.     -- Selects the 3rd item slot within the turtle, the 3rd item slot is where the wood should be
  25.     turtle.select(3)
  26.     -- Drops the wood into the chest inventory above itself
  27.     turtle.dropUp()
  28.     -- Selects the 1st item slot ready for planting saplings
  29.     turtle.select(1)
  30. end
  31.  
  32. -- Performs the refueling of the turtle
  33. function refuel()
  34.     -- Selects the 2nd item slot within the turtle, the 2nd item slot should contain the fuel source for the turtle
  35.     turtle.select(2)
  36.     -- Moves forward under the hopper and chest used to store the fuel source
  37.     turtle.forward()
  38.     -- Waits for the collection of 32 items of fuel
  39.     while turtle.getItemCount(2) < 32 do
  40.         os.sleep(0.1)
  41.     end
  42.     -- Once 32 items have be collected, returns to position
  43.     turtle.back()
  44.     -- Consumes the fuel
  45.     turtle.refuel()
  46.     -- Selects the 1st item slot ready for planting sapligns
  47.     turtle.select(1)
  48. end
  49.  
  50. -- Performs the restocking of saplings
  51. function restock()
  52.     -- Moves backward under the hopper and chest used to store saplings
  53.     turtle.back()
  54.     -- Waits for the collection of 32 saplings
  55.     while turtle.getItemCount(1) < 32 do
  56.         os.sleep(0.1)
  57.     end
  58.     -- Returns back to position
  59.     turtle.forward()
  60. end
  61.  
  62. -- Main loop
  63. while true do
  64.     -- Checks if fuel level is low
  65.     if turtle.getFuelLevel() < 15 then
  66.         -- If it's low, calls the refuel function
  67.         refuel()
  68.     end
  69.  
  70.     -- Checks if sapling count is low (item count from slot 1)
  71.     if turtle.getItemCount(1) < 5 then
  72.         -- If it's low, calls restock function
  73.         restock()
  74.     end
  75.  
  76.     -- Checks if a tree has grown by detecting whether or not a blocks is beneath it (the top of the tree)
  77.     if turtle.detectDown() then
  78.         -- If the tree has grown, calls farm function
  79.         farm()
  80.         -- once tree has been farmed and returned to position, calls unload_wood function
  81.         unload_wood()
  82.     end
  83. end
Advertisement
Add Comment
Please, Sign In to add comment