Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[ FARM program v0.7 ]]--
- print("farm [# spaces forward] [# columns]")
- local args = { ... }
- local x, y = 0, 0
- local alternating = false
- FARM_seedsInvSlotNum = 0
- local function initFarming()
- if args ~= nil and #args < 1 then
- print("Please input how far forward the turtle should go...")
- y = io.read()
- else
- y = args[1]
- end
- if args ~= nil and #args < 2 then
- print("Please input the number of columns there are...")
- x = io.read()
- else
- x = args[2]
- end
- if x == nil or y == nil then
- return
- end
- print("You should place the turtle at the X.")
- print("You should place a chest at the ☐.")
- for rowsSample=0,y-1,1 do
- textutils.slowPrint(string.rep('.',x))
- end
- print("☐X"..string.rep('.',x-2))
- print("Press Y then Enter to continue.")
- local confirmation = io.read()
- if confirmation ~= "Y" and confirmation ~= "y" then
- print("Cancelled farming...")
- return
- end
- end
- local function alternateTurn()
- if alternating then
- turtle.turnLeft()
- turtle.forward()
- turtle.turnLeft()
- else
- turtle.turnRight()
- turtle.forward()
- turtle.turnRight()
- end
- end
- local function plantCrop()
- local previousSlot = turtle.getSelectedSlot()
- if FARM_seedsInvSlotNum == 0 then
- for invSlot=1,16,1 do
- local data = turtle.getItemDetail(invSlot)
- if data and data.name == "minecraft:wheat_seeds" then
- FARM_seedsInvSlotNum = invSlot
- turtle.select(invSlot)
- turtle.placeDown()
- end
- end
- elseif FARM_seedsInvSlotNum >= 1 and FARM_seedsInvSlotNum <= 16 then
- turtle.select(FARM_seedsInvSlotNum)
- turtle.placeDown()
- end
- turtle.select(previousSlot)
- end
- local function checkCrop()
- local exists, data = turtle.inspectDown()
- if exists and data.name == "minecraft:wheat" and data.metadata == 7 then
- turtle.digDown()
- end
- end
- local function doFarming()
- for ax=1,x,1 do
- for ay=1,y,1 do
- checkCrop()
- plantCrop()
- turtle.forward()
- end
- checkCrop()
- plantCrop()
- alternateTurn()
- alternating = not alternating
- end
- end
- local function dumpAllInventory()
- for invSlot=1,16,1 do
- turtle.select(invSlot)
- turtle.dropDown()
- end
- end
- local function goHome()
- if alternating then
- for hy=1,y,1 do
- turtle.forward()
- end
- turtle.turnRight()
- for hx=1,x,1 do
- turtle.forward()
- end
- else
- turtle.turnLeft()
- for hx=1,x,1 do
- turtle.forward()
- end
- end
- end
- initFarming()
- doFarming()
- goHome()
- dumpAllInventory()
- turtle.turnRight()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement