Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- FarmerBot v1.0.0
- Guide
- -----------------
- Crops: Wheat
- -----------------
- Goals:
- Farm down a line of crops and constantly check the crops.
- 2.0 Goals:
- - Allow multiple bots at the same time (designating their name in logs)
- - Attempt to till the ground below it (excluding water)
- - Add more crops
- ]]--
- -- Globals --
- local crops = {
- { id = 1, mature = 7, name = "minecraft:carrots", seed = "minecraft:carrot", label = "Carrots" },
- { id = 2, mature = 7, name = "minecraft:wheat", seed = "minecraft:wheat_seeds", label = "Wheat" },
- { id = 3, mature = 7, name = "minecraft:potatoes", seed = "minecraft:potato", label = "Potatoes" },
- { id = 4, mature = 7, name = "magicalcrops:MinicioCrop", seed = "magicalcrops:MinicioSeeds", label = "Minicio" }
- }
- -- Helper Function: Determine if the crop is fully developed. If not, alert the user.
- function isGrown(row, length, current, expected)
- rednet.send(12, "[FarmBot] Crop (" .. row .. "," .. length .. ") status: " .. tonumber(string.format("%.3f", (current/expected) * 100)) .. "%", "bttp")
- if current == expected then
- return true
- end
- return false
- end
- -- Helper Function: Determines if the crop ID has any seeds for said crop. Selects seed if true.
- function hasSeeds(id)
- for k,v in pairs(crops) do
- if v.id == id then
- for i = 1, 16 do
- local data = turtle.getItemDetail(i)
- if data.name == v.seed then
- turtle.select(i)
- return true
- end
- end
- end
- end
- return false
- end
- function dropItems()
- for i = 16,1,-1 do
- turtle.select(i)
- turtle.dropDown()
- end
- end
- -- Network Handling (modem on right)
- if rednet.isOpen("right") then
- rednet.send(12, "[FarmBot] Connected to modem!", "bttp")
- else
- rednet.open("right")
- rednet.send(12, "[FarmBot] Turning on modem...", "bttp")
- rednet.send(12, "[FarmBot] Connected successfully!", "bttp")
- end
- -- Player Input
- local input = { rows = 0, length = 0 }
- -- Ask player for input
- term.write("Please enter number of rows: ")
- input.rows = tonumber(read())
- term.write("Please enter in length of row: ")
- input.length = tonumber(read())
- rednet.send(12, "[FarmBot] Farming " .. input.rows .. "x" .. input.length .. " sized farm.", "bttp")
- -- Preface: Determine if the bot was placed on the ground. If so, go up one block.
- rednet.send(12, "[FarmBot] Is there a block below? " .. tostring(turtle.detectDown()), "bttp")
- if turtle.detectDown() then
- turtle.up()
- end
- turtle.forward()
- while true do
- -- Start farming the area.
- for i = 1, input.rows do
- for j = 1, input.length do
- -- Check status of current crop.
- if turtle.detectDown() then
- --There is something below. Determine if it is something we can handle.
- local success, data = turtle.inspectDown()
- if success then
- for k,v in pairs(crops) do
- if data.name == v.name then
- if isGrown(i,j,data.metadata,v.mature) then
- --Break the block... Then replace...
- turtle.digDown()
- turtle.suckDown() -- Pick up the local crop.
- if hasSeeds(v.id) then
- turtle.placeDown()
- else
- rednet.send(12, "[FarmBot] Unable to find seed for " .. v.label .. " (" .. i .. "," .. j .. ")", "bttp")
- end
- end
- end
- end
- else
- rednet.send(12, "[FarmBot] Cannot read block (" .. i .. "," .. j .. ")", "bttp")
- end
- else
- rednet.send(12, "[FarmBot] No block found (" .. i .. "," .. j .. ")", "bttp")
- end
- -- Go forward one to continue.
- if j < input.length then
- turtle.forward()
- end
- end
- os.sleep(3)
- -- Done reviewing the row. Now move to new row.
- local isEven = i % 2 == 0
- if isEven == false then
- turtle.turnLeft()
- turtle.forward()
- turtle.turnLeft()
- else
- turtle.turnRight()
- turtle.forward()
- turtle.turnRight()
- end
- end
- rednet.send(12, "[FarmBot] Resetting back to start.", "bttp")
- os.sleep(5)
- -- Go back to start where chest is.
- for k = 1, input.length do
- turtle.forward()
- end
- turtle.turnLeft()
- for l = 1, input.rows do
- turtle.forward()
- end
- turtle.turnLeft()
- -- Drop items in hopper below.
- turtle.down()
- os.sleep(2)
- dropItems()
- os.sleep(2)
- turtle.up()
- turtle.forward()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement