Advertisement
Shaka01

Dark Oak Feller

Oct 23rd, 2024
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.03 KB | None | 0 0
  1. -- general stuff
  2. if fs.exists("API") == false then
  3. shell.run("pastebin", "get", "EzkfU5ZM", "API")
  4. end
  5. shaka = require("API")
  6. local inv = nil
  7. -- local ID = os.getComputerID()
  8. -- ID = ID + 1
  9. -- local targetInv = "turtle_" ..ID
  10. -- targetInv = tostring(targetInv)
  11. local targetInv = "turtle_5"
  12. local block = nil
  13.  
  14.  
  15. -- functions
  16.  
  17. local function connect()
  18.     local sides = {"left", "right", "top", "bottom", "front", "back"}
  19.     for i, side in ipairs(sides) do
  20.         local device = peripheral.getType(side)
  21.         if device == "modem" then
  22.         modem = peripheral.wrap(side)
  23.         if modem.isWireless() then
  24.             wirelessModem = peripheral.wrap(side)
  25.             rednet.open(side)
  26.         else
  27.             wiredModem = peripheral.wrap(side)
  28.             rednet.close(side)
  29.         end
  30.         elseif device == "monitor" then
  31.             monitor = peripheral.wrap(side)
  32.         end
  33.     end
  34. end
  35. connect()
  36.  
  37. local function getInventories()
  38.  if wiredModem ~= nil then
  39.   fromInventories = {}
  40.   local inventories = wiredModem.getNamesRemote()
  41.   for _, inventoryName in ipairs(inventories) do
  42.     if shaka.stringFind(inventoryName, "turtle") == false and inventoryName ~= nil and shaka.stringFind(inventoryName, "computer") == false then
  43.         inv = peripheral.wrap(inventoryName)
  44.     end
  45.   end
  46.  end
  47. end
  48.  
  49. local function dropItems()
  50.     getInventories()
  51.     for i = 1, 16 do
  52.         if turtle.getItemCount(i) > 0 then
  53.             inv.pullItems(targetInv, i)
  54.         end
  55.     end
  56. end
  57.  
  58. local function start()
  59.     turtle.dig()
  60.     if turtle.getFuelLevel() < 10 then
  61.         turtle.refuel()
  62.     end
  63.     -- turtle.back()
  64.     -- turtle.back()
  65. end
  66.  
  67. local function getItem(itemName, slot, amount)
  68.     local found = false -- Track if the item was found
  69.  
  70.     for k, v in pairs(inv.list()) do
  71.         for a, b in pairs(v) do
  72.             if a == "name" and b == itemName then
  73.                 local itemDetail = inv.getItemDetail(k)
  74.  
  75.                 -- Check if item is "minecraft:dark_oak_sapling" and validate its count
  76.                 if itemName == "minecraft:dark_oak_sapling" then
  77.                     if itemDetail.count >= amount then
  78.                         inv.pushItems(targetInv, k, amount, slot)
  79.                         return true -- Successfully transferred the required amount of dark oak saplings
  80.                     else
  81.                         -- Dark oak sapling found, but not enough quantity
  82.                         found = true
  83.                     end
  84.                 else
  85.                     -- For other items, transfer regardless of count
  86.                     inv.pushItems(targetInv, k, amount, slot)
  87.                     return true -- Successfully transferred the item
  88.                 end
  89.             end
  90.         end
  91.     end
  92.  
  93.     -- If we found the item but not enough dark oak saplings, or didn't find the item
  94.     return found
  95. end
  96.  
  97. local function showMsg(message)
  98. term.clear()
  99. shaka.centerText(message, 3)
  100. sleep(0.5)
  101. end
  102.  
  103.  
  104. local function replant()
  105.     showMsg("Re-planting")
  106.     repeat sleep(0.1) until turtle.forward()
  107.     repeat sleep(0.1) until turtle.forward()
  108.     turtle.turnLeft()
  109.     repeat sleep(0.1) until turtle.place()
  110.     turtle.turnRight()
  111.     repeat sleep(0.1) until turtle.back()
  112.     repeat sleep(0.1) until turtle.place()
  113.     turtle.turnLeft()
  114.     repeat sleep(0.1) until turtle.place()
  115.     turtle.turnRight()
  116.     repeat sleep(0.1) until turtle.back()
  117.     repeat sleep(0.1) until turtle.place()
  118.     -- repeat showMsg("Waiting for bonemeal") until getItem("minecraft:bone_meal", 16, 64)
  119.    
  120.     repeat
  121.         if turtle.getItemCount(16) < 1 then
  122.             repeat showMsg("Searching for bonemeal") until getItem("minecraft:bone_meal", 16, 64)
  123.         end
  124.         showMsg("Re-growing")
  125.         turtle.place()
  126.         a, block = turtle.inspect()
  127.     until block.name == "minecraft:dark_oak_log"
  128.     term.clear()
  129.     dropItems()
  130.     term.clear()
  131. end
  132.  
  133. while true do
  134. start()
  135. sleep(0.1)
  136. connect()
  137. getInventories()
  138. dropItems()
  139. if turtle.getFuelLevel() < 100 then
  140.     showMsg("Refueling")
  141.     getItem("minecraft:charcoal", 1, 64)
  142.     turtle.refuel()
  143.     dropItems()
  144.     term.clear()
  145. end
  146. turtle.select(16)
  147. repeat
  148.     showMsg("Searching for saplings")
  149. until getItem("minecraft:dark_oak_sapling", 16, 4)
  150. term.clear()
  151. replant()
  152. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement