Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --ComputerCraft EnderPainter by Teki 0.1
- local monitor
- local eventType = "mouse_click"
- local enderStorage
- local color1 = 1
- local color2 = 1
- local color3 = 1
- local colorSaved1 = 1
- local colorSaved2 = 1
- local colorSaved3 = 1
- local function roundTo(num, n)
- local mult = 10^(n or 0)
- return math.floor(num * mult + 0.5) / mult
- end
- function getIndex(tab, target)
- for i=1,#tab do
- if tab[i] == target then
- return i
- end
- end
- return false
- end
- if peripheral.find("monitor") == nil then
- monitor = term.current()
- else
- monitor = peripheral.find("monitor")
- term.redirect(monitor)
- eventType = "monitor_touch"
- end
- local sizeX,sizeY = monitor.getSize()
- local unitX = roundTo(sizeX/7)
- local unitY = roundTo(sizeY/3)
- local enderColors = {
- colors.white,
- colors.black,
- colors.orange,
- colors.magenta,
- colors.lightBlue,
- colors.yellow,
- colors.lime,
- colors.pink,
- colors.gray,
- colors.lightGray,
- colors.cyan,
- colors.purple,
- colors.blue,
- colors.brown,
- colors.green,
- colors.red
- }
- function catchStorage()
- if peripheral.find("ender_chest") ~= nil then
- enderStorage = peripheral.find("ender_chest")
- elseif peripheral.find("ender_tank") ~= nil then
- enderStorage = peripheral.find("ender_tank")
- else
- enderStorage = nil
- end
- if enderStorage ~= nil then
- color1, color2, color3 = enderStorage.getColors()
- end
- end
- function updateColor(colorUpdated)
- colorUpdated = getIndex(enderColors, colorUpdated)
- if colorUpdated < 16 then
- return enderColors[colorUpdated+1]
- else
- return enderColors[1]
- end
- end
- function draw()
- monitor.setBackgroundColour(colors.black)
- monitor.clear()
- --ENDERSTORAGE COLORS
- paintutils.drawFilledBox(unitX, unitY, 2*unitX, 2*unitY-1, color1)
- paintutils.drawFilledBox(3*unitX, unitY, 4*unitX, 2*unitY-1, color2)
- paintutils.drawFilledBox(5*unitX, unitY, 6*unitX, 2*unitY-1, color3)
- -- COLOR INDEX
- paintutils.drawFilledBox(1, sizeY-1, 16, sizeY-1, colors.white)
- for i=1, #enderColors do
- paintutils.drawFilledBox(i, sizeY, i, sizeY, enderColors[i])
- end
- -- SAVED COLORS
- paintutils.drawFilledBox(sizeX-8, sizeY-2, sizeX-7, sizeY-1, colorSaved1)
- paintutils.drawFilledBox(sizeX-5, sizeY-2, sizeX-4, sizeY-1, colorSaved2)
- paintutils.drawFilledBox(sizeX-2, sizeY-2, sizeX-1, sizeY-1, colorSaved3)
- monitor.setBackgroundColour(colors.black)
- monitor.setCursorPos(2,2)
- if enderStorage == nil then
- monitor.setTextColor(colors.red)
- write("No EnderStorage Found !")
- else
- monitor.setTextColor(colors.green)
- write("EnderStorage Found ! ")
- end
- -- ENDERSTORAGE COLOR INDEX
- monitor.setCursorPos(getIndex(enderColors, color3),sizeY-1)
- write("3")
- monitor.setCursorPos(getIndex(enderColors, color2),sizeY-1)
- write("2")
- monitor.setCursorPos(getIndex(enderColors, color1),sizeY-1)
- write("1")
- -- COPY/PASTE
- monitor.setCursorPos(sizeX-6,sizeY-3)
- write("COPY")
- monitor.setCursorPos(sizeX-7,sizeY)
- write("PASTE")
- end
- while true do
- -- Fetching Data
- catchStorage()
- -- Drawing
- draw()
- -- Catching Events
- event, side, xPos, yPos = os.pullEvent(eventType)
- if enderStorage ~= nil then
- enderStorage.setColors(color1, color2, color3)
- end
- if (xPos >= unitX and xPos <= unitX*2) and (yPos >= unitY and yPos <= 2*unitY-1) then
- color1 = updateColor(color1)
- elseif (xPos >= unitX*3 and xPos <= unitX*4) and (yPos >= unitY and yPos <= 2*unitY-1) then
- color2 = updateColor(color2)
- elseif (xPos >= unitX*5 and xPos <= unitX*6) and (yPos >= unitY and yPos <= 2*unitY-1) then
- color3 = updateColor(color3)
- elseif (xPos >= 23 and xPos <= 28) and (yPos == 9) then
- colorSaved1 = color1
- colorSaved2 = color2
- colorSaved3 = color3
- elseif (xPos >= 23 and xPos <= 28) and (yPos == 12) then
- color1 = colorSaved1
- color2 = colorSaved2
- color3 = colorSaved3
- end
- if enderStorage ~= nil then
- enderStorage.setColors(color1, color2, color3)
- end
- sleep(0)
- end
Add Comment
Please, Sign In to add comment