.dev

Developers1 min read

Assets

Images, sounds and models addressed by hash and cached on the client.

Capability
asset:1
Kinds
PNG · OGG · OBJ
Client cache
64 MB per server

Some modules take your own files: sidebar row icons, hologram images, nametag badges, tab icons, UI images, sounds and private branding art. These are assets, addressed by their SHA-256 hash.

When you send something that references an asset, the SDK first offers the hash. The client answers with the hashes it does not have, and only those are sent. A returning player who already has your art downloads nothing.

Registering an asset

Load assets once, at startup, through the store on TehoApi:

Java
AssetStore store = TehoApi.get().assets();

Asset coin = store.load(Asset.Kind.PNG, getDataFolder().toPath().resolve("coin.png"));
Asset anthem = store.ogg(Files.readAllBytes(getDataFolder().toPath().resolve("anthem.ogg")));
MethodWhat it does
load(kind, Path) / load(kind, InputStream)Reads and registers a file.
png(bytes), ogg(bytes), obj(bytes)Registers bytes you already have.
register(Asset)Registers an Asset you built with Asset.of(kind, bytes).
find(hash)Looks one up by hash.

Using an asset

Pass the Asset wherever a builder accepts one. The SDK handles the offer, the client's request and chunking.

Java
teho.hud().sidebar(Sidebar.replace("Skyline")
        .row(Sidebar.Row.of("coins", "Coins").value("1,250").icon(coin))
        .build());

teho.audio().play(Sound.asset("anthem", anthem).music(true).build());

Limits

KindMax sizeUsed by
PNG2 MBSidebar and tab icons, hologram images, nametag badges, UI images, branding
OGG4 MBAudio
OBJ2 MBCached by the client, but no module draws models yet

Builders that need an image check the kind and throw if you pass, say, an OGG as a sidebar icon. Asset.of checks the size.

The client keeps up to 64 MB per server in an LRU cache and evicts the least recently used assets first.