Search in sources :

Example 6 with ResourceUrn

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

the class CollectiveBehaviorSystem method initialise.

@Override
public void initialise() {
    List<ResourceUrn> uris = Lists.newArrayList();
    uris.addAll(new ArrayList<>(assetManager.getAvailableAssets(StaticSound.class)));
    for (ResourceUrn uri : assetManager.getAvailableAssets(BehaviorTree.class)) {
        Optional<BehaviorTree> asset = assetManager.getAsset(uri, BehaviorTree.class);
        if (asset.isPresent()) {
            trees.add(asset.get());
        } else {
            logger.warn("Failed to load behavior tree asset {}.", uri);
        }
    }
}
Also used : ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) BehaviorTree(org.terasology.engine.logic.behavior.asset.BehaviorTree)

Example 7 with ResourceUrn

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

the class BehaviorSystem method save.

public void save(BehaviorTree tree) {
    Path savePath;
    ResourceUrn uri = tree.getUrn();
    if (BEHAVIORS.equals(uri.getModuleName())) {
        savePath = PathManager.getInstance().getHomeModPath().resolve(BEHAVIORS.toString()).resolve("assets").resolve("behaviors");
    } else {
        Path overridesPath = PathManager.getInstance().getHomeModPath().resolve(BEHAVIORS.toString()).resolve("overrides");
        savePath = overridesPath.resolve(uri.getModuleName().toString()).resolve("behaviors");
    }
    BehaviorTreeFormat loader = new BehaviorTreeFormat();
    try {
        Files.createDirectories(savePath);
        Path file = savePath.resolve(uri.getResourceName() + ".behavior");
        try (FileOutputStream fos = new FileOutputStream(file.toFile())) {
            loader.save(fos, tree.getData());
        }
    } catch (IOException e) {
        throw new RuntimeException("Cannot save asset " + uri + " to " + savePath, e);
    }
}
Also used : Path(java.nio.file.Path) BehaviorTreeFormat(org.terasology.engine.logic.behavior.asset.BehaviorTreeFormat) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn)

Example 8 with ResourceUrn

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

the class WorldSerializerImpl method createPrefab.

private void createPrefab(EntityData.Prefab prefabData) {
    SimpleUri uri = new SimpleUri(prefabData.getName());
    try (ModuleContext.ContextSpan ignored = ModuleContext.setContext(moduleManager.getEnvironment().get(uri.getModuleName()))) {
        PrefabData protoPrefab = prefabSerializer.deserialize(prefabData);
        Assets.generateAsset(new ResourceUrn(prefabData.getName()), protoPrefab, Prefab.class);
    } catch (Exception e) {
        logger.error("Failed to create prefab {}", prefabData.getName());
    }
}
Also used : PrefabData(org.terasology.engine.entitySystem.prefab.PrefabData) SimpleUri(org.terasology.engine.core.SimpleUri) ModuleContext(org.terasology.engine.core.module.ModuleContext) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn)

Example 9 with ResourceUrn

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

the class EntityAwareWorldProviderTest method createBlockWithPrefab.

private Block createBlockWithPrefab(String urn, Prefab prefab, boolean keepActive, AssetManager assetManager, BlockManager blockManager) {
    BlockFamilyDefinitionData data = new BlockFamilyDefinitionData();
    data.setBlockFamily(SymmetricFamily.class);
    data.getBaseSection().getEntity().setPrefab(prefab);
    data.getBaseSection().getEntity().setKeepActive(keepActive);
    assetManager.loadAsset(new ResourceUrn(urn), data, BlockFamilyDefinition.class);
    return blockManager.getBlock(urn);
}
Also used : BlockFamilyDefinitionData(org.terasology.engine.world.block.loader.BlockFamilyDefinitionData) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn)

Example 10 with ResourceUrn

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

the class EntityAwareWorldProviderTest method setup.

@BeforeEach
public void setup() throws Exception {
    super.setup();
    GameThread.setToCurrentThread();
    this.entityManager = context.get(EngineEntityManager.class);
    AssetManager assetManager = context.get(AssetManager.class);
    BlockManager blockManager = context.get(BlockManager.class);
    airBlock = blockManager.getBlock(BlockManager.AIR_ID);
    worldStub = new WorldProviderCoreStub(airBlock);
    worldProvider = new EntityAwareWorldProvider(worldStub, context);
    plainBlock = createBlock("test:plainblock", assetManager, blockManager);
    prefabWithString = createPrefabWithString("test:prefabWithString", "Test", assetManager);
    blockWithString = createBlockWithPrefab("test:blockWithString", prefabWithString, false, assetManager, blockManager);
    keepActiveBlock = createBlockWithPrefab("test:keepActiveBlock", prefabWithString, true, assetManager, blockManager);
    Prefab prefabWithDifferentString = createPrefabWithString("test:prefabWithDifferentString", "Test2", assetManager);
    blockWithDifferentString = createBlockWithPrefab("test:prefabWithDifferentString", prefabWithDifferentString, false, assetManager, blockManager);
    BlockFamily blockFamily = createBlockFamily("test:blockFamily", prefabWithString, assetManager, blockManager);
    Iterator<Block> iterator = blockFamily.getBlocks().iterator();
    blockInFamilyOne = iterator.next();
    blockInFamilyTwo = iterator.next();
    PrefabData retainedPrefabData = new PrefabData();
    retainedPrefabData.addComponent(new RetainedOnBlockChangeComponent(3));
    Prefab retainedPrefab = assetManager.loadAsset(new ResourceUrn("test:retainedPrefab"), retainedPrefabData, Prefab.class);
    blockWithRetainedComponent = createBlockWithPrefab("test:blockWithRetainedComponent", retainedPrefab, false, assetManager, blockManager);
    worldProvider.initialise();
}
Also used : EngineEntityManager(org.terasology.engine.entitySystem.entity.internal.EngineEntityManager) AssetManager(org.terasology.gestalt.assets.management.AssetManager) PrefabData(org.terasology.engine.entitySystem.prefab.PrefabData) RetainedOnBlockChangeComponent(org.terasology.unittest.stubs.RetainedOnBlockChangeComponent) BlockManager(org.terasology.engine.world.block.BlockManager) Block(org.terasology.engine.world.block.Block) BlockFamily(org.terasology.engine.world.block.family.BlockFamily) EntityAwareWorldProvider(org.terasology.engine.world.internal.EntityAwareWorldProvider) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) Prefab(org.terasology.engine.entitySystem.prefab.Prefab) WorldProviderCoreStub(org.terasology.engine.testUtil.WorldProviderCoreStub) BeforeEach(org.junit.jupiter.api.BeforeEach)

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