SHOW:
|
|
- or go back to the newest paste.
1 | function exchange(list,y,page) | |
2 | w,h = term.getSize() | |
3 | y=y+(h-1)*(page-1) | |
4 | local l = list[y] | |
5 | if y<=#list then | |
6 | --/execute if entity @p[nbt={Inventory:[{id:"",Count:b}]}] | |
7 | invcheck = "execute unless entity @p[nbt={Inventory:[{id:\""..l[1].."\",Count:"..l[2].."b}]}] run " | |
8 | checkstr = "execute if entity @p[nbt={Inventory:[{id:\""..l[1].."\",Count:"..l[2].."b}]}] run " | |
9 | exec(checkstr.."give @p "..l[3].." "..l[4]) | |
10 | exec(checkstr.."tellraw @p {\"text\":\"Success!\",\"color\":\"green\"}") | |
11 | exec(invcheck.."tellraw @p {\"text\":\"Items not found! Make sure specified amount of items is in a separate slot.\",\"color\":\"red\"}") | |
12 | exec(checkstr.."clear @p "..l[1].." "..l[2]) | |
13 | end | |
14 | end | |
15 | function draw(list,page) | |
16 | term.redirect(peripheral.wrap("top")) | |
17 | peripheral.wrap("top").setTextScale(0.5) | |
18 | term.clear() | |
19 | term.setCursorPos(1,1) | |
20 | w,h = term.getSize() | |
21 | pages = 1 | |
22 | if h>#list then | |
23 | pages = math.floor(#list/(h-1)) | |
24 | end | |
25 | for i=1+(h-1)*(page-1),(h-1)*page do | |
26 | if i>#list then break end | |
27 | print(list[i][2].." "..list[i][1].." -> "..list[i][4].." "..list[i][3]) | |
28 | end | |
29 | term.setCursorPos(1,h) | |
30 | write("<<<") | |
31 | term.setCursorPos(math.floor(w/2),h) | |
32 | write(page) | |
33 | term.setCursorPos(w-2,h) | |
34 | write(">>>") | |
35 | end | |
36 | --------------+ | |
37 | page = 1 --+# | |
38 | table = {} --+# | |
39 | --------------+ | |
40 | table[1] = {"minecraft:polished_diorite",1,"minecraft:stone",6} | |
41 | table[2] = {"minecraft:stone",2,"minecraft:dirt",1} | |
42 | --------------- | |
43 | draw(table,page) | |
44 | while true do | |
45 | name,side,x,y = os.pullEvent("monitor_touch") | |
46 | w,h = term.getSize() | |
47 | if y<h then | |
48 | exchange(table,y,page) | |
49 | else | |
50 | if x<w/2 then | |
51 | page=page-1 | |
52 | if page<1 then | |
53 | page = math.ceil(#table/(h-1)) | |
54 | end | |
55 | else | |
56 | page=page+1 | |
57 | if page>math.ceil(#table/(h-1)) then | |
58 | page = 1 | |
59 | end | |
60 | end | |
61 | end | |
62 | draw(table,page) | |
63 | end |