Exemple #1
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);
 }
 /**
  * @param event An instance of the ActivateEvent event
  * @param entity An instance of EntityRef Deal with the real activation event (No predicted) and
  *     play a sound.
  */
 @ReceiveEvent(components = {PlaySoundActionComponent.class})
 public void onActivate(ActivateEvent event, EntityRef entity) {
   if (event.getInstigator().equals(localPlayer.getCharacterEntity())) {
     return; // owner has heard sound from prediction
   }
   PlaySoundActionComponent playSound = entity.getComponent(PlaySoundActionComponent.class);
   StaticSound sound = random.nextItem(playSound.sounds);
   verifyAndPlaySound(event, playSound, sound);
 }
 private void updateFocalDistance(HitResult hitInfo, float delta) {
   float focusRate = 4.0f; // how fast the focus distance is updated
   // if the hit result from a trace has a recorded a hit
   if (hitInfo.isHit()) {
     Vector3f playerToTargetRay = new Vector3f();
     // calculate the distance from the player to the hit point
     playerToTargetRay.sub(hitInfo.getHitPoint(), localPlayer.getPosition());
     // gradually adjust focalDistance from it's current value to the hit point distance
     focalDistance = TeraMath.lerp(focalDistance, playerToTargetRay.length(), delta * focusRate);
     // if nothing was hit, gradually adjust the focusDistance to the maximum length of the update
     // function trace
   } else {
     focalDistance = TeraMath.lerp(focalDistance, targetDistance, delta * focusRate);
   }
 }
  @Override
  public boolean switchItem(
      EntityRef fromInventory,
      EntityRef instigator,
      int slotFrom,
      EntityRef toInventory,
      int slotTo) {
    if (!InventoryUtils.moveItem(instigator, fromInventory, slotFrom, toInventory, slotTo)) {
      return false;
    }

    MoveItemRequest request =
        new MoveItemRequest(instigator, fromInventory, slotFrom, toInventory, slotTo, changeId++);
    pendingMoves.put(request.getChangeId(), request);
    localPlayer.getClientEntity().send(request);

    return true;
  }
  public void update(float delta) {
    // Repair lost target
    // TODO: Improvements to temporary chunk handling will remove the need for this
    boolean lostTarget = false;

    updateTarget();
    if (!target.exists()) {
      targetBlockPos = null;
      lostTarget = true;
    }

    // TODO: This will change when camera are handled better (via a component)
    Camera camera = worldRenderer.getActiveCamera();

    HitResult hitInfo =
        physics.rayTrace(
            new Vector3f(camera.getPosition()),
            new Vector3f(camera.getViewingDirection()),
            targetDistance,
            filter);
    updateFocalDistance(hitInfo, delta);
    Vector3i newBlockPos = null;

    EntityRef newTarget = EntityRef.NULL;
    if (hitInfo.isHit()) {
      newTarget = hitInfo.getEntity();
      hitPosition = hitInfo.getHitPoint();
      hitNormal = hitInfo.getHitNormal();
      if (hitInfo.isWorldHit()) {
        newBlockPos = new Vector3i(hitInfo.getBlockPosition());
      }
    }
    if (!Objects.equal(target, newTarget) || lostTarget) {
      EntityRef oldTarget = target;
      oldTarget.send(new CameraOutEvent());
      newTarget.send(new CameraOverEvent());
      localPlayer.getCharacterEntity().send(new CameraTargetChangedEvent(oldTarget, newTarget));
    }
    target = newTarget;
    targetBlockPos = newBlockPos;
  }
Exemple #6
0
 @Override
 public void update(float delta) {
   audioManager.updateListener(
       localPlayer.getPosition(), localPlayer.getViewRotation(), localPlayer.getVelocity());
 }
  @Override
  public void update() {
    super.update();

    updateHealthBar(localPlayer.getCharacterEntity().getComponent(HealthComponent.class));
    updateBreathBar(
        localPlayer.getCharacterEntity().getComponent(DrownsComponent.class),
        localPlayer.getCharacterEntity().getComponent(DrowningComponent.class));
  }
Exemple #8
-1
 private EntityRef[] getInputEntities() {
   return new EntityRef[] {localPlayer.getClientEntity(), localPlayer.getCharacterEntity()};
 }
  @Override
  public boolean moveItemToSlots(
      EntityRef instigator,
      EntityRef fromInventory,
      int slotFrom,
      EntityRef toInventory,
      List<Integer> toSlots) {
    if (!InventoryUtils.moveItemToSlots(
        instigator, fromInventory, slotFrom, toInventory, toSlots)) {
      return false;
    }

    MoveItemToSlotsRequest request =
        new MoveItemToSlotsRequest(
            instigator, fromInventory, slotFrom, toInventory, toSlots, changeId++);
    pendingMoves.put(request.getChangeId(), request);
    localPlayer.getClientEntity().send(request);

    return true;
  }