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.
- ]]--
- -- Globals --
- local CARROT = { id = 1, mature = 7, name = "minecraft:carrots", seed = "minecraft:carrot" }
- local WHEAT = { id = 2, mature = 7, name = "minecraft:wheat", seed = "minecraft:wheat_seeds" }
- local POTATO = { id = 3, mature = 7, name = "minecraft:potatoes", seed = "minecraft:potato" }
- -- Helper Function: Determine if the crop is fully developed. If not, alert the user.
- function isGrown(row, length, current, expected)
- rednet.send(11, "[FarmBot] Crop (" .. row .. ", " .. length .. ") status: " .. (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)
- if id == CARROT.id then
- for i = 1, 16 do
- local data = turtle.getItemDetail(i)
- if data.name == CARROT.seed then
- turtle.select(i)
- return true
- end
- end
- elseif id == WHEAT.id then
- for i = 1, 16 do
- local data = turtle.getItemDetail(i)
- if data.name == WHEAT.seed then
- turtle.select(i)
- return true
- end
- end
- elseif id == POTATO.id then
- for i = 1, 16 do
- local data = turtle.getItemDetail(i)
- if data.name == POTATO.seed then
- turtle.select(i)
- return true
- end
- end
- else
- return false
- end
- 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(11, "[FarmBot] Connected to modem!", "bttp")
- else
- rednet.open("right")
- rednet.send(11, "[FarmBot] Turning on modem...", "bttp")
- rednet.send(11, "[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(11, "[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.
- if turtle.detectDown() then
- turtle.up()
- os.sleep(2)
- turtle.forward()
- end
- 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
- --Determine if names match to any crop
- if data.name == CARROT.name then
- --Determine if the crop is grown. If it is, remove it and replace it.
- if isGrown(i,j,data.metadata,CARROT.mature) then
- --Break the block... Then replace...
- turtle.digDown()
- turtle.suckDown() -- Pick up the local crop.
- if hasSeeds(CARROT.id) then
- turtle.placeDown()
- else
- rednet.send(11, "[FarmBot] Unable to find seed for CARROT (" .. i .. "," .. j .. ")", "bttp")
- end
- end
- elseif data.name == WHEAT.name then
- --Determine if the crop is grown. If it is, remove it and replace it.
- if isGrown(i,j,data.metadata,WHEAT.mature) then
- --Break the block... Then replace...
- turtle.digDown()
- turtle.suckDown() -- Pick up the local crop.
- if hasSeeds(WHEAT.id) then
- turtle.placeDown()
- else
- rednet.send(11, "[FarmBot] Unable to find seed for WHEAT (" .. i .. "," .. j .. ")", "bttp")
- end
- end
- elseif data.name == POTATO.name then
- --Determine if the crop is grown. If it is, remove it and replace it.
- if isGrown(i,j,data.metadata,POTATO.mature) then
- --Break the block... Then replace...
- turtle.digDown()
- turtle.suckDown() -- Pick up the local crop.
- if hasSeeds(POTATO.id) then
- turtle.placeDown()
- else
- rednet.send(11, "[FarmBot] Unable to find seed for POTATO (" .. i .. "," .. j .. ")", "bttp")
- end
- end
- else
- rednet.send(11, "[FarmBot] Unable to recognize crop (" .. data.name .. ")", "bttp")
- end
- else
- rednet.send(11, "[FarmBot] Cannot read block (" .. i .. "," .. j .. ")", "bttp")
- end
- else
- rednet.send(11, "[FarmBot] No block found (" .. i .. "," .. j .. ")", "bttp")
- end
- -- Go forward one to continue.
- turtle.forward()
- 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(11, "[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