	

    local blown = true
    local mind = blown
     
    local x,y = term.getSize()
    local charX, charY = 4,4
    local selectedSlot = 1
    local health = 10
    local debug1 = false
    local debugX = 1
    local debugY = 1
    local scrollX = 0
    local scrollY = 0
    local biome = "desert"
    local worldTransition = nil
    local skyColor = colors.lightBlue
    local guiData = {} --Coming Soon
    local height = 5
    local seed = os.time()
     
    local recipes = {}
    local screenData = {}
    biomes = {
            [1] = "desert",
            [2] = "forest",
            [1] = "extreme_hills",
    }
    spawnBiomes = {
            [1] = "desert",
            [2] = "forest",
    }
    world = {
    }
    inventory = {
    }
     
    blocks = {}
    chunks = {}
     
    tArgs = { ... }
    if tArgs[1] then
            local chars = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',',','.','\\','/',';','\'','[',']','-','=','','<','>','?',':','"','{','}','_','+','`','~','1','2','3','4','5','6','7','8','9','0','!','@','#','$','%','^','&','*','(',')',' '}
            local resultsc = 50
            local sText = table.concat( tArgs, " " )
            for i=1,#sText do
                    local text = string.sub( sText, i, i )
                    for i=1,#chars do
                            if chars[i] == text then
                                    resultsc = resultsc + i
                            else
                                    resultsc = resultsc + 12
                            end
                    end
            end
           
            seed = tonumber( resultsc )
    end
     
    math.randomseed( seed )
     
    local function cPrint( txt ) --Version 2.0 of cPrint
            local function printC( text )
                    x2,y2 = term.getCursorPos()
                    term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), y2)
                    write(text.. "\n")
            end
           
            if type(txt) == "string" then
                    printC( txt )
            elseif type(txt) == "table" then
                    for i=1,#txt do
                            printC( txt[i] )
                    end
            end
    end
     
    local function lPrint( txt )
            local x2, y2 = term.getCursorPos()
            term.setCursorPos( (x-(#txt))+1, y2 )
            write( text.. "\n" )
    end
     
    local drawingBoard = {
            ["A"] = colors.white,
            ["B"] = colors.orange,
            ["C"] = colors.magenta,
            ["D"] = colors.lightBlue,
            ["E"] = colors.yellow,
            ["F"] = colors.lime,
            ["G"] = colors.pink,
            ["H"] = colors.gray,
            ["I"] = colors.lightGray,
            ["J"] = colors.cyan,
            ["K"] = colors.purple,
            ["L"] = colors.blue,
            ["M"] = colors.brown,
            ["N"] = colors.green,
            ["O"] = colors.red,
            ["P"] = colors.black,
    }
     
    local function advWrite( pos1, pos2, str )
            for i=1,#str do
                    local symb = drawingBoard[ string.sub( str, i, i) ]
                    term.setCursorPos( pos1 + (i-1) , pos2 )
                    if symb then
                            term.setBackgroundColour( symb )
                            write(" ")
                    end
            end
    end
     
    function registerBlock( id, name, color, hardness, info, placeable, texture, onTouched )
            if placeable == nil then
                    placeable = true
            end
           
            if texture == nil then
                    texture = " "
            end
           
            blocks[id] = {
                                            ["DisplayName"] = name,
                                            ["Color"] = color,
                                            ["Hardness"] = hardness,
                                            ["Others"] = info,
                                            ["CanBePlaced"] = placeable,
                                            ["Texture"] = texture,
                                            ["onTouched"] = onTouched,
                                    }
    end
     
    function registerItem( id, name, color, text )
            blocks[id] = {
                                            ["DisplayName"] = name,
                                            ["Color"] = color,
                                            ["Hardness"] = -1,
                                            ["Others"] = "Item",
                                            ["CanBePlaced"] = false,
                                            ["Texture"] = text,
                                            ["onTouched"] = onTouched,
                                    }
    end
     
    function getColorByName( name )
            for i=1,256 do
                    blockInfo = blocks[i]
                    if blockInfo then
                            if blockInfo["DisplayName"] == name then
                                    return blockInfo["Color"]
                            end
                    end
            end
           
            return false
    end
     
    function getHardnessByName( name )
            for i=1,256 do
                    blockInfo = blocks[i]
                    if blockInfo then
                            if blockInfo["DisplayName"] == name then
                                    return blockInfo["Hardness"]
                            end
                    end
            end
           
            return false
    end
     
    function drawPixel( x22, y22, color )
            if screenData[ x22.. "/" ..y22 ] ~= color then
                    screenData[ x22.. "/" ..y22 ] = color
                    local x1,y1 = term.getCursorPos()
                    term.setCursorPos(x22,y22)
                    if tostring( color ) == color then
                            if getColorByName( color ) then
                                    term.setBackgroundColour( getColorByName( color ) )
                            else
                                    term.setBackgroundColour( colors.magenta )
                            end
                    else
                            term.setBackgroundColour( color )
                    end
                    write(" ")
                    term.setCursorPos(x1,y1)
                    term.setBackgroundColour( colors.black )
            end
    end
     
    function drawCharacter()
            drawPixel(charX, charY-1, colors.orange)
            drawPixel(charX, charY, colors.cyan)
    end
     
    function hasBlock( name, inventory1 )
                    for i=1,24 do
                            if inventory[i] then
                                    if (inventory[i])["name"] == name then
                                            if inventory1 and inventory[i]["quantity"] == 9 then
                                            else
                                                    return i, inventory[i]["quantity"]
                                            end
                                    end
                            end
                    end
            return false
    end
     
    function breakBlock( x, y )
            x = x - scrollX
            y = y - scrollY
            for i=1,#world do
                    blockInfo = world[i]
                    if blockInfo["x"] == x and blockInfo["y"] == y then
                            inventoryNum = #inventory+1
                            inv, amm = hasBlock( blockInfo["name"], true )
                            tValue = math.random(1,3)
                            if blockInfo["name"] ~= "Sapling" then
                                    tValue = 3
                            end
                           
                            if #inventory ~= 24 then
                                    if tValue == 3 then
                                            if inv and amm ~= 9 then
                                                    inventory[inv]["quantity"] = amm +1
                                            else
                                                    inventory[inventoryNum] = {
                                                                    ["name"] = blockInfo["name"],
                                                                    ["quantity"] = 1,
                                                            }
                                            end
                                    end
                            end
                            world[i] = nil
                    end
            end
            cleanupWorld()
    end
     
    function getBlockInfo( x,y )
            x = x - scrollX
            y = y - scrollY
            for i=1,#world do
                    blockInfo = world[i]
                    if blockInfo["x"] == x and blockInfo["y"] == y then
                            return blockInfo["x"], blockInfo["y"], blockInfo["name"]
                    end
            end
    end
     
    function cleanupWorld()
            local nWorld = {}
            for k,v in pairs( world ) do
                    if v then
                            nWorld[#nWorld+1] = v
                    end
            end
            world = nWorld
    end
     
    function clear()
            term.setBackgroundColour( skyColor )
            screenData = {}
            drawPixel(1,1, colors.yellow )
            drawPixel(2,1, colors.orange )
            drawPixel(2,2, colors.orange )
            drawPixel(1,2, colors.orange )
    end
     
    function redrawWorld()
            local oldScreenData = screenData
           
            clear()
            drawWorld()
            drawCharacter()
            drawGUI()
           
            if oldScreenData ~= screenData then
                    for i,v in pairs( oldScreenData ) do
                            if screenData[ i ] == nil then
                                    local tWords = {}
                                    for match in string.gmatch( i, "[^/\t]+" ) do
                                            table.insert( tWords, match )
                                    end
                                   
                                    local screenX = tonumber(tWords[1])
                                    local screenY = tonumber(tWords[2])
                                   
                                    term.setCursorPos( screenX, screenY )
                                    term.setBackgroundColour( skyColor )
                                    write(" ")
                            end
                    end
            end
    end
     
    function placeBlock( x,y,name )
            x = x - scrollX
            y = y - scrollY
            world[#world+1] = {
                                                    ["x"] = x,
                                                    ["y"] = y,
                                                    ["name"] = name,
                                            }
    end
     
    function drawWorld()
            for i=1,#world do
                    local blockInfo = world[i]
                    --if blocksAbove(blockInfo["x"],blockInfo["y"]) ~= 5 then
                            --[[if (blockInfo["x"] + scrollX < 1 or blockInfo["x"] < x) or (blockInfo["y"] + scrollY < 1 or blockInfo["y"] + scrollY < y or blockInfo["y"] + scrollY == y) then
                                    if getBlockInfo( blockInfo["x"] + scrollX, blockInfo["y"] -1 + scrollY ) then
                                            if blockInfo["name"] == "Grass" then
                                                    blockInfo["name"] = "Dirt"
                                            end
                                    end
                                    drawPixel(blockInfo["x"]+scrollX,blockInfo["y"]+scrollY,blockInfo["name"])
                            elseif blockInfo["x"] + scrollX == x and blockInfo["y"] + scrollY == y then]]
                                    drawPixel(blockInfo["x"]+scrollX,blockInfo["y"]+scrollY,blockInfo["name"])
                            --end
                    --[[else
                            drawPixel(blockInfo["x"],blockInfo["y"], "Darkness")
                    end]]
            end
                   
            if debug1 then
                    term.setBackgroundColour( colors.white )
                    term.setTextColour( colors.gray )
                    term.setCursorPos(1,1)
                    write("               ")
                    term.setCursorPos(1,1)
                    write("Debugging...")
                    term.setCursorPos(1,2)
                    write("               ")
                    term.setCursorPos(1,2)
                    if getBlockInfo( debugX, debugY ) then
                            term.setTextColour( colors.red )
                    end
                    write("MouseX: " ..debugX)
                    term.setCursorPos(1,3)
                    write("               ")
                    term.setCursorPos(1,3)
                    write("MouseY: " ..debugY)
                    term.setTextColour( colors.gray )
                    term.setCursorPos(1,4)
                    write("               ")
                    term.setCursorPos(1,4)
                    write("CharX: " ..charX)
                    term.setCursorPos(1,5)
                    write("               ")
                    term.setCursorPos(1,5)
                    write("CharY: " ..charY)
                    term.setBackgroundColour( colors.black )
                    term.setTextColour( colors.white )
            end
    end
     
    function registerMob()
    end
     
    function generateWorld( type_ )
            if type_ == "forest" then
                    for i=1,x do
                            generateChunk(type_, i)
                    end
            elseif type_ == "desert" then
                    for i=1,x do
                            generateChunk(type_, i)
                    end
            elseif type_ == "extreme_hills" then
                    for i=1,x do
                            generateChunk(type_, i)
                    end
            end
           
            local biomeTransition = math.random(1,30)
            if biomeTransition == 30 then
                    biome = math.random(1,#biomes)
            end
    end
     
    function generateChunk( type_, i )
            local hills = math.random( 10 )
            if type_ == "forest" then
                    if hills == 1 then
                            if height > 4 then
                                    height = height -1
                            end
                    elseif hills == 10 then
                            if height < 12 then
                                    height = height +1
                            end
                    end
                   
                    if math.random( 3 ) == 3 then
                            generateTree(i, height-1)
                    end
                    placeBlock(i,height, "Grass")
                    placeBlock(i,height+1, "Dirt")
                    placeBlock(i,height+2, "Dirt")
                    blockType = math.random(1,2)
                    if blockType == 1 then
                            placeBlock(i,height+3, "Dirt")
                    else
                            placeBlock(i,height+3, "Stone")
                    end
                           
                    for v=height+4,y do
                            placeBlock(i,v, "Stone")
                    end
            elseif type_ == "extreme_hills" then
                    if hills > 5 then
                            if height > -3 then
                                    height = height -1
                            end
                    elseif hills <= 5 then
                            if height < 17 then
                                    height = height +1
                            end
                    end
                   
                    placeBlock(i,height, "Grass")
                    placeBlock(i,height+1, "Dirt")
                    placeBlock(i,height+2, "Dirt")
                    blockType = math.random(1,2)
                    if blockType == 1 then
                            placeBlock(i,height+3, "Dirt")
                    else
                            placeBlock(i,height+3, "Stone")
                    end
                           
                    for v=height+4,y do
                            placeBlock(i,v, "Stone")
                    end
            elseif type_ == "desert" then
                    if hills == 1 then
                            if height > 5 then
                                    height = height -1
                            end
                    elseif hills == 10 then
                            if height < 15 then
                                    height = height +1
                            end
                    end
                   
                    placeBlock(i,height, "Sand")
                    placeBlock(i,height+1, "Sand")
                    placeBlock(i,height+2, "Sand")
                    blockType = math.random(1,2)
                    if blockType == 1 then
                            placeBlock(i,height+3, "Sand")
                    else
                            placeBlock(i,height+3, "Stone")
                    end
                           
                    for v=height+4,y do
                            placeBlock(i,v, "Stone")
                    end
            end
           
            chunks[i - scrollX] = {
                    ["Type"] = type_,
                    ["Height"] = height,
            }
    end
     
    function generateTree( posX, posY )
            placeBlock( posX, posY, "Wood" )
            placeBlock( posX, posY-1, "Wood" )
            placeBlock( posX, posY-2, "Sapling" )
            placeBlock( posX, posY-3, "Sapling" )
            placeBlock( posX-1, posY-2, "Sapling" )
            placeBlock( posX+1, posY-2, "Sapling" )
    end
     
    function drawGUI()
            for i=1,8 do
                    drawPixel( i, y , colors.white )
            end
            for i=1,20 do
                    drawPixel( i, y-1 , colors.black )
            end
            drawPixel( 9, y , colors.black )
            drawPixel( 20, y , colors.black )
            for i=1,health do
                    drawPixel( 9+i, y, colors.red )
            end
            term.setCursorPos(10, y-1)
            write("Health")
            term.setCursorPos(1, y-2)
            if inventory[selectedSlot] then
                    write( inventory[selectedSlot]["name"].. "(" ..inventory[selectedSlot]["quantity"].. ")" )
            end
            for i=1,8 do
                    if inventory[i] then
                            drawPixel( i, y, getColorByName( inventory[i]["name"] ) )
                            term.setCursorPos(i,y-1)
                            write( inventory[i]["quantity"] )
                    end
            end
            drawPixel( selectedSlot, y-1, colors.lime )
           
            for i=1,#guiData do
                    local gData = guiData[i]
                    if gData["Enabled"] == true then
                            gData["Main"]( i )
                    end
            end
    end
           
    function blocksAbove( x123, y123 )
            local abuv = 0
            for i=1,5 do
                    if getBlockInfo( x123, y123-i ) then
                            abuv = abuv +1
                    end
            end
            return abuv
    end
     
    function blockBelow( x123, y123 )
            if getBlockInfo( x123, y123+1 ) then
                    return true
            end
            return false
    end
     
    function newGUI( name, func, key )
            local guiID = #guiData+1
            guiData[ guiID ] = {
                    ["Main"] = func,
                    [ "Enabled" ] = false,
                    [ "Name" ] = name,
                    [ "Toggle" ] = key,
            }
            return guiID
    end
     
    function newCraftingSmall( obj1, obj2, obj3, obj4, result, count )
            if count == nil then
                    count = 1
            end
           
            recipes[ #recipes ] = {
                    ["Crafting"] = {
                            obj1,
                            obj2,
                            obj3,
                            obj4,
                    },
                    ["Result"] = {
                            ["Name"] = result,
                            ["Ammount"] = count,
                    },
            }
    end
     
    function inventoryx( inv )
            local selected = 0
            local itemsX = {}
            local currentRecipe = {}
            local disallowed = -1 --Don't touch
            local itemsC = {}
            local crafting = {
                    "XCraftingX",
                    "X1X2XXXXXX",
                    "XXXX->5XXX",
                    "X3X4XXXXXX",
                    "XXXXXXXXXX",
            }
            local function drawContainers()
                    local invPos = 1
                    local text = "          "
                    term.setCursorPos(1,3)
                    xPos = math.ceil((x / 2) - (text:len() / 2))
                    for i=1,10 do
                            drawPixel( xPos+i-1,3,colors.black )
                    end
                    print()
                   
                    for x=1,3 do
                            local x,y = term.getSize()
                            x2,y2 = term.getCursorPos()
                            xPos = math.ceil((x / 2) - (text:len() / 2))
                            drawPixel( xPos, y2, colors.black )
                           
                            for v=1,8 do
                                    local i = ((v+xPos))
                                    if inventory[invPos] then
                                            drawPixel( i, y2, getColorByName( inventory[invPos]["name"] ) )
                                            term.setCursorPos( i,y2 )
                                            if invPos == selected then
                                                    term.setTextColour( colors.lime )
                                            end
                                            term.setBackgroundColour( getColorByName( inventory[invPos]["name"] ) )
                                            write( inventory[invPos]["quantity"] )
                                           
                                            term.setTextColour( colors.white )
                                    else
                                            drawPixel( i, y2, colors.white )
                                    end
                                    itemsX[ i.. "/" ..y2 ] = invPos
                                    invPos = invPos +1
                            end
                           
                            drawPixel( xPos+9, y2, colors.black )
                            print()
                    end
            end
           
            local function drawTable( txt )
                    for i=1,#txt do
                            local text = ( txt[i] )
                            local x1, y2 = term.getCursorPos()
                            local x2 = math.ceil((x / 2) - (text:len() / 2))
                           
                            for v=1,#text do
                                    local cTxt = string.sub( text, v, v )
                                   
                                    if cTxt == "X" then
                                            drawPixel( (x2+v)-1, y2, colors.black )
                                    elseif cTxt == "1" or cTxt == "2" or cTxt == "3" or cTxt == "4" or cTxt == "5" then
                                            local invPos = 30 + tonumber( cTxt ) --Everything above 30 won't show up in the inventory :D (So it can be used as a extra inventory or whatevz)
                                            itemsX[ ((x2+v)-1).. "/" ..y2 ] = invPos
                                            if cTxt == "5" then
                                                    disallowed = invPos
                                            else
                                                    itemsC[ tonumber( cTxt ) ] = invPos
                                            end
                                           
                                            if inventory[invPos] then
                                                    drawPixel( (x2+v)-1, y2, getColorByName( inventory[invPos]["name"] ) )
                                                    term.setCursorPos( (x2+v)-1,y2 )
                                                    if invPos == selected then
                                                            term.setTextColour( colors.lime )
                                                    end
                                                    term.setBackgroundColour( getColorByName( inventory[invPos]["name"] ) )
                                                    write( inventory[invPos]["quantity"] )
                                                   
                                                    term.setTextColour( colors.white )
                                                    term.setBackgroundColour( colors.black )
                                            else
                                                    drawPixel( (x2+v)-1, y2, colors.white )
                                            end
                                    else
                                            drawPixel( (x2+v)-1, y2, colors.black )
                                            term.setCursorPos( (x2+v)-1, y2 )
                                            write( cTxt )
                                    end
                            end
                           
                            term.setCursorPos( 1, y2 +1 )
                    end
            end
           
            local function usefunc( id ) --mah useless function
                    if itemsC[ id ] ~= nil then
                            if inventory[itemsC[ id ]] ~= nil then
                                    if inventory[itemsC[ id ]]["name"] ~= nil then
                                            return inventory[itemsC[ id ]]["name"]
                                    end
                            end
                    end
                    return false
            end
           
            while true do
                    if itemsC[1] then
                            currentRecipe = {
                                    usefunc( 1 ),
                                    usefunc( 2 ),
                                    usefunc( 3 ),
                                    usefunc( 4 ),
                            }
                           
                            for lol=1,#recipes do
                                    for i=1,4 do
                                            if currentRecipe[i] == recipes[lol]["Crafting"][i] then
                                                    inventory[disallowed] =  {
                                                            ["name"] = recipes[lol]["Result"]["Name"],
                                                            ["quantity"] = recipes[lol]["Result"]["Ammount"],
                                                    }
                                                    break
                                            end
                                    end
                            end
                    end
           
                    drawContainers()
                    term.setBackgroundColour( colors.black )
                    term.setTextColour( colors.white )
                    cPrint( text )
                    drawTable( crafting )
                   
                    local event, key, posX, posY = os.pullEvent(  )
                   
                    if event == "key" then
                            guiData[ inv ][ "Enabled" ] = false
                            redrawWorld()
                            break
                    elseif event == "mouse_click" then
                            if key == 1 then
                                    if itemsX[ posX.. "/" ..posY ] ~= nil then
                                            if selected ~= 0 then
                                                    local itemPos = itemsX[ posX.. "/" ..posY ]
                                                    if itemPos == selected then
                                                            selected = 0
                                                    elseif itemPos ~= disallowed then
                                                            for i,v in pairs( itemsX ) do
                                                                    if v == selected then
                                                                            local old1 = v
                                                                            local old2 = itemPos
                                                                           
                                                                           
                                                                            local old3 = inventory[ old2 ]
                                                                            oldInventory = inventory
                                                                           
                                                                            inventory[ old2 ] = oldInventory[ old1 ]
                                                                            inventory[ old1 ] = old3
                                                                           
                                                                            if old1 == disallowed then
                                                                                    for i=1,4 do
                                                                                            inventory[ itemsC[i] ] = nil
                                                                                    end
                                                                            end
                                                                           
                                                                            selected = 0
                                                                            redrawWorld()
                                                                            break
                                                                    end
                                                            end
                                                    end
                                            else
                                                    selected = itemsX[ posX.. "/" ..posY ]
                                            end
                                    end
                            end
                    end
            end
    end
     
    fs.makeDir(".minecraft")
    fs.makeDir(".minecraft/mods")
    fs.makeDir(".minecraft/saves")
    fs.makeDir(".minecraft/screenshots")
     
    registerBlock( 1, "Stone", colors.gray, 3)
    registerBlock( 2, "Dirt", colors.brown, 1)
    registerBlock( 3, "Grass", colors.green, 1)
    registerBlock( 4, "IronOre", colors.orange, 1)
    registerBlock( 5, "GoldOre", colors.yellow, 1)
    registerBlock( 6, "CoalOre", colors.black, 1)
    registerBlock( 7, "Diamond", colors.blue, 1)
    registerBlock( 8, "Darkness", colors.black, -1)
    registerBlock( 9, "Wood", colors.brown, 1)
    registerBlock( 10, "Sapling", colors.lime, 1)
    registerBlock( 11, "Planks", colors.orange, 1)
    registerBlock( 12, "Sand", colors.yellow, 1)
    registerBlock( 13, "Gravel", colors.lightGray, 1)
     
    newCraftingSmall( "Wood", "Wood", "Wood", "Wood", "Planks", 4 )
     
    local inv = newGUI( "Inventory", inventoryx, 18 )
     
    biome = spawnBiomes[ math.random(#spawnBiomes) ]
    --[[print("generating world...")
    print("biome: " ..biome)
    sleep(1)]]--
    generateWorld( biome ) --Generate spawn Biome
     
    term.setBackgroundColour( colors.lightBlue )
    term.clear()
    redrawWorld()
    term.setTextColour( colors.gray )
    term.setCursorPos(1,1)
    term.setBackgroundColour( colors.lightBlue )
    write("Mineception v1.02")
    term.setCursorPos(1,3)
    cPrint("Mineception")
    term.setTextColour( colors.yellow )
    cPrint("Now with crafting!")
    term.setCursorPos(1,5)
    term.setBackgroundColour( colors.lightGray )
    term.setTextColour( colors.white )
    cPrint("      Singleplayer      ")
    term.setCursorPos(1,7)
    term.setTextColour( colors.gray )
    term.setBackgroundColour( colors.black )
    cPrint("      Multi-player      ")
     
    while true do
            local _, lor, mX, mY = os.pullEvent("mouse_click")
            if lor == 1 then
                    if mY == 5 then
                            if mX < 37 or mX > 14 then
                                    break
                            end
                    end
            end
    end
     
    term.setBackgroundColour( skyColor )
    term.clear()
     
    redrawWorld()
     
    term.setBackgroundColour( colors.white )
    term.setTextColour( colors.white )
     
    if blockBelow( charX, charY ) ~= true and gravity == nil then
            gravity = os.startTimer(0)
    end
     
    while true do
            --os.startTimer( 0 )
            local event, key, posX, posY = os.pullEvent()
            oldslot = selectedSlot
            if event == "key" then
                    if key == keys.left then
                            function collide()
                                    if getBlockInfo( charX -1, charY ) or getBlockInfo( charX -1, charY-1 ) then
                                            if getBlockInfo( charX -1, charY-1) and getBlockInfo( charX -1, charY-2) and getBlockInfo( charX -1, charY) then
                                            else
                                                    drawPixel(charX, charY, skyColor)
                                                    drawPixel(charX, charY-1, skyColor)
                                                    charX = charX -1
                                                    charY = charY -1
                                            end
                                    else
                                            local x11, y11, name = getBlockInfo( charX, charY-1)
                                            local _x11, _y11, _name = getBlockInfo( charX, charY)
                                            if name then
                                                    drawPixel(charX, charY-1, name)
                                            else
                                                    drawPixel(charX, charY-1, skyColor)
                                            end
                                            if _name then
                                                    drawPixel(charX, charY, _name)
                                            else
                                                    drawPixel(charX, charY, skyColor)
                                            end
                                            charX = charX -1
                                    end
                            end
                           
                            if charX ~= 3 then
                                    collide()
                            else
                                    height = chunks[charX-2 - scrollX]["Height"]
                                    biomeTransition = math.random(1,15)
                                    if biomeTransition == 1 then
                                            biome = biomes[ math.random(1,#biomes) ]
                                    end
                                    scrollX = scrollX +1
                                    if not chunks[charX-2 - scrollX] then
                                            generateChunk( biome, charX-2 )
                                    end
                                   
                                    redrawWorld()
                            end
                    elseif key == keys.right then
                            function collide()
                                    if getBlockInfo( charX +1, charY ) or getBlockInfo( charX +1, charY-1 ) then
                                            if getBlockInfo( charX +1, charY-1) and getBlockInfo( charX +1, charY-2) and getBlockInfo( charX +1, charY) then
                                            elseif getBlockInfo( charX +1, charY-1 ) then
                                            else
                                                    drawPixel(charX, charY, skyColor)
                                                    drawPixel(charX, charY-1, skyColor)
                                                    charX = charX +1
                                                    charY = charY -1
                                            end
                                    else
                                            local x11, y11, name = getBlockInfo( charX, charY-1)
                                            local _x11, _y11, _name = getBlockInfo( charX, charY)
                                            if name then
                                                    drawPixel(charX, charY-1, name)
                                            else
                                                    drawPixel(charX, charY-1, skyColor)
                                            end
                                            if _name then
                                                    drawPixel(charX, charY, _name)
                                            else
                                                    drawPixel(charX, charY, skyColor)
                                            end
                                            charX = charX +1
                                    end
                            end
                           
                            if charX < x -2 then
                                    collide()
                            else
                                    height = chunks[charX+2 - scrollX]["Height"]
                                    biomeTransition = math.random(1,15)
                                    if biomeTransition == 1 then
                                            biome = biomes[ math.random(1,#biomes) ]
                                    end
                                    scrollX = scrollX -1
                                    if not chunks[charX+2 - scrollX] then
                                            generateChunk( biome, charX+2 )
                                    end
                                   
                                    redrawWorld()
                            end
                    elseif key == 2 then
                            selectedSlot = 1
                    elseif key == 3 then
                            selectedSlot = 2
                    elseif key == 4 then
                            selectedSlot = 3
                    elseif key == 5 then
                            selectedSlot = 4
                    elseif key == 6 then
                            selectedSlot = 5
                    elseif key == 7 then
                            selectedSlot = 6
                    elseif key == 8 then
                            selectedSlot = 7
                    elseif key == 9 then
                            selectedSlot = 8
                    elseif key == 61 then
                            if debug1 then debug1 = false else debug1 = true end
                            clear()
                            drawWorld()
                    end
                   
                   
                    for i=1,#guiData do
                            local gData = guiData[i]
                            if gData["Toggle"]  == key then
                                    if gData[ "Enabled" ] then
                                            gData[ "Enabled" ] = false
                                    else
                                            gData[ "Enabled" ] = true
                                    end
                                   
                                    redrawWorld()
                            end
                    end
            elseif event == "mouse_click" then
                    debugX = posX
                    debugY = posY
                    if key == 1 then
                            local _, _, nameyy = getBlockInfo( posX, posY )
                            if getHardnessByName( nameyy ) ~= -1 then
                                    breakBlock( posX, posY )
                                    drawPixel( posX, posY, skyColor )
                            end
                    elseif key == 2 then
                            if inventory[selectedSlot] then
                                    if posY == charY and posX == charX then
                                            if not getBlockInfo(charX,charY -2) then
                                                    placeBlock( charX, charY, inventory[selectedSlot]["name"] )
                                                    inventory[selectedSlot]["quantity"] = inventory[selectedSlot]["quantity"] -1
                                                    drawPixel(charX,charY,inventory[selectedSlot]["name"])
                                                    if inventory[selectedSlot]["quantity"] == 0 then
                                                            inventory[selectedSlot] = nil
                                                    end
                                                   
                                                    drawPixel(charX,charY-1,skyColor)
                                                    charY = charY -1
                                            end
                                    elseif not getBlockInfo( posX, posY ) then
                                            if posY == charY+1 and posX == charX then else
                                                    placeBlock( posX, posY, inventory[selectedSlot]["name"] )
                                                    inventory[selectedSlot]["quantity"] = inventory[selectedSlot]["quantity"] -1
                                                    drawPixel( posX, posY, inventory[selectedSlot]["name"] )
                                                    if inventory[selectedSlot]["quantity"] == 0 then
                                                            inventory[selectedSlot] = nil
                                                    end
                                            end
                                    end
                            end
                    end
            elseif event == "timer" then
                    if key == worldTransition then
                            worldTransition = nil
                    elseif key == gravity then
                            local x11, y11, name = getBlockInfo( charX, charY-1)
                            local _x11, _y11, _name = getBlockInfo( charX, charY)
                            if name then
                                    drawPixel(charX, charY-1, name)
                            else
                                    drawPixel(charX, charY-1, skyColor)
                            end
                            if _name then
                                    drawPixel(charX, charY, _name)
                            else
                                    drawPixel(charX, charY, skyColor)
                            end
                            charY = charY +1
                            gravity = nil
                    else
                            --[[local oldSkyColor = skyColor
                            if os.time() > 6 and os.time() < 20 then
                                    skyColor = colors.lightBlue
                            else
                                    skyColor = colors.purple
                            end
                           
                            if skyColor ~= oldSkyColor then
                                    redrawWorld()
                            end]]
                    end
            end
                   
            if oldslot ~= selectedSlot then
                    clear()
                    drawWorld()
            end
           
            if blockBelow( charX, charY ) ~= true and gravity == nil then
                    gravity = os.startTimer(0)
            end
           
            drawCharacter()
            drawGUI()
    end
