1234567891011121314151617181920212223242526272829 |
- #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 {
- const BlockId* id = registryToId.search(registry);
- return id == nullptr ? blocks[0] : blocks[*id];
- }
- const Block& BlockRegistry::getBlock(BlockId id) const {
- return id < blocks.getLength() ? blocks[id] : blocks[0];
- }
|