Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Farmer needs a 10x10 prepared plot and storage chests structure
- local function isItemSlot(slotToCheck,itemType,exactMatch)
- --slotToCheck: numeric, slot to examine
- --itemType: string, base item type example "log","coal","sapling"
- --[exactMatch]: boolean, item type must be exact, i.e. "minecraft:wheat"
- local rc = false
- if exactMatch == nil then exactMatch = false end
- blockInfo = turtle.getItemDetail(slotToCheck)
- if blockInfo then
- --if item then return true
- if exactMatch == false then
- if string.find(blockInfo.name,itemType) ~= nil then
- rc = true
- end
- else
- if blockInfo.name == itemType then
- rc = true
- end
- end
- end
- return rc
- end
- local function getItemSlot(itemType, exactMatch)
- --returns slot with item or -1 if no item found
- --itemType: string, type of item example"log","coal","sapling"
- --[exactMatch]: boolean, item type must be exact, i.e. "minecraft:wheat"
- if exactMatch == nil then exactMatch = false end
- for x = 1,16 do
- if isItemSlot(x,itemType,exactMatch) then
- return x
- end
- end
- return -1
- end
- local function itemInventoryCount(itemType)
- local total = 0
- local current = 0
- for slot = 1, 16 do
- current = turtle.getItemCount(slot)
- if current > 0 then
- if isItemSlot(slot,itemType) then
- total = total + current
- end
- end
- end
- return total
- end
- local function dropExcessSeeds()
- local overage = 0
- local dropAmt = 0
- local x = 0
- local seedCnt = 0
- --try to load
- seedCnt = itemInventoryCount("seeds")
- while seedCnt > 120 do
- overage = seedCnt - 120
- x = getItemSlot("seeds")
- if x == -1 then
- --can't find any so how is count > 180 ????
- else
- turtle.select(x)
- slotAmt = turtle.getItemCount(x)
- if (overage) >= slotAmt then
- dropAmt = slotAmt
- else
- dropAmt = overage
- end
- turtle.drop(dropAmt)
- end
- seedCnt = seedCnt - dropAmt
- end
- end
- local function fuelSelf(minFuel)
- --min fuel is number representing the minimum amount of fuel we want turtle to have at start of this process
- local rc = false
- if turtle.getFuelLevel() < minFuel then
- --only burn coal
- x = getItemSlot("coal")
- if x ~= -1 then
- turtle.select(x)
- if turtle.refuel() then
- rc = true
- end
- end
- else
- --fuel above minimum so return true
- rc = true
- end
- return rc
- end
- --*********************MAIN PROGRAM CODE***************
- local action = ""
- --see colCnt parameter at top of file, this sets how many columns to travel
- print("CropFarm requires 10X10 area of dirt and either flax or wheat seeds")
- print("Place coal and seeds in any slot")
- sleep(3)
- if _G["mta"] == false then
- error("MTA API not loaded.")
- end
- local success = false
- local info
- local xSlot
- while true do
- if fuelSelf(200) == false then
- print("Low fuel level!")
- while fuelSelf(200) == false do
- sleep(4)
- end
- end
- print("Fuel: "..tostring(turtle.getFuelLevel()))
- for cols = 1,10 do
- if cols == 1 then
- mta.forward()
- end
- for rows = 1,10 do
- success, info = turtle.inspectDown()
- if success then
- --if wheat or flax then is it ready to harvest
- if (info.name == "minecraft:wheat") or (info.name == "yegamolchattels:flax_plant") then
- if info.metadata == 7 then
- --harvest it
- turtle.digDown()
- local seedSlot = getItemSlot("seeds")
- if seedSlot > -1 then
- turtle.select(seedSlot)
- turtle.placeDown()
- end
- end
- else
- --not sure what to do here?
- end
- else
- --nothing there so till and plant
- turtle.digDown()
- local seedSlot = getItemSlot("seeds")
- if seedSlot > -1 then
- turtle.select(seedSlot)
- turtle.placeDown()
- end
- end
- if rows < 10 then
- mta.forward()
- end
- end
- --on last column head towards storage otherwise continue on
- if cols ~= 10 then
- if math.fmod(cols,2) ~= 0 then
- turtle.turnRight()
- mta.forward()
- turtle.turnRight()
- else
- turtle.turnLeft()
- mta.forward()
- turtle.turnLeft()
- end
- else
- mta.forward(1)
- turtle.turnRight()
- mta.forward(9)
- end
- end
- --drop anything over 120 seeds
- turtle.turnLeft()
- dropExcessSeeds()
- --drop all wheat into chest
- turtle.turnRight()
- xSlot = getItemSlot("minecraft:wheat", true)
- while xSlot > -1 do
- turtle.select(xSlot)
- turtle.drop()
- xSlot = getItemSlot("minecraft:wheat", true)
- end
- --drop all flax fiber
- xSlot = getItemSlot(":flax_fiber")
- while xSlot > -1 do
- turtle.select(xSlot)
- turtle.drop()
- xSlot = getItemSlot("flax_fiber")
- end
- turtle.turnRight()
- --get ready to do it all again at 6 am
- local alarm = os.setAlarm(6)
- local sleepyTime = true
- while sleepyTime do
- local evt, arg = os.pullEvent("alarm")
- if arg == alarm then
- sleepyTime = false
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement