{"id":13423409,"url":"https://github.com/fogleman/Craft","last_synced_at":"2025-03-15T17:31:43.129Z","repository":{"id":38375374,"uuid":"9330072","full_name":"fogleman/Craft","owner":"fogleman","description":"A simple Minecraft clone written in C using modern OpenGL (shaders).","archived":false,"fork":false,"pushed_at":"2024-04-03T15:49:34.000Z","size":14666,"stargazers_count":10577,"open_issues_count":124,"forks_count":1406,"subscribers_count":350,"default_branch":"master","last_synced_at":"2025-03-11T19:18:45.210Z","etag":null,"topics":["c","game","glsl","minecraft","multiplayer","opengl","sqlite"],"latest_commit_sha":null,"homepage":"http://www.michaelfogleman.com/craft/","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fogleman.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2013-04-09T19:47:38.000Z","updated_at":"2025-03-11T11:49:04.000Z","dependencies_parsed_at":"2023-02-06T08:01:52.585Z","dependency_job_id":"2b480eea-3df3-4c07-bbb7-dd303defd39b","html_url":"https://github.com/fogleman/Craft","commit_stats":{"total_commits":706,"total_committers":17,"mean_commits":"41.529411764705884","dds":0.0439093484419264,"last_synced_commit":"d6888a6e1e54340358ce25b1220f410541360b6b"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fogleman%2FCraft","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fogleman%2FCraft/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fogleman%2FCraft/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fogleman%2FCraft/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fogleman","download_url":"https://codeload.github.com/fogleman/Craft/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243766830,"owners_count":20344820,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c","game","glsl","minecraft","multiplayer","opengl","sqlite"],"created_at":"2024-07-31T00:00:33.874Z","updated_at":"2025-03-15T17:31:42.273Z","avatar_url":"https://github.com/fogleman.png","language":"C","readme":"## Craft\n\nMinecraft clone for Windows, Mac OS X and Linux. Just a few thousand lines of C using modern OpenGL (shaders). Online multiplayer support is included using a Python-based server.\n\nhttp://www.michaelfogleman.com/craft/\n\n![Screenshot](https://i.imgur.com/SH7wcas.png)\n\n### Features\n\n* Simple but nice looking terrain generation using perlin / simplex noise.\n* More than 10 types of blocks and more can be added easily.\n* Supports plants (grass, flowers, trees, etc.) and transparency (glass).\n* Simple clouds in the sky (they don't move).\n* Day / night cycles and a textured sky dome.\n* World changes persisted in a sqlite3 database.\n* Multiplayer support!\n\n### Download\n\nMac and Windows binaries are available on the website.\n\nhttp://www.michaelfogleman.com/craft/\n\nSee below to run from source.\n\n### Install Dependencies\n\n#### Mac OS X\n\nDownload and install [CMake](http://www.cmake.org/cmake/resources/software.html)\nif you don't already have it. You may use [Homebrew](http://brew.sh) to simplify\nthe installation:\n\n    brew install cmake\n\n#### Linux (Ubuntu)\n\n    sudo apt-get install cmake libglew-dev xorg-dev libcurl4-openssl-dev\n    sudo apt-get build-dep glfw\n\n#### Windows\n\nDownload and install [CMake](http://www.cmake.org/cmake/resources/software.html)\nand [MinGW](http://www.mingw.org/). Add `C:\\MinGW\\bin` to your `PATH`.\n\nDownload and install [cURL](http://curl.haxx.se/download.html) so that\nCURL/lib and CURL/include are in your Program Files directory.\n\nUse the following commands in place of the ones described in the next section.\n\n    cmake -G \"MinGW Makefiles\"\n    mingw32-make\n\n### Compile and Run\n\nOnce you have the dependencies (see above), run the following commands in your\nterminal.\n\n    git clone https://github.com/fogleman/Craft.git\n    cd Craft\n    cmake .\n    make\n    ./craft\n\n### Multiplayer\n\nAfter many years, craft.michaelfogleman.com has been taken down. See the [Server](#server) section for info on self-hosting.\n\n#### Client\n\nYou can connect to a server with command line arguments...\n\n```bash\n./craft [HOST [PORT]]\n```\n\nOr, with the \"/online\" command in the game itself.\n    \n    /online [HOST [PORT]]\n\n#### Server\n\nYou can run your own server or connect to mine. The server is written in Python\nbut requires a compiled DLL so it can perform the terrain generation just like\nthe client.\n\n```bash\ngcc -std=c99 -O3 -fPIC -shared -o world -I src -I deps/noise deps/noise/noise.c src/world.c\npython server.py [HOST [PORT]]\n```\n\n### Controls\n\n- WASD to move forward, left, backward, right.\n- Space to jump.\n- Left Click to destroy a block.\n- Right Click or Cmd + Left Click to create a block.\n- Ctrl + Right Click to toggle a block as a light source.\n- 1-9 to select the block type to create.\n- E to cycle through the block types.\n- Tab to toggle between walking and flying.\n- ZXCVBN to move in exact directions along the XYZ axes.\n- Left shift to zoom.\n- F to show the scene in orthographic mode.\n- O to observe players in the main view.\n- P to observe players in the picture-in-picture view.\n- T to type text into chat.\n- Forward slash (/) to enter a command.\n- Backquote (`) to write text on any block (signs).\n- Arrow keys emulate mouse movement.\n- Enter emulates mouse click.\n\n### Chat Commands\n\n    /goto [NAME]\n\nTeleport to another user.\nIf NAME is unspecified, a random user is chosen.\n\n    /list\n\nDisplay a list of connected users.\n\n    /login NAME\n\nSwitch to another registered username.\nThe login server will be re-contacted. The username is case-sensitive.\n\n    /logout\n\nUnauthenticate and become a guest user.\nAutomatic logins will not occur again until the /login command is re-issued.\n\n    /offline [FILE]\n\nSwitch to offline mode.\nFILE specifies the save file to use and defaults to \"craft\".\n\n    /online HOST [PORT]\n\nConnect to the specified server.\n\n    /pq P Q\n\nTeleport to the specified chunk.\n\n    /spawn\n\nTeleport back to the spawn point.\n\n### Screenshot\n\n![Screenshot](https://i.imgur.com/foYz3aN.png)\n\n### Implementation Details\n\n#### Terrain Generation\n\nThe terrain is generated using Simplex noise - a deterministic noise function seeded based on position. So the world will always be generated the same way in a given location.\n\nThe world is split up into 32x32 block chunks in the XZ plane (Y is up). This allows the world to be “infinite” (floating point precision is currently a problem at large X or Z values) and also makes it easier to manage the data. Only visible chunks need to be queried from the database.\n\n#### Rendering\n\nOnly exposed faces are rendered. This is an important optimization as the vast majority of blocks are either completely hidden or are only exposing one or two faces. Each chunk records a one-block width overlap for each neighboring chunk so it knows which blocks along its perimeter are exposed.\n\nOnly visible chunks are rendered. A naive frustum-culling approach is used to test if a chunk is in the camera’s view. If it is not, it is not rendered. This results in a pretty decent performance improvement as well.\n\nChunk buffers are completely regenerated when a block is changed in that chunk, instead of trying to update the VBO.\n\nText is rendered using a bitmap atlas. Each character is rendered onto two triangles forming a 2D rectangle.\n\n“Modern” OpenGL is used - no deprecated, fixed-function pipeline functions are used. Vertex buffer objects are used for position, normal and texture coordinates. Vertex and fragment shaders are used for rendering. Matrix manipulation functions are in matrix.c for translation, rotation, perspective, orthographic, etc. matrices. The 3D models are made up of very simple primitives - mostly cubes and rectangles. These models are generated in code in cube.c.\n\nTransparency in glass blocks and plants (plants don’t take up the full rectangular shape of their triangle primitives) is implemented by discarding magenta-colored pixels in the fragment shader.\n\n#### Database\n\nUser changes to the world are stored in a sqlite database. Only the delta is stored, so the default world is generated and then the user changes are applied on top when loading.\n\nThe main database table is named “block” and has columns p, q, x, y, z, w. (p, q) identifies the chunk, (x, y, z) identifies the block position and (w) identifies the block type. 0 represents an empty block (air).\n\nIn game, the chunks store their blocks in a hash map. An (x, y, z) key maps to a (w) value.\n\nThe y-position of blocks are limited to 0 \u003c= y \u003c 256. The upper limit is mainly an artificial limitation to prevent users from building unnecessarily tall structures. Users are not allowed to destroy blocks at y = 0 to avoid falling underneath the world.\n\n#### Multiplayer\n\nMultiplayer mode is implemented using plain-old sockets. A simple, ASCII, line-based protocol is used. Each line is made up of a command code and zero or more comma-separated arguments. The client requests chunks from the server with a simple command: C,p,q,key. “C” means “Chunk” and (p, q) identifies the chunk. The key is used for caching - the server will only send block updates that have been performed since the client last asked for that chunk. Block updates (in realtime or as part of a chunk request) are sent to the client in the format: B,p,q,x,y,z,w. After sending all of the blocks for a requested chunk, the server will send an updated cache key in the format: K,p,q,key. The client will store this key and use it the next time it needs to ask for that chunk. Player positions are sent in the format: P,pid,x,y,z,rx,ry. The pid is the player ID and the rx and ry values indicate the player’s rotation in two different axes. The client interpolates player positions from the past two position updates for smoother animation. The client sends its position to the server at most every 0.1 seconds (less if not moving).\n\nClient-side caching to the sqlite database can be performance intensive when connecting to a server for the first time. For this reason, sqlite writes are performed on a background thread. All writes occur in a transaction for performance. The transaction is committed every 5 seconds as opposed to some logical amount of work completed. A ring / circular buffer is used as a queue for what data is to be written to the database.\n\nIn multiplayer mode, players can observe one another in the main view or in a picture-in-picture view. Implementation of the PnP was surprisingly simple - just change the viewport and render the scene again from the other player’s point of view.\n\n#### Collision Testing\n\nHit testing (what block the user is pointing at) is implemented by scanning a ray from the player’s position outward, following their sight vector. This is not a precise method, so the step rate can be made smaller to be more accurate.\n\nCollision testing simply adjusts the player’s position to remain a certain distance away from any adjacent blocks that are obstacles. (Clouds and plants are not marked as obstacles, so you pass right through them.)\n\n#### Sky Dome\n\nA textured sky dome is used for the sky. The X-coordinate of the texture represents time of day. The Y-values map from the bottom of the sky sphere to the top of the sky sphere. The player is always in the center of the sphere. The fragment shaders for the blocks also sample the sky texture to determine the appropriate fog color to blend with based on the block’s position relative to the backing sky.\n\n#### Ambient Occlusion\n\nAmbient occlusion is implemented as described on this page:\n\nhttp://0fps.wordpress.com/2013/07/03/ambient-occlusion-for-minecraft-like-worlds/\n\n#### Dependencies\n\n* GLEW is used for managing OpenGL extensions across platforms.\n* GLFW is used for cross-platform window management.\n* CURL is used for HTTPS / SSL POST for the authentication process.\n* lodepng is used for loading PNG textures.\n* sqlite3 is used for saving the blocks added / removed by the user.\n* tinycthread is used for cross-platform threading.\n","funding_links":[],"categories":["C","Reference","By Industry","游戏","Games Tools / Game Development","c","Sandbox","Native","Uncategorized"],"sub_categories":["Miscs","Gaming","网络服务_其他","General","Sandbox","Uncategorized"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffogleman%2FCraft","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffogleman%2FCraft","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffogleman%2FCraft/lists"}