After forking the repository, run the following commands to get started:
- Ensure you have Node.js and
pnpm
installed. To install pnpm runnpm i -g [email protected]
. - Install dependencies:
pnpm i
- Start the project in development mode:
pnpm start
- Read the Tasks Categories and Workflow sections below
- Let us know if you are working on something and be sure to open a PR if you got any changes. Happy coding!
There are 3 main parts of the project:
This is the main app source code which reuses all the other parts of the project.
The first version used Webpack, then was migrated to Esbuild and now is using Rsbuild!
- Scripts:
- Start:
pnpm start
,pnpm dev-rsbuild
(if you don't need proxy server also running) - Build:
pnpm build
(note thatbuild
script builds only the core app, not the whole project!)
- Start:
Paths:
src
- main app source codesrc/react
- React components - almost all UI is in this folder. Almost every component has its base (reused in app and storybook) andProvider
- which is a component that provides context to its children. Consider looking at DeathScreen component to see how it's used.
-
Playground Scripts:
- Start:
pnpm run-playground
(playground, mesher + server) orpnpm watch-playground
- Build:
pnpm build-playground
ornode prismarine-viewer/esbuild.mjs
- Start:
-
Mesher Scripts:
- Start:
pnpm watch-mesher
- Build:
pnpm build-mesher
- Start:
Paths:
prismarine-viewer
- Improved and refactored version of https://github.com/prismarineJS/prismarine-viewer. Here is everything related to rendering the game world itself (no ui at all). Two most important parts here are:prismarine-viewer/viewer/lib/worldrenderer.ts
- adding new objects to three.js happens here (sections)prismarine-viewer/viewer/lib/models.ts
- preparing data for rendering (blocks) - happens in worker: out file -worker.js
, building -prismarine-viewer/buildWorker.mjs
prismarine-viewer/examples/playground.ts
- Playground (source of <mcraft.fun/playground.html>) Use this for testing any rendering changes. You can also modify the playground code.
Storybook is a tool for easier developing and testing React components.
Path of all Storybook stories is src/react/**/*.stories.tsx
.
- Scripts:
- Start:
pnpm storybook
- Build:
pnpm build-storybook
- Start:
How different modules are used:
mineflayer
- providerbot
variable and as mineflayer states it is a wrapper for thenode-minecraft-protocol
module and is used to connect and interact with real Java Minecraft servers. However not all events & properties are exposed and sometimes you have to usebot._client.on('packet_name', data => ...)
to handle packets that are not handled via mineflayer API. Also you can use almost any mineflayer plugin.
To start the main web app and playground, run pnpm run-all
. Note is doesn't start storybook and tests.
Cypress tests are located in cypress
folder. To run them, run pnpm test-mc-server
and then pnpm test:cypress
when the pnpm prod-start
is running (or change the port to 3000 to test with the dev server). Usually you don't need to run these until you get issues on the CI.
There are not many unit tests for now (which we are trying to improve).
Location of unit tests: **/*.test.ts
files in src
folder and prismarine-viewer
folder.
Start them with pnpm test-unit
.
You can get a description of packets for the latest protocol version from https://wiki.vg/Protocol and for previous protocol versions from https://wiki.vg/Protocol_version_numbers (look for Page links that have Protocol in URL).
Also there are src/generatedClientPackets.ts and src/generatedServerPackets.ts files that have definitions of packets that come from the server and the client respectively. These files are generated from the protocol files. Protocol, blocks info and other data go from https://github.com/prismarineJS/minecraft-data repository.
-
To link dependency locally e.g. flying-squid add this to
pnpm
>overrides
of root package.json:"flying-squid": "file:../space-squid",
(with some modulespnpm link
also works) -
Press
Y
to reload application into the same world (server, local world or random singleplayer world) -
To start React profiling disable
REACT_APP_PROFILING
code first. -
It's recommended to use debugger for debugging. VSCode has a great debugger built-in. If debugger is slow, you can use
--no-sources
flag that would allow browser to speedup .map file parsing. -
Some data are cached between restarts. If you see something doesn't work after upgrading dependencies, try to clear the by simply removing the
dist
folder. -
The same folder
dist
is used for both development and production builds, so be careful when deploying the project. -
Use
start-prod
script to start the project in production mode after running thebuild
script to build the project. -
If CI is failing on the next branch for some reason, feel free to use the latest commit for release branch. We will update the base branch asap. Please, always make sure to allow maintainers do changes when opening PRs.
(most important for now are on top).
Everything related to the client side packets. Investigate issues when something goes wrong with some server. It's much easier to work on these types of tasks when you have experience in Java with Minecraft, a deep understanding of the original client, and know how to debug it (which is not hard actually). Right now the client is easily detectable by anti-cheat plugins, and the main goal is to fix it (mostly because of wrong physics implementation).
Priority tasks:
- Rewrite or fix the physics logic (Botcraft or Grim can be used as a reference as well)
- Implement basic minecart / boat / horse riding
- Fix auto jump module (false triggers, performance issues)
- Investigate connection issues to some servers
- Setup a platform for automatic cron testing against the latest version of the anti-cheat plugins
- ...
Goals:
- Make more servers playable. Right now on hypixel-like servers (servers with minigames), only tnt run (and probably ) is fully playable.
Notes:
- You can see the incoming/outgoing packets in the console (F12 in Chrome) by enabling
options.debugLogNotFrequentPackets = true
. However, if you need a FULL log of all packets, you can start recording the packets by going intoSettings
>Advanced
>Enable Packets Replay
and then you can download the file and use it to replay the packets. - You can use mcraft-e2e studio to send the same packets over and over again (which is useful for testing) or use the packets replayer (which is useful for debugging).
Example tasks:
- Improve / fix entity rendering
- Better update entities on specific packets
- Investigate performance issues under different conditions (instructions provided)
- Work on the playground code
Goals:
- Fix a lot of entity rendering issues (including position updates)
- Implement switching camera mode (first person, third person, etc)
- Animated blocks
- Armor rendering
- ...
Note:
- It's useful to know how to use helpers & additional cameras (e.g. setScissor)
Flying squid fork (space-squid). Example tasks:
- Add missing commands (e.g. /scoreboard)
- Basic physics (player fall damage, falling blocks & entities)
- Basic entities AI (spawning, attacking)
- Pvp
- Emit more packets on some specific events (e.g. when a player uses an item)
- Make more maps playable (e.g. fix when something is not implemented in both server and client and blocking map interaction)
- ...
Long Term Goals:
- Make most adventure maps playable
- Make a way to complete the game from the scratch (crafting, different dimensions, terrain generation, etc)
- Make bedwars playable! Most of the tasks are straightforward to implement, just be sure to use a debugger ;). If you feel you are stuck, ask for help on Discord. Absolutely any tests / refactor suggestions are welcome!
New React components, improve UI (including mobile support).
- Locate the problem on the public test server & make an easily reproducible environment (you can also use local packets replay server or your custom server setup). Dm me for details on public test server / replay server
- Debug the code, find an issue in the code, isolate the problem
- Develop, try to fix and test. Finally we should find a way to fix it. It's ideal to have an automatic test but it's not necessary for now
- Repeat step 1 to make sure the task is done and the problem is fixed (or the feature is implemented)
- Ensure mineflayer fork is up to date with the latest version of mineflayer original repo
- Update PrismarineJS dependencies to the latest version:
minecraft-data
(be sure to replace the version twice in the package.json),mineflayer
,minecraft-protocol
,prismarine-block
,prismarine-chunk
,prismarine-item
, ... - If
minecraft-protocol
patch fails, do this:- Remove the patch from
patchedDependencies
inpackage.json
- Run
pnpm patch minecraft-protocol
, open patch directory - Apply the patch manually in this directory:
patch -p1 < minecraft-protocol@<version>.patch
- Run the suggested command from
pnpm patch ...
(previous step) to update the patch
- Remove the patch from
- cleanup folder & modules structure, cleanup playground code