Neon1432

simpletree

May 31st, 2022 (edited)
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.36 KB | None | 0 0
  1. dofile("bs/wrapper")
  2. local params = bs.params.load("bs/files/simpletree_params")
  3. local hook = bs.rdnt.hook:new()
  4. hook.port = "simpletree"
  5.  
  6. if params[1] == nil then
  7.     bs.ui.clear()
  8.     local menuparam = {{text = "Oaktree", value = "oak"}, {text = "Birchtree", value = "birch"}, {text = "Jungetree", value = "jungle"}, {}}
  9.     local ttype = bs.ui.printMenu("Which Tree-Type do you want to farm?", menuparam)
  10.     params.type = ttype
  11.     repeat
  12.         bs.ui.clear()
  13.         print("Please put in at least 4 saplings to start with")
  14.         bs.ui.pressenter()
  15.     until bs.inventory.IsInInventory(params.type.."_sapling", 4)
  16.     if ttype == "oak" then
  17.         bs.ui.clear()
  18.         print("Please add the block at %height% ")
  19.         bs.ui.pressenter()
  20.     end
  21.     bs.ui.clear()
  22.     print("Please setup a saplingfarmer 1 block behind this one and 2 blocks to the right")
  23.     bs.ui.pressenter()
  24.     if hook:connect(5) ~= 0 then
  25.         printError("Cannot connect to saplingfarmer")
  26.     end
  27.     params.socketID = hook.socketID
  28.     bs.params.save("bs/files/simpletree_params", params)
  29. else
  30.     hook.socketID = params.socketID
  31. end
  32.  
  33. local function growTree()
  34.     if not bs.inventory.selectID(params.type.."_logs") then return false, "no more saplings" end
  35.     turtle.place()
  36.     while true do
  37.         redstone.setOutput("down", true)
  38.         sleep(0.05)
  39.         redstone.setOutput("down", false)
  40.         local inspect = turtle.inspect()
  41.         if string.find(inspect.name, "log") <> 0 then
  42.             return true
  43.         end
  44.     end
  45. end
  46.  
  47. local function breakTree()
  48.     turtle.dig()
  49.     turtle.forward()
  50.     local inspect = turtle.inspectUp()
  51.     while string.find(inspect.name, "log") <> 0 do
  52.         turtle.digUp()
  53.         turtle.up()
  54.         inspect = turtle.inspectUp()
  55.     end
  56.     turtle.digUp()
  57.     turtle.up()
  58.     repeat
  59.         for I = 1, 4 do
  60.             turtle.dig()
  61.             turtle.turnLeft()
  62.         end
  63.     until not turtle.down()
  64.     turtle.back()
  65. end
  66.  
  67.  
  68. local function dropLogs()
  69.     turtle.back()
  70.     turtle.turnLeft()
  71.     turtle.turnLeft()
  72.     for I = 1, 16 do
  73.         if turtle.getItemDetail(I) ~= nil then
  74.             local detail = turtle.getItemDetail(I)
  75.             if string.find(detail.name, "sapling") == 0 then
  76.                 turtle.select(I)
  77.                 turtle.drop()
  78.             end
  79.         end
  80.     end
  81.     turtle.select(1)
  82.     turtle.turnLeft()
  83.     turtle.turnLeft()
  84.     turtle.forward()
  85. end
  86.  
  87. while true do
  88.     if not growTree() then printError("No saplings found") end
  89.     hook:request("breakleaves")
  90.     breakTree()
  91.     if bs.inventory.getfirstFreeIndex() > 12 then
  92.         dropLogs()
  93.     end
  94.     hook:request("giveItems")
  95. end
  96.  
  97.  
Add Comment
Please, Sign In to add comment