Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- general stuff
- if fs.exists("API") == false then
- shell.run("pastebin", "get", "EzkfU5ZM", "API")
- end
- shaka = require("API")
- local inv = nil
- -- local ID = os.getComputerID()
- -- ID = ID + 1
- -- local targetInv = "turtle_" ..ID
- -- targetInv = tostring(targetInv)
- local targetInv = "turtle_5"
- local block = nil
- -- functions
- local function connect()
- local sides = {"left", "right", "top", "bottom", "front", "back"}
- for i, side in ipairs(sides) do
- local device = peripheral.getType(side)
- if device == "modem" then
- modem = peripheral.wrap(side)
- if modem.isWireless() then
- wirelessModem = peripheral.wrap(side)
- rednet.open(side)
- else
- wiredModem = peripheral.wrap(side)
- rednet.close(side)
- end
- elseif device == "monitor" then
- monitor = peripheral.wrap(side)
- end
- end
- end
- connect()
- local function getInventories()
- if wiredModem ~= nil then
- fromInventories = {}
- local inventories = wiredModem.getNamesRemote()
- for _, inventoryName in ipairs(inventories) do
- if shaka.stringFind(inventoryName, "turtle") == false and inventoryName ~= nil and shaka.stringFind(inventoryName, "computer") == false then
- inv = peripheral.wrap(inventoryName)
- end
- end
- end
- end
- local function dropItems()
- getInventories()
- for i = 1, 16 do
- if turtle.getItemCount(i) > 0 then
- inv.pullItems(targetInv, i)
- end
- end
- end
- local function start()
- turtle.dig()
- if turtle.getFuelLevel() < 10 then
- turtle.refuel()
- end
- -- turtle.back()
- -- turtle.back()
- end
- local function getItem(itemName, slot, amount)
- local found = false -- Track if the item was found
- for k, v in pairs(inv.list()) do
- for a, b in pairs(v) do
- if a == "name" and b == itemName then
- local itemDetail = inv.getItemDetail(k)
- -- Check if item is "minecraft:dark_oak_sapling" and validate its count
- if itemName == "minecraft:dark_oak_sapling" then
- if itemDetail.count >= amount then
- inv.pushItems(targetInv, k, amount, slot)
- return true -- Successfully transferred the required amount of dark oak saplings
- else
- -- Dark oak sapling found, but not enough quantity
- found = true
- end
- else
- -- For other items, transfer regardless of count
- inv.pushItems(targetInv, k, amount, slot)
- return true -- Successfully transferred the item
- end
- end
- end
- end
- -- If we found the item but not enough dark oak saplings, or didn't find the item
- return found
- end
- local function showMsg(message)
- term.clear()
- shaka.centerText(message, 3)
- sleep(0.5)
- end
- local function replant()
- showMsg("Re-planting")
- repeat sleep(0.1) until turtle.forward()
- repeat sleep(0.1) until turtle.forward()
- turtle.turnLeft()
- repeat sleep(0.1) until turtle.place()
- turtle.turnRight()
- repeat sleep(0.1) until turtle.back()
- repeat sleep(0.1) until turtle.place()
- turtle.turnLeft()
- repeat sleep(0.1) until turtle.place()
- turtle.turnRight()
- repeat sleep(0.1) until turtle.back()
- repeat sleep(0.1) until turtle.place()
- -- repeat showMsg("Waiting for bonemeal") until getItem("minecraft:bone_meal", 16, 64)
- repeat
- if turtle.getItemCount(16) < 1 then
- repeat showMsg("Searching for bonemeal") until getItem("minecraft:bone_meal", 16, 64)
- end
- showMsg("Re-growing")
- turtle.place()
- a, block = turtle.inspect()
- until block.name == "minecraft:dark_oak_log"
- term.clear()
- dropItems()
- term.clear()
- end
- while true do
- start()
- sleep(0.1)
- connect()
- getInventories()
- dropItems()
- if turtle.getFuelLevel() < 100 then
- showMsg("Refueling")
- getItem("minecraft:charcoal", 1, 64)
- turtle.refuel()
- dropItems()
- term.clear()
- end
- turtle.select(16)
- repeat
- showMsg("Searching for saplings")
- until getItem("minecraft:dark_oak_sapling", 16, 4)
- term.clear()
- replant()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement