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);
}
}
}
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);
}
}
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;
}
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;
}
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);
}
Aggregations