Botcraft 1.21.7
Loading...
Searching...
No Matches
AssetsManager.hpp
Go to the documentation of this file.
1#pragma once
2
6
7#include <vector>
8#include <unordered_map>
9
10namespace Botcraft
11{
12#if USE_GUI
13 namespace Renderer
14 {
15 class Atlas;
16 }
17#endif
18
20 {
21 public:
22 static AssetsManager& getInstance();
23
24 AssetsManager(AssetsManager const&) = delete;
25 void operator=(AssetsManager const&) = delete;
26
27#if PROTOCOL_VERSION < 347 /* < 1.13 */
28 const std::unordered_map<int, std::unordered_map<unsigned char, std::unique_ptr<Blockstate> > >& Blockstates() const;
29#else
30 const std::unordered_map<int, std::unique_ptr<Blockstate> >& Blockstates() const;
31#endif
32 const Blockstate* GetBlockstate(const BlockstateId id) const;
33 /// @brief Get the first blockstate found with a given name
34 /// @param name Name of the blockstate
35 /// @return A blockstate matching the given name, or default block if not found
36 const Blockstate* GetBlockstate(const std::string& name) const;
37
38 /// @brief Get all blockstates that match a given name
39 /// @param name Name of the blockstate
40 /// @return A vector of all blockstates matching the given name
41 std::vector<const Blockstate*> GetBlockstates(const std::string& name) const;
42
43#if PROTOCOL_VERSION < 358 /* < 1.13 */
44 const std::unordered_map<unsigned char, std::unique_ptr<Biome> >& Biomes() const;
45 const Biome* GetBiome(const unsigned char id) const;
46#else
47 const std::unordered_map<int, std::unique_ptr<Biome> >& Biomes() const;
48 const Biome* GetBiome(const int id) const;
49#endif
50
51 const std::unordered_map<ItemId, std::unique_ptr<Item> >& Items() const;
52 const Item* GetItem(const ItemId id) const;
53 const Item* GetItem(const std::string& item_name) const;
54 ItemId GetItemID(const std::string& item_name) const;
55
56#if USE_GUI
57 const Renderer::Atlas* GetAtlas() const;
58#endif
59
60 private:
62
63 void LoadBlocksFile();
64#if PROTOCOL_VERSION > 340 /* > 1.12.2 */
65 void FlattenBlocks();
66#endif
67 void LoadBiomesFile();
68 void LoadItemsFile();
69#if USE_GUI
70 void LoadTextures();
71#endif
72 void ClearCaches();
73
74#if USE_GUI
76#endif
77
78 private:
79#if PROTOCOL_VERSION < 347 /* < 1.13 */
80 std::unordered_map<int, std::unordered_map<unsigned char, std::unique_ptr<Blockstate> > > blockstates;
81#else
82 std::unordered_map<int, std::unique_ptr<Blockstate> > blockstates;
83 std::vector<const Blockstate*> flattened_blockstates;
85#endif
86#if PROTOCOL_VERSION < 358 /* < 1.13 */
87 std::unordered_map<unsigned char, std::unique_ptr<Biome> > biomes;
88#else
89 std::unordered_map<int, std::unique_ptr<Biome> > biomes;
90#endif
91 std::unordered_map<ItemId, std::unique_ptr<Item>> items;
92#if USE_GUI
93 std::unique_ptr<Renderer::Atlas> atlas;
94#endif
95 };
96} // Botcraft
const std::unordered_map< int, std::unique_ptr< Blockstate > > & Blockstates() const
std::unique_ptr< Renderer::Atlas > atlas
std::unordered_map< int, std::unique_ptr< Biome > > biomes
std::unordered_map< int, std::unique_ptr< Blockstate > > blockstates
const Biome * GetBiome(const int id) const
const std::unordered_map< ItemId, std::unique_ptr< Item > > & Items() const
std::vector< const Blockstate * > flattened_blockstates
void operator=(AssetsManager const &)=delete
std::vector< const Blockstate * > GetBlockstates(const std::string &name) const
Get all blockstates that match a given name.
const Renderer::Atlas * GetAtlas() const
const Item * GetItem(const ItemId id) const
static AssetsManager & getInstance()
std::unordered_map< ItemId, std::unique_ptr< Item > > items
ItemId GetItemID(const std::string &item_name) const
AssetsManager(AssetsManager const &)=delete
const std::unordered_map< int, std::unique_ptr< Biome > > & Biomes() const
const Blockstate * GetBlockstate(const BlockstateId id) const
int ItemId
Definition Item.hpp:15
unsigned int BlockstateId