pub struct AssetPack { /* private fields */ }
Expand description

A collection of Minecraft assets at a given file path.

Implementations

Returns a new AssetPack that can read data from the given directory.

The provided root_dir should be the directory that contains the assets/ and/or data/ directories.

Example
use minecraft_assets::api::AssetPack;

let assets = AssetPack::at_path("~/.minecraft/");

// Load the block states for `oak_planks`
let states = assets.load_blockstates("oak_planks").unwrap();
let variants = states.variants().unwrap();

assert_eq!(variants.len(), 1);

let model_properties = &variants[""].models()[0];
assert_eq!(model_properties.model, "block/oak_planks");

Returns the full path to a resource given a ResourceLocation.

NOTE: no validation of the path is performed. The returned path may not point to an existing file. This method simply computes what the path should be for a given resource.

Example
let assets = AssetPack::at_path("~/.minecraft/");

let loc = ResourceLocation::BlockStates("stone".into());
assert_eq!(
    assets.get_resource_path(&loc).to_string_lossy(),
    "~/.minecraft/assets/minecraft/blockstates/stone.json"
);

Loads the BlockStates of the block with the provided id.

Example
let states = assets.load_blockstates("stone");
let states = assets.load_blockstates("minecraft:dirt");

Loads the block Model identified by the given name or path.

Example
let model = assets.load_block_model("stone");
let model = assets.load_block_model("block/dirt");

Loads the block Model identified by the given name or path, as well as all of its parents and ancestors.

The models are returned as a list, with the first element being the model that was originally requested, the next element being its parent, and so on with the last element being the topmost parent.

Example
let models = assets.load_block_model_recursive("block/cube_all").unwrap();

let expected = vec![
    assets.load_block_model("block/cube_all").unwrap(),
    assets.load_block_model("block/cube").unwrap(),
    assets.load_block_model("block/block").unwrap(),
];
assert_eq!(models, expected);

Loads the item Model identified by the given name or path.

Example
let model = assets.load_item_model("compass");
let model = assets.load_item_model("item/diamond_hoe");

Loads the item Model identified by the given name or path, as well as all of its parents and ancestors.

The models are returned as a list, with the first element being the model that was originally requested, the next element being its parent, and so on with the last element being the topmost parent.

Example
let models = assets.load_item_model_recursive("item/diamond_hoe").unwrap();

let expected = vec![
    assets.load_item_model("item/diamond_hoe").unwrap(),
    assets.load_item_model("item/handheld").unwrap(),
    assets.load_item_model("item/generated").unwrap(),
];
assert_eq!(models, expected);

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.