AdditionalPylons

fixed cc shop (1.21.1)

Mar 26th, 2026
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.85 KB | None | 0 0
  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.         local r,s = commands.clear("@p "..l[1].." "..l[2])
  7.         local n = tonumber(string.match(s[1], "%s%d+%s"))
  8.         if not r or n~=l[2] then
  9.             commands.tellraw("@p {\"text\":\"Insufficient items.\",\"color\":\"red\"}")
  10.             if n then commands.give("@p "..l[1].." "..n) end
  11.         else
  12.             commands.tellraw("@p {\"text\":\"Success!\",\"color\":\"green\"}")
  13.             commands.give("@p "..l[3].." "..l[4])
  14.         end
  15.     end
  16. end
  17. function draw(list,page)
  18.     term.redirect(peripheral.wrap("top"))
  19.     peripheral.wrap("top").setTextScale(0.5)
  20.     term.clear()
  21.     term.setCursorPos(1,1)
  22.     w,h = term.getSize()
  23.     pages = 1
  24.     if h>#list then
  25.         pages = math.floor(#list/(h-1))
  26.     end
  27.     for i=1+(h-1)*(page-1),(h-1)*page do
  28.         if i>#list then break end
  29.         print(list[i][2].." "..list[i][1].." -> "..list[i][4].." "..list[i][3])
  30.     end
  31.     term.setCursorPos(1,h)
  32.     write("<<<")
  33.     term.setCursorPos(math.floor(w/2),h)
  34.     write(page)
  35.     term.setCursorPos(w-2,h)
  36.     write(">>>")
  37. end
  38. --------------+
  39. page = 1   --+#
  40. table = {} --+#
  41. --------------+
  42. table[1] = {"minecraft:polished_diorite",1,"minecraft:stone",6}
  43. table[2] = {"minecraft:stone",2,"minecraft:dirt",1}
  44. ---------------
  45. draw(table,page)
  46. while true do
  47.     name,side,x,y = os.pullEvent("monitor_touch")
  48.     w,h = term.getSize()
  49.     if y<h then
  50.         exchange(table,y,page)
  51.     else
  52.         if x<w/2 then
  53.             page=page-1
  54.             if page<1 then
  55.                 page = math.ceil(#table/(h-1))
  56.             end
  57.         else
  58.             page=page+1
  59.             if page>math.ceil(#table/(h-1)) then
  60.                 page = 1
  61.             end
  62.         end
  63.     end
  64.     draw(table,page)
  65. end
Advertisement
Add Comment
Please, Sign In to add comment