@Override public boolean hasBlockFamily(BlockUri uri) { if (registeredBlockInfo.get().registeredFamilyByUri.containsKey(uri) || availableFamilies.containsKey(uri) || freeformBlockUris.contains(uri)) { return true; } return uri.hasShape() && Assets.get(uri.getShapeUri()) != null && freeformBlockUris.contains(uri.getRootFamilyUri()); }
public BlockFamily loadWithShape(BlockUri uri) { try (ModuleContext.ContextSpan ignored = ModuleContext.setContext(uri.getModuleName())) { BlockShape shape = cubeShape; if (uri.hasShape()) { AssetUri shapeUri = uri.getShapeUri(); if (!shapeUri.isValid()) { return null; } shape = (BlockShape) Assets.get(shapeUri); if (shape == null) { return null; } } AssetUri blockDefUri = new AssetUri(AssetType.BLOCK_DEFINITION, uri.getModuleName(), uri.getFamilyName()); BlockDefinition def; if (assetManager.getAssetURLs(blockDefUri).isEmpty()) { // An auto-block def = new BlockDefinition(); } else { def = createBlockDefinition( inheritData(blockDefUri, readJson(blockDefUri).getAsJsonObject())); } def.shape = (shape.getURI().toSimpleString()); if (shape.isCollisionYawSymmetric()) { Block block = constructSingleBlock(blockDefUri, def); if (block.getDisplayName().isEmpty()) { block.setDisplayName(shape.getDisplayName()); } else if (!shape.getDisplayName().isEmpty()) { block.setDisplayName(block.getDisplayName() + " " + shape.getDisplayName()); } return new SymmetricFamily(uri, block, def.categories); } else { Map<Side, Block> blockMap = Maps.newEnumMap(Side.class); constructHorizontalBlocks(blockDefUri, def, blockMap); for (Block block : blockMap.values()) { if (block.getDisplayName().isEmpty()) { block.setDisplayName(shape.getDisplayName()); } else if (!shape.getDisplayName().isEmpty()) { block.setDisplayName(block.getDisplayName() + " " + shape.getDisplayName()); } } return new HorizontalBlockFamily(uri, blockMap, def.categories); } } catch (Exception e) { logger.error("Error loading block shape {}", uri, e); } return null; }