Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tArgs = {...}
- if #tArgs < 2 or tonumber(tArgs[1]) == nil or tonumber(tArgs[2] == nil) then
- print('Usage: wartfarmer <forward> <right>')
- print(' The size of the field is relative')
- print(' to the turtle\'s start point. Turtle')
- print(' should be *above* the netherwart.')
- return
- end
- local FORWARD_LEN = tonumber(tArgs[1])
- local RIGHT_LEN = tonumber(tArgs[2])
- local i
- local function plantWart()
- for i=1,16 do
- itemData = turtle.getItemDetail(i)
- if itemData ~= nil and itemData['name'] == 'minecraft:nether_wart' then
- turtle.placeDown() -- plant netherwart
- break
- end
- end
- end
- -- note that "forward" and "right" are relative to the turtle's start
- local forwardPos = 1
- local rightPos = 1
- local movingForward = true
- local outOfFuel = false
- local wartCount = 0
- -- quick fuel check
- if turtle.getFuelLevel() == 0 then
- print('Out of fuel!')
- end
- print('Hold Ctrl-T to stop farmer.')
- --main program
- while true do
- -- check if below is a chest
- local exists, block = turtle.inspectDown()
- if exists and (string.find(block['name'], 'chest') or string.find(block['name'], 'barrel')) then
- -- drop off inventory into chest
- print('Dropping off inventory into chest...')
- for i=1,16 do
- turtle.select(i)
- itemData = turtle.getItemDetail()
- if itemData ~= nil and itemData['name'] == 'minecraft:nether_wart' then
- wartCount = wartCount + turtle.getItemCount()
- end
- turtle.dropDown(64) -- deposit everything into chest, warts and whatever
- end
- print(' ', wartCount, ' warts deposited.')
- wartCount = 0
- elseif not exists then
- -- nothing is under the turtle, so try to plant netherwart
- plantWart()
- elseif block['name'] == 'minecraft:nether_wart' and block['metadata'] == 3 then
- -- netherart (and fully mature) is below, so harvest it
- turtle.digDown()
- turtle.suckDown() -- pick up any netherwart
- plantWart()
- end
- -- move the turtle along 1 block
- if movingForward and forwardPos < FORWARD_LEN then
- -- moving forward down the row
- moved = turtle.forward()
- if not moved then outOfFuel = true end
- forwardPos = forwardPos + 1 -- keep track of where we are
- elseif movingForward and forwardPos == FORWARD_LEN then
- -- at the end of the row
- if rightPos < RIGHT_LEN then
- -- go to next row
- turtle.turnRight()
- moved = turtle.forward()
- if not moved then outOfFuel = true end
- rightPos = rightPos + 1 -- keep track of where we are
- turtle.turnRight()
- movingForward = false
- elseif rightPos == RIGHT_LEN then
- -- end of the last row, go back home
- turtle.turnRight()
- turtle.turnRight()
- for i=1,(FORWARD_LEN-1) do
- moved = turtle.forward()
- if not moved then outOfFuel = true end
- end
- turtle.turnRight()
- for i=1,(RIGHT_LEN-1) do
- moved = turtle.forward()
- if not moved then outOfFuel = true end
- end
- turtle.turnRight()
- -- should be back at start now in correct orientation
- forwardPos = 1
- rightPos = 1
- movingForward = true
- sleep(210) -- wait 3:30 for regrow
- end
- elseif not movingForward and forwardPos > 1 then
- -- moving back down the row
- moved = turtle.forward()
- if not moved then outOfFuel = true end
- forwardPos = forwardPos - 1 -- keep track of where we are
- elseif not movingForward and forwardPos == 1 then
- -- back at start of row, turn to next row
- if rightPos < RIGHT_LEN then
- -- go to next row
- turtle.turnLeft()
- moved = turtle.forward()
- if not moved then outOfFuel = true end
- rightPos = rightPos + 1 -- keep track of where we are
- turtle.turnLeft()
- movingForward = true
- elseif rightPos == RIGHT_LEN then
- -- end of the last row, go back home
- turtle.turnRight()
- for i=1,(RIGHT_LEN-1) do
- moved = turtle.forward()
- if not moved then outOfFuel = true end
- end
- turtle.turnRight()
- -- should be back at start now in correct orientation
- forwardPos = 1
- rightPos = 1
- movingForward = true
- sleep(210) -- wait 3:30 for regrow
- end
- end
- --print('Pos: ', forwardPos, ', ', rightPos)
- if outOfFuel then
- print('Out of fuel (or blocked)! Refuel and')
- print('move turtle back to start point.')
- return
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement