Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- dropApple = true
- dropPaper = true
- dropCookie = true
- dropFish = false
- function dropUp()
- count = turtle.getItemCount()
- if count > 0 then
- if turtle.dropUp() == false then
- term.clear()
- term.setCursorPos(1,1)
- print("Inventory full.")
- repeat
- sleep(0.5)
- until turtle.dropUp()
- end
- end
- end
- function scanInv()
- for i = 1, 16 do
- data = turtle.getItemDetail(i)
- if data then
- if data.name == "minecraft:paper" and dropPaper == true then
- turtle.select(i)
- turtle.dropDown()
- elseif data.name == "minecraft:apple" and dropApple == true then
- turtle.select(i)
- turtle.dropDown()
- elseif data.name == "minecraft:cookie" and dropCookie == true then
- turtle.select(i)
- turtle.dropDown()
- elseif data.name == "minecraft:pufferfish" and dropFish == true then
- turtle.select(i)
- turtle.dropDown()
- elseif data.name ~= "minecraft:barrel" then
- turtle.select(i)
- dropUp()
- end
- end
- end
- end
- function findItem(item)
- for i = 1, 16 do
- local data = turtle.getItemDetail(i)
- if data then
- if data.name == item then
- turtle.select(i)
- end
- end
- end
- end
- function centerText(monitor, y, text)
- local w, h = monitor.getSize()
- local x = math.floor((w - string.len(text) + 2) / 2)
- monitor.setCursorPos(x , y)
- print(text)
- end
- function findBarrelCount()
- barrelCount = 0
- for i = 1, 16 do
- local data = turtle.getItemDetail(i)
- if data then
- if data.name == "minecraft:barrel" then
- barrelCount = barrelCount + 1
- end
- end
- end
- return barrelCount
- end
- function saveCounter(number)
- local file = io.open("counter", "w") -- open file in write mode
- file:write(number) -- write number to file
- file:close() -- close file
- end
- function readCounter()
- local file = io.open("counter", "r") -- open file in read mode
- if file then
- local number = tonumber(file:read("*all")) -- read the entire file as a string and convert to a number
- file:close() -- close file
- return number
- else
- return nil -- file doesn't exist or couldn't be opened
- end
- end
- function formatNumber(number)
- local formatted = tostring(number)
- local k = #formatted % 3
- if k == 0 then k = 3 end
- formatted = formatted:sub(1, k) .. formatted:sub(k+1):gsub("(%d%d%d)", ".%1")
- return formatted
- end
- function identifySpecialBarrel(slot)
- local data = turtle.getItemDetail(slot, true)
- if data then
- if data.name == "minecraft:barrel" then
- if data.lore then
- return true
- else
- return false
- end
- else
- print("No Barrel")
- end
- end
- end
- local file = io.open("counter", "r")
- if not file then
- file = io.open("counter", "w")
- file:write("1")
- file:close()
- end
- cycleCount = readCounter()
- while true do
- term.clear()
- term.setCursorPos(1,1)
- cycleCount = readCounter()
- term.setTextColor(colors.yellow)
- centerText(term, 4, "Currently running cycle")
- term.setTextColor(colors.green)
- displayCount = formatNumber(cycleCount)
- centerText(term, 7, displayCount)
- local bool, blockFront = turtle.inspect()
- if blockFront.name ~= "minecraft:barrel" then
- findItem("minecraft:barrel")
- slot = turtle.getSelectedSlot()
- if identifySpecialBarrel(slot) == true then
- turtle.place()
- turtle.select(1)
- end
- else
- turtle.select(1)
- repeat until turtle.suck() == false
- scanInv()
- if turtle.dig() then
- cycleCount = cycleCount + 1
- saveCounter(cycleCount)
- else
- print("Stuff went sideways.")
- end
- end
- for i = 1, 2 do
- findItem("minecraft:barrel")
- slot = turtle.getSelectedSlot()
- if identifySpecialBarrel(slot) == true then
- turtle.place()
- else
- dropUp()
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement