Dojnaz

CC Ender Chest Touch Coder

Oct 29th, 2020 (edited)
759
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local mon = peripheral.wrap("monitor_59")
  2. local eChestSide = "right"
  3.  
  4. function sleepASec()
  5.   sleep(1)
  6. end
  7.  
  8. function touchPull()
  9.   event, side, x, y = os.pullEvent("monitor_touch")
  10.   print(x, ",", y)
  11.   if (not (math.fmod(x-1,6) > 4)) then
  12.     if (not (y > 16)) then
  13.       slot = (x-math.fmod(x,6))/6
  14.       print("Slot ", slot)
  15.       if (not (chest == nil)) then
  16.         a,b,c = chest.getColors()
  17.         if (slot == 0) then a = math.pow(2, y-1) end
  18.         if (slot == 1) then b = math.pow(2, y-1) end
  19.         if (slot == 2) then c = math.pow(2, y-1) end
  20.         chest.setColors(a,b,c)
  21.       end
  22.     end
  23.   end
  24. end
  25.  
  26. function drawColor(x, y, color)
  27.   mon.setBackgroundColor(color)
  28.   mon.setTextColor(color)
  29.   mon.setCursorPos(x,y)
  30.   mon.write(" ")
  31.   mon.setBackgroundColor(colors.black)
  32.   mon.setTextColor(colors.white)
  33. end
  34.  
  35. while (true) do
  36.   mon.clear()
  37.   mon.setCursorPos(1,1)
  38.   chest = peripheral.wrap(eChestSide)
  39.   if (chest == nil) then
  40.     mon.write("Place the chest")
  41.     mon.setCursorPos(1,2)
  42.     mon.write("on the " .. eChestSide)
  43.     mon.setCursorPos(1,3)
  44.     mon.write("of the computer")
  45.     sleep(1)
  46.   else
  47.     if (chest.getColors == nil) then
  48.       mon.write("That's not an")
  49.       mon.setCursorPos(1,2)
  50.       mon.write("ender chest!")
  51.       sleep(1)
  52.     else
  53.       for x = 1,3,1 do
  54.         for y = 1,16,1 do
  55.           drawColor(x*7-6, y, math.pow(2, y-1))
  56.           drawColor(x*7-5, y, math.pow(2, y-1))
  57.           drawColor(x*7-4, y, math.pow(2, y-1))
  58.           drawColor(x*7-3, y, math.pow(2, y-1))
  59.         end
  60.       end
  61.       if (parallel.waitForAny(sleepASec, touchPull) == 2) then
  62.         print("Touch!")
  63.       end
  64.     end
  65.   end
  66. end
  67.  
RAW Paste Data