Posted 30 December 2015 - 05:06 PM
Just a quick and dirty cake-making crafty turtle program! Maybe I'll polish it up if anyone else wants me to – at the moment it derps out on weird input (i.e. an empty bucket in the milk chest).
print("Name: "..os.getComputerLabel())
print("ID: "..os.getComputerID())
print("Fuel: "..turtle.getFuelLevel())
–TODO: a lot more checking, to handle edge-cases and bad input gracefully.
–Maybe I will if anyone else uses this program, or if I need it for another world.
–HOW TO USE THIS PROGRAM: Arrange four chests around a turtle and put another
–chest on the bottom. The contents of the chests must be as follows:
–FRONT CHEST: Vanilla Sugar Canes
–RIGHT CHEST: Eggs
–BACK CHEST: Buckets of milk
–LEFT CHEST: Wheat
–BOTTOM CHEST: Cakes
–The turtle will take in these ingredients, turn them into cakes, and drop them
–in the chest below.
–NOTE: The turtle will deposit empty buckets into the milk chest. You will need
–some way to immediately remove them while leaving full milk buckets, otherwise
–this turtle's program will pick them back up and fail to produce cakes.
–(e.g. itemducts, golems, etc. Anything that will "filter")
–NOTE: There are two comments that can be "uncommented out" to have this program run
–indefinitely (at lines 137 & 153). Call fiveCakes() to have the program repeat itself.
function getMilk()
print("Getting milk.")
turtle.select(2)
turtle.suck()
turtle.select(3)
turtle.suck()
turtle.select(4)
turtle.suck()
local odd = false
if turtle.compareTo(3)==false then
odd = true
else
turtle.select(3)
if turtle.compareTo(2)==false then
odd = true
else
turtle.select(2)
if turtle.compareTo(4)==false then
odd = true
end
end
end
if odd==true then
return false
else
return true
end
end
function getEggs()
print("Getting Eggs.")
turtle.select(7)
turtle.suck(1)
return true
–check to make sure it's an egg, if not return false
end
function getCaneSugar()
print("Getting Cane")
turtle.select(6)
turtle.suck(2)
print("preCraft")
turtle.craft()
print("postCraft")
turtle.transferTo(8, 1)
return true
end
function getWheat()
print("Getting Wheat")
turtle.select(10)
turtle.suck(1)
turtle.select(11)
turtle.suck(1)
turtle.select(12)
turtle.suck(1)
–double check it's wheat
return true
end
function makeCake()
print("Making Cake")
turtle.select(1)
turtle.craft()
–make sure cake passed
turtle.dropDown()
return true
end
function dumpBuckets()
print("Putting things where they belong.")
turtle.select(2)
turtle.drop()
turtle.select(3)
turtle.drop()
turtle.select(4)
turtle.drop()
end
function makeCakes()
print("Putting that culinary degree to good use.")
–make a cake
local milk = false
local eggs = false
local cane = false
local wheat = false
cane = getCaneSugar()
if cane==true then
turtle.turnRight()
eggs = getEggs()
if eggs == true then
turtle.turnRight()
milk = getMilk()
if milk == true then
turtle.turnRight()
wheat = getWheat()
if wheat == true then
turtle.turnLeft()
makeCake()
dumpBuckets()
turtle.turnRight()
turtle.turnRight()
end
end
end
end
fiveCakes() –enable when program is ready.
end
function fiveCakes()
–try to pull 5 cakes from underChest
turtle.select(1)
turtle.suckDown(5)
–put a cake-detecting method in here
local cakeCount = turtle.getItemCount(1)
turtle.dropDown(5)
if cakeCount>4 then
print("We have enough cakes, already!")
os.sleep(60)
fiveCakes() –enable when program is ready.
else
makeCakes()
end
end
fiveCakes()