Struct minecraft_assets::api::AssetPack
source · [−]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"
);pub fn load_blockstates<'a>(
&self,
block_id: impl Into<ResourceIdentifier<'a>>
) -> Result<BlockStates>
pub fn load_blockstates<'a>(
&self,
block_id: impl Into<ResourceIdentifier<'a>>
) -> 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");pub fn load_block_model_recursive<'a>(
&self,
model: impl Into<ModelIdentifier<'a>>
) -> Result<Vec<Model>>
pub fn load_block_model_recursive<'a>(
&self,
model: impl Into<ModelIdentifier<'a>>
) -> 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);pub fn load_item_model_recursive<'a>(
&self,
model: impl Into<ModelIdentifier<'a>>
) -> Result<Vec<Model>>
pub fn load_item_model_recursive<'a>(
&self,
model: impl Into<ModelIdentifier<'a>>
) -> 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
Auto Trait Implementations
impl RefUnwindSafe for AssetPack
impl UnwindSafe for AssetPack
Blanket Implementations
Mutably borrows from an owned value. Read more