Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("JAPI/JMove.lua")
- -- /\ +y (FORWARD)
- -- | F F F
- -- | F F F
- -- | F F F
- -- | T F F F
- -- ---------> +x
- function printUsage()
- textutils.pagedPrint("Usage: farm <width> <length> <farm dir up>")
- textutils.pagedPrint(" <farm dir up> can be a number or a string.")
- textutils.pagedPrint(" Number: 0 .. 3")
- textutils.pagedPrint(" String: FORWARD/POS_Y, LEFT/NEG_X, BACK/NEG_Y or RIGHT/POS_X")
- error()
- end
- local tArgs = { ... }
- if #tArgs ~= 3 then
- printUsage()
- return
- end
- local farmWidth = tArgs[1]
- local farmLength = tArgs[2]
- local farmDirUp = tArgs[3]
- local success, data = JMove.isDir(farmDirUp)
- if success == false then
- printUsage()
- return
- end
- local farmItemType = "minecraft:wheat"
- local farmItemSeedType = "minecraft:wheat_seeds"
- local waitTime = 2
- function waitToBegin()
- JMove.turnTo(JMove.POS_X)
- local begin = false
- while begin == false do
- sleep(waitTime)
- local s, d = turtle.inspect()
- if s then
- print("Waiting...")
- if d.name == farmItemType then
- local age = d.state.age
- if age == 7 then
- print("Initiate farming")
- begin = true
- end
- end
- else
- print("Wheat at (0, 0, 0) is gone!")
- begin = true
- end
- end
- end
- function dumpItems()
- JMove.turnTo(JMove.NEG_Y)
- local numSeeds = 0
- local shouldDumpSeeds = false
- for i=1, 16, 1 do
- turtle.select(i)
- local data = turtle.getItemDetail()
- if data then
- if data.name == farmItemSeedType then
- if shouldDumpSeeds == false then
- numSeeds = numSeeds + data.count
- local numFarmBlocks = farmWidth*farmLength
- if numSeeds > numFarmBlocks then
- local dropCount = numSeeds-numFarmBlocks
- shouldDumpSeeds = true
- turtle.drop(dropCount)
- end
- else
- turtle.drop()
- end
- elseif data.name == farmItemType then
- turtle.drop()
- end
- end
- end
- end
- function reset()
- JMove.setPos(-1, 0, -1)
- JMove.setPOSY(farmDirUp)
- dumpItems()
- waitToBegin()
- end
- function toStart()
- reset()
- JMove.refuel()
- JMove.moveTo(-1, 0, 0)
- JMove.moveTo(0, 0, 0)
- end
- function placeSeed()
- local seeds = JUtils.findItem(farmItemSeedType)
- if seeds then
- turtle.placeDown()
- local s, d = turtle.inspectDown()
- if s then
- if d.name ~= farmItemType then
- print("Warning: Tile at", JMove.posToStr(), "is blocked!")
- else
- print("Placed seed at", JMove.posToStr())
- end
- else
- -- Till the dirt block
- local couldTill= turtle.digDown()
- if couldTill == false then
- print("Warning: Missing dirt block at", JMove.posToStr(), "!")
- else
- turtle.placeDown()
- print("Tilled and placed seed at", JMove.posToStr(), "!")
- end
- end
- else
- print("No seeds was found, add seeds and press 'enter' when done!")
- local hasSeeds = false
- while hasSeeds == false do
- action, key = os.pullEventRaw()
- if action == "key" then
- if key == keys.enter then
- local seeds = JUtils.findItem(farmItemSeedType)
- if seeds then
- hasSeeds = true
- else
- print("That was not seeds, try again and press 'enter' when done!")
- end
- end
- end
- end
- placeSeed()
- end
- end
- function farm()
- local success, data = turtle.inspectDown()
- if success then
- if data.name == farmItemType then
- local age = data.state.age
- -- Destroy is full grown
- if age == 7 then
- turtle.digDown()
- print("Farmed wheet at", JMove.posToStr(), "!")
- placeSeed()
- end
- end
- else
- placeSeed()
- end
- end
- local fw = farmWidth-1
- local fh = farmLength-1
- while true do
- toStart()
- farm()
- y = 0
- repeat
- local xStart = fw-1
- local xEnd = 0
- local xStep = -1
- if y%2 == 0 then
- xStart = 1
- xEnd = fw
- xStep = 1
- end
- if y ~= 0 then
- local i = xStart + 1
- if y%2 == 0 then i = 0 end
- JMove.moveTo(i, y, 0)
- farm()
- end
- for x=xStart,xEnd,xStep do
- JMove.moveTo(x, y, 0)
- farm()
- end
- y = y + 1
- until y > fh
- -- Move back to starting position on the farm.
- JMove.moveTo(0, 0, 0)
- JMove.moveTo(-1, 0, 0)
- JMove.moveTo(-1, 0, -1)
- JMove.turnTo(farmDirUp)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement