12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- #include "common/block/Blocks.h"
- const int BlockRegistry::BLOCK_AMOUNT = 4;
- const Block* BlockRegistry::BLOCKS[BLOCK_AMOUNT];
- const BlockAir Blocks::AIR;
- const Block Blocks::GRASS;
- const Block Blocks::DIRT;
- const Block Blocks::STONE;
- BlockRegistry::BlockRegistry()
- {
- }
- void BlockRegistry::registerBlock(const Block& block)
- {
- BlockId id = block.getId();
- if(id >= 0 && id < BLOCK_AMOUNT && BLOCKS[id] == nullptr)
- {
- BLOCKS[id] = █
- }
- }
- const Block& BlockRegistry::getBlockFromId(BlockId id)
- {
- return *BLOCKS[(id >= 0 && id < BLOCK_AMOUNT && BLOCKS[id] != nullptr) * id];
- }
- void BlockRegistry::init()
- {
- for(int i = 0; i < BLOCK_AMOUNT; i++)
- {
- BLOCKS[i] = nullptr;
- }
- }
- void BlockRegistry::registerBlocks()
- {
- init();
-
- registerBlock(Blocks::AIR);
- registerBlock(Blocks::GRASS);
- registerBlock(Blocks::DIRT);
- registerBlock(Blocks::STONE);
- }
|