Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- dofile("turtleMoveApi")
- function randomPlaceDown()
- local slots = { 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16 }
- for i = 1, 16 do
- local j = math.random(i, 16)
- slots[i], slots[j] = slots[j], slots[i]
- end
- for i = 1, 16 do
- if 0 < turtle.getItemCount(slots[i]) then
- turtle.select(slots[i])
- local rslt = turtle.placeDown()
- if true == rslt then
- break
- end
- end
- end
- end
- function harvestAndRandomPlaceDown()
- turtle.select(1)
- e2()
- e2()
- randomPlaceDown()
- end
- function test()
- if false == turtle.detectDown() then
- e2()
- randomPlaceDown()
- end
- -- https://github.com/kssr3951/NichePeripherals
- -- metascanner
- local w = peripheral.wrap("right")
- local ret, code = w.scanDown()
- if true == ret then
- if code == "0Q7WXFt!R6Kgeo45WciNOw00" then
- harvestAndRandomPlaceDown() -- rice
- elseif code == "v6hCMTVVntvJvQOK8hr59M00" then
- harvestAndRandomPlaceDown() -- bean
- elseif code == "tbBElJYibHzxRE5vJ1XJnM00" then
- harvestAndRandomPlaceDown() -- wheat
- elseif code == "IWUgHfKk7HrzAxaySVFdv000" then
- harvestAndRandomPlaceDown() -- soybeans
- elseif code == "SYzSqeOm3QkJhJEWx8cfy000" then
- harvestAndRandomPlaceDown() -- tomato
- elseif code == "pMn3UATm9wmDPwlrnH!V8000" then
- harvestAndRandomPlaceDown() -- carrot
- elseif code == "k3APXY8iRQ5UCAwhhnPYs000" then
- harvestAndRandomPlaceDown() -- potato
- end
- end
- end
- local function getSameItemCount(slot)
- local cnt = turtle.getItemCount(slot)
- if 0 == cnt then
- return 0
- end
- turtle.select(slot)
- cnt = 0
- local slotList = { }
- for i = 1, 16 do
- if true == turtle.compareTo(i) then
- cnt = cnt + turtle.getItemCount(i)
- table.insert(slotList, 1, i)
- end
- end
- return cnt, slotList
- end
- function dumpHalf()
- local doneList = { }
- for i = 1, 16 do
- local cnt, slotList = getSameItemCount(i)
- if 0 < cnt and nil == doneList[i] then
- local remain = math.floor(cnt / 2)
- for _, j in ipairs(slotList) do
- doneList[j] = true
- end
- for _, j in ipairs(slotList) do
- turtle.select(j)
- local dropCnt = math.min(remain, turtle.getItemCount(j))
- turtle.dropDown(dropCnt)
- remain = remain - dropCnt
- if remain <= 0 then
- break
- end
- end
- end
- end
- end
- function refuel()
- local refuelDone = false
- for i = 1, 16 do
- if 0 == turtle.getItemCount(i) then
- turtle.select(i)
- turtle.suckDown(15)
- turtle.refuel(15)
- refuelDone = true
- break
- end
- end
- if not refuelDone then
- for i = 1, 16 do
- vacuum(i)
- for j = 1, 16 do
- if 0 == turtle.getItemCount(j) then
- turtle.select(j)
- turtle.suckDown(15)
- turtle.refuel(15)
- return
- end
- end
- end
- end
- end
- function displayFuelLevel()
- print("fuelLevel = " .. tostring(turtle.getFuelLevel()))
- debug("fuelLevel = " .. tostring(turtle.getFuelLevel()))
- end
- registFunction("test", test)
- registFunction("dumpHalf", dumpHalf)
- registFunction("refuel", refuel)
- registFunction("displayFuelLevel", displayFuelLevel)
- -- ------------------------------------
- -- main
- -- ------------------------------------
- debug("----------------------------------------")
- debug("-- 1ckFarmer2")
- debug("----------------------------------------")
- registScript(
- rep(256,
- displayFuelLevel,
- rep(4,
- rep(16,
- rep(15,test,f),
- test,
- breakLast,
- swOddEven({r,f,r},{l,f,l})
- ),
- r,rep(7,f),r,rep(7,f),
- anotherLast(
- {d,dumpHalf,u},
- {d,f,dumpHalf,b,refuel,u}
- ),
- r,rep(7,f),r,rep(7,f),
- r,
- rep(4,u),
- rep(4,rep(40,l),d)
- )
- )
- )
- loadData()
- executeScript()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement