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