@Override
  protected void setupAssetManager() {
    setupEmptyAssetManager();

    AssetManager assetManager = CoreRegistry.get(AssetManager.class);
    AudioManager audioManager = CoreRegistry.get(AudioManager.class);
    AssetType.registerAssetTypes(assetManager);

    CodeSource tsCodeSource = TerasologyEngine.class.getProtectionDomain().getCodeSource();
    assetManager.addAssetSource(
        new ClasspathSource(
            TerasologyConstants.ENGINE_MODULE,
            tsCodeSource,
            TerasologyConstants.ASSETS_SUBDIRECTORY,
            TerasologyConstants.OVERRIDES_SUBDIRECTORY));

    CodeSource thisCodeSource = HeadlessEnvironment.class.getProtectionDomain().getCodeSource();
    assetManager.addAssetSource(
        new ClasspathSource(
            "unittest",
            thisCodeSource,
            TerasologyConstants.ASSETS_SUBDIRECTORY,
            TerasologyConstants.OVERRIDES_SUBDIRECTORY));

    assetManager.setAssetFactory(
        AssetType.PREFAB,
        new AssetFactory<PrefabData, Prefab>() {

          @Override
          public Prefab buildAsset(AssetUri uri, PrefabData data) {
            return new PojoPrefab(uri, data);
          }
        });
    assetManager.setAssetFactory(
        AssetType.SHAPE,
        new AssetFactory<BlockShapeData, BlockShape>() {

          @Override
          public BlockShape buildAsset(AssetUri uri, BlockShapeData data) {
            return new BlockShapeImpl(uri, data);
          }
        });

    assetManager.setAssetFactory(
        AssetType.UI_SKIN,
        new AssetFactory<UISkinData, UISkin>() {
          @Override
          public UISkin buildAsset(AssetUri uri, UISkinData data) {
            return new UISkin(uri, data);
          }
        });

    assetManager.setAssetFactory(AssetType.SOUND, audioManager.getStaticSoundFactory());
    assetManager.setAssetFactory(AssetType.MUSIC, audioManager.getStreamingSoundFactory());
  }
Example #2
0
 @ReceiveEvent
 public void onPlaySound(PlaySoundEvent playSoundEvent, EntityRef entity) {
   LocationComponent location = entity.getComponent(LocationComponent.class);
   if (location != null) {
     audioManager.playSound(
         playSoundEvent.getSound(),
         location.getWorldPosition(),
         playSoundEvent.getVolume(),
         AudioManager.PRIORITY_NORMAL);
   } else {
     audioManager.playSound(playSoundEvent.getSound(), playSoundEvent.getVolume());
   }
 }
Example #3
0
 @Command(shortDescription = "Plays a test sound")
 public void playTestSound(
     @CommandParam("xOffset") float xOffset, @CommandParam("zOffset") float zOffset) {
   Vector3f position = localPlayer.getPosition();
   position.x += xOffset;
   position.z += zOffset;
   audioManager.playSound(Assets.getSound("engine:dig"), position);
 }
Example #4
0
 @ReceiveEvent
 public void onPlaySound(PlaySoundForOwnerEvent playSoundEvent, EntityRef entity) {
   ClientComponent clientComponent =
       networkSystem.getOwnerEntity(entity).getComponent(ClientComponent.class);
   if (clientComponent != null && !clientComponent.local) {
     return;
   }
   audioManager.playSound(
       playSoundEvent.getSound(), playSoundEvent.getVolume(), AudioManager.PRIORITY_HIGH);
 }
Example #5
0
 /**
  * @param event ActivateEvent from the onActivate method
  * @param playSound ActionComponent for playing a sound
  * @param sound StaticSound instance for a sound Helper method for the activation of a sound.
  *     Check for the current position and play a sound according to it.
  */
 private void verifyAndPlaySound(
     ActivateEvent event, PlaySoundActionComponent playSound, StaticSound sound) {
   if (sound != null) {
     Vector3f pos = null;
     switch (playSound.relativeTo) {
       case Target:
         pos = event.getTargetLocation();
         break;
       default:
         pos = event.getInstigatorLocation();
         break;
     }
     if (pos == null) {
       pos = event.getOrigin();
     }
     audioManager.playSound(sound, pos, playSound.volume, AudioManager.PRIORITY_NORMAL);
   }
 }
Example #6
0
 /**
  * @param event An instance of the ActivationPredicted event
  * @param entity An instance of EntityRef Deal with the predicted activation events and play a
  *     sound.
  */
 @ReceiveEvent(components = {PlaySoundActionComponent.class})
 public void onActivationPredicted(ActivationPredicted event, EntityRef entity) {
   PlaySoundActionComponent playSound = entity.getComponent(PlaySoundActionComponent.class);
   StaticSound sound = random.nextItem(playSound.sounds);
   if (sound != null) {
     Vector3f pos = null;
     switch (playSound.relativeTo) {
       case Target:
         pos = event.getTargetLocation();
         break;
       default:
         pos = event.getInstigatorLocation();
         break;
     }
     if (pos == null) {
       pos = event.getOrigin();
     }
     audioManager.playSound(sound, pos, playSound.volume, AudioManager.PRIORITY_NORMAL);
   }
 }
Example #7
0
 @Override
 public void update(float delta) {
   audioManager.updateListener(
       localPlayer.getPosition(), localPlayer.getViewRotation(), localPlayer.getVelocity());
 }
Example #8
0
 @Command(shortDescription = "Toggle muting all sound")
 public String mute() {
   audioManager.setMute(!audioManager.isMute());
   return "All sound is now " + ((audioManager.isMute()) ? "muted." : "unmuted.");
 }