Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- slot= 1
- turtle.select(slot)
- --This function is placed before every place block to check if the turtle is out of inventory, if the first slot is empty it will swap to the next slot
- function autoswap()
- while turtle.getItemCount(slot) == 0 do
- slot = slot+ 1
- if slot == 16 then print("Too much") break end
- turtle.select(slot)
- end
- end
- --Scan takes an array and attempts to append the name of the material in front of it, and keep count of it. If the material already exists then it adds one to the count. The next two following functions do the same thing but scan up or down.
- function scan(n)
- print("hey I'm starting")
- x, y= turtle.inspect()
- material= y.name
- for i=1, #(n[1]) do
- if n[1][i] == material then
- n[2][i]= n[2][i]+1
- print("old material")
- return n
- end
- end
- tempEnd= #(n[1])+1
- n[1][tempEnd]= material
- n[2][tempEnd]= 1
- print("new material")
- return n
- end
- function scanUp(n)
- print("hey I'm starting")
- x, y= turtle.inspectUp()
- material= y.name
- for i=1, #(n[1]) do
- if n[1][i] == material then
- n[2][i]= n[2][i]+1
- print("old material")
- return n
- end
- end
- tempEnd= #(n[1])+1
- n[1][tempEnd]= material
- n[2][tempEnd]= 1
- print("new material")
- return n
- end
- function scanDown(n)
- print("hey I'm starting")
- x, y= turtle.inspectDown()
- material= y.name
- for i=1, #(n[1]) do
- if n[1][i] == material then
- n[2][i]= n[2][i]+1
- print("old material")
- return n
- end
- end
- tempEnd= #(n[1])+1
- n[1][tempEnd]= material
- n[2][tempEnd]= 1
- print("new material")
- return n
- end
- --loops through a given array and prints out the name of the material, and the associated count
- function display(n)
- print(" ")
- for i=1, #(n[1]) do
- print(n[1][i] .. " ".. n[2][i])
- end
- end
- --Must be used in order to save your array for later
- function saveCount(n, name)
- file= io.open(name, "w")
- for i=1, #(n[1]) do
- file:write(n[1][i].. "\n".. n[2][i].. "\n")
- end
- file:close()
- end
- --Loads another file as an array
- function loadCount(dataName)
- file= io.open(dataName, "r")
- local lineNumber= 1
- local mats= {}
- local matCounts= {}
- local count= 1
- for line in file:lines() do
- if lineNumber%2 == 1 then
- mats[count]= line
- else
- matCounts[count]= tonumber(line)
- count= count +1
- end
- lineNumber= lineNumber+1
- end
- return {mats, matCounts}
- end
- function barGraph(input)
- -- Find the max height and make that the height of the bar graph then reset to original spot
- max= 1
- for i=1, #(input[2]) do
- if max< input[2][i] then max= input[2][i] end
- end
- autoswap()
- turtle.place()
- for i=1, max do
- turtle.up()
- autoswap()
- turtle.place()
- end
- while not turtle.detectDown() do turtle.down() end
- --Position self to place directly down and do movement make horizontal axis
- turtle.turnRight()
- turtle.forward()
- turtle.turnLeft()
- turtle.up()
- turtle.forward()
- turtle.turnRight()
- for i=1, #(input[2])*2 do
- autoswap()
- turtle.placeDown()
- turtle.forward()
- end
- --Reset position and be ready to place bars
- for i=1, #(input[2])*2 do turtle.back() end
- turtle.turnRight()
- turtle.forward()
- turtle.down()
- turtle.turnLeft()
- turtle.forward()
- turtle.turnLeft()
- --bar graphs
- for i=1, #(input[2]) do
- for height= 1, input[2][i] do
- turtle.up()
- autoswap()
- turtle.place()
- end
- while not turtle.detectDown() do turtle.down() end
- turtle.back()
- turtle.select(16)
- material= input[1][i]
- material= string.sub(material,11,-1)
- turtle.place(material)
- turtle.select(slot)
- turtle.turnRight()
- turtle.forward()
- turtle.forward()
- turtle.turnLeft()
- turtle.forward()
- end
- end
- list = loadCount(myData)
- barGraph(list)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement