12345678910111213141516171819202122232425262728293031 |
- #include "common/block/BlockRegistry.h"
- BlockRegistry::BlockRegistry() {
- add("air");
- add("stone");
- add("dirt");
- add("grass");
- }
- void BlockRegistry::forEach(void(*f)(const Block&)) const {
- for(const Block& b : blocks) {
- f(b);
- }
- }
- void BlockRegistry::add(const char* registry) {
- BlockId id = blocks.getLength();
- blocks.add(id, registry);
- registryToId.add(registry, id);
- }
- const Block& BlockRegistry::getBlock(const BlockName& registry) const {
- return blocks[registryToId.search(registry, 0)];
- }
- const Block& BlockRegistry::getBlock(BlockId id) const {
- if(id < blocks.getLength()) {
- return blocks[id];
- }
- return blocks[0];
- }
|