Search in sources :

Example 66 with ResourceUrn

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

the class EntitySystemSetupUtil method registerEvents.

private static void registerEvents(EventSystem eventSystem, ModuleEnvironment environment) {
    for (Class<? extends Event> type : environment.getSubtypesOf(Event.class)) {
        if (type.getAnnotation(DoNotAutoRegister.class) == null) {
            Name module = verifyNotNull(environment.getModuleProviding(type), "Environment has no module for %s", type.getSimpleName());
            eventSystem.registerEvent(new ResourceUrn(module.toString(), type.getSimpleName()), type);
        }
    }
}
Also used : DoNotAutoRegister(org.terasology.engine.entitySystem.systems.internal.DoNotAutoRegister) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) Name(org.terasology.gestalt.naming.Name)

Example 67 with ResourceUrn

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

the class CollectiveBehaviorSystem 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 68 with ResourceUrn

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

the class CollectiveBehaviorSystem method createTree.

public BehaviorTree createTree(String name, BehaviorNode root) {
    BehaviorTreeData data = new BehaviorTreeData();
    data.setRoot(root);
    BehaviorTree behaviorTree = assetManager.loadAsset(new ResourceUrn(BEHAVIORS, new Name(name.replaceAll("\\W+", ""))), data, BehaviorTree.class);
    trees.add(behaviorTree);
    save(behaviorTree);
    return behaviorTree;
}
Also used : BehaviorTreeData(org.terasology.engine.logic.behavior.asset.BehaviorTreeData) BehaviorTree(org.terasology.engine.logic.behavior.asset.BehaviorTree) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) Name(org.terasology.gestalt.naming.Name)

Example 69 with ResourceUrn

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

the class BehaviorSystem method createTree.

public BehaviorTree createTree(String name, BehaviorNode root) {
    BehaviorTreeData data = new BehaviorTreeData();
    data.setRoot(root);
    BehaviorTree behaviorTree = assetManager.loadAsset(new ResourceUrn(BEHAVIORS, new Name(name.replaceAll("\\W+", ""))), data, BehaviorTree.class);
    trees.add(behaviorTree);
    save(behaviorTree);
    return behaviorTree;
}
Also used : BehaviorTreeData(org.terasology.engine.logic.behavior.asset.BehaviorTreeData) BehaviorTree(org.terasology.engine.logic.behavior.asset.BehaviorTree) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) Name(org.terasology.gestalt.naming.Name)

Example 70 with ResourceUrn

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

the class InteractionUtil method getActiveInteractionScreenUri.

/**
 * @return the active interaction screen uri of the specified character.
 * The method returns null if the player has no interaction screen open.
 * The method is only intended to be called for the own character.
 */
public static ResourceUrn getActiveInteractionScreenUri(EntityRef character) {
    CharacterComponent characterComponent = character.getComponent(CharacterComponent.class);
    if (characterComponent == null) {
        return null;
    }
    EntityRef interactionTarget = characterComponent.predictedInteractionTarget;
    if (!interactionTarget.exists()) {
        return null;
    }
    InteractionScreenComponent screenComponent = interactionTarget.getComponent(InteractionScreenComponent.class);
    if (screenComponent == null) {
        return null;
    }
    return new ResourceUrn(screenComponent.screen);
}
Also used : CharacterComponent(org.terasology.engine.logic.characters.CharacterComponent) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef)

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