minecraft_assets/api/resource/kind.rs
1use crate::api::ResourceCategory;
2
3/// The type of a resource.
4#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
5pub enum ResourceKind {
6 /// Resources (`.json`) in `assets/<namespace>/blockstates/`.
7 BlockStates,
8
9 /// Resources (`.json`) in `assets/<namespace>/models/block/`.
10 BlockModel,
11
12 /// Resources (`.json`) in `assets/<namespace>/models/item/`.
13 ItemModel,
14
15 /// Resources (`.png`) in `assets/<namespace>/textures/`.
16 Texture,
17
18 /// Resources (`.mcmeta`) in `assets/<namespace>/textures/`.
19 TextureMeta,
20}
21
22impl ResourceKind {
23 /// Returns the category of this resource type (assets or data).
24 pub fn category(&self) -> ResourceCategory {
25 match self {
26 Self::BlockStates
27 | Self::BlockModel
28 | Self::ItemModel
29 | Self::Texture
30 | Self::TextureMeta => ResourceCategory::Assets,
31 }
32 }
33
34 /// Returns the file extension used for this resource's file.
35 ///
36 /// # Example
37 ///
38 /// ```
39 /// # use minecraft_assets::api::*;
40 /// let kind = ResourceKind::BlockStates;
41 /// assert_eq!(kind.extension(), "json");
42 ///
43 /// let kind = ResourceKind::Texture;
44 /// assert_eq!(kind.extension(), "png");
45 ///
46 /// let kind = ResourceKind::TextureMeta;
47 /// assert_eq!(kind.extension(), "mcmeta");
48 /// ```
49 pub fn extension(&self) -> &'static str {
50 match self {
51 Self::BlockStates | Self::BlockModel | Self::ItemModel => "json",
52 Self::Texture => "png",
53 Self::TextureMeta => "mcmeta",
54 }
55 }
56
57 /// Returns the path relative to `assets/<namespace>/` or
58 /// `data/<namespace>/` in which resources of this type reside.
59 pub fn directory(&self) -> &'static str {
60 match self {
61 Self::BlockStates => "blockstates",
62 Self::BlockModel => "models/block",
63 Self::ItemModel => "models/item",
64 Self::Texture | Self::TextureMeta => "textures",
65 }
66 }
67}