---- Super Security Door, By Gustavo Wizard, @2014
---- This program needs Direwolf20 Button API
---- This program needs 2 monitors (bottom 1x1 and top 3x1) 
---- Plz give credit for me and for the button API author if using this program in any way


os.loadAPI("btn")
m = peripheral.wrap("top")

m.setTextScale(0.5)

while true do
m.setBackgroundColor(colors.black)
m.clear()
m.setCursorPos(2,1)
m.setTextColor(colors.cyan)
m.write("Instructions")
m.setCursorPos(2,13)
m.write("Retrive Sample")
m.setCursorPos(23,1)
m.write("Open Cage")
m.setCursorPos(23,13)
m.write("Close Cage")

term.redirect(m)

paintutils.drawLine(2,3,14,3,colors.magenta)
paintutils.drawLine(2,8,14,8,colors.magenta)
paintutils.drawLine(2,3,2,8,colors.magenta)
paintutils.drawLine(14,3,14,8,colors.magenta)

paintutils.drawLine(22,3,34,3,colors.magenta)
paintutils.drawLine(22,8,34,8,colors.magenta)
paintutils.drawLine(22,3,22,8,colors.magenta)
paintutils.drawLine(34,3,34,8,colors.magenta)

paintutils.drawLine(2,15,14,15,colors.pink)
paintutils.drawLine(2,20,14,20,colors.pink)
paintutils.drawLine(2,15,2,20,colors.pink)
paintutils.drawLine(14,15,14,20,colors.pink)

paintutils.drawLine(22,15,34,15,colors.pink)
paintutils.drawLine(22,20,34,20,colors.pink)
paintutils.drawLine(22,15,22,20,colors.pink)
paintutils.drawLine(34,15,34,20,colors.pink)

m.setBackgroundColor(colors.blue)
m.setTextColor(colors.white)

function fillTable()
 btn.setTable("Teachme", col, 4,12,5,6)
 btn.setTable("Retrive", ret, 4,12,17,18)
 btn.setTable("Open ", ope, 24,32,5,6)
 btn.setTable("Close", clo, 24,32,17,18)
 btn.screen()
end

function getClick()
 event,side,x,y = os.pullEvent("monitor_touch")
 btn.checkxy(x,y)
end

function col()
m.clear()
m.setTextColor(colors.lime)
m.setCursorPos(2,2)
m.write("ADVANCED GENETICS MOD INSTRUCTIONS")
m.setTextColor(colors.white)
m.setCursorPos(1,3)
m.write("----------------------------------------------")
m.setCursorPos(2,5)
m.write("1) Collect a Skin sample pressing")
m.setCursorPos(2,6)
m.write("the button 'Retrive' here")
m.setCursorPos(2,7)
m.write("2) Put the sample on DNA Analyser")
m.setCursorPos(2,8)
m.write("3) Put the Cell on DNA Extractor")
m.setCursorPos(2,9)
m.write("4) Put the helix on DNA Decrypter")
m.setCursorPos(2,10)
m.write("5) Put the decoded helix on Insulator")
m.setCursorPos(2,11)
m.write("6) Put the insulated helix on Cloner")
m.setCursorPos(2,12)
m.write("Put insulated Cells on Cloner Inventory")
m.setCursorPos(2,14)
m.write("Insulated Cells come from DNA Insulator")
m.setCursorPos(2,15)
m.write("So you need at least a Cell reserve")

sleep(9)
end

function ret()
 btn.flash("Retrive")
 rs.setOutput("left", true)
 sleep(2)
 rs.setOutput("left", false)
end

function ope()
 btn.flash("Open ")
 commands.gamerule("commandBlockOutput", false)
 x,y,z = commands.getBlockPosition()
 commands.setblock(x-1,y,z+4,0)
 commands.setblock(x-1,y+1,z+4,0)
 commands.setblock(x-1,y+2,z+4,0)
 
 commands.setblock(x-2,y,z+4,0)
 commands.setblock(x-2,y+1,z+4,0)
 commands.setblock(x-2,y+2,z+4,0)
 
 commands.setblock(x-3,y,z+4,0)
 commands.setblock(x-3,y+1,z+4,0)
 commands.setblock(x-3,y+2,z+4,0)
 
 commands.playsound("tile.piston.out","@a")
end

function clo()
 btn.flash("Close")
 commands.gamerule("commandBlockOutput", false)
 x,y,z = commands.getBlockPosition()
 commands.setblock(x-1,y,z+4,101)
 commands.setblock(x-1,y+1,z+4,101)
 commands.setblock(x-1,y+2,z+4,101)
 
 commands.setblock(x-2,y,z+4,101)
 commands.setblock(x-2,y+1,z+4,101)
 commands.setblock(x-2,y+2,z+4,101)
 
 commands.setblock(x-3,y,z+4,101)
 commands.setblock(x-3,y+1,z+4,101)
 commands.setblock(x-3,y+2,z+4,101)
 
 commands.playsound("tile.piston.in","@a")
end

fillTable()

getClick()

end

