xXm0dzXx

Mineception - Minecraft in Minecraft

Dec 18th, 2012
2,155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 24.16 KB | None | 0 0
  1. local blown = true
  2. local mind = blown
  3.  
  4. local x,y = term.getSize()
  5. local charX, charY = 4,4
  6. local selectedSlot = 1
  7. local health = 10
  8. local debug1 = false
  9. local debugX = 1
  10. local debugY = 1
  11. local scrollX = 0
  12. local scrollY = 0
  13. local biome = "desert"
  14. local worldTransition = nil
  15. local skyColor = colors.lightBlue
  16. local guiData = {} --Coming Soon
  17. local height = 5
  18. local seed = os.time()
  19.  
  20. local recipes = {}
  21. local screenData = {}
  22. biomes = {
  23.     [1] = "desert",
  24.     [2] = "forest",
  25.     [1] = "extreme_hills",
  26. }
  27. spawnBiomes = {
  28.     [1] = "desert",
  29.     [2] = "forest",
  30. }
  31. world = {
  32. }
  33. inventory = {
  34. }
  35.  
  36. blocks = {}
  37. chunks = {}
  38.  
  39. tArgs = { ... }
  40. if tArgs[1] then
  41.     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','!','@','#','$','%','^','&','*','(',')',' '}
  42.     local resultsc = 50
  43.     local sText = table.concat( tArgs, " " )
  44.     for i=1,#sText do
  45.         local text = string.sub( sText, i, i )
  46.         for i=1,#chars do
  47.             if chars[i] == text then
  48.                 resultsc = resultsc + i
  49.             else
  50.                 resultsc = resultsc + 12
  51.             end
  52.         end
  53.     end
  54.    
  55.     seed = tonumber( resultsc )
  56. end
  57.  
  58. math.randomseed( seed )
  59.  
  60. local function cPrint( txt ) --Version 2.0 of cPrint
  61.     local function printC( text )
  62.         x2,y2 = term.getCursorPos()
  63.         term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), y2)
  64.         write(text.. "\n")
  65.     end
  66.    
  67.     if type(txt) == "string" then
  68.         printC( txt )
  69.     elseif type(txt) == "table" then
  70.         for i=1,#txt do
  71.             printC( txt[i] )
  72.         end
  73.     end
  74. end
  75.  
  76. local function lPrint( txt )
  77.     local x2, y2 = term.getCursorPos()
  78.     term.setCursorPos( (x-(#txt))+1, y2 )
  79.     write( text.. "\n" )
  80. end
  81.  
  82. local drawingBoard = {
  83.     ["A"] = colors.white,
  84.     ["B"] = colors.orange,
  85.     ["C"] = colors.magenta,
  86.     ["D"] = colors.lightBlue,
  87.     ["E"] = colors.yellow,
  88.     ["F"] = colors.lime,
  89.     ["G"] = colors.pink,
  90.     ["H"] = colors.gray,
  91.     ["I"] = colors.lightGray,
  92.     ["J"] = colors.cyan,
  93.     ["K"] = colors.purple,
  94.     ["L"] = colors.blue,
  95.     ["M"] = colors.brown,
  96.     ["N"] = colors.green,
  97.     ["O"] = colors.red,
  98.     ["P"] = colors.black,
  99. }
  100.  
  101. local function advWrite( pos1, pos2, str )
  102.     for i=1,#str do
  103.         local symb = drawingBoard[ string.sub( str, i, i) ]
  104.         term.setCursorPos( pos1 + (i-1) , pos2 )
  105.         if symb then
  106.             term.setBackgroundColour( symb )
  107.             write(" ")
  108.         end
  109.     end
  110. end
  111.  
  112. function registerBlock( id, name, color, hardness, info, placeable, texture, onTouched )
  113.     if placeable == nil then
  114.         placeable = true
  115.     end
  116.    
  117.     if texture == nil then
  118.         texture = " "
  119.     end
  120.    
  121.     blocks[id] = {
  122.                     ["DisplayName"] = name,
  123.                     ["Color"] = color,
  124.                     ["Hardness"] = hardness,
  125.                     ["Others"] = info,
  126.                     ["CanBePlaced"] = placeable,
  127.                     ["Texture"] = texture,
  128.                     ["onTouched"] = onTouched,
  129.                 }
  130. end
  131.  
  132. function registerItem( id, name, color, text )
  133.     blocks[id] = {
  134.                     ["DisplayName"] = name,
  135.                     ["Color"] = color,
  136.                     ["Hardness"] = -1,
  137.                     ["Others"] = "Item",
  138.                     ["CanBePlaced"] = false,
  139.                     ["Texture"] = text,
  140.                     ["onTouched"] = onTouched,
  141.                 }
  142. end
  143.  
  144. function getColorByName( name )
  145.     for i=1,256 do
  146.         blockInfo = blocks[i]
  147.         if blockInfo then
  148.             if blockInfo["DisplayName"] == name then
  149.                 return blockInfo["Color"]
  150.             end
  151.         end
  152.     end
  153.    
  154.     return false
  155. end
  156.  
  157. function getHardnessByName( name )
  158.     for i=1,256 do
  159.         blockInfo = blocks[i]
  160.         if blockInfo then
  161.             if blockInfo["DisplayName"] == name then
  162.                 return blockInfo["Hardness"]
  163.             end
  164.         end
  165.     end
  166.    
  167.     return false
  168. end
  169.  
  170. function drawPixel( x22, y22, color )
  171.     if screenData[ x22.. "/" ..y22 ] ~= color then
  172.         screenData[ x22.. "/" ..y22 ] = color
  173.         local x1,y1 = term.getCursorPos()
  174.         term.setCursorPos(x22,y22)
  175.         if tostring( color ) == color then
  176.             if getColorByName( color ) then
  177.                 term.setBackgroundColour( getColorByName( color ) )
  178.             else
  179.                 term.setBackgroundColour( colors.magenta )
  180.             end
  181.         else
  182.             term.setBackgroundColour( color )
  183.         end
  184.         write(" ")
  185.         term.setCursorPos(x1,y1)
  186.         term.setBackgroundColour( colors.black )
  187.     end
  188. end
  189.  
  190. function drawCharacter()
  191.     drawPixel(charX, charY-1, colors.orange)
  192.     drawPixel(charX, charY, colors.cyan)
  193. end
  194.  
  195. function hasBlock( name, inventory1 )
  196.         for i=1,24 do
  197.             if inventory[i] then
  198.                 if (inventory[i])["name"] == name then
  199.                     if inventory1 and inventory[i]["quantity"] == 9 then
  200.                     else
  201.                         return i, inventory[i]["quantity"]
  202.                     end
  203.                 end
  204.             end
  205.         end
  206.     return false
  207. end
  208.  
  209. function breakBlock( x, y )
  210.     x = x - scrollX
  211.     y = y - scrollY
  212.     for i=1,#world do
  213.         blockInfo = world[i]
  214.         if blockInfo["x"] == x and blockInfo["y"] == y then
  215.             inventoryNum = #inventory+1
  216.             inv, amm = hasBlock( blockInfo["name"], true )
  217.             tValue = math.random(1,3)
  218.             if blockInfo["name"] ~= "Sapling" then
  219.                 tValue = 3
  220.             end
  221.            
  222.             if #inventory ~= 24 then
  223.                 if tValue == 3 then
  224.                     if inv and amm ~= 9 then
  225.                         inventory[inv]["quantity"] = amm +1
  226.                     else
  227.                         inventory[inventoryNum] = {
  228.                                 ["name"] = blockInfo["name"],
  229.                                 ["quantity"] = 1,
  230.                             }
  231.                     end
  232.                 end
  233.             end
  234.             world[i] = nil
  235.         end
  236.     end
  237.     cleanupWorld()
  238. end
  239.  
  240. function getBlockInfo( x,y )
  241.     x = x - scrollX
  242.     y = y - scrollY
  243.     for i=1,#world do
  244.         blockInfo = world[i]
  245.         if blockInfo["x"] == x and blockInfo["y"] == y then
  246.             return blockInfo["x"], blockInfo["y"], blockInfo["name"]
  247.         end
  248.     end
  249. end
  250.  
  251. function cleanupWorld()
  252.     local nWorld = {}
  253.     for k,v in pairs( world ) do
  254.         if v then
  255.             nWorld[#nWorld+1] = v
  256.         end
  257.     end
  258.     world = nWorld
  259. end
  260.  
  261. function clear()
  262.     term.setBackgroundColour( skyColor )
  263.     screenData = {}
  264.     drawPixel(1,1, colors.yellow )
  265.     drawPixel(2,1, colors.orange )
  266.     drawPixel(2,2, colors.orange )
  267.     drawPixel(1,2, colors.orange )
  268. end
  269.  
  270. function redrawWorld()
  271.     local oldScreenData = screenData
  272.    
  273.     clear()
  274.     drawWorld()
  275.     drawCharacter()
  276.     drawGUI()
  277.    
  278.     if oldScreenData ~= screenData then
  279.         for i,v in pairs( oldScreenData ) do
  280.             if screenData[ i ] == nil then
  281.                 local tWords = {}
  282.                 for match in string.gmatch( i, "[^/\t]+" ) do
  283.                     table.insert( tWords, match )
  284.                 end
  285.                
  286.                 local screenX = tonumber(tWords[1])
  287.                 local screenY = tonumber(tWords[2])
  288.                
  289.                 term.setCursorPos( screenX, screenY )
  290.                 term.setBackgroundColour( skyColor )
  291.                 write(" ")
  292.             end
  293.         end
  294.     end
  295. end
  296.  
  297. function placeBlock( x,y,name )
  298.     x = x - scrollX
  299.     y = y - scrollY
  300.     world[#world+1] = {
  301.                         ["x"] = x,
  302.                         ["y"] = y,
  303.                         ["name"] = name,
  304.                     }
  305. end
  306.  
  307. function drawWorld()
  308.     for i=1,#world do
  309.         local blockInfo = world[i]
  310.         --if blocksAbove(blockInfo["x"],blockInfo["y"]) ~= 5 then
  311.             --[[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
  312.                 if getBlockInfo( blockInfo["x"] + scrollX, blockInfo["y"] -1 + scrollY ) then
  313.                     if blockInfo["name"] == "Grass" then
  314.                         blockInfo["name"] = "Dirt"
  315.                     end
  316.                 end
  317.                 drawPixel(blockInfo["x"]+scrollX,blockInfo["y"]+scrollY,blockInfo["name"])
  318.             elseif blockInfo["x"] + scrollX == x and blockInfo["y"] + scrollY == y then]]
  319.                 drawPixel(blockInfo["x"]+scrollX,blockInfo["y"]+scrollY,blockInfo["name"])
  320.             --end
  321.         --[[else
  322.             drawPixel(blockInfo["x"],blockInfo["y"], "Darkness")
  323.         end]]
  324.     end
  325.        
  326.     if debug1 then
  327.         term.setBackgroundColour( colors.white )
  328.         term.setTextColour( colors.gray )
  329.         term.setCursorPos(1,1)
  330.         write("               ")
  331.         term.setCursorPos(1,1)
  332.         write("Debugging...")
  333.         term.setCursorPos(1,2)
  334.         write("               ")
  335.         term.setCursorPos(1,2)
  336.         if getBlockInfo( debugX, debugY ) then
  337.             term.setTextColour( colors.red )
  338.         end
  339.         write("MouseX: " ..debugX)
  340.         term.setCursorPos(1,3)
  341.         write("               ")
  342.         term.setCursorPos(1,3)
  343.         write("MouseY: " ..debugY)
  344.         term.setTextColour( colors.gray )
  345.         term.setCursorPos(1,4)
  346.         write("               ")
  347.         term.setCursorPos(1,4)
  348.         write("CharX: " ..charX)
  349.         term.setCursorPos(1,5)
  350.         write("               ")
  351.         term.setCursorPos(1,5)
  352.         write("CharY: " ..charY)
  353.         term.setBackgroundColour( colors.black )
  354.         term.setTextColour( colors.white )
  355.     end
  356. end
  357.  
  358. function registerMob()
  359. end
  360.  
  361. function generateWorld( type_ )
  362.     if type_ == "forest" then
  363.         for i=1,x do
  364.             generateChunk(type_, i)
  365.         end
  366.     elseif type_ == "desert" then
  367.         for i=1,x do
  368.             generateChunk(type_, i)
  369.         end
  370.     elseif type_ == "extreme_hills" then
  371.         for i=1,x do
  372.             generateChunk(type_, i)
  373.         end
  374.     end
  375.    
  376.     local biomeTransition = math.random(1,30)
  377.     if biomeTransition == 30 then
  378.         biome = math.random(1,#biomes)
  379.     end
  380. end
  381.  
  382. function generateChunk( type_, i )
  383.     local hills = math.random( 10 )
  384.     if type_ == "forest" then
  385.         if hills == 1 then
  386.             if height > 4 then
  387.                 height = height -1
  388.             end
  389.         elseif hills == 10 then
  390.             if height < 12 then
  391.                 height = height +1
  392.             end
  393.         end
  394.        
  395.         if math.random( 3 ) == 3 then
  396.             generateTree(i, height-1)
  397.         end
  398.         placeBlock(i,height, "Grass")
  399.         placeBlock(i,height+1, "Dirt")
  400.         placeBlock(i,height+2, "Dirt")
  401.         blockType = math.random(1,2)
  402.         if blockType == 1 then
  403.             placeBlock(i,height+3, "Dirt")
  404.         else
  405.             placeBlock(i,height+3, "Stone")
  406.         end
  407.            
  408.         for v=height+4,y do
  409.             placeBlock(i,v, "Stone")
  410.         end
  411.     elseif type_ == "extreme_hills" then
  412.         if hills > 5 then
  413.             if height > -3 then
  414.                 height = height -1
  415.             end
  416.         elseif hills <= 5 then
  417.             if height < 17 then
  418.                 height = height +1
  419.             end
  420.         end
  421.        
  422.         placeBlock(i,height, "Grass")
  423.         placeBlock(i,height+1, "Dirt")
  424.         placeBlock(i,height+2, "Dirt")
  425.         blockType = math.random(1,2)
  426.         if blockType == 1 then
  427.             placeBlock(i,height+3, "Dirt")
  428.         else
  429.             placeBlock(i,height+3, "Stone")
  430.         end
  431.            
  432.         for v=height+4,y do
  433.             placeBlock(i,v, "Stone")
  434.         end
  435.     elseif type_ == "desert" then
  436.         if hills == 1 then
  437.             if height > 5 then
  438.                 height = height -1
  439.             end
  440.         elseif hills == 10 then
  441.             if height < 15 then
  442.                 height = height +1
  443.             end
  444.         end
  445.        
  446.         placeBlock(i,height, "Sand")
  447.         placeBlock(i,height+1, "Sand")
  448.         placeBlock(i,height+2, "Sand")
  449.         blockType = math.random(1,2)
  450.         if blockType == 1 then
  451.             placeBlock(i,height+3, "Sand")
  452.         else
  453.             placeBlock(i,height+3, "Stone")
  454.         end
  455.            
  456.         for v=height+4,y do
  457.             placeBlock(i,v, "Stone")
  458.         end
  459.     end
  460.    
  461.     chunks[i - scrollX] = {
  462.         ["Type"] = type_,
  463.         ["Height"] = height,
  464.     }
  465. end
  466.  
  467. function generateTree( posX, posY )
  468.     placeBlock( posX, posY, "Wood" )
  469.     placeBlock( posX, posY-1, "Wood" )
  470.     placeBlock( posX, posY-2, "Sapling" )
  471.     placeBlock( posX, posY-3, "Sapling" )
  472.     placeBlock( posX-1, posY-2, "Sapling" )
  473.     placeBlock( posX+1, posY-2, "Sapling" )
  474. end
  475.  
  476. function drawGUI()
  477.     for i=1,8 do
  478.         drawPixel( i, y , colors.white )
  479.     end
  480.     for i=1,20 do
  481.         drawPixel( i, y-1 , colors.black )
  482.     end
  483.     drawPixel( 9, y , colors.black )
  484.     drawPixel( 20, y , colors.black )
  485.     for i=1,health do
  486.         drawPixel( 9+i, y, colors.red )
  487.     end
  488.     term.setCursorPos(10, y-1)
  489.     write("Health")
  490.     term.setCursorPos(1, y-2)
  491.     if inventory[selectedSlot] then
  492.         write( inventory[selectedSlot]["name"].. "(" ..inventory[selectedSlot]["quantity"].. ")" )
  493.     end
  494.     for i=1,8 do
  495.         if inventory[i] then
  496.             drawPixel( i, y, getColorByName( inventory[i]["name"] ) )
  497.             term.setCursorPos(i,y-1)
  498.             write( inventory[i]["quantity"] )
  499.         end
  500.     end
  501.     drawPixel( selectedSlot, y-1, colors.lime )
  502.    
  503.     for i=1,#guiData do
  504.         local gData = guiData[i]
  505.         if gData["Enabled"] == true then
  506.             gData["Main"]( i )
  507.         end
  508.     end
  509. end
  510.    
  511. function blocksAbove( x123, y123 )
  512.     local abuv = 0
  513.     for i=1,5 do
  514.         if getBlockInfo( x123, y123-i ) then
  515.             abuv = abuv +1
  516.         end
  517.     end
  518.     return abuv
  519. end
  520.  
  521. function blockBelow( x123, y123 )
  522.     if getBlockInfo( x123, y123+1 ) then
  523.         return true
  524.     end
  525.     return false
  526. end
  527.  
  528. function newGUI( name, func, key )
  529.     local guiID = #guiData+1
  530.     guiData[ guiID ] = {
  531.         ["Main"] = func,
  532.         [ "Enabled" ] = false,
  533.         [ "Name" ] = name,
  534.         [ "Toggle" ] = key,
  535.     }
  536.     return guiID
  537. end
  538.  
  539. function newCraftingSmall( obj1, obj2, obj3, obj4, result, count )
  540.     if count == nil then
  541.         count = 1
  542.     end
  543.    
  544.     recipes[ #recipes ] = {
  545.         ["Crafting"] = {
  546.             obj1,
  547.             obj2,
  548.             obj3,
  549.             obj4,
  550.         },
  551.         ["Result"] = {
  552.             ["Name"] = result,
  553.             ["Ammount"] = count,
  554.         },
  555.     }
  556. end
  557.  
  558. function inventoryx( inv )
  559.     local selected = 0
  560.     local itemsX = {}
  561.     local currentRecipe = {}
  562.     local disallowed = -1 --Don't touch
  563.     local itemsC = {}
  564.     local crafting = {
  565.         "XCraftingX",
  566.         "X1X2XXXXXX",
  567.         "XXXX->5XXX",
  568.         "X3X4XXXXXX",
  569.         "XXXXXXXXXX",
  570.     }
  571.     local function drawContainers()
  572.         local invPos = 1
  573.         local text = "          "
  574.         term.setCursorPos(1,3)
  575.         xPos = math.ceil((x / 2) - (text:len() / 2))
  576.         for i=1,10 do
  577.             drawPixel( xPos+i-1,3,colors.black )
  578.         end
  579.         print()
  580.        
  581.         for x=1,3 do
  582.             local x,y = term.getSize()
  583.             x2,y2 = term.getCursorPos()
  584.             xPos = math.ceil((x / 2) - (text:len() / 2))
  585.             drawPixel( xPos, y2, colors.black )
  586.            
  587.             for v=1,8 do
  588.                 local i = ((v+xPos))
  589.                 if inventory[invPos] then
  590.                     drawPixel( i, y2, getColorByName( inventory[invPos]["name"] ) )
  591.                     term.setCursorPos( i,y2 )
  592.                     if invPos == selected then
  593.                         term.setTextColour( colors.lime )
  594.                     end
  595.                     term.setBackgroundColour( getColorByName( inventory[invPos]["name"] ) )
  596.                     write( inventory[invPos]["quantity"] )
  597.                    
  598.                     term.setTextColour( colors.white )
  599.                 else
  600.                     drawPixel( i, y2, colors.white )
  601.                 end
  602.                 itemsX[ i.. "/" ..y2 ] = invPos
  603.                 invPos = invPos +1
  604.             end
  605.            
  606.             drawPixel( xPos+9, y2, colors.black )
  607.             print()
  608.         end
  609.     end
  610.    
  611.     local function drawTable( txt )
  612.         for i=1,#txt do
  613.             local text = ( txt[i] )
  614.             local x1, y2 = term.getCursorPos()
  615.             local x2 = math.ceil((x / 2) - (text:len() / 2))
  616.            
  617.             for v=1,#text do
  618.                 local cTxt = string.sub( text, v, v )
  619.                
  620.                 if cTxt == "X" then
  621.                     drawPixel( (x2+v)-1, y2, colors.black )
  622.                 elseif cTxt == "1" or cTxt == "2" or cTxt == "3" or cTxt == "4" or cTxt == "5" then
  623.                     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)
  624.                     itemsX[ ((x2+v)-1).. "/" ..y2 ] = invPos
  625.                     if cTxt == "5" then
  626.                         disallowed = invPos
  627.                     else
  628.                         itemsC[ tonumber( cTxt ) ] = invPos
  629.                     end
  630.                    
  631.                     if inventory[invPos] then
  632.                         drawPixel( (x2+v)-1, y2, getColorByName( inventory[invPos]["name"] ) )
  633.                         term.setCursorPos( (x2+v)-1,y2 )
  634.                         if invPos == selected then
  635.                             term.setTextColour( colors.lime )
  636.                         end
  637.                         term.setBackgroundColour( getColorByName( inventory[invPos]["name"] ) )
  638.                         write( inventory[invPos]["quantity"] )
  639.                        
  640.                         term.setTextColour( colors.white )
  641.                         term.setBackgroundColour( colors.black )
  642.                     else
  643.                         drawPixel( (x2+v)-1, y2, colors.white )
  644.                     end
  645.                 else
  646.                     drawPixel( (x2+v)-1, y2, colors.black )
  647.                     term.setCursorPos( (x2+v)-1, y2 )
  648.                     write( cTxt )
  649.                 end
  650.             end
  651.            
  652.             term.setCursorPos( 1, y2 +1 )
  653.         end
  654.     end
  655.    
  656.     local function usefunc( id ) --mah useless function
  657.         if itemsC[ id ] ~= nil then
  658.             if inventory[itemsC[ id ]] ~= nil then
  659.                 if inventory[itemsC[ id ]]["name"] ~= nil then
  660.                     return inventory[itemsC[ id ]]["name"]
  661.                 end
  662.             end
  663.         end
  664.         return false
  665.     end
  666.    
  667.     while true do
  668.         if itemsC[1] then
  669.             currentRecipe = {
  670.                 usefunc( 1 ),
  671.                 usefunc( 2 ),
  672.                 usefunc( 3 ),
  673.                 usefunc( 4 ),
  674.             }
  675.            
  676.             for lol=1,#recipes do
  677.                 for i=1,4 do
  678.                     if currentRecipe[i] == recipes[lol]["Crafting"][i] then
  679.                         inventory[disallowed] =  {
  680.                             ["name"] = recipes[lol]["Result"]["Name"],
  681.                             ["quantity"] = recipes[lol]["Result"]["Ammount"],
  682.                         }
  683.                         break
  684.                     end
  685.                 end
  686.             end
  687.         end
  688.    
  689.         drawContainers()
  690.         term.setBackgroundColour( colors.black )
  691.         term.setTextColour( colors.white )
  692.         cPrint( text )
  693.         drawTable( crafting )
  694.        
  695.         local event, key, posX, posY = os.pullEvent(  )
  696.        
  697.         if event == "key" then
  698.             guiData[ inv ][ "Enabled" ] = false
  699.             redrawWorld()
  700.             break
  701.         elseif event == "mouse_click" then
  702.             if key == 1 then
  703.                 if itemsX[ posX.. "/" ..posY ] ~= nil then
  704.                     if selected ~= 0 then
  705.                         local itemPos = itemsX[ posX.. "/" ..posY ]
  706.                         if itemPos == selected then
  707.                             selected = 0
  708.                         elseif itemPos ~= disallowed then
  709.                             for i,v in pairs( itemsX ) do
  710.                                 if v == selected then
  711.                                     local old1 = v
  712.                                     local old2 = itemPos
  713.                                    
  714.                                    
  715.                                     local old3 = inventory[ old2 ]
  716.                                     oldInventory = inventory
  717.                                    
  718.                                     inventory[ old2 ] = oldInventory[ old1 ]
  719.                                     inventory[ old1 ] = old3
  720.                                    
  721.                                     if old1 == disallowed then
  722.                                         for i=1,4 do
  723.                                             inventory[ itemsC[i] ] = nil
  724.                                         end
  725.                                     end
  726.                                    
  727.                                     selected = 0
  728.                                     redrawWorld()
  729.                                     break
  730.                                 end
  731.                             end
  732.                         end
  733.                     else
  734.                         selected = itemsX[ posX.. "/" ..posY ]
  735.                     end
  736.                 end
  737.             end
  738.         end
  739.     end
  740. end
  741.  
  742. fs.makeDir(".minecraft")
  743. fs.makeDir(".minecraft/mods")
  744. fs.makeDir(".minecraft/saves")
  745. fs.makeDir(".minecraft/screenshots")
  746.  
  747. registerBlock( 1, "Stone", colors.gray, 3)
  748. registerBlock( 2, "Dirt", colors.brown, 1)
  749. registerBlock( 3, "Grass", colors.green, 1)
  750. registerBlock( 4, "IronOre", colors.orange, 1)
  751. registerBlock( 5, "GoldOre", colors.yellow, 1)
  752. registerBlock( 6, "CoalOre", colors.black, 1)
  753. registerBlock( 7, "Diamond", colors.blue, 1)
  754. registerBlock( 8, "Darkness", colors.black, -1)
  755. registerBlock( 9, "Wood", colors.brown, 1)
  756. registerBlock( 10, "Sapling", colors.lime, 1)
  757. registerBlock( 11, "Planks", colors.orange, 1)
  758. registerBlock( 12, "Sand", colors.yellow, 1)
  759. registerBlock( 13, "Gravel", colors.lightGray, 1)
  760.  
  761. newCraftingSmall( "Wood", "Wood", "Wood", "Wood", "Planks", 4 )
  762.  
  763. local inv = newGUI( "Inventory", inventoryx, 18 )
  764.  
  765. biome = spawnBiomes[ math.random(#spawnBiomes) ]
  766. --[[print("generating world...")
  767. print("biome: " ..biome)
  768. sleep(1)]]--
  769. generateWorld( biome ) --Generate spawn Biome
  770.  
  771. term.setBackgroundColour( colors.lightBlue )
  772. term.clear()
  773. redrawWorld()
  774. term.setTextColour( colors.gray )
  775. term.setCursorPos(1,1)
  776. term.setBackgroundColour( colors.lightBlue )
  777. write("Mineception v1.02")
  778. term.setCursorPos(1,3)
  779. cPrint("Mineception")
  780. term.setTextColour( colors.yellow )
  781. cPrint("Now with crafting!")
  782. term.setCursorPos(1,5)
  783. term.setBackgroundColour( colors.lightGray )
  784. term.setTextColour( colors.white )
  785. cPrint("      Singleplayer      ")
  786. term.setCursorPos(1,7)
  787. term.setTextColour( colors.gray )
  788. term.setBackgroundColour( colors.black )
  789. cPrint("      Multi-player      ")
  790.  
  791. while true do
  792.     local _, lor, mX, mY = os.pullEvent("mouse_click")
  793.     if lor == 1 then
  794.         if mY == 5 then
  795.             if mX < 37 or mX > 14 then
  796.                 break
  797.             end
  798.         end
  799.     end
  800. end
  801.  
  802. term.setBackgroundColour( skyColor )
  803. term.clear()
  804.  
  805. redrawWorld()
  806.  
  807. term.setBackgroundColour( colors.white )
  808. term.setTextColour( colors.white )
  809.  
  810. if blockBelow( charX, charY ) ~= true and gravity == nil then
  811.     gravity = os.startTimer(0)
  812. end
  813.  
  814. while true do
  815.     --os.startTimer( 0 )
  816.     local event, key, posX, posY = os.pullEvent()
  817.     oldslot = selectedSlot
  818.     if event == "key" then
  819.         if key == keys.left then
  820.             function collide()
  821.                 if getBlockInfo( charX -1, charY ) or getBlockInfo( charX -1, charY-1 ) then
  822.                     if getBlockInfo( charX -1, charY-1) and getBlockInfo( charX -1, charY-2) and getBlockInfo( charX -1, charY) then
  823.                     else
  824.                         drawPixel(charX, charY, skyColor)
  825.                         drawPixel(charX, charY-1, skyColor)
  826.                         charX = charX -1
  827.                         charY = charY -1
  828.                     end
  829.                 else
  830.                     local x11, y11, name = getBlockInfo( charX, charY-1)
  831.                     local _x11, _y11, _name = getBlockInfo( charX, charY)
  832.                     if name then
  833.                         drawPixel(charX, charY-1, name)
  834.                     else
  835.                         drawPixel(charX, charY-1, skyColor)
  836.                     end
  837.                     if _name then
  838.                         drawPixel(charX, charY, _name)
  839.                     else
  840.                         drawPixel(charX, charY, skyColor)
  841.                     end
  842.                     charX = charX -1
  843.                 end
  844.             end
  845.            
  846.             if charX ~= 3 then
  847.                 collide()
  848.             else
  849.                 height = chunks[charX-2 - scrollX]["Height"]
  850.                 biomeTransition = math.random(1,15)
  851.                 if biomeTransition == 1 then
  852.                     biome = biomes[ math.random(1,#biomes) ]
  853.                 end
  854.                 scrollX = scrollX +1
  855.                 if not chunks[charX-2 - scrollX] then
  856.                     generateChunk( biome, charX-2 )
  857.                 end
  858.                
  859.                 redrawWorld()
  860.             end
  861.         elseif key == keys.right then
  862.             function collide()
  863.                 if getBlockInfo( charX +1, charY ) or getBlockInfo( charX +1, charY-1 ) then
  864.                     if getBlockInfo( charX +1, charY-1) and getBlockInfo( charX +1, charY-2) and getBlockInfo( charX +1, charY) then
  865.                     elseif getBlockInfo( charX +1, charY-1 ) then
  866.                     else
  867.                         drawPixel(charX, charY, skyColor)
  868.                         drawPixel(charX, charY-1, skyColor)
  869.                         charX = charX +1
  870.                         charY = charY -1
  871.                     end
  872.                 else
  873.                     local x11, y11, name = getBlockInfo( charX, charY-1)
  874.                     local _x11, _y11, _name = getBlockInfo( charX, charY)
  875.                     if name then
  876.                         drawPixel(charX, charY-1, name)
  877.                     else
  878.                         drawPixel(charX, charY-1, skyColor)
  879.                     end
  880.                     if _name then
  881.                         drawPixel(charX, charY, _name)
  882.                     else
  883.                         drawPixel(charX, charY, skyColor)
  884.                     end
  885.                     charX = charX +1
  886.                 end
  887.             end
  888.            
  889.             if charX < x -2 then
  890.                 collide()
  891.             else
  892.                 height = chunks[charX+2 - scrollX]["Height"]
  893.                 biomeTransition = math.random(1,15)
  894.                 if biomeTransition == 1 then
  895.                     biome = biomes[ math.random(1,#biomes) ]
  896.                 end
  897.                 scrollX = scrollX -1
  898.                 if not chunks[charX+2 - scrollX] then
  899.                     generateChunk( biome, charX+2 )
  900.                 end
  901.                
  902.                 redrawWorld()
  903.             end
  904.         elseif key == 2 then
  905.             selectedSlot = 1
  906.         elseif key == 3 then
  907.             selectedSlot = 2
  908.         elseif key == 4 then
  909.             selectedSlot = 3
  910.         elseif key == 5 then
  911.             selectedSlot = 4
  912.         elseif key == 6 then
  913.             selectedSlot = 5
  914.         elseif key == 7 then
  915.             selectedSlot = 6
  916.         elseif key == 8 then
  917.             selectedSlot = 7
  918.         elseif key == 9 then
  919.             selectedSlot = 8
  920.         elseif key == 61 then
  921.             if debug1 then debug1 = false else debug1 = true end
  922.             clear()
  923.             drawWorld()
  924.         end
  925.        
  926.        
  927.         for i=1,#guiData do
  928.             local gData = guiData[i]
  929.             if gData["Toggle"]  == key then
  930.                 if gData[ "Enabled" ] then
  931.                     gData[ "Enabled" ] = false
  932.                 else
  933.                     gData[ "Enabled" ] = true
  934.                 end
  935.                
  936.                 redrawWorld()
  937.             end
  938.         end
  939.     elseif event == "mouse_click" then
  940.         debugX = posX
  941.         debugY = posY
  942.         if key == 1 then
  943.             local _, _, nameyy = getBlockInfo( posX, posY )
  944.             if getHardnessByName( nameyy ) ~= -1 then
  945.                 breakBlock( posX, posY )
  946.                 drawPixel( posX, posY, skyColor )
  947.             end
  948.         elseif key == 2 then
  949.             if inventory[selectedSlot] then
  950.                 if posY == charY and posX == charX then
  951.                     if not getBlockInfo(charX,charY -2) then
  952.                         placeBlock( charX, charY, inventory[selectedSlot]["name"] )
  953.                         inventory[selectedSlot]["quantity"] = inventory[selectedSlot]["quantity"] -1
  954.                         drawPixel(charX,charY,inventory[selectedSlot]["name"])
  955.                         if inventory[selectedSlot]["quantity"] == 0 then
  956.                             inventory[selectedSlot] = nil
  957.                         end
  958.                        
  959.                         drawPixel(charX,charY-1,skyColor)
  960.                         charY = charY -1
  961.                     end
  962.                 elseif not getBlockInfo( posX, posY ) then
  963.                     if posY == charY+1 and posX == charX then else
  964.                         placeBlock( posX, posY, inventory[selectedSlot]["name"] )
  965.                         inventory[selectedSlot]["quantity"] = inventory[selectedSlot]["quantity"] -1
  966.                         drawPixel( posX, posY, inventory[selectedSlot]["name"] )
  967.                         if inventory[selectedSlot]["quantity"] == 0 then
  968.                             inventory[selectedSlot] = nil
  969.                         end
  970.                     end
  971.                 end
  972.             end
  973.         end
  974.     elseif event == "timer" then
  975.         if key == worldTransition then
  976.             worldTransition = nil
  977.         elseif key == gravity then
  978.             local x11, y11, name = getBlockInfo( charX, charY-1)
  979.             local _x11, _y11, _name = getBlockInfo( charX, charY)
  980.             if name then
  981.                 drawPixel(charX, charY-1, name)
  982.             else
  983.                 drawPixel(charX, charY-1, skyColor)
  984.             end
  985.             if _name then
  986.                 drawPixel(charX, charY, _name)
  987.             else
  988.                 drawPixel(charX, charY, skyColor)
  989.             end
  990.             charY = charY +1
  991.             gravity = nil
  992.         else
  993.             --[[local oldSkyColor = skyColor
  994.             if os.time() > 6 and os.time() < 20 then
  995.                 skyColor = colors.lightBlue
  996.             else
  997.                 skyColor = colors.purple
  998.             end
  999.            
  1000.             if skyColor ~= oldSkyColor then
  1001.                 redrawWorld()
  1002.             end]]
  1003.         end
  1004.     end
  1005.        
  1006.     if oldslot ~= selectedSlot then
  1007.         clear()
  1008.         drawWorld()
  1009.     end
  1010.    
  1011.     if blockBelow( charX, charY ) ~= true and gravity == nil then
  1012.         gravity = os.startTimer(0)
  1013.     end
  1014.    
  1015.     drawCharacter()
  1016.     drawGUI()
  1017. end
Advertisement
Add Comment
Please, Sign In to add comment