- Java 99.5%
- Scheme 0.5%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
Gear caught after a finished scrap pass went into the chest unscrapped once free slots fell below minFreeSlots, because the pass only re-armed above scrapAtFreeSlots. The pass now always runs before an unload when any candidate is in the inventory (items it gave up on are still deposited, without looping). Also adds /afkfish off scrap (alias salvage): reel in, scrap everything scrappable, then stop. manifest.scm: document guix shell --pure, since an inherited JAVA_HOME beats the JDK 25 on PATH. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> |
||
| gradle/wrapper | ||
| src | ||
| .gitattributes | ||
| .gitignore | ||
| build.gradle | ||
| gradle.properties | ||
| gradlew | ||
| gradlew.bat | ||
| LICENSE | ||
| manifest-gametest.scm | ||
| manifest.scm | ||
| README.md | ||
| settings.gradle | ||
afkfish
Client-side Fabric mod for unattended fishing on a Paper + mcMMO server without tripping mcMMO's fishing anti-exploit checks.
- Minecraft 26.3 (Mojang's year-based numbering, so "1.26.3" is 26.3), Fabric Loader 0.19.5,
Fabric API 0.161.0+26.3, Java 25. Built from the official
fabric-example-modtemplate (Loom 1.18, unobfuscated Mojang names). - Client only. It depends on Fabric API and nothing else.
Build
Requires a JDK 25 (e.g. Temurin or your distro's openjdk-25
package). Gradle itself is fetched by the wrapper, and Minecraft, Fabric and other dependencies
are downloaded on the first build, so you need network access.
java -version # must report 25; if not, point JAVA_HOME at a JDK 25
./gradlew build # Windows: gradlew.bat build
# → build/libs/afkfish-<version>.jar
Loom refuses to run under any other Java version, so if java on your PATH is older, set
JAVA_HOME (e.g. JAVA_HOME=/usr/lib/jvm/java-25-openjdk ./gradlew build).
To install, put the jar (not the -sources one) in your instance's mods/ folder along with
Fabric API for 26.3, and launch with Fabric Loader 0.19.5
or newer.
Unit tests (pure logic, JUnit 5) run as part of build, or with ./gradlew test.
Guix
manifest.scm provides the build environment:
guix shell --pure -m manifest.scm -- ./gradlew build
--pure matters here. Without it, a JAVA_HOME from the home profile (e.g. JDK 21) leaks
into the shell and Loom refuses to run.
In-game smoke test (optional)
src/gametest is a Fabric client gametest. It builds a pond in a flat singleplayer world,
with a stone pillar in it, then finds spots with /afkfish spot auto and toggles the mod through
the real client commands. It fishes until the worn rod is swapped, then checks eating, GUI
pause/resume, damage pause, toggle-off-mid-eat and the CSV log. It fills the inventory and checks
unloading into a chest, then junk dropping once the chest is full. Finally it runs the spot
search and fishes again from a boat. Vanilla fishing only, no mcMMO.
It launches a real client, so it needs a display (or Xvfb) and working OpenGL:
./gradlew runClientGameTest
# headless Linux:
xvfb-run -a -s "-screen 0 1280x720x24" ./gradlew runClientGameTest
On Guix, manifest-gametest.scm adds Xvfb, Mesa and the native libraries the client loads:
guix shell --pure -m manifest-gametest.scm -- sh -c \
'LD_LIBRARY_PATH=$GUIX_ENVIRONMENT/lib xvfb-run -a -s "-screen 0 1280x720x24" ./gradlew runClientGameTest'
Setting up a pond
The mod needs two spots whose landings are at least minSpotSeparation (4.5) blocks apart.
That keeps each catch outside the other spot's mcMMO over-fishing box (see
below). Any water large enough for two such spots will
work. Building it as vanilla "open water" also unlocks treasure catches (enchanted books, bows,
name tags…). Without open water you only get fish and junk.
A landing counts as open water when the 5×5 column around the bobber, from one block below it to two blocks above the surface, is made of complete layers:
- Water layers: at least the surface and the layer under it, so 2+ deep. Every block must be still (source) water. Flowing water and waterlogged blocks (slabs, stairs, fences) do not count.
- Air layers: the two layers above the surface must be air or lily pads, so no roof, bridge, slab or overhang within 2 blocks above the water.
- Every layer must be uniform, so there can be no solid block within 2 blocks sideways of the landing, and no water floating above air.
Landings scatter by about a block, so give each spot a margin beyond its 5×5 column. For
reference, the in-game test uses a 29×24 pond, 3 deep and open to the sky, with the player
standing on the shore 3 blocks back from the edge. It works with a 2×2 stone pillar sticking out
of the water. Smaller ponds are fine if both spots still fit, but run /afkfish spot auto. It
reports whether both spots are open water.
Other things to sort out around the pond:
- Where you stand: on the shore facing the middle of the water, or in a boat. In a boat, both spots must fall within ±105° of the boat's heading.
- Chest: optional, within 4.5 blocks reach of where you stand (see Inventory space).
- Repair and salvage blocks: optional, an iron block (mcMMO repair) and a gold block
(mcMMO salvage) you can face from where you stand, then set with
/afkfish repairand/afkfish salvage. In a boat they must be inside the ±105° clamp. Put the gold block close so its drops reach you (see Scrapping). - Safety: with the default
onDamage = DISCONNECT, any hit that takes you below 10 health disconnects you. Light the area and fence it off so mobs can't reach you, and make sure nothing pushes you more thanmaxDriftBlocks(2) from where you started.
Usage
- Hold a fishing rod. Spare rods and food go in the hotbar.
- Face the middle of the water and run
/afkfish spot auto(see Spot search). Or set them by hand: look at the first casting direction and run/afkfish spot a, then the second and run/afkfish spot b. The two hook landing points must be at leastminSpotSeparation(4.5) blocks apart in X or Z. Landings scatter by a block or so per cast. In testing, standing casts needed about ±35° from center (70° apart). Casts from a boat land closer, so they needed about ±60° (120° apart, which is still inside the ±105° boat clamp). If the spots are too close, the mod pauses after the first catch at each spot. - Optional: look at a chest within reach and run
/afkfish chest(see Inventory space). /afkfish on, or the toggle key (unbound by default; Controls → afkfish).
| Command | |
|---|---|
/afkfish on |
start, or resume from a pause |
/afkfish off |
stop; releases all input immediately |
/afkfish off scrap |
reel in, scrap everything scrappable, then stop (off salvage is the same) |
/afkfish status |
state, spot, uptime, casts/catches/rate, bite wait, recoveries, mcMMO messages |
/afkfish spot a|b |
store the current yaw/pitch |
/afkfish spot auto |
find and set both spots with test casts |
/afkfish chest |
unload into the chest, barrel, ender chest or shulker box you are looking at |
/afkfish chest clear |
forget the chest |
/afkfish repair |
use the block you are looking at as the mcMMO repair anvil (iron block) |
/afkfish salvage |
use the block you are looking at as the mcMMO salvage anvil (gold block) |
/afkfish scrap clear |
forget both blocks |
/afkfish reload |
re-read config/afkfish.json |
Spots and the chest are saved per server in config/afkfish-sessions.json and come back when you
join that server again. Singleplayer worlds are saved per save folder. If fishing was on when the
connection ended, the mod reminds you on rejoin to run /afkfish on.
Spot search
/afkfish spot auto sweeps test casts across the water you face: yaw ±autoSpotYawRange
(75°) in autoSpotYawStep (15°) steps, at each pitch in autoSpotPitches (10° and 25°).
That is 22 casts, about a minute. In a boat, angles outside the ±105° clamp are skipped.
Each hook is left to settle in water for 0.8 s, its position is recorded, and it is reeled in.
A cast that has not settled in water after castHookTimeoutMs is discarded.
Each landing is scored on the blocks around it, using the same rules as vanilla's open-water (treasure) check:
- open water even if the landing shifts by one block
- open water
- water only
Ties are broken by how far the water extends before the shore (up to 4 blocks). The search then
picks the pair at least minSpotSeparation + autoSpotMargin (5.5) blocks apart whose worse
landing scores best. It prefers the smaller turn between them, and sets A and B. The result
says whether both spots are open water. If no pair is far enough apart, the spots are left as
they were.
- Test casts are not catches, so mcMMO's over-fishing and too-often checks never see them. If a fish bites during one, it is reeled in like a normal catch, keeping the reel floor.
- Reeling in an empty hook from water costs no durability. A cast that lands on the shore
costs 2. The search swaps rods at
rodMinDurabilitylike fishing does. - Opening a screen, damage, drifting, leaving the boat or
/afkfish offaborts the search. The spots stay unchanged and it does not resume. - The search judges the water at the moment it runs. Run it again after changing the surroundings.
Inventory space
A catch that does not fit drops at your feet, and it despawns (or drifts off, from a boat).
So before every cast the mod makes sure at least minFreeSlots (2) slots are empty. One is for
the next catch. The other covers a catch still flying in when the check runs. When fewer are
free, it tries these in order:
- Unload into the chest, if one is set and not known to be full. It turns to the chest,
right-clicks it, shift-clicks every stack in 100–250 ms steps, closes it and turns back.
Everything goes in except fishing rods and
foodItemsin the hotbar. Raw cod and salmon are loot, not food. When a stack does not fit, the chest counts as full until the next/afkfish on. - Drop junk (
autoDropWhenFull): oneautoDropItemsstack at a time, until enough slots are free. Enchanted items, enchanted books and anything rarer than common are never dropped, even if listed. - Pause with an alert. Nothing worth keeping is ever thrown away to make room.
Scrapping (mcMMO repair + salvage)
With both blocks set (/afkfish repair, /afkfish salvage, from where you fish; in a boat they
must be inside the ±105° clamp, and the gold block close enough that drops reach you), a pass runs
before the chest step whenever fewer than scrapAtFreeSlots (6) slots are free. For each tool or
armor piece of a scrapMaterials material, plus bows (scrapExtraItems, repaired with string).
Never netherite, never rods:
- Swap it into a hotbar slot (an empty one, else one without a rod or food) and select it.
- Turn to the repair block and right-click until the target durability is reached. Plain items
are repaired fully. Enchanted items are repaired only to the salvage minimum (max ÷ the item's
crafting material count, e.g. a third for pickaxes and axes, all of it for shovels) plus
scrapEnchantedMarginPct, so Arcane Salvage can still give a book. mcMMO sends no message for a repair, so progress is read from the item's damage. Three clicks without progress (no materials, or the confirm click) mean it salvages as is. - Turn to the salvage block and right-click (the first click only asks for confirmation). "Too damaged" sends it back for a few more repair clicks, then it gives up on that item for the pass.
- Wait until the dropped materials are picked up, or pause if they are not.
The pass ends when no candidates are left, and re-arms once free slots are back above the threshold.
Independently of that threshold, the pass always runs before a chest unload when any candidate is in the
inventory, so gear caught after a finished pass never goes into the chest unscrapped. Only items the pass
gave up on (skipped) are deposited as they are.
Chest unloading and junk dropping always keep the fullest stack of each repairMaterials item.
Salvage drops flow back into those same ingots. The mcMMO messages are matched by salvagedRegex,
tooDamagedRegex and fullDurabilityRegex.
/afkfish off scrap runs the same pass once before stopping, whatever the free slots: it reels in the
line (a bite already being reeled is finished), scraps every candidate left in the inventory, selects the rod
and stops. It needs both blocks set and refuses otherwise, without stopping. /afkfish off or the
toggle key abandons it and stops at once. A pause during the wind-down (blocked block, drops not
picked up) ends it like any pause, and /afkfish on then resumes normal fishing. Run
/afkfish off scrap while paused to retry the wind-down. Items it gives up on are skipped, not retried.
If the chest is not under the crosshair at click time (blocked, or out of the 4.5-block reach) or does not open within 2 s (locked, or claimed by a protection plugin), the mod pauses. It does not fall back to dropping. Set the chest from where you fish. In a boat it must be inside the ±105° yaw clamp. Its screen does not trigger the GUI pause. Pausing or stopping mid-unload closes it.
How it stays inside mcMMO's rules
These are mcMMO's checks, from FishingManager / PlayerListener.onPlayerFishLowest:
- Over-fishing. Each catch's hook position gets a box ±
moveRange/2in X/Z and ±1 in Y. If the box overlaps the anchor box, a counter increments; otherwise the counter resets and the anchor moves. When the counter reachesoverFishLimit, the catch is voided (Fishing.ScarcityTip). One catch earlier, mcMMO sendsFishing.LowResourcesTip. - Too often. A catch less than 1000 ms after the previous one is voided
(
Fishing.Scared), and the timer still resets.
The mod handles them like this:
- It alternates between spots A and B every
catchesPerSpotcatches. That value is capped at min(8,overFishLimit− 2), so the counter never reaches the tip. - After the first catch at each spot, it checks the A/B landing separation and pauses if it
is below
minSpotSeparation. - It runs a client-side replica of the over-fish tracker on every catch. It pauses when the
predicted counter reaches
overFishLimit− 1, which covers drift and servers with changed or translated messages. - Reels are at least
minReelIntervalMsapart (default 1100, never below 1000). EachFishing.Scaredmessage adds 500 ms to that floor for the session. - A
Fishing.ScarcityTiporFishing.LowResourcesTipmessage pauses the mod. - Fishing from a minecart is refused, and riding one pauses the mod, because mcMMO ejects you on cast. Boats are fine. Both spots must lie within the client's ±105° passenger yaw clamp of the boat's heading.
Behaviour
- Bite detection: the synced
FishingHook.bitingflag (the client copy ofDATA_BITING, read through an accessor mixin). The fallback is theentity.fishing_bobber.splashsound within 2 blocks of the player's own hook, captured by aClientPacketListenermixin because Fabric API has no sound event. - Cycle: bite → wait 150–450 ms → reel → wait 600–1500 ms → rod/food checks → smooth turn to the next spot over 200–400 ms with ±1.5° jitter → cast. If the fish lets go before the reel, the line stays out.
- Recovery:
- no hook 3 s after casting → recast
- hook out of water for 3 s → reel and recast
- no bite in 60 s → reel and recast
- hook caught on an entity → reel and recast
- 5 recoveries in a row → pause
- Rod: swaps to another hotbar rod when the held rod's remaining durability is at or below
rodMinDurability. If there is no spare, it pauses. A rod is never used below the reserve. - Food: at food ≤
eatAtFood, it eats the firstfoodItemsentry found in the hotbar, holding use until the food bar rises, then reselects the rod. With no food, it pauses. - Inventory space: scrap gear, unload into the chest, drop junk, or pause. See Inventory space.
- Pauses: pausing plays a chat notice and a sound. The triggers are:
- a non-chat GUI is open (resumes automatically when it closes)
- riding a minecart, or leaving the boat the run started in
- more than 2 blocks from the start position
- spots too close together, predicted over-fishing, or an mcMMO scarcity message
- recovery, rod or food problems
- no inventory space left to free, or a chest that cannot be reached or opened
- damage, when
onDamage = PAUSE
- Stops: death, dimension change, disconnect, or
onDamage = DISCONNECT(the default), which disconnects when damage takes health belowdamageHealthThreshold. - Log: one row per catch in
logs/afkfish/YYYY-MM-DD.csv:timestamp,spot,hook_x,hook_y,hook_z,wait_ms,item. The item is read from the item entity that spawns at the hook. It isunknownif none is seen within 1 s, for example when mcMMO deletes a voided catch.
Config (config/afkfish.json)
Defaults are written on first run. Out-of-range values are clamped on load, and the clamps
are reported by /afkfish reload.
| Key | Default | |
|---|---|---|
moveRange, overFishLimit |
3, 10 | mirror mcMMO experience.yml → Fishing_ExploitFix_Options |
minSpotSeparation |
4.5 | min max(|dx|,|dz|) between A and B landings |
catchesPerSpot |
1 | 1..min(8, overFishLimit−2) |
autoSpotYawRange, autoSpotYawStep |
75, 15 | spot search sweep, degrees either side of where you face |
autoSpotPitches |
[10, 25] | one sweep per pitch; lower casts farther |
autoSpotMargin |
1.0 | added to minSpotSeparation for the search, for landing scatter |
minReelIntervalMs |
1100 | ≥ 1000 |
reelDelayMinMs/MaxMs |
150/450 | bite → reel |
postReelMinMs/MaxMs |
600/1500 | reel → turn |
rotateMinMs/MaxMs, rotateJitterDeg |
200/400, 1.5 | |
splashRadius |
2.0 | sound fallback radius |
castHookTimeoutMs, hookNotInWaterMs, biteTimeoutMs |
3000, 3000, 60000 | recovery triggers |
maxConsecutiveRecoveries |
5 | |
rodMinDurability |
10 | |
eatAtFood, eatTimeoutMs, foodItems |
14, 4000, cooked fish, bread, … | priority order, hotbar only; kept out of the chest |
minFreeSlots |
2 | 1..27; empty slots kept before each cast |
inventoryClickMinMs/MaxMs |
100/250 | between shift-clicks and junk drops |
autoDropWhenFull, autoDropItems |
true, vanilla fishing junk | drop junk when the chest is unset or full |
scrapEnabled, scrapAtFreeSlots |
true, 6 | the pass needs both blocks set; runs below this many free slots |
scrapMaterials |
wooden, stone, golden, copper, iron, diamond, chainmail, leather | item prefixes to scrap; netherite is not listed |
scrapExtraItems |
minecraft:bow |
scrapped by exact ID; only bows are supported |
repairMaterials |
planks, cobble, copper, iron, gold, diamond, leather, string | fullest stack kept out of the chest and bin |
scrapEnchantedMarginPct |
3 | enchanted items repair to the salvage minimum + this % of max durability |
scrapResponseMs, scrapPickupTimeoutMs, scrapMaxRepairClicks |
350, 4000, 24 | wait after each click; wait for drops; repair clicks per item |
salvagedRegex, tooDamagedRegex, fullDurabilityRegex |
mcMMO en_US strings | |
maxDriftBlocks |
2.0 | |
onDamage, damageHealthThreshold |
DISCONNECT, 10 |
IGNORE | PAUSE | DISCONNECT |
scarcityRegex, lowResourcesRegex, scaredRegex |
mcMMO en_US strings | matched against plain text, formatting stripped |
scaredPenaltyMs |
500 | |
hud, alertSound, csvLog |
false, true, true |
Layout
afkfish.core: pure Java and unit tested. It holds the state machine (FishingController), the mcMMO replica (Mcmmo), spots/alternation, timing, chat matching, spot search scoring (SpotSearch), config, the saved sessions (SessionStore) and the CSV log. Everything touches the game only through theGameinterface. A test enforces that there are no Minecraft or Fabric imports.afkfish: the Minecraft glue.MinecraftGameimplementsGame.AfkFishClientholds the Fabric events, commands, key mapping and HUD.afkfish.mixin:FishingHookAccessorfor the bite flag, andClientPacketListenerMixinfor server sounds.
States: IDLE, CASTING, WAITING, REELING, ROTATING, EATING, SWAPPING_ROD, RECOVERING, UNLOADING,
DROPPING, SCRAPPING, PAUSED, SEARCHING (spot search).
Everything runs from ClientTickEvents.END_CLIENT_TICK, with no extra threads or sleeps.
The only inputs are rotation, use item (the same MultiPlayerGameMode.useItem path as a
right-click), right-clicking the chest (useItemOn), shift-clicks in its screen, closing it,
holding the use key while eating, hotbar selection and Ctrl+Q-style drops.