Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- --------
- -- farmer
- -- --------
- local function showUsage()
- print("slot1 : melon x 1")
- print("slot2 : pumpkin x 1")
- print("slot3 : potato x 1")
- print("slot4 : carrot x 1")
- print("slot5 : wheat x 1")
- print("slot6 : seeds x 1")
- print("slot7 : poisonous potato x 1")
- end
- -- --------
- --
- -- --------
- local f = function() while not turtle.forward() do end end
- local b = function() while not turtle.back() do end end
- local l = turtle.turnLeft
- local r = turtle.turnRight
- local u = function() while not turtle.up() do end end
- local d = function() while not turtle.down() do end end
- local e2 = turtle.digDown -- excavate
- local p2 = turtle.placeDown
- local sel = turtle.select
- function vacuum(slotNo)
- local result = false
- turtle.select(slotNo)
- for i = 1, 16 do
- if slotNo ~= i and turtle.compareTo(i) and 1 < turtle.getItemCount(i) then
- turtle.select(i)
- turtle.transferTo(slotNo, turtle.getItemSpace(slotNo))
- result = true
- if 0 == turtle.getItemSpace(slotNo) then
- break
- end
- turtle.select(slotNo)
- end
- end
- turtle.select(slotNo)
- return result
- end
- local function makeVacuumFunc(slotNo)
- return function()
- if 1 == turtle.getItemCount(slotNo) then
- vacuum(slotNo)
- end
- end
- end
- local v3 = makeVacuumFunc(3)
- local v4 = makeVacuumFunc(4)
- local v6 = makeVacuumFunc(6)
- local function getTotal(slotNo)
- local cnt = turtle.getItemCount(slotNo)
- turtle.select(slotNo)
- for i=1,16 do
- if i ~= slotNo and turtle.compareTo(i) then
- cnt = cnt + turtle.getItemCount(i)
- end
- end
- return cnt
- end
- local function dropDownExceptK(slotNo, dropCnt, keepCnt)
- local function slotAction(i, mustKeep, mustDrop, slotNo)
- local cnt = turtle.getItemCount(i)
- if mustKeep < cnt then
- local dropAble = cnt - mustKeep
- local nowDrop = math.min(dropAble, mustDrop)
- mustKeep = 0
- mustDrop = mustDrop - nowDrop
- turtle.select(i)
- turtle.dropDown(nowDrop)
- turtle.select(slotNo)
- else
- mustKeep = mustKeep - cnt
- end
- end
- turtle.select(slotNo)
- local mustKeep = keepCnt
- local mustDrop = dropCnt
- for i=1,16 do
- if i ~= slotNo and turtle.compareTo(i) then
- slotAction(i, mustKeep, mustDrop, slotNo)
- end
- end
- vacuum(slotNo)
- slotAction(slotNo, mustKeep, mustDrop, slotNo)
- end
- local function dropDownExcept1(slotNo)
- turtle.select(slotNo)
- turtle.dropDown(turtle.getItemCount()-1)
- for i=1,16 do
- if i ~= slotNo and turtle.compareTo(i) then
- turtle.select(i)
- turtle.dropDown()
- turtle.select(slotNo)
- end
- end
- vacuum(slotNo)
- end
- local function dropDownHalf(slotNo)
- turtle.select(slotNo)
- local c = turtle.getItemCount(slotNo)
- turtle.dropDown((c-1)/2)
- for i=1,16 do
- if i~=slotNo and turtle.compareTo(i) then
- turtle.select(i)
- c = turtle.getItemCount(i)
- turtle.dropDown(c/2)
- turtle.select(slotNo)
- end
- end
- end
- local function exec(...)
- for i = 1, select("#", ...) do
- local sbj = select(i, ...)
- if "function" == type(sbj) then
- sbj()
- elseif "table" == type(sbj) then
- for j, f in ipairs(sbj) do
- f()
- end
- end
- end
- end
- local function rep(num, ...)
- local ret = {}
- for i = 1, num do
- for j = 1, select("#", ...) do
- local sbj = select(j, ...)
- if "function" == type(sbj) then
- table.insert(ret, sbj)
- elseif "table" == type(sbj) then
- for j, f in ipairs(sbj) do
- table.insert(ret, f)
- end
- end
- end
- end
- return ret
- end
- -- --------
- -- main
- -- --------
- while true do
- -- refuel
- exec(u,f,f)
- sel(16)
- turtle.suckUp(3)
- turtle.refuel()
- exec(b)
- -- meron
- sel(1)
- exec(rep(11,e2,f),e2)
- sel(2) -- pumpkin
- exec(r,f,f,f,r)
- exec(rep(11,e2,f))
- exec(e2)
- -- potato
- sel(3)
- exec(r,r,rep(4,f),r,f)
- local potato = {e2,v3,p2}
- exec(
- rep(2,
- rep(7,potato,f),potato,l,f,l,
- rep(7,potato,f),potato,r,f,r
- )
- )
- sel(4)
- local carrot = {e2,v4,p2}
- exec(l)
- exec(
- rep(4,
- rep(3,carrot,f),carrot,r,f,r,
- rep(3,carrot,f),carrot,l,f,l
- )
- )
- sel(6)
- local wheat = {e2,v6,p2}
- exec(f,f,f,r)
- exec(
- rep(4,
- rep(3,wheat,f),wheat,r,f,r,
- rep(3,wheat,f),wheat,l,f,l
- )
- )
- exec(f,f,f,l,l)
- exec(
- rep(2,
- rep(11,wheat,f),wheat,l,f,l,
- rep(11,wheat,f),wheat,r,f,r
- )
- )
- exec(l)
- exec(
- rep(4,
- rep(2,wheat,f),wheat,r,f,r,
- rep(2,wheat,f),wheat,l,f,l
- )
- )
- exec(d,f,f,f,l)
- -- melon
- dropDownExcept1(1)
- exec(f)
- -- pumpkin
- dropDownExcept1(2)
- exec(f)
- -- potato
- dropDownExcept1(3)
- exec(f)
- -- carrot
- dropDownHalf(4)
- exec(f)
- -- seeds
- local tc = getTotal(6)
- dropDownExceptK(6, math.max(0, (tc-16)/2), 32)
- --dropDownHalf(6)
- exec(f)
- -- wheat
- dropDownHalf(5)
- exec(f)
- -- seeds (animal food)
- tc = getTotal(6)
- dropDownExceptK(6, math.max(0, (tc-16)/2), 32)
- --dropDownExcept1(6)
- exec(f)
- -- carrot (animal food)
- dropDownExcept1(4)
- exec(f)
- -- wheat (animal food)
- dropDownExcept1(5)
- exec(l,l,rep(8,f),r,f,f)
- -- poisonous potato
- dropDownExcept1(7)
- exec(f,l,rep(7,f),r)
- print("fuelLv : " .. tostring(turtle.getFuelLevel()))
- for i = 0,9 do
- for j = 0,9 do
- local cnt = 99 - (i * 10 + j)
- term.write(tostring(cnt) .. " ")
- os.sleep(12)
- end
- print()
- end
- print("go!!!")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement