use of org.terasology.gestalt.assets.ResourceUrn in project Terasology by MovingBlocks.
the class EntityAwareWorldProviderTest method createBlockFamily.
private BlockFamily createBlockFamily(String urn, Prefab prefab, AssetManager assetManager, BlockManager blockManager) {
BlockFamilyDefinitionData data = new BlockFamilyDefinitionData();
data.setBlockFamily(HorizontalFamily.class);
data.getBaseSection().getEntity().setKeepActive(true);
data.getBaseSection().getEntity().setPrefab(prefab);
assetManager.loadAsset(new ResourceUrn(urn), data, BlockFamilyDefinition.class);
return blockManager.getBlockFamily(urn);
}
use of org.terasology.gestalt.assets.ResourceUrn in project Terasology by MovingBlocks.
the class Actor method getComponentField.
public Object getComponentField(ComponentFieldUri uri) {
ComponentLibrary componentLibrary = CoreRegistry.get(EntitySystemLibrary.class).getComponentLibrary();
ComponentMetadata<? extends Component> metadata = componentLibrary.getMetadata(new ResourceUrn(uri.getComponentUri().toString()));
if (metadata == null) {
return null;
}
Component component = entity.getComponent(metadata.getType());
if (component == null) {
return null;
}
FieldMetadata<?, ?> fieldMetadata = metadata.getField(uri.getFieldName());
if (fieldMetadata == null) {
return null;
}
Field field = fieldMetadata.getField();
try {
return field.get(component);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
}
use of org.terasology.gestalt.assets.ResourceUrn in project Terasology by MovingBlocks.
the class IconMeshDataProducer method getAssetData.
@Override
public Optional<MeshData> getAssetData(ResourceUrn urn) throws IOException {
if (ICON_DISCRIMINATOR.equals(urn.getResourceName())) {
ResourceUrn textureUrn = new ResourceUrn(urn.getModuleName().toString() + ResourceUrn.RESOURCE_SEPARATOR + urn.getFragmentName().toString());
Optional<TextureRegionAsset> textureRegionAsset = assetManager.getAsset(textureUrn, TextureRegionAsset.class);
if (textureRegionAsset.isPresent() && !textureRegionAsset.get().getTexture().isDisposed()) {
return Optional.of(IconMeshFactory.generateIconMeshData(textureRegionAsset.get()));
}
}
return Optional.empty();
}
use of org.terasology.gestalt.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.gestalt.assets.ResourceUrn in project Terasology by MovingBlocks.
the class BlockCommands method replaceBlock.
@Command(shortDescription = "Replaces a block in front of user", helpText = "Replaces a block in front of the user at the specified max distance", runOnServer = true, requiredPermission = PermissionManager.CHEAT_PERMISSION)
public void replaceBlock(@Sender EntityRef sender, @CommandParam("blockName") String uri, @CommandParam(value = "maxDistance", required = false) Integer maxDistanceParam) {
int maxDistance = maxDistanceParam != null ? maxDistanceParam : 12;
EntityRef playerEntity = sender.getComponent(ClientComponent.class).character;
EntityRef gazeEntity = GazeAuthoritySystem.getGazeEntityForCharacter(playerEntity);
LocationComponent gazeLocation = gazeEntity.getComponent(LocationComponent.class);
Set<ResourceUrn> matchingUris = Assets.resolveAssetUri(uri, BlockFamilyDefinition.class);
targetSystem.updateTarget(gazeLocation.getWorldPosition(new Vector3f()), gazeLocation.getWorldDirection(new Vector3f()), maxDistance);
EntityRef target = targetSystem.getTarget();
BlockComponent targetLocation = target.getComponent(BlockComponent.class);
if (matchingUris.size() == 1) {
Optional<BlockFamilyDefinition> def = Assets.get(matchingUris.iterator().next(), BlockFamilyDefinition.class);
if (def.isPresent()) {
BlockFamily blockFamily = blockManager.getBlockFamily(uri);
Block block = blockManager.getBlock(blockFamily.getURI());
world.setBlock(targetLocation.getPosition(), block);
} else if (matchingUris.size() > 1) {
StringBuilder builder = new StringBuilder();
builder.append("Non-unique shape name, possible matches: ");
Iterator<ResourceUrn> shapeUris = sortItems(matchingUris).iterator();
while (shapeUris.hasNext()) {
builder.append(shapeUris.next().toString());
if (shapeUris.hasNext()) {
builder.append(", ");
}
}
}
}
}
Aggregations