Example #1
0
 private List<BlockFamily> processMultiBlockFamily(
     AssetUri blockDefUri, BlockDefinition blockDef) {
   List<BlockFamily> result = Lists.newArrayList();
   for (String shapeString : blockDef.shapes) {
     BlockShape shape = (BlockShape) Assets.get(AssetType.SHAPE, shapeString);
     if (shape != null) {
       BlockUri familyUri;
       if (shape.equals(cubeShape)) {
         familyUri = new BlockUri(blockDefUri.getModuleName(), blockDefUri.getAssetName());
       } else {
         familyUri =
             new BlockUri(
                 blockDefUri.getModuleName(),
                 blockDefUri.getAssetName(),
                 shape.getURI().getModuleName(),
                 shape.getURI().getAssetName());
       }
       blockDef.shape = shapeString;
       if (shape.isCollisionYawSymmetric()) {
         Block block = constructSingleBlock(blockDefUri, blockDef);
         result.add(new SymmetricFamily(familyUri, block, blockDef.categories));
       } else {
         Map<Side, Block> blockMap = Maps.newEnumMap(Side.class);
         constructHorizontalBlocks(blockDefUri, blockDef, blockMap);
         result.add(new HorizontalBlockFamily(familyUri, blockMap, blockDef.categories));
       }
     }
   }
   return result;
 }
Example #2
0
  public LoadBlockDefinitionResults loadBlockDefinitions() {
    logger.info("Loading Blocks...");

    LoadBlockDefinitionResults result = new LoadBlockDefinitionResults();
    for (AssetUri blockDefUri : Assets.list(AssetType.BLOCK_DEFINITION)) {
      try (ModuleContext.ContextSpan ignored =
          ModuleContext.setContext(blockDefUri.getModuleName())) {
        JsonElement rawJson = readJson(blockDefUri);
        if (rawJson != null) {
          JsonObject blockDefJson = rawJson.getAsJsonObject();

          // Don't process templates
          if (blockDefJson.has("template") && blockDefJson.get("template").getAsBoolean()) {
            continue;
          }
          logger.debug("Loading {}", blockDefUri);

          BlockDefinition blockDef = createBlockDefinition(inheritData(blockDefUri, blockDefJson));

          if (isShapelessBlockFamily(blockDef)) {
            result.shapelessDefinitions.add(
                new FreeformFamily(
                    new BlockUri(blockDefUri.getModuleName(), blockDefUri.getAssetName()),
                    blockDef.categories));
          } else {
            if (blockDef.liquid) {
              blockDef.rotation = null;
              blockDef.shapes.clear();
              blockDef.shape = trimmedLoweredShape.getURI().toSimpleString();
            }

            if (blockDef.shapes.isEmpty()) {
              BlockFamilyFactory familyFactory =
                  blockFamilyFactoryRegistry.getBlockFamilyFactory(blockDef.rotation);
              result.families.add(
                  familyFactory.createBlockFamily(this, blockDefUri, blockDef, blockDefJson));
            } else {
              result.families.addAll(processMultiBlockFamily(blockDefUri, blockDef));
            }
          }
        }
      } catch (Exception e) {
        logger.error("Error loading block {}", blockDefUri, e);
      }
    }
    result.shapelessDefinitions.addAll(loadAutoBlocks());
    return result;
  }
  @Test
  public void testColorTransformedToTextureUri() throws Exception {
    AssetUri assetUri = TextureUtil.getTextureUriForColor(Color.RED);
    assertEquals(AssetType.TEXTURE, assetUri.getAssetType());
    assertEquals("engine", assetUri.getModuleName());
    assertEquals("color.ff0000ff", assetUri.getAssetName());

    int red = 0x12;
    int green = 0x3;
    int blue = 0xc4;
    int alpha = 0xe;
    assetUri = TextureUtil.getTextureUriForColor(new Color(red, green, blue, alpha));
    assertEquals(AssetType.TEXTURE, assetUri.getAssetType());
    assertEquals("engine", assetUri.getModuleName());
    assertEquals("color.1203c40e", assetUri.getAssetName());
  }
Example #4
0
 private List<FreeformFamily> loadAutoBlocks() {
   logger.debug("Loading Auto Blocks...");
   List<FreeformFamily> result = Lists.newArrayList();
   for (AssetUri blockTileUri : Assets.list(AssetType.BLOCK_TILE)) {
     if (assetManager
         .getAssetURLs(blockTileUri)
         .get(0)
         .getPath()
         .contains(AUTO_BLOCK_URL_FRAGMENT)) {
       logger.debug("Loading auto block {}", blockTileUri);
       BlockUri uri = new BlockUri(blockTileUri.getModuleName(), blockTileUri.getAssetName());
       result.add(new FreeformFamily(uri));
     }
   }
   return result;
 }