4.7 KiB
Contributing Guide
After forking the repository, run the following commands to get started:
- Ensure you have Node.js and
pnpminstalled. To install pnpm runnpm i -g pnpm@9.0.4. - Install dependencies:
pnpm i - Start the project in development mode:
pnpm start
Project Structure
There are 3 main parts of the project:
Core (src)
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 thatbuildscript 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.
Renderer: Playground & Mesher (prismarine-viewer)
-
Playground Scripts:
- Start:
pnpm run-playground(playground, mesher + server) orpnpm watch-playground - Build:
pnpm build-playgroundornode 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.mjsprismarine-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 (.storybook)
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:
Core-related
How different modules are used:
mineflayer- providerbotvariable and as mineflayer states it is a wrapper for thenode-minecraft-protocolmodule 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.
Making protocol-related changes
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.
A few other notes
-
To link dependency locally e.g. flying-squid add this to
pnpm>overridesof root package.json:"flying-squid": "file:../space-squid",(with some modulespnpm linkalso works) -
Press
Yto reload application into the same world (server, local world or random singleplayer world) -
To start React profiling disable
REACT_APP_PROFILINGcode first. -
It's recommended to use debugger for debugging. VSCode has a great debugger built-in. If debugger is slow, you can use
--no-sourcesflag 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
distfolder. -
The same folder
distis used for both development and production builds, so be careful when deploying the project. -
Use
start-prodscript to start the project in production mode after running thebuildscript 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.
Would be useful to have
- cleanup folder & modules structure, cleanup playground code