Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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 hillyGen = math.random(1,9)
- local biome = "desert"
- local worldTransition = nil
- local screenData = {}
- biomes = {
- [1] = "desert",
- [2] = "flatland",
- }
- world = {
- }
- inventory = {
- }
- blocks = {}
- chunks = {}
- local function cPrint(text)
- local x,y = term.getSize()
- x2,y2 = term.getCursorPos()
- term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), y2)
- write(text.. "\n")
- end
- function registerBlock( id, name, color, hardness, info )
- blocks[id] = {
- ["DisplayName"] = name,
- ["Color"] = color,
- ["Hardness"] = hardness,
- ["Others"] = info,
- }
- 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,8 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 tValue == 3 then
- if inv and amm ~= 9 then
- inventory[inv]["quantity"] = amm +1
- else
- inventory[inventoryNum] = {
- ["name"] = blockInfo["name"],
- ["quantity"] = 1,
- }
- 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( colors.lightBlue )
- 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( colors.lightBlue )
- write(" ")
- term.setBackgroundColour( colors.black )
- 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_ == "flatland" then
- generateTree(math.random(5,12), 4)
- for i=1,x do
- generateChunk(type_, i)
- end
- elseif type_ == "desert" 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 )
- if type_ == "flatland" then
- placeBlock(i,5, "Grass")
- placeBlock(i,6, "Grass")
- placeBlock(i,7, "Dirt")
- blockType = math.random(1,2)
- if blockType == 1 then
- placeBlock(i,8, "Dirt")
- else
- placeBlock(i,8, "Stone")
- end
- for v=9,y do
- placeBlock(i,v, "Stone")
- end
- chunks[i] = type_
- elseif type_ == "desert" then
- if hillyGen == 1 then
- placeBlock(i,4, "Sand")
- placeBlock(i,5, "Sand")
- local hillyGone = math.random(1,8)
- if hillyGone == 1 then
- hillyGen = 2
- end
- else
- hillyGen = math.random(1,9)
- end
- placeBlock(i,5, "Sand")
- placeBlock(i,6, "Sand")
- placeBlock(i,7, "Sand")
- blockType = math.random(1,2)
- if blockType == 1 then
- placeBlock(i,8, "Sand")
- else
- placeBlock(i,8, "Stone")
- end
- for v=9,y do
- placeBlock(i,v, "Stone")
- end
- chunks[i] = type_
- end
- 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 )
- 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
- 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)
- biome = biomes[ math.random(1,#biomes) ]
- --[[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)
- write("Mineception v0.01")
- term.setCursorPos(1,3)
- cPrint("Mineception")
- 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( colors.white )
- term.setTextColour( colors.white )
- redrawWorld()
- while true do
- local event, key, posX, posY = os.pullEvent()
- oldslot = selectedSlot
- if event == "key" then
- if key == keys.left then
- if charX ~= 3 then
- 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, colors.lightBlue)
- drawPixel(charX, charY-1, colors.lightBlue)
- 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, colors.lightBlue)
- end
- if _name then
- drawPixel(charX, charY, _name)
- else
- drawPixel(charX, charY, colors.lightBlue)
- end
- charX = charX -1
- end
- else
- biomeTransition = math.random(1,15)
- if biomeTransition == 1 then
- biome = biomes[ math.random(1,#biomes) ]
- end
- scrollX = scrollX +1
- if chunks[charX-2] then
- generateChunk( biome, charX-2 )
- end
- redrawWorld()
- end
- elseif key == keys.right then
- if charX < x -3 then
- 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, colors.lightBlue)
- drawPixel(charX, charY-1, colors.lightBlue)
- 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, colors.lightBlue)
- end
- if _name then
- drawPixel(charX, charY, _name)
- else
- drawPixel(charX, charY, colors.lightBlue)
- end
- charX = charX +1
- end
- else
- biomeTransition = math.random(1,15)
- if biomeTransition == 1 then
- biome = biomes[ math.random(1,#biomes) ]
- end
- scrollX = scrollX -1
- if chunks[charX+2] 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
- 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, colors.lightBlue )
- 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,colors.lightBlue)
- 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, colors.lightBlue)
- end
- if _name then
- drawPixel(charX, charY, _name)
- else
- drawPixel(charX, charY, colors.lightBlue)
- end
- charY = charY +1
- gravity = nil
- 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
Advertisement
Add Comment
Please, Sign In to add comment