*This program requires a Shearing turtle from MiscPeripherals 2.3 or higher!*
There is one bug with this program which is that I tried to add a code to the program to have the turtle detect if the chest it was trying to put wool into was full it would stop working and wait for there to be space in the chest. However this code kept throwing an error that I didn't know how to correct so I commented out that peice of the code.
As long as you make sure the chest doesn't get over-filled, the program works great. If someone feels up to debugging that problem in my code please share!
For the setup, it's best to have two shearing turtles in a 5x3 or 6x3 space set up n a way that there is only 1 block between the turtles and walls keeping the sheep in such as below.
T = Turtle
S = Space
S S S S S
S T S T S
S S S S S
or
S S S S S S
S T S S T S
S S S S S S
Here's the code:
Spoiler
-- Sheep shearing program for shearing turtle
-- Fuel must be provided in a chest directly above the turtle
-- Collected wool is placed in the chest directly under the turtle
cycles = 0
totalwool = 0
local function shear()
turtle.attack()
turtle.turnRight()
turtle.attack()
turtle.turnRight()
turtle.attack()
turtle.turnRight()
turtle.attack()
turtle.turnRight()
end
local function updateterm()
term.clear()
print("---------------------------------")
write("Cycles: ")
write(cycles)
write(" | ")
write("Total Wool: ")
write(totalwool)
print("---------------------------------")
print("")
end
local function getFuel()
turtle.select(16)
while turtle.getItemCount(16) < 2 do
redstone.setOutput("top", true)
sleep(5)
redstone.setOutput("top", false)
turtle.suckUp(63)
os.sleep(1)
if turtle.getItemCount(16) < 2 then
print("I need more fuel in above chest")
print("Waiting 30 seconds before checking again")
os.sleep(30)
end
end
end
local function checkFuel()
while turtle.getFuelLevel() < 10 do
getFuel()
turtle.select(16)
turtle.refuel(1)
end
end
local function storeWool()
storecheck = false
-- while storecheck == false do
for i=1,15,1 do
if turtle.getItemCount(i) > 0 then
turtle.select(i)
totalwool = totalwool + turtle.getItemCount(i)
storecheck = not turtle.dropDown()
end
end
-- end
if storagespace == false then
print("The inventory is full I can't store my harvest")
print("Waiting 30 seconds before checking again")
os.sleep(30)
end
end
while true do
checkFuel()
shear()
storeWool()
cycles = cycles + 1
updateterm()
os.sleep(5)
end
Set up a coal chest above the turtles, and a storage chest below both turtles. The coal chests are optional. To my own experiance feeding a turtle a stack of charoal is enough to have it run for so long I filled a double-chest with wool.
If you have BuildCraft, Redpower, or similar, you may want to pull items out of the chests under the turtles and pipe it elsewhere. If desired it's easy enough to flip the code so the turtle puts items in the chest above them, and either tries to fetch coal from below, or just fill them yourself.
Edits:
Edit 1,2,3: Removed garbage code I forgot was in there during testing, fixed indentation some to reduce confusion.
Edit 4: Changed the line "storecheck = turtle.dropDown()" to "storecheck = not turtle.dropDown()" to see if that works. Left code commented out till i can test it.