Search in sources :

Example 46 with ResourceUrn

use of org.terasology.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.logic.behavior.asset.BehaviorTreeFormat) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) ResourceUrn(org.terasology.assets.ResourceUrn)

Example 47 with ResourceUrn

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

the class BehaviorSystem 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)) {
        try {
            Optional<BehaviorTree> asset = assetManager.getAsset(uri, BehaviorTree.class);
            asset.ifPresent(behaviorTree -> trees.add(behaviorTree));
        } catch (RuntimeException e) {
            logger.info("Failed to load behavior tree asset {}.", uri, e);
        }
    }
}
Also used : ResourceUrn(org.terasology.assets.ResourceUrn) BehaviorTree(org.terasology.logic.behavior.asset.BehaviorTree)

Example 48 with ResourceUrn

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

the class BehaviorNodeFactory method refreshPrefabs.

private void refreshPrefabs() {
    Collection<Prefab> prefabs = prefabManager.listPrefabs(BehaviorNodeComponent.class);
    if (prefabs.size() == 0) {
        // called from main menu
        List<String> nodes = Arrays.asList("counter", "timer", "loop", "lookup", "dynselector", "fail", "parallel", "playMusic", "playSound", "running", "selector", "setAnimation", "sequence", "succeed");
        prefabs = Lists.newArrayList();
        for (String node : nodes) {
            prefabs.add(Assets.get(new ResourceUrn("engine:" + node), Prefab.class).orElse(null));
        }
    }
    for (Prefab prefab : prefabs) {
        EntityBuilder entityBuilder = entityManager.newBuilder(prefab);
        entityBuilder.setPersistent(false);
        EntityRef entityRef = entityBuilder.build();
        BehaviorNodeComponent component = entityRef.getComponent(BehaviorNodeComponent.class);
        addToCategory(component);
        nodeComponents.add(component);
    }
}
Also used : EntityBuilder(org.terasology.entitySystem.entity.EntityBuilder) ResourceUrn(org.terasology.assets.ResourceUrn) Prefab(org.terasology.entitySystem.prefab.Prefab) EntityRef(org.terasology.entitySystem.entity.EntityRef)

Example 49 with ResourceUrn

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

the class InternalLightGeneratorTest method setup.

@Before
public void setup() throws Exception {
    super.setup();
    AssetManager assetManager = CoreRegistry.get(AssetManager.class);
    blockManager = new BlockManagerImpl(new NullWorldAtlas(), assetManager);
    CoreRegistry.put(BlockManager.class, blockManager);
    airBlock = blockManager.getBlock(BlockManager.AIR_ID);
    biomeManager = Mockito.mock(BiomeManager.class);
    BlockFamilyDefinitionData solidData = new BlockFamilyDefinitionData();
    solidData.getBaseSection().setDisplayName("Stone");
    solidData.getBaseSection().setShape(assetManager.getAsset("engine:cube", BlockShape.class).get());
    solidData.getBaseSection().setTranslucent(false);
    solidData.setFamilyFactory(new SymmetricBlockFamilyFactory());
    assetManager.loadAsset(new ResourceUrn("engine:stone"), solidData, BlockFamilyDefinition.class);
    solidBlock = blockManager.getBlock(new BlockUri(new ResourceUrn("engine:stone")));
    BlockFamilyDefinitionData fullLightData = new BlockFamilyDefinitionData();
    fullLightData.getBaseSection().setDisplayName("Torch");
    fullLightData.getBaseSection().setShape(assetManager.getAsset("engine:cube", BlockShape.class).get());
    fullLightData.getBaseSection().setLuminance(ChunkConstants.MAX_LIGHT);
    fullLightData.setFamilyFactory(new SymmetricBlockFamilyFactory());
    assetManager.loadAsset(new ResourceUrn("engine:torch"), fullLightData, BlockFamilyDefinition.class);
    fullLight = blockManager.getBlock(new BlockUri(new ResourceUrn("engine:torch")));
}
Also used : BiomeManager(org.terasology.world.biomes.BiomeManager) BlockUri(org.terasology.world.block.BlockUri) AssetManager(org.terasology.assets.management.AssetManager) BlockFamilyDefinitionData(org.terasology.world.block.loader.BlockFamilyDefinitionData) NullWorldAtlas(org.terasology.world.block.tiles.NullWorldAtlas) ResourceUrn(org.terasology.assets.ResourceUrn) SymmetricBlockFamilyFactory(org.terasology.world.block.family.SymmetricBlockFamilyFactory) BlockManagerImpl(org.terasology.world.block.internal.BlockManagerImpl) Before(org.junit.Before)

Example 50 with ResourceUrn

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

the class BetweenChunkPropagationTest method setup.

@Before
@Override
public void setup() throws Exception {
    super.setup();
    AssetManager assetManager = CoreRegistry.get(AssetManager.class);
    regenRules = new SunlightRegenPropagationRules();
    blockManager = new BlockManagerImpl(new NullWorldAtlas(), assetManager, true);
    biomeManager = Mockito.mock(BiomeManager.class);
    CoreRegistry.put(BlockManager.class, blockManager);
    BlockFamilyDefinitionData solidData = new BlockFamilyDefinitionData();
    solidData.getBaseSection().setDisplayName("Stone");
    solidData.getBaseSection().setShape(assetManager.getAsset("engine:cube", BlockShape.class).get());
    solidData.getBaseSection().setTranslucent(false);
    solidData.setFamilyFactory(new SymmetricBlockFamilyFactory());
    assetManager.loadAsset(new ResourceUrn("engine:stone"), solidData, BlockFamilyDefinition.class);
    solid = blockManager.getBlock(new BlockUri(new ResourceUrn("engine:stone")));
    regenWorldView = new SunlightRegenWorldView(provider);
    lightWorldView = new SunlightWorldView(provider);
    lightRules = new SunlightPropagationRules(regenWorldView);
    sunlightPropagator = new StandardBatchPropagator(lightRules, lightWorldView);
    propagator = new SunlightRegenBatchPropagator(regenRules, regenWorldView, sunlightPropagator, lightWorldView);
}
Also used : BiomeManager(org.terasology.world.biomes.BiomeManager) BlockUri(org.terasology.world.block.BlockUri) AssetManager(org.terasology.assets.management.AssetManager) SunlightRegenWorldView(org.terasology.world.propagation.light.SunlightRegenWorldView) SunlightPropagationRules(org.terasology.world.propagation.light.SunlightPropagationRules) SunlightWorldView(org.terasology.world.propagation.light.SunlightWorldView) BlockFamilyDefinitionData(org.terasology.world.block.loader.BlockFamilyDefinitionData) NullWorldAtlas(org.terasology.world.block.tiles.NullWorldAtlas) ResourceUrn(org.terasology.assets.ResourceUrn) SunlightRegenPropagationRules(org.terasology.world.propagation.light.SunlightRegenPropagationRules) SymmetricBlockFamilyFactory(org.terasology.world.block.family.SymmetricBlockFamilyFactory) BlockManagerImpl(org.terasology.world.block.internal.BlockManagerImpl) Before(org.junit.Before)

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