[ci skip] Simplify and update contribution guidelines

This commit is contained in:
Nassim Jahnke 2024-12-23 12:08:32 +01:00
parent 17f649de1e
commit 976b0a4d8b
No known key found for this signature in database
GPG Key ID: EF6771C01F6EF02F

View File

@ -11,15 +11,12 @@ of any minor nitpicks we might have. Often, it's better for us to solve these
problems for you than make you go back and forth trying to fix them yourself. problems for you than make you go back and forth trying to fix them yourself.
Unfortunately, if you use an organization for your PR, it prevents Paper from Unfortunately, if you use an organization for your PR, it prevents Paper from
modifying it. This requires us to manually merge your PR, resulting in us modifying it. To avoid this, please do not use repositories on organizations
closing the PR instead of marking it as merged. for PRs.
We much prefer to have PRs show as merged, so please do not use repositories
on organizations for PRs.
## Requirements ## Requirements
To get started with PRing changes, you'll need the following software, most of To get started with making changes, you'll need the following software, most of
which can be obtained in (most) package managers such as `apt` (Debian / Ubuntu; which can be obtained in (most) package managers such as `apt` (Debian / Ubuntu;
you will most likely use this for WSL), `homebrew` (macOS / Linux), and more: you will most likely use this for WSL), `homebrew` (macOS / Linux), and more:
@ -39,22 +36,22 @@ If you're compiling with Docker, you can use Adoptium's
[`eclipse-temurin`](https://hub.docker.com/_/eclipse-temurin/) images like so: [`eclipse-temurin`](https://hub.docker.com/_/eclipse-temurin/) images like so:
```console ```console
# docker run -it -v "$(pwd)":/data --rm eclipse-temurin:21.0.3_9-jdk bash # docker run -it -v "$(pwd)":/data --rm eclipse-temurin:21.0.5_11-jdk bash
Pulling image... Pulling image...
root@abcdefg1234:/# javac -version root@abcdefg1234:/# javac -version
javac 21.0.3 javac 21.0.5
``` ```
## Understanding Patches ## Understanding Patches
Unlike the API and its implementation, modifications to Vanilla source files Unlike the API and its implementation, modifications to Minecraft source files
are done through patches. These patches/extensions are split into different are done through patches. These patches/extensions are split into different
three different sets, which are: three different sets, which are:
- `sources` - Per-file patches to individual Minecraft classes; - `sources`: Per-file patches to Minecraft classes;
- `resources` - Per-file patches to Minecraft data files; - `resources`: Per-file patches to Minecraft data files;
- `features` - Larger feature patches that modify multiple Minecraft classes. - `features`: Larger feature patches that modify multiple Minecraft classes.
Because this entire structure is based on patches and git, a basic understanding Because this entire structure is based on patches and git, a basic understanding
of how to use git is required. A basic tutorial can be found here: of how to use git is required. A basic tutorial can be found here:
@ -63,8 +60,8 @@ of how to use git is required. A basic tutorial can be found here:
Assuming you have already forked the repository: Assuming you have already forked the repository:
1. Clone your fork to your local machine; 1. Clone your fork to your local machine;
2. Type `./gradlew applyPatches` in a terminal to apply the changes from upstream. 2. Type `./gradlew applyPatches` in a terminal to apply the patches.
On Windows, replace the `./` with `.\` at the beginning for all `gradlew` commands; On Windows, remove the `./` the beginning of `gradlew` commands;
3. cd into `paper-server` for server changes, and `paper-api` for API changes. 3. cd into `paper-server` for server changes, and `paper-api` for API changes.
**Only changes made in `paper-server/src/minecraft` have to deal with the patch system.** **Only changes made in `paper-server/src/minecraft` have to deal with the patch system.**
@ -73,54 +70,25 @@ initial commits are the decompiled and deobfuscated Minecraft source files. The
patches are applied on top of these files as a single, large commit, which is then followed patches are applied on top of these files as a single, large commit, which is then followed
by the individual feature-patch commits. by the individual feature-patch commits.
### Modifying (per-file) Minecraft patches ## Modifying (per-file) Minecraft patches
This is generally what you need to do when editing Minecraft files. Updating our This is generally what you need to do when editing Minecraft files. Updating our
per-file patches is as easy as making your changes and then running per-file patches is as easy as:
# TODO 1. Making your changes;
in the root directory. If nothing went wrong, you can rebuild patches with 2. Running `./gradlew fixupSourcePatches` in the root directory;
`./gradlew rebuildPatches` and finally commit and PR the patch changes. 3. If nothing went wrong, rebuilding patches with `./gradlew rebuildPatches`;
### Adding larger feature patches ### Resolving rebase conflicts
If you run into conflicts while running `fixupSourcePatches`, you need to go a more
Feature patches are exclusively used for large-scale changes that are hard to manual route:
track and maintain, and that can be optionally dropped, such as the more involved
optimizations we have. This makes it easier to update Paper during Minecraft updates,
since we can temporarily drop these patches and reapply them later.
Adding such patches is very simple:
1. Modify `paper-server/src/vanilla` with the appropriate changes;
1. Type `git add .` inside these directories to add your changes;
1. Run `git commit` with the desired patch message;
1. Run `./gradlew rebuildPatches` in the main directory to convert your commit into a new
patch;
1. PR the generated patch file(s) back to this repository.
Your commit will be converted into a patch that you can then PR into Paper.
> ❗ Please note that if you have some specific implementation detail you'd like
> to document, you should do so in the patch message *or* in comments.
### Modifying larger feature patches
Modifying existing feature patches is slightly more complex.
#### Method 1
This method works by temporarily resetting your `HEAD` to the desired commit to This method works by temporarily resetting your `HEAD` to the desired commit to
edit it using `git rebase`. edit it using `git rebase`.
> ❗ While in the middle of an edit, you will not be able to compile unless you 0. If you have changes you are working on, type `git stash` to store them for
> *also* reset the opposing module(s) to a related commit. In the API's case, later;
> you must reset the Server, and reset the API if you're editing the Server.
> Note also that either module _may_ not compile when doing so. This is not
> ideal nor intentional, but it happens. Feel free to fix this in a PR to us!
1. If you have changes you are working on, type `git stash` to store them for
later;
- You can type `git stash pop` to get them back at any point. - You can type `git stash pop` to get them back at any point.
1. Type `git rebase -i base`; 1. cd into `paper-server/src/minecraft/java` and run `git rebase -i base`;
- It should show something like - It should show something like
[this](https://gist.github.com/zachbr/21e92993cb99f62ffd7905d7b02f3159) in [this](https://gist.github.com/zachbr/21e92993cb99f62ffd7905d7b02f3159) in
the text editor you get. the text editor you get.
@ -128,47 +96,62 @@ later;
If you don't know how to use `vim` and don't want to If you don't know how to use `vim` and don't want to
learn, enter `:q!` and press enter. Before redoing this step, do learn, enter `:q!` and press enter. Before redoing this step, do
`export EDITOR=nano` for an easier editor to use. `export EDITOR=nano` for an easier editor to use.
1. Replace `pick` with `edit` for the commit/patch you want to modify, and 1. Replace `pick` with `edit` for the commit/patch you want to modify (in this
"save" the changes; case the very first commit, `paper File Patches`), and
- Only do this for **one** commit at a time. "save" the changes;
1. Make the changes you want to make to the patch; 1. Make the changes you want to make to the patch;
1. Type `git add .` to add your changes; 1. Run `git add .` to add your changes;
1. Type `git commit --amend` to commit; 1. Run `git commit --amend` to commit;
- **Make sure to add `--amend`** or else a new patch will be created. 1. Run `git rebase --continue` to finish rebasing;
- You can also modify the commit message and author here. 1. Run `./gradlew rebuildPatches` in the root directory;
1. Type `git rebase --continue` to finish rebasing;
1. Type `./gradlew rebuildPatches` in the root directory;
- This will modify the appropriate patches based on your commits.
1. PR your modified patch file(s) back to this repository.
#### Method 2 - Fixup commits ## Adding larger feature patches
If you are simply editing a more recent commit or your change is small, simply Feature patches are exclusively used for large-scale changes that are hard to
making the change at HEAD and then moving the commit after you have tested it track and maintain and that can be optionally dropped, such as the more involved
may be easier. optimizations we have. This makes it easier to update Paper during Minecraft updates,
since we can temporarily drop these patches and reapply them later.
This method has the benefit of being able to compile to test your change without There is only a very small chance that you will have to use this system, but adding
messing with your HEADs. such patches is very simple:
##### Manual method 1. Modify `paper-server/src/minecraft` with the appropriate changes;
1. Run `git add .` inside that directory to add your changes;
1. Run `git commit` with the desired patch message;
1. Run `./gradlew rebuildPatches` in the root directory.
1. Make your change while at HEAD; Your commit will be converted into a patch that you can then PR into Paper.
> ❗ Please note that if you have some specific implementation detail you'd like
> to document, you should do so in the patch message *or* in comments.
## Modifying larger feature patches
One way of modifying feature patches is to reset to the patch commit and follow
the instructions from the [rebase section](#resolving-rebase-conflicts). If you
are sure there won't be any conflicts from later patches, you can also use the
fixup method.
### Fixup method
#### Manual method
1. Make your changes;
1. Make a temporary commit. You don't need to make a message for this; 1. Make a temporary commit. You don't need to make a message for this;
1. Type `git rebase -i base`, move (cut) your temporary commit and 1. Type `git rebase -i base`, move (cut) your temporary commit and
move it under the line of the patch you wish to modify; move it under the line of the patch you wish to modify;
1. Change the `pick` to the appropriate action: 1. Change the `pick` to the appropriate action:
1. `f`/`fixup`: Merge your changes into the patch without touching the 1. `f`/`fixup`: Merge your changes into the patch without touching the
message. message.
1. `s`/`squash`: Merge your changes into the patch and use your commit message 1. `s`/`squash`: Merge your changes into the patch and use your commit message
and subject. and subject.
1. Type `./gradlew rebuildPatches` in the root directory; 1. Run `./gradlew rebuildPatches` in the root directory;
- This will modify the appropriate patches based on your commits. - This will modify the appropriate patches based on your commits.
1. PR your modified patch file(s) back to this repository.
##### Automatic method #### Automatic method
1. Make your change while at HEAD; 1. Make your changes;
1. Make a fixup commit. `git commit -a --fixup <hashOfPatchToFix>`; 1. Make a fixup commit: `git commit -a --fixup <hash of patch to fix>`;
- If you want to modify a per-file patch, use `git commit -a --fixup file` - If you want to modify a per-file patch, use `git commit -a --fixup file`
- You can also use `--squash` instead of `--fixup` if you want the commit - You can also use `--squash` instead of `--fixup` if you want the commit
message to also be changed. message to also be changed.
@ -176,20 +159,19 @@ move it under the line of the patch you wish to modify;
assist you too. assist you too.
- Alternatively, if you only know the name of the patch, you can do - Alternatively, if you only know the name of the patch, you can do
`git commit -a --fixup "Subject of Patch name"`. `git commit -a --fixup "Subject of Patch name"`.
1. Rebase with autosquash: `git rebase -i --autosquash mache/main`. 1. Rebase with autosquash: `git rebase -i --autosquash base`.
This will automatically move your fixup commit to the right place, and you just This will automatically move your fixup commit to the right place, and you just
need to "save" the changes. need to "save" the changes.
1. Type `./gradlew rebuildPatches` in the root directory; 1. Run `./gradlew rebuildPatches` in the root directory. This will modify the
- This will modify the appropriate patches based on your commits. appropriate patches based on your commits.
1. PR your modified patch file(s) back to this repository.
## Rebasing PRs ## Rebasing PRs
Steps to rebase a PR to include the latest changes from `main`. Steps to rebase a PR to include the latest changes from `main`.
These steps assume the `origin` remote is your fork of this repository and `upstream` is the official PaperMC repository. These steps assume the `origin` remote is your fork of this repository and `upstream` is the official PaperMC repository.
1. Pull the latest changes from upstreams main: `git switch main && git pull upstream main`. 1. Fetch the latest changes from upstream's main: `git fetch upstream`.
1. Checkout feature/fix branch and rebase on main: `git checkout patch-branch && git rebase main`. 1. Checkout your feature/fix branch and rebase on main: `git switch patch-branch && git rebase upstream/main`.
1. Apply updated patches: `./gradlew applyPatches`. 1. Apply updated patches: `./gradlew applyPatches`.
1. If there are conflicts, fix them. 1. If there are conflicts, fix them.
1. If your PR creates new feature patches instead of modifying existing ones, ensure your newly-created patch is the last commit by either: 1. If your PR creates new feature patches instead of modifying existing ones, ensure your newly-created patch is the last commit by either:
@ -197,7 +179,7 @@ These steps assume the `origin` remote is your fork of this repository and `upst
* Running `git rebase --interactive base` and moving the commits to the end. * Running `git rebase --interactive base` and moving the commits to the end.
1. Rebuild patches: `./gradlew rebuildPatches`. 1. Rebuild patches: `./gradlew rebuildPatches`.
1. Commit modified patches. 1. Commit modified patches.
1. Force push changes: `git push --force`. 1. Force push changes: `git push --force`. Make sure you're not deleting any of your commits or changes here!
## PR Policy ## PR Policy
@ -212,7 +194,9 @@ when making and submitting changes.
## Formatting ## Formatting
All modifications to Vanilla files should be marked. All modifications to Vanilla files should be marked. For historical reasons,
API and API-implementation contain a lot of these too, but they are no longer
required.
- You need to add a comment with a short and identifiable description of the patch: - You need to add a comment with a short and identifiable description of the patch:
`// Paper start - <COMMIT DESCRIPTION>` `// Paper start - <COMMIT DESCRIPTION>`
@ -224,16 +208,19 @@ All modifications to Vanilla files should be marked.
with `// Paper end - <COMMIT DESCRIPTION>`. with `// Paper end - <COMMIT DESCRIPTION>`.
- One-line changes should have `// Paper - <COMMIT DESCRIPTION>` at the end of the line. - One-line changes should have `// Paper - <COMMIT DESCRIPTION>` at the end of the line.
> [!NOTE] These comments are incredibly important to be able to keep track of changes
> across files and to remember what they are for, even a decade into the future.
Here's an example of how to mark changes by Paper: Here's an example of how to mark changes by Paper:
```java ```java
entity.getWorld().dontBeStupid(); // Paper - Was beStupid(), which is bad entity.getWorld().dontBeStupid(); // Paper - Move away from beStupid()
entity.getFriends().forEach(Entity::explode); entity.getFriends().forEach(Entity::explode);
entity.updateFriends(); entity.updateFriends();
// Paper start - Use plugin-set spawn // Paper start - Use plugin-set spawn
// entity.getWorld().explode(entity.getWorld().getSpawn()); // entity.getWorld().explode(entity.getWorld().getSpawn());
Location spawnLocation = ((CraftWorld)entity.getWorld()).getSpawnLocation(); Location spawnLocation = ((CraftWorld) entity.getWorld()).getSpawnLocation();
entity.getWorld().explode(new BlockPosition(spawnLocation.getX(), spawnLocation.getY(), spawnLocation.getZ())); entity.getWorld().explode(new BlockPosition(spawnLocation.getX(), spawnLocation.getY(), spawnLocation.getZ()));
// Paper end - Use plugin-set spawn // Paper end - Use plugin-set spawn
``` ```
@ -244,17 +231,18 @@ into most IDEs and formatters by default. There are a few notes, however:
There are exceptions, especially in Spigot-related files There are exceptions, especially in Spigot-related files
- When in doubt or the code around your change is in a clearly different style, - When in doubt or the code around your change is in a clearly different style,
use the same style as the surrounding code. use the same style as the surrounding code.
- Usage of the `var` keyword is heavily discouraged, as it makes reading patch files - Usage of the `var` keyword is discouraged, as it makes reading patch files a
a lot harder and can lead to confusion during updates due to changed return types. lot harder and can lead to confusion during updates due to changed return types.
The only exception to this is if a line would otherwise be way too long/filled with The only exception to this is if a line would otherwise be way too long/filled with
hard to parse generics in a case where the base type itself is already obvious hard to parse generics in a case where the base type itself is already obvious.
### Imports ### Imports
When adding new imports to a Vanilla class (or if you're editing feature patches), use the fully qualified class name When adding new imports to a Vanilla class, use the fully qualified class name
instead of adding a new import to the top of the file. If you are using a type a significant number of times, you instead of adding a new import to the top of the file. If you are using a type a significant number of times, you
can add an import with a comment. However, if its only used a couple of times, the FQN is preferred to prevent future can add an import with a comment. However, if it's only used a couple of times, the FQN is preferred to prevent future
patch conflicts in the import section of the file. patch conflicts in the import section of the file.
```java ```java
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
// don't add import here, use FQN like below // don't add import here, use FQN like below
@ -272,7 +260,7 @@ We are in the process of switching nullability annotation libraries, so you migh
`@Nullable` annotation from `org.jspecify.annotations`. Whenever you create a new class, add `@NullMarked`, meaning types `@Nullable` annotation from `org.jspecify.annotations`. Whenever you create a new class, add `@NullMarked`, meaning types
are assumed to be non-null by default. For less obvious placing such as on generics or arrays, see the [JSpecify docs](https://jspecify.dev/docs/user-guide/). are assumed to be non-null by default. For less obvious placing such as on generics or arrays, see the [JSpecify docs](https://jspecify.dev/docs/user-guide/).
**For classes added by upstream**: Keep using both `@Nullable` and `@NotNull` from `org.jetbrains.annotations`. These **For other classes**: Keep using both `@Nullable` and `@NotNull` from `org.jetbrains.annotations`. These
will be replaced later. will be replaced later.
## Access Transformers ## Access Transformers
@ -282,30 +270,7 @@ to change the visibility or remove the final modifier from fields, methods, and
file, you can add ATs that are applied when you `./gradlew applyPatches`. You can read about the format of ATs file, you can add ATs that are applied when you `./gradlew applyPatches`. You can read about the format of ATs
[here](https://mcforge.readthedocs.io/en/latest/advanced/accesstransformers/#access-modifiers). [here](https://mcforge.readthedocs.io/en/latest/advanced/accesstransformers/#access-modifiers).
### Important <!--
ATs should be included in the patch file which requires them within the commit message. Do not commit any changes to the
`build-data/paper.at` file, just use it to initially change the visibility of members until you have finalized what you
need. Then, in the commit message for the patch which requires the ATs, add a header at the bottom of the commit message
before any co-authors. It should look like the following after you `./gradlew rebuildPatches`.
```
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jake Potrebic <jake.m.potrebic@gmail.com>
Date: Wed, 8 Jun 2022 22:20:16 -0700
Subject: [PATCH] Paper config files
This patch adds Paper configuration files.
Access transformers for this patch are below, but before the co-authors.
== AT ==
public org.spigotmc.SpigotWorldConfig getBoolean(Ljava/lang/String;Z)Z
public net.minecraft.world.level.NaturalSpawner SPAWNING_CATEGORIES
Co-authored-by: Jason Penilla <11360596+jpenilla@users.noreply.github.com>
diff --git a/build.gradle.kts b/build.gradle.kts
...
```
## Patch Notes ## Patch Notes
When submitting feature patches to Paper, we may ask you to add notes to the patch When submitting feature patches to Paper, we may ask you to add notes to the patch
@ -356,6 +321,7 @@ index a92bf8967..d0ab87d0f 100644
--- a/src/main/java/net/minecraft/server/PlayerConnection.java --- a/src/main/java/net/minecraft/server/PlayerConnection.java
+++ b/src/main/java/net/minecraft/server/PlayerConnection.java +++ b/src/main/java/net/minecraft/server/PlayerConnection.java
``` ```
-->
## Obfuscation Helpers ## Obfuscation Helpers
@ -423,12 +389,6 @@ of the `net.minecraft.world.level.Level` which you can then access the config by
int maxPlayers = level.paperConfig().misc.maxNumOfPlayers; int maxPlayers = level.paperConfig().misc.maxNumOfPlayers;
``` ```
#### Committing changes
All changes to the `GlobalConfiguration` and `WorldConfiguration` files
should be done in the commit that created them. So do an interactive rebase
or fixup to apply just those changes to that commit, then add a new commit
that includes the logic that uses that option in the server somewhere.
## Testing API changes ## Testing API changes
### Using the Paper Test Plugin ### Using the Paper Test Plugin
@ -461,7 +421,7 @@ If you use Maven to build your plugin:
### My commit doesn't need a build, what do I do? ### My commit doesn't need a build, what do I do?
Well, quite simple: You add `[ci skip]` to the start of your commit subject. Quite simple: You add `[ci skip]` to the start of your commit subject.
This case most often applies to changes to files like `README.md`, this very This case most often applies to changes to files like `README.md`, this very
file (`CONTRIBUTING.md`), the `LICENSE.md` file, and so forth. file (`CONTRIBUTING.md`), the `LICENSE.md` file, and so forth.
@ -471,8 +431,8 @@ file (`CONTRIBUTING.md`), the `LICENSE.md` file, and so forth.
This only applies if you're running Windows. If you're running a prior Windows This only applies if you're running Windows. If you're running a prior Windows
release, either update to Windows 10/11 or move to macOS/Linux/BSD. release, either update to Windows 10/11 or move to macOS/Linux/BSD.
In order to speed up patching process on Windows, it's recommended you get WSL In order to speed up patching process on Windows, it's recommended you get WSL 2.
2. This is available in Windows 10 v2004, build 19041 or higher. (You can check This is available in Windows 10 v2004, build 19041 or higher. (You can check
your version by running `winver` in the run window (Windows key + R)). If you're your version by running `winver` in the run window (Windows key + R)). If you're
using an out of date version of Windows 10, update your system with the using an out of date version of Windows 10, update your system with the
[Windows 10 Update Assistant](https://www.microsoft.com/en-us/software-download/windows10) or [Windows 11 Update Assistant](https://www.microsoft.com/en-us/software-download/windows11). [Windows 10 Update Assistant](https://www.microsoft.com/en-us/software-download/windows10) or [Windows 11 Update Assistant](https://www.microsoft.com/en-us/software-download/windows11).