Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function exchange(list,y,page)
- w,h = term.getSize()
- y=y+(h-1)*(page-1)
- local l = list[y]
- if y<=#list then
- --/execute if entity @p[nbt={Inventory:[{id:"",Count:b}]}]
- invcheck = "execute unless entity @p[nbt={Inventory:[{id:\""..l[1].."\",Count:"..l[2].."b}]}] run "
- checkstr = "execute if entity @p[nbt={Inventory:[{id:\""..l[1].."\",Count:"..l[2].."b}]}] run "
- exec(checkstr.."give @p "..l[3].." "..l[4])
- exec(checkstr.."tellraw @p {\"text\":\"Success!\",\"color\":\"green\"}")
- exec(invcheck.."tellraw @p {\"text\":\"Items not found! Make sure specified amount of items is in a separate slot.\",\"color\":\"red\"}")
- exec(checkstr.."clear @p "..l[1].." "..l[2])
- end
- end
- function draw(list,page)
- term.redirect(peripheral.wrap("top"))
- peripheral.wrap("top").setTextScale(0.5)
- term.clear()
- term.setCursorPos(1,1)
- w,h = term.getSize()
- pages = 1
- if h>#list then
- pages = math.floor(#list/(h-1))
- end
- for i=1+(h-1)*(page-1),(h-1)*page do
- if i>#list then break end
- print(list[i][2].." "..list[i][1].." -> "..list[i][4].." "..list[i][3])
- end
- term.setCursorPos(1,h)
- write("<<<")
- term.setCursorPos(math.floor(w/2),h)
- write(page)
- term.setCursorPos(w-2,h)
- write(">>>")
- end
- --------------+
- page = 1 --+#
- table = {} --+#
- --------------+
- table[1] = {"minecraft:polished_diorite",1,"minecraft:stone",6}
- table[2] = {"minecraft:stone",2,"minecraft:dirt",1}
- ---------------
- draw(table,page)
- while true do
- name,side,x,y = os.pullEvent("monitor_touch")
- w,h = term.getSize()
- if y<h then
- exchange(table,y,page)
- else
- if x<w/2 then
- page=page-1
- if page<1 then
- page = math.ceil(#table/(h-1))
- end
- else
- page=page+1
- if page>math.ceil(#table/(h-1)) then
- page = 1
- end
- end
- end
- draw(table,page)
- end
Add Comment
Please, Sign In to add comment