<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[[Guide] Working with Baritone API]]></title><description><![CDATA[<p dir="auto"><img src="/assets/uploads/files/1753981889445-7cd8d800-c82a-46d9-9471-dcab0068a3ad-image-resized.png" alt="7cd8d800-c82a-46d9-9471-dcab0068a3ad-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto">ts version (npm package subject to change in the near future once a proper name is found)</p>
<pre><code>import { BaritoneAPI } from "jvm-types/baritone/api/BaritoneAPI"
import { GoalXZ } from "jvm-types/baritone/api/pathing/goals/GoalXZ"

const script = registerScript.apply({
    name: "baritone-api-example",
    version: "1.0.0",
    authors: ["commandblock2"]
});

script.registerModule({
    name: "baritone-api-example",
    description: "Baritone example module",
    category: "Client",

}, (mod) =&gt; {
    mod.on("enable", () =&gt; {
        BaritoneAPI.getSettings().allowSprint.value = true;
        BaritoneAPI.getSettings().primaryTimeoutMS.value = Primitives.long(2000);
        const baritone = BaritoneAPI.getProvider().getPrimaryBaritone();
        baritone.getCustomGoalProcess().setGoalAndPath(new GoalXZ(100, 100))
    })
})

export { }
</code></pre>
<p dir="auto">js version, but slightly changed from the compiled one (imports to Java.type), probably should work but never tested.<br />
Edit: The directly compiled version works on my custom branch. But I was kinda disappointed for baritone not documenting if they provide access to their path finding engine without path execution, if any one knows, please leave a comment.</p>
<pre><code>const BaritoneAPI_1 = Java.type("baritone.api.BaritoneAPI");
const GoalXZ_1 = Java.type("baritone.api.pathing.goals.GoalXZ");
const script = registerScript.apply({
    name: "baritone-api-example",
    version: "1.0.0",
    authors: ["commandblock2"]
});
script.registerModule({
    name: "baritone-api-example",
    description: "Baritone example module",
    category: "Client",
}, (mod) =&gt; {
    mod.on("enable", () =&gt; {
        BaritoneAPI_1.BaritoneAPI.getSettings().allowSprint.value = true;
        BaritoneAPI_1.BaritoneAPI.getSettings().primaryTimeoutMS.value = Primitives.long(2000);
        const baritone = BaritoneAPI_1.BaritoneAPI.getProvider().getPrimaryBaritone();
        baritone.getCustomGoalProcess().setGoalAndPath(new GoalXZ_1.GoalXZ(100, 100));
    });
});
</code></pre>
]]></description><link>https://forum.liquidbounce.net/topic/8531/guide-working-with-baritone-api</link><generator>RSS for Node</generator><lastBuildDate>Wed, 16 Sep 2026 04:15:14 GMT</lastBuildDate><atom:link href="https://forum.liquidbounce.net/topic/8531.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 31 Jul 2025 17:15:05 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to [Guide] Working with Baritone API on Sat, 02 Aug 2025 15:42:40 GMT]]></title><description><![CDATA[<p dir="auto">It's definitely doable, but you need to use the <code>unoptimized</code> jar to directly call this. Here is the script in ts, but you may need to adapt the <code>imports</code> to <code>Java.type</code> in js. And also for the visualization manager it's not yet available outside of my project. will release once the api is well designed and performance becomes decent and after a proper name is found for the npm package.</p>
<pre><code>import { BaritoneAPI } from "jvm-types/baritone/api/BaritoneAPI"
import { GoalXZ } from "jvm-types/baritone/api/pathing/goals/GoalXZ"
import { CalculationContext } from "jvm-types/baritone/pathing/movement/CalculationContext"
import { Favoring } from "jvm-types/baritone/utils/pathing/Favoring"
import { BetterBlockPos } from "jvm-types/baritone/api/utils/BetterBlockPos"
import { IPath } from "jvm-types/baritone/api/pathing/calc/IPath"
import { VisualizationManager } from "lbng-utils-typed/dist/visualization-utils"
import { PathCalculationResult$Type } from "jvm-types/baritone/api/utils/PathCalculationResult$Type"

// note: this import is not from baritone-api jar
// it is only presented in the baritone-unoptimized jar
// as the `AStarPathFinder` class is possibly obfuscated in the baritone-standalone jar
// so you will have to install the baritone-unoptimized jar to use this import
import { AStarPathFinder } from "jvm-types/baritone/pathing/calc/AStarPathFinder"


const script = registerScript.apply({
    name: "astar-pathfinder-example",
    version: "1.0.0",
    authors: ["commandblock2"]
});

script.registerModule({
    name: "baritone-api-example",
    description: "Baritone example module",
    category: "Client",

}, (mod) =&gt; {
    mod.on("enable", () =&gt; {
        BaritoneAPI.getSettings().allowSprint.value = true;
        BaritoneAPI.getSettings().primaryTimeoutMS.value = Primitives.long(2000);
        const baritone = BaritoneAPI.getProvider().getPrimaryBaritone();
        baritone.getCustomGoalProcess().setGoalAndPath(new GoalXZ(100, 100))
    })
})

script.registerModule({
    name: "astar-pathfinder-example",
    description: "Direct AStarPathFinder construction example",
    category: "Client",
    settings: {
        goalX: Setting.float({
            name: "Goal X",
            default: 100,
            range: [-10000, 10000] // Assuming a reasonable range
        }),
        goalZ: Setting.float({
            name: "Goal Z",
            default: 100,
            range: [-10000, 10000] // Assuming a reasonable range
        }),
        recalculateInterval: Setting.int({
            name: "Recalculate Interval (ticks)",
            default: 20,
            range: [1, 200]
        })
    }
}, (mod) =&gt; {

    const viz = new VisualizationManager(mod);

    let previousPath: IPath | null = null;

    let lastRecalculateTick = 0;

    const calculatePath = () =&gt; {
        const baritone = BaritoneAPI.getProvider().getPrimaryBaritone();

        // Get current player position
        const playerPos = baritone.getPlayerContext().playerFeet();
        const start = new BetterBlockPos(playerPos.getX(), playerPos.getY(), playerPos.getZ());

        // Create calculation context for threaded use
        const context = new CalculationContext(baritone, true);

        // Create favoring (empty favoring for no preferences)
        const favoring = new Favoring(baritone.getPlayerContext(), previousPath as unknown as IPath, context);

        // Create goal using settings
        const goal = new GoalXZ(mod.settings.goalX.get() as unknown as number, mod.settings.goalZ.get() as unknown as number);

        // Construct AStarPathFinder directly
        const pathfinder = new AStarPathFinder(
            start,           // realStart
            start.getX(),    // startX
            start.getY(),    // startY
            start.getZ(),    // startZ
            goal,            // goal
            favoring,        // favoring
            context          // context
        );

        // @ts-expect-error
        UnsafeThread.run(() =&gt; {
            const result = pathfinder.calculate(Primitives.long(2000), Primitives.long(5000));

            // Handle result
            if (result.getType() != PathCalculationResult$Type.CANCELLATION) {
                const path = result.getPath().get();
                console.log("Path found! Length: " + path.length());
                mc.execute(() =&gt; {
                    viz.addVisualization({
                        lineData: {
                            positions: path.positions().map((pos) =&gt; new Vec3d(pos.x + .5, pos.y, pos.z + .5)),

                        },
                        durationTicks: 20 * 60,
                    });
                    previousPath = path;
                });
                // Use the path as needed - you now have direct access without execution
            } else {
                console.log("Path calculation failed: " + result.getType().toString());
            }
        });
    };

    mod.on("enable", () =&gt; {
        viz.clearAllVisualizations();
        lastRecalculateTick = 0; // Reset on enable
        calculatePath(); // Initial calculation
    });

    mod.on("gametick", () =&gt; {
        if (mc.player &amp;&amp; mc.world &amp;&amp; (mc.player.age - lastRecalculateTick) &gt;= (mod.settings.recalculateInterval.get() as unknown as number)) {
            calculatePath();
            lastRecalculateTick = mc.player.age;
        }
    });
});

export { }
</code></pre>
<p dir="auto"><img src="/assets/uploads/files/1754149301736-vlcsnap-2025-08-02-23h41m20s672.png" alt="vlcsnap-2025-08-02-23h41m20s672.png" class=" img-fluid img-markdown" /></p>
]]></description><link>https://forum.liquidbounce.net/post/40242</link><guid isPermaLink="true">https://forum.liquidbounce.net/post/40242</guid><dc:creator><![CDATA[commandblock2]]></dc:creator><pubDate>Sat, 02 Aug 2025 15:42:40 GMT</pubDate></item><item><title><![CDATA[Reply to [Guide] Working with Baritone API on Thu, 31 Jul 2025 17:22:36 GMT]]></title><description><![CDATA[<p dir="auto">it probably does have a AStarPathFinder just for this, but it's gonna be tested if this is really going to work.</p>
<p dir="auto"><img src="/assets/uploads/files/1753982465954-549119de-3d82-4af2-b536-1c5a7cc7247a-image-resized.png" alt="image.png" class=" img-fluid img-markdown" /></p>
]]></description><link>https://forum.liquidbounce.net/post/40238</link><guid isPermaLink="true">https://forum.liquidbounce.net/post/40238</guid><dc:creator><![CDATA[commandblock2]]></dc:creator><pubDate>Thu, 31 Jul 2025 17:22:36 GMT</pubDate></item></channel></rss>