Botcraft 1.21.4
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#if PROTOCOL_VERSION < 358 /* < 1.13 */
39 const std::unordered_map<unsigned char, std::unique_ptr<Biome> >& Biomes() const;
40 const Biome* GetBiome(const unsigned char id) const;
41#else
42 const std::unordered_map<int, std::unique_ptr<Biome> >& Biomes() const;
43 const Biome* GetBiome(const int id) const;
44#endif
45
46 const std::unordered_map<ItemId, std::unique_ptr<Item> >& Items() const;
47 const Item* GetItem(const ItemId id) const;
48 const Item* GetItem(const std::string& item_name) const;
49 ItemId GetItemID(const std::string& item_name) const;
50
51#if USE_GUI
52 const Renderer::Atlas* GetAtlas() const;
53#endif
54
55 private:
57
58 void LoadBlocksFile();
59#if PROTOCOL_VERSION > 340 /* > 1.12.2 */
60 void FlattenBlocks();
61#endif
62 void LoadBiomesFile();
63 void LoadItemsFile();
64#if USE_GUI
65 void LoadTextures();
66#endif
67 void ClearCaches();
68
69#if USE_GUI
71#endif
72
73 private:
74#if PROTOCOL_VERSION < 347 /* < 1.13 */
75 std::unordered_map<int, std::unordered_map<unsigned char, std::unique_ptr<Blockstate> > > blockstates;
76#else
77 std::unordered_map<int, std::unique_ptr<Blockstate> > blockstates;
78 std::vector<const Blockstate*> flattened_blockstates;
80#endif
81#if PROTOCOL_VERSION < 358 /* < 1.13 */
82 std::unordered_map<unsigned char, std::unique_ptr<Biome> > biomes;
83#else
84 std::unordered_map<int, std::unique_ptr<Biome> > biomes;
85#endif
86 std::unordered_map<ItemId, std::unique_ptr<Item>> items;
87#if USE_GUI
88 std::unique_ptr<Renderer::Atlas> atlas;
89#endif
90 };
91} // 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
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