Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- cur_lvl = 0
- cur_dir = 0
- items = {}
- function save(t, n)
- local file = fs.open(n, "w")
- file.write(textutils.serialize(t))
- file.close()
- end
- function load(n)
- local file = fs.open(n, "r")
- local data = file.readAll()
- file.close()
- return textutils.unserialize(data)
- end
- function equals(i1, i2)
- return i1.name == i2.name and i1.damage == i2.damage
- end
- function contains(t, i)
- for n, v in pairs(t) do
- if equals(v, i) then
- return n
- end
- end
- return 0
- end
- function go_to(lvl, dir)
- while cur_lvl > lvl do
- turtle.down()
- cur_lvl = cur_lvl - 1
- end
- while cur_lvl < lvl do
- turtle.up()
- cur_lvl = cur_lvl + 1
- end
- turn = cur_dir - dir
- for i=1, (turn + 4) % 4 do
- turtle.turnRight()
- end
- cur_dir = dir
- end
- function add_item(item)
- n = contains(items, item)
- if n == 0 then
- v = {name = item.name, count = item.count, damage = item.damage}
- v.level = math.floor(#items / 4) + 1
- v.dir = #items % 4
- table.insert(items, v)
- go_to(-v.level, v.dir)
- turtle.drop()
- else
- go_to(0, 0)
- turtle.drop()
- amt = turtle.getItemCount()
- items[n].count = items[n].count + item.count - amt
- turtle.dropDown()
- end
- end
- function deposit_items()
- for i=1, 16 do
- turtle.select(i)
- item = turtle.getItemDetail()
- if item then
- add_item(item)
- end
- end
- go_to(0, 0)
- end
- while true do
- if turtle.suckUp() then
- sleep(3)
- while turtle.suckUp() do
- end
- deposit_items()
- end
- end
- --items = {}
- --items["diamond_sword"] = 2
- --items["iron_axe"] = 6
- --items["iron_sword"] = 8
- --
- --search = io.read()
- --print("Searching...")
- --
- --top_result = nil
- --for k, v in pairs(items) do
- -- r = string.find(k, search)
- -- if r then
- -- x = string.len(k) + r
- -- if not top_result or x < top_result.val then
- -- top_result = {name=k,deets=v,val = x}
- -- end
- -- end
- --end
- --print(top_result.name)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement