Search in sources :

Example 11 with ResourceUrn

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);
}
Also used : BlockFamilyDefinitionData(org.terasology.engine.world.block.loader.BlockFamilyDefinitionData) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn)

Example 12 with ResourceUrn

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);
    }
}
Also used : Field(java.lang.reflect.Field) EntitySystemLibrary(org.terasology.engine.entitySystem.metadata.EntitySystemLibrary) ComponentLibrary(org.terasology.engine.entitySystem.metadata.ComponentLibrary) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) Component(org.terasology.gestalt.entitysystem.component.Component)

Example 13 with ResourceUrn

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();
}
Also used : ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) TextureRegionAsset(org.terasology.engine.rendering.assets.texture.TextureRegionAsset)

Example 14 with ResourceUrn

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();
}
Also used : BlockShape(org.terasology.engine.world.block.shapes.BlockShape) BlockFamilyDefinition(org.terasology.engine.world.block.loader.BlockFamilyDefinition) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn)

Example 15 with ResourceUrn

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(", ");
                }
            }
        }
    }
}
Also used : ClientComponent(org.terasology.engine.network.ClientComponent) LocationComponent(org.terasology.engine.logic.location.LocationComponent) BlockComponent(org.terasology.engine.world.block.BlockComponent) Vector3f(org.joml.Vector3f) Iterator(java.util.Iterator) Block(org.terasology.engine.world.block.Block) BlockFamily(org.terasology.engine.world.block.family.BlockFamily) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) BlockFamilyDefinition(org.terasology.engine.world.block.loader.BlockFamilyDefinition) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) Command(org.terasology.engine.logic.console.commandSystem.annotations.Command)

Aggregations

ResourceUrn (org.terasology.gestalt.assets.ResourceUrn)90 Test (org.junit.jupiter.api.Test)19 Name (org.terasology.gestalt.naming.Name)12 BeforeEach (org.junit.jupiter.api.BeforeEach)11 BlockFamilyDefinitionData (org.terasology.engine.world.block.loader.BlockFamilyDefinitionData)10 IOException (java.io.IOException)9 AssetManager (org.terasology.gestalt.assets.management.AssetManager)9 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)8 Prefab (org.terasology.engine.entitySystem.prefab.Prefab)8 PrefabData (org.terasology.engine.entitySystem.prefab.PrefabData)7 Command (org.terasology.engine.logic.console.commandSystem.annotations.Command)7 BlockUri (org.terasology.engine.world.block.BlockUri)7 AssetDataFile (org.terasology.gestalt.assets.format.AssetDataFile)7 Texture (org.terasology.engine.rendering.assets.texture.Texture)5 BlockManagerImpl (org.terasology.engine.world.block.internal.BlockManagerImpl)5 BlockFamilyDefinition (org.terasology.engine.world.block.loader.BlockFamilyDefinition)5 NullWorldAtlas (org.terasology.engine.world.block.tiles.NullWorldAtlas)5 ExtraBlockDataManager (org.terasology.engine.world.chunks.blockdata.ExtraBlockDataManager)5 StringComponent (org.terasology.unittest.stubs.StringComponent)5 ByteBuffer (java.nio.ByteBuffer)4