pub struct AssetPack { /* private fields */ }Expand description
Top-level API for accessing Minecraft assets.
Implementations§
Source§impl AssetPack
impl AssetPack
Sourcepub fn at_path(root_dir: impl AsRef<Path>) -> Self
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");Sourcepub fn new<P>(provider: P) -> Selfwhere
P: ResourceProvider + 'static,
pub fn new<P>(provider: P) -> Selfwhere
P: ResourceProvider + 'static,
Returns a new AssetPack that uses the given ResourceProvider.
Sourcepub fn load_blockstates(&self, block_id: &str) -> Result<BlockStates>
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");Sourcepub fn load_block_model(&self, model: &str) -> Result<Model>
pub fn load_block_model(&self, model: &str) -> Result<Model>
Sourcepub fn load_block_model_recursive(&self, model: &str) -> Result<Vec<Model>>
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);Sourcepub fn load_item_model(&self, model: &str) -> Result<Model>
pub fn load_item_model(&self, model: &str) -> Result<Model>
Sourcepub fn load_item_model_recursive(&self, model: &str) -> Result<Vec<Model>>
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);