Develop a mod that enables regular villagers to climb ladders, enhancing their mobility and interaction with the environment. Include configurable settings to control climbing behavior and compatibility with existing AI routines, ensuring villagers can navigate vertical spaces effectively without disrupting their pathfinding.
Plan:
gradle.properties,build.gradle— project build setupfabric.mod.json,villagerladderclimb.mixins.json— mod metadata & mixin registrationVillagerLadderClimb.java— main initializer, loads configClimbConfig.java+ConfigManager.java— JSON config (enabled, climbSpeed)LivingEntityMixin.java— injects intotickMovement(), applies upward velocity when a villager is on a climbable block
Here’s what the mod does and how each piece connects:
How it works
LivingEntityMixin hooks into LivingEntity.tickMovement() every tick. When the entity is a VillagerEntity and is standing inside a block tagged minecraft:climbable (ladders, vines, scaffolding, etc.), it overrides the Y velocity to climbSpeed. Vanilla’s own isClimbing() returns true for any living entity on a climbable block, which suppresses free-fall physics in travel() — so the manually-applied upward velocity carries through without being immediately cancelled by gravity.
Config file (config/villagerladderclimb.json)
Generated automatically on first launch:
Key | Default | Description |
|---|---|---|
enabled | true | Master toggle |
climbSpeed | 0.15 | Upward velocity per tick (0.05 = slow crawl, 0.4 = fast) |
requireHorizontalCollision | false | true = only climb when pushed against the block (more realistic); false = climb whenever inside any climbable block |
can you fix pathfinding so they can try to go to a bed if there is a way to it trough a ladder
Now I have everything I need. Two new files: LandPathNodeMakerMixin (handles pathfinding graph) + updating the mixins JSON to register it.
Plan:
getNodeTypeinject → returnsOPENfor climbable blocks instead ofBLOCKED, scoped to villagersgetSuccessorsinject → after normal horizontal successors are built, appends the node directly above any climbable block so the pathfinder can chain up a ladder columnRegister the new mixin in
villagerladderclimb.mixins.json
Here’s what the pathfinding fix does:
How the two injections work together
Villager wants to reach a bed at Y=10, ladder at X=5 Y=5..9:
LandPathNodeMakerMixin.getNodeType()
→ block at (5,5,z) is a ladder → normally BLOCKED → now returns OPEN
→ block at (5,6,z) .. (5,9,z) → same
→ A* can now include ladder blocks as valid waypoints
LandPathNodeMakerMixin.getSuccessors()
→ current node = (5,5,z) [ladder], count = N horizontal nodes
→ block above (5,6,z) is also a ladder → typeAbove = OPEN
→ appends PathNode(5,6,z) to successors array, returns N+1
→ repeats at each rung until (5,9,z) → block above is the floor (WALKABLE)
→ floor node is appended → path reaches the destination
The existing LivingEntityMixin still applies the upward velocity each tick so the villager physically climbs once the path is accepted. Together they handle both the planning (pathfinding graph) and the execution (movement physics) sides of ladder climbing.
The compilation failed with this error:
Compilation failed with 4 error(s):
ERROR in src/main/java/com/example/villagerladderclimb/mixin/LandPathNodeMakerMixin.java at line 39: cannot find symbol
if (!(ctx.getEntity() instanceof VillagerEntity)) return;
^
symbol: method getEntity()
location: variable ctx of type PathContext
ERROR in src/main/java/com/example/villagerladderclimb/mixin/LandPathNodeMakerMixin.java at line 63: cannot find symbol
if (!(context.getEntity() instanceof VillagerEntity)) return;
^
symbol: method getEntity()
location: variable context of type PathContext
ERROR in src/main/java/com/example/villagerladderclimb/mixin/LandPathNodeMakerMixin.java at line 39: cannot find symbol
if (!(ctx.getEntity() instanceof VillagerEntity)) return;
^
symbol: method getEntity()
location: variable ctx of type PathContext
ERROR in src/main/java/com/example/villagerladderclimb/mixin/LandPathNodeMakerMixin.java at line 63: cannot find symbol
if (!(context.getEntity() instanceof VillagerEntity)) return;
^
symbol: method getEntity()
location: variable context of type PathContext
=== COMPILATION ERROR ANALYSIS ===
MISSING METHODS:
- getEntity()
ACTION: Check method names and signatures
FILES TO INVESTIGATE:
- src/main/java/com/example/villagerladderclimb/mixin/LandPathNodeMakerMixin.java
- src/main/java/com/example/villagerladderclimb/mixin/LandPathNodeMakerMixin.java
Please fix this error by creating a new artifact with the corrected code.
PathContext in 1.21.11 is a record or simple holder — let me check its actual API via the Yarn mappings docs.
The fix is straightforward: PathContext has no getEntity(). The entity is stored in PathNodeMaker.entity (a protected MobEntity field). I need to @Shadow it and also fix the getNodeType signature — the abstract method takes 5 params (PathContext, int, int, int, MobEntity), not 4.
Three fixes applied:
ctx.getEntity()/context.getEntity()→this.entity—PathContextnever stored the entity; the entity lives inPathNodeMaker.entity(aprotected MobEntityfield), so we@Shadowit and reference it directly.@Shadow protected MobEntity entityadded — shadows the inherited field fromPathNodeMaker.getNodeTypeshadow signature fixed: 4 params → 5 params — the abstract method isgetNodeType(PathContext, int, int, int, MobEntity). The 4-param overload isgetDefaultNodeTypeand doesn’t exist on this class, which would have caused another compile error.
Villagers are no longer in the game, can you fix that
The crash is caused by the @Inject targeting getNodeType with a 4-param descriptor — that overload doesn’t exist in LandPathNodeMaker. The correct method takes 5 params (PathContext, int, int, int, MobEntity). Mixin fails to apply at runtime and crashes the entity loading pipeline, wiping villagers from the world.
Root cause: The inject descriptor getNodeType(PathContext;III) referenced a non-existent 4-parameter overload. Mixin couldn’t find the method at runtime, threw a hard error during entity class loading, and villagers never got registered into the world.
Fix: Corrected the descriptor to the real 5-parameter signature getNodeType(PathContext, int, int, int, MobEntity) and updated the handler to accept the MobEntity mob parameter directly — cleaner than shadowing this.entity for the same check.
still no villagers even if i try to spawn one
Found the root issue. LandPathNodeMaker has a private PathNode[] successors field — same name as the getSuccessors method parameter — and getNodeType in 1.21.11 is defined at the PathNodeMaker level with a different intermediary name than the LandPathNodeMaker override. Together these cause a hard Mixin failure at class load time, which kills VillagerEntity before it can be spawned.
The fix: rewrite the mixin to inject into getDefaultNodeType (4-param, no entity arg) instead, use this.entity via shadow, call ctx.getBlockState() directly, and drop the unnecessary @Shadow getNodeType.
Three concrete changes vs the broken version:
Change | Why |
|---|---|
Inject into getDefaultNodeType(PathContext,III) instead of 5-param getNodeType | getNodeType in 1.21.11 lives on PathNodeMaker with a separate intermediary name from the LandPathNodeMaker override — Mixin couldn’t resolve the selector and threw a hard load error |
Removed @Shadow getNodeType | No longer called internally; removing it eliminates the shadow that was competing with the inject target |
ctx.getBlockState(pos) instead of ctx.getWorld().getBlockState(pos) | PathContext exposes getBlockState directly (caches lookups); getWorld() returns CollisionView which avoids an unnecessary cast |
package com.example.villagerladderclimb;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
@Environment(EnvType.CLIENT)
public class VillagerLadderClimbClient implements ClientModInitializer {
@Override
public void onInitializeClient() {
// No client-side setup required
}
}