Beispiel #1
0
  @SuppressWarnings("incomplete-switch")
  @Override
  public void onTick(float dt) {
    switch (Spout.getPlatform()) {
      case PROXY:
      case SERVER:
        World world = head.getPosition().getWorld();
        if (!(world.getBlock(head.getPosition()).getMaterial() instanceof Water)) {
          setAir(MAX_AIR);
          return;
        }

        if (getOwner() instanceof Player
            && !getOwner().get(Human.class).getGameMode().equals(GameMode.SURVIVAL)) {
          return;
        }

        setAir(getAir() - dt);
        if (getAir() < 0) {
          // out of air; damage one heart every second
          if (damageTimer-- < 0) {
            health.damage(
                2, new BlockDamageCause(world.getBlock(head.getPosition()), DamageType.DROWN));
            damageTimer = 20;
          }
        }
        break;
      case CLIENT:
        if (!(getOwner() instanceof Player)) {
          return;
        }
        // Animate air meter
        final float maxSecsBubbles = VanillaData.AIR_SECS.getDefaultValue();
        final float secsBubbles = getData().get(VanillaData.AIR_SECS);
        if (secsBubbles == maxSecsBubbles) {
          hideBubbles();
        } else {
          HUDComponent hud = getOwner().get(HUDComponent.class);
          if (hud != null) {
            hud.getAirMeter().update();
          }
        }
        break;
    }
  }
Beispiel #2
0
 public void showBubbles() {
   HUDComponent hud = getOwner().get(HUDComponent.class);
   if (hud != null) {
     hud.getAirMeter().show();
   }
 }