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) {
}
}
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;
}
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();
}
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());
}
}
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 + "'");
}
}
Aggregations