Search in sources :

Example 36 with ResourceUrn

use of org.terasology.assets.ResourceUrn in project Terasology by MovingBlocks.

the class NUISkinEditorScreen method resetStateInternal.

/**
 * {@inheritDoc}
 */
@Override
protected void resetStateInternal(JsonTree node) {
    getEditor().setTreeViewModel(node, true);
    resetPreviewWidget();
    getEditor().clearHistory();
    updateConfig();
    selectedAsset = selectedAssetPending;
    try {
        ResourceUrn urn = new ResourceUrn(selectedAsset);
        setSelectedAssetPath(urn);
    } catch (InvalidUrnException ignored) {
    }
}
Also used : InvalidUrnException(org.terasology.assets.exceptions.InvalidUrnException) ResourceUrn(org.terasology.assets.ResourceUrn)

Example 37 with ResourceUrn

use of org.terasology.assets.ResourceUrn in project Terasology by MovingBlocks.

the class BlockCommands method giveBlock.

/**
 * Called by 'give' command in ItemCommands.java to attempt to put a block in the player's inventory when no item is found.
 * Called by 'giveBulkBlock' command in BlockCommands.java to put a block in the player's inventory.
 * @return Null if not found, otherwise success or warning message
 */
public String giveBlock(@Sender EntityRef sender, @CommandParam("blockName") String uri, @CommandParam(value = "quantity", required = false) Integer quantityParam, @CommandParam(value = "shapeName", required = false) String shapeUriParam) {
    Set<ResourceUrn> matchingUris = Assets.resolveAssetUri(uri, BlockFamilyDefinition.class);
    BlockFamily blockFamily = null;
    if (matchingUris.size() == 1) {
        Optional<BlockFamilyDefinition> def = Assets.get(matchingUris.iterator().next(), BlockFamilyDefinition.class);
        if (def.isPresent()) {
            if (def.get().isFreeform()) {
                if (shapeUriParam == null) {
                    blockFamily = blockManager.getBlockFamily(new BlockUri(def.get().getUrn(), new ResourceUrn("engine:cube")));
                } else {
                    Set<ResourceUrn> resolvedShapeUris = Assets.resolveAssetUri(shapeUriParam, BlockShape.class);
                    if (resolvedShapeUris.isEmpty()) {
                        return "Found block. No shape found for '" + shapeUriParam + "'";
                    } else if (resolvedShapeUris.size() > 1) {
                        StringBuilder builder = new StringBuilder();
                        builder.append("Found block. Non-unique shape name, possible matches: ");
                        Iterator<ResourceUrn> shapeUris = sortItems(resolvedShapeUris).iterator();
                        while (shapeUris.hasNext()) {
                            builder.append(shapeUris.next().toString());
                            if (shapeUris.hasNext()) {
                                builder.append(", ");
                            }
                        }
                        return builder.toString();
                    }
                    blockFamily = blockManager.getBlockFamily(new BlockUri(def.get().getUrn(), resolvedShapeUris.iterator().next()));
                }
            } else {
                blockFamily = blockManager.getBlockFamily(new BlockUri(def.get().getUrn()));
            }
        }
        if (blockFamily == null) {
            // Should never be reached
            return "Block not found";
        }
        int defaultQuantity = blockFamily.getArchetypeBlock().isStackable() ? 16 : 1;
        int quantity = quantityParam != null ? quantityParam : defaultQuantity;
        return giveBlock(blockFamily, quantity, sender);
    } else if (matchingUris.size() > 1) {
        StringBuilder builder = new StringBuilder();
        builder.append("Non-unique block name, possible matches: ");
        Joiner.on(", ").appendTo(builder, matchingUris);
        return builder.toString();
    }
    return null;
}
Also used : BlockUri(org.terasology.world.block.BlockUri) Iterator(java.util.Iterator) BlockFamily(org.terasology.world.block.family.BlockFamily) ResourceUrn(org.terasology.assets.ResourceUrn) BlockFamilyDefinition(org.terasology.world.block.loader.BlockFamilyDefinition)

Example 38 with ResourceUrn

use of org.terasology.assets.ResourceUrn in project Terasology by MovingBlocks.

the class BlockManagerImpl method loadFamily.

private Optional<BlockFamily> loadFamily(BlockUri uri) {
    Optional<BlockFamilyDefinition> familyDef = assetManager.getAsset(uri.getBlockFamilyDefinitionUrn(), BlockFamilyDefinition.class);
    if (familyDef.isPresent() && familyDef.get().isLoadable()) {
        if (familyDef.get().isFreeform()) {
            ResourceUrn shapeUrn;
            if (uri.getShapeUrn().isPresent()) {
                shapeUrn = uri.getShapeUrn().get();
            } else {
                shapeUrn = CUBE_SHAPE_URN;
            }
            Optional<BlockShape> shape = assetManager.getAsset(shapeUrn, BlockShape.class);
            if (shape.isPresent()) {
                return Optional.of(familyDef.get().createFamily(shape.get(), blockBuilder));
            }
        } else if (!familyDef.get().isFreeform()) {
            return Optional.of(familyDef.get().createFamily(blockBuilder));
        }
    } else {
        logger.error("Family not available: {}", uri);
    }
    return Optional.empty();
}
Also used : BlockShape(org.terasology.world.block.shapes.BlockShape) BlockFamilyDefinition(org.terasology.world.block.loader.BlockFamilyDefinition) ResourceUrn(org.terasology.assets.ResourceUrn)

Example 39 with ResourceUrn

use of org.terasology.assets.ResourceUrn in project Terasology by MovingBlocks.

the class Atlas method doReload.

@Override
protected void doReload(AtlasData data) {
    subtextures.clear();
    for (Map.Entry<Name, SubtextureData> entry : data.getSubtextures().entrySet()) {
        ResourceUrn subtextureUrn = new ResourceUrn(getUrn().getModuleName(), getUrn().getResourceName(), entry.getKey());
        subtextures.put(subtextureUrn, entry.getValue());
    }
}
Also used : SubtextureData(org.terasology.rendering.assets.texture.subtexture.SubtextureData) ResourceUrn(org.terasology.assets.ResourceUrn) Map(java.util.Map) Name(org.terasology.naming.Name)

Example 40 with ResourceUrn

use of org.terasology.assets.ResourceUrn in project Terasology by MovingBlocks.

the class FontFormat method parsePage.

private void parsePage(FontDataBuilder builder, Name moduleName, String pageInfo) throws IOException {
    Matcher pageMatcher = pagePattern.matcher(pageInfo);
    if (pageMatcher.matches()) {
        int pageId = Integer.parseInt(pageMatcher.group(1));
        Name textureName = new Name(pageMatcher.group(2).substring(0, pageMatcher.group(2).lastIndexOf('.')));
        Optional<Material> material = assetManager.getAsset(new ResourceUrn(moduleName, new Name("font"), textureName), Material.class);
        if (!material.isPresent()) {
            throw new IOException("Failed to load font - unable to resolve font page '" + textureName + "'");
        } else {
            builder.addPage(pageId, assetManager.getAsset(new ResourceUrn(moduleName, textureName), Texture.class).get(), material.get());
        }
    } else {
        throw new IOException("Failed to load font - invalid page line '" + pageInfo + "'");
    }
}
Also used : Matcher(java.util.regex.Matcher) Material(org.terasology.rendering.assets.material.Material) IOException(java.io.IOException) ResourceUrn(org.terasology.assets.ResourceUrn) Name(org.terasology.naming.Name)

Aggregations

ResourceUrn (org.terasology.assets.ResourceUrn)65 Before (org.junit.Before)10 BlockFamilyDefinitionData (org.terasology.world.block.loader.BlockFamilyDefinitionData)10 AssetManager (org.terasology.assets.management.AssetManager)9 Prefab (org.terasology.entitySystem.prefab.Prefab)9 SymmetricBlockFamilyFactory (org.terasology.world.block.family.SymmetricBlockFamilyFactory)9 Command (org.terasology.logic.console.commandSystem.annotations.Command)8 EntityRef (org.terasology.entitySystem.entity.EntityRef)7 PrefabData (org.terasology.entitySystem.prefab.PrefabData)7 BlockUri (org.terasology.world.block.BlockUri)7 Name (org.terasology.naming.Name)6 Texture (org.terasology.rendering.assets.texture.Texture)6 BlockManagerImpl (org.terasology.world.block.internal.BlockManagerImpl)6 NullWorldAtlas (org.terasology.world.block.tiles.NullWorldAtlas)6 ByteBuffer (java.nio.ByteBuffer)5 Test (org.junit.Test)5 SimpleUri (org.terasology.engine.SimpleUri)5 IOException (java.io.IOException)4 PojoPrefab (org.terasology.entitySystem.prefab.internal.PojoPrefab)4 BiomeManager (org.terasology.world.biomes.BiomeManager)4