AssetPack

Struct AssetPack 

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

Top-level API for accessing Minecraft assets.

Implementations§

Source§

impl AssetPack

Source

pub fn at_path(root_dir: impl AsRef<Path>) -> Self

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");
Source

pub fn new<P>(provider: P) -> Self
where P: ResourceProvider + 'static,

Returns a new AssetPack that uses the given ResourceProvider.

Source

pub fn load_blockstates(&self, block_id: &str) -> Result<BlockStates>

Loads the BlockStates of the block with the provided id.

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

pub fn load_block_model(&self, model: &str) -> Result<Model>

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");
Source

pub fn load_block_model_recursive(&self, model: &str) -> Result<Vec<Model>>

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);
Source

pub fn load_item_model(&self, model: &str) -> Result<Model>

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");
Source

pub fn load_item_model_recursive(&self, model: &str) -> Result<Vec<Model>>

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§

Source§

impl Deref for AssetPack

Source§

type Target = dyn ResourceProvider

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.