Search in sources :

Example 1 with BlockUriParseException

use of org.terasology.world.block.BlockUriParseException in project Terasology by MovingBlocks.

the class BlockManagerImpl method initialise.

public void initialise(List<String> registeredBlockFamilies, Map<String, Short> knownBlockMappings) {
    if (knownBlockMappings.size() >= MAX_ID) {
        nextId.set(UNKNOWN_ID);
    } else if (knownBlockMappings.size() > 0) {
        nextId.set(knownBlockMappings.values().stream().max(Short::compareTo).orElse((short) 0) + 1);
    }
    registeredBlockInfo.set(new RegisteredState());
    for (String rawFamilyUri : registeredBlockFamilies) {
        try {
            BlockUri familyUri = new BlockUri(rawFamilyUri);
            Optional<BlockFamily> family = loadFamily(familyUri);
            if (family.isPresent()) {
                for (Block block : family.get().getBlocks()) {
                    Short id = knownBlockMappings.get(block.getURI().toString());
                    if (id != null) {
                        block.setId(id);
                    } else {
                        logger.error("Missing id for block {} in provided family {}", block.getURI(), family.get().getURI());
                        if (generateNewIds) {
                            block.setId(getNextId());
                        } else {
                            block.setId(UNKNOWN_ID);
                        }
                    }
                }
                registerFamily(family.get());
            }
        } catch (BlockUriParseException e) {
            logger.error("Failed to parse block family, skipping", e);
        }
    }
}
Also used : BlockUri(org.terasology.world.block.BlockUri) BlockUriParseException(org.terasology.world.block.BlockUriParseException) Block(org.terasology.world.block.Block) BlockFamily(org.terasology.world.block.family.BlockFamily)

Aggregations

Block (org.terasology.world.block.Block)1 BlockUri (org.terasology.world.block.BlockUri)1 BlockUriParseException (org.terasology.world.block.BlockUriParseException)1 BlockFamily (org.terasology.world.block.family.BlockFamily)1