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