Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local slot = {
- "input", --1
- "bow",
- "unbreaking_1", --3
- "unbreaking_2", --4
- "unbreaking_3", --5
- "punch_1", --6
- "power_1", --7
- "power_2", --8
- "power_3", --9
- }
- local function isChestCasual(data)
- return data
- and data.name=="minecraft:chest"
- and data.state.facing=="north"
- end
- local function isChestUsual(data)
- return data
- and data.name=="minecraft:chest"
- and data.state.facing=="east"
- end
- local function isChestUnusual(data)
- return data
- and data.name=="minecraft:chest"
- and data.state.facing=="south"
- end
- local function facingChestCasual()
- local test,data=turtle.inspect()
- if isChestCasual(data) then return end
- if isChestUsual(data) then return turtle.turnLeft() end
- if isChestUnusual(data) then
- turtle.turnRight()
- end
- turtle.turnRight()
- end
- local function facingChestUsual()
- local test,data=turtle.inspect()
- if isChestUsual(data) then return end
- if isChestUnusual(data) then return turtle.turnLeft() end
- if not test then
- turtle.turnRight()
- end
- turtle.turnRight()
- end
- local function facingChestUnusual()
- local test,data=turtle.inspect()
- if isChestUnusual(data) then return end
- if not test then return turtle.turnLeft() end
- if isChestCasual(data) then
- turtle.turnRight()
- end
- turtle.turnRight()
- end
- local function output(str,line)
- term.setCursorPos(1,line)
- term.clearLine()
- term.write(str)
- end
- local function compare()
- turtle.select(1)
- local s
- for s=2,#slot do
- if turtle.compareTo(s) then
- return slot[s]
- end
- end
- return false
- end
- local function clean()
- if #slot >= 16 then return end
- local s
- for s = (#slot+1),16 do
- if turtle.getItemCount(s)>0 then
- turtle.select(s)
- turtle.transferTo(1)
- turtle.select(1)
- return
- end
- end
- end
- term.setCursorPos(1,1)
- term.clear()
- print(string.format("#%d %s",
- os.getComputerID(),
- os.getComputerLabel()))
- local t = os.startTimer(.1)
- while true do
- turtle.select(1)
- output("",3)
- output("",4)
- local e,p = os.pullEvent()
- os.cancelTimer(t)
- if e=="turtle_inventory" or turtle.getItemCount(1)>0 then
- output("Manage inventory",2)
- local test = compare()
- output("manage inventory: "..(test and test or "unknown"),3)
- if not test then
- --unusual enchant
- output("Unusual bow",4)
- facingChestUnusual()
- turtle.drop()
- elseif test=="bow" then
- --casual bow
- output("Casual bow",4)
- facingChestCasual()
- turtle.drop()
- else
- --usual enchant
- output("Usual enchanted bow",4)
- facingChestUsual()
- turtle.drop()
- end
- elseif e=="timer" and p==t then
- --print time
- output(string.format("running: %d",math.floor(os.clock())),2)
- elseif e=="terminate" then
- print("")
- end
- clean()
- t = os.startTimer(1)
- end
Advertisement
Add Comment
Please, Sign In to add comment