ghast v0.5.6

Core concepts

Versions

ghast speaks 1.8.9, 1.12.2, 1.16.5, 26.1, 26.2 and 26.3 behind one bot API. This page shows how a version is chosen, what the shared API covers, where versions genuinely differ and how the API tells you, and which cargo feature builds each version.

The versions

Game versionsProtocolGameVersionCargo feature
1.8 – 1.8.947V1_8_9v1_8
1.12.1338V1_12_1v1_12_2
1.12.2340V1_12_2v1_12_2
1.16.2751V1_16_2v1_16_5
1.16.3753V1_16_3v1_16_5
1.16.4 – 1.16.5754V1_16_5v1_16_5
26.1, 26.1.1, 26.1.2775V26_1v26_1
26.2776V26_2v26_2
26.3777V26_3v26_3

Versions that share a protocol number are served by the same code: 26.1, 26.1.1 and 26.1.2 are one protocol (775) and give identical oracle records, so they are one row. 1.12.1, 1.16.2 and 1.16.3 are sub-versions: they run the code of 1.12.2 or 1.16.5 with their own protocol number (and, for 1.12.1, its VarInt keep-alive ids), and they come with that row's feature.

Every version feature is on by default. To build fewer, see Installation.

Choosing a version at connect time

You name the version when you build the Client. ghast does not ask the server which version it runs, so the value must match the server. GameVersion parses from a game version or a protocol number: "1.8" through "1.8.9" and "47", "1.12.1", "1.12.2", "1.16.2" through "1.16.5", "26.1", "26.1.1", "26.1.2", "26.2", "26.3", and "338", "340", "751", "753", "754", "775", "776", "777".

use ghast::{Account, Behavior, Client, ClientError, GameVersion, TickContext};

struct Report;

impl Behavior for Report {
    fn start(&mut self, ctx: &mut TickContext<'_>) {
        let v = ctx.version();
        let caps = v.caps();
        println!(
            "{v} (protocol {}): eye height {}, chat limit {}, 1.9 combat: {}",
            caps.protocol, caps.eye_height, caps.chat_limit, caps.combat_1_9
        );
        if caps.configuration_state {
            println!("this version has a configuration state between login and play");
        }
    }

    fn tick(&mut self, ctx: &mut TickContext<'_>) {
        if ctx.is_dead() {
            ctx.respawn();
        }
    }
}

#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // "1.8.9", "1.16.4", "26.1.2", "776", ... all parse.
    let arg = std::env::args().nth(1).unwrap_or_else(|| "26.3".into());
    let version: GameVersion = arg.parse()?;

    for v in GameVersion::ALL.iter().filter(|v| v.enabled()) {
        println!("built with {v} (protocol {})", v.protocol());
    }

    let client = Client::new("localhost:25565".parse()?, version, Account::offline("Bot")?);
    match client.run(&mut Report).await {
        Ok(end) => println!("{end:?}"),
        Err(ClientError::VersionNotEnabled(v)) => eprintln!("enable the ghast feature for {v}"),
        Err(e) => return Err(e.into()),
    }
    Ok(())
}

GameVersion::ALL lists every supported version, oldest first. enabled() says whether this build includes a version. A version whose feature is off still exists, and running it returns ClientError::VersionNotEnabled.

GameVersion is #[non_exhaustive], and new Minecraft versions arrive as new variants in patch releases. Give every match on it a _ arm.

What one API covers

When run starts, it matches the version once and runs a session compiled for that version. The engine and your behaviour are version-free: behaviours never see packets or versions unless they ask. One Behavior therefore runs on every version without changes, including:

  • the tick loop, Controls, set_aim and the movement physics of each version;
  • chat, respawn, slot selection, digging, placing, using items and attacking, with each version's rules (1.8 and 1.9+ combat, for example) applied for you;
  • inventory windows and clicks with each version's click prediction;
  • entity tracking, the HUD, signs, books and fishing, where the version has them.

The ext helpers go one step further: item and block names and ids follow the connection's version, 26.x included.

Where versions differ

Some differences are real game differences, and the API exposes them instead of hiding them.

The capability row. GameVersion::caps() (or ctx.version().caps()) returns the version's Capabilities: protocol number, eye heights, the chat limit, whether 1.9 combat applies, whether a configuration state exists, and more. The client core reads this row instead of comparing version numbers, and so can you.

Values that change meaning. A few readers return version-specific values:

  • world().raw_block returns the version's raw block state id (the 1.8 id << 4 | meta, or the global palette id on later versions); decode it with ghast::data.
  • world().build_height() is None for the fixed 0 to 256 worlds of 1.8.9 to 1.16.5 and gives the dimension's height on 26.x.
  • dimension() is a number as text ("0", "-1", "1") on 1.8.9 and 1.12.2, and the world name on 1.16.5 and 26.x.
  • chat truncates to the version's limit (100 UTF-16 units on 1.8, 256 on 1.16).

Features a version does not have. Some groups only exist on some versions:

FeatureVersions
boss bars (Interests::HUD)1.9+ (not 1.8.9)
item cooldowns1.12.2, 1.16.5, 26.x
server dialogs (Interests::DIALOGS)26.1+
server recipes and tags (Interests::RECIPES)1.16.5 only; other versions need none
configuration state, server transfers26.x
shared chunk store (Client::shared_chunks)26.x; older versions ignore it
bot screen (ghast-viewer)1.8.9 and 26.x

On 26.3, which has no serverbound swing packet, swing sends punch instead.

Raw packets. Behavior::raw_packets takes the GameVersion, because packet ids differ by version. Decode the copies with the version's module under ghast::protocol (for example ghast::protocol::v1_8).

The full table of what is verified on which version is in the root README, and how each version is checked against vanilla is in Accuracy.