| name | patch-workflow |
| description | Guide for creating, modifying, and rebuilding patches in DeerFoliaPlus. Use when working with patch files, editing upstream code, running git rebase workflows, rebuilding patches with Gradle, or troubleshooting patch conflicts. Triggers on patch creation, patch editing, rebuildAllServerPatches, applyAllPatches, git rebase, fixup, squash, or any patch-related git workflow. |
Patch Workflow
Procedural guide for all patch operations in DeerFoliaPlus. Patches are git-format-patch diffs maintained as .patch files, applied and rebuilt via Paperweight.
Patch Directory Map
| Directory | Target codebase | When to use |
|---|
DeerFoliaPlus-server/minecraft-patches/features/ | Vanilla NMS (net.minecraft.*) | Modifying Minecraft server internals |
DeerFoliaPlus-server/paper-patches/features/ | CraftBukkit / Paper server | Modifying Paper/CraftBukkit server code |
DeerFoliaPlus-server/DeerFolia-patches/features/ | DeerFolia server | Modifying DeerFolia-specific server code |
DeerFoliaPlus-api/paper-patches/features/ | Paper API (Bukkit/Server) | Modifying Bukkit/Paper API interfaces |
DeerFoliaPlus-api/folia-patches/features/ | Folia API | Modifying Folia API interfaces |
Patch files are numbered sequentially: 0001-Title.patch, 0002-Title.patch, etc.
Patch File Format
Standard git-format-patch with unified diff:
From <hash> Mon Sep 17 00:00:00 2001
From: Author <email>
Date: <date>
Subject: [PATCH] <Title>
diff --git a/path/to/File.java b/path/to/File.java
index abc1234..def5678 100644
--- a/path/to/File.java
+++ b/path/to/File.java
@@ -line,count +line,count @@ context
unchanged line
-removed line
+added line
unchanged line
Modification Markers (CRITICAL)
All modifications to upstream code MUST use comment markers:
<modified code>
someCode();
public int field;
For code ported from Leaves, use // Leaves start/end - <description> markers.
Import Rule
In patch hunks, use fully qualified class names instead of import statements to minimize merge conflicts:
import cn.lunadeer.mc.deerfoliaplus.configurations.DeerFoliaPlusConfiguration;
if (cn.lunadeer.mc.deerfoliaplus.configurations.DeerFoliaPlusConfiguration.fakePlayer.enable) { ... }
Creating a New Patch (Upstream Modification)
- Ensure patches are applied:
./gradlew applyAllPatches
- Edit files in
DeerFoliaPlus-server/ or DeerFoliaPlus-api/ (the module working directories — NOT patch files directly)
- Stage and commit in the module directory:
cd DeerFoliaPlus-server
git add .
git commit -m "Descriptive patch title"
- Return to project root and rebuild:
cd ..
./gradlew rebuildAllServerPatches
- New
.patch file appears in the appropriate patches directory. Commit it to the main repo.
Modifying an Existing Patch
Method A: Rebase Edit (for any patch)
- Enter the module directory:
cd DeerFoliaPlus-server
- Start interactive rebase:
git rebase -i base
- Change
pick to edit for the target patch commit. Save and exit.
- Make changes to the source files.
- Stage and amend (do NOT create a new commit):
git add .
git commit --amend
- Continue rebase:
git rebase --continue
- Rebuild patches from project root:
cd ..
./gradlew rebuildAllServerPatches
Warning: During rebase, the project may not compile. This is expected.
Method B: Fixup (for recent patches or small changes)
- Make changes in the module directory and commit:
cd DeerFoliaPlus-server
git add .
git commit --fixup <target-patch-hash>
- Use
git log to find the target patch hash
- Use
git log --grep=<patch-name> to search by title
- Use
--squash instead of --fixup to also update the commit message
- Auto-squash rebase:
git rebase -i --autosquash base
Save and exit — the fixup commit is auto-positioned.
- Rebuild from root:
cd ..
./gradlew rebuildAllServerPatches
Method C: Manual Reorder (when fixup positioning needs control)
- Make changes, commit with any message.
- Interactive rebase:
git rebase -i base
- Move the new commit below the target patch.
- Change the new commit's action:
f / fixup — merge without changing message
s / squash — merge and update message
- Save, exit, then rebuild patches.
Rebuild Commands
./gradlew rebuildAllServerPatches
./gradlew applyAllPatches
Troubleshooting
Patch fails to apply
If applyAllPatches fails with conflicts:
- Check the error output for the failing patch file path.
- Manually apply:
git apply --reject <patch-file>
- Inspect generated
.rej files for conflict details.
- Resolve conflicts in the source files.
- Delete
.rej files.
- Stage resolved files:
git add .
- Continue:
git am --resolved
- Repeat if more patches conflict.
Rebase conflicts
If git rebase --continue fails:
- Resolve conflicts in the indicated files.
git add .
git rebase --continue
- If unrecoverable:
git rebase --abort starts over.